From f8f0f0835a971a658f4ee2ae386e448338b1a7d7 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Tue, 4 Dec 2018 12:27:23 +0100 Subject: TapHandler: ignore scroll events and native gestures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit During a 2-finger press (to emulate right click on a trackpad), the OS may also generate a QWheelEvent with ScrollBegin phase just in case scrolling starts. This must not prematurely deactivate the TapHandler. Also if a gesture or wheel event begins as the very first event after an application starts, ensure that subsequent mouse events are not mis-delivered as wheel or gesture events. Fixes: QTBUG-71955 Change-Id: Ic12e116483ab9ad37c4ac3b1d10ccb62e1349e0a Reviewed-by: Jan Arve Sæther --- .../qquicktaphandler/data/rightTapHandler.qml | 41 ++++++++++++++++++++++ .../qquicktaphandler/tst_qquicktaphandler.cpp | 39 ++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 tests/auto/quick/pointerhandlers/qquicktaphandler/data/rightTapHandler.qml (limited to 'tests/auto/quick/pointerhandlers/qquicktaphandler') diff --git a/tests/auto/quick/pointerhandlers/qquicktaphandler/data/rightTapHandler.qml b/tests/auto/quick/pointerhandlers/qquicktaphandler/data/rightTapHandler.qml new file mode 100644 index 0000000000..aea01c154c --- /dev/null +++ b/tests/auto/quick/pointerhandlers/qquicktaphandler/data/rightTapHandler.qml @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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 + +Rectangle { + width: 320 + height: 240 + color: rightTap.pressed ? "tomato" : "beige" + TapHandler { + id: rightTap + objectName: "right button TapHandler" + longPressThreshold: 0.5 + acceptedButtons: Qt.RightButton + } +} diff --git a/tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp b/tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp index 467c964001..ab6fa0dbe4 100644 --- a/tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp +++ b/tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp @@ -69,6 +69,7 @@ private slots: void mouseLongPress(); void buttonsMultiTouch(); void componentUserBehavioralOverride(); + void rightLongPressIgnoreWheel(); private: void createView(QScopedPointer &window, const char *fileName); @@ -622,6 +623,44 @@ void tst_TapHandler::componentUserBehavioralOverride() QCOMPARE(userGrabChangedSpy.count(), 2); } +void tst_TapHandler::rightLongPressIgnoreWheel() +{ + QScopedPointer windowPtr; + createView(windowPtr, "rightTapHandler.qml"); + QQuickView * window = windowPtr.data(); + + QQuickTapHandler *tap = window->rootObject()->findChild(); + QVERIFY(tap); + QSignalSpy tappedSpy(tap, SIGNAL(tapped(QQuickEventPoint *))); + QSignalSpy longPressedSpy(tap, SIGNAL(longPressed())); + QPoint p1(100, 100); + + // Mouse wheel with ScrollBegin phase (because as soon as two fingers are touching + // the trackpad, it will send such an event: QTBUG-71955) + { + QWheelEvent wheelEvent(p1, p1, QPoint(0, 0), QPoint(0, 0), + Qt::NoButton, Qt::NoModifier, Qt::ScrollBegin, false, Qt::MouseEventNotSynthesized); + QGuiApplication::sendEvent(window, &wheelEvent); + } + + // Press + QTest::mousePress(window, Qt::RightButton, Qt::NoModifier, p1); + QTRY_COMPARE(tap->isPressed(), true); + + // Mouse wheel ScrollEnd phase + QWheelEvent wheelEvent(p1, p1, QPoint(0, 0), QPoint(0, 0), + Qt::NoButton, Qt::NoModifier, Qt::ScrollEnd, false, Qt::MouseEventNotSynthesized); + QGuiApplication::sendEvent(window, &wheelEvent); + QTRY_COMPARE(longPressedSpy.count(), 1); + QCOMPARE(tap->isPressed(), true); + QCOMPARE(tappedSpy.count(), 0); + + // Release + QTest::mouseRelease(window, Qt::RightButton, Qt::NoModifier, p1, 500); + QTRY_COMPARE(tap->isPressed(), false); + QCOMPARE(tappedSpy.count(), 0); +} + QTEST_MAIN(tst_TapHandler) #include "tst_qquicktaphandler.moc" -- cgit v1.2.3