diff --git a/dom/base/nsFocusManager.cpp b/dom/base/nsFocusManager.cpp index 075d8e791e6d..c73e5f1d475d 100644 --- a/dom/base/nsFocusManager.cpp +++ b/dom/base/nsFocusManager.cpp @@ -3401,15 +3401,16 @@ nsresult nsFocusManager::GetNextTabbableContent( } } + nsIContent* oldTopLevelScopeOwner = nullptr; // Walk frames to find something tabbable matching aCurrentTabIndex while (frame) { // Try to find the topmost scope owner, since we want to skip the node // that is not owned by document in frame traversal. nsIContent* currentContent = frame->GetContent(); - nsIContent* oldTopLevelScopeOwner = currentTopLevelScopeOwner; - if (!aForward || currentTopLevelScopeOwner != currentContent) { - currentTopLevelScopeOwner = GetTopLevelScopeOwner(currentContent); + if (currentTopLevelScopeOwner) { + oldTopLevelScopeOwner = currentTopLevelScopeOwner; } + currentTopLevelScopeOwner = GetTopLevelScopeOwner(currentContent); if (currentTopLevelScopeOwner && currentTopLevelScopeOwner == oldTopLevelScopeOwner) { // We're within non-document scope, continue. diff --git a/testing/web-platform/tests/shadow-dom/focus/focus-tabindex-order-shadow-zero-host-not-set-scrollable.html b/testing/web-platform/tests/shadow-dom/focus/focus-tabindex-order-shadow-zero-host-not-set-scrollable.html new file mode 100644 index 000000000000..9a12d8b8f42c --- /dev/null +++ b/testing/web-platform/tests/shadow-dom/focus/focus-tabindex-order-shadow-zero-host-not-set-scrollable.html @@ -0,0 +1,38 @@ + + +HTML Test: focus - the sequential focus navigation order with shadow dom and scrollable/non-focusable host + + + + + + + + +