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 | #else |
91 | Q_UNUSED(text); |
92 | #endif |
93 | return window()->title(); |
94 | } |
95 | |
96 | QAccessibleInterface *QAccessibleQuickWindow::childAt(int x, int y) const |
97 | { |
98 | Q_ASSERT(window()); |
99 | for (int i = childCount() - 1; i >= 0; --i) { |
100 | QAccessibleInterface *childIface = child(index: i); |
101 | if (childIface && !childIface->state().invisible) { |
102 | if (QAccessibleInterface *iface = childIface->childAt(x, y)) |
103 | return iface; |
104 | if (childIface->rect().contains(ax: x, ay: y)) |
105 | return childIface; |
106 | } |
107 | } |
108 | return nullptr; |
109 | } |
110 | |
111 | int QAccessibleQuickWindow::indexOfChild(const QAccessibleInterface *iface) const |
112 | { |
113 | int i = -1; |
114 | if (iface) { |
115 | const QList<QQuickItem *> &roots = rootItems(); |
116 | i = roots.size() - 1; |
117 | while (i >= 0) { |
118 | if (iface->object() == roots.at(i)) |
119 | break; |
120 | --i; |
121 | } |
122 | } |
123 | return i; |
124 | } |
125 | |
126 | QT_END_NAMESPACE |
127 | |
128 | #endif // accessibility |
129 |