Ungrab mouse when FocusAboutToChange instead of Leave
authorFrederik Gladhorn <frederik.gladhorn@digia.com>
Fri, 11 Jan 2013 13:48:32 +0000 (14:48 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 24 Jan 2013 17:17:04 +0000 (18:17 +0100)
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 <gabriel.dedietrich@digia.com>
src/quick/items/qquickwindow.cpp
tests/auto/quick/qquickflickable/qquickflickable.pro
tests/auto/quick/qquickflickable/tst_qquickflickable.cpp
tests/auto/quick/qquickmousearea/qquickmousearea.pro
tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp

index f812840..f433428 100644 (file)
@@ -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;
index 3ba752b..95c703b 100644 (file)
@@ -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
index 662e860..784988b 100644 (file)
@@ -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<QQuickFlickable*>(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<QQuickFlickable*>(window->rootObject());
index 957b04a..dd7b434 100644 (file)
@@ -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
index 9fd4237..ffe7b51 100644 (file)
@@ -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<QQuickMouseArea*>("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<QQuickMouseArea*>(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;
     }