forked from mirrors/gecko-dev
Bug 1756323 - Cleanup mouse event coord code. r=jfkthame
Differential Revision: https://phabricator.services.mozilla.com/D139234
This commit is contained in:
parent
6e24f3bf7d
commit
957e1363f5
6 changed files with 68 additions and 109 deletions
|
|
@ -133,16 +133,9 @@ RootAccessibleWrap::HandleEvent(Event* aDOMEvent) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
MouseEvent* mouseEvent = aDOMEvent->AsMouseEvent();
|
||||
if (mouseEvent) {
|
||||
nsPresContext* pc = PresContext();
|
||||
|
||||
int32_t x =
|
||||
pc->CSSPixelsToDevPixels(mouseEvent->ScreenX(CallerType::System));
|
||||
int32_t y =
|
||||
pc->CSSPixelsToDevPixels(mouseEvent->ScreenY(CallerType::System));
|
||||
|
||||
ExploreByTouch(x, y);
|
||||
if (MouseEvent* mouseEvent = aDOMEvent->AsMouseEvent()) {
|
||||
LayoutDeviceIntPoint point = mouseEvent->ScreenPointLayoutDevicePix();
|
||||
ExploreByTouch(point.x, point.y);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
|||
|
|
@ -63,8 +63,8 @@ void MouseEvent::InitMouseEvent(const nsAString& aType, bool aCanBubble,
|
|||
mouseEventBase->mButton = aButton;
|
||||
mouseEventBase->InitBasicModifiers(aCtrlKey, aAltKey, aShiftKey,
|
||||
aMetaKey);
|
||||
mClientPoint.x = aClientX;
|
||||
mClientPoint.y = aClientY;
|
||||
mDefaultClientPoint.x = aClientX;
|
||||
mDefaultClientPoint.y = aClientY;
|
||||
mouseEventBase->mRefPoint.x = aScreenX;
|
||||
mouseEventBase->mRefPoint.y = aScreenY;
|
||||
|
||||
|
|
@ -223,123 +223,77 @@ void MouseEvent::GetRegion(nsAString& aRegion) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t MouseEvent::ScreenX(CallerType aCallerType) {
|
||||
CSSIntPoint MouseEvent::ScreenPoint(CallerType aCallerType) const {
|
||||
if (mEvent->mFlags.mIsPositionless) {
|
||||
return 0;
|
||||
return {};
|
||||
}
|
||||
|
||||
if (nsContentUtils::ResistFingerprinting(aCallerType)) {
|
||||
// Sanitize to something sort of like client cooords, but not quite
|
||||
// (defaulting to (0,0) instead of our pre-specified client coords).
|
||||
return Event::GetClientCoords(mPresContext, mEvent, mEvent->mRefPoint,
|
||||
CSSIntPoint(0, 0))
|
||||
.x;
|
||||
CSSIntPoint(0, 0));
|
||||
}
|
||||
|
||||
return Event::GetScreenCoords(mPresContext, mEvent, mEvent->mRefPoint).x;
|
||||
return Event::GetScreenCoords(mPresContext, mEvent, mEvent->mRefPoint);
|
||||
}
|
||||
|
||||
int32_t MouseEvent::ScreenY(CallerType aCallerType) {
|
||||
if (mEvent->mFlags.mIsPositionless) {
|
||||
return 0;
|
||||
}
|
||||
LayoutDeviceIntPoint MouseEvent::ScreenPointLayoutDevicePix() const {
|
||||
const CSSIntPoint point = ScreenPoint(CallerType::System);
|
||||
auto scale = mPresContext ? mPresContext->CSSToDevPixelScale()
|
||||
: CSSToLayoutDeviceScale();
|
||||
return LayoutDeviceIntPoint::Round(point * scale);
|
||||
}
|
||||
|
||||
if (nsContentUtils::ResistFingerprinting(aCallerType)) {
|
||||
// Sanitize to something sort of like client cooords, but not quite
|
||||
// (defaulting to (0,0) instead of our pre-specified client coords).
|
||||
return Event::GetClientCoords(mPresContext, mEvent, mEvent->mRefPoint,
|
||||
CSSIntPoint(0, 0))
|
||||
.y;
|
||||
}
|
||||
|
||||
return Event::GetScreenCoords(mPresContext, mEvent, mEvent->mRefPoint).y;
|
||||
DesktopIntPoint MouseEvent::ScreenPointDesktopPix() const {
|
||||
const CSSIntPoint point = ScreenPoint(CallerType::System);
|
||||
auto scale =
|
||||
mPresContext
|
||||
? mPresContext->CSSToDevPixelScale() /
|
||||
mPresContext->DeviceContext()->GetDesktopToDeviceScale()
|
||||
: CSSToDesktopScale();
|
||||
return DesktopIntPoint::Round(point * scale);
|
||||
}
|
||||
|
||||
already_AddRefed<nsIScreen> MouseEvent::GetScreen() {
|
||||
if (mEvent->mFlags.mIsPositionless) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!mPresContext) {
|
||||
return nullptr;
|
||||
}
|
||||
nsCOMPtr<nsIScreenManager> screenMgr =
|
||||
do_GetService("@mozilla.org/gfx/screenmanager;1");
|
||||
if (!screenMgr) {
|
||||
return nullptr;
|
||||
}
|
||||
const CSSIntPoint point =
|
||||
Event::GetScreenCoords(mPresContext, mEvent, mEvent->mRefPoint);
|
||||
DesktopPoint desktopPoint =
|
||||
point * mPresContext->CSSToDevPixelScale() /
|
||||
mPresContext->DeviceContext()->GetDesktopToDeviceScale();
|
||||
return screenMgr->ScreenForRect(DesktopIntRect(
|
||||
DesktopIntPoint::Round(desktopPoint), DesktopIntSize(1, 1)));
|
||||
return screenMgr->ScreenForRect(
|
||||
DesktopIntRect(ScreenPointDesktopPix(), DesktopIntSize(1, 1)));
|
||||
}
|
||||
|
||||
int32_t MouseEvent::PageX() const {
|
||||
CSSIntPoint MouseEvent::PagePoint() const {
|
||||
if (mEvent->mFlags.mIsPositionless) {
|
||||
return 0;
|
||||
return {};
|
||||
}
|
||||
|
||||
if (mPrivateDataDuplicated) {
|
||||
return mPagePoint.x;
|
||||
return mPagePoint;
|
||||
}
|
||||
|
||||
return Event::GetPageCoords(mPresContext, mEvent, mEvent->mRefPoint,
|
||||
mClientPoint)
|
||||
.x;
|
||||
mDefaultClientPoint);
|
||||
}
|
||||
|
||||
int32_t MouseEvent::PageY() const {
|
||||
CSSIntPoint MouseEvent::ClientPoint() const {
|
||||
if (mEvent->mFlags.mIsPositionless) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (mPrivateDataDuplicated) {
|
||||
return mPagePoint.y;
|
||||
}
|
||||
|
||||
return Event::GetPageCoords(mPresContext, mEvent, mEvent->mRefPoint,
|
||||
mClientPoint)
|
||||
.y;
|
||||
}
|
||||
|
||||
int32_t MouseEvent::ClientX() {
|
||||
if (mEvent->mFlags.mIsPositionless) {
|
||||
return 0;
|
||||
return {};
|
||||
}
|
||||
|
||||
return Event::GetClientCoords(mPresContext, mEvent, mEvent->mRefPoint,
|
||||
mClientPoint)
|
||||
.x;
|
||||
mDefaultClientPoint);
|
||||
}
|
||||
|
||||
int32_t MouseEvent::ClientY() {
|
||||
CSSIntPoint MouseEvent::OffsetPoint() const {
|
||||
if (mEvent->mFlags.mIsPositionless) {
|
||||
return 0;
|
||||
return {};
|
||||
}
|
||||
|
||||
return Event::GetClientCoords(mPresContext, mEvent, mEvent->mRefPoint,
|
||||
mClientPoint)
|
||||
.y;
|
||||
}
|
||||
|
||||
int32_t MouseEvent::OffsetX() {
|
||||
if (mEvent->mFlags.mIsPositionless) {
|
||||
return 0;
|
||||
}
|
||||
return Event::GetOffsetCoords(mPresContext, mEvent, mEvent->mRefPoint,
|
||||
mClientPoint)
|
||||
.x;
|
||||
}
|
||||
|
||||
int32_t MouseEvent::OffsetY() {
|
||||
if (mEvent->mFlags.mIsPositionless) {
|
||||
return 0;
|
||||
}
|
||||
return Event::GetOffsetCoords(mPresContext, mEvent, mEvent->mRefPoint,
|
||||
mClientPoint)
|
||||
.y;
|
||||
mDefaultClientPoint);
|
||||
}
|
||||
|
||||
bool MouseEvent::AltKey() { return mEvent->AsInputEvent()->IsAlt(); }
|
||||
|
|
|
|||
|
|
@ -12,8 +12,7 @@
|
|||
#include "mozilla/dom/MouseEventBinding.h"
|
||||
#include "mozilla/EventForwards.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mozilla::dom {
|
||||
|
||||
class MouseEvent : public UIEvent {
|
||||
public:
|
||||
|
|
@ -34,15 +33,31 @@ class MouseEvent : public UIEvent {
|
|||
return Button() + 1;
|
||||
}
|
||||
|
||||
int32_t ScreenX(CallerType aCallerType);
|
||||
int32_t ScreenY(CallerType aCallerType);
|
||||
already_AddRefed<nsIScreen> GetScreen();
|
||||
int32_t PageX() const;
|
||||
int32_t PageY() const;
|
||||
int32_t ClientX();
|
||||
int32_t ClientY();
|
||||
int32_t OffsetX();
|
||||
int32_t OffsetY();
|
||||
|
||||
// In CSS coords.
|
||||
CSSIntPoint ScreenPoint(CallerType) const;
|
||||
int32_t ScreenX(CallerType aCallerType) const {
|
||||
return ScreenPoint(aCallerType).x;
|
||||
}
|
||||
int32_t ScreenY(CallerType aCallerType) const {
|
||||
return ScreenPoint(aCallerType).y;
|
||||
}
|
||||
LayoutDeviceIntPoint ScreenPointLayoutDevicePix() const;
|
||||
DesktopIntPoint ScreenPointDesktopPix() const;
|
||||
|
||||
CSSIntPoint PagePoint() const;
|
||||
int32_t PageX() const { return PagePoint().x; }
|
||||
int32_t PageY() const { return PagePoint().y; }
|
||||
|
||||
CSSIntPoint ClientPoint() const;
|
||||
int32_t ClientX() const { return ClientPoint().x; }
|
||||
int32_t ClientY() const { return ClientPoint().y; }
|
||||
|
||||
CSSIntPoint OffsetPoint() const;
|
||||
int32_t OffsetX() const { return OffsetPoint().x; }
|
||||
int32_t OffsetY() const { return OffsetPoint().y; }
|
||||
|
||||
bool CtrlKey();
|
||||
bool ShiftKey();
|
||||
bool AltKey();
|
||||
|
|
@ -91,8 +106,7 @@ class MouseEvent : public UIEvent {
|
|||
const nsAString& aModifiersList);
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
} // namespace mozilla::dom
|
||||
|
||||
already_AddRefed<mozilla::dom::MouseEvent> NS_NewDOMMouseEvent(
|
||||
mozilla::dom::EventTarget* aOwner, nsPresContext* aPresContext,
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ UIEvent::UIEvent(EventTarget* aOwner, nsPresContext* aPresContext,
|
|||
WidgetGUIEvent* aEvent)
|
||||
: Event(aOwner, aPresContext,
|
||||
aEvent ? aEvent : new InternalUIEvent(false, eVoidEvent, nullptr)),
|
||||
mClientPoint(0, 0),
|
||||
mDefaultClientPoint(0, 0),
|
||||
mLayerPoint(0, 0),
|
||||
mPagePoint(0, 0),
|
||||
mMovementPoint(0, 0),
|
||||
|
|
@ -189,12 +189,12 @@ nsIntPoint UIEvent::GetLayerPoint() const {
|
|||
}
|
||||
|
||||
void UIEvent::DuplicatePrivateData() {
|
||||
mClientPoint = Event::GetClientCoords(mPresContext, mEvent, mEvent->mRefPoint,
|
||||
mClientPoint);
|
||||
mDefaultClientPoint = Event::GetClientCoords(
|
||||
mPresContext, mEvent, mEvent->mRefPoint, mDefaultClientPoint);
|
||||
mMovementPoint = GetMovementPoint();
|
||||
mLayerPoint = GetLayerPoint();
|
||||
mPagePoint = Event::GetPageCoords(mPresContext, mEvent, mEvent->mRefPoint,
|
||||
mClientPoint);
|
||||
mDefaultClientPoint);
|
||||
// GetScreenPoint converts mEvent->mRefPoint to right coordinates.
|
||||
CSSIntPoint screenPoint =
|
||||
Event::GetScreenCoords(mPresContext, mEvent, mEvent->mRefPoint);
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ class UIEvent : public Event {
|
|||
|
||||
nsCOMPtr<nsPIDOMWindowOuter> mView;
|
||||
int32_t mDetail;
|
||||
CSSIntPoint mClientPoint;
|
||||
CSSIntPoint mDefaultClientPoint;
|
||||
// Screenpoint is mEvent->mRefPoint.
|
||||
nsIntPoint mLayerPoint;
|
||||
CSSIntPoint mPagePoint;
|
||||
|
|
|
|||
|
|
@ -336,10 +336,8 @@ nsresult nsXULPopupListener::LaunchPopup(MouseEvent* aEvent) {
|
|||
pm->ShowPopup(mPopupContent, mElement, u""_ns, 0, 0, false, true, false,
|
||||
aEvent);
|
||||
} else {
|
||||
int32_t xPos = aEvent->ScreenX(CallerType::System);
|
||||
int32_t yPos = aEvent->ScreenY(CallerType::System);
|
||||
|
||||
pm->ShowPopupAtScreen(mPopupContent, xPos, yPos, mIsContext, aEvent);
|
||||
CSSIntPoint pos = aEvent->ScreenPoint(CallerType::System);
|
||||
pm->ShowPopupAtScreen(mPopupContent, pos.x, pos.y, mIsContext, aEvent);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
|||
Loading…
Reference in a new issue