From 339c9349a8bcd6242574fba8b557729b2b29ff79 Mon Sep 17 00:00:00 2001 From: Jocelyn Turcotte Date: Fri, 19 Sep 2014 14:44:00 +0200 Subject: Bring back the mapping of touch IDs to fix flinging This logic was removed in 3a30ed4ecc9c828641daef85f88f93baf78826b6 but was still needed by the velocity tracker used for fling gestures. Also disable swipe gestures in the gesture config since they have unwanted side-effects on the gesture detection and we don't use them. Change-Id: Icbb44a4c27e2cd243d631484d03a956e9dce64dc Reviewed-by: Andras Becsi --- src/core/render_widget_host_view_qt.cpp | 46 ++++++++++++++++++++++++++++----- src/core/render_widget_host_view_qt.h | 3 +++ 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index 0c015f39c..b809f0a0a 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -115,17 +115,28 @@ static inline Qt::InputMethodHints toQtInputMethodHints(ui::TextInputType inputT } } +static inline int firstAvailableId(const QMap &map) +{ + ui::BitSet32 usedIds; + QMap::const_iterator end = map.end(); + for (QMap::const_iterator it = map.begin(); it != end; ++it) + usedIds.mark_bit(it.value()); + return usedIds.first_unmarked_bit(); +} + static inline ui::GestureProvider::Config QtGestureProviderConfig() { ui::GestureProvider::Config config = ui::DefaultGestureProviderConfig(); // Causes an assert in CreateWebGestureEventFromGestureEventData and we don't need them in Qt. config.gesture_begin_end_types_enabled = false; + // Swipe gestures aren't forwarded, we don't use them and they abort the gesture detection. + config.scale_gesture_detector_config.gesture_detector_config.swipe_enabled = config.gesture_detector_config.swipe_enabled = false; return config; } class MotionEventQt : public ui::MotionEvent { public: - MotionEventQt(QTouchEvent *ev, const base::TimeTicks &eventTime, Action action, int index = -1) - : touchPoints(ev->touchPoints()) + MotionEventQt(const QList &touchPoints, const base::TimeTicks &eventTime, Action action, int index = -1) + : touchPoints(touchPoints) , eventTime(eventTime) , action(action) , index(index) @@ -770,6 +781,25 @@ void RenderWidgetHostViewQt::processMotionEvent(const ui::MotionEvent &motionEve m_host->ForwardTouchEvent(content::CreateWebTouchEventFromMotionEvent(motionEvent)); } +QList RenderWidgetHostViewQt::mapTouchPointIds(const QList &inputPoints) +{ + QList outputPoints = inputPoints; + for (int i = 0; i < outputPoints.size(); ++i) { + QTouchEvent::TouchPoint &point = outputPoints[i]; + + int qtId = point.id(); + QMap::const_iterator it = m_touchIdMapping.find(qtId); + if (it == m_touchIdMapping.end()) + it = m_touchIdMapping.insert(qtId, firstAvailableId(m_touchIdMapping)); + point.setId(it.value()); + + if (point.state() == Qt::TouchPointReleased) + m_touchIdMapping.remove(qtId); + } + + return outputPoints; +} + float RenderWidgetHostViewQt::dpiScale() const { return m_adapterClient ? m_adapterClient->dpiScale() : 1.0; @@ -940,8 +970,10 @@ void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev) m_eventsToNowDelta = base::TimeTicks::Now() - eventTimestamp; eventTimestamp += m_eventsToNowDelta; + QList touchPoints = mapTouchPointIds(ev->touchPoints()); + if (ev->type() == QEvent::TouchCancel) { - MotionEventQt cancelEvent(ev, eventTimestamp, ui::MotionEvent::ACTION_CANCEL); + MotionEventQt cancelEvent(touchPoints, eventTimestamp, ui::MotionEvent::ACTION_CANCEL); processMotionEvent(cancelEvent); return; } @@ -949,9 +981,9 @@ void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev) if (ev->type() == QEvent::TouchBegin) m_sendMotionActionDown = true; - for (int i = 0; i < ev->touchPoints().size(); ++i) { + for (int i = 0; i < touchPoints.size(); ++i) { ui::MotionEvent::Action action; - switch (ev->touchPoints()[i].state()) { + switch (touchPoints[i].state()) { case Qt::TouchPointPressed: if (m_sendMotionActionDown) { action = ui::MotionEvent::ACTION_DOWN; @@ -963,14 +995,14 @@ void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev) action = ui::MotionEvent::ACTION_MOVE; break; case Qt::TouchPointReleased: - action = ev->touchPoints().size() > 1 ? ui::MotionEvent::ACTION_POINTER_UP : ui::MotionEvent::ACTION_UP; + action = touchPoints.size() > 1 ? ui::MotionEvent::ACTION_POINTER_UP : ui::MotionEvent::ACTION_UP; break; default: // Ignore Qt::TouchPointStationary continue; } - MotionEventQt motionEvent(ev, eventTimestamp, action, i); + MotionEventQt motionEvent(touchPoints, eventTimestamp, action, i); processMotionEvent(motionEvent); } } diff --git a/src/core/render_widget_host_view_qt.h b/src/core/render_widget_host_view_qt.h index 301ff2df9..d4a3ff248 100644 --- a/src/core/render_widget_host_view_qt.h +++ b/src/core/render_widget_host_view_qt.h @@ -45,6 +45,7 @@ #include "content/browser/accessibility/browser_accessibility_manager.h" #include "content/browser/renderer_host/render_widget_host_view_base.h" #include "ui/events/gesture_detection/filtered_gesture_provider.h" +#include #include #include #include @@ -221,6 +222,7 @@ public: private: void sendDelegatedFrameAck(); void processMotionEvent(const ui::MotionEvent &motionEvent); + QList mapTouchPointIds(const QList &inputPoints); float dpiScale() const; bool IsPopup() const; @@ -230,6 +232,7 @@ private: ui::FilteredGestureProvider m_gestureProvider; base::TimeDelta m_eventsToNowDelta; bool m_sendMotionActionDown; + QMap m_touchIdMapping; scoped_ptr m_delegate; QExplicitlySharedDataPointer m_frameNodeData; -- cgit v1.2.3