summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-12-07 23:02:03 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2021-12-11 00:51:10 +0100
commit9da1f6b6080b667f7e879f953441b713ccff656b (patch)
treeac3bde4f50f599cec222126418e8423deb6f8f74
parent4229de1685dd0a671f332faf7bfed3ffe5cd8a87 (diff)
Fix widget gesture grabbing
After 7369c31ca1f446e81eda1c93ba13767ffcd83efe, unaccepted touch points were not grabbed anymore in calls to activateImplicitTouchGrab. However, gesture recognition relies that widgets for which a gesture has been partially recognized grab also unaccepted touch points. Add a parameter to allow the implicit grabbing to take place also for unaccepted event points. Add test case that replays touch events similar to what Squish is doing, and fails without this fix. Pick-to: 6.2 Change-Id: Idb0b20301b1827be57a03013a59043d97c2ee7b6 Reviewed-by: Stefan Gehn <stefan.gehn@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/widgets/kernel/qapplication.cpp13
-rw-r--r--src/widgets/kernel/qapplication_p.h4
-rw-r--r--tests/auto/widgets/kernel/qgesturerecognizer/tst_qgesturerecognizer.cpp20
3 files changed, 31 insertions, 6 deletions
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index 0fa3c6a3d7..fa381e796c 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -3159,8 +3159,9 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
#ifndef QT_NO_GESTURES
if (!eventAccepted && !gesturePendingWidget.isNull()) {
- // the first widget subscribed to a gesture gets an implicit grab
- d->activateImplicitTouchGrab(gesturePendingWidget, touchEvent);
+ // the first widget subscribed to a gesture gets an implicit grab for all
+ // points, also for events and event points that have not been accepted.
+ d->activateImplicitTouchGrab(gesturePendingWidget, touchEvent, QApplicationPrivate::GrabAllPoints);
}
#endif
@@ -3851,16 +3852,18 @@ QWidget *QApplicationPrivate::findClosestTouchPointTarget(const QPointingDevice
return static_cast<QWidget *>(closestTarget);
}
-void QApplicationPrivate::activateImplicitTouchGrab(QWidget *widget, QTouchEvent *touchEvent)
+void QApplicationPrivate::activateImplicitTouchGrab(QWidget *widget, QTouchEvent *touchEvent,
+ ImplicitTouchGrabMode grabMode)
{
if (touchEvent->type() != QEvent::TouchBegin)
return;
// If the widget dispatched the event further (see QGraphicsProxyWidget), then
- // there might already be an implicit grabber. Don't override that.
+ // there might already be an implicit grabber. Don't override that. A widget that
+ // has partially recognized a gesture needs to grab all points.
for (int i = 0; i < touchEvent->pointCount(); ++i) {
auto &mep = QMutableEventPoint::from(touchEvent->point(i));
- if (!mep.target() && mep.isAccepted())
+ if (!mep.target() && (mep.isAccepted() || grabMode == GrabAllPoints))
mep.setTarget(widget);
}
// TODO setExclusiveGrabber() to be consistent with Qt Quick?
diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h
index 6bb1f35d1b..155081fd79 100644
--- a/src/widgets/kernel/qapplication_p.h
+++ b/src/widgets/kernel/qapplication_p.h
@@ -248,7 +248,9 @@ public:
QWidget *findClosestTouchPointTarget(const QPointingDevice *device, const QEventPoint &touchPoint);
void appendTouchPoint(const QEventPoint &touchPoint);
void removeTouchPoint(int touchPointId);
- void activateImplicitTouchGrab(QWidget *widget, QTouchEvent *touchBeginEvent);
+ enum ImplicitTouchGrabMode { GrabAcceptedPoints, GrabAllPoints };
+ void activateImplicitTouchGrab(QWidget *widget, QTouchEvent *touchBeginEvent,
+ ImplicitTouchGrabMode grabMode = GrabAcceptedPoints);
static bool translateRawTouchEvent(QWidget *widget, const QTouchEvent *touchEvent);
static void translateTouchCancel(const QPointingDevice *device, ulong timestamp);
diff --git a/tests/auto/widgets/kernel/qgesturerecognizer/tst_qgesturerecognizer.cpp b/tests/auto/widgets/kernel/qgesturerecognizer/tst_qgesturerecognizer.cpp
index b65f6a5ff6..9687601158 100644
--- a/tests/auto/widgets/kernel/qgesturerecognizer/tst_qgesturerecognizer.cpp
+++ b/tests/auto/widgets/kernel/qgesturerecognizer/tst_qgesturerecognizer.cpp
@@ -53,6 +53,7 @@ private Q_SLOTS:
void pinchGesture();
void swipeGesture_data();
void swipeGesture();
+ void touchReplay();
#endif // !QT_NO_GESTURES
private:
@@ -326,6 +327,25 @@ void tst_QGestureRecognizer::swipeGesture()
}
}
+void tst_QGestureRecognizer::touchReplay()
+{
+ const Qt::GestureType gestureType = Qt::TapGesture;
+ QWidget parent;
+ TestWidget widget(GestureTypeVector(1, gestureType));
+ widget.setParent(&parent);
+ widget.setGeometry(0, 0, 100, 100);
+ parent.adjustSize();
+ parent.show();
+ QVERIFY(QTest::qWaitForWindowActive(&parent));
+
+ QWindow* windowHandle = parent.window()->windowHandle();
+ const QPoint globalPos = QPoint(42, 16);
+ QTest::touchEvent(windowHandle, m_touchDevice).press(1, globalPos);
+ QTest::touchEvent(windowHandle, m_touchDevice).release(1, globalPos);
+
+ QVERIFY(widget.gestureReceived(gestureType));
+}
+
#endif // !QT_NO_GESTURES
QTEST_MAIN(tst_QGestureRecognizer)