Bug 1850341 - Improve focus handling in hidepopover. r=emilio

Fix the previous handling of checking if focus is within the hierarchy.

Differential Revision: https://phabricator.services.mozilla.com/D186937
This commit is contained in:
Ziran Sun
2023-09-29 12:47:09 +00:00
parent 4d353f0ef3
commit 8439e158b4
3 changed files with 12 additions and 31 deletions

View File

@@ -3393,10 +3393,18 @@ void nsGenericHTMLElement::FocusPreviousElementAfterHidingPopover() {
return;
}
// Run the focusing steps for previouslyFocusedElement.
FocusOptions options;
options.mPreventScroll = true;
control->Focus(options, CallerType::NonSystem, IgnoreErrors());
// Step 14.2 at
// https://html.spec.whatwg.org/multipage/popover.html#hide-popover-algorithm
// If focusPreviousElement is true and document's focused area of the
// document's DOM anchor is a shadow-including inclusive descendant of
// element, then run the focusing steps for previouslyFocusedElement;
nsIContent* currentFocus = OwnerDoc()->GetUnretargetedFocusedContent();
if (currentFocus &&
currentFocus->IsShadowIncludingInclusiveDescendantOf(this)) {
FocusOptions options;
options.mPreventScroll = true;
control->Focus(options, CallerType::NonSystem, IgnoreErrors());
}
}
// https://html.spec.whatwg.org/multipage/popover.html#dom-togglepopover