Bug 1377752 - part2: Selection::NotifySelectionListeners() should make nsFocusManager not scroll new focused element into the view if it's not focused document r?smaug draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 05 Jul 2017 21:35:18 +0900
changeset 604233 24d8cade3195b3a1a66a8ecd35851113e19a0650
parent 604232 62a06e867ea05fb802a5ec7acf4b96fa3d23c659
child 636140 157d7a23916d473a3ec0a3ef9ab4c70c7b4dcf02
push id67016
push usermasayuki@d-toybox.com
push dateWed, 05 Jul 2017 16:47:06 +0000
reviewerssmaug
bugs1377752
milestone56.0a1
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;