Bug 1298908 - Extract a helper method that does the dispatching of contextmenu events. r?botond draft
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 30 Aug 2016 17:32:08 -0400
changeset 407723 5e6bb095e129bbceaca13a30ac65cccac18bbebe
parent 407722 fa6f91ffb4965302f316635e91d456c8103e08c2
child 407724 8cc3a15748a06887f0d40ef9cf24f58091d88f9f
push id28026
push userkgupta@mozilla.com
push dateTue, 30 Aug 2016 21:32:39 +0000
reviewersbotond
bugs1298908
milestone51.0a1
Bug 1298908 - Extract a helper method that does the dispatching of contextmenu events. r?botond MozReview-Commit-ID: JrtpHhtjhRw
gfx/layers/apz/util/APZEventState.cpp
gfx/layers/apz/util/APZEventState.h
--- a/gfx/layers/apz/util/APZEventState.cpp
+++ b/gfx/layers/apz/util/APZEventState.cpp
@@ -200,33 +200,23 @@ APZEventState::ProcessSingleTap(const CS
                                         nsITimer::TYPE_ONE_SHOT);
   if (NS_FAILED(rv)) {
     // Make |callback| not hold the timer, so they will both be destructed when
     // we leave the scope of this function.
     callback->ClearTimer();
   }
 }
 
-void
-APZEventState::ProcessLongTap(const nsCOMPtr<nsIPresShell>& aPresShell,
-                              const CSSPoint& aPoint,
-                              const CSSToLayoutDeviceScale& aScale,
-                              Modifiers aModifiers,
-                              const ScrollableLayerGuid& aGuid,
-                              uint64_t aInputBlockId)
+bool
+APZEventState::FireContextmenuEvents(const nsCOMPtr<nsIPresShell>& aPresShell,
+                                     const CSSPoint& aPoint,
+                                     const CSSToLayoutDeviceScale& aScale,
+                                     Modifiers aModifiers,
+                                     const nsCOMPtr<nsIWidget>& aWidget)
 {
-  APZES_LOG("Handling long tap at %s\n", Stringify(aPoint).c_str());
-
-  nsCOMPtr<nsIWidget> widget = GetWidget();
-  if (!widget) {
-    return;
-  }
-
-  SendPendingTouchPreventedResponse(false);
-
   // Converting the modifiers to DOM format for the DispatchMouseEvent call
   // is the most useless thing ever because nsDOMWindowUtils::SendMouseEvent
   // just converts them back to widget format, but that API has many callers,
   // including in JS code, so it's not trivial to change.
   bool eventHandled =
       APZCCallbackHelper::DispatchMouseEvent(aPresShell, NS_LITERAL_STRING("contextmenu"),
                          aPoint, 2, 1, WidgetModifiersToDOMModifiers(aModifiers), true,
                          nsIDOMMouseEvent::MOZ_SOURCE_TOUCH);
@@ -238,21 +228,43 @@ APZEventState::ProcessLongTap(const nsCO
     mActiveElementManager->ClearActivation();
   } else {
     // If no one handle context menu, fire MOZLONGTAP event
     LayoutDevicePoint ldPoint = aPoint * aScale;
     int time = 0;
     nsEventStatus status =
         APZCCallbackHelper::DispatchSynthesizedMouseEvent(eMouseLongTap, time,
                                                           ldPoint,
-                                                          aModifiers, widget);
+                                                          aModifiers, aWidget);
     eventHandled = (status == nsEventStatus_eConsumeNoDefault);
     APZES_LOG("MOZLONGTAP event handled: %d\n", eventHandled);
   }
 
+  return eventHandled;
+}
+
+void
+APZEventState::ProcessLongTap(const nsCOMPtr<nsIPresShell>& aPresShell,
+                              const CSSPoint& aPoint,
+                              const CSSToLayoutDeviceScale& aScale,
+                              Modifiers aModifiers,
+                              const ScrollableLayerGuid& aGuid,
+                              uint64_t aInputBlockId)
+{
+  APZES_LOG("Handling long tap at %s\n", Stringify(aPoint).c_str());
+
+  nsCOMPtr<nsIWidget> widget = GetWidget();
+  if (!widget) {
+    return;
+  }
+
+  SendPendingTouchPreventedResponse(false);
+
+  bool eventHandled = FireContextmenuEvents(aPresShell, aPoint, aScale,
+        aModifiers, widget);
   mContentReceivedInputBlockCallback(aGuid, aInputBlockId, eventHandled);
 
   if (eventHandled) {
     // Also send a touchcancel to content, so that listeners that might be
     // waiting for a touchend don't trigger.
     WidgetTouchEvent cancelTouchEvent(true, eTouchCancel, widget.get());
     cancelTouchEvent.mModifiers = aModifiers;
     auto ldPoint = LayoutDeviceIntPoint::Round(aPoint * aScale);
--- a/gfx/layers/apz/util/APZEventState.h
+++ b/gfx/layers/apz/util/APZEventState.h
@@ -71,16 +71,21 @@ public:
   void ProcessAPZStateChange(const nsCOMPtr<nsIDocument>& aDocument,
                              ViewID aViewId,
                              APZStateChange aChange,
                              int aArg);
   void ProcessClusterHit();
 private:
   ~APZEventState();
   bool SendPendingTouchPreventedResponse(bool aPreventDefault);
+  bool FireContextmenuEvents(const nsCOMPtr<nsIPresShell>& aPresShell,
+                             const CSSPoint& aPoint,
+                             const CSSToLayoutDeviceScale& aScale,
+                             Modifiers aModifiers,
+                             const nsCOMPtr<nsIWidget>& aWidget);
   already_AddRefed<nsIWidget> GetWidget() const;
 private:
   nsWeakPtr mWidget;
   RefPtr<ActiveElementManager> mActiveElementManager;
   ContentReceivedInputBlockCallback mContentReceivedInputBlockCallback;
   bool mPendingTouchPreventedResponse;
   ScrollableLayerGuid mPendingTouchPreventedGuid;
   uint64_t mPendingTouchPreventedBlockId;