diff --git a/dom/events/Event.cpp b/dom/events/Event.cpp index 845da685b084..6cdd693fe55a 100644 --- a/dom/events/Event.cpp +++ b/dom/events/Event.cpp @@ -899,7 +899,8 @@ Event::Shutdown() } } -LayoutDeviceIntPoint +// static +CSSIntPoint Event::GetScreenCoords(nsPresContext* aPresContext, WidgetEvent* aEvent, LayoutDeviceIntPoint aPoint) @@ -907,8 +908,7 @@ Event::GetScreenCoords(nsPresContext* aPresContext, 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) { @@ -923,19 +923,26 @@ Event::GetScreenCoords(nsPresContext* aPresContext, 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 diff --git a/dom/events/Event.h b/dom/events/Event.h index bc44d91644a8..412901d4a7a5 100644 --- a/dom/events/Event.h +++ b/dom/events/Event.h @@ -133,9 +133,9 @@ public: 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, diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index 38eff6fb94db..6234eb8881d5 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -270,7 +270,7 @@ 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; @@ -560,9 +560,9 @@ EventStateManager::PreHandleEvent(nsPresContext* aPresContext, 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; diff --git a/dom/events/EventStateManager.h b/dom/events/EventStateManager.h index 8fac0ee8218c..c6a83fbfbcfb 100644 --- a/dom/events/EventStateManager.h +++ b/dom/events/EventStateManager.h @@ -256,7 +256,7 @@ public: // 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 diff --git a/dom/events/Touch.cpp b/dom/events/Touch.cpp index 50ebde73d7b9..35a4bb911ae2 100644 --- a/dom/events/Touch.cpp +++ b/dom/events/Touch.cpp @@ -32,7 +32,7 @@ Touch::Touch(EventTarget* aTarget, 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; @@ -54,7 +54,7 @@ Touch::Touch(int32_t aIdentifier, { mIdentifier = aIdentifier; mPagePoint = CSSIntPoint(0, 0); - mScreenPoint = LayoutDeviceIntPoint(0, 0); + mScreenPoint = CSSIntPoint(0, 0); mClientPoint = CSSIntPoint(0, 0); mRefPoint = aPoint; mPointsInitialized = false; diff --git a/dom/events/Touch.h b/dom/events/Touch.h index d1e6cd435eee..36db8c23b8bf 100644 --- a/dom/events/Touch.h +++ b/dom/events/Touch.h @@ -81,7 +81,7 @@ public: int32_t mIdentifier; CSSIntPoint mPagePoint; CSSIntPoint mClientPoint; - LayoutDeviceIntPoint mScreenPoint; + CSSIntPoint mScreenPoint; LayoutDeviceIntPoint mRadius; float mRotationAngle; float mForce; diff --git a/dom/events/UIEvent.cpp b/dom/events/UIEvent.cpp index 3bb548d6a143..d12eb45910e4 100644 --- a/dom/events/UIEvent.cpp +++ b/dom/events/UIEvent.cpp @@ -359,11 +359,13 @@ UIEvent::DuplicatePrivateData() 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; } diff --git a/dom/events/UIEvent.h b/dom/events/UIEvent.h index 476f2613437b..a130744d7d7b 100644 --- a/dom/events/UIEvent.h +++ b/dom/events/UIEvent.h @@ -40,62 +40,6 @@ public: 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 Constructor(const GlobalObject& aGlobal, const nsAString& aType, diff --git a/dom/events/test/mochitest.ini b/dom/events/test/mochitest.ini index 36dc95673785..e23b950136f2 100644 --- a/dom/events/test/mochitest.ini +++ b/dom/events/test/mochitest.ini @@ -124,7 +124,6 @@ skip-if = toolkit == 'android' #CRASH_DUMP, RANDOM 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] diff --git a/layout/base/Units.h b/layout/base/Units.h index f02231ca1c4c..5945a8609c4d 100644 --- a/layout/base/Units.h +++ b/layout/base/Units.h @@ -289,6 +289,11 @@ struct LayoutDevicePixel { 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);