From 6933b7e8e6dc279a8eb34e1f4c60bc109dfb7d26 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Fri, 11 Jan 2013 14:48:32 +0100 Subject: Ungrab mouse when FocusAboutToChange instead of Leave Commit 7b2e2117162594a2d0234bb02408f5b5a446488b introduced a regression in mouse handling: When moving the mouse out of the window it would cancel all further mouse events. That is actually not wanted (eg scroll bars). Instead ungrab the mouse when the focus changes, that means the mouse handling with popups works and the scrollbar use case is also fixed. All the tests related to this seem quite timing sensitive, so try some more QTRY_VERIFY. Remove the parallel_test so that more cpu time will actually let the tests pass more reliably. Change-Id: I90586b05f461d3762728a466d71bcb967e03d14b Reviewed-by: Gabriel de Dietrich --- src/quick/items/qquickwindow.cpp | 4 ++-- .../auto/quick/qquickflickable/qquickflickable.pro | 1 - .../quick/qquickflickable/tst_qquickflickable.cpp | 10 ++++----- .../auto/quick/qquickmousearea/qquickmousearea.pro | 2 -- .../quick/qquickmousearea/tst_qquickmousearea.cpp | 26 +++++++++++++--------- 5 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index f812840782..f4334286fa 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -1129,8 +1129,6 @@ bool QQuickWindow::event(QEvent *e) case QEvent::Leave: d->clearHover(); d->lastMousePosition = QPoint(); - if (d->mouseGrabberItem) - d->mouseGrabberItem->ungrabMouse(); break; #ifndef QT_NO_DRAGANDDROP case QEvent::DragEnter: @@ -1148,6 +1146,8 @@ bool QQuickWindow::event(QEvent *e) if (d->activeFocusItem) qGuiApp->inputMethod()->commit(); #endif + if (d->mouseGrabberItem) + d->mouseGrabberItem->ungrabMouse(); break; default: break; diff --git a/tests/auto/quick/qquickflickable/qquickflickable.pro b/tests/auto/quick/qquickflickable/qquickflickable.pro index 3ba752bf7d..95c703befe 100644 --- a/tests/auto/quick/qquickflickable/qquickflickable.pro +++ b/tests/auto/quick/qquickflickable/qquickflickable.pro @@ -9,6 +9,5 @@ include (../shared/util.pri) TESTDATA = data/* -CONFIG += parallel_test QT += core-private gui-private v8-private qml-private quick-private testlib DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp index 662e86018c..784988b913 100644 --- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp +++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp @@ -618,7 +618,7 @@ void tst_qquickflickable::movingAndFlicking() window->setSource(testFileUrl("flickable03.qml")); window->show(); window->requestActivate(); - QTest::qWaitForWindowActive(window); + QVERIFY(QTest::qWaitForWindowActive(window)); QVERIFY(window->rootObject() != 0); QQuickFlickable *flickable = qobject_cast(window->rootObject()); @@ -639,7 +639,7 @@ void tst_qquickflickable::movingAndFlicking() // do a flick that keeps the view within the bounds flick(window, flickFrom, flickToWithoutSnapBack, 200); - QVERIFY(flickable->isMoving()); + QTRY_VERIFY(flickable->isMoving()); QCOMPARE(flickable->isMovingHorizontally(), horizontalEnabled); QCOMPARE(flickable->isMovingVertically(), verticalEnabled); QVERIFY(flickable->isFlicking()); @@ -695,7 +695,7 @@ void tst_qquickflickable::movingAndFlicking() QTRY_VERIFY(!flickable->isMoving()); flick(window, flickFrom, flickToWithSnapBack, 200); - QVERIFY(flickable->isMoving()); + QTRY_VERIFY(flickable->isMoving()); QCOMPARE(flickable->isMovingHorizontally(), horizontalEnabled); QCOMPARE(flickable->isMovingVertically(), verticalEnabled); QVERIFY(flickable->isFlicking()); @@ -999,7 +999,7 @@ void tst_qquickflickable::pressWhileFlicking() // flicking == false, moving == true; flick(window, QPoint(20,190), QPoint(20, 50), 200); QVERIFY(flickable->verticalVelocity() > 0.0); - QVERIFY(flickable->isFlicking()); + QTRY_VERIFY(flickable->isFlicking()); QVERIFY(flickable->isFlickingVertically()); QVERIFY(!flickable->isFlickingHorizontally()); QVERIFY(flickable->isMoving()); @@ -1257,7 +1257,7 @@ void tst_qquickflickable::flickTwiceUsingTouches() window->setSource(testFileUrl("longList.qml")); window->show(); window->requestActivate(); - QTest::qWaitForWindowActive(window); + QVERIFY(QTest::qWaitForWindowActive(window)); QVERIFY(window->rootObject() != 0); QQuickFlickable *flickable = qobject_cast(window->rootObject()); diff --git a/tests/auto/quick/qquickmousearea/qquickmousearea.pro b/tests/auto/quick/qquickmousearea/qquickmousearea.pro index 957b04a558..dd7b434898 100644 --- a/tests/auto/quick/qquickmousearea/qquickmousearea.pro +++ b/tests/auto/quick/qquickmousearea/qquickmousearea.pro @@ -10,7 +10,5 @@ include (../../shared/util.pri) TESTDATA = data/* -CONFIG += parallel_test - QT += core-private gui-private qml-private quick-private network testlib DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp index 9fd42373e2..ffe7b51537 100644 --- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp +++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp @@ -248,7 +248,7 @@ void tst_QQuickMouseArea::dragging() window->setSource(testFileUrl("dragging.qml")); window->show(); window->requestActivate(); - QTest::qWait(20); + QVERIFY(QTest::qWaitForWindowExposed(window)); QVERIFY(window->rootObject() != 0); QQuickMouseArea *mouseRegion = window->rootObject()->findChild("mouseregion"); @@ -274,19 +274,17 @@ void tst_QQuickMouseArea::dragging() // First move event triggers drag, second is acted upon. // This is due to possibility of higher stacked area taking precedence. - QTest::mouseMove(window, QPoint(111,111)); - QTest::qWait(50); - QTest::mouseMove(window, QPoint(122,122)); - QTest::qWait(50); + QTest::mouseMove(window, QPoint(111,111), 50); + QTest::mouseMove(window, QPoint(116,116), 50); + QTest::mouseMove(window, QPoint(122,122), 50); - QVERIFY(drag->active()); - QCOMPARE(blackRect->x(), 72.0); + QTRY_VERIFY(drag->active()); + QTRY_COMPARE(blackRect->x(), 72.0); QCOMPARE(blackRect->y(), 72.0); QTest::mouseRelease(window, button, 0, QPoint(122,122)); - QTest::qWait(50); - QVERIFY(!drag->active()); + QTRY_VERIFY(!drag->active()); QCOMPARE(blackRect->x(), 72.0); QCOMPARE(blackRect->y(), 72.0); @@ -477,20 +475,28 @@ void tst_QQuickMouseArea::noOnClickedWithPressAndHold() window->show(); window->requestActivate(); QVERIFY(window->rootObject() != 0); + QQuickMouseArea *mouseArea = qobject_cast(window->rootObject()->children().first()); + QVERIFY(mouseArea); QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0); QGuiApplication::sendEvent(window, &pressEvent); + QVERIFY(mouseArea->pressedButtons() == Qt::LeftButton); QVERIFY(!window->rootObject()->property("clicked").toBool()); QVERIFY(!window->rootObject()->property("held").toBool()); + // timeout is 800 (in qquickmousearea.cpp) QTest::qWait(1000); + QCoreApplication::processEvents(); + + QVERIFY(!window->rootObject()->property("clicked").toBool()); + QVERIFY(window->rootObject()->property("held").toBool()); QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0); QGuiApplication::sendEvent(window, &releaseEvent); + QTRY_VERIFY(window->rootObject()->property("held").toBool()); QVERIFY(!window->rootObject()->property("clicked").toBool()); - QVERIFY(window->rootObject()->property("held").toBool()); delete window; } -- cgit v1.2.3