Bug 1377752 - part2: Selection::NotifySelectionListeners() should make nsFocusManager not scroll new focused element into the view if it's not focused document r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 05 Jul 2017 21:35:18 +0900
changeset 367591 617800a7300f4b3cb26714f51146581ff009da0a
parent 367590 9955dd87b1697e26ec1b5dc49899af5e13ed9c68
child 367592 a3c423b4ab945b653fe4acfa4995cd351aef1b38
push id92263
push usercbook@mozilla.com
push dateThu, 06 Jul 2017 09:21:27 +0000
treeherdermozilla-inbound@530b9cd1f963 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1377752
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1377752 - part2: Selection::NotifySelectionListeners() should make nsFocusManager not scroll new focused element into the view if it's not focused document r=smaug When changing selection into a contenteditable element in non-focused document, new focused editor shouldn't be scrolled into the view for compatibility with the other browsers. MozReview-Commit-ID: FabqizyJrPW
dom/base/Selection.cpp
--- a/dom/base/Selection.cpp
+++ b/dom/base/Selection.cpp
@@ -3729,18 +3729,23 @@ Selection::NotifySelectionListeners()
       // When all selected ranges are in an editing host, it should take focus.
       // But otherwise, we shouldn't move focus since Chromium doesn't move
       // focus but only selection range is updated.
       if (newEditingHost && newEditingHost != focusedElement) {
         MOZ_ASSERT(!newEditingHost->IsInNativeAnonymousSubtree());
         nsCOMPtr<nsIDOMElement> domElementToFocus =
           do_QueryInterface(newEditingHost->AsDOMNode());
         // Note that don't steal focus from focused window if the window doesn't
-        // have focus.
-        fm->SetFocus(domElementToFocus, nsIFocusManager::FLAG_NOSWITCHFRAME);
+        // have focus and if the window isn't focused window, shouldn't be
+        // scrolled to the new focused element.
+        uint32_t flags = nsIFocusManager::FLAG_NOSWITCHFRAME;
+        if (focusedWindow != fm->GetFocusedWindow()) {
+          flags |= nsIFocusManager::FLAG_NOSCROLL;
+        }
+        fm->SetFocus(domElementToFocus, flags);
       }
     }
   }
 
   RefPtr<nsFrameSelection> frameSelection = mFrameSelection;
   if (frameSelection->GetBatching()) {
     frameSelection->SetDirty();
     return NS_OK;