Bug 870311 - Fix coordinates on contextmenu event, r=kats
authorMichael Wu <mwu@mozilla.com>
Tue, 16 Jul 2013 15:54:59 -0400
changeset 138718 b1d0825c97cc3cb256c5a4f8adf6716544f26937
parent 138717 909a9483c796db9a30a67cfa74eaf7ecf613adab
child 138719 fd10ead17acea3be28ab8b485c499b0ccd142fbb
push id24964
push userryanvm@gmail.com
push dateTue, 16 Jul 2013 20:04:09 +0000
treeherderautoland@fd10ead17ace [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs870311
milestone25.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 870311 - Fix coordinates on contextmenu event, r=kats
dom/ipc/TabChild.cpp
dom/ipc/TabChild.h
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -1644,17 +1644,17 @@ bool
 TabChild::RecvMouseEvent(const nsString& aType,
                          const float&    aX,
                          const float&    aY,
                          const int32_t&  aButton,
                          const int32_t&  aClickCount,
                          const int32_t&  aModifiers,
                          const bool&     aIgnoreRootScrollFrame)
 {
-  DispatchMouseEvent(aType, aX, aY, aButton, aClickCount, aModifiers,
+  DispatchMouseEvent(aType, CSSPoint(aX, aY), aButton, aClickCount, aModifiers,
                      aIgnoreRootScrollFrame);
   return true;
 }
 
 bool
 TabChild::RecvRealMouseEvent(const nsMouseEvent& event)
 {
   nsMouseEvent localEvent(event);
@@ -1667,24 +1667,24 @@ TabChild::RecvMouseWheelEvent(const Whee
 {
   WheelEvent localEvent(event);
   DispatchWidgetEvent(localEvent);
   return true;
 }
 
 void
 TabChild::DispatchSynthesizedMouseEvent(uint32_t aMsg, uint64_t aTime,
-                                        const nsIntPoint& aRefPoint)
+                                        const LayoutDevicePoint& aRefPoint)
 {
   MOZ_ASSERT(aMsg == NS_MOUSE_MOVE || aMsg == NS_MOUSE_BUTTON_DOWN ||
              aMsg == NS_MOUSE_BUTTON_UP);
 
   nsMouseEvent event(true, aMsg, NULL,
       nsMouseEvent::eReal, nsMouseEvent::eNormal);
-  event.refPoint = aRefPoint;
+  event.refPoint = nsIntPoint(aRefPoint.x, aRefPoint.y);
   event.time = aTime;
   event.button = nsMouseEvent::eLeftButton;
   event.inputSource = nsIDOMMouseEvent::MOZ_SOURCE_TOUCH;
   if (aMsg != NS_MOUSE_MOVE) {
     event.clickCount = 1;
   }
 
   DispatchWidgetEvent(event);
@@ -1730,17 +1730,17 @@ TabChild::UpdateTapState(const nsTouchEv
       return;
     }
     if (aStatus == nsEventStatus_eConsumeNoDefault ||
         nsIPresShell::gPreventMouseEvents) {
       return;
     }
 
     Touch* touch = static_cast<Touch*>(aEvent.touches[0].get());
-    mGestureDownPoint = touch->mRefPoint;
+    mGestureDownPoint = LayoutDevicePoint(touch->mRefPoint.x, touch->mRefPoint.y);
     mActivePointerId = touch->mIdentifier;
     if (sClickHoldContextMenusEnabled) {
       MOZ_ASSERT(!mTapHoldTimer);
       mTapHoldTimer = NewRunnableMethod(this,
                                         &TabChild::FireContextMenuEvent);
       MessageLoop::current()->PostDelayedTask(FROM_HERE, mTapHoldTimer,
                                               sContextMenuDelayMs);
     }
@@ -1752,17 +1752,17 @@ TabChild::UpdateTapState(const nsTouchEv
   if (!currentlyTrackingTouch) {
     return;
   }
   Touch* trackedTouch = GetTouchForIdentifier(aEvent, mActivePointerId);
   if (!trackedTouch) {
     return;
   }
 
-  nsIntPoint currentPoint = trackedTouch->mRefPoint;
+  LayoutDevicePoint currentPoint = LayoutDevicePoint(trackedTouch->mRefPoint.x, trackedTouch->mRefPoint.y);
   int64_t time = aEvent.time;
   switch (aEvent.message) {
   case NS_TOUCH_MOVE:
     if (abs(currentPoint.x - mGestureDownPoint.x) > sDragThreshold.width ||
         abs(currentPoint.y - mGestureDownPoint.y) > sDragThreshold.height) {
       CancelTapTracking();
     }
     return;
@@ -1781,19 +1781,25 @@ TabChild::UpdateTapState(const nsTouchEv
   default:
     NS_WARNING("Unknown touch event type");
   }
 }
 
 void
 TabChild::FireContextMenuEvent()
 {
+  double scale;
+  GetDefaultScale(&scale);
+  if (scale < 0) {
+    scale = 1;
+  }
+
   MOZ_ASSERT(mTapHoldTimer && mActivePointerId >= 0);
   bool defaultPrevented = DispatchMouseEvent(NS_LITERAL_STRING("contextmenu"),
-                                             mGestureDownPoint.x, mGestureDownPoint.y,
+                                             mGestureDownPoint / CSSToLayoutDeviceScale(scale),
                                              2 /* Right button */,
                                              1 /* Click count */,
                                              0 /* Modifiers */,
                                              false /* Ignore root scroll frame */);
 
   // Fire a click event if someone didn't call preventDefault() on the context
   // menu event.
   if (defaultPrevented) {
@@ -2273,28 +2279,27 @@ TabChild::NotifyPainted()
 bool
 TabChild::IsAsyncPanZoomEnabled()
 {
     return mScrolling == ASYNC_PAN_ZOOM;
 }
 
 bool
 TabChild::DispatchMouseEvent(const nsString& aType,
-                             const float&    aX,
-                             const float&    aY,
+                             const CSSPoint& aPoint,
                              const int32_t&  aButton,
                              const int32_t&  aClickCount,
                              const int32_t&  aModifiers,
                              const bool&     aIgnoreRootScrollFrame)
 {
   nsCOMPtr<nsIDOMWindowUtils> utils(GetDOMWindowUtils());
   NS_ENSURE_TRUE(utils, true);
   
   bool defaultPrevented = false;
-  utils->SendMouseEvent(aType, aX, aY, aButton, aClickCount, aModifiers,
+  utils->SendMouseEvent(aType, aPoint.x, aPoint.y, aButton, aClickCount, aModifiers,
                         aIgnoreRootScrollFrame, 0, 0, &defaultPrevented);
   return defaultPrevented;
 }
 
 void
 TabChild::MakeVisible()
 {
     if (mWidget) {
--- a/dom/ipc/TabChild.h
+++ b/dom/ipc/TabChild.h
@@ -304,18 +304,17 @@ public:
     void NotifyPainted();
 
     bool IsAsyncPanZoomEnabled();
 
     /** Return a boolean indicating if the page has called preventDefault on
      *  the event.
      */
     bool DispatchMouseEvent(const nsString& aType,
-                            const float&    aX,
-                            const float&    aY,
+                            const CSSPoint& aPoint,
                             const int32_t&  aButton,
                             const int32_t&  aClickCount,
                             const int32_t&  aModifiers,
                             const bool&     aIgnoreRootScrollFrame);
 
     /**
      * Signal to this TabChild that it should be made visible:
      * activated widget, retained layer tree, etc.  (Respectively,
@@ -402,17 +401,17 @@ private:
     // chrome script.
     //
     // XXX/bug 780335: Do the work the browser chrome script does in C++ instead
     // so we don't need things like this.
     void DispatchMessageManagerMessage(const nsAString& aMessageName,
                                        const nsACString& aJSONData);
 
     void DispatchSynthesizedMouseEvent(uint32_t aMsg, uint64_t aTime,
-                                       const nsIntPoint& aRefPoint);
+                                       const LayoutDevicePoint& aRefPoint);
 
     // These methods are used for tracking synthetic mouse events
     // dispatched for compatibility.  On each touch event, we
     // UpdateTapState().  If we've detected that the current gesture
     // isn't a tap, then we CancelTapTracking().  In the meantime, we
     // may detect a context-menu event, and if so we
     // FireContextMenuEvent().
     void FireContextMenuEvent();
@@ -440,17 +439,17 @@ private:
     RenderFrameChild* mRemoteFrame;
     nsRefPtr<ContentChild> mManager;
     nsRefPtr<TabChildGlobal> mTabChildGlobal;
     uint32_t mChromeFlags;
     nsIntRect mOuterRect;
     ScreenIntSize mInnerSize;
     // When we're tracking a possible tap gesture, this is the "down"
     // point of the touchstart.
-    nsIntPoint mGestureDownPoint;
+    LayoutDevicePoint mGestureDownPoint;
     // The touch identifier of the active gesture.
     int32_t mActivePointerId;
     // A timer task that fires if the tap-hold timeout is exceeded by
     // the touch we're tracking.  That is, if touchend or a touchmove
     // that exceeds the gesture threshold doesn't happen.
     CancelableTask* mTapHoldTimer;
     // Whether we have already received a FileDescriptor for the app package.
     bool mAppPackageFileDescriptorRecved;