From 5d27912b61867c7f435ac9ced057bb81a12415de Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Mon, 7 Feb 2022 22:33:38 +0000 Subject: [PATCH] Bug 1746104 - part 5-2: Add some utility methods to `IMENotification::SelectionChangeDataBase` r=m_kato Differential Revision: https://phabricator.services.mozilla.com/D137423 --- dom/events/IMEContentObserver.cpp | 15 +++++---------- widget/IMEData.cpp | 13 +++++++++++++ widget/IMEData.h | 14 ++++++++++++++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/dom/events/IMEContentObserver.cpp b/dom/events/IMEContentObserver.cpp index ab7c7219b898..285485d81f56 100644 --- a/dom/events/IMEContentObserver.cpp +++ b/dom/events/IMEContentObserver.cpp @@ -1286,13 +1286,10 @@ bool IMEContentObserver::UpdateSelectionCache(bool aRequireFlush /* = true */) { MOZ_ASSERT(querySelectedTextEvent.mReply->mOffsetAndData.isSome()); mFocusedWidget = querySelectedTextEvent.mReply->mFocusedWidget; - mSelectionData.mOffset = querySelectedTextEvent.mReply->StartOffset(); - *mSelectionData.mString = querySelectedTextEvent.mReply->DataRef(); - mSelectionData.SetWritingMode( - querySelectedTextEvent.mReply->WritingModeRef()); - mSelectionData.mReversed = querySelectedTextEvent.mReply->mReversed; + mSelectionData.Assign(querySelectedTextEvent); - // WARNING: Don't modify the reason of selection change here. + // WARNING: Don't set the reason of selection change here because it should be + // set the reason at sending the notification. MOZ_LOG(sIMECOLog, LogLevel::Debug, ("0x%p IMEContentObserver::UpdateSelectionCache(), " @@ -1788,10 +1785,8 @@ void IMEContentObserver::IMENotificationSender::SendSelectionChange() { // selection change. SelectionChangeData& newSelChangeData = observer->mSelectionData; if (lastSelChangeData.IsValid() && - lastSelChangeData.mOffset == newSelChangeData.mOffset && - lastSelChangeData.String() == newSelChangeData.String() && - lastSelChangeData.GetWritingMode() == newSelChangeData.GetWritingMode() && - lastSelChangeData.mReversed == newSelChangeData.mReversed) { + lastSelChangeData.EqualsRangeAndDirectionAndWritingMode( + newSelChangeData)) { MOZ_LOG(sIMECOLog, LogLevel::Debug, ("0x%p IMEContentObserver::IMENotificationSender::" "SendSelectionChange(), not notifying IME of " diff --git a/widget/IMEData.cpp b/widget/IMEData.cpp index 64c44ff51e67..88b02385b76e 100644 --- a/widget/IMEData.cpp +++ b/widget/IMEData.cpp @@ -4,9 +4,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "IMEData.h" + #include #include "gfxFontUtils.h" +#include "TextEvents.h" #include "mozilla/WritingModes.h" @@ -343,6 +345,17 @@ std::ostream& operator<<(std::ostream& aStream, * IMENotification::SelectionChangeDataBase ******************************************************************************/ +void IMENotification::SelectionChangeDataBase::Assign( + const WidgetQueryContentEvent& aQuerySelectedTextEvent) { + MOZ_ASSERT(aQuerySelectedTextEvent.mMessage == eQuerySelectedText); + MOZ_ASSERT(aQuerySelectedTextEvent.Succeeded()); + + mOffset = aQuerySelectedTextEvent.mReply->StartOffset(); + *mString = aQuerySelectedTextEvent.mReply->DataRef(); + SetWritingMode(aQuerySelectedTextEvent.mReply->WritingModeRef()); + mReversed = aQuerySelectedTextEvent.mReply->mReversed; +} + void IMENotification::SelectionChangeDataBase::SetWritingMode( const WritingMode& aWritingMode) { mWritingModeBits = aWritingMode.GetBits(); diff --git a/widget/IMEData.h b/widget/IMEData.h index a83de0df483a..d73b3e003d6a 100644 --- a/widget/IMEData.h +++ b/widget/IMEData.h @@ -793,6 +793,7 @@ struct IMENotification final { AssignReason(aOther.mCausedByComposition, aOther.mCausedBySelectionEvent, aOther.mOccurredDuringComposition); } + void Assign(const WidgetQueryContentEvent& aQuerySelectedTextEvent); void AssignReason(bool aCausedByComposition, bool aCausedBySelectionEvent, bool aOccurredDuringComposition) { mCausedByComposition = aCausedByComposition; @@ -800,6 +801,19 @@ struct IMENotification final { mOccurredDuringComposition = aOccurredDuringComposition; } + bool EqualsRange(const SelectionChangeDataBase& aOther) const { + MOZ_ASSERT(IsValid()); + return mOffset == aOther.mOffset && mString->Equals(*aOther.mString); + } + bool EqualsRangeAndDirection(const SelectionChangeDataBase& aOther) const { + return EqualsRange(aOther) && mReversed == aOther.mReversed; + } + bool EqualsRangeAndDirectionAndWritingMode( + const SelectionChangeDataBase& aOther) const { + return EqualsRangeAndDirection(aOther) && + mWritingModeBits == aOther.mWritingModeBits; + } + OffsetAndData ToUint32OffsetAndData() const { return OffsetAndData(mOffset, *mString, OffsetAndDataFor::SelectedString);