diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index bfa37f44a39..86e9bd8223f 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -2533,6 +2533,20 @@ nsWindow::OnLeaveNotifyEvent(GdkEventCrossing *aEvent) DispatchInputEvent(&event); } +template static LayoutDeviceIntPoint +GetRefPoint(nsWindow* aWindow, Event* aEvent) +{ + if (aEvent->window == aWindow->GetGdkWindow()) { + // we are the window that the event happened on so no need for expensive WidgetToScreenOffset + return aWindow->GdkEventCoordsToDevicePixels(aEvent->x, aEvent->y); + } + // XXX we're never quite sure which GdkWindow the event came from due to our custom bubbling + // in scroll_event_cb(), so use ScreenToWidget to translate the screen root coordinates into + // coordinates relative to this widget. + return aWindow->GdkEventCoordsToDevicePixels( + aEvent->x_root, aEvent->y_root) - aWindow->WidgetToScreenOffset(); +} + void nsWindow::OnMotionNotifyEvent(GdkEventMotion *aEvent) { @@ -2593,16 +2607,8 @@ nsWindow::OnMotionNotifyEvent(GdkEventMotion *aEvent) event.time = aEvent->time; event.timeStamp = GetEventTimeStamp(aEvent->time); #endif /* MOZ_X11 */ - } - else { - // XXX see OnScrollEvent() - if (aEvent->window == mGdkWindow) { - event.refPoint = GdkEventCoordsToDevicePixels(aEvent->x, aEvent->y); - } else { - LayoutDeviceIntPoint point = GdkEventCoordsToDevicePixels( - aEvent->x_root, aEvent->y_root); - event.refPoint = point - WidgetToScreenOffset(); - } + } else { + event.refPoint = GetRefPoint(this, aEvent); modifierState = aEvent->state; @@ -2671,14 +2677,7 @@ void nsWindow::InitButtonEvent(WidgetMouseEvent& aEvent, GdkEventButton* aGdkEvent) { - // XXX see OnScrollEvent() - if (aGdkEvent->window == mGdkWindow) { - aEvent.refPoint = GdkEventCoordsToDevicePixels(aGdkEvent->x, aGdkEvent->y); - } else { - LayoutDeviceIntPoint point = GdkEventCoordsToDevicePixels( - aGdkEvent->x_root, aGdkEvent->y_root); - aEvent.refPoint = point - WidgetToScreenOffset(); - } + aEvent.refPoint = GetRefPoint(this, aGdkEvent); guint modifierState = aGdkEvent->state; // aEvent's state doesn't include this event's information. Therefore, @@ -3193,17 +3192,7 @@ nsWindow::OnScrollEvent(GdkEventScroll *aEvent) break; } - if (aEvent->window == mGdkWindow) { - // we are the window that the event happened on so no need for expensive WidgetToScreenOffset - wheelEvent.refPoint = GdkEventCoordsToDevicePixels(aEvent->x, aEvent->y); - } else { - // XXX we're never quite sure which GdkWindow the event came from due to our custom bubbling - // in scroll_event_cb(), so use ScreenToWidget to translate the screen root coordinates into - // coordinates relative to this widget. - LayoutDeviceIntPoint point = GdkEventCoordsToDevicePixels( - aEvent->x_root, aEvent->y_root); - wheelEvent.refPoint = point - WidgetToScreenOffset(); - } + wheelEvent.refPoint = GetRefPoint(this, aEvent); KeymapWrapper::InitInputEvent(wheelEvent, aEvent->state); @@ -3411,13 +3400,7 @@ nsWindow::OnTouchEvent(GdkEventTouch* aEvent) return FALSE; } - LayoutDeviceIntPoint touchPoint; - if (aEvent->window == mGdkWindow) { - touchPoint = LayoutDeviceIntPoint(aEvent->x, aEvent->y); - } else { - touchPoint = LayoutDeviceIntPoint(aEvent->x_root, aEvent->y_root) - - WidgetToScreenOffset(); - } + LayoutDeviceIntPoint touchPoint = GetRefPoint(this, aEvent); int32_t id; RefPtr touch; diff --git a/widget/gtk/nsWindow.h b/widget/gtk/nsWindow.h index 8125b48a0c7..e3765e2f3e4 100644 --- a/widget/gtk/nsWindow.h +++ b/widget/gtk/nsWindow.h @@ -335,6 +335,21 @@ public: uint32_t aAdditionalFlags, nsIObserver* aObserver) override; + // HiDPI scale conversion + gint GdkScaleFactor(); + + // To GDK + gint DevicePixelsToGdkCoordRoundUp(int pixels); + gint DevicePixelsToGdkCoordRoundDown(int pixels); + GdkPoint DevicePixelsToGdkPointRoundDown(nsIntPoint point); + GdkRectangle DevicePixelsToGdkSizeRoundUp(nsIntSize pixelSize); + + // From GDK + int GdkCoordToDevicePixels(gint coord); + mozilla::LayoutDeviceIntPoint GdkPointToDevicePixels(GdkPoint point); + mozilla::LayoutDeviceIntPoint GdkEventCoordsToDevicePixels(gdouble x, gdouble y); + nsIntRect GdkRectToDevicePixels(GdkRectangle rect); + protected: virtual ~nsWindow(); @@ -528,21 +543,6 @@ private: RefPtr mIMContext; nsAutoPtr mCurrentTimeGetter; - - // HiDPI scale conversion - gint GdkScaleFactor(); - - // To GDK - gint DevicePixelsToGdkCoordRoundUp(int pixels); - gint DevicePixelsToGdkCoordRoundDown(int pixels); - GdkPoint DevicePixelsToGdkPointRoundDown(nsIntPoint point); - GdkRectangle DevicePixelsToGdkSizeRoundUp(nsIntSize pixelSize); - - // From GDK - int GdkCoordToDevicePixels(gint coord); - mozilla::LayoutDeviceIntPoint GdkPointToDevicePixels(GdkPoint point); - mozilla::LayoutDeviceIntPoint GdkEventCoordsToDevicePixels(gdouble x, gdouble y); - nsIntRect GdkRectToDevicePixels(GdkRectangle rect); }; class nsChildWindow : public nsWindow {