From c86595d5c286deadd742d2c5f884c555fcc90ce6 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Wed, 16 Sep 2015 17:48:24 +0900 Subject: [PATCH] Bug 1203381 part.6 IMEContentObserver shouldn't post position change event if Reflow() is called during handling a query content event and sending NOTIFY_IME_OF_POSITION_CHANGE since the result of query content event includes the latest layout information r=smaug --- dom/events/IMEContentObserver.cpp | 23 +++++++++++++++++++---- dom/events/IMEContentObserver.h | 3 +++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/dom/events/IMEContentObserver.cpp b/dom/events/IMEContentObserver.cpp index b786ca96619a..2e771c453a8c 100644 --- a/dom/events/IMEContentObserver.cpp +++ b/dom/events/IMEContentObserver.cpp @@ -229,6 +229,7 @@ IMEContentObserver::IMEContentObserver() , mIsSelectionChangeEventPending(false) , mIsPositionChangeEventPending(false) , mIsFlushingPendingNotifications(false) + , mIsHandlingQueryContentEvent(false) { #ifdef DEBUG mTextChangeData.Test(); @@ -592,10 +593,6 @@ IMEContentObserver::ReflowInterruptible(DOMHighResTimeStamp aStart, nsresult IMEContentObserver::HandleQueryContentEvent(WidgetQueryContentEvent* aEvent) { - MOZ_LOG(sIMECOLog, LogLevel::Debug, - ("IMECO: 0x%p IMEContentObserver::HandleQueryContentEvent(aEvent={ " - "mMessage=%s })", this, ToChar(aEvent->mMessage))); - // If the instance has cache, it should use the cached selection which was // sent to the widget. if (aEvent->mMessage == eQuerySelectedText && aEvent->mUseNativeLineBreak && @@ -613,6 +610,12 @@ IMEContentObserver::HandleQueryContentEvent(WidgetQueryContentEvent* aEvent) return NS_OK; } + MOZ_LOG(sIMECOLog, LogLevel::Debug, + ("IMECO: 0x%p IMEContentObserver::HandleQueryContentEvent(aEvent={ " + "mMessage=%s })", this, ToChar(aEvent->mMessage))); + + AutoRestore handling(mIsHandlingQueryContentEvent); + mIsHandlingQueryContentEvent = true; ContentEventHandler handler(GetPresContext()); nsresult rv = handler.HandleQueryContentEvent(aEvent); if (aEvent->mSucceeded) { @@ -1103,6 +1106,18 @@ IMEContentObserver::MaybeNotifyIMEOfPositionChange() { MOZ_LOG(sIMECOLog, LogLevel::Debug, ("IMECO: 0x%p IMEContentObserver::MaybeNotifyIMEOfPositionChange()", this)); + // If reflow is caused by ContentEventHandler during PositionChangeEvent + // sending NOTIFY_IME_OF_POSITION_CHANGE, we don't need to notify IME of it + // again since ContentEventHandler returns the result including this reflow's + // result. + if (mIsHandlingQueryContentEvent && + mSendingNotification == NOTIFY_IME_OF_POSITION_CHANGE) { + MOZ_LOG(sIMECOLog, LogLevel::Debug, + ("IMECO: 0x%p IMEContentObserver::MaybeNotifyIMEOfPositionChange(), " + "ignored since caused by ContentEventHandler during sending " + "NOTIY_IME_OF_POSITION_CHANGE", this)); + return; + } PostPositionChangeNotification(); FlushMergeableNotifications(); } diff --git a/dom/events/IMEContentObserver.h b/dom/events/IMEContentObserver.h index de829d2e5b94..1f7a0cd2ad19 100644 --- a/dom/events/IMEContentObserver.h +++ b/dom/events/IMEContentObserver.h @@ -258,6 +258,9 @@ private: // FlushMergeableNotifications() creates IMENotificationSender and // IMENotificationSender sent all pending notifications. bool mIsFlushingPendingNotifications; + // mIsHandlingQueryContentEvent is true when IMEContentObserver is handling + // WidgetQueryContentEvent with ContentEventHandler. + bool mIsHandlingQueryContentEvent; /**