Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qaccessiblequickview.cpp
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
6
7#include <QtGui/qguiapplication.h>
8#include <QtGui/private/qwindow_p.h>
9
10#include <QtQuick/qquickitem.h>
11#include <QtQuick/private/qquickitem_p.h>
12
14
15#if QT_CONFIG(accessibility)
16
17QT_BEGIN_NAMESPACE
18
19QAccessibleQuickWindow::QAccessibleQuickWindow(QQuickWindow *object)
20 :QAccessibleObject(object)
21{
22}
23
24QList<QQuickItem *> QAccessibleQuickWindow::rootItems() const
25{
26 if (QQuickItem *ci = window() ? window()->contentItem() : nullptr)
27 return accessibleUnignoredChildren(ci);
28 return QList<QQuickItem *>();
29}
30
31int QAccessibleQuickWindow::childCount() const
32{
33 return rootItems().size();
34}
35
36QAccessibleInterface *QAccessibleQuickWindow::parent() const
37{
38 if (QWindow *w = window()) {
39 // A quick window hosted in a window container needs to reflect the container
40 if (QObject *a11yParent = QWindowPrivate::get(w)->accessibleParent)
41 return QAccessible::queryAccessibleInterface(a11yParent);
42 }
43
44 return QAccessible::queryAccessibleInterface(qApp);
45}
46
47QAccessibleInterface *QAccessibleQuickWindow::child(int index) const
48{
49 const QList<QQuickItem*> &kids = rootItems();
50 if (index >= 0 && index < kids.size())
51 return QAccessible::queryAccessibleInterface(kids.at(index));
52 return nullptr;
53}
54
55QAccessibleInterface *QAccessibleQuickWindow::focusChild() const
56{
57 QObject *focusObject = window() ? window()->focusObject() : nullptr;
58 if (focusObject) {
59 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(focusObject);
60 if (!iface || iface == this || !iface->focusChild())
61 return iface;
62 return iface->focusChild();
63 }
64 return nullptr;
65}
66
67QAccessible::Role QAccessibleQuickWindow::role() const
68{
69 if (window() && window()->isTopLevel())
70 return QAccessible::Window;
71
72 return QAccessible::Client;
73}
74
75QAccessible::State QAccessibleQuickWindow::state() const
76{
77 QAccessible::State st;
78
79 if (!window()) {
80 st.invalid = true;
81 return st;
82 }
83
84 st.invisible = !window()->isVisible();
85 st.focused = window() == QGuiApplication::focusWindow();
86 st.active = window()->isActive();
87
88 return st;
89}
90
91QRect QAccessibleQuickWindow::rect() const
92{
93 if (!window())
94 return {};
95 return QRect(window()->mapToGlobal(QPoint(0, 0)), window()->size());
96}
97
98QString QAccessibleQuickWindow::text(QAccessible::Text text) const
99{
100 if (!window())
101 return {};
102#ifdef Q_ACCESSIBLE_QUICK_ITEM_ENABLE_DEBUG_DESCRIPTION
103 if (text == QAccessible::DebugDescription) {
104 return QString::fromLatin1(object()->metaObject()->className()) ;
105 }
106#endif
107 if (text == QAccessible::Name && window()->isTopLevel())
108 return window()->title();
109 else
110 return {};
111}
112
113QAccessibleInterface *QAccessibleQuickWindow::childAt(int x, int y) const
114{
115 Q_ASSERT(window());
116
117 if (!window()->contentItem())
118 return nullptr;
119
120 const QList<QQuickItem *> kids = accessibleUnignoredChildren(window()->contentItem(), true);
121 for (int i = kids.size() - 1; i >= 0; --i) {
122 QAccessibleInterface *childIface = QAccessible::queryAccessibleInterface(kids.at(i));
123 if (childIface && !childIface->state().invisible) {
124 if (QAccessibleInterface *iface = childIface->childAt(x, y))
125 return iface;
126 if (childIface->rect().contains(x, y))
127 return childIface;
128 }
129 }
130 return nullptr;
131}
132
133int QAccessibleQuickWindow::indexOfChild(const QAccessibleInterface *iface) const
134{
135 int i = -1;
136 if (iface) {
137 const QList<QQuickItem *> &roots = rootItems();
138 i = roots.size() - 1;
139 while (i >= 0) {
140 if (iface->object() == roots.at(i))
141 break;
142 --i;
143 }
144 }
145 return i;
146}
147
148QT_END_NAMESPACE
149
150#endif // accessibility