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
--- 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;