Bug 1466208 - part 23: Create PresShell::EventHandler::ComputeEventTargetFrameAndPresShellAtEventPoint() r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 27 Feb 2019 13:59:30 +0000
changeset 519472 37f52c22967c6e4354ca3fdb1599970ffe30e8c8
parent 519471 02de7c233aaa50c41935db835a31835115df7b99
child 519473 28bc841f06fc5f4d01defbacc80e017f701a8d57
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1466208
milestone67.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 1466208 - part 23: Create PresShell::EventHandler::ComputeEventTargetFrameAndPresShellAtEventPoint() r=smaug We cannot move each block into separated methods while computing EventTargetData because we need to check capturing contents, etc. Therefore, only each block should be moved to separated methods for now. This moves a block which computes event target from point of the event. If this can be moved to EventTargetData, it might be easier to understand, but its helper method GetFrameToHandleNonTouchEvent() requires to access members of EventHandler. Therefore, we need to treat EventTargetData as an out param of the new method. Differential Revision: https://phabricator.services.mozilla.com/D21189
layout/base/PresShell.cpp
layout/base/PresShell.h
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -6587,26 +6587,20 @@ nsresult PresShell::EventHandler::Handle
     // Get the frame at the event point. However, don't do this if we're
     // capturing and retargeting the event because the captured frame will
     // be used instead below. Also keep using the root frame if we're dealing
     // with a window-level mouse exit event since we want to start sending
     // mouse out events at the root EventStateManager.
     EventTargetData eventTargetData(mPresShell, rootFrameToHandleEvent);
     if (!isCaptureRetargeted && !isWindowLevelMouseExit &&
         !pointerCapturingContent) {
-      if (aGUIEvent->mClass == eTouchEventClass) {
-        eventTargetData.SetFrameAndComputePresShell(TouchManager::SetupTarget(
-            aGUIEvent->AsTouchEvent(), rootFrameToHandleEvent));
-      } else {
-        eventTargetData.SetFrameAndComputePresShell(
-            GetFrameToHandleNonTouchEvent(rootFrameToHandleEvent, aGUIEvent));
-        if (!eventTargetData.mFrame) {
-          *aEventStatus = nsEventStatus_eIgnore;
-          return NS_OK;
-        }
+      if (!ComputeEventTargetFrameAndPresShellAtEventPoint(
+              rootFrameToHandleEvent, aGUIEvent, &eventTargetData)) {
+        *aEventStatus = nsEventStatus_eIgnore;
+        return NS_OK;
       }
     }
 
     // if a node is capturing the mouse, check if the event needs to be
     // retargeted at the capturing content instead. This will be the case when
     // capture retargeting is being used, no frame was found or the frame's
     // content is not a descendant of the capturing content.
     if (capturingContent && !pointerCapturingContent &&
@@ -6920,16 +6914,36 @@ nsIFrame* PresShell::EventHandler::GetFr
 
   // Finally, we need to recompute the target with the latest layout.
   targetFrame = FindFrameTargetedByInputEvent(
       aGUIEvent, aRootFrameToHandleEvent, eventPoint, flags);
 
   return targetFrame ? targetFrame : aRootFrameToHandleEvent;
 }
 
+bool PresShell::EventHandler::ComputeEventTargetFrameAndPresShellAtEventPoint(
+    nsIFrame* aRootFrameToHandleEvent, WidgetGUIEvent* aGUIEvent,
+    EventTargetData* aEventTargetData) {
+  MOZ_ASSERT(aRootFrameToHandleEvent);
+  MOZ_ASSERT(aGUIEvent);
+  MOZ_ASSERT(aEventTargetData);
+
+  if (aGUIEvent->mClass == eTouchEventClass) {
+    nsIFrame* targetFrameAtTouchEvent = TouchManager::SetupTarget(
+        aGUIEvent->AsTouchEvent(), aRootFrameToHandleEvent);
+    aEventTargetData->SetFrameAndComputePresShell(targetFrameAtTouchEvent);
+    return true;
+  }
+
+  nsIFrame* targetFrame =
+      GetFrameToHandleNonTouchEvent(aRootFrameToHandleEvent, aGUIEvent);
+  aEventTargetData->SetFrameAndComputePresShell(targetFrame);
+  return !!aEventTargetData->mFrame;
+}
+
 bool PresShell::EventHandler::MaybeHandleEventWithAccessibleCaret(
     WidgetGUIEvent* aGUIEvent, nsEventStatus* aEventStatus) {
   MOZ_ASSERT(aGUIEvent);
   MOZ_ASSERT(aEventStatus);
 
   // Don't dispatch event to AccessibleCaretEventHub when the event status
   // is nsEventStatus_eConsumeNoDefault. This might be happened when content
   // preventDefault on the pointer events. In such case, we also call
--- a/layout/base/PresShell.h
+++ b/layout/base/PresShell.h
@@ -666,16 +666,33 @@ class PresShell final : public nsIPresSh
      *                                  event.  nullptr if the caller should
      *                                  stop handling the event.
      */
     MOZ_CAN_RUN_SCRIPT
     nsIFrame* GetFrameToHandleNonTouchEvent(nsIFrame* aRootFrameToHandleEvent,
                                             WidgetGUIEvent* aGUIEvent);
 
     /**
+     * ComputeEventTargetFrameAndPresShellAtEventPoint() computes event
+     * target frame at the event point of aGUIEvent and set it to
+     * aEventTargetData.
+     *
+     * @param aRootFrameToHandleEvent   The root frame to handle aGUIEvent.
+     * @param aGUIEvent                 The handling event.
+     * @param aEventTargetData          [out] Its frame and PresShell will
+     *                                  be set.
+     * @return                          true if the caller can handle the
+     *                                  event.  Otherwise, false.
+     */
+    MOZ_CAN_RUN_SCRIPT
+    bool ComputeEventTargetFrameAndPresShellAtEventPoint(
+        nsIFrame* aRootFrameToHandleEvent, WidgetGUIEvent* aGUIEvent,
+        EventTargetData* aEventTargetData);
+
+    /**
      * MaybeDiscardEvent() checks whether it's safe to handle aGUIEvent right
      * now.  If it's not safe, this may notify somebody of discarding event if
      * necessary.
      *
      * @param aGUIEvent   Handling event.
      * @return            true if it's not safe to handle the event.
      */
     bool MaybeDiscardEvent(WidgetGUIEvent* aGUIEvent);