Bug 1220925 - Event::GetScreenCoords should return CSSIntPoint instead of LayoutDevicePoint. r=botond
authorRandall Barker <rbarker@mozilla.com>
Tue, 10 Nov 2015 11:32:40 -0500
changeset 271937 a26be9d0cfed544c15b55dd1b84c03aa666ac22e
parent 271936 0372851573014c50a1337263408cb9641a62ea7f
child 271938 0132945252d2e0c34dee0fca06465df9fc5d152f
push id67805
push userkgupta@mozilla.com
push dateTue, 10 Nov 2015 16:33:05 +0000
treeherdermozilla-inbound@a26be9d0cfed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1220925
milestone45.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 1220925 - Event::GetScreenCoords should return CSSIntPoint instead of LayoutDevicePoint. r=botond This patch converts Event::GetScreenCoords to return the same type as Event::GetClientCoords and Event::GetPageCoords which is a CSSIntPoint. When the function was originally updated it was switched to returning LayoutDevicePoint. Additionally the redundant functions UIEvent::CalculateClientPoint and UIEvent::CalculateScreenPoint were removed.
dom/events/Event.cpp
dom/events/Event.h
dom/events/EventStateManager.cpp
dom/events/EventStateManager.h
dom/events/Touch.cpp
dom/events/Touch.h
dom/events/UIEvent.cpp
dom/events/UIEvent.h
dom/events/test/mochitest.ini
layout/base/Units.h
--- a/dom/events/Event.cpp
+++ b/dom/events/Event.cpp
@@ -894,53 +894,60 @@ Event::PopupAllowedEventsChanged()
 void
 Event::Shutdown()
 {
   if (sPopupAllowedEvents) {
     free(sPopupAllowedEvents);
   }
 }
 
-LayoutDeviceIntPoint
+// static
+CSSIntPoint
 Event::GetScreenCoords(nsPresContext* aPresContext,
                        WidgetEvent* aEvent,
                        LayoutDeviceIntPoint aPoint)
 {
   if (!nsContentUtils::LegacyIsCallerChromeOrNativeCode() &&
       nsContentUtils::ResistFingerprinting()) {
     // When resisting fingerprinting, return client coordinates instead.
-    CSSIntPoint clientCoords = GetClientCoords(aPresContext, aEvent, aPoint, CSSIntPoint(0, 0));
-    return LayoutDeviceIntPoint(clientCoords.x, clientCoords.y);
+    return GetClientCoords(aPresContext, aEvent, aPoint, CSSIntPoint(0, 0));
   }
 
   if (EventStateManager::sIsPointerLocked) {
     return EventStateManager::sLastScreenPoint;
   }
 
   if (!aEvent ||
        (aEvent->mClass != eMouseEventClass &&
         aEvent->mClass != eMouseScrollEventClass &&
         aEvent->mClass != eWheelEventClass &&
         aEvent->mClass != ePointerEventClass &&
         aEvent->mClass != eTouchEventClass &&
         aEvent->mClass != eDragEventClass &&
         aEvent->mClass != eSimpleGestureEventClass)) {
-    return LayoutDeviceIntPoint(0, 0);
+    return CSSIntPoint(0, 0);
   }
 
+  // Doing a straight conversion from LayoutDeviceIntPoint to CSSIntPoint
+  // seem incorrect, but it is needed to maintain legacy functionality.
+  if (!aPresContext) {
+    return CSSIntPoint(aPoint.x, aPoint.y);
+  }
+
+  LayoutDeviceIntPoint offset = aPoint;
+
   WidgetGUIEvent* guiEvent = aEvent->AsGUIEvent();
-  if (!guiEvent->widget) {
-    return aPoint;
+  if (guiEvent && guiEvent->widget) {
+    offset += guiEvent->widget->WidgetToScreenOffset();
   }
 
-  LayoutDeviceIntPoint offset = aPoint + guiEvent->widget->WidgetToScreenOffset();
-  nscoord factor =
-    aPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom();
-  return LayoutDeviceIntPoint(nsPresContext::AppUnitsToIntCSSPixels(offset.x * factor),
-                              nsPresContext::AppUnitsToIntCSSPixels(offset.y * factor));
+  nsPoint pt =
+    LayoutDevicePixel::ToAppUnits(offset, aPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom());
+
+  return CSSPixel::FromAppUnitsRounded(pt);
 }
 
 // static
 CSSIntPoint
 Event::GetPageCoords(nsPresContext* aPresContext,
                      WidgetEvent* aEvent,
                      LayoutDeviceIntPoint aPoint,
                      CSSIntPoint aDefaultPoint)
--- a/dom/events/Event.h
+++ b/dom/events/Event.h
@@ -128,19 +128,19 @@ public:
   static CSSIntPoint GetClientCoords(nsPresContext* aPresContext,
                                      WidgetEvent* aEvent,
                                      LayoutDeviceIntPoint aPoint,
                                      CSSIntPoint aDefaultPoint);
   static CSSIntPoint GetPageCoords(nsPresContext* aPresContext,
                                    WidgetEvent* aEvent,
                                    LayoutDeviceIntPoint aPoint,
                                    CSSIntPoint aDefaultPoint);
-  static LayoutDeviceIntPoint GetScreenCoords(nsPresContext* aPresContext,
-                                              WidgetEvent* aEvent,
-                                              LayoutDeviceIntPoint aPoint);
+  static CSSIntPoint GetScreenCoords(nsPresContext* aPresContext,
+                                     WidgetEvent* aEvent,
+                                     LayoutDeviceIntPoint aPoint);
   static CSSIntPoint GetOffsetCoords(nsPresContext* aPresContext,
                                      WidgetEvent* aEvent,
                                      LayoutDeviceIntPoint aPoint,
                                      CSSIntPoint aDefaultPoint);
 
   static already_AddRefed<Event> Constructor(const GlobalObject& aGlobal,
                                              const nsAString& aType,
                                              const EventInit& aParam,
--- a/dom/events/EventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -265,17 +265,17 @@ static uint32_t sESMInstanceCount = 0;
 static bool sPointerEventEnabled = false;
 
 int32_t EventStateManager::sUserInputEventDepth = 0;
 bool EventStateManager::sNormalLMouseEventInProcess = false;
 EventStateManager* EventStateManager::sActiveESM = nullptr;
 nsIDocument* EventStateManager::sMouseOverDocument = nullptr;
 nsWeakFrame EventStateManager::sLastDragOverFrame = nullptr;
 LayoutDeviceIntPoint EventStateManager::sLastRefPoint = kInvalidRefPoint;
-LayoutDeviceIntPoint EventStateManager::sLastScreenPoint = LayoutDeviceIntPoint(0, 0);
+CSSIntPoint EventStateManager::sLastScreenPoint = CSSIntPoint(0, 0);
 LayoutDeviceIntPoint EventStateManager::sSynthCenteringPoint = kInvalidRefPoint;
 CSSIntPoint EventStateManager::sLastClientPoint = CSSIntPoint(0, 0);
 bool EventStateManager::sIsPointerLocked = false;
 // Reference to the pointer locked element.
 nsWeakPtr EventStateManager::sPointerLockedElement;
 // Reference to the document which requested pointer lock.
 nsWeakPtr EventStateManager::sPointerLockedDoc;
 nsCOMPtr<nsIContent> EventStateManager::sDragOverContent = nullptr;
@@ -555,19 +555,19 @@ EventStateManager::PreHandleEvent(nsPres
 #endif
   // Store last known screenPoint and clientPoint so pointer lock
   // can use these values as constants.
   if (aEvent->mFlags.mIsTrusted &&
       ((mouseEvent && mouseEvent->IsReal()) ||
        aEvent->mClass == eWheelEventClass) &&
       !sIsPointerLocked) {
     sLastScreenPoint =
-      UIEvent::CalculateScreenPoint(aPresContext, aEvent);
+      Event::GetScreenCoords(aPresContext, aEvent, aEvent->refPoint);
     sLastClientPoint =
-      UIEvent::CalculateClientPoint(aPresContext, aEvent, nullptr);
+      Event::GetClientCoords(aPresContext, aEvent, aEvent->refPoint, CSSIntPoint(0, 0));
   }
 
   *aStatus = nsEventStatus_eIgnore;
 
   if (aEvent->mClass == eQueryContentEventClass) {
     HandleQueryContentEvent(aEvent->AsQueryContentEvent());
     return NS_OK;
   }
--- a/dom/events/EventStateManager.h
+++ b/dom/events/EventStateManager.h
@@ -251,17 +251,17 @@ public:
   static bool CanVerticallyScrollFrameWithWheel(nsIFrame* aFrame);
 
   // Holds the point in screen coords that a mouse event was dispatched to,
   // before we went into pointer lock mode. This is constantly updated while
   // the pointer is not locked, but we don't update it while the pointer is
   // locked. This is used by dom::Event::GetScreenCoords() to make mouse
   // events' screen coord appear frozen at the last mouse position while
   // the pointer is locked.
-  static LayoutDeviceIntPoint sLastScreenPoint;
+  static CSSIntPoint sLastScreenPoint;
 
   // Holds the point in client coords of the last mouse event. Used by
   // dom::Event::GetClientCoords() to make mouse events' client coords appear
   // frozen at the last mouse position while the pointer is locked.
   static CSSIntPoint sLastClientPoint;
 
   static bool sIsPointerLocked;
   static nsWeakPtr sPointerLockedElement;
--- a/dom/events/Touch.cpp
+++ b/dom/events/Touch.cpp
@@ -27,17 +27,17 @@ Touch::Touch(EventTarget* aTarget,
              int32_t aRadiusX,
              int32_t aRadiusY,
              float aRotationAngle,
              float aForce)
 {
   mTarget = aTarget;
   mIdentifier = aIdentifier;
   mPagePoint = CSSIntPoint(aPageX, aPageY);
-  mScreenPoint = LayoutDeviceIntPoint(aScreenX, aScreenY);
+  mScreenPoint = CSSIntPoint(aScreenX, aScreenY);
   mClientPoint = CSSIntPoint(aClientX, aClientY);
   mRefPoint = LayoutDeviceIntPoint(0, 0);
   mPointsInitialized = true;
   mRadius.x = aRadiusX;
   mRadius.y = aRadiusY;
   mRotationAngle = aRotationAngle;
   mForce = aForce;
 
@@ -49,17 +49,17 @@ Touch::Touch(EventTarget* aTarget,
 Touch::Touch(int32_t aIdentifier,
              LayoutDeviceIntPoint aPoint,
              LayoutDeviceIntPoint aRadius,
              float aRotationAngle,
              float aForce)
 {
   mIdentifier = aIdentifier;
   mPagePoint = CSSIntPoint(0, 0);
-  mScreenPoint = LayoutDeviceIntPoint(0, 0);
+  mScreenPoint = CSSIntPoint(0, 0);
   mClientPoint = CSSIntPoint(0, 0);
   mRefPoint = aPoint;
   mPointsInitialized = false;
   mRadius = aRadius;
   mRotationAngle = aRotationAngle;
   mForce = aForce;
 
   mChanged = false;
--- a/dom/events/Touch.h
+++ b/dom/events/Touch.h
@@ -76,17 +76,17 @@ public:
 
   nsCOMPtr<EventTarget> mTarget;
   LayoutDeviceIntPoint mRefPoint;
   bool mChanged;
   uint32_t mMessage;
   int32_t mIdentifier;
   CSSIntPoint mPagePoint;
   CSSIntPoint mClientPoint;
-  LayoutDeviceIntPoint mScreenPoint;
+  CSSIntPoint mScreenPoint;
   LayoutDeviceIntPoint mRadius;
   float mRotationAngle;
   float mForce;
 protected:
   ~Touch();
 
   bool mPointsInitialized;
 };
--- a/dom/events/UIEvent.cpp
+++ b/dom/events/UIEvent.cpp
@@ -354,21 +354,23 @@ UIEvent::DuplicatePrivateData()
   mClientPoint =
     Event::GetClientCoords(mPresContext, mEvent, mEvent->refPoint,
                            mClientPoint);
   mMovementPoint = GetMovementPoint();
   mLayerPoint = GetLayerPoint();
   mPagePoint =
     Event::GetPageCoords(mPresContext, mEvent, mEvent->refPoint, mClientPoint);
   // GetScreenPoint converts mEvent->refPoint to right coordinates.
-  LayoutDeviceIntPoint screenPoint =
+  CSSIntPoint screenPoint =
     Event::GetScreenCoords(mPresContext, mEvent, mEvent->refPoint);
   nsresult rv = Event::DuplicatePrivateData();
   if (NS_SUCCEEDED(rv)) {
-    mEvent->refPoint = screenPoint;
+    CSSToLayoutDeviceScale scale = mPresContext ? mPresContext->CSSToDevPixelScale()
+                                                : CSSToLayoutDeviceScale(1);
+    mEvent->refPoint = RoundedToInt(screenPoint * scale);
   }
   return rv;
 }
 
 NS_IMETHODIMP_(void)
 UIEvent::Serialize(IPC::Message* aMsg, bool aSerializeInterfaceType)
 {
   if (aSerializeInterfaceType) {
--- a/dom/events/UIEvent.h
+++ b/dom/events/UIEvent.h
@@ -35,72 +35,16 @@ public:
   NS_DECL_NSIDOMUIEVENT
 
   // Forward to Event
   NS_FORWARD_TO_EVENT_NO_SERIALIZATION_NO_DUPLICATION
   NS_IMETHOD DuplicatePrivateData() override;
   NS_IMETHOD_(void) Serialize(IPC::Message* aMsg, bool aSerializeInterfaceType) override;
   NS_IMETHOD_(bool) Deserialize(const IPC::Message* aMsg, void** aIter) override;
 
-  static LayoutDeviceIntPoint CalculateScreenPoint(nsPresContext* aPresContext,
-                                                   WidgetEvent* aEvent)
-  {
-    if (!aEvent ||
-        (aEvent->mClass != eMouseEventClass &&
-         aEvent->mClass != eMouseScrollEventClass &&
-         aEvent->mClass != eWheelEventClass &&
-         aEvent->mClass != eDragEventClass &&
-         aEvent->mClass != ePointerEventClass &&
-         aEvent->mClass != eSimpleGestureEventClass)) {
-      return LayoutDeviceIntPoint(0, 0);
-    }
-
-    WidgetGUIEvent* event = aEvent->AsGUIEvent();
-    if (!event->widget) {
-      return aEvent->refPoint;
-    }
-
-    LayoutDeviceIntPoint offset = aEvent->refPoint + event->widget->WidgetToScreenOffset();
-    nscoord factor =
-      aPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom();
-    return LayoutDeviceIntPoint(nsPresContext::AppUnitsToIntCSSPixels(offset.x * factor),
-                                nsPresContext::AppUnitsToIntCSSPixels(offset.y * factor));
-  }
-
-  static CSSIntPoint CalculateClientPoint(nsPresContext* aPresContext,
-                                          WidgetEvent* aEvent,
-                                          CSSIntPoint* aDefaultClientPoint)
-  {
-    if (!aEvent ||
-        (aEvent->mClass != eMouseEventClass &&
-         aEvent->mClass != eMouseScrollEventClass &&
-         aEvent->mClass != eWheelEventClass &&
-         aEvent->mClass != eDragEventClass &&
-         aEvent->mClass != ePointerEventClass &&
-         aEvent->mClass != eSimpleGestureEventClass) ||
-        !aPresContext ||
-        !aEvent->AsGUIEvent()->widget) {
-      return aDefaultClientPoint
-             ? *aDefaultClientPoint
-             : CSSIntPoint(0, 0);
-    }
-
-    nsIPresShell* shell = aPresContext->GetPresShell();
-    if (!shell) {
-      return CSSIntPoint(0, 0);
-    }
-    nsIFrame* rootFrame = shell->GetRootFrame();
-    if (!rootFrame) {
-      return CSSIntPoint(0, 0);
-    }
-    nsPoint pt =
-      nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, rootFrame);
-
-    return CSSIntPoint::FromAppUnitsRounded(pt);
-  }
 
   static already_AddRefed<UIEvent> Constructor(const GlobalObject& aGlobal,
                                                const nsAString& aType,
                                                const UIEventInit& aParam,
                                                ErrorResult& aRv);
 
   virtual JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
   {
--- a/dom/events/test/mochitest.ini
+++ b/dom/events/test/mochitest.ini
@@ -119,17 +119,16 @@ skip-if = toolkit == 'android' #CRASH_DU
 [test_bug667919-1.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android' #CRASH_DUMP, RANDOM # b2g(bug 900969, 5 tests) b2g-debug(bug 900969, 5 tests) b2g-desktop(bug 900969, 5 tests)
 [test_bug689564.html]
 skip-if = toolkit == 'android' #CRASH_DUMP, RANDOM
 [test_bug698929.html]
 skip-if = toolkit == 'android' #CRASH_DUMP, RANDOM
 [test_bug704423.html]
 [test_bug741666.html]
-skip-if = toolkit == 'android'
 [test_bug742376.html]
 [test_bug812744.html]
 [test_bug855741.html]
 [test_bug864040.html]
 skip-if = buildapp == 'b2g' # b2g(failing when the test gets moved around, and on debug)
 [test_bug924087.html]
 [test_bug930374-content.html]
 [test_bug944011.html]
--- a/layout/base/Units.h
+++ b/layout/base/Units.h
@@ -284,16 +284,21 @@ struct LayoutDevicePixel {
   }
 
   static LayoutDeviceIntSize FromAppUnitsRounded(const nsSize& aSize, nscoord aAppUnitsPerDevPixel) {
     return LayoutDeviceIntSize(
       NSAppUnitsToIntPixels(aSize.width, aAppUnitsPerDevPixel),
       NSAppUnitsToIntPixels(aSize.height, aAppUnitsPerDevPixel));
   }
 
+  static nsPoint ToAppUnits(const LayoutDeviceIntPoint& aPoint, nscoord aAppUnitsPerDevPixel) {
+    return nsPoint(aPoint.x * aAppUnitsPerDevPixel,
+                   aPoint.y * aAppUnitsPerDevPixel);
+  }
+
   static nsSize ToAppUnits(const LayoutDeviceIntSize& aSize, nscoord aAppUnitsPerDevPixel) {
     return nsSize(aSize.width * aAppUnitsPerDevPixel,
                   aSize.height * aAppUnitsPerDevPixel);
   }
 
   static nsSize ToAppUnits(const LayoutDeviceSize& aSize, nscoord aAppUnitsPerDevPixel) {
     return nsSize(NSFloatPixelsToAppUnits(aSize.width, aAppUnitsPerDevPixel),
                   NSFloatPixelsToAppUnits(aSize.height, aAppUnitsPerDevPixel));