Fix acceptance of unhandled mouse events.
authorSimon Hausmann <simon.hausmann@nokia.com>
Fri, 3 Feb 2012 13:41:17 +0000 (14:41 +0100)
committerQt by Nokia <qt-info@nokia.com>
Mon, 6 Feb 2012 20:12:57 +0000 (21:12 +0100)
Mouse events not handled by the canvas need to be ignored, in order for
features like touch synthetization to work. In case of the initially
delivered mouse press event, the canvas did not ignore the event if it
was not handled. This patch corrects that and adds an auto-test to verify
the new behaviour.

Change-Id: I8499701f5a161ce1e90a70303aa7ca4ccf2f0b6f
Reviewed-by: Andras Becsi <andras.becsi@nokia.com>
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>

src/quick/items/qquickcanvas.cpp
tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp

index 660d7df..a92e839 100644 (file)
@@ -835,7 +835,11 @@ bool QQuickCanvasPrivate::deliverMouseEvent(QMouseEvent *event)
     if (!mouseGrabberItem &&
          event->type() == QEvent::MouseButtonPress &&
          (event->button() & event->buttons()) == event->buttons()) {
-        return deliverInitialMousePressEvent(rootItem, event);
+        if (deliverInitialMousePressEvent(rootItem, event))
+            event->accept();
+        else
+            event->ignore();
+        return event->isAccepted();
     }
 
     if (mouseGrabberItem) {
index 795580c..4a23842 100644 (file)
@@ -210,6 +210,8 @@ private slots:
 
     void focusObject();
 
+    void ignoreUnhandledMouseEvents();
+
 private:
     QTouchDevice *touchDevice;
 };
@@ -696,6 +698,43 @@ void tst_qquickcanvas::focusObject()
     delete canvas;
 }
 
+void tst_qquickcanvas::ignoreUnhandledMouseEvents()
+{
+    QQuickCanvas* canvas = new QQuickCanvas;
+    canvas->resize(100, 100);
+    canvas->show();
+
+    QQuickItem* item = new QQuickItem;
+    item->setSize(QSizeF(100, 100));
+    item->setParentItem(canvas->rootItem());
+
+    {
+        QMouseEvent me(QEvent::MouseButtonPress, QPointF(50, 50), Qt::LeftButton, Qt::LeftButton,
+                       Qt::NoModifier);
+        me.setAccepted(true);
+        QVERIFY(QCoreApplication::sendEvent(canvas, &me));
+        QVERIFY(!me.isAccepted());
+    }
+
+    {
+        QMouseEvent me(QEvent::MouseMove, QPointF(51, 51), Qt::LeftButton, Qt::LeftButton,
+                       Qt::NoModifier);
+        me.setAccepted(true);
+        QVERIFY(QCoreApplication::sendEvent(canvas, &me));
+        QVERIFY(!me.isAccepted());
+    }
+
+    {
+        QMouseEvent me(QEvent::MouseButtonRelease, QPointF(51, 51), Qt::LeftButton, Qt::LeftButton,
+                       Qt::NoModifier);
+        me.setAccepted(true);
+        QVERIFY(QCoreApplication::sendEvent(canvas, &me));
+        QVERIFY(!me.isAccepted());
+    }
+
+    delete canvas;
+}
+
 QTEST_MAIN(tst_qquickcanvas)
 
 #include "tst_qquickcanvas.moc"