Bug 1891934 - [popover] Handling focus naviagtion when invoker is not focusable. r=smaug

At popover navigation bug 1856539, we left the case that when invoker is not focusable to its default behaviour.
At https://github.com/web-platform-tests/wpt/pull/45391, it is suggested that we should another element next to
the invoker to focus.

Differential Revision: https://phabricator.services.mozilla.com/D207693
This commit is contained in:
Ziran Sun 2024-05-02 08:51:13 +00:00
parent e95677bb53
commit 44f3e9c4c2
2 changed files with 20 additions and 12 deletions

View file

@ -4303,20 +4303,22 @@ nsresult nsFocusManager::GetNextTabbableContent(
// Stepping out popover scope.
// For forward, search for the next tabbable content after invoker.
// For backward, we should get back to the invoker.
// For backward, we should get back to the invoker if the invoker is
// focusable. Otherwise search for the next tabbable content after
// invoker.
if (oldTopLevelScopeOwner &&
IsOpenPopoverWithInvoker(oldTopLevelScopeOwner) &&
currentTopLevelScopeOwner != oldTopLevelScopeOwner) {
if (auto* popover = Element::FromNode(oldTopLevelScopeOwner)) {
RefPtr<nsIContent> invokerContent =
popover->GetPopoverData()->GetInvoker()->AsContent();
RefPtr<nsIContent> rootElement = invokerContent;
if (auto* doc = invokerContent->GetComposedDoc()) {
rootElement = doc->GetRootElement();
}
if (aForward) {
nsIFrame* frame = invokerContent->GetPrimaryFrame();
int32_t tabIndex = frame->IsFocusable().mTabIndex;
RefPtr<nsIContent> rootElement = invokerContent;
if (auto* doc = invokerContent->GetComposedDoc()) {
rootElement = doc->GetRootElement();
}
if (tabIndex >= 0 &&
(aIgnoreTabIndex || aCurrentTabIndex == tabIndex)) {
nsresult rv = GetNextTabbableContent(
@ -4327,12 +4329,19 @@ nsresult nsFocusManager::GetNextTabbableContent(
return rv;
}
}
} else if (invokerContent &&
invokerContent->IsFocusableWithoutStyle()) {
// FIXME(emilio): The check above should probably use
// nsIFrame::IsFocusable, not IsFocusableWithoutStyle.
invokerContent.forget(aResultContent);
return NS_OK;
} else if (invokerContent) {
nsIFrame* frame = invokerContent->GetPrimaryFrame();
if (frame && frame->IsFocusable()) {
invokerContent.forget(aResultContent);
return NS_OK;
}
nsresult rv = GetNextTabbableContent(
aPresShell, rootElement, aOriginalStartContent, invokerContent,
false, 0, true, false, aNavigateByKey, true,
aReachedToEndForDocumentNavigation, aResultContent);
if (NS_SUCCEEDED(rv) && *aResultContent) {
return rv;
}
}
}
}

View file

@ -6,7 +6,6 @@
expected:
if (os == "win") and not debug and (processor == "x86_64"): [FAIL, PASS, TIMEOUT]
if (os == "mac") and not debug: [FAIL, PASS, TIMEOUT]
FAIL
[Circular reference tab navigation]
expected: