Bug 1370806 - Part 1. Use RAII class for StartBatchChanges and EndBatchChanges. r?masayuki draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Wed, 07 Jun 2017 14:11:31 +0900
changeset 590730 d0859fd2db6f92a948a51a8dc05a78c735f36fea
parent 590317 a49112c7a5765802096b3fc298069b9495436107
child 590731 d2149a814760b5c6ae50d9f7a5c309fb837eb447
push id62809
push userbmo:m_kato@ga2.so-net.ne.jp
push dateThu, 08 Jun 2017 01:13:10 +0000
reviewersmasayuki
bugs1370806
milestone55.0a1
Bug 1370806 - Part 1. Use RAII class for StartBatchChanges and EndBatchChanges. r?masayuki Although we use StartBatchChanges and EndBatchChanges in nsTextEditorState::SetValue, we have a path that EndBatchChanges isn't called. So we should use RAII class to call EndBatchChanges correctly. MozReview-Commit-ID: 6bjtTT9wItA
dom/html/nsTextEditorState.cpp
--- a/dom/html/nsTextEditorState.cpp
+++ b/dom/html/nsTextEditorState.cpp
@@ -2611,26 +2611,20 @@ nsTextEditorState::SetValue(const nsAStr
 
       // Time to mess with our security context... See comments in GetValue()
       // for why this is needed.  Note that we have to do this up here, because
       // otherwise SelectAll() will fail.
       {
         AutoNoJSAPI nojsapi;
 
         nsCOMPtr<nsISelection> domSel;
-        nsCOMPtr<nsISelectionPrivate> selPriv;
         mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
                               getter_AddRefs(domSel));
-        if (domSel)
-        {
-          selPriv = do_QueryInterface(domSel);
-          if (selPriv) {
-            selPriv->StartBatchChanges();
-          }
-        }
+        SelectionBatcher selectionBatcher(domSel ? domSel->AsSelection() :
+                                                   nullptr);
 
         nsCOMPtr<nsIPlaintextEditor> plaintextEditor = do_QueryInterface(mEditor);
         if (!plaintextEditor || !weakFrame.IsAlive()) {
           NS_WARNING("Somehow not a plaintext editor?");
           return true;
         }
 
         valueSetter.Init();
@@ -2687,20 +2681,16 @@ nsTextEditorState::SetValue(const nsAStr
           return true;
         }
 
         if (!IsSingleLineTextControl()) {
           if (!mCachedValue.Assign(newValue, fallible)) {
             return false;
           }
         }
-
-        if (selPriv) {
-          selPriv->EndBatchChanges();
-        }
       }
     }
   } else {
     if (!mValue) {
       mValue.emplace();
     }
 
     // We can't just early-return here if mValue->Equals(newValue), because