Bug 1189396 part.2 Implement IMENotification::SelectionChangeData::Assign() to copy its members r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 22 Aug 2015 01:43:41 +0900
changeset 291464 f99e7dec5a4f5ca54d0562431bc67bdbff8a7695
parent 291463 1f6713554675c6a655b0229b1e44decaf33ae0d2
child 291465 c5f78184538a0ce83186948a8983344318755556
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1189396
milestone43.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 1189396 part.2 Implement IMENotification::SelectionChangeData::Assign() to copy its members r=smaug
widget/IMEData.h
--- a/widget/IMEData.h
+++ b/widget/IMEData.h
@@ -426,24 +426,27 @@ struct IMENotification final
         mMouseButtonEventData.mModifiers = 0;
       default:
         break;
     }
   }
 
   void Assign(const IMENotification& aOther)
   {
-    Clear();
-    mMessage = aOther.mMessage;
+    bool changingMessage = mMessage != aOther.mMessage;
+    if (changingMessage) {
+      Clear();
+      mMessage = aOther.mMessage;
+    }
     switch (mMessage) {
       case NOTIFY_IME_OF_SELECTION_CHANGE:
-        mSelectionChangeData = aOther.mSelectionChangeData;
-        // mString should be different instance because of ownership issue.
-        mSelectionChangeData.mString =
-          new nsString(aOther.mSelectionChangeData.String());
+        if (changingMessage) {
+          mSelectionChangeData.mString = new nsString();
+        }
+        mSelectionChangeData.Assign(aOther.mSelectionChangeData);
         break;
       case NOTIFY_IME_OF_TEXT_CHANGE:
         mTextChangeData = aOther.mTextChangeData;
         break;
       case NOTIFY_IME_OF_MOUSE_BUTTON_EVENT:
         mMouseButtonEventData = aOther.mMouseButtonEventData;
         break;
       default:
@@ -476,40 +479,17 @@ struct IMENotification final
   {
     switch (mMessage) {
       case NOTIFY_IME_OF_NOTHING:
         MOZ_ASSERT(aNotification.mMessage != NOTIFY_IME_OF_NOTHING);
         Assign(aNotification);
         break;
       case NOTIFY_IME_OF_SELECTION_CHANGE:
         MOZ_ASSERT(aNotification.mMessage == NOTIFY_IME_OF_SELECTION_CHANGE);
-        mSelectionChangeData.mOffset =
-          aNotification.mSelectionChangeData.mOffset;
-        *mSelectionChangeData.mString =
-          aNotification.mSelectionChangeData.String();
-        mSelectionChangeData.mWritingMode =
-          aNotification.mSelectionChangeData.mWritingMode;
-        mSelectionChangeData.mReversed =
-          aNotification.mSelectionChangeData.mReversed;
-        if (!mSelectionChangeData.mCausedByComposition) {
-          mSelectionChangeData.mCausedByComposition =
-            aNotification.mSelectionChangeData.mCausedByComposition;
-        } else {
-          mSelectionChangeData.mCausedByComposition =
-            mSelectionChangeData.mCausedByComposition &&
-              aNotification.mSelectionChangeData.mCausedByComposition;
-        }
-        if (!mSelectionChangeData.mCausedBySelectionEvent) {
-          mSelectionChangeData.mCausedBySelectionEvent =
-            aNotification.mSelectionChangeData.mCausedBySelectionEvent;
-        } else {
-          mSelectionChangeData.mCausedBySelectionEvent =
-            mSelectionChangeData.mCausedBySelectionEvent &&
-              aNotification.mSelectionChangeData.mCausedBySelectionEvent;
-        }
+        mSelectionChangeData.Assign(aNotification.mSelectionChangeData);
         break;
       case NOTIFY_IME_OF_TEXT_CHANGE:
         MOZ_ASSERT(aNotification.mMessage == NOTIFY_IME_OF_TEXT_CHANGE);
         mTextChangeData += aNotification.mTextChangeData;
         break;
       case NOTIFY_IME_OF_POSITION_CHANGE:
       case NOTIFY_IME_OF_COMPOSITION_UPDATE:
         MOZ_ASSERT(aNotification.mMessage == mMessage);
@@ -605,16 +585,25 @@ struct IMENotification final
       mReversed = false;
       mCausedByComposition = false;
       mCausedBySelectionEvent = false;
     }
     bool IsValid() const
     {
       return mOffset != UINT32_MAX;
     }
+    void Assign(const SelectionChangeData& aOther)
+    {
+      mOffset = aOther.mOffset;
+      *mString = aOther.String();
+      mWritingMode = aOther.mWritingMode;
+      mReversed = aOther.mReversed;
+      mCausedByComposition = aOther.mCausedByComposition;
+      mCausedBySelectionEvent = aOther.mCausedBySelectionEvent;
+    }
   };
 
   struct TextChangeDataBase
   {
     // mStartOffset is the start offset of modified or removed text in
     // original content and inserted text in new content.
     uint32_t mStartOffset;
     // mRemovalEndOffset is the end offset of modified or removed text in