Bug 1162818 part.3 nsEditor should store actual composition string length in it r=ehsan
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 05 Jun 2015 02:06:09 +0900
changeset 247171 75ceb4773c0d6f2576dea5ac37a5bf11eb4f5cde
parent 247170 e037403d3e8c1e82956046c0b208864079a96b0b
child 247172 30de3e9b5741b64e4becb779db9dab17a86fcc58
push id28855
push userkwierso@gmail.com
push dateFri, 05 Jun 2015 01:19:30 +0000
treeherdermozilla-central@227d356ac030 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1162818
milestone41.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 1162818 part.3 nsEditor should store actual composition string length in it r=ehsan
editor/libeditor/nsEditor.cpp
editor/libeditor/nsEditor.h
--- a/editor/libeditor/nsEditor.cpp
+++ b/editor/libeditor/nsEditor.cpp
@@ -132,16 +132,17 @@ nsEditor::nsEditor()
 ,  mSelState(nullptr)
 ,  mPhonetic(nullptr)
 ,  mModCount(0)
 ,  mFlags(0)
 ,  mUpdateCount(0)
 ,  mPlaceHolderBatch(0)
 ,  mAction(EditAction::none)
 ,  mIMETextOffset(0)
+,  mIMETextLength(0)
 ,  mDirection(eNone)
 ,  mDocDirtyState(-1)
 ,  mSpellcheckCheckboxState(eTriUnset)
 ,  mShouldTxnSetSelection(true)
 ,  mDidPreDestroy(false)
 ,  mDidPostCreate(false)
 ,  mDispatchInputEvent(true)
 ,  mIsInEditAction(false)
@@ -2044,16 +2045,17 @@ nsEditor::EndIMEComposition()
       NS_ASSERTION(NS_SUCCEEDED(rv),
                    "nsIAbsorbingTransaction::Commit() failed");
     }
   }
 
   /* reset the data we need to construct a transaction */
   mIMETextNode = nullptr;
   mIMETextOffset = 0;
+  mIMETextLength = 0;
   mComposition->EndHandlingComposition(this);
   mComposition = nullptr;
 
   // notify editor observers of action
   NotifyEditorObservers(eNotifyEditorObserversOfEnd);
 }
 
 
@@ -2384,16 +2386,17 @@ nsEditor::InsertTextIntoTextNodeImpl(con
       }
       nsAutoString stringToInsert(aStringToInsert);
       stringToInsert.Mid(*mPhonetic,
                          textRange.mStartOffset, textRange.Length());
     }
 
     txn = CreateTxnForIMEText(aStringToInsert);
     isIMETransaction = true;
+    mIMETextLength = aStringToInsert.Length();
   } else {
     txn = CreateTxnForInsertText(aStringToInsert, aTextNode, aOffset);
   }
 
   // Let listeners know what's up
   for (auto& listener : mActionListeners) {
     listener->WillInsertText(
       static_cast<nsIDOMCharacterData*>(aTextNode.AsDOMNode()), aOffset,
@@ -4193,20 +4196,21 @@ nsEditor::CreateTxnForDeleteNode(nsINode
 
   txn.forget(aTxn);
   return NS_OK;
 }
 
 already_AddRefed<IMETextTxn>
 nsEditor::CreateTxnForIMEText(const nsAString& aStringToInsert)
 {
+  MOZ_ASSERT(mIMETextNode);
   // During handling IME composition, mComposition must have been initialized.
   // TODO: We can simplify IMETextTxn::Init() with TextComposition class.
   nsRefPtr<IMETextTxn> txn = new IMETextTxn(*mIMETextNode, mIMETextOffset,
-                                            mComposition->String().Length(),
+                                            mIMETextLength,
                                             mComposition->GetRanges(),
                                             aStringToInsert, *this);
   return txn.forget();
 }
 
 
 NS_IMETHODIMP
 nsEditor::CreateTxnForAddStyleSheet(CSSStyleSheet* aSheet, AddStyleSheetTxn* *aTxn)
--- a/editor/libeditor/nsEditor.h
+++ b/editor/libeditor/nsEditor.h
@@ -848,16 +848,19 @@ protected:
   uint32_t          mFlags;        // behavior flags. See nsIPlaintextEditor.idl for the flags we use.
 
   int32_t           mUpdateCount;
 
   int32_t           mPlaceHolderBatch;   // nesting count for batching
   EditAction        mAction;             // the current editor action
 
   uint32_t          mIMETextOffset;    // offset in text node where IME comp string begins
+  // The Length of the composition string or commit string.  If this is length
+  // of commit string, the length is truncated by maxlength attribute.
+  uint32_t          mIMETextLength;
 
   EDirection        mDirection;          // the current direction of editor action
   int8_t            mDocDirtyState;      // -1 = not initialized
   uint8_t           mSpellcheckCheckboxState; // a Tristate value
 
   bool mShouldTxnSetSelection;  // turn off for conservative selection adjustment by txns
   bool mDidPreDestroy;    // whether PreDestroy has been called
   bool mDidPostCreate;    // whether PostCreate has been called