diff --git a/dom/base/nsFocusManager.cpp b/dom/base/nsFocusManager.cpp index 098d380e6e036..6f226bbe93a5b 100644 --- a/dom/base/nsFocusManager.cpp +++ b/dom/base/nsFocusManager.cpp @@ -2636,16 +2636,15 @@ void nsFocusManager::Focus( aWindow->SetFocusedElement(aElement, focusMethod, false); + // if the focused element changed, scroll it into view + if (aElement && aFocusChanged) { + ScrollIntoView(presShell, aElement, aFlags); + } const RefPtr presContext = presShell->GetPresContext(); if (sendFocusEvent) { NotifyFocusStateChange(aElement, nullptr, aFlags, /* aGettingFocus = */ true, shouldShowFocusRing); - // If the focused element changed, scroll it into view - if (aFocusChanged) { - ScrollIntoView(presShell, aElement, aFlags); - } - // If this is a remote browser, focus its widget and activate remote // content. Note that we might no longer be in the same document, // due to the events we fired above when aIsNewDocument. diff --git a/testing/web-platform/tests/focus/scroll-matches-focus.html b/testing/web-platform/tests/focus/scroll-matches-focus.html deleted file mode 100644 index 46a58fdf974f5..0000000000000 --- a/testing/web-platform/tests/focus/scroll-matches-focus.html +++ /dev/null @@ -1,47 +0,0 @@ - - -:focus applies before scrolling into view - - - - - - -
-
I am focusable
-
-