Bug 1466208 - part 43: Create PresShell::EventHandler::FinalizeHandlingEvent() r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 11 Mar 2019 01:52:40 +0000
changeset 521448 8620e56a5f3858391b42f51684ff735699895049
parent 521447 10e9bbf2d1df3b261a86356d3e9e15da962a9568
child 521449 d8098dde10d83f0f9b37bda5ffd37a42317d15b3
push id10866
push usernerli@mozilla.com
push dateTue, 12 Mar 2019 18:59:09 +0000
treeherdermozilla-beta@445c24a51727 [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 43: Create PresShell::EventHandler::FinalizeHandlingEvent() r=smaug Finally, we should move the last switch statement in `HandleEventInternal()` to the new method. Then, `HandleEventInternal() does nothing complicated things by itself. Differential Revision: https://phabricator.services.mozilla.com/D22461
layout/base/PresShell.cpp
layout/base/PresShell.h
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -7693,64 +7693,21 @@ nsresult PresShell::EventHandler::Handle
   if (!mPresShell->IsDestroying() && aIsHandlingNativeEvent) {
     // Ensure that notifications to IME should be sent before getting next
     // native event from the event queue.
     // XXX Should we check the event message or event class instead of
     //     using aIsHandlingNativeEvent?
     manager->TryToFlushPendingNotificationsToIME();
   }
 
-  switch (aEvent->mMessage) {
-    case eKeyPress:
-    case eKeyDown:
-    case eKeyUp: {
-      if (aEvent->AsKeyboardEvent()->mKeyCode == NS_VK_ESCAPE) {
-        if (aEvent->mMessage == eKeyUp) {
-          // Reset this flag after key up is handled.
-          mPresShell->mIsLastChromeOnlyEscapeKeyConsumed = false;
-        } else {
-          if (aEvent->mFlags.mOnlyChromeDispatch &&
-              aEvent->mFlags.mDefaultPreventedByChrome) {
-            mPresShell->mIsLastChromeOnlyEscapeKeyConsumed = true;
-          }
-        }
-      }
-      if (aEvent->mMessage == eKeyDown) {
-        mPresShell->mIsLastKeyDownCanceled = aEvent->mFlags.mDefaultPrevented;
-      }
-      break;
-    }
-    case eMouseUp:
-      // reset the capturing content now that the mouse button is up
-      nsIPresShell::SetCapturingContent(nullptr, 0);
-      break;
-    case eMouseMove:
-      nsIPresShell::AllowMouseCapture(false);
-      break;
-    case eDrag:
-    case eDragEnd:
-    case eDragEnter:
-    case eDragExit:
-    case eDragLeave:
-    case eDragOver:
-    case eDrop: {
-      // After any drag event other than dragstart (which is handled
-      // separately, as we need to collect the data first), the DataTransfer
-      // needs to be made protected, and then disconnected.
-      DataTransfer* dataTransfer = aEvent->AsDragEvent()->mDataTransfer;
-      if (dataTransfer) {
-        dataTransfer->Disconnect();
-      }
-      break;
-    }
-    default:
-      break;
-  }
+  FinalizeHandlingEvent(aEvent);
+
   RecordEventHandlingResponsePerformance(aEvent);
-  return rv;
+
+  return rv;  // Result of DispatchEvent()
 }
 
 nsresult PresShell::EventHandler::DispatchEvent(
     EventStateManager* aEventStateManager, WidgetEvent* aEvent,
     bool aTouchIsNew, nsEventStatus* aEventStatus,
     nsIContent* aOverrideClickTarget) {
   MOZ_ASSERT(aEventStateManager);
   MOZ_ASSERT(aEvent);
@@ -7867,16 +7824,65 @@ bool PresShell::EventHandler::PrepareToD
       return false;
     }
 
     default:
       return false;
   }
 }
 
+void PresShell::EventHandler::FinalizeHandlingEvent(WidgetEvent* aEvent) {
+  switch (aEvent->mMessage) {
+    case eKeyPress:
+    case eKeyDown:
+    case eKeyUp: {
+      if (aEvent->AsKeyboardEvent()->mKeyCode == NS_VK_ESCAPE) {
+        if (aEvent->mMessage == eKeyUp) {
+          // Reset this flag after key up is handled.
+          mPresShell->mIsLastChromeOnlyEscapeKeyConsumed = false;
+        } else {
+          if (aEvent->mFlags.mOnlyChromeDispatch &&
+              aEvent->mFlags.mDefaultPreventedByChrome) {
+            mPresShell->mIsLastChromeOnlyEscapeKeyConsumed = true;
+          }
+        }
+      }
+      if (aEvent->mMessage == eKeyDown) {
+        mPresShell->mIsLastKeyDownCanceled = aEvent->mFlags.mDefaultPrevented;
+      }
+      return;
+    }
+    case eMouseUp:
+      // reset the capturing content now that the mouse button is up
+      nsIPresShell::SetCapturingContent(nullptr, 0);
+      return;
+    case eMouseMove:
+      nsIPresShell::AllowMouseCapture(false);
+      return;
+    case eDrag:
+    case eDragEnd:
+    case eDragEnter:
+    case eDragExit:
+    case eDragLeave:
+    case eDragOver:
+    case eDrop: {
+      // After any drag event other than dragstart (which is handled
+      // separately, as we need to collect the data first), the DataTransfer
+      // needs to be made protected, and then disconnected.
+      DataTransfer* dataTransfer = aEvent->AsDragEvent()->mDataTransfer;
+      if (dataTransfer) {
+        dataTransfer->Disconnect();
+      }
+      return;
+    }
+    default:
+      return;
+  }
+}
+
 bool PresShell::EventHandler::PrepareToDispatchContextMenuEvent(
     WidgetEvent* aEvent) {
   MOZ_ASSERT(aEvent);
   MOZ_ASSERT(aEvent->mMessage == eContextMenu);
 
   // XXX Why do we treat untrusted eContextMenu here?
 
   WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
--- a/layout/base/PresShell.h
+++ b/layout/base/PresShell.h
@@ -1195,16 +1195,24 @@ class PresShell final : public nsIPresSh
      *                          event becomes cancelable.
      */
     void DispatchTouchEventToDOM(WidgetEvent* aEvent,
                                  nsEventStatus* aEventStatus,
                                  nsPresShellEventCB* aEventCB,
                                  bool aTouchIsNew);
 
     /**
+     * FinalizeHandlingEvent() should be called after calling DispatchEvent()
+     * and then, this cleans up the state of mPresShell and aEvent.
+     *
+     * @param aEvent            The handled event.
+     */
+    void FinalizeHandlingEvent(WidgetEvent* aEvent);
+
+    /**
      * AutoCurrentEventInfoSetter() pushes and pops current event info of
      * aEventHandler.mPresShell.
      */
     struct MOZ_STACK_CLASS AutoCurrentEventInfoSetter final {
       explicit AutoCurrentEventInfoSetter(EventHandler& aEventHandler)
           : mEventHandler(aEventHandler) {
         MOZ_DIAGNOSTIC_ASSERT(!mEventHandler.mCurrentEventInfoSetter);
         mEventHandler.mCurrentEventInfoSetter = this;