diff --git a/dom/events/IMEContentObserver.cpp b/dom/events/IMEContentObserver.cpp index 011f9fe0603..5dd212945fe 100644 --- a/dom/events/IMEContentObserver.cpp +++ b/dom/events/IMEContentObserver.cpp @@ -1074,10 +1074,8 @@ IMEContentObserver::SelectionChangeEvent::Run() } IMENotification notification(NOTIFY_IME_OF_SELECTION_CHANGE); - notification.mSelectionChangeData.mOffset = - selection.mReply.mOffset; - notification.mSelectionChangeData.mLength = - selection.mReply.mString.Length(); + notification.mSelectionChangeData.mOffset = selection.mReply.mOffset; + *notification.mSelectionChangeData.mString = selection.mReply.mString; notification.mSelectionChangeData.SetWritingMode( selection.GetWritingMode()); notification.mSelectionChangeData.mReversed = selection.mReply.mReversed; diff --git a/widget/PuppetWidget.cpp b/widget/PuppetWidget.cpp index 897b5a936ad..5ffd9081612 100644 --- a/widget/PuppetWidget.cpp +++ b/widget/PuppetWidget.cpp @@ -795,7 +795,7 @@ PuppetWidget::NotifyIMEOfSelectionChange( mContentCache.SetSelection( this, aIMENotification.mSelectionChangeData.mOffset, - aIMENotification.mSelectionChangeData.mLength, + aIMENotification.mSelectionChangeData.Length(), aIMENotification.mSelectionChangeData.mReversed, aIMENotification.mSelectionChangeData.GetWritingMode()); diff --git a/widget/gtk/nsGtkIMModule.cpp b/widget/gtk/nsGtkIMModule.cpp index bcf3759653e..ae4a20c3c39 100644 --- a/widget/gtk/nsGtkIMModule.cpp +++ b/widget/gtk/nsGtkIMModule.cpp @@ -788,11 +788,11 @@ nsGtkIMModule::OnSelectionChange(nsWindow* aCaller, MOZ_LOG(gGtkIMLog, LogLevel::Info, ("GtkIMModule(%p): OnSelectionChange(aCaller=0x%p, aIMENotification={ " - "mSelectionChangeData={ mOffset=%u, mLength=%u, mReversed=%s, " + "mSelectionChangeData={ mOffset=%u, Length()=%u, mReversed=%s, " "mWritingMode=%s, mCausedByComposition=%s, mCausedBySelectionEvent=%s " "} }), mCompositionState=%s, mIsDeletingSurrounding=%s", this, aCaller, selectionChangeData.mOffset, - selectionChangeData.mLength, + selectionChangeData.Length(), GetBoolName(selectionChangeData.mReversed), GetWritingModeName(selectionChangeData.GetWritingMode()).get(), GetBoolName(selectionChangeData.mCausedByComposition), @@ -1854,7 +1854,7 @@ nsGtkIMModule::Selection::Assign(const IMENotification& aIMENotification) { MOZ_ASSERT(aIMENotification.mMessage == NOTIFY_IME_OF_SELECTION_CHANGE); mOffset = aIMENotification.mSelectionChangeData.mOffset; - mLength = aIMENotification.mSelectionChangeData.mLength; + mLength = aIMENotification.mSelectionChangeData.Length(); mWritingMode = aIMENotification.mSelectionChangeData.GetWritingMode(); } diff --git a/widget/nsGUIEventIPC.h b/widget/nsGUIEventIPC.h index bf7a091ccf8..a57ddd2b156 100644 --- a/widget/nsGUIEventIPC.h +++ b/widget/nsGUIEventIPC.h @@ -707,8 +707,9 @@ struct ParamTraits static void Write(Message* aMsg, const paramType& aParam) { + MOZ_RELEASE_ASSERT(aParam.mString); WriteParam(aMsg, aParam.mOffset); - WriteParam(aMsg, aParam.mLength); + WriteParam(aMsg, *aParam.mString); WriteParam(aMsg, aParam.mWritingMode); WriteParam(aMsg, aParam.mReversed); WriteParam(aMsg, aParam.mCausedByComposition); @@ -717,8 +718,9 @@ struct ParamTraits static bool Read(const Message* aMsg, void** aIter, paramType* aResult) { + aResult->mString = new nsString(); return ReadParam(aMsg, aIter, &aResult->mOffset) && - ReadParam(aMsg, aIter, &aResult->mLength) && + ReadParam(aMsg, aIter, aResult->mString) && ReadParam(aMsg, aIter, &aResult->mWritingMode) && ReadParam(aMsg, aIter, &aResult->mReversed) && ReadParam(aMsg, aIter, &aResult->mCausedByComposition) && diff --git a/widget/nsIWidget.h b/widget/nsIWidget.h index d48d9693ef5..a294d32a5ad 100644 --- a/widget/nsIWidget.h +++ b/widget/nsIWidget.h @@ -599,19 +599,29 @@ enum IMEMessage : IMEMessageType REQUEST_TO_CANCEL_COMPOSITION }; -struct IMENotification +struct IMENotification final { IMENotification() : mMessage(NOTIFY_IME_OF_NOTHING) {} + IMENotification(const IMENotification& aOther) + { + Assign(aOther); + } + + ~IMENotification() + { + Clear(); + } + MOZ_IMPLICIT IMENotification(IMEMessage aMessage) : mMessage(aMessage) { switch (aMessage) { case NOTIFY_IME_OF_SELECTION_CHANGE: mSelectionChangeData.mOffset = UINT32_MAX; - mSelectionChangeData.mLength = 0; + mSelectionChangeData.mString = new nsString(); mSelectionChangeData.mWritingMode = 0; mSelectionChangeData.mReversed = false; mSelectionChangeData.mCausedByComposition = false; @@ -633,8 +643,41 @@ struct IMENotification } } + void Assign(const IMENotification& aOther) + { + 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()); + break; + case NOTIFY_IME_OF_TEXT_CHANGE: + mTextChangeData = aOther.mTextChangeData; + break; + case NOTIFY_IME_OF_MOUSE_BUTTON_EVENT: + mMouseButtonEventData = aOther.mMouseButtonEventData; + break; + default: + break; + } + } + + IMENotification& operator=(const IMENotification& aOther) + { + Assign(aOther); + return *this; + } + void Clear() { + if (mMessage == NOTIFY_IME_OF_SELECTION_CHANGE) { + MOZ_ASSERT(mSelectionChangeData.mString); + delete mSelectionChangeData.mString; + mSelectionChangeData.mString = nullptr; + } mMessage = NOTIFY_IME_OF_NOTHING; } @@ -648,14 +691,14 @@ struct IMENotification switch (mMessage) { case NOTIFY_IME_OF_NOTHING: MOZ_ASSERT(aNotification.mMessage != NOTIFY_IME_OF_NOTHING); - *this = aNotification; + Assign(aNotification); break; case NOTIFY_IME_OF_SELECTION_CHANGE: MOZ_ASSERT(aNotification.mMessage == NOTIFY_IME_OF_SELECTION_CHANGE); mSelectionChangeData.mOffset = aNotification.mSelectionChangeData.mOffset; - mSelectionChangeData.mLength = - aNotification.mSelectionChangeData.mLength; + *mSelectionChangeData.mString = + aNotification.mSelectionChangeData.String(); mSelectionChangeData.mWritingMode = aNotification.mSelectionChangeData.mWritingMode; mSelectionChangeData.mReversed = @@ -733,7 +776,9 @@ struct IMENotification { // Selection range. uint32_t mOffset; - uint32_t mLength; + + // Selected string + nsString* mString; // Writing mode at the selection. uint8_t mWritingMode; @@ -747,15 +792,23 @@ struct IMENotification uint32_t StartOffset() const { - return mOffset + (mReversed ? mLength : 0); + return mOffset + (mReversed ? Length() : 0); } uint32_t EndOffset() const { - return mOffset + (mReversed ? 0 : mLength); + return mOffset + (mReversed ? 0 : Length()); + } + const nsString& String() const + { + return *mString; + } + uint32_t Length() const + { + return mString->Length(); } bool IsInInt32Range() const { - return mOffset + mLength <= INT32_MAX; + return mOffset + Length() <= INT32_MAX; } }; diff --git a/widget/windows/nsTextStore.cpp b/widget/windows/nsTextStore.cpp index 09341589fcb..f93f4ef0058 100644 --- a/widget/windows/nsTextStore.cpp +++ b/widget/windows/nsTextStore.cpp @@ -4436,11 +4436,12 @@ nsTextStore::OnSelectionChangeInternal(const IMENotification& aIMENotification) aIMENotification.mSelectionChangeData; MOZ_LOG(sTextStoreLog, LogLevel::Debug, ("TSF: 0x%p nsTextStore::OnSelectionChangeInternal(" - "aIMENotification={ mSelectionChangeData={ mOffset=%lu, mLength=%lu, " - "mReversed=%s, mWritingMode=%s, mCausedByComposition=%s, " - "mCausedBySelectionEvent=%s } }), mSink=0x%p, mSinkMask=%s, " - "mIsRecordingActionsWithoutLock=%s, mComposition.IsComposing()=%s", - this, selectionChangeData.mOffset, selectionChangeData.mLength, + "aIMENotification={ mSelectionChangeData={ mOffset=%lu, " + "Length()=%lu, mReversed=%s, mWritingMode=%s, " + "mCausedByComposition=%s, mCausedBySelectionEvent=%s } }), " + "mSink=0x%p, mSinkMask=%s, mIsRecordingActionsWithoutLock=%s, " + "mComposition.IsComposing()=%s", + this, selectionChangeData.mOffset, selectionChangeData.Length(), GetBoolName(selectionChangeData.mReversed), GetWritingModeName(selectionChangeData.GetWritingMode()).get(), GetBoolName(selectionChangeData.mCausedByComposition), @@ -4458,7 +4459,7 @@ nsTextStore::OnSelectionChangeInternal(const IMENotification& aIMENotification) mSelection.SetSelection( selectionChangeData.mOffset, - selectionChangeData.mLength, + selectionChangeData.Length(), selectionChangeData.mReversed, selectionChangeData.GetWritingMode());