aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYoungSun Park <cathy.park@lge.com>2019-08-16 21:32:22 +0900
committerJohannes Oikarinen <johannes.oikarinen@qt.io>2020-09-15 15:38:19 +0300
commit3ff11ceca37dcc4b6f0420332fa7f6aa007be7f3 (patch)
treef23018b359d2502527fc1a9706fb2152e2bc3197 /tests
parent6412bcd2219d2a5c1f8193d8f394ddb1279dee2b (diff)
QQuickWindow: Consider z-order of children when delivering pointer events
When creating a target item list for handling pointer events, put children after the parent item if they have negative z-order value. This fixes an issue where an item does not receive a pointer event if there is a child item that accepts the event even when that child item is shown under the parent item as per the stacking order. Fixes: QTBUG-83114 Pick-to: 5.15 Change-Id: I711faa22516f5c2396b1138dc507bcaa4ba22241 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/pointerhandlers/qquicktaphandler/data/tapHandlersOverlapped.qml60
-rw-r--r--tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp33
-rw-r--r--tests/auto/quick/qquickmousearea/data/mouseAreasOverlapped.qml37
-rw-r--r--tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp34
4 files changed, 164 insertions, 0 deletions
diff --git a/tests/auto/quick/pointerhandlers/qquicktaphandler/data/tapHandlersOverlapped.qml b/tests/auto/quick/pointerhandlers/qquicktaphandler/data/tapHandlersOverlapped.qml
new file mode 100644
index 0000000000..8d2e36d921
--- /dev/null
+++ b/tests/auto/quick/pointerhandlers/qquicktaphandler/data/tapHandlersOverlapped.qml
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite 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.12
+
+Item {
+ width: 300
+ height: 200
+ property var taps: []
+
+ Rectangle {
+ x: 25
+ y: 25
+ width: 200
+ height: 100
+ color: "salmon"
+
+ TapHandler {
+ objectName: "parentTapHandler"
+ onTapped: taps.push(objectName)
+ }
+
+ Rectangle {
+ x: 25
+ y: 25
+ width: 200
+ height: 100
+ color: "lightsteelblue"
+
+ TapHandler {
+ objectName: "childTapHandler"
+ onTapped: taps.push(objectName)
+ }
+ }
+ }
+}
diff --git a/tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp b/tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp
index 32a68293c2..89de571abd 100644
--- a/tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp
+++ b/tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp
@@ -70,6 +70,7 @@ private slots:
void buttonsMultiTouch();
void componentUserBehavioralOverride();
void rightLongPressIgnoreWheel();
+ void negativeZStackingOrder();
private:
void createView(QScopedPointer<QQuickView> &window, const char *fileName);
@@ -744,6 +745,38 @@ void tst_TapHandler::rightLongPressIgnoreWheel()
QCOMPARE(tappedSpy.count(), 0);
}
+void tst_TapHandler::negativeZStackingOrder() // QTBUG-83114
+{
+ QScopedPointer<QQuickView> windowPtr;
+ createView(windowPtr, "tapHandlersOverlapped.qml");
+ QQuickView *window = windowPtr.data();
+ QQuickItem *root = window->rootObject();
+
+ QQuickTapHandler *parentTapHandler = window->rootObject()->findChild<QQuickTapHandler*>("parentTapHandler");
+ QVERIFY(parentTapHandler != nullptr);
+ QSignalSpy clickSpyParent(parentTapHandler, &QQuickTapHandler::tapped);
+ QQuickTapHandler *childTapHandler = window->rootObject()->findChild<QQuickTapHandler*>("childTapHandler");
+ QVERIFY(childTapHandler != nullptr);
+ QSignalSpy clickSpyChild(childTapHandler, &QQuickTapHandler::tapped);
+
+ QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(150, 100));
+ QCOMPARE(clickSpyChild.count(), 1);
+ QCOMPARE(clickSpyParent.count(), 1);
+ auto order = root->property("taps").toList();
+ QVERIFY(order.at(0) == "childTapHandler");
+ QVERIFY(order.at(1) == "parentTapHandler");
+
+ // Now change stacking order and try again.
+ childTapHandler->parentItem()->setZ(-1);
+ root->setProperty("taps", QVariantList());
+ QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(150, 100));
+ QCOMPARE(clickSpyChild.count(), 2);
+ QCOMPARE(clickSpyParent.count(), 2);
+ order = root->property("taps").toList();
+ QVERIFY(order.at(0) == "parentTapHandler");
+ QVERIFY(order.at(1) == "childTapHandler");
+}
+
QTEST_MAIN(tst_TapHandler)
#include "tst_qquicktaphandler.moc"
diff --git a/tests/auto/quick/qquickmousearea/data/mouseAreasOverlapped.qml b/tests/auto/quick/qquickmousearea/data/mouseAreasOverlapped.qml
new file mode 100644
index 0000000000..aba574283b
--- /dev/null
+++ b/tests/auto/quick/qquickmousearea/data/mouseAreasOverlapped.qml
@@ -0,0 +1,37 @@
+
+import QtQuick 2.0
+
+Item {
+ width: 300
+ height:200
+ property var clicks: []
+
+ Rectangle {
+ x: 75
+ y: 75
+ width: 200
+ height: 100
+ color: "salmon"
+
+ MouseArea {
+ objectName: "parentMouseArea"
+ anchors.fill: parent
+ onClicked: clicks.push(objectName)
+ }
+
+ Rectangle {
+ x: 25
+ y: 25
+ width: 200
+ height: 100
+ color: "lightsteelblue"
+
+ MouseArea {
+ id: mouseArea
+ objectName: "childMouseArea"
+ anchors.fill: parent
+ onClicked: clicks.push(objectName)
+ }
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
index c38ab72a7b..7bf9660978 100644
--- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
+++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
@@ -158,6 +158,7 @@ private slots:
void mask();
void nestedEventDelivery();
void settingHiddenInPressUngrabs();
+ void negativeZStackingOrder();
private:
int startDragDistance() const {
@@ -2438,6 +2439,39 @@ void tst_QQuickMouseArea::settingHiddenInPressUngrabs()
QVERIFY(!mouseArea->pressed());
}
+void tst_QQuickMouseArea::negativeZStackingOrder() // QTBUG-83114
+{
+ QQuickView window;
+ QByteArray errorMessage;
+ QVERIFY2(QQuickTest::initView(window, testFileUrl("mouseAreasOverlapped.qml"), true, &errorMessage), errorMessage.constData());
+ window.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
+ QVERIFY(window.rootObject() != nullptr);
+ QQuickItem *root = window.rootObject();
+
+ QQuickMouseArea *parentMouseArea = root->findChild<QQuickMouseArea*>("parentMouseArea");
+ QVERIFY(parentMouseArea != nullptr);
+ QSignalSpy clickSpyParent(parentMouseArea, &QQuickMouseArea::clicked);
+ QQuickMouseArea *childMouseArea = root->findChild<QQuickMouseArea*>("childMouseArea");
+ QVERIFY(childMouseArea != nullptr);
+ QSignalSpy clickSpyChild(childMouseArea, &QQuickMouseArea::clicked);
+
+ QTest::mouseClick(&window, Qt::LeftButton, Qt::NoModifier, QPoint(150, 100));
+ QCOMPARE(clickSpyChild.count(), 1);
+ QCOMPARE(clickSpyParent.count(), 0);
+ auto order = root->property("clicks").toList();
+ QVERIFY(order.at(0) == "childMouseArea");
+
+ // Now change stacking order and try again.
+ childMouseArea->parentItem()->setZ(-1);
+ root->setProperty("clicks", QVariantList());
+ QTest::mouseClick(&window, Qt::LeftButton, Qt::NoModifier, QPoint(150, 100));
+ QCOMPARE(clickSpyChild.count(), 1);
+ QCOMPARE(clickSpyParent.count(), 1);
+ order = root->property("clicks").toList();
+ QVERIFY(order.at(0) == "parentMouseArea");
+}
+
QTEST_MAIN(tst_QQuickMouseArea)
#include "tst_qquickmousearea.moc"