Bug 1358025 - Part 3. Use nsIEditor.setText when input.value setter isn't user interaction. r=masayuki
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Thu, 18 May 2017 16:32:21 +0900
changeset 411237 f5c9b93e31d3c293cb2b1e1b4bcaf98da304e280
parent 411236 bbe1b297cc891e07d1c5962bbcd74f967ee09239
child 411238 97275ae04155d9fc5172b2c28012e521a529503a
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1358025
milestone55.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 1358025 - Part 3. Use nsIEditor.setText when input.value setter isn't user interaction. r=masayuki When not using eSetValue_BySetUserInput, we should use SetText transaction instead for fast path. For backward compatibility, when input.value setter is by user interaction, I keep original way. Because the original way doesn't replace all text when some string matches. MozReview-Commit-ID: IDm7Y1NBmaK
dom/html/nsTextEditorState.cpp
--- a/dom/html/nsTextEditorState.cpp
+++ b/dom/html/nsTextEditorState.cpp
@@ -2598,30 +2598,16 @@ nsTextEditorState::SetValue(const nsAStr
         if (domSel)
         {
           selPriv = do_QueryInterface(domSel);
           if (selPriv) {
             selPriv->StartBatchChanges();
           }
         }
 
-        nsCOMPtr<nsISelectionController> kungFuDeathGrip = mSelCon.get();
-        uint32_t currentLength = currentValue.Length();
-        uint32_t newlength = newValue.Length();
-        if (!currentLength ||
-            !StringBeginsWith(newValue, currentValue)) {
-          // Replace the whole text.
-          currentLength = 0;
-          kungFuDeathGrip->SelectAll();
-        } else {
-          // Collapse selection to the end so that we can append data.
-          mBoundFrame->SelectAllOrCollapseToEndOfText(false);
-        }
-        const nsAString& insertValue =
-          StringTail(newValue, newlength - currentLength);
         nsCOMPtr<nsIPlaintextEditor> plaintextEditor = do_QueryInterface(mEditor);
         if (!plaintextEditor || !weakFrame.IsAlive()) {
           NS_WARNING("Somehow not a plaintext editor?");
           return true;
         }
 
         valueSetter.Init();
 
@@ -2629,20 +2615,39 @@ nsTextEditorState::SetValue(const nsAStr
         // set the value, restore flags
         {
           AutoRestoreEditorState restoreState(mEditor, plaintextEditor);
 
           mTextListener->SettingValue(true);
           bool notifyValueChanged = !!(aFlags & eSetValue_Notify);
           mTextListener->SetValueChanged(notifyValueChanged);
 
-          if (insertValue.IsEmpty()) {
-            mEditor->DeleteSelection(nsIEditor::eNone, nsIEditor::eStrip);
+          if (aFlags & eSetValue_BySetUserInput) {
+            nsCOMPtr<nsISelectionController> kungFuDeathGrip = mSelCon.get();
+            uint32_t currentLength = currentValue.Length();
+            uint32_t newlength = newValue.Length();
+            if (!currentLength ||
+                !StringBeginsWith(newValue, currentValue)) {
+              // Replace the whole text.
+              currentLength = 0;
+              kungFuDeathGrip->SelectAll();
+            } else {
+              // Collapse selection to the end so that we can append data.
+              mBoundFrame->SelectAllOrCollapseToEndOfText(false);
+            }
+            const nsAString& insertValue =
+              StringTail(newValue, newlength - currentLength);
+
+            if (insertValue.IsEmpty()) {
+              mEditor->DeleteSelection(nsIEditor::eNone, nsIEditor::eStrip);
+            } else {
+              plaintextEditor->InsertText(insertValue);
+            }
           } else {
-            plaintextEditor->InsertText(insertValue);
+            plaintextEditor->SetText(newValue);
           }
 
           mTextListener->SetValueChanged(true);
           mTextListener->SettingValue(false);
         }
 
         if (!weakFrame.IsAlive()) {
           // If the frame was destroyed because of a flush somewhere inside