diff options
author | Kirill Burtsev <kirill.burtsev@qt.io> | 2020-11-19 18:31:11 +0100 |
---|---|---|
committer | Kirill Burtsev <kirill.burtsev@qt.io> | 2020-11-28 08:50:39 +0100 |
commit | f5800f41752c566957e269f51fe4109f64c68f01 (patch) | |
tree | d9434ad9ac2ec771282d2454bd7284d744c0ac73 | |
parent | 1f95517f7f0b91172e950552bd8b44755de38e93 (diff) |
Touch handling: fix mapped ids cleanup for TouchCancel event
TouchCancel may come with empty points list, so previous one (from TouchBegin)
is used. Therefore it should be cleaned independently on leaving the scope.
Thus unify common code cleanup in the end of handleTouchEvent and ensure
TouchCancel's ids remove from mapping.
Change-Id: I1ef2baa5f920fa9096ddac2ddd5d4ac70ab6e218
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r-- | src/core/render_widget_host_view_qt.cpp | 50 | ||||
-rw-r--r-- | src/core/render_widget_host_view_qt.h | 1 |
2 files changed, 26 insertions, 25 deletions
diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index 19b942d6f..c4a07a70c 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -99,6 +99,7 @@ #include <QKeyEvent> #include <QMouseEvent> #include <QPixmap> +#include <QScopeGuard> #include <QScreen> #include <QStyleHints> #include <QVariant> @@ -1559,12 +1560,6 @@ content::MouseWheelPhaseHandler *RenderWidgetHostViewQt::GetMouseWheelPhaseHandl return &m_mouseWheelPhaseHandler; } -void RenderWidgetHostViewQt::clearPreviousTouchMotionState() -{ - m_previousTouchPoints.clear(); - m_touchMotionStarted = false; -} - #ifndef QT_NO_GESTURES void RenderWidgetHostViewQt::handleGestureEvent(QNativeGestureEvent *ev) { @@ -1605,9 +1600,26 @@ void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev) return l.second.state() < r.second.state(); }); + auto sc = qScopeGuard([&] () { + switch (ev->type()) { + case QEvent::TouchCancel: + for (auto &&it : qAsConst(touchPoints)) + m_touchIdMapping.remove(it.second.id()); + Q_FALLTHROUGH(); + + case QEvent::TouchEnd: + m_previousTouchPoints.clear(); + m_touchMotionStarted = false; + break; + default: + m_previousTouchPoints = touchPoints; + break; + } + }); + + ui::MotionEvent::Action action; // Check first if the touch event should be routed to the selectionController if (!touchPoints.isEmpty()) { - ui::MotionEvent::Action action; switch (touchPoints[0].second.state()) { case Qt::TouchPointPressed: action = ui::MotionEvent::Action::DOWN; @@ -1622,31 +1634,25 @@ void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev) action = ui::MotionEvent::Action::NONE; break; } - - MotionEventQt motionEvent(touchPoints, eventTimestamp, action, ev->modifiers(), 0); - if (m_touchSelectionController->WillHandleTouchEvent(motionEvent)) { - m_previousTouchPoints = touchPoints; - ev->accept(); - return; - } } else { // An empty touchPoints always corresponds to a TouchCancel event. // We can't forward touch cancellations without a previously processed touch event, // as Chromium expects the previous touchPoints for Action::CANCEL. // If both are empty that means the TouchCancel was sent without an ongoing touch, // so there's nothing to cancel anyway. + Q_ASSERT(ev->type() == QEvent::TouchCancel); touchPoints = m_previousTouchPoints; if (touchPoints.isEmpty()) return; - MotionEventQt cancelEvent(touchPoints, eventTimestamp, ui::MotionEvent::Action::CANCEL, ev->modifiers()); - if (m_touchSelectionController->WillHandleTouchEvent(cancelEvent)) { - m_previousTouchPoints.clear(); - ev->accept(); - return; - } + action = ui::MotionEvent::Action::CANCEL; } + MotionEventQt me(touchPoints, eventTimestamp, action, ev->modifiers(), + action == ui::MotionEvent::Action::CANCEL ? -1 : 0); + if (m_touchSelectionController->WillHandleTouchEvent(me)) + return; + switch (ev->type()) { case QEvent::TouchBegin: m_sendMotionActionDown = true; @@ -1664,11 +1670,9 @@ void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev) processMotionEvent(cancelEvent); } - clearPreviousTouchMotionState(); return; } case QEvent::TouchEnd: - clearPreviousTouchMotionState(); m_touchSelectionControllerClient->onTouchUp(); break; default: @@ -1714,8 +1718,6 @@ void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev) MotionEventQt motionEvent(touchPoints, eventTimestamp, action, ev->modifiers(), i); processMotionEvent(motionEvent); } - - m_previousTouchPoints = touchPoints; } #if QT_CONFIG(tabletevent) diff --git a/src/core/render_widget_host_view_qt.h b/src/core/render_widget_host_view_qt.h index cbc68dca9..7b0e03241 100644 --- a/src/core/render_widget_host_view_qt.h +++ b/src/core/render_widget_host_view_qt.h @@ -237,7 +237,6 @@ private: friend class DelegatedFrameHostClientQt; void processMotionEvent(const ui::MotionEvent &motionEvent); - void clearPreviousTouchMotionState(); typedef QPair<int, QTouchEvent::TouchPoint> TouchPoint; QList<TouchPoint> mapTouchPoints(const QList<QTouchEvent::TouchPoint> &input); |