Accessibility: Work with QQuickWindow
authorFrederik Gladhorn <frederik.gladhorn@digia.com>
Wed, 12 Dec 2012 10:49:21 +0000 (11:49 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 4 Jan 2013 13:16:18 +0000 (14:16 +0100)
Before we would only be accessible when QQView was used.
While the window has the content item, that one will not
appear in the hierarchy of accessible objects since it has
no valueable properties to expose. Instead it's first child
will be used (which was the case before when QQView was used).

Change-Id: I03cefb5c8dcd8296d51ff2bfcb677386a5f1d698
Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
src/plugins/accessible/quick/accessible.json
src/plugins/accessible/quick/main.cpp
src/plugins/accessible/quick/qaccessiblequickview.cpp
src/plugins/accessible/quick/qaccessiblequickview.h

index 845a45aa78e96b90df3a46a08cba968388baa3e3..b21218f19cde8b81c0ae73b23bc78ac7c4e3aebd 100644 (file)
@@ -1,3 +1,3 @@
 {
-    "Keys": [ "QQuickView", "QQuickItem" ]
+    "Keys": [ "QQuickWindow", "QQuickItem" ]
 }
index cac5d7e58dde3c20f3d8f78b25f9aa1a8a97be92..019c84fc6e52f5a6a229994324ffb14b3c0e252e 100644 (file)
@@ -44,7 +44,7 @@
 #include "qaccessiblequickview.h"
 #include "qaccessiblequickitem.h"
 
-#include <QtQuick/QQuickView>
+#include <QtQuick/QQuickWindow>
 #include <QtQuick/QQuickItem>
 #include <QtQuick/private/qquickitem_p.h>
 #include <QtQuick/private/qquickaccessibleattached_p.h>
@@ -77,15 +77,15 @@ AccessibleQuickFactory::AccessibleQuickFactory()
 QStringList AccessibleQuickFactory::keys() const
 {
     QStringList list;
-    list << QLatin1String("QQuickView");
+    list << QLatin1String("QQuickWindow");
     list << QLatin1String("QQuickItem");
     return list;
 }
 
 QAccessibleInterface *AccessibleQuickFactory::create(const QString &classname, QObject *object)
 {
-    if (classname == QLatin1String("QQuickView")) {
-        return new QAccessibleQuickView(qobject_cast<QQuickView *>(object)); // FIXME
+    if (classname == QLatin1String("QQuickWindow")) {
+        return new QAccessibleQuickWindow(qobject_cast<QQuickWindow *>(object));
     } else if (classname == QLatin1String("QQuickItem")) {
         QQuickItem *item = qobject_cast<QQuickItem *>(object);
         Q_ASSERT(item);
index 0106a3d68bca8d85e96024e9d85be785fa400716..f70a41c6e24f52f53583e27482522aa789a20f22 100644 (file)
 
 QT_BEGIN_NAMESPACE
 
-QAccessibleQuickView::QAccessibleQuickView(QQuickView *object)
+QAccessibleQuickWindow::QAccessibleQuickWindow(QQuickWindow *object)
     :QAccessibleObject(object)
 {
 }
 
-int QAccessibleQuickView::childCount() const
+QQuickItem *QAccessibleQuickWindow::rootItem() const
 {
-    return view()->contentItem() ? 1 : 0;
+    if (window()->contentItem())
+        return window()->contentItem()->childItems().first();
+    return 0;
 }
 
-QAccessibleInterface *QAccessibleQuickView::parent() const
+int QAccessibleQuickWindow::childCount() const
+{
+    return rootItem() ? 1 : 0;
+}
+
+QAccessibleInterface *QAccessibleQuickWindow::parent() const
 {
     // FIXME: for now we assume to be a top level window...
     return QAccessible::queryAccessibleInterface(qApp);
 }
 
-QAccessibleInterface *QAccessibleQuickView::child(int index) const
+QAccessibleInterface *QAccessibleQuickWindow::child(int index) const
 {
     if (index == 0) {
-        if (QQuickItem *declarativeRoot = view()->rootObject())
+        if (QQuickItem *declarativeRoot = rootItem())
             return new QAccessibleQuickItem(declarativeRoot);
     }
     return 0;
 }
 
-QAccessible::Role QAccessibleQuickView::role() const
+QAccessible::Role QAccessibleQuickWindow::role() const
 {
     return QAccessible::Window; // FIXME
 }
 
-QAccessible::State QAccessibleQuickView::state() const
+QAccessible::State QAccessibleQuickWindow::state() const
 {
     QAccessible::State st;
-    if (view() == QGuiApplication::focusWindow())
+    if (window() == QGuiApplication::focusWindow())
         st.active = true;
-    if (!view()->isVisible())
+    if (!window()->isVisible())
         st.invisible = true;
     return st;
 }
 
-QRect QAccessibleQuickView::rect() const
+QRect QAccessibleQuickWindow::rect() const
 {
-    return QRect(view()->x(), view()->y(), view()->width(), view()->height());
+    return QRect(window()->x(), window()->y(), window()->width(), window()->height());
 }
 
-QString QAccessibleQuickView::text(QAccessible::Text text) const
+QString QAccessibleQuickWindow::text(QAccessible::Text text) const
 {
 #ifdef Q_ACCESSIBLE_QUICK_ITEM_ENABLE_DEBUG_DESCRIPTION
     if (text == QAccessible::DebugDescription) {
@@ -107,7 +114,7 @@ QString QAccessibleQuickView::text(QAccessible::Text text) const
 #else
     Q_UNUSED(text)
 #endif
-    return view()->title();
+    return window()->title();
 }
 
 
@@ -152,10 +159,10 @@ static QQuickItem *childAt_helper(QQuickItem *item, int x, int y)
     return 0;
 }
 
-QAccessibleInterface *QAccessibleQuickView::childAt(int x, int y) const
+QAccessibleInterface *QAccessibleQuickWindow::childAt(int x, int y) const
 {
-    Q_ASSERT(view());
-    QQuickItem *root = view()->contentItem();
+    Q_ASSERT(window());
+    QQuickItem *root = rootItem();
     if (root) {
         if (QQuickItem *item = childAt_helper(root, x, y))
             return QAccessible::queryAccessibleInterface(item);
@@ -164,15 +171,14 @@ QAccessibleInterface *QAccessibleQuickView::childAt(int x, int y) const
     return 0;
 }
 
-int QAccessibleQuickView::indexOfChild(const QAccessibleInterface *iface) const
+int QAccessibleQuickWindow::indexOfChild(const QAccessibleInterface *iface) const
 {
     if (iface) {
-        QQuickItem *declarativeRoot = view()->rootObject();
+        QQuickItem *declarativeRoot = rootItem();
         if (declarativeRoot == iface->object())
             return 0;
     }
     return -1;
-
 }
 
 QT_END_NAMESPACE
index 03061be275f2ef0110e445d52afbb6fd4d74cff5..2b01b18f3cea567857210fa5e47a53168d6a08ea 100644 (file)
 
 #include <QtGui/qaccessible2.h>
 #include <QtGui/qaccessibleobject.h>
-#include <QtQuick/qquickview.h>
+#include <QtQuick/qquickwindow.h>
 
 QT_BEGIN_NAMESPACE
 
 #ifndef QT_NO_ACCESSIBILITY
 
-class QAccessibleQuickView : public QAccessibleObject
+class QAccessibleQuickWindow : public QAccessibleObject
 {
 public:
-    QAccessibleQuickView(QQuickView *object);
+    QAccessibleQuickWindow(QQuickWindow *object);
 
     QAccessibleInterface *parent() const;
     QAccessibleInterface *child(int index) const;
@@ -66,8 +66,10 @@ public:
     int indexOfChild(const QAccessibleInterface *iface) const;
     QString text(QAccessible::Text text) const;
     QAccessibleInterface *childAt(int x, int y) const;
+
 private:
-    QQuickView *view() const { return static_cast<QQuickView*>(object()); }
+    QQuickWindow *window() const { return static_cast<QQuickWindow*>(object()); }
+    QQuickItem *rootItem() const;
 };
 
 #endif // QT_NO_ACCESSIBILITY