From 09a341f4a62a0fe244dc188a75d77d0067ad1fe7 Mon Sep 17 00:00:00 2001 From: Christophe Chapuis Date: Tue, 13 Oct 2015 23:15:51 +0200 Subject: Fix touch events coordinates when using custom devicePixelRatio Task-number: QTBUG-48766 Change-Id: Idcae6dc84829fe96db62c6cb30ab193873d36709 Reviewed-by: Kai Koehne Reviewed-by: Joerg Bornemann --- src/core/render_widget_host_view_qt.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/core/render_widget_host_view_qt.cpp') diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index 572bc340c..7c5ed64e7 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -182,12 +182,13 @@ static inline int flagsFromModifiers(Qt::KeyboardModifiers modifiers) class MotionEventQt : public ui::MotionEvent { public: - MotionEventQt(const QList &touchPoints, const base::TimeTicks &eventTime, Action action, const Qt::KeyboardModifiers modifiers, int index = -1) + MotionEventQt(const QList &touchPoints, const base::TimeTicks &eventTime, Action action, const Qt::KeyboardModifiers modifiers, float dpiScale, int index = -1) : touchPoints(touchPoints) , eventTime(eventTime) , action(action) , flags(flagsFromModifiers(modifiers)) , index(index) + , dpiScale(dpiScale) { // ACTION_DOWN and ACTION_UP must be accesssed through pointer_index 0 Q_ASSERT((action != ACTION_DOWN && action != ACTION_UP) || index == 0); @@ -198,8 +199,8 @@ public: virtual int GetActionIndex() const Q_DECL_OVERRIDE { return index; } virtual size_t GetPointerCount() const Q_DECL_OVERRIDE { return touchPoints.size(); } virtual int GetPointerId(size_t pointer_index) const Q_DECL_OVERRIDE { return touchPoints.at(pointer_index).id(); } - virtual float GetX(size_t pointer_index) const Q_DECL_OVERRIDE { return touchPoints.at(pointer_index).pos().x(); } - virtual float GetY(size_t pointer_index) const Q_DECL_OVERRIDE { return touchPoints.at(pointer_index).pos().y(); } + virtual float GetX(size_t pointer_index) const Q_DECL_OVERRIDE { return touchPoints.at(pointer_index).pos().x() / dpiScale; } + virtual float GetY(size_t pointer_index) const Q_DECL_OVERRIDE { return touchPoints.at(pointer_index).pos().y() / dpiScale; } virtual float GetRawX(size_t pointer_index) const Q_DECL_OVERRIDE { return touchPoints.at(pointer_index).screenPos().x(); } virtual float GetRawY(size_t pointer_index) const Q_DECL_OVERRIDE { return touchPoints.at(pointer_index).screenPos().y(); } virtual float GetTouchMajor(size_t pointer_index) const Q_DECL_OVERRIDE @@ -234,6 +235,7 @@ private: Action action; int flags; int index; + float dpiScale; }; RenderWidgetHostViewQt::RenderWidgetHostViewQt(content::RenderWidgetHost* widget) @@ -999,7 +1001,7 @@ void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev) QList touchPoints = mapTouchPointIds(ev->touchPoints()); if (ev->type() == QEvent::TouchCancel) { - MotionEventQt cancelEvent(touchPoints, eventTimestamp, ui::MotionEvent::ACTION_CANCEL, ev->modifiers()); + MotionEventQt cancelEvent(touchPoints, eventTimestamp, ui::MotionEvent::ACTION_CANCEL, ev->modifiers(), dpiScale()); processMotionEvent(cancelEvent); return; } @@ -1032,7 +1034,7 @@ void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev) continue; } - MotionEventQt motionEvent(touchPoints, eventTimestamp, action, ev->modifiers(), i); + MotionEventQt motionEvent(touchPoints, eventTimestamp, action, ev->modifiers(), dpiScale(), i); processMotionEvent(motionEvent); } } -- cgit v1.2.3