/src/qtbase/src/gui/accessible/qaccessibleobject.cpp
Line | Count | Source |
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 "qaccessibleobject.h" |
5 | | |
6 | | #if QT_CONFIG(accessibility) |
7 | | |
8 | | #include <QtGui/QGuiApplication> |
9 | | #include <QtGui/QWindow> |
10 | | |
11 | | #include "qpointer.h" |
12 | | #include "qmetaobject.h" |
13 | | |
14 | | QT_BEGIN_NAMESPACE |
15 | | |
16 | | class QAccessibleObjectPrivate |
17 | | { |
18 | | public: |
19 | | QPointer<QObject> object; |
20 | | }; |
21 | | |
22 | | /*! |
23 | | \class QAccessibleObject |
24 | | \brief The QAccessibleObject class implements parts of the |
25 | | QAccessibleInterface for QObjects. |
26 | | |
27 | | \ingroup accessibility |
28 | | \inmodule QtGui |
29 | | |
30 | | This class is part of \l {Accessibility for QWidget Applications}. |
31 | | |
32 | | This class is mainly provided for convenience. All subclasses of |
33 | | the QAccessibleInterface that provide implementations of non-widget objects |
34 | | should use this class as their base class. |
35 | | |
36 | | \sa QAccessible, QAccessibleWidget |
37 | | */ |
38 | | |
39 | | /*! |
40 | | Creates a QAccessibleObject for \a object. |
41 | | */ |
42 | | QAccessibleObject::QAccessibleObject(QObject *object) |
43 | 0 | { |
44 | 0 | d = new QAccessibleObjectPrivate; |
45 | 0 | d->object = object; |
46 | 0 | } |
47 | | |
48 | | /*! |
49 | | Destroys the QAccessibleObject. |
50 | | |
51 | | This only happens when a call to release() decrements the internal |
52 | | reference counter to zero. |
53 | | */ |
54 | | QAccessibleObject::~QAccessibleObject() |
55 | 0 | { |
56 | 0 | delete d; |
57 | 0 | } |
58 | | |
59 | | /*! |
60 | | \reimp |
61 | | */ |
62 | | QObject *QAccessibleObject::object() const |
63 | 0 | { |
64 | 0 | return d->object; |
65 | 0 | } |
66 | | |
67 | | /*! |
68 | | \reimp |
69 | | */ |
70 | | bool QAccessibleObject::isValid() const |
71 | 0 | { |
72 | 0 | return !d->object.isNull(); |
73 | 0 | } |
74 | | |
75 | | /*! \reimp */ |
76 | | QRect QAccessibleObject::rect() const |
77 | 0 | { |
78 | 0 | return QRect(); |
79 | 0 | } |
80 | | |
81 | | /*! \reimp */ |
82 | | void QAccessibleObject::setText(QAccessible::Text, const QString &) |
83 | 0 | { |
84 | 0 | } |
85 | | |
86 | | /*! \reimp */ |
87 | | QAccessibleInterface *QAccessibleObject::childAt(int x, int y) const |
88 | 0 | { |
89 | 0 | for (int i = 0; i < childCount(); ++i) { |
90 | 0 | QAccessibleInterface *childIface = child(i); |
91 | 0 | Q_ASSERT(childIface); |
92 | 0 | if (childIface->isValid() && childIface->rect().contains(x,y)) |
93 | 0 | return childIface; |
94 | 0 | } |
95 | 0 | return nullptr; |
96 | 0 | } |
97 | | |
98 | | /*! |
99 | | \class QAccessibleApplication |
100 | | \brief The QAccessibleApplication class implements the QAccessibleInterface for QApplication. |
101 | | |
102 | | \internal |
103 | | |
104 | | \ingroup accessibility |
105 | | */ |
106 | | |
107 | | /*! |
108 | | Creates a QAccessibleApplication for the QApplication object referenced by qApp. |
109 | | */ |
110 | | QAccessibleApplication::QAccessibleApplication() |
111 | 0 | : QAccessibleObject(qApp) |
112 | 0 | { |
113 | 0 | } |
114 | | |
115 | | QWindow *QAccessibleApplication::window() const |
116 | 0 | { |
117 | | // an application can have several windows, and AFAIK we don't need |
118 | | // to notify about changes on the application. |
119 | 0 | return nullptr; |
120 | 0 | } |
121 | | |
122 | | // all toplevel windows except popups |
123 | | static QObjectList topLevelObjects() |
124 | 0 | { |
125 | 0 | QObjectList list; |
126 | 0 | const QWindowList tlw(QGuiApplication::topLevelWindows()); |
127 | 0 | for (int i = 0; i < tlw.size(); ++i) { |
128 | 0 | QWindow *w = tlw.at(i); |
129 | 0 | if (w->type() != Qt::Popup) { |
130 | 0 | if (QAccessibleInterface *root = w->accessibleRoot()) { |
131 | 0 | if (root->object()) |
132 | 0 | list.append(root->object()); |
133 | 0 | } |
134 | 0 | } |
135 | 0 | } |
136 | |
|
137 | 0 | return list; |
138 | 0 | } |
139 | | |
140 | | /*! \reimp */ |
141 | | int QAccessibleApplication::childCount() const |
142 | 0 | { |
143 | 0 | return topLevelObjects().size(); |
144 | 0 | } |
145 | | |
146 | | /*! \reimp */ |
147 | | int QAccessibleApplication::indexOfChild(const QAccessibleInterface *child) const |
148 | 0 | { |
149 | 0 | if (!child) |
150 | 0 | return -1; |
151 | 0 | const QObjectList tlw(topLevelObjects()); |
152 | 0 | return tlw.indexOf(child->object()); |
153 | 0 | } |
154 | | |
155 | | QAccessibleInterface *QAccessibleApplication::parent() const |
156 | 0 | { |
157 | 0 | return nullptr; |
158 | 0 | } |
159 | | |
160 | | QAccessibleInterface *QAccessibleApplication::child(int index) const |
161 | 0 | { |
162 | 0 | const QObjectList tlo(topLevelObjects()); |
163 | 0 | if (index >= 0 && index < tlo.size()) |
164 | 0 | return QAccessible::queryAccessibleInterface(tlo.at(index)); |
165 | 0 | return nullptr; |
166 | 0 | } |
167 | | |
168 | | |
169 | | /*! \reimp */ |
170 | | QAccessibleInterface *QAccessibleApplication::focusChild() const |
171 | 0 | { |
172 | 0 | if (QWindow *window = QGuiApplication::focusWindow()) |
173 | 0 | return window->accessibleRoot(); |
174 | 0 | return nullptr; |
175 | 0 | } |
176 | | |
177 | | /*! \reimp */ |
178 | | QString QAccessibleApplication::text(QAccessible::Text t) const |
179 | 0 | { |
180 | 0 | switch (t) { |
181 | 0 | case QAccessible::Name: |
182 | 0 | return QGuiApplication::applicationName(); |
183 | 0 | case QAccessible::Description: |
184 | 0 | return QGuiApplication::applicationFilePath(); |
185 | 0 | case QAccessible::Identifier: |
186 | 0 | return QGuiApplication::desktopFileName(); |
187 | 0 | default: |
188 | 0 | break; |
189 | 0 | } |
190 | 0 | return QString(); |
191 | 0 | } |
192 | | |
193 | | /*! \reimp */ |
194 | | QAccessible::Role QAccessibleApplication::role() const |
195 | 0 | { |
196 | 0 | return QAccessible::Application; |
197 | 0 | } |
198 | | |
199 | | /*! \reimp */ |
200 | | QAccessible::State QAccessibleApplication::state() const |
201 | 0 | { |
202 | 0 | return QAccessible::State(); |
203 | 0 | } |
204 | | |
205 | | |
206 | | QT_END_NAMESPACE |
207 | | |
208 | | #endif // QT_CONFIG(accessibility) |