| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "qaccessiblequickview_p.h" |
| 5 | |
| 6 | #include <QtGui/qguiapplication.h> |
| 7 | |
| 8 | #include <QtQuick/qquickitem.h> |
| 9 | #include <QtQuick/private/qquickitem_p.h> |
| 10 | |
| 11 | #include "qaccessiblequickitem_p.h" |
| 12 | |
| 13 | #if QT_CONFIG(accessibility) |
| 14 | |
| 15 | QT_BEGIN_NAMESPACE |
| 16 | |
| 17 | QAccessibleQuickWindow::QAccessibleQuickWindow(QQuickWindow *object) |
| 18 | :QAccessibleObject(object) |
| 19 | { |
| 20 | } |
| 21 | |
| 22 | QList<QQuickItem *> QAccessibleQuickWindow::rootItems() const |
| 23 | { |
| 24 | if (QQuickItem *ci = window() ? window()->contentItem() : nullptr) |
| 25 | return accessibleUnignoredChildren(item: ci); |
| 26 | return QList<QQuickItem *>(); |
| 27 | } |
| 28 | |
| 29 | int QAccessibleQuickWindow::childCount() const |
| 30 | { |
| 31 | return rootItems().size(); |
| 32 | } |
| 33 | |
| 34 | QAccessibleInterface *QAccessibleQuickWindow::parent() const |
| 35 | { |
| 36 | // FIXME: for now we assume to be a top level window... |
| 37 | return QAccessible::queryAccessibleInterface(qApp); |
| 38 | } |
| 39 | |
| 40 | QAccessibleInterface *QAccessibleQuickWindow::child(int index) const |
| 41 | { |
| 42 | const QList<QQuickItem*> &kids = rootItems(); |
| 43 | if (index >= 0 && index < kids.size()) |
| 44 | return QAccessible::queryAccessibleInterface(kids.at(i: index)); |
| 45 | return nullptr; |
| 46 | } |
| 47 | |
| 48 | QAccessibleInterface *QAccessibleQuickWindow::focusChild() const |
| 49 | { |
| 50 | QObject *focusObject = window() ? window()->focusObject() : nullptr; |
| 51 | if (focusObject) { |
| 52 | QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(focusObject); |
| 53 | if (!iface || iface == this || !iface->focusChild()) |
| 54 | return iface; |
| 55 | return iface->focusChild(); |
| 56 | } |
| 57 | return nullptr; |
| 58 | } |
| 59 | |
| 60 | QAccessible::Role QAccessibleQuickWindow::role() const |
| 61 | { |
| 62 | return QAccessible::Window; |
| 63 | } |
| 64 | |
| 65 | QAccessible::State QAccessibleQuickWindow::state() const |
| 66 | { |
| 67 | QAccessible::State st; |
| 68 | if (window() == QGuiApplication::focusWindow()) |
| 69 | st.active = true; |
| 70 | if (!window() || !window()->isVisible()) |
| 71 | st.invisible = true; |
| 72 | return st; |
| 73 | } |
| 74 | |
| 75 | QRect QAccessibleQuickWindow::rect() const |
| 76 | { |
| 77 | if (!window()) |
| 78 | return {}; |
| 79 | return QRect(window()->x(), window()->y(), window()->width(), window()->height()); |
| 80 | } |
| 81 | |
| 82 | QString QAccessibleQuickWindow::text(QAccessible::Text text) const |
| 83 | { |
| 84 | if (!window()) |
| 85 | return {}; |
| 86 | #ifdef Q_ACCESSIBLE_QUICK_ITEM_ENABLE_DEBUG_DESCRIPTION |
| 87 | if (text == QAccessible::DebugDescription) { |
| 88 | return QString::fromLatin1(object()->metaObject()->className()) ; |
| 89 | } |
| 90 | #endif |
| 91 | if (text == QAccessible::Name) |
| 92 | return window()->title(); |
| 93 | else |
| 94 | return {}; |
| 95 | } |
| 96 | |
| 97 | QAccessibleInterface *QAccessibleQuickWindow::childAt(int x, int y) const |
| 98 | { |
| 99 | Q_ASSERT(window()); |
| 100 | for (int i = childCount() - 1; i >= 0; --i) { |
| 101 | QAccessibleInterface *childIface = child(index: i); |
| 102 | if (childIface && !childIface->state().invisible) { |
| 103 | if (QAccessibleInterface *iface = childIface->childAt(x, y)) |
| 104 | return iface; |
| 105 | if (childIface->rect().contains(ax: x, ay: y)) |
| 106 | return childIface; |
| 107 | } |
| 108 | } |
| 109 | return nullptr; |
| 110 | } |
| 111 | |
| 112 | int QAccessibleQuickWindow::indexOfChild(const QAccessibleInterface *iface) const |
| 113 | { |
| 114 | int i = -1; |
| 115 | if (iface) { |
| 116 | const QList<QQuickItem *> &roots = rootItems(); |
| 117 | i = roots.size() - 1; |
| 118 | while (i >= 0) { |
| 119 | if (iface->object() == roots.at(i)) |
| 120 | break; |
| 121 | --i; |
| 122 | } |
| 123 | } |
| 124 | return i; |
| 125 | } |
| 126 | |
| 127 | QT_END_NAMESPACE |
| 128 | |
| 129 | #endif // accessibility |
| 130 |
