Bug 1380824 - Call RepaintSelection out of script blocker. r=masayuki, a=gchang
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Mon, 28 Aug 2017 10:00:34 -0400
changeset 356263 fbddb5cdd3c705d1d70afa96530a9fb0522cd7ea
parent 356262 744f8f20e8292f326eb922dea1b45b2a047801d2
child 356264 76c25987a2759a4c649aea1dacf7eb79e983c29f
push id7278
push userryanvm@gmail.com
push dateMon, 28 Aug 2017 14:01:40 +0000
treeherdermozilla-esr52@e45e21461784 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki, gchang
bugs1380824
milestone52.3.1
Bug 1380824 - Call RepaintSelection out of script blocker. r=masayuki, a=gchang
editor/libeditor/EditorBase.cpp
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -4782,16 +4782,34 @@ EditorBase::InitializeSelection(nsIDOMEv
                                               mIMETextLength,
                                               mComposition->GetRanges());
     }
   }
 
   return NS_OK;
 }
 
+class RepaintSelectionRunner final : public Runnable {
+public:
+  explicit RepaintSelectionRunner(nsISelectionController* aSelectionController)
+    : mSelectionController(aSelectionController)
+  {
+  }
+
+  NS_IMETHOD Run() override
+  {
+    mSelectionController->RepaintSelection(
+                            nsISelectionController::SELECTION_NORMAL);
+    return NS_OK;
+  }
+
+private:
+  nsCOMPtr<nsISelectionController> mSelectionController;
+};
+
 NS_IMETHODIMP
 EditorBase::FinalizeSelection()
 {
   nsCOMPtr<nsISelectionController> selCon;
   nsresult rv = GetSelectionController(getter_AddRefs(selCon));
   NS_ENSURE_SUCCESS(rv, rv);
 
   RefPtr<Selection> selection = GetSelection();
@@ -4830,17 +4848,21 @@ EditorBase::FinalizeSelection()
     // while this editor doesn't have focus.
     selCon->SetDisplaySelection(nsISelectionController::SELECTION_HIDDEN);
   } else {
     // Otherwise, although we're not sure how this case happens, the
     // independent selection should be marked as disabled.
     selCon->SetDisplaySelection(nsISelectionController::SELECTION_DISABLED);
   }
 
-  selCon->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(selCon));
   return NS_OK;
 }
 
 Element*
 EditorBase::GetRoot()
 {
   if (!mRootElement) {
     // Let GetRootElement() do the work