Bug 1536366 - Make PresShell::EventHandler::PrepareToDispatchEvent() call TouchManager::PreHandleEvent() instead of PresShell::EventHandler::HandleEventWithCurrentEventInfo() r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 27 Mar 2019 01:08:23 +0000
changeset 466254 c972f777f7597630f1db8bebc17d0f399e1395c3
parent 466253 d0221689e8e9a720dca3bdc7f4c3371c09f6626c
child 466255 334d8f9c99957c9eef94ecf99437a0b8e7dda7c7
push id35762
push usercsabou@mozilla.com
push dateWed, 27 Mar 2019 04:44:00 +0000
treeherdermozilla-central@bc572aee49b6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1536366, 1536353
milestone68.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 1536366 - Make PresShell::EventHandler::PrepareToDispatchEvent() call TouchManager::PreHandleEvent() instead of PresShell::EventHandler::HandleEventWithCurrentEventInfo() r=smaug The only caller of `TouchManager::PreHandleEvent()` is `PresShell::EventHandler::HandleEventWithCurrentEventInfo()` which is guaranteed that it never handles untrused event by bug 1536353. Therefore, we can make `PresShell::EventHandler::PrepareToDispatchEvent()` call it instead. That's better place from the point of view of semantics and making `PresShell::EventHandler::PrepareToDispatchEvent()` simpler. Note that this may cause changing the score of a telemetry probe, "INPUT_EVENT_QUEUED_APZ_TOUCH_MOVE_MS" because it will include the time of the runtime cost of `TouchManager::PreHandleEvent()` when the event is an `eTouchMove` event and handled by APZ. However, this was expired in 60. So, we don't meet any changes with this patch actually. Differential Revision: https://phabricator.services.mozilla.com/D24133
layout/base/PresShell.cpp
layout/base/PresShell.h
layout/base/TouchManager.cpp
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -7662,33 +7662,26 @@ nsresult PresShell::EventHandler::Handle
     nsFocusManager* fm = nsFocusManager::GetFocusManager();
     if (fm) {
       // This may run script now.  So, mPresShell might be destroyed after here.
       fm->FlushBeforeEventHandlingIfNeeded(mPresShell->mCurrentEventContent);
     }
   }
 
   bool isHandlingUserInput = false;
-  if (!PrepareToDispatchEvent(aEvent, &isHandlingUserInput)) {
+  bool touchIsNew = false;
+  if (!PrepareToDispatchEvent(aEvent, aEventStatus, &isHandlingUserInput,
+                              &touchIsNew)) {
     return NS_OK;
   }
 
   // We finished preparing to dispatch the event.  So, let's record the
   // performance.
   RecordEventPreparationPerformance(aEvent);
 
-  // XXX Why don't we measure the performance of TouchManager::PreHandleEvent()
-  //     with RecordEventPreparationPerformance()?
-  bool touchIsNew = false;
-  if (!mPresShell->mTouchManager.PreHandleEvent(
-          aEvent, aEventStatus, touchIsNew, isHandlingUserInput,
-          mPresShell->mCurrentEventContent)) {
-    return NS_OK;
-  }
-
   AutoHandlingUserInputStatePusher userInpStatePusher(isHandlingUserInput,
                                                       aEvent, GetDocument());
 
   nsAutoPopupStatePusher popupStatePusher(
       PopupBlocker::GetEventPopupControlState(aEvent));
 
   // FIXME. If the event was reused, we need to clear the old target,
   // bug 329430
@@ -7788,21 +7781,25 @@ nsresult PresShell::EventHandler::Dispat
   //    generation of synthetic events.
   // Refetch the prescontext, in case it changed.
   RefPtr<nsPresContext> presContext = GetPresContext();
   return aEventStateManager->PostHandleEvent(
       presContext, aEvent, mPresShell->GetCurrentEventFrame(), aEventStatus,
       aOverrideClickTarget);
 }
 
-bool PresShell::EventHandler::PrepareToDispatchEvent(WidgetEvent* aEvent,
-                                                     bool* aIsUserInteraction) {
+bool PresShell::EventHandler::PrepareToDispatchEvent(
+    WidgetEvent* aEvent, nsEventStatus* aEventStatus, bool* aIsUserInteraction,
+    bool* aTouchIsNew) {
   MOZ_ASSERT(aEvent->IsTrusted());
+  MOZ_ASSERT(aEventStatus);
   MOZ_ASSERT(aIsUserInteraction);
-
+  MOZ_ASSERT(aTouchIsNew);
+
+  *aTouchIsNew = false;
   if (aEvent->IsUserAction()) {
     mPresShell->mHasHandledUserInput = true;
   }
 
   switch (aEvent->mMessage) {
     case eKeyPress:
     case eKeyDown:
     case eKeyUp: {
@@ -7858,16 +7855,24 @@ bool PresShell::EventHandler::PrepareToD
       // In this case, we don't fire "contextmenu" event on web content because
       // of not cancelable.
       if (mouseEvent->IsShift()) {
         aEvent->mFlags.mOnlyChromeDispatch = true;
         aEvent->mFlags.mRetargetToNonNativeAnonymous = true;
       }
       return true;
     }
+    case eTouchStart:
+    case eTouchMove:
+    case eTouchEnd:
+    case eTouchCancel:
+    case eTouchPointerCancel:
+      return mPresShell->mTouchManager.PreHandleEvent(
+          aEvent, aEventStatus, *aTouchIsNew, *aIsUserInteraction,
+          mPresShell->mCurrentEventContent);
     default:
       *aIsUserInteraction = false;
       return true;
   }
 }
 
 void PresShell::EventHandler::FinalizeHandlingEvent(WidgetEvent* aEvent) {
   switch (aEvent->mMessage) {
--- a/layout/base/PresShell.h
+++ b/layout/base/PresShell.h
@@ -1096,25 +1096,31 @@ class PresShell final : public nsIPresSh
      * @param aEvent            The handled event.
      */
     void RecordEventHandlingResponsePerformance(const WidgetEvent* aEvent);
 
     /**
      * PrepareToDispatchEvent() prepares to dispatch aEvent.
      *
      * @param aEvent                    The handling event.
+     * @param aEventStatus              [in/out] The status of aEvent.
      * @param aIsUserInteraction        [out] Set to true if the event is user
      *                                  interaction.  I.e., enough obvious input
      *                                  to allow to open popup, etc.  Otherwise,
      *                                  set to false.
+     * @param aTouchIsNew               [out] Set to true if the event is an
+     *                                  eTouchMove event and it represents new
+     *                                  touch.  Otherwise, set to false.
      * @return                          true if the caller can dispatch the
      *                                  event into the DOM.
      */
     MOZ_CAN_RUN_SCRIPT
-    bool PrepareToDispatchEvent(WidgetEvent* aEvent, bool* aIsUserInteraction);
+    bool PrepareToDispatchEvent(WidgetEvent* aEvent,
+                                nsEventStatus* aEventStatus,
+                                bool* aIsUserInteraction, bool* aTouchIsNew);
 
     /**
      * MaybeHandleKeyboardEventBeforeDispatch() may handle aKeyboardEvent
      * if it should do something before dispatched into the DOM.
      *
      * @param aKeyboardEvent    The handling keyboard event.
      */
     MOZ_CAN_RUN_SCRIPT
--- a/layout/base/TouchManager.cpp
+++ b/layout/base/TouchManager.cpp
@@ -218,20 +218,20 @@ nsIFrame* TouchManager::SuppressInvalidP
     }
   }
   return frame;
 }
 
 bool TouchManager::PreHandleEvent(WidgetEvent* aEvent, nsEventStatus* aStatus,
                                   bool& aTouchIsNew, bool& aIsHandlingUserInput,
                                   nsCOMPtr<nsIContent>& aCurrentEventContent) {
-  if (!aEvent->IsTrusted()) {
-    return true;
-  }
+  MOZ_DIAGNOSTIC_ASSERT(aEvent->IsTrusted());
 
+  // NOTE: If you need to handle new event messages here, you need to add new
+  //       cases in PresShell::EventHandler::PrepareToDispatchEvent().
   switch (aEvent->mMessage) {
     case eTouchStart: {
       aIsHandlingUserInput = true;
       WidgetTouchEvent* touchEvent = aEvent->AsTouchEvent();
       // if there is only one touch in this touchstart event, assume that it is
       // the start of a new touch session and evict any old touches in the
       // queue
       if (touchEvent->mTouches.Length() == 1) {