diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2021-05-12 23:22:11 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2021-05-20 22:51:55 +0200 |
commit | b09ce7dcd8ecf24ef23da8197a64e3fced3fc894 (patch) | |
tree | 2effcad3c18f63ca7ace2ae8cf4da2f0fd33121a /tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp | |
parent | e685d061621f0c55ed8c6ea29ea1380af03f8c1c (diff) | |
download | qtdeclarative-b09ce7dcd8ecf24ef23da8197a64e3fced3fc894.tar.gz |
Don't let PointerHandler steal mouse grab from keepMouseGrab layer
As explained in the comment, the handler can override the keepMouseGrab
"veto" if the item is a parent (like a Flickable) that filters events,
but not in other cases. The logic was wrong though, apparently.
Amends 090f404cf80da35734f712b02cc1543acecd5b62
Pick-to: 5.15 6.1
Fixes: QTBUG-78258
Task-number: QTBUG-79163
Change-Id: I9a473ab3b23743f863cb0be13767fdbc29cd5e1c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp')
-rw-r--r-- | tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp b/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp index 4fd8fc01e3..b6c86a7d88 100644 --- a/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp +++ b/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp @@ -70,6 +70,7 @@ private slots: void touchPassiveGrabbers(); void touchPinchAndMouseMove(); void unsuitableEventDuringDrag(); + void underModalLayer(); private: void sendWheelEvent(QQuickView &window, QPoint pos, QPoint angleDelta, QPoint pixelDelta, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, bool inverted); @@ -894,6 +895,59 @@ void tst_DragHandler::sendWheelEvent(QQuickView &window, QPoint pos, QPoint angl QQuickTouchUtils::flush(&window); } +class ModalLayer : public QQuickItem { +public: + explicit ModalLayer(QQuickItem* parent = nullptr) : QQuickItem(parent) { + this->setAcceptedMouseButtons(Qt::AllButtons); + this->setAcceptTouchEvents(true); + this->setKeepMouseGrab(true); + this->setKeepTouchGrab(true); + } + + bool event(QEvent* event) override { + switch (event->type()) { + case QEvent::KeyPress: + case QEvent::MouseMove: + case QEvent::MouseButtonPress: + case QEvent::MouseButtonRelease: + case QEvent::MouseTrackingChange: + case QEvent::MouseButtonDblClick: + case QEvent::Wheel: + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + case QEvent::TouchCancel: + case QEvent::TouchEnd: { + qCDebug(lcPointerTests) << "BLOCK!" << event->type(); + return true; + } + default: break; + } + return QQuickItem::event(event); + } +}; + +void tst_DragHandler::underModalLayer() // QTBUG-78258 +{ + qmlRegisterType<ModalLayer>("Test", 1, 0, "ModalLayer"); + + const int dragThreshold = QGuiApplication::styleHints()->startDragDistance(); + QScopedPointer<QQuickView> windowPtr; + createView(windowPtr, "dragHandlerUnderModalLayer.qml"); + QQuickView * window = windowPtr.data(); + QPointer<QQuickDragHandler> dragHandler = window->rootObject()->findChild<QQuickDragHandler*>(); + QVERIFY(dragHandler); + + QPoint p1(250, 250); + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, p1); + p1 += QPoint(dragThreshold, dragThreshold); + QTest::mouseMove(window, p1); + QVERIFY(!dragHandler->active()); + p1 += QPoint(dragThreshold, dragThreshold); + QTest::mouseMove(window, p1); + QVERIFY(!dragHandler->active()); + QTest::mouseRelease(window, Qt::LeftButton); +} + QTEST_MAIN(tst_DragHandler) #include "tst_qquickdraghandler.moc" |