Bug 1420589 Part5: Separate the logic to get shell for touch events into a function. r=smaug.
authorStone Shih <sshih@mozilla.com>
Sat, 09 Dec 2017 09:11:10 +0800
changeset 396968 7a568d63c332deb3988fe058ced0fd6f62b3ed81
parent 396967 48188682637759405eade9bcca074ac4616c3d63
child 396969 62f76b10e91f4fcda8dc8a5288160a372ddd6855
push id33117
push userebalazs@mozilla.com
push dateWed, 20 Dec 2017 09:47:43 +0000
treeherdermozilla-central@a235bf4868ab [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1420589
milestone59.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 1420589 Part5: Separate the logic to get shell for touch events into a function. r=smaug. MozReview-Commit-ID: LbYKBZAqeJM
layout/base/PresShell.cpp
layout/base/PresShell.h
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -6825,16 +6825,60 @@ PresShell::CanDispatchEvent(const Widget
   bool rv =
     mPresContext && !mHaveShutDown && nsContentUtils::IsSafeToRunScript();
   if (aEvent) {
     rv &= (aEvent && aEvent->mWidget && !aEvent->mWidget->Destroyed());
   }
   return rv;
 }
 
+/* static */ PresShell*
+PresShell::GetShellForTouchEvent(WidgetGUIEvent* aEvent)
+{
+  PresShell* shell = nullptr;
+  switch (aEvent->mMessage) {
+  case eTouchMove:
+  case eTouchCancel:
+  case eTouchEnd: {
+    // get the correct shell to dispatch to
+    WidgetTouchEvent* touchEvent = aEvent->AsTouchEvent();
+    for (dom::Touch* touch : touchEvent->mTouches) {
+      if (!touch) {
+        break;
+      }
+
+      RefPtr<dom::Touch> oldTouch =
+        TouchManager::GetCapturedTouch(touch->Identifier());
+      if (!oldTouch) {
+        break;
+      }
+
+      nsCOMPtr<nsIContent> content = do_QueryInterface(oldTouch->GetTarget());
+      if (!content) {
+        break;
+      }
+
+      nsIFrame* contentFrame = content->GetPrimaryFrame();
+      if (!contentFrame) {
+        break;
+      }
+
+      shell = static_cast<PresShell*>(contentFrame->PresContext()->PresShell());
+      if (shell) {
+        break;
+      }
+    }
+    break;
+  }
+  default:
+    break;
+  }
+  return shell;
+}
+
 nsresult
 PresShell::HandleEvent(nsIFrame* aFrame,
                        WidgetGUIEvent* aEvent,
                        bool aDontRetargetEvents,
                        nsEventStatus* aEventStatus,
                        nsIContent** aTargetContent)
 {
 #ifdef MOZ_TASK_TRACER
@@ -7212,53 +7256,20 @@ PresShell::HandleEvent(nsIFrame* aFrame,
     }
 
     if (!frame) {
       NS_WARNING("Nothing to handle this event!");
       return NS_OK;
     }
 
     PresShell* shell = static_cast<PresShell*>(frame->PresShell());
-    switch (aEvent->mMessage) {
-      case eTouchMove:
-      case eTouchCancel:
-      case eTouchEnd: {
-        // get the correct shell to dispatch to
-        WidgetTouchEvent* touchEvent = aEvent->AsTouchEvent();
-        for (dom::Touch* touch : touchEvent->mTouches) {
-          if (!touch) {
-            break;
-          }
-
-          RefPtr<dom::Touch> oldTouch =
-            TouchManager::GetCapturedTouch(touch->Identifier());
-          if (!oldTouch) {
-            break;
-          }
-
-          nsCOMPtr<nsIContent> content =
-            do_QueryInterface(oldTouch->GetTarget());
-          if (!content) {
-            break;
-          }
-
-          nsIFrame* contentFrame = content->GetPrimaryFrame();
-          if (!contentFrame) {
-            break;
-          }
-
-          shell = static_cast<PresShell*>(contentFrame->PresShell());
-          if (shell) {
-            break;
-          }
-        }
-        break;
-      }
-    default:
-      break;
+    if (aEvent->mClass == eTouchEventClass) {
+      if (PresShell* newShell = GetShellForTouchEvent(aEvent)) {
+        shell = newShell;
+      }
     }
 
     // Check if we have an active EventStateManager which isn't the
     // EventStateManager of the current PresContext.
     // If that is the case, and mouse is over some ancestor document,
     // forward event handling to the active document.
     // This way content can get mouse events even when
     // mouse is over the chrome or outside the window.
--- a/layout/base/PresShell.h
+++ b/layout/base/PresShell.h
@@ -408,16 +408,18 @@ public:
                                            uint32_t aSheetType) override;
 
   virtual bool HasHandledUserInput() const override {
     return mHasHandledUserInput;
   }
 
   virtual void FireResizeEvent() override;
 
+  static PresShell* GetShellForTouchEvent(WidgetGUIEvent* aEvent);
+
 protected:
   virtual ~PresShell();
 
   void HandlePostedReflowCallbacks(bool aInterruptible);
   void CancelPostedReflowCallbacks();
 
   void ScheduleBeforeFirstPaint();
   void UnsuppressAndInvalidate();