Bug 1380824 - Call RepaintSelection out of script blocker. r=masayuki
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Thu, 17 Aug 2017 15:28:04 +0900
changeset 424849 6a65de867d0011c87d7e14b0fa3c2b1cf74e662d
parent 424848 822d7f1bc602f84332b13e258738aa3b95700691
child 424850 636403d10e6004f3a4a1a077cfbd2bc6c429e07b
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1380824
milestone57.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 1380824 - Call RepaintSelection out of script blocker. r=masayuki MozReview-Commit-ID: LFyZLW0da7f
editor/libeditor/EditorBase.cpp
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -4887,16 +4887,35 @@ EditorBase::InitializeSelection(nsIDOMEv
                                               mIMETextLength,
                                               mComposition->GetRanges());
     }
   }
 
   return NS_OK;
 }
 
+class RepaintSelectionRunner final : public Runnable {
+public:
+  explicit RepaintSelectionRunner(nsISelectionController* aSelectionController)
+    : Runnable("RepaintSelectionRunner")
+    , mSelectionController(aSelectionController)
+  {
+  }
+
+  NS_IMETHOD Run() override
+  {
+    mSelectionController->RepaintSelection(
+                            nsISelectionController::SELECTION_NORMAL);
+    return NS_OK;
+  }
+
+private:
+  nsCOMPtr<nsISelectionController> mSelectionController;
+};
+
 NS_IMETHODIMP
 EditorBase::FinalizeSelection()
 {
   nsCOMPtr<nsISelectionController> selectionController =
     GetSelectionController();
   if (NS_WARN_IF(!selectionController)) {
     return NS_ERROR_FAILURE;
   }
@@ -4941,18 +4960,20 @@ EditorBase::FinalizeSelection()
                            nsISelectionController::SELECTION_HIDDEN);
   } else {
     // Otherwise, although we're not sure how this case happens, the
     // independent selection should be marked as disabled.
     selectionController->SetDisplaySelection(
                            nsISelectionController::SELECTION_DISABLED);
   }
 
-  selectionController->RepaintSelection(
-                         nsISelectionController::SELECTION_NORMAL);
+  // FinalizeSelection might be called from ContentRemoved even if selection
+  // isn't updated.  So we need to call RepaintSelection after updated it.
+  nsContentUtils::AddScriptRunner(
+                    new RepaintSelectionRunner(selectionController));
   return NS_OK;
 }
 
 Element*
 EditorBase::GetRoot()
 {
   if (!mRootElement) {
     // Let GetRootElement() do the work