Bug 960871 part.5 Copy mRanges and related methods from WidgetTextEvent to WidgetCompositionEvent r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 07 Oct 2014 19:01:47 +0900
changeset 209140 97aa7fef7adc1c2f009df86a526aff937aa52ad9
parent 209139 279373ac52ffac806b4bf3f4856e43888daf9b4d
child 209141 5216b7b1e4e3115a11c126d4b52ecffff710f64c
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerssmaug
bugs960871
milestone35.0a1
Bug 960871 part.5 Copy mRanges and related methods from WidgetTextEvent to WidgetCompositionEvent r=smaug
widget/TextEvents.h
widget/nsGUIEventIPC.h
--- a/widget/TextEvents.h
+++ b/widget/TextEvents.h
@@ -315,22 +315,42 @@ public:
     return result;
   }
 
   // The composition string or the commit string.  If the instance is a
   // compositionstart event, this is initialized with selected text by
   // TextComposition automatically.
   nsString mData;
 
+  nsRefPtr<TextRangeArray> mRanges;
+
   void AssignCompositionEventData(const WidgetCompositionEvent& aEvent,
                                   bool aCopyTargets)
   {
     AssignGUIEventData(aEvent, aCopyTargets);
 
     mData = aEvent.mData;
+
+    // Currently, we don't need to copy the other members because they are
+    // for internal use only (not available from JS).
+  }
+
+  bool IsComposing() const
+  {
+    return mRanges && mRanges->IsComposing();
+  }
+
+  uint32_t TargetClauseOffset() const
+  {
+    return mRanges ? mRanges->TargetClauseOffset() : 0;
+  }
+
+  uint32_t RangeCount() const
+  {
+    return mRanges ? mRanges->Length() : 0;
   }
 };
 
 /******************************************************************************
  * mozilla::WidgetQueryContentEvent
  ******************************************************************************/
 
 class WidgetQueryContentEvent : public WidgetGUIEvent
--- a/widget/nsGUIEventIPC.h
+++ b/widget/nsGUIEventIPC.h
@@ -489,24 +489,43 @@ struct ParamTraits<mozilla::WidgetCompos
 {
   typedef mozilla::WidgetCompositionEvent paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
   {
     WriteParam(aMsg, static_cast<mozilla::WidgetGUIEvent>(aParam));
     WriteParam(aMsg, aParam.mSeqno);
     WriteParam(aMsg, aParam.mData);
+    bool hasRanges = !!aParam.mRanges;
+    WriteParam(aMsg, hasRanges);
+    if (hasRanges) {
+      WriteParam(aMsg, *aParam.mRanges.get());
+    }
   }
 
   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   {
-    return ReadParam(aMsg, aIter,
-                     static_cast<mozilla::WidgetGUIEvent*>(aResult)) &&
-           ReadParam(aMsg, aIter, &aResult->mSeqno) &&
-           ReadParam(aMsg, aIter, &aResult->mData);
+    bool hasRanges;
+    if (!ReadParam(aMsg, aIter,
+                   static_cast<mozilla::WidgetGUIEvent*>(aResult)) ||
+        !ReadParam(aMsg, aIter, &aResult->mSeqno) ||
+        !ReadParam(aMsg, aIter, &aResult->mData) ||
+        !ReadParam(aMsg, aIter, &hasRanges)) {
+      return false;
+    }
+
+    if (!hasRanges) {
+      aResult->mRanges = nullptr;
+    } else {
+      aResult->mRanges = new mozilla::TextRangeArray();
+      if (!ReadParam(aMsg, aIter, aResult->mRanges.get())) {
+        return false;
+      }
+    }
+    return true;
   }
 };
 
 template<>
 struct ParamTraits<mozilla::WidgetQueryContentEvent>
 {
   typedef mozilla::WidgetQueryContentEvent paramType;