aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Arve Saether <jan-arve.saether@qt.io>2017-06-22 10:12:56 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2018-01-31 08:26:32 +0000
commit6a7c662bd5f7fe4a223aba2e15bb24a9ffc92df6 (patch)
treee50095e8b210bdcee0c3a35b31fc11faf1a4574f
parente447285925623c40f5ddce65fa20e16333c75de0 (diff)
Do not stop delivering to handlers if all points are accepted
Some Pointer Handlers can perform the desired interaction using only passive grabs. When such a handler is used to modify behavior of another event-handling Item or Handler which needs to take the exclusive grab, this allows them to cooperate: both can see the updates, and neither prevents delivery of events to both. Change-Id: I312cc301c52fcdf805245bbe0ac60fd28f92c01f Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r--src/quick/items/qquickwindow.cpp8
-rw-r--r--tests/auto/quick/pointerhandlers/qquickdraghandler/data/simpleTapAndDragHandlers.qml112
-rw-r--r--tests/auto/quick/pointerhandlers/qquickdraghandler/qquickdraghandler.pro8
-rw-r--r--tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp85
-rw-r--r--tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp15
5 files changed, 212 insertions, 16 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp
index 2d0f1218bf..8582dd8d2c 100644
--- a/src/quick/items/qquickwindow.cpp
+++ b/src/quick/items/qquickwindow.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQuick module of the Qt Toolkit.
@@ -2422,8 +2422,6 @@ void QQuickWindowPrivate::deliverUpdatedTouchPoints(QQuickPointerTouchEvent *eve
done = true;
event->localize(receiver);
handler->handlePointerEvent(event);
- if (event->allPointsAccepted())
- done = true;
}
if (done)
break;
@@ -2524,8 +2522,6 @@ void QQuickWindowPrivate::deliverMatchingPointsToItem(QQuickItem *item, QQuickPo
}
if (handlersOnly)
return;
- if (pointerEvent->allPointsAccepted() && !pointerEvent->isReleaseEvent())
- return;
// If all points are released and the item is not the grabber, it doesn't get the event.
// But if at least one point is still pressed, we might be in a potential gesture-takeover scenario.
@@ -2537,8 +2533,6 @@ void QQuickWindowPrivate::deliverMatchingPointsToItem(QQuickItem *item, QQuickPo
auto event = pointerEvent->asPointerMouseEvent();
if (event && item->acceptedMouseButtons() & event->button()) {
auto point = event->point(0);
- if (point->isAccepted())
- return;
// The only reason to already have a mouse grabber here is
// synthetic events - flickable sends one when setPressDelay is used.
auto oldMouseGrabber = q->mouseGrabberItem();
diff --git a/tests/auto/quick/pointerhandlers/qquickdraghandler/data/simpleTapAndDragHandlers.qml b/tests/auto/quick/pointerhandlers/qquickdraghandler/data/simpleTapAndDragHandlers.qml
new file mode 100644
index 0000000000..adb8332213
--- /dev/null
+++ b/tests/auto/quick/pointerhandlers/qquickdraghandler/data/simpleTapAndDragHandlers.qml
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the manual tests of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.8
+import Qt.labs.handlers 1.0
+
+Rectangle {
+ id: root
+ width: 900
+ height: 850
+ objectName: "root"
+ color: "#222222"
+
+ Row {
+ objectName: "row"
+ anchors.fill: parent
+ spacing: 10
+ Rectangle {
+ width: 50
+ height: 50
+ color: "aqua"
+ objectName: "dragAndTap"
+ DragHandler {
+ objectName: "drag"
+ }
+ TapHandler {
+ objectName: "tap"
+ gesturePolicy: TapHandler.DragThreshold
+ }
+ }
+ Rectangle {
+ width: 50
+ height: 50
+ color: "aqua"
+ objectName: "tapAndDrag"
+ TapHandler {
+ objectName: "tap"
+ gesturePolicy: TapHandler.DragThreshold
+ }
+ DragHandler {
+ objectName: "drag"
+ }
+ }
+
+ Rectangle {
+ color: "aqua"
+ width: 50
+ height: 50
+ objectName: "dragAndTapNotSiblings"
+ DragHandler {
+ objectName: "drag"
+ }
+ Rectangle {
+ color: "blue"
+ width: 30
+ height: 30
+ anchors.centerIn: parent
+ TapHandler {
+ objectName: "tap"
+ gesturePolicy: TapHandler.DragThreshold
+ }
+ }
+ }
+ Rectangle {
+ color: "aqua"
+ width: 50
+ height: 50
+ objectName: "tapAndDragNotSiblings"
+ TapHandler {
+ objectName: "tap"
+ gesturePolicy: TapHandler.DragThreshold
+ }
+ Rectangle {
+ color: "blue"
+ x: 10
+ y: 10
+ width: 30
+ height: 30
+ DragHandler {
+ objectName: "drag"
+ }
+ }
+ }
+
+
+ }
+}
diff --git a/tests/auto/quick/pointerhandlers/qquickdraghandler/qquickdraghandler.pro b/tests/auto/quick/pointerhandlers/qquickdraghandler/qquickdraghandler.pro
index b50fe5ca6f..42c4e46c4f 100644
--- a/tests/auto/quick/pointerhandlers/qquickdraghandler/qquickdraghandler.pro
+++ b/tests/auto/quick/pointerhandlers/qquickdraghandler/qquickdraghandler.pro
@@ -12,4 +12,10 @@ include (../../shared/util.pri)
TESTDATA = data/*
-# OTHER_FILES += data/foo.qml
+OTHER_FILES += data/DragAnywhereSlider.qml \
+ data/FlashAnimation.qml \
+ data/Slider.qml \
+ data/draggables.qml \
+ data/grabberstate.qml \
+ data/multipleSliders.qml \
+ data/reparenting.qml \
diff --git a/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp b/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp
index 8dc035949e..f827b82205 100644
--- a/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp
+++ b/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQml module of the Qt Toolkit.
@@ -58,9 +58,12 @@ private slots:
void touchDragMulti();
void touchDragMultiSliders_data();
void touchDragMultiSliders();
+ void touchPassiveGrabbers_data();
+ void touchPassiveGrabbers();
private:
void createView(QScopedPointer<QQuickView> &window, const char *fileName);
+ QSet<QQuickPointerHandler *> passiveGrabbers(QQuickWindow *window, int pointId = 0);
QTouchDevice *touchDevice;
};
@@ -77,6 +80,24 @@ void tst_DragHandler::createView(QScopedPointer<QQuickView> &window, const char
QVERIFY(window->rootObject() != 0);
}
+QSet<QQuickPointerHandler*> tst_DragHandler::passiveGrabbers(QQuickWindow *window, int pointId /*= 0*/)
+{
+ QSet<QQuickPointerHandler*> result;
+ QQuickWindowPrivate *winp = QQuickWindowPrivate::get(window);
+ if (QQuickPointerDevice* device = QQuickPointerDevice::touchDevice(touchDevice)) {
+ QQuickPointerEvent *pointerEvent = winp->pointerEventInstance(device);
+ for (int i = 0; i < pointerEvent->pointCount(); ++i) {
+ QQuickEventPoint *eventPoint = pointerEvent->point(i);
+ QVector<QPointer <QQuickPointerHandler> > passives = eventPoint->passiveGrabbers();
+ if (!pointId || eventPoint->pointId() == pointId) {
+ for (auto it = passives.constBegin(); it != passives.constEnd(); ++it)
+ result << it->data();
+ }
+ }
+ }
+ return result;
+}
+
void tst_DragHandler::initTestCase()
{
// This test assumes that we don't get synthesized mouse events from QGuiApplication
@@ -398,6 +419,68 @@ void tst_DragHandler::touchDragMultiSliders()
touch.commit();
}
+void tst_DragHandler::touchPassiveGrabbers_data()
+{
+ QTest::addColumn<QString>("itemName");
+ QTest::addColumn<QStringList>("expectedPassiveGrabberNames");
+
+ QTest::newRow("Drag And Tap") << "dragAndTap" << QStringList({"drag", "tap"});
+ QTest::newRow("Tap And Drag") << "tapAndDrag" << QStringList({"tap", "drag"});
+ QTest::newRow("Drag And Tap (not siblings)") << "dragAndTapNotSiblings" << QStringList({"drag", "tap"});
+ QTest::newRow("Tap And Drag (not siblings)") << "tapAndDragNotSiblings" << QStringList({"tap", "drag"});
+}
+
+void tst_DragHandler::touchPassiveGrabbers()
+{
+ QFETCH(QString, itemName);
+ QFETCH(QStringList, expectedPassiveGrabberNames);
+
+ QScopedPointer<QQuickView> windowPtr;
+ createView(windowPtr, "simpleTapAndDragHandlers.qml");
+ QQuickView * window = windowPtr.data();
+
+ QQuickItem *row2 = window->rootObject()->findChild<QQuickItem*>(itemName);
+ QSet<QQuickPointerHandler *> expectedPassiveGrabbers;
+ for (QString objectName : expectedPassiveGrabberNames)
+ expectedPassiveGrabbers << row2->findChild<QQuickPointerHandler*>(objectName);
+
+ QPointF p1 = row2->mapToScene(row2->clipRect().center());
+ QTest::QTouchEventSequence touch = QTest::touchEvent(window, touchDevice);
+ touch.press(1, p1.toPoint()).commit();
+ QQuickTouchUtils::flush(window);
+
+ QCOMPARE(passiveGrabbers(window), expectedPassiveGrabbers);
+
+ QQuickDragHandler *dragHandler = nullptr;
+ for (QQuickPointerHandler *handler: expectedPassiveGrabbers) {
+ QCOMPARE(static_cast<QQuickSinglePointHandler *>(handler)->point().scenePressPosition(), p1);
+ QQuickDragHandler *dh = qmlobject_cast<QQuickDragHandler *>(handler);
+ if (dh)
+ dragHandler = dh;
+ }
+ QVERIFY(dragHandler);
+ QPointF initialPos = dragHandler->target()->position();
+
+ p1 += QPointF(50, 50);
+ touch.move(1, p1.toPoint()).commit();
+ QQuickTouchUtils::flush(window);
+ QTRY_VERIFY(dragHandler->active());
+
+ p1 += QPointF(50, 50);
+ touch.move(1, p1.toPoint()).commit();
+ QQuickTouchUtils::flush(window);
+ QPointF movementDelta = dragHandler->target()->position() - initialPos;
+ qCDebug(lcPointerTests) << "DragHandler moved the target by" << movementDelta;
+ QVERIFY(movementDelta.x() >= 100);
+ QVERIFY(movementDelta.y() >= 100);
+
+ QTest::qWait(500);
+
+ touch.release(1, p1.toPoint());
+ touch.commit();
+ QQuickTouchUtils::flush(window);
+}
+
QTEST_MAIN(tst_DragHandler)
#include "tst_qquickdraghandler.moc"
diff --git a/tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp b/tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp
index cc39dd54f7..d38ae3190e 100644
--- a/tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp
+++ b/tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQml module of the Qt Toolkit.
@@ -504,17 +504,18 @@ void tst_PointerHandlers::mouseEventDelivery()
eventItem1->grabPointer = true;
p1 = QPoint(20, 20);
QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, p1);
- QTRY_COMPARE(eventItem1->eventList.size(), 2);
+ QTRY_COMPARE(eventItem1->eventList.size(), 3);
QCOMPARE_EVENT(0, Event::HandlerDestination, QEvent::None, Qt::TouchPointPressed, QQuickEventPoint::GrabExclusive);
QCOMPARE_EVENT(1, Event::HandlerDestination, QEvent::Pointer, Qt::TouchPointPressed, QQuickEventPoint::GrabExclusive);
+ QCOMPARE_EVENT(2, Event::MouseDestination, QEvent::MouseButtonPress, Qt::TouchPointPressed, 0);
p1 += QPoint(10, 0);
QTest::mouseMove(window, p1);
- QCOMPARE(eventItem1->eventList.size(), 3);
- QCOMPARE_EVENT(2, Event::HandlerDestination, QEvent::Pointer, Qt::TouchPointMoved, QQuickEventPoint::GrabExclusive);
+ QCOMPARE(eventItem1->eventList.size(), 4);
+ QCOMPARE_EVENT(3, Event::HandlerDestination, QEvent::Pointer, Qt::TouchPointMoved, QQuickEventPoint::GrabExclusive);
QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, p1);
- QCOMPARE(eventItem1->eventList.size(), 5);
- QCOMPARE_EVENT(3, Event::HandlerDestination, QEvent::Pointer, Qt::TouchPointReleased, QQuickEventPoint::GrabExclusive);
- QCOMPARE_EVENT(4, Event::HandlerDestination, QEvent::None, Qt::TouchPointReleased, QQuickEventPoint::UngrabExclusive);
+ QCOMPARE(eventItem1->eventList.size(), 6);
+ QCOMPARE_EVENT(4, Event::HandlerDestination, QEvent::Pointer, Qt::TouchPointReleased, QQuickEventPoint::GrabExclusive);
+ QCOMPARE_EVENT(5, Event::HandlerDestination, QEvent::None, Qt::TouchPointReleased, QQuickEventPoint::UngrabExclusive);
eventItem1->eventList.clear();
}