Create accessible interfaces only for items with attached prop
authorFrederik Gladhorn <frederik.gladhorn@nokia.com>
Fri, 23 Mar 2012 16:42:09 +0000 (17:42 +0100)
committerQt by Nokia <qt-info@nokia.com>
Tue, 10 Apr 2012 19:03:04 +0000 (21:03 +0200)
If the attached property is not found, ignore the item, unless
it is part of the tree. We still create a valid hierarchy this
way, but filter out all irrelevant items. The same goes for
hit-testing.

On the other hand this patch enables the root item to be found
by setting isAccessible on it when updating the flags. Otherwise
the hierarchy is not valid again.

Change-Id: Ied422fd0506d13458757c87a5dad7cdb9d3079bf
Reviewed-by: Jan-Arve Sæther <jan-arve.saether@nokia.com>
src/plugins/accessible/quick/main.cpp
src/plugins/accessible/quick/qaccessiblequickview.cpp
src/quick/items/qquickitem.cpp
tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp

index 2c75e59..6592c59 100644 (file)
@@ -46,6 +46,7 @@
 
 #include <QtQuick/QQuickView>
 #include <QtQuick/QQuickItem>
+#include <QtQuick/private/qquickitem_p.h>
 #include <QtQuick/private/qquickaccessibleattached_p.h>
 
 #include <qaccessibleplugin.h>
@@ -86,8 +87,11 @@ QAccessibleInterface *AccessibleQuickFactory::create(const QString &classname, Q
     if (classname == QLatin1String("QQuickView")) {
         return new QAccessibleQuickView(qobject_cast<QQuickView *>(object)); // FIXME
     } else if (classname == QLatin1String("QQuickItem")) {
-        QQuickItem * item = qobject_cast<QQuickItem *>(object);
+        QQuickItem *item = qobject_cast<QQuickItem *>(object);
         Q_ASSERT(item);
+        QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
+        if (!itemPrivate->isAccessible)
+            return 0;
 
         QVariant v = QQuickAccessibleAttached::property(item, "role");
         bool ok;
index 2df1f24..ed8167f 100644 (file)
@@ -127,7 +127,11 @@ static QQuickItem *childAt_helper(QQuickItem *item, int x, int y)
     }
 
     QScopedPointer<QAccessibleInterface> accessibleInterface(QAccessible::queryAccessibleInterface(item));
-    if (accessibleInterface && accessibleInterface->childCount() == 0) {
+    // this item has no Accessible attached property
+    if (!accessibleInterface)
+        return 0;
+
+    if (accessibleInterface->childCount() == 0) {
         return (itemScreenRect(item).contains(x, y)) ? item : 0;
     }
 
@@ -155,6 +159,7 @@ QAccessibleInterface *QAccessibleQuickView::childAt(int x, int y) const
     if (root) {
         if (QQuickItem *item = childAt_helper(root, x, y))
             return QAccessible::queryAccessibleInterface(item);
+        return QAccessible::queryAccessibleInterface(root);
     }
     return 0;
 }
index d2a8ada..c5a2b44 100644 (file)
@@ -1633,9 +1633,6 @@ void QQuickItemPrivate::setAccessibleFlagAndListener()
         if (item->d_func()->isAccessible)
             break; // already set - grandparents should have the flag set as well.
 
-        if (item->canvas() && item->canvas()->rootItem() == item)
-            break; // don't add a listener to the canvas root item
-
         item->d_func()->isAccessible = true;
         item = item->d_func()->parentItem;
     }
index ca04751..45a9d11 100644 (file)
@@ -345,15 +345,17 @@ void tst_QQuickAccessible::hitTest()
     QAI rootItem = QAI(canvasIface->child(0));
     QRect rootRect = rootItem->rect();
 
-    // hit the root item
-    QAI rootItemIface(canvasIface->childAt(rootRect.x() + 200, rootRect.y() + 50));
-    QVERIFY(rootItemIface);
-    QCOMPARE(rootRect, rootItemIface->rect());
+    // check the root item from app
+    QAI appIface = QAI(QAccessible::queryAccessibleInterface(qApp));
+    QVERIFY(appIface);
+    QAI itemHit(appIface->childAt(rootRect.x() + 200, rootRect.y() + 50));
+    QVERIFY(itemHit);
+    QCOMPARE(rootRect, itemHit->rect());
 
     // hit rect1
     QAI rect1(rootItem->child(0));
     QRect rect1Rect = rect1->rect();
-    rootItemIface = QAI(rootItem->childAt(rect1Rect.x() + 10, rect1Rect.y() + 10));
+    QAI rootItemIface = QAI(rootItem->childAt(rect1Rect.x() + 10, rect1Rect.y() + 10));
     QVERIFY(rootItemIface);
     QCOMPARE(rect1Rect, rootItemIface->rect());
     QCOMPARE(rootItemIface->text(QAccessible::Name), QLatin1String("rect1"));