Bug 1184449 part.1 IMENotifiation::SelectionChangeData should store selected string r=smaug

This commit is contained in:
Masayuki Nakano 2015-07-22 12:40:32 +09:00
parent 1b3d398131
commit 94b57ee7a6
6 changed files with 79 additions and 25 deletions

View File

@ -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;

View File

@ -795,7 +795,7 @@ PuppetWidget::NotifyIMEOfSelectionChange(
mContentCache.SetSelection(
this,
aIMENotification.mSelectionChangeData.mOffset,
aIMENotification.mSelectionChangeData.mLength,
aIMENotification.mSelectionChangeData.Length(),
aIMENotification.mSelectionChangeData.mReversed,
aIMENotification.mSelectionChangeData.GetWritingMode());

View File

@ -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();
}

View File

@ -707,8 +707,9 @@ struct ParamTraits<mozilla::widget::IMENotification::SelectionChangeData>
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<mozilla::widget::IMENotification::SelectionChangeData>
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) &&

View File

@ -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;
}
};

View File

@ -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());