Bug 1466208 - part 26: Create PresShell::EventHandler::EventTargetData::UpdateTouchEventTarget() r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 02 Mar 2019 00:02:10 +0000
changeset 520015 a6fd8376d3ec14c2fb5eacb4720d97813b0e28e9
parent 519964 4166cae81546f54accae807413f806d20bf30920
child 520016 06b992be418341f5eb3051405826a812dc4a5b27
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 26: Create PresShell::EventHandler::EventTargetData::UpdateTouchEventTarget() r=smaug After dispatching pointer events, `PresShell::EventHandler::HandleEvent()` updates event target only when the event is a touch event. We should do it in a new method of `EventTargetData`. Although I don't know why this is done in `PresShell::EventHandler::DispatchPrecedingPointerEvent()`. Differential Revision: https://phabricator.services.mozilla.com/D21192
layout/base/PresShell.cpp
layout/base/PresShell.h
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -6654,32 +6654,20 @@ nsresult PresShell::EventHandler::Handle
     // automatically updated.
     if (!DispatchPrecedingPointerEvent(
             aFrame, aGUIEvent, pointerCapturingContent, aDontRetargetEvents,
             &eventTargetData, aEventStatus)) {
       return NS_OK;
     }
 
     // frame could be null after dispatching pointer events.
-    if (aGUIEvent->mClass == eTouchEventClass) {
-      if (aGUIEvent->mMessage == eTouchStart) {
-        WidgetTouchEvent* touchEvent = aGUIEvent->AsTouchEvent();
-        if (nsIFrame* newFrame =
-                TouchManager::SuppressInvalidPointsAndGetTargetedFrame(
-                    touchEvent)) {
-          eventTargetData.SetFrameAndComputePresShellAndContent(newFrame,
-                                                                aGUIEvent);
-        }
-      } else if (PresShell* newShell =
-                     PresShell::GetShellForTouchEvent(aGUIEvent)) {
-        // Touch events (except touchstart) are dispatching to the captured
-        // element. Get correct shell from it.
-        eventTargetData.mPresShell = newShell;
-      }
-    }
+    // XXX Despite of this comment, we update the event target data outside
+    //     DispatchPrecedingPointerEvent().  Can we make it call
+    //     UpdateTouchEventTarget()?
+    eventTargetData.UpdateTouchEventTarget(aGUIEvent);
 
     // Handle the event in the correct shell.
     // We pass the subshell's root frame as the frame to start from. This is
     // the only correct alternative; if the event was captured then it
     // must have been captured by us or some ancestor shell and we
     // now ask the subshell to dispatch it normally.
     eventTargetData.mPresShell->PushCurrentEventInfo(eventTargetData.mFrame,
                                                      eventTargetData.mContent);
@@ -10860,8 +10848,37 @@ bool PresShell::EventHandler::EventTarge
   while (content && !content->IsElement()) {
     content = content->GetFlattenedTreeParent();
   }
   mContent = content;
 
   // If we found an element, target it.  Otherwise, target *nothing*.
   return !!mContent;
 }
+
+void PresShell::EventHandler::EventTargetData::UpdateTouchEventTarget(
+    WidgetGUIEvent* aGUIEvent) {
+  MOZ_ASSERT(aGUIEvent);
+
+  if (aGUIEvent->mClass != eTouchEventClass) {
+    return;
+  }
+
+  if (aGUIEvent->mMessage == eTouchStart) {
+    WidgetTouchEvent* touchEvent = aGUIEvent->AsTouchEvent();
+    nsIFrame* newFrame =
+        TouchManager::SuppressInvalidPointsAndGetTargetedFrame(touchEvent);
+    if (!newFrame) {
+      return;  // XXX Why don't we stop handling the event in this case?
+    }
+    SetFrameAndComputePresShellAndContent(newFrame, aGUIEvent);
+    return;
+  }
+
+  PresShell* newPresShell = PresShell::GetShellForTouchEvent(aGUIEvent);
+  if (!newPresShell) {
+    return;  // XXX Why don't we stop handling the event in this case?
+  }
+
+  // Touch events (except touchstart) are dispatching to the captured
+  // element. Get correct shell from it.
+  mPresShell = newPresShell;
+}
--- a/layout/base/PresShell.h
+++ b/layout/base/PresShell.h
@@ -634,16 +634,25 @@ class PresShell final : public nsIPresSh
        * @param aGUIEvent       The handling event.
        * @return                true if caller can keep handling the event.
        *                        Otherwise, false.
        *                        Note that even if this returns true, mContent
        *                        may be nullptr.
        */
       bool ComputeElementFromFrame(WidgetGUIEvent* aGUIEvent);
 
+      /**
+       * UpdateTouchEventTarget() updates mFrame, mPresShell and mContent if
+       * aGUIEvent is a touch event and there is new proper target.
+       *
+       * @param aGUIEvent       The handled event.  If it's not a touch event,
+       *                        this method does nothing.
+       */
+      void UpdateTouchEventTarget(WidgetGUIEvent* aGUIEvent);
+
       RefPtr<PresShell> mPresShell;
       nsIFrame* mFrame;
       nsCOMPtr<nsIContent> mContent;
       nsCOMPtr<nsIContent> mOverrideClickTarget;
     };
 
     /**
      * MaybeFlushPendingNotifications() maybe flush pending notifications if