Bug 1514511 - Flush the document, not the shell, in Selection::ScrollIntoView. r=bzbarsky
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sat, 26 Jan 2019 08:55:24 +0100
changeset 515539 da799f611f33fc367cb49193872709c2cd89fd8a
parent 515538 edfd8a13603c0d5ebb69362dff02bb138f616127
child 515540 8f22c3daa581e0f5c89f7ee6a8e74f6a00e3d7fd
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1514511
milestone66.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 1514511 - Flush the document, not the shell, in Selection::ScrollIntoView. r=bzbarsky Flushing just the shell is not quite sound, since it doesn't flush parent documents, and also doesn't have the side effect of ensuring the shell is not destroying and the document is not in the bfcache. Differential Revision: https://phabricator.services.mozilla.com/D14687
dom/base/Selection.cpp
--- a/dom/base/Selection.cpp
+++ b/dom/base/Selection.cpp
@@ -3036,20 +3036,24 @@ void Selection::ScrollIntoView(int16_t a
     aRv.Throw(rv);
   }
 }
 
 nsresult Selection::ScrollIntoView(SelectionRegion aRegion,
                                    nsIPresShell::ScrollAxis aVertical,
                                    nsIPresShell::ScrollAxis aHorizontal,
                                    int32_t aFlags) {
-  if (!mFrameSelection) return NS_OK;  // nothing to do
+  if (!mFrameSelection) {
+    return NS_OK;
+  }
 
   nsIPresShell* presShell = mFrameSelection->GetShell();
-  if (!presShell) return NS_OK;
+  if (!presShell || !presShell->GetDocument()) {
+    return NS_OK;
+  }
 
   if (mFrameSelection->GetBatching()) return NS_OK;
 
   if (!(aFlags & Selection::SCROLL_SYNCHRONOUS))
     return PostScrollSelectionIntoViewEvent(aRegion, aFlags, aVertical,
                                             aHorizontal);
 
   // From this point on, the presShell may get destroyed by the calls below, so
@@ -3058,17 +3062,17 @@ nsresult Selection::ScrollIntoView(Selec
   nsCOMPtr<nsIPresShell> kungFuDeathGrip(presShell);
 
   // Now that text frame character offsets are always valid (though not
   // necessarily correct), the worst that will happen if we don't flush here
   // is that some callers might scroll to the wrong place.  Those should
   // either manually flush if they're in a safe position for it or use the
   // async version of this method.
   if (aFlags & Selection::SCROLL_DO_FLUSH) {
-    presShell->FlushPendingNotifications(FlushType::Layout);
+    presShell->GetDocument()->FlushPendingNotifications(FlushType::Layout);
 
     // Reget the presshell, since it might have been Destroy'ed.
     presShell = mFrameSelection ? mFrameSelection->GetShell() : nullptr;
     if (!presShell) return NS_OK;
   }
 
   //
   // Scroll the selection region into view.