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
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 16 Sep 2015 17:48:24 +0900
changeset 295375 46046fcbf40ff4b11330f0dd6150b740f4cd39dc
parent 295374 3a37db144dcd1f23d0d8d87c3f48a7fb94f27fed
child 295376 34606afcc726979bbbc8d5e1b8841fa7865d5f67
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1203381
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
dom/events/IMEContentObserver.h
--- a/dom/events/IMEContentObserver.cpp
+++ b/dom/events/IMEContentObserver.cpp
@@ -224,16 +224,17 @@ IMEContentObserver::IMEContentObserver()
   , mSendingNotification(NOTIFY_IME_OF_NOTHING)
   , mIsObserving(false)
   , mIMEHasFocus(false)
   , mIsFocusEventPending(false)
   , mIsTextChangeEventPending(false)
   , mIsSelectionChangeEventPending(false)
   , mIsPositionChangeEventPending(false)
   , mIsFlushingPendingNotifications(false)
+  , mIsHandlingQueryContentEvent(false)
 {
 #ifdef DEBUG
   mTextChangeData.Test();
 #endif
   if (!sIMECOLog) {
     sIMECOLog = PR_NewLogModule("IMEContentObserver");
   }
 }
@@ -587,20 +588,16 @@ IMEContentObserver::ReflowInterruptible(
 {
   MaybeNotifyIMEOfPositionChange();
   return NS_OK;
 }
 
 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 &&
       mSelectionData.IsValid()) {
     aEvent->mReply.mContentsRoot = mRootContent;
     aEvent->mReply.mHasSelection = !mSelectionData.IsCollapsed();
     aEvent->mReply.mOffset = mSelectionData.mOffset;
     aEvent->mReply.mString = mSelectionData.String();
@@ -608,16 +605,22 @@ IMEContentObserver::HandleQueryContentEv
     aEvent->mReply.mReversed = mSelectionData.mReversed;
     aEvent->mSucceeded = true;
     MOZ_LOG(sIMECOLog, LogLevel::Debug,
       ("IMECO: 0x%p IMEContentObserver::HandleQueryContentEvent(aEvent={ "
        "mMessage=%s })", this, ToChar(aEvent->mMessage)));
     return NS_OK;
   }
 
+  MOZ_LOG(sIMECOLog, LogLevel::Debug,
+    ("IMECO: 0x%p IMEContentObserver::HandleQueryContentEvent(aEvent={ "
+     "mMessage=%s })", this, ToChar(aEvent->mMessage)));
+
+  AutoRestore<bool> handling(mIsHandlingQueryContentEvent);
+  mIsHandlingQueryContentEvent = true;
   ContentEventHandler handler(GetPresContext());
   nsresult rv = handler.HandleQueryContentEvent(aEvent);
   if (aEvent->mSucceeded) {
     // We need to guarantee that mRootContent should be always same value for
     // the observing editor.
     aEvent->mReply.mContentsRoot = mRootContent;
   }
   return rv;
@@ -1098,16 +1101,28 @@ IMEContentObserver::MaybeNotifyIMEOfSele
   FlushMergeableNotifications();
 }
 
 void
 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();
 }
 
 bool
 IMEContentObserver::UpdateSelectionCache()
 {
   MOZ_ASSERT(IsSafeToNotifyIME());
--- a/dom/events/IMEContentObserver.h
+++ b/dom/events/IMEContentObserver.h
@@ -253,16 +253,19 @@ private:
   bool mIsFocusEventPending;
   bool mIsTextChangeEventPending;
   bool mIsSelectionChangeEventPending;
   bool mIsPositionChangeEventPending;
   // mIsFlushingPendingNotifications is true between
   // FlushMergeableNotifications() creates IMENotificationSender and
   // IMENotificationSender sent all pending notifications.
   bool mIsFlushingPendingNotifications;
+  // mIsHandlingQueryContentEvent is true when IMEContentObserver is handling
+  // WidgetQueryContentEvent with ContentEventHandler.
+  bool mIsHandlingQueryContentEvent;
 
 
   /**
    * Helper classes to notify IME.
    */
 
   class AChangeEvent: public nsRunnable
   {