Bug 1466208 - part 32: Create PresShell::EventHandler::HandleEventAtFocusedContent() and PresShell::EventHandler::HandleEventWithFrameForPresShell() r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 06 Mar 2019 06:03:31 +0000
changeset 520482 a52bca8b0dd5027e116400b9dfa69a3d53ba8cb6
parent 520481 6a337f6390227e9903c436e125a1d198c0d01781
child 520483 b8e5c1d19e24a94643360c610ef9a3f304dcbc11
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 32: Create PresShell::EventHandler::HandleEventAtFocusedContent() and PresShell::EventHandler::HandleEventWithFrameForPresShell() r=smaug The remaining part of `PresShell::EventHandler::HandleEvent()` does: 1. Handles the event at focused content. 2. Handles the event with given frame which is a frame for `mPresShell`. For making them clearer, this patch moves them into new methods. Differential Revision: https://phabricator.services.mozilla.com/D21197
layout/base/PresShell.cpp
layout/base/PresShell.h
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -6535,55 +6535,21 @@ nsresult PresShell::EventHandler::Handle
       // Keypress events in new blank tabs should not be completely thrown away.
       // Retarget them -- the parent chrome shell might make use of them.
       return RetargetEventToParent(aGUIEvent, aEventStatus);
     }
 
     return NS_OK;
   }
 
-  AutoCurrentEventInfoSetter eventInfoSetter(*this);
-
   if (aGUIEvent->IsTargetedAtFocusedContent()) {
-    mPresShell->mCurrentEventContent = nullptr;
-
-    RefPtr<Element> eventTargetElement =
-        ComputeFocusedEventTargetElement(aGUIEvent);
-
-    mPresShell->mCurrentEventFrame = nullptr;
-    if (eventTargetElement) {
-      nsresult rv = NS_OK;
-      if (MaybeHandleEventWithAnotherPresShell(eventTargetElement, aGUIEvent,
-                                               aEventStatus, &rv)) {
-        return rv;
-      }
-    }
-    mPresShell->mCurrentEventContent = eventTargetElement;
-
-    if (!mPresShell->GetCurrentEventContent() ||
-        !mPresShell->GetCurrentEventFrame() ||
-        InZombieDocument(mPresShell->mCurrentEventContent)) {
-      return RetargetEventToParent(aGUIEvent, aEventStatus);
-    }
-  } else {
-    mPresShell->mCurrentEventFrame = aFrame;
-  }
-
-  nsresult rv = NS_OK;
-  if (mPresShell->GetCurrentEventFrame()) {
-    nsCOMPtr<nsIContent> overrideClickTarget;  // Required due to bug  1506439
-    rv =
-        HandleEventInternal(aGUIEvent, aEventStatus, true, overrideClickTarget);
-  }
-
-#ifdef DEBUG
-  mPresShell->ShowEventTargetDebug();
-#endif
-
-  return rv;
+    return HandleEventAtFocusedContent(aGUIEvent, aEventStatus);
+  }
+
+  return HandleEventWithFrameForPresShell(aFrame, aGUIEvent, aEventStatus);
 }
 
 nsresult PresShell::EventHandler::HandleEventUsingCoordinates(
     nsIFrame* aFrameForPresShell, WidgetGUIEvent* aGUIEvent,
     nsEventStatus* aEventStatus, bool aDontRetargetEvents) {
   MOZ_ASSERT(aGUIEvent);
   MOZ_ASSERT(aGUIEvent->IsUsingCoordinates());
   MOZ_ASSERT(aEventStatus);
@@ -7447,16 +7413,56 @@ PresShell::EventHandler::HandleEventWith
 
   EventHandler eventHandlerForCapturingContent(
       std::move(presShellForCapturingContent));
   return eventHandlerForCapturingContent.HandleEventWithTarget(
       aGUIEvent, nullptr, aPointerCapturingContent, aEventStatus, true, nullptr,
       overrideClickTarget);
 }
 
+nsresult PresShell::EventHandler::HandleEventAtFocusedContent(
+    WidgetGUIEvent* aGUIEvent, nsEventStatus* aEventStatus) {
+  MOZ_ASSERT(aGUIEvent);
+  MOZ_ASSERT(aGUIEvent->IsTargetedAtFocusedContent());
+  MOZ_ASSERT(aEventStatus);
+
+  AutoCurrentEventInfoSetter eventInfoSetter(*this);
+
+  RefPtr<Element> eventTargetElement =
+      ComputeFocusedEventTargetElement(aGUIEvent);
+
+  mPresShell->mCurrentEventFrame = nullptr;
+  if (eventTargetElement) {
+    nsresult rv = NS_OK;
+    if (MaybeHandleEventWithAnotherPresShell(eventTargetElement, aGUIEvent,
+                                             aEventStatus, &rv)) {
+      return rv;
+    }
+  }
+
+  // If we cannot handle the event with mPresShell, let's try to handle it
+  // with parent PresShell.
+  mPresShell->mCurrentEventContent = eventTargetElement;
+  if (!mPresShell->GetCurrentEventContent() ||
+      !mPresShell->GetCurrentEventFrame() ||
+      InZombieDocument(mPresShell->mCurrentEventContent)) {
+    return RetargetEventToParent(aGUIEvent, aEventStatus);
+  }
+
+  nsCOMPtr<nsIContent> overrideClickTarget;  // Required due to bug  1506439
+  nsresult rv =
+      HandleEventInternal(aGUIEvent, aEventStatus, true, overrideClickTarget);
+
+#ifdef DEBUG
+  mPresShell->ShowEventTargetDebug();
+#endif
+
+  return rv;
+}
+
 Element* PresShell::EventHandler::ComputeFocusedEventTargetElement(
     WidgetGUIEvent* aGUIEvent) {
   MOZ_ASSERT(aGUIEvent);
   MOZ_ASSERT(aGUIEvent->IsTargetedAtFocusedContent());
 
   // key and IME related events go to the focused frame in this DOM window.
   nsPIDOMWindowOuter* window = GetDocument()->GetWindow();
   nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
@@ -7529,16 +7535,41 @@ bool PresShell::EventHandler::MaybeHandl
   }
 
   EventHandler eventHandler(std::move(eventTargetPresShell));
   *aRv = eventHandler.HandleRetargetedEvent(aGUIEvent, aEventStatus,
                                             aEventTargetElement);
   return true;
 }
 
+nsresult PresShell::EventHandler::HandleEventWithFrameForPresShell(
+    nsIFrame* aFrameForPresShell, WidgetGUIEvent* aGUIEvent,
+    nsEventStatus* aEventStatus) {
+  MOZ_ASSERT(aGUIEvent);
+  MOZ_ASSERT(!aGUIEvent->IsUsingCoordinates());
+  MOZ_ASSERT(!aGUIEvent->IsTargetedAtFocusedContent());
+  MOZ_ASSERT(aEventStatus);
+
+  AutoCurrentEventInfoSetter eventInfoSetter(*this, aFrameForPresShell,
+                                             nullptr);
+
+  nsresult rv = NS_OK;
+  if (mPresShell->GetCurrentEventFrame()) {
+    nsCOMPtr<nsIContent> overrideClickTarget;  // Required due to bug  1506439
+    rv =
+        HandleEventInternal(aGUIEvent, aEventStatus, true, overrideClickTarget);
+  }
+
+#ifdef DEBUG
+  mPresShell->ShowEventTargetDebug();
+#endif
+
+  return rv;
+}
+
 Document* PresShell::GetPrimaryContentDocument() {
   nsPresContext* context = GetPresContext();
   if (!context || !context->IsRoot()) {
     return nullptr;
   }
 
   nsCOMPtr<nsIDocShellTreeItem> shellAsTreeItem = context->GetDocShell();
   if (!shellAsTreeItem) {
--- a/layout/base/PresShell.h
+++ b/layout/base/PresShell.h
@@ -949,16 +949,27 @@ class PresShell final : public nsIPresSh
      *                                  HandeEventWithTraget().
      */
     MOZ_CAN_RUN_SCRIPT
     nsresult HandleEventWithPointerCapturingContentWithoutItsFrame(
         nsIFrame* aFrameForPresShell, WidgetGUIEvent* aGUIEvent,
         nsIContent* aPointerCapturingContent, nsEventStatus* aEventStatus);
 
     /**
+     * HandleEventAtFocusedContent() handles aGUIEvent at focused content.
+     *
+     * @param aGUIEvent         The handling event which should be handled at
+     *                          focused content.
+     * @param aEventStatus      [in/out] The event status of aGUIEvent.
+     */
+    MOZ_CAN_RUN_SCRIPT
+    nsresult HandleEventAtFocusedContent(WidgetGUIEvent* aGUIEvent,
+                                         nsEventStatus* aEventStatus);
+
+    /**
      * ComputeFocusedEventTargetElement() returns event target element for
      * aGUIEvent which should be handled with focused content.
      * This may set/unset sLastKeyDownEventTarget if necessary.
      *
      * @param aGUIEvent                 The handling event.
      * @return                          The element which should be the event
      *                                  target of aGUIEvent.
      */
@@ -1003,16 +1014,31 @@ class PresShell final : public nsIPresSh
         return NS_OK;
       }
       nsCOMPtr<nsIContent> overrideClickTarget;
       return HandleEventInternal(aGUIEvent, aEventStatus, true,
                                  overrideClickTarget);
     }
 
     /**
+     * HandleEventWithFrameForPresShell() handles aGUIEvent with the frame
+     * for mPresShell.
+     *
+     * @param aFrameForPresShell        The frame for mPresShell.
+     * @param aGUIEvent                 The handling event.  It shouldn't be
+     *                                  handled with using coordinates nor
+     *                                  handled at focused content.
+     * @param aEventStatus              [in/out] The status of aGUIEvent.
+     */
+    MOZ_CAN_RUN_SCRIPT
+    nsresult HandleEventWithFrameForPresShell(nsIFrame* aFrameForPresShell,
+                                              WidgetGUIEvent* aGUIEvent,
+                                              nsEventStatus* aEventStatus);
+
+    /**
      * XXX Needs better name.
      * HandleEventInternal() dispatches aEvent into the DOM tree and
      * notify EventStateManager of that.
      *
      * @param aEvent                    Event to be dispatched.
      * @param aEventStatus              [in/out] EventStatus of aEvent.
      * @param aIsHandlingNativeEvent    true if aGUIEvent represents a native
      *                                  event.