From 0533725c60198aeced54ad53454a09a3b3691394 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 27 Sep 2021 17:48:55 +0200 Subject: Flickable: don't react to any mouse button other than the left In case of mouse "chording", ignore all other buttons. Fixes: QTBUG-96909 Change-Id: Ib091b271390c5b4e3aafbbe24d2dc7b6f08db175 Reviewed-by: Richard Moe Gustavsen Reviewed-by: Fabian Kosmale (cherry picked from commit f91aa3b4d8ae7bfba65a8252099ded3b428f7acf) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/quick/qquickflickable/data/dragon.qml | 15 +++++++ .../quick/qquickflickable/tst_qquickflickable.cpp | 50 ++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 tests/auto/quick/qquickflickable/data/dragon.qml (limited to 'tests/auto') diff --git a/tests/auto/quick/qquickflickable/data/dragon.qml b/tests/auto/quick/qquickflickable/data/dragon.qml new file mode 100644 index 0000000000..b82477453b --- /dev/null +++ b/tests/auto/quick/qquickflickable/data/dragon.qml @@ -0,0 +1,15 @@ +import QtQuick 2.12 + +Flickable { + id: flick + width: 320 + height: 320 + contentWidth: 500 + contentHeight: 500 + Text { + anchors.centerIn: parent + font.pixelSize: 50 + text: "🐉" + color: flick.dragging ? "orange" : "grey" + } +} diff --git a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp index 57c9dda230..2146836048 100644 --- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp +++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp @@ -205,6 +205,8 @@ private slots: void synchronousDrag(); void visibleAreaBinding(); void parallelTouch(); + void ignoreNonLeftMouseButtons(); + void ignoreNonLeftMouseButtons_data(); private: void flickWithTouch(QQuickWindow *window, const QPoint &from, const QPoint &to); @@ -2649,6 +2651,54 @@ void tst_qquickflickable::parallelTouch() // QTBUG-30840 QTRY_VERIFY(!flickable2->isMoving()); } +void tst_qquickflickable::ignoreNonLeftMouseButtons() // QTBUG-96909 +{ + QFETCH(Qt::MouseButton, otherButton); + const int threshold = qApp->styleHints()->startDragDistance(); + QQuickView view; + view.setSource(testFileUrl("dragon.qml")); + view.show(); + view.requestActivate(); + QQuickFlickable *flickable = static_cast(view.rootObject()); + QSignalSpy dragSpy(flickable, &QQuickFlickable::draggingChanged); + + // Drag with left button + QPoint p1(100, 100); + moveAndPress(&view, p1); + for (int i = 0; i < 8; ++i) { + p1 -= QPoint(threshold, threshold); + QTest::mouseMove(&view, p1, 50); + } + QVERIFY(flickable->isDragging()); + QCOMPARE(dragSpy.count(), 1); + + // Press other button too, then release left button: dragging changes to false + QTest::mousePress(&view, otherButton); + QTest::mouseRelease(&view, Qt::LeftButton); + QTRY_COMPARE(flickable->isDragging(), false); + QCOMPARE(dragSpy.count(), 2); + + // Drag further with the other button held: Flickable ignores it + for (int i = 0; i < 8; ++i) { + p1 -= QPoint(threshold, threshold); + QTest::mouseMove(&view, p1, 50); + } + QCOMPARE(flickable->isDragging(), false); + QCOMPARE(dragSpy.count(), 2); + + // Release other button: nothing happens + QTest::mouseRelease(&view, otherButton); + QCOMPARE(dragSpy.count(), 2); +} + +void tst_qquickflickable::ignoreNonLeftMouseButtons_data() +{ + QTest::addColumn("otherButton"); + + QTest::newRow("right") << Qt::RightButton; + QTest::newRow("middle") << Qt::MiddleButton; +} + QTEST_MAIN(tst_qquickflickable) #include "tst_qquickflickable.moc" -- cgit v1.2.3