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
atspiadaptor.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
6
7#include <QtGui/qwindow.h>
8#include <QtGui/qguiapplication.h>
9#include <qdbusmessage.h>
10#include <qdbusreply.h>
11#include <qclipboard.h>
12
13#include <QtCore/qloggingcategory.h>
14#include <QtCore/qtversion.h>
15
16#if QT_CONFIG(accessibility)
17#include "socket_interface_p.h"
18#include "qspi_constant_mappings_p.h"
19#include <QtCore/private/qstringiterator_p.h>
20#include <QtGui/private/qaccessiblebridgeutils_p.h>
21
22#include "qspiapplicationadaptor_p.h"
23/*!
24 \class AtSpiAdaptor
25 \internal
26
27 \brief AtSpiAdaptor is the main class to forward between QAccessibleInterface and AT-SPI DBus
28
29 AtSpiAdaptor implements the functions specified in all at-spi interfaces.
30 It sends notifications coming from Qt via dbus and listens to incoming dbus requests.
31*/
32
33// ATSPI_COORD_TYPE_PARENT was added in at-spi 2.30, define here for older versions
34#if ATSPI_COORD_TYPE_COUNT < 3
35#define ATSPI_COORD_TYPE_PARENT 2
36#endif
37
38// ATSPI_*_VERSION defines were added in libatspi 2.50,
39// as was the AtspiLive enum; define values here for older versions
40#if !defined(ATSPI_MAJOR_VERSION) || !defined(ATSPI_MINOR_VERSION) || ATSPI_MAJOR_VERSION < 2 || ATSPI_MINOR_VERSION < 50
41#define ATSPI_LIVE_POLITE 1
42#define ATSPI_LIVE_ASSERTIVE 2
43#endif
44
45QT_BEGIN_NAMESPACE
46
47using namespace Qt::StringLiterals;
48using namespace QtGuiPrivate; // for D-Bus accessibility wrappers
49
50Q_STATIC_LOGGING_CATEGORY(lcAccessibilityAtspi, "qt.accessibility.atspi")
51Q_STATIC_LOGGING_CATEGORY(lcAccessibilityAtspiCreation, "qt.accessibility.atspi.creation")
52
53AtSpiAdaptor::AtSpiAdaptor(QAtSpiDBusConnection *connection, QObject *parent)
54 : QDBusVirtualObject(parent), m_dbus(connection)
55 , sendFocus(0)
56 , sendObject(0)
57 , sendObject_active_descendant_changed(0)
58 , sendObject_announcement(0)
59 , sendObject_attributes_changed(0)
60 , sendObject_bounds_changed(0)
61 , sendObject_children_changed(0)
62// , sendObject_children_changed_add(0)
63// , sendObject_children_changed_remove(0)
64 , sendObject_column_deleted(0)
65 , sendObject_column_inserted(0)
66 , sendObject_column_reordered(0)
67 , sendObject_link_selected(0)
68 , sendObject_model_changed(0)
69 , sendObject_property_change(0)
70 , sendObject_property_change_accessible_description(0)
71 , sendObject_property_change_accessible_name(0)
72 , sendObject_property_change_accessible_parent(0)
73 , sendObject_property_change_accessible_role(0)
74 , sendObject_property_change_accessible_table_caption(0)
75 , sendObject_property_change_accessible_table_column_description(0)
76 , sendObject_property_change_accessible_table_column_header(0)
77 , sendObject_property_change_accessible_table_row_description(0)
78 , sendObject_property_change_accessible_table_row_header(0)
79 , sendObject_property_change_accessible_table_summary(0)
80 , sendObject_property_change_accessible_value(0)
81 , sendObject_row_deleted(0)
82 , sendObject_row_inserted(0)
83 , sendObject_row_reordered(0)
84 , sendObject_selection_changed(0)
85 , sendObject_state_changed(0)
86 , sendObject_text_attributes_changed(0)
87 , sendObject_text_bounds_changed(0)
88 , sendObject_text_caret_moved(0)
89 , sendObject_text_changed(0)
90// , sendObject_text_changed_delete(0)
91// , sendObject_text_changed_insert(0)
92 , sendObject_text_selection_changed(0)
93 , sendObject_value_changed(0)
94 , sendObject_visible_data_changed(0)
95 , sendWindow(0)
96 , sendWindow_activate(0)
97 , sendWindow_close(0)
98 , sendWindow_create(0)
99 , sendWindow_deactivate(0)
100// , sendWindow_desktop_create(0)
101// , sendWindow_desktop_destroy(0)
102 , sendWindow_lower(0)
103 , sendWindow_maximize(0)
104 , sendWindow_minimize(0)
105 , sendWindow_move(0)
106 , sendWindow_raise(0)
107 , sendWindow_reparent(0)
108 , sendWindow_resize(0)
109 , sendWindow_restore(0)
110 , sendWindow_restyle(0)
111 , sendWindow_shade(0)
112 , sendWindow_unshade(0)
113{
114 m_applicationAdaptor = new QSpiApplicationAdaptor(m_dbus->connection(), this);
115 connect(m_applicationAdaptor, SIGNAL(windowActivated(QObject*,bool)), this, SLOT(windowActivated(QObject*,bool)));
116
117 updateEventListeners();
118 bool success = m_dbus->connection().connect("org.a11y.atspi.Registry"_L1, "/org/a11y/atspi/registry"_L1,
119 "org.a11y.atspi.Registry"_L1, "EventListenerRegistered"_L1, this,
120 SLOT(eventListenerRegistered(QString,QString)));
121 success = success && m_dbus->connection().connect("org.a11y.atspi.Registry"_L1, "/org/a11y/atspi/registry"_L1,
122 "org.a11y.atspi.Registry"_L1, "EventListenerDeregistered"_L1, this,
123 SLOT(eventListenerDeregistered(QString,QString)));
124}
125
126AtSpiAdaptor::~AtSpiAdaptor()
127{
128}
129
130/*!
131 Provide DBus introspection.
132 */
133QString AtSpiAdaptor::introspect(const QString &path) const
134{
135 constexpr auto accessibleIntrospection =
136 " <interface name=\"org.a11y.atspi.Accessible\">\n"
137 " <property access=\"read\" type=\"s\" name=\"Name\"/>\n"
138 " <property access=\"read\" type=\"s\" name=\"Description\"/>\n"
139 " <property access=\"read\" type=\"s\" name=\"HelpText\"/>\n"
140 " <property access=\"read\" type=\"(so)\" name=\"Parent\">\n"
141 " <annotation value=\"QSpiObjectReference\" name=\"org.qtproject.QtDBus.QtTypeName\"/>\n"
142 " </property>\n"
143 " <property access=\"read\" type=\"i\" name=\"ChildCount\"/>\n"
144 " <method name=\"GetChildAtIndex\">\n"
145 " <arg direction=\"in\" type=\"i\" name=\"index\"/>\n"
146 " <arg direction=\"out\" type=\"(so)\"/>\n"
147 " <annotation value=\"QSpiObjectReference\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
148 " </method>\n"
149 " <method name=\"GetChildren\">\n"
150 " <arg direction=\"out\" type=\"a(so)\"/>\n"
151 " <annotation value=\"QSpiObjectReferenceArray\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
152 " </method>\n"
153 " <method name=\"GetIndexInParent\">\n"
154 " <arg direction=\"out\" type=\"i\"/>\n"
155 " </method>\n"
156 " <method name=\"GetRelationSet\">\n"
157 " <arg direction=\"out\" type=\"a(ua(so))\"/>\n"
158 " <annotation value=\"QSpiRelationArray\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
159 " </method>\n"
160 " <method name=\"GetRole\">\n"
161 " <arg direction=\"out\" type=\"u\"/>\n"
162 " </method>\n"
163 " <method name=\"GetRoleName\">\n"
164 " <arg direction=\"out\" type=\"s\"/>\n"
165 " </method>\n"
166 " <method name=\"GetLocalizedRoleName\">\n"
167 " <arg direction=\"out\" type=\"s\"/>\n"
168 " </method>\n"
169 " <method name=\"GetState\">\n"
170 " <arg direction=\"out\" type=\"au\"/>\n"
171 " <annotation value=\"QSpiUIntList\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
172 " </method>\n"
173 " <method name=\"GetAttributes\">\n"
174 " <arg direction=\"out\" type=\"a{ss}\"/>\n"
175 " <annotation value=\"QSpiAttributeSet\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
176 " </method>\n"
177 " <method name=\"GetApplication\">\n"
178 " <arg direction=\"out\" type=\"(so)\"/>\n"
179 " <annotation value=\"QSpiObjectReference\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
180 " </method>\n"
181 " <method name=\"GetAccessibleId\">\n"
182 " <arg direction=\"out\" type=\"s\"/>\n"
183 " </method>\n"
184 " </interface>\n"
185 ""_L1;
186
187 constexpr auto actionIntrospection =
188 " <interface name=\"org.a11y.atspi.Action\">\n"
189 " <property access=\"read\" type=\"i\" name=\"NActions\"/>\n"
190 " <method name=\"GetDescription\">\n"
191 " <arg direction=\"in\" type=\"i\" name=\"index\"/>\n"
192 " <arg direction=\"out\" type=\"s\"/>\n"
193 " </method>\n"
194 " <method name=\"GetName\">\n"
195 " <arg direction=\"in\" type=\"i\" name=\"index\"/>\n"
196 " <arg direction=\"out\" type=\"s\"/>\n"
197 " </method>\n"
198 " <method name=\"GetKeyBinding\">\n"
199 " <arg direction=\"in\" type=\"i\" name=\"index\"/>\n"
200 " <arg direction=\"out\" type=\"s\"/>\n"
201 " </method>\n"
202 " <method name=\"GetActions\">\n"
203 " <arg direction=\"out\" type=\"a(sss)\" name=\"index\"/>\n"
204 " <annotation value=\"QSpiActionArray\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
205 " </method>\n"
206 " <method name=\"DoAction\">\n"
207 " <arg direction=\"in\" type=\"i\" name=\"index\"/>\n"
208 " <arg direction=\"out\" type=\"b\"/>\n"
209 " </method>\n"
210 " </interface>\n"
211 ""_L1;
212
213 constexpr auto applicationIntrospection =
214 " <interface name=\"org.a11y.atspi.Application\">\n"
215 " <property access=\"read\" type=\"s\" name=\"ToolkitName\"/>\n"
216 " <property access=\"read\" type=\"s\" name=\"Version\"/>\n"
217 " <property access=\"readwrite\" type=\"i\" name=\"Id\"/>\n"
218 " <method name=\"GetLocale\">\n"
219 " <arg direction=\"in\" type=\"u\" name=\"lctype\"/>\n"
220 " <arg direction=\"out\" type=\"s\"/>\n"
221 " </method>\n"
222 " <method name=\"GetApplicationBusAddress\">\n"
223 " <arg direction=\"out\" type=\"s\" name=\"address\"/>\n"
224 " </method>\n"
225 " </interface>\n"
226 ""_L1;
227
228 constexpr auto collectionIntrospection =
229 " <interface name=\"org.a11y.atspi.Collection\">\n"
230 " <method name=\"GetMatches\">\n"
231 " <arg direction=\"in\" name=\"rule\" type=\"(aiia{ss}iaiiasib)\"/>\n"
232 " <annotation name=\"org.qtproject.QtDBus.QtTypeName.In0\" value=\"QSpiMatchRule\"/>\n"
233 " <arg direction=\"in\" name=\"sortby\" type=\"u\"/>\n"
234 " <arg direction=\"in\" name=\"count\" type=\"i\"/>\n"
235 " <arg direction=\"in\" name=\"traverse\" type=\"b\"/>\n"
236 " <arg direction=\"out\" type=\"a(so)\"/>\n"
237 " <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"QSpiReferenceSet\"/>\n"
238 " </method>\n"
239 " <method name=\"GetMatchesTo\">\n"
240 " <arg direction=\"in\" name=\"current_object\" type=\"o\"/>\n"
241 " <annotation name=\"org.qtproject.QtDBus.QtTypeName.In0\" value=\"QSpiObjectReference\"/>\n"
242 " <arg direction=\"in\" name=\"rule\" type=\"(aiia{ss}iaiiasib)\"/>\n"
243 " <annotation name=\"org.qtproject.QtDBus.QtTypeName.In1\" value=\"QSpiMatchRule\"/>\n"
244 " <arg direction=\"in\" name=\"sortby\" type=\"u\"/>\n"
245 " <arg direction=\"in\" name=\"tree\" type=\"u\"/>\n"
246 " <arg direction=\"in\" name=\"limit_scope\" type=\"b\"/>\n"
247 " <arg direction=\"in\" name=\"count\" type=\"i\"/>\n"
248 " <arg direction=\"in\" name=\"traverse\" type=\"b\"/>\n"
249 " <arg direction=\"out\" type=\"a(so)\"/>\n"
250 " <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"QSpiReferenceSet\"/>\n"
251 " </method>\n"
252 " <method name=\"GetMatchesFrom\">\n"
253 " <arg direction=\"in\" name=\"current_object\" type=\"o\"/>\n"
254 " <annotation name=\"org.qtproject.QtDBus.QtTypeName.In0\" value=\"QSpiObjectReference\"/>\n"
255 " <arg direction=\"in\" name=\"rule\" type=\"(aiia{ss}iaiiasib)\"/>\n"
256 " <annotation name=\"org.qtproject.QtDBus.QtTypeName.In1\" value=\"QSpiMatchRule\"/>\n"
257 " <arg direction=\"in\" name=\"sortby\" type=\"u\"/>\n"
258 " <arg direction=\"in\" name=\"tree\" type=\"u\"/>\n"
259 " <arg direction=\"in\" name=\"count\" type=\"i\"/>\n"
260 " <arg direction=\"in\" name=\"traverse\" type=\"b\"/>\n"
261 " <arg direction=\"out\" type=\"a(so)\"/>\n"
262 " <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"QSpiReferenceSet\"/>\n"
263 " </method>\n"
264 " <method name=\"GetActiveDescendant\">\n"
265 " <arg direction=\"out\" type=\"(so)\"/>\n"
266 " <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"QSpiReferenceSet\"/>\n"
267 " </method>\n"
268 " </interface>\n"
269 ""_L1;
270
271 constexpr auto componentIntrospection =
272 " <interface name=\"org.a11y.atspi.Component\">\n"
273 " <method name=\"Contains\">\n"
274 " <arg direction=\"in\" type=\"i\" name=\"x\"/>\n"
275 " <arg direction=\"in\" type=\"i\" name=\"y\"/>\n"
276 " <arg direction=\"in\" type=\"u\" name=\"coord_type\"/>\n"
277 " <arg direction=\"out\" type=\"b\"/>\n"
278 " </method>\n"
279 " <method name=\"GetAccessibleAtPoint\">\n"
280 " <arg direction=\"in\" type=\"i\" name=\"x\"/>\n"
281 " <arg direction=\"in\" type=\"i\" name=\"y\"/>\n"
282 " <arg direction=\"in\" type=\"u\" name=\"coord_type\"/>\n"
283 " <arg direction=\"out\" type=\"(so)\"/>\n"
284 " <annotation value=\"QSpiObjectReference\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
285 " </method>\n"
286 " <method name=\"GetExtents\">\n"
287 " <arg direction=\"in\" type=\"u\" name=\"coord_type\"/>\n"
288 " <arg direction=\"out\" type=\"(iiii)\"/>\n"
289 " <annotation value=\"QSpiRect\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
290 " </method>\n"
291 " <method name=\"GetPosition\">\n"
292 " <arg direction=\"in\" type=\"u\" name=\"coord_type\"/>\n"
293 " <arg direction=\"out\" type=\"i\" name=\"x\"/>\n"
294 " <arg direction=\"out\" type=\"i\" name=\"y\"/>\n"
295 " </method>\n"
296 " <method name=\"GetSize\">\n"
297 " <arg direction=\"out\" type=\"i\" name=\"width\"/>\n"
298 " <arg direction=\"out\" type=\"i\" name=\"height\"/>\n"
299 " </method>\n"
300 " <method name=\"GetLayer\">\n"
301 " <arg direction=\"out\" type=\"u\"/>\n"
302 " </method>\n"
303 " <method name=\"GetMDIZOrder\">\n"
304 " <arg direction=\"out\" type=\"n\"/>\n"
305 " </method>\n"
306 " <method name=\"GrabFocus\">\n"
307 " <arg direction=\"out\" type=\"b\"/>\n"
308 " </method>\n"
309 " <method name=\"GetAlpha\">\n"
310 " <arg direction=\"out\" type=\"d\"/>\n"
311 " </method>\n"
312 " <method name=\"SetExtents\">\n"
313 " <arg direction=\"in\" type=\"i\" name=\"x\"/>\n"
314 " <arg direction=\"in\" type=\"i\" name=\"y\"/>\n"
315 " <arg direction=\"in\" type=\"i\" name=\"width\"/>\n"
316 " <arg direction=\"in\" type=\"i\" name=\"height\"/>\n"
317 " <arg direction=\"in\" type=\"u\" name=\"coord_type\"/>\n"
318 " <arg direction=\"out\" type=\"b\"/>\n"
319 " </method>\n"
320 " <method name=\"SetPosition\">\n"
321 " <arg direction=\"in\" type=\"i\" name=\"x\"/>\n"
322 " <arg direction=\"in\" type=\"i\" name=\"y\"/>\n"
323 " <arg direction=\"in\" type=\"u\" name=\"coord_type\"/>\n"
324 " <arg direction=\"out\" type=\"b\"/>\n"
325 " </method>\n"
326 " <method name=\"SetSize\">\n"
327 " <arg direction=\"in\" type=\"i\" name=\"width\"/>\n"
328 " <arg direction=\"in\" type=\"i\" name=\"height\"/>\n"
329 " <arg direction=\"out\" type=\"b\"/>\n"
330 " </method>\n"
331 " </interface>\n"
332 ""_L1;
333
334 constexpr auto editableTextIntrospection =
335 " <interface name=\"org.a11y.atspi.EditableText\">\n"
336 " <method name=\"SetTextContents\">\n"
337 " <arg direction=\"in\" type=\"s\" name=\"newContents\"/>\n"
338 " <arg direction=\"out\" type=\"b\"/>\n"
339 " </method>\n"
340 " <method name=\"InsertText\">\n"
341 " <arg direction=\"in\" type=\"i\" name=\"position\"/>\n"
342 " <arg direction=\"in\" type=\"s\" name=\"text\"/>\n"
343 " <arg direction=\"in\" type=\"i\" name=\"length\"/>\n"
344 " <arg direction=\"out\" type=\"b\"/>\n"
345 " </method>\n"
346 " <method name=\"CopyText\">\n"
347 " <arg direction=\"in\" type=\"i\" name=\"startPos\"/>\n"
348 " <arg direction=\"in\" type=\"i\" name=\"endPos\"/>\n"
349 " </method>\n"
350 " <method name=\"CutText\">\n"
351 " <arg direction=\"in\" type=\"i\" name=\"startPos\"/>\n"
352 " <arg direction=\"in\" type=\"i\" name=\"endPos\"/>\n"
353 " <arg direction=\"out\" type=\"b\"/>\n"
354 " </method>\n"
355 " <method name=\"DeleteText\">\n"
356 " <arg direction=\"in\" type=\"i\" name=\"startPos\"/>\n"
357 " <arg direction=\"in\" type=\"i\" name=\"endPos\"/>\n"
358 " <arg direction=\"out\" type=\"b\"/>\n"
359 " </method>\n"
360 " <method name=\"PasteText\">\n"
361 " <arg direction=\"in\" type=\"i\" name=\"position\"/>\n"
362 " <arg direction=\"out\" type=\"b\"/>\n"
363 " </method>\n"
364 " </interface>\n"
365 ""_L1;
366
367 constexpr auto selectionIntrospection =
368 " <interface name=\"org.a11y.atspi.Selection\">\n"
369 " <property name=\"NSelectedChildren\" type=\"i\" access=\"read\"/>\n"
370 " <method name=\"GetSelectedChild\">\n"
371 " <arg direction=\"in\" name=\"selectedChildIndex\" type=\"i\"/>\n"
372 " <arg direction=\"out\" type=\"(so)\"/>\n"
373 " <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"QSpiObjectReference\"/>\n"
374 " </method>\n"
375 " <method name=\"SelectChild\">\n"
376 " <arg direction=\"in\" name=\"childIndex\" type=\"i\"/>\n"
377 " <arg direction=\"out\" type=\"b\"/>\n"
378 " </method>\n"
379 " <method name=\"DeselectSelectedChild\">\n"
380 " <arg direction=\"in\" name=\"selectedChildIndex\" type=\"i\"/>\n"
381 " <arg direction=\"out\" type=\"b\"/>\n"
382 " </method>\n"
383 " <method name=\"IsChildSelected\">\n"
384 " <arg direction=\"in\" name=\"childIndex\" type=\"i\"/>\n"
385 " <arg direction=\"out\" type=\"b\"/>\n"
386 " </method>\n"
387 " <method name=\"SelectAll\">\n"
388 " <arg direction=\"out\" type=\"b\"/>\n"
389 " </method>\n"
390 " <method name=\"ClearSelection\">\n"
391 " <arg direction=\"out\" type=\"b\"/>\n"
392 " </method>\n"
393 " <method name=\"DeselectChild\">\n"
394 " <arg direction=\"in\" name=\"childIndex\" type=\"i\"/>\n"
395 " <arg direction=\"out\" type=\"b\"/>\n"
396 " </method>\n"
397 " </interface>\n"
398 ""_L1;
399
400 constexpr auto tableIntrospection =
401 " <interface name=\"org.a11y.atspi.Table\">\n"
402 " <property access=\"read\" type=\"i\" name=\"NRows\"/>\n"
403 " <property access=\"read\" type=\"i\" name=\"NColumns\"/>\n"
404 " <property access=\"read\" type=\"(so)\" name=\"Caption\">\n"
405 " <annotation value=\"QSpiObjectReference\" name=\"org.qtproject.QtDBus.QtTypeName\"/>\n"
406 " </property>\n"
407 " <property access=\"read\" type=\"(so)\" name=\"Summary\">\n"
408 " <annotation value=\"QSpiObjectReference\" name=\"org.qtproject.QtDBus.QtTypeName\"/>\n"
409 " </property>\n"
410 " <property access=\"read\" type=\"i\" name=\"NSelectedRows\"/>\n"
411 " <property access=\"read\" type=\"i\" name=\"NSelectedColumns\"/>\n"
412 " <method name=\"GetAccessibleAt\">\n"
413 " <arg direction=\"in\" type=\"i\" name=\"row\"/>\n"
414 " <arg direction=\"in\" type=\"i\" name=\"column\"/>\n"
415 " <arg direction=\"out\" type=\"(so)\"/>\n"
416 " <annotation value=\"QSpiObjectReference\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
417 " </method>\n"
418 " <method name=\"GetIndexAt\">\n"
419 " <arg direction=\"in\" type=\"i\" name=\"row\"/>\n"
420 " <arg direction=\"in\" type=\"i\" name=\"column\"/>\n"
421 " <arg direction=\"out\" type=\"i\"/>\n"
422 " </method>\n"
423 " <method name=\"GetRowAtIndex\">\n"
424 " <arg direction=\"in\" type=\"i\" name=\"index\"/>\n"
425 " <arg direction=\"out\" type=\"i\"/>\n"
426 " </method>\n"
427 " <method name=\"GetColumnAtIndex\">\n"
428 " <arg direction=\"in\" type=\"i\" name=\"index\"/>\n"
429 " <arg direction=\"out\" type=\"i\"/>\n"
430 " </method>\n"
431 " <method name=\"GetRowDescription\">\n"
432 " <arg direction=\"in\" type=\"i\" name=\"row\"/>\n"
433 " <arg direction=\"out\" type=\"s\"/>\n"
434 " </method>\n"
435 " <method name=\"GetColumnDescription\">\n"
436 " <arg direction=\"in\" type=\"i\" name=\"column\"/>\n"
437 " <arg direction=\"out\" type=\"s\"/>\n"
438 " </method>\n"
439 " <method name=\"GetRowExtentAt\">\n"
440 " <arg direction=\"in\" type=\"i\" name=\"row\"/>\n"
441 " <arg direction=\"in\" type=\"i\" name=\"column\"/>\n"
442 " <arg direction=\"out\" type=\"i\"/>\n"
443 " </method>\n"
444 " <method name=\"GetColumnExtentAt\">\n"
445 " <arg direction=\"in\" type=\"i\" name=\"row\"/>\n"
446 " <arg direction=\"in\" type=\"i\" name=\"column\"/>\n"
447 " <arg direction=\"out\" type=\"i\"/>\n"
448 " </method>\n"
449 " <method name=\"GetRowHeader\">\n"
450 " <arg direction=\"in\" type=\"i\" name=\"row\"/>\n"
451 " <arg direction=\"out\" type=\"(so)\"/>\n"
452 " <annotation value=\"QSpiObjectReference\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
453 " </method>\n"
454 " <method name=\"GetColumnHeader\">\n"
455 " <arg direction=\"in\" type=\"i\" name=\"column\"/>\n"
456 " <arg direction=\"out\" type=\"(so)\"/>\n"
457 " <annotation value=\"QSpiObjectReference\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
458 " </method>\n"
459 " <method name=\"GetSelectedRows\">\n"
460 " <arg direction=\"out\" type=\"ai\"/>\n"
461 " <annotation value=\"QSpiIntList\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
462 " </method>\n"
463 " <method name=\"GetSelectedColumns\">\n"
464 " <arg direction=\"out\" type=\"ai\"/>\n"
465 " <annotation value=\"QSpiIntList\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
466 " </method>\n"
467 " <method name=\"IsRowSelected\">\n"
468 " <arg direction=\"in\" type=\"i\" name=\"row\"/>\n"
469 " <arg direction=\"out\" type=\"b\"/>\n"
470 " </method>\n"
471 " <method name=\"IsColumnSelected\">\n"
472 " <arg direction=\"in\" type=\"i\" name=\"column\"/>\n"
473 " <arg direction=\"out\" type=\"b\"/>\n"
474 " </method>\n"
475 " <method name=\"IsSelected\">\n"
476 " <arg direction=\"in\" type=\"i\" name=\"row\"/>\n"
477 " <arg direction=\"in\" type=\"i\" name=\"column\"/>\n"
478 " <arg direction=\"out\" type=\"b\"/>\n"
479 " </method>\n"
480 " <method name=\"AddRowSelection\">\n"
481 " <arg direction=\"in\" type=\"i\" name=\"row\"/>\n"
482 " <arg direction=\"out\" type=\"b\"/>\n"
483 " </method>\n"
484 " <method name=\"AddColumnSelection\">\n"
485 " <arg direction=\"in\" type=\"i\" name=\"column\"/>\n"
486 " <arg direction=\"out\" type=\"b\"/>\n"
487 " </method>\n"
488 " <method name=\"RemoveRowSelection\">\n"
489 " <arg direction=\"in\" type=\"i\" name=\"row\"/>\n"
490 " <arg direction=\"out\" type=\"b\"/>\n"
491 " </method>\n"
492 " <method name=\"RemoveColumnSelection\">\n"
493 " <arg direction=\"in\" type=\"i\" name=\"column\"/>\n"
494 " <arg direction=\"out\" type=\"b\"/>\n"
495 " </method>\n"
496 " <method name=\"GetRowColumnExtentsAtIndex\">\n"
497 " <arg direction=\"in\" type=\"i\" name=\"index\"/>\n"
498 " <arg direction=\"out\" type=\"b\"/>\n"
499 " <arg direction=\"out\" type=\"i\" name=\"row\"/>\n"
500 " <arg direction=\"out\" type=\"i\" name=\"col\"/>\n"
501 " <arg direction=\"out\" type=\"i\" name=\"row_extents\"/>\n"
502 " <arg direction=\"out\" type=\"i\" name=\"col_extents\"/>\n"
503 " <arg direction=\"out\" type=\"b\" name=\"is_selected\"/>\n"
504 " </method>\n"
505 " </interface>\n"
506 ""_L1;
507
508 constexpr auto tableCellIntrospection =
509 " <interface name=\"org.a11y.atspi.TableCell\">\n"
510 " <property access=\"read\" name=\"ColumnSpan\" type=\"i\" />\n"
511 " <property access=\"read\" name=\"Position\" type=\"(ii)\">\n"
512 " <annotation name=\"org.qtproject.QtDBus.QtTypeName\" value=\"QPoint\"/>\n"
513 " </property>\n"
514 " <property access=\"read\" name=\"RowSpan\" type=\"i\" />\n"
515 " <property access=\"read\" name=\"Table\" type=\"(so)\" >\n"
516 " <annotation name=\"org.qtproject.QtDBus.QtTypeName\" value=\"QSpiObjectReference\"/>\n"
517 " </property>\n"
518 " <method name=\"GetRowColumnSpan\">\n"
519 " <arg direction=\"out\" type=\"b\" />\n"
520 " <arg direction=\"out\" name=\"row\" type=\"i\" />\n"
521 " <arg direction=\"out\" name=\"col\" type=\"i\" />\n"
522 " <arg direction=\"out\" name=\"row_extents\" type=\"i\" />\n"
523 " <arg direction=\"out\" name=\"col_extents\" type=\"i\" />\n"
524 " </method>\n"
525 " <method name=\"GetColumnHeaderCells\">\n"
526 " <arg direction=\"out\" type=\"a(so)\"/>\n"
527 " <annotation value=\"QSpiObjectReferenceArray\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
528 " </method>\n"
529 " <method name=\"GetRowHeaderCells\">\n"
530 " <arg direction=\"out\" type=\"a(so)\"/>\n"
531 " <annotation value=\"QSpiObjectReferenceArray\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
532 " </method>\n"
533 " </interface>\n"
534 ""_L1;
535
536 constexpr auto textIntrospection =
537 " <interface name=\"org.a11y.atspi.Text\">\n"
538 " <property access=\"read\" type=\"i\" name=\"CharacterCount\"/>\n"
539 " <property access=\"read\" type=\"i\" name=\"CaretOffset\"/>\n"
540 " <method name=\"GetStringAtOffset\">\n"
541 " <arg direction=\"in\" name=\"offset\" type=\"i\"/>\n"
542 " <arg direction=\"in\" name=\"granularity\" type=\"u\"/>\n"
543 " <arg direction=\"out\" type=\"s\"/>\n"
544 " <arg direction=\"out\" name=\"startOffset\" type=\"i\"/>\n"
545 " <arg direction=\"out\" name=\"endOffset\" type=\"i\"/>\n"
546 " </method>\n"
547 " <method name=\"GetText\">\n"
548 " <arg direction=\"in\" type=\"i\" name=\"startOffset\"/>\n"
549 " <arg direction=\"in\" type=\"i\" name=\"endOffset\"/>\n"
550 " <arg direction=\"out\" type=\"s\"/>\n"
551 " </method>\n"
552 " <method name=\"SetCaretOffset\">\n"
553 " <arg direction=\"in\" type=\"i\" name=\"offset\"/>\n"
554 " <arg direction=\"out\" type=\"b\"/>\n"
555 " </method>\n"
556 " <method name=\"GetTextBeforeOffset\">\n"
557 " <arg direction=\"in\" type=\"i\" name=\"offset\"/>\n"
558 " <arg direction=\"in\" type=\"u\" name=\"type\"/>\n"
559 " <arg direction=\"out\" type=\"s\"/>\n"
560 " <arg direction=\"out\" type=\"i\" name=\"startOffset\"/>\n"
561 " <arg direction=\"out\" type=\"i\" name=\"endOffset\"/>\n"
562 " </method>\n"
563 " <method name=\"GetTextAtOffset\">\n"
564 " <arg direction=\"in\" type=\"i\" name=\"offset\"/>\n"
565 " <arg direction=\"in\" type=\"u\" name=\"type\"/>\n"
566 " <arg direction=\"out\" type=\"s\"/>\n"
567 " <arg direction=\"out\" type=\"i\" name=\"startOffset\"/>\n"
568 " <arg direction=\"out\" type=\"i\" name=\"endOffset\"/>\n"
569 " </method>\n"
570 " <method name=\"GetTextAfterOffset\">\n"
571 " <arg direction=\"in\" type=\"i\" name=\"offset\"/>\n"
572 " <arg direction=\"in\" type=\"u\" name=\"type\"/>\n"
573 " <arg direction=\"out\" type=\"s\"/>\n"
574 " <arg direction=\"out\" type=\"i\" name=\"startOffset\"/>\n"
575 " <arg direction=\"out\" type=\"i\" name=\"endOffset\"/>\n"
576 " </method>\n"
577 " <method name=\"GetCharacterAtOffset\">\n"
578 " <arg direction=\"in\" type=\"i\" name=\"offset\"/>\n"
579 " <arg direction=\"out\" type=\"i\"/>\n"
580 " </method>\n"
581 " <method name=\"GetAttributeValue\">\n"
582 " <arg direction=\"in\" type=\"i\" name=\"offset\"/>\n"
583 " <arg direction=\"in\" type=\"s\" name=\"attributeName\"/>\n"
584 " <arg direction=\"out\" type=\"s\"/>\n"
585 " </method>\n"
586 " <method name=\"GetAttributes\">\n"
587 " <arg direction=\"in\" type=\"i\" name=\"offset\"/>\n"
588 " <arg direction=\"out\" type=\"a{ss}\"/>\n"
589 " <arg direction=\"out\" type=\"i\" name=\"startOffset\"/>\n"
590 " <arg direction=\"out\" type=\"i\" name=\"endOffset\"/>\n"
591 " <annotation value=\"QSpiAttributeSet\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
592 " </method>\n"
593 " <method name=\"GetDefaultAttributes\">\n"
594 " <arg direction=\"out\" type=\"a{ss}\"/>\n"
595 " <annotation value=\"QSpiAttributeSet\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
596 " </method>\n"
597 " <method name=\"GetCharacterExtents\">\n"
598 " <arg direction=\"in\" type=\"i\" name=\"offset\"/>\n"
599 " <arg direction=\"out\" type=\"i\" name=\"x\"/>\n"
600 " <arg direction=\"out\" type=\"i\" name=\"y\"/>\n"
601 " <arg direction=\"out\" type=\"i\" name=\"width\"/>\n"
602 " <arg direction=\"out\" type=\"i\" name=\"height\"/>\n"
603 " <arg direction=\"in\" type=\"u\" name=\"coordType\"/>\n"
604 " </method>\n"
605 " <method name=\"GetOffsetAtPoint\">\n"
606 " <arg direction=\"in\" type=\"i\" name=\"x\"/>\n"
607 " <arg direction=\"in\" type=\"i\" name=\"y\"/>\n"
608 " <arg direction=\"in\" type=\"u\" name=\"coordType\"/>\n"
609 " <arg direction=\"out\" type=\"i\"/>\n"
610 " </method>\n"
611 " <method name=\"GetNSelections\">\n"
612 " <arg direction=\"out\" type=\"i\"/>\n"
613 " </method>\n"
614 " <method name=\"GetSelection\">\n"
615 " <arg direction=\"in\" type=\"i\" name=\"selectionNum\"/>\n"
616 " <arg direction=\"out\" type=\"i\" name=\"startOffset\"/>\n"
617 " <arg direction=\"out\" type=\"i\" name=\"endOffset\"/>\n"
618 " </method>\n"
619 " <method name=\"AddSelection\">\n"
620 " <arg direction=\"in\" type=\"i\" name=\"startOffset\"/>\n"
621 " <arg direction=\"in\" type=\"i\" name=\"endOffset\"/>\n"
622 " <arg direction=\"out\" type=\"b\"/>\n"
623 " </method>\n"
624 " <method name=\"RemoveSelection\">\n"
625 " <arg direction=\"in\" type=\"i\" name=\"selectionNum\"/>\n"
626 " <arg direction=\"out\" type=\"b\"/>\n"
627 " </method>\n"
628 " <method name=\"SetSelection\">\n"
629 " <arg direction=\"in\" type=\"i\" name=\"selectionNum\"/>\n"
630 " <arg direction=\"in\" type=\"i\" name=\"startOffset\"/>\n"
631 " <arg direction=\"in\" type=\"i\" name=\"endOffset\"/>\n"
632 " <arg direction=\"out\" type=\"b\"/>\n"
633 " </method>\n"
634 " <method name=\"GetRangeExtents\">\n"
635 " <arg direction=\"in\" type=\"i\" name=\"startOffset\"/>\n"
636 " <arg direction=\"in\" type=\"i\" name=\"endOffset\"/>\n"
637 " <arg direction=\"out\" type=\"i\" name=\"x\"/>\n"
638 " <arg direction=\"out\" type=\"i\" name=\"y\"/>\n"
639 " <arg direction=\"out\" type=\"i\" name=\"width\"/>\n"
640 " <arg direction=\"out\" type=\"i\" name=\"height\"/>\n"
641 " <arg direction=\"in\" type=\"u\" name=\"coordType\"/>\n"
642 " </method>\n"
643 " <method name=\"GetBoundedRanges\">\n"
644 " <arg direction=\"in\" type=\"i\" name=\"x\"/>\n"
645 " <arg direction=\"in\" type=\"i\" name=\"y\"/>\n"
646 " <arg direction=\"in\" type=\"i\" name=\"width\"/>\n"
647 " <arg direction=\"in\" type=\"i\" name=\"height\"/>\n"
648 " <arg direction=\"in\" type=\"u\" name=\"coordType\"/>\n"
649 " <arg direction=\"in\" type=\"u\" name=\"xClipType\"/>\n"
650 " <arg direction=\"in\" type=\"u\" name=\"yClipType\"/>\n"
651 " <arg direction=\"out\" type=\"a(iisv)\"/>\n"
652 " <annotation value=\"QSpiRangeList\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
653 " </method>\n"
654 " <method name=\"GetAttributeRun\">\n"
655 " <arg direction=\"in\" type=\"i\" name=\"offset\"/>\n"
656 " <arg direction=\"in\" type=\"b\" name=\"includeDefaults\"/>\n"
657 " <arg direction=\"out\" type=\"a{ss}\"/>\n"
658 " <arg direction=\"out\" type=\"i\" name=\"startOffset\"/>\n"
659 " <arg direction=\"out\" type=\"i\" name=\"endOffset\"/>\n"
660 " <annotation value=\"QSpiAttributeSet\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
661 " </method>\n"
662 " <method name=\"GetDefaultAttributeSet\">\n"
663 " <arg direction=\"out\" type=\"a{ss}\"/>\n"
664 " <annotation value=\"QSpiAttributeSet\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
665 " </method>\n"
666 " <method name=\"ScrollSubstringTo\">\n"
667 " <arg direction=\"in\" name=\"startOffset\" type=\"i\"/>\n"
668 " <arg direction=\"in\" name=\"endOffset\" type=\"i\"/>\n"
669 " <arg direction=\"in\" name=\"type\" type=\"u\"/>\n"
670 " <arg direction=\"out\" type=\"b\"/>\n"
671 " </method>\n"
672 " </interface>\n"
673 ""_L1;
674
675 constexpr auto valueIntrospection =
676 " <interface name=\"org.a11y.atspi.Value\">\n"
677 " <property access=\"read\" type=\"d\" name=\"MinimumValue\"/>\n"
678 " <property access=\"read\" type=\"d\" name=\"MaximumValue\"/>\n"
679 " <property access=\"read\" type=\"d\" name=\"MinimumIncrement\"/>\n"
680 " <property access=\"readwrite\" type=\"d\" name=\"CurrentValue\"/>\n"
681 " <method name=\"SetCurrentValue\">\n"
682 " <arg direction=\"in\" type=\"d\" name=\"value\"/>\n"
683 " </method>\n"
684 " </interface>\n"
685 ""_L1;
686
687 QAccessibleInterface * interface = interfaceFromPath(path);
688 if (!interface) {
689 qCWarning(lcAccessibilityAtspi) << "Could not find accessible on path:" << path;
690 return QString();
691 }
692
693 QStringList interfaces = accessibleInterfaces(interface);
694
695 QString xml;
696 xml.append(accessibleIntrospection);
697 xml.append(collectionIntrospection);
698
699 if (interfaces.contains(ATSPI_DBUS_INTERFACE_COMPONENT ""_L1))
700 xml.append(componentIntrospection);
701 if (interfaces.contains(ATSPI_DBUS_INTERFACE_TEXT ""_L1))
702 xml.append(textIntrospection);
703 if (interfaces.contains(ATSPI_DBUS_INTERFACE_EDITABLE_TEXT ""_L1))
704 xml.append(editableTextIntrospection);
705 if (interfaces.contains(ATSPI_DBUS_INTERFACE_ACTION ""_L1))
706 xml.append(actionIntrospection);
707 if (interfaces.contains(ATSPI_DBUS_INTERFACE_SELECTION ""_L1))
708 xml.append(selectionIntrospection);
709 if (interfaces.contains(ATSPI_DBUS_INTERFACE_TABLE ""_L1))
710 xml.append(tableIntrospection);
711 if (interfaces.contains(ATSPI_DBUS_INTERFACE_TABLE_CELL ""_L1))
712 xml.append(tableCellIntrospection);
713 if (interfaces.contains(ATSPI_DBUS_INTERFACE_VALUE ""_L1))
714 xml.append(valueIntrospection);
715 if (path == ATSPI_DBUS_PATH_ROOT ""_L1)
716 xml.append(applicationIntrospection);
717
718 return xml;
719}
720
721void AtSpiAdaptor::setBitFlag(const QString &flag)
722{
723 Q_ASSERT(flag.size());
724
725 // assume we don't get nonsense - look at first letter only
726 switch (flag.at(0).toLower().toLatin1()) {
727 case 'o': {
728 if (flag.size() <= 8) { // Object::
729 sendObject = 1;
730 } else { // Object:Foo:Bar
731 QString right = flag.mid(7);
732 if (false) {
733 } else if (right.startsWith("ActiveDescendantChanged"_L1)) {
734 sendObject_active_descendant_changed = 1;
735 } else if (right.startsWith("Announcement"_L1)) {
736 sendObject_announcement = 1;
737 } else if (right.startsWith("AttributesChanged"_L1)) {
738 sendObject_attributes_changed = 1;
739 } else if (right.startsWith("BoundsChanged"_L1)) {
740 sendObject_bounds_changed = 1;
741 } else if (right.startsWith("ChildrenChanged"_L1)) {
742 sendObject_children_changed = 1;
743 } else if (right.startsWith("ColumnDeleted"_L1)) {
744 sendObject_column_deleted = 1;
745 } else if (right.startsWith("ColumnInserted"_L1)) {
746 sendObject_column_inserted = 1;
747 } else if (right.startsWith("ColumnReordered"_L1)) {
748 sendObject_column_reordered = 1;
749 } else if (right.startsWith("LinkSelected"_L1)) {
750 sendObject_link_selected = 1;
751 } else if (right.startsWith("ModelChanged"_L1)) {
752 sendObject_model_changed = 1;
753 } else if (right.startsWith("PropertyChange"_L1)) {
754 if (right == "PropertyChange:AccessibleDescription"_L1) {
755 sendObject_property_change_accessible_description = 1;
756 } else if (right == "PropertyChange:AccessibleName"_L1) {
757 sendObject_property_change_accessible_name = 1;
758 } else if (right == "PropertyChange:AccessibleParent"_L1) {
759 sendObject_property_change_accessible_parent = 1;
760 } else if (right == "PropertyChange:AccessibleRole"_L1) {
761 sendObject_property_change_accessible_role = 1;
762 } else if (right == "PropertyChange:TableCaption"_L1) {
763 sendObject_property_change_accessible_table_caption = 1;
764 } else if (right == "PropertyChange:TableColumnDescription"_L1) {
765 sendObject_property_change_accessible_table_column_description = 1;
766 } else if (right == "PropertyChange:TableColumnHeader"_L1) {
767 sendObject_property_change_accessible_table_column_header = 1;
768 } else if (right == "PropertyChange:TableRowDescription"_L1) {
769 sendObject_property_change_accessible_table_row_description = 1;
770 } else if (right == "PropertyChange:TableRowHeader"_L1) {
771 sendObject_property_change_accessible_table_row_header = 1;
772 } else if (right == "PropertyChange:TableSummary"_L1) {
773 sendObject_property_change_accessible_table_summary = 1;
774 } else if (right == "PropertyChange:AccessibleValue"_L1) {
775 sendObject_property_change_accessible_value = 1;
776 } else {
777 sendObject_property_change = 1;
778 }
779 } else if (right.startsWith("RowDeleted"_L1)) {
780 sendObject_row_deleted = 1;
781 } else if (right.startsWith("RowInserted"_L1)) {
782 sendObject_row_inserted = 1;
783 } else if (right.startsWith("RowReordered"_L1)) {
784 sendObject_row_reordered = 1;
785 } else if (right.startsWith("SelectionChanged"_L1)) {
786 sendObject_selection_changed = 1;
787 } else if (right.startsWith("StateChanged"_L1)) {
788 sendObject_state_changed = 1;
789 } else if (right.startsWith("TextAttributesChanged"_L1)) {
790 sendObject_text_attributes_changed = 1;
791 } else if (right.startsWith("TextBoundsChanged"_L1)) {
792 sendObject_text_bounds_changed = 1;
793 } else if (right.startsWith("TextCaretMoved"_L1)) {
794 sendObject_text_caret_moved = 1;
795 } else if (right.startsWith("TextChanged"_L1)) {
796 sendObject_text_changed = 1;
797 } else if (right.startsWith("TextSelectionChanged"_L1)) {
798 sendObject_text_selection_changed = 1;
799 } else if (right.startsWith("ValueChanged"_L1)) {
800 sendObject_value_changed = 1;
801 } else if (right.startsWith("VisibleDataChanged"_L1)
802 || right.startsWith("VisibledataChanged"_L1)) { // typo in libatspi
803 sendObject_visible_data_changed = 1;
804 } else {
805 qCWarning(lcAccessibilityAtspi) << "Subscription string not handled:" << flag;
806 }
807 }
808 break;
809 }
810 case 'w': { // window
811 if (flag.size() <= 8) {
812 sendWindow = 1;
813 } else { // object:Foo:Bar
814 QString right = flag.mid(7);
815 if (false) {
816 } else if (right.startsWith("Activate"_L1)) {
817 sendWindow_activate = 1;
818 } else if (right.startsWith("Close"_L1)) {
819 sendWindow_close= 1;
820 } else if (right.startsWith("Create"_L1)) {
821 sendWindow_create = 1;
822 } else if (right.startsWith("Deactivate"_L1)) {
823 sendWindow_deactivate = 1;
824 } else if (right.startsWith("Lower"_L1)) {
825 sendWindow_lower = 1;
826 } else if (right.startsWith("Maximize"_L1)) {
827 sendWindow_maximize = 1;
828 } else if (right.startsWith("Minimize"_L1)) {
829 sendWindow_minimize = 1;
830 } else if (right.startsWith("Move"_L1)) {
831 sendWindow_move = 1;
832 } else if (right.startsWith("Raise"_L1)) {
833 sendWindow_raise = 1;
834 } else if (right.startsWith("Reparent"_L1)) {
835 sendWindow_reparent = 1;
836 } else if (right.startsWith("Resize"_L1)) {
837 sendWindow_resize = 1;
838 } else if (right.startsWith("Restore"_L1)) {
839 sendWindow_restore = 1;
840 } else if (right.startsWith("Restyle"_L1)) {
841 sendWindow_restyle = 1;
842 } else if (right.startsWith("Shade"_L1)) {
843 sendWindow_shade = 1;
844 } else if (right.startsWith("Unshade"_L1)) {
845 sendWindow_unshade = 1;
846 } else if (right.startsWith("DesktopCreate"_L1)) {
847 // ignore this one
848 } else if (right.startsWith("DesktopDestroy"_L1)) {
849 // ignore this one
850 } else {
851 qCWarning(lcAccessibilityAtspi) << "Subscription string not handled:" << flag;
852 }
853 }
854 break;
855 }
856 case 'f': {
857 sendFocus = 1;
858 break;
859 }
860 case 'd': { // document is not implemented
861 break;
862 }
863 case 't': { // terminal is not implemented
864 break;
865 }
866 case 'm': { // mouse* is handled in a different way by the gnome atspi stack
867 break;
868 }
869 default:
870 qCWarning(lcAccessibilityAtspi) << "Subscription string not handled:" << flag;
871 }
872}
873
874/*!
875 Checks via dbus which events should be sent.
876 */
877void AtSpiAdaptor::updateEventListeners()
878{
879 QDBusMessage m = QDBusMessage::createMethodCall("org.a11y.atspi.Registry"_L1,
880 "/org/a11y/atspi/registry"_L1,
881 "org.a11y.atspi.Registry"_L1, "GetRegisteredEvents"_L1);
882 QDBusReply<QSpiEventListenerArray> listenersReply = m_dbus->connection().call(m);
883 if (listenersReply.isValid()) {
884 const QSpiEventListenerArray evList = listenersReply.value();
885 for (const QSpiEventListener &ev : evList)
886 setBitFlag(ev.eventName);
887 m_applicationAdaptor->sendEvents(!evList.isEmpty());
888 } else {
889 qCDebug(lcAccessibilityAtspi) << "Could not query active accessibility event listeners.";
890 }
891}
892
893void AtSpiAdaptor::eventListenerDeregistered(const QString &/*bus*/, const QString &/*path*/)
894{
895// qCDebug(lcAccessibilityAtspi) << "AtSpiAdaptor::eventListenerDeregistered: " << bus << path;
896 updateEventListeners();
897}
898
899void AtSpiAdaptor::eventListenerRegistered(const QString &/*bus*/, const QString &/*path*/)
900{
901// qCDebug(lcAccessibilityAtspi) << "AtSpiAdaptor::eventListenerRegistered: " << bus << path;
902 updateEventListeners();
903}
904
905/*!
906 This slot needs to get called when a \a window has be activated or deactivated (become focused).
907 When \a active is true, the window just received focus, otherwise it lost the focus.
908 */
909void AtSpiAdaptor::windowActivated(QObject* window, bool active)
910{
911 if (!(sendWindow || sendWindow_activate))
912 return;
913
914 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(window);
915 // If the window has been quickly activated or disabled, it will cause a crash.
916 if (iface == nullptr)
917 return;
918 Q_ASSERT(!active || iface->isValid());
919
920 QString windowTitle;
921 // in dtor it may be invalid
922 if (iface->isValid())
923 windowTitle = iface->text(QAccessible::Name);
924
925 QDBusVariant data;
926 data.setVariant(windowTitle);
927
928 QVariantList args = packDBusSignalArguments(QString(), 0, 0, QVariant::fromValue(data));
929
930 QString status = active ? "Activate"_L1 : "Deactivate"_L1;
931 QString path = pathForObject(window);
932 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_WINDOW ""_L1, status, args);
933
934 QVariantList stateArgs = packDBusSignalArguments("active"_L1, active ? 1 : 0, 0, variantForPath(path));
935 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "StateChanged"_L1, stateArgs);
936}
937
938QVariantList AtSpiAdaptor::packDBusSignalArguments(const QString &type, int data1, int data2, const QVariant &variantData)
939{
940 QVariantList arguments;
941 arguments << type << data1 << data2 << variantData << QMap<QString, QVariant>();
942 return arguments;
943}
944
945QVariant AtSpiAdaptor::variantForPath(const QString &path) const
946{
947 QDBusVariant data;
948 data.setVariant(QVariant::fromValue(QSpiObjectReference(m_dbus->connection(), QDBusObjectPath(path))));
949 return QVariant::fromValue(data);
950}
951
952bool AtSpiAdaptor::sendDBusSignal(const QString &path, const QString &interface, const QString &signalName, const QVariantList &arguments) const
953{
954 QDBusMessage message = QDBusMessage::createSignal(path, interface, signalName);
955 message.setArguments(arguments);
956 return m_dbus->connection().send(message);
957}
958
959QAccessibleInterface *AtSpiAdaptor::interfaceFromPath(const QString &dbusPath)
960{
961 if (dbusPath == ATSPI_DBUS_PATH_ROOT ""_L1)
962 return QAccessible::queryAccessibleInterface(qApp);
963
964 QStringList parts = dbusPath.split(u'/');
965 if (parts.size() != 6) {
966 qCDebug(lcAccessibilityAtspi) << "invalid path: " << dbusPath;
967 return nullptr;
968 }
969
970 QString objectString = parts.at(5);
971 QAccessible::Id id = objectString.toUInt();
972
973 // The id is always in the range [INT_MAX+1, UINT_MAX]
974 if ((int)id >= 0)
975 qCWarning(lcAccessibilityAtspi) << "No accessible object found for id: " << id;
976
977 return QAccessible::accessibleInterface(id);
978}
979
980void AtSpiAdaptor::notifyStateChange(QAccessibleInterface *interface, const QString &state, int value)
981{
982 QString path = pathForInterface(interface);
983 QVariantList stateArgs = packDBusSignalArguments(state, value, 0, variantForPath(path));
984 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "StateChanged"_L1, stateArgs);
985}
986
987void AtSpiAdaptor::sendAnnouncement(QAccessibleAnnouncementEvent *event)
988{
989 QAccessibleInterface *iface = event->accessibleInterface();
990 if (!iface) {
991 qCWarning(lcAccessibilityAtspi, "Announcement event has no accessible set.");
992 return;
993 }
994 if (!iface->isValid()) {
995 qCWarning(lcAccessibilityAtspi) << "Announcement event with invalid accessible: " << iface;
996 return;
997 }
998
999 const QString path = pathForInterface(iface);
1000 const QString message = event->message();
1001 const QAccessible::AnnouncementPoliteness prio = event->politeness();
1002 const int politeness = (prio == QAccessible::AnnouncementPoliteness::Assertive) ? ATSPI_LIVE_ASSERTIVE : ATSPI_LIVE_POLITE;
1003
1004 const QVariantList args = packDBusSignalArguments(QString(), politeness, 0, QVariant::fromValue(QDBusVariant(message)));
1005 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "Announcement"_L1, args);
1006}
1007
1008/*!
1009 This function gets called when Qt notifies about accessibility updates.
1010*/
1011void AtSpiAdaptor::notify(QAccessibleEvent *event)
1012{
1013 switch (event->type()) {
1014 case QAccessible::ObjectCreated:
1015 if (sendObject || sendObject_children_changed)
1016 notifyAboutCreation(event->accessibleInterface());
1017 break;
1018 case QAccessible::ObjectShow: {
1019 if (sendObject || sendObject_state_changed) {
1020 notifyStateChange(event->accessibleInterface(), "showing"_L1, 1);
1021 }
1022 break;
1023 }
1024 case QAccessible::ObjectHide: {
1025 if (sendObject || sendObject_state_changed) {
1026 notifyStateChange(event->accessibleInterface(), "showing"_L1, 0);
1027 }
1028 break;
1029 }
1030 case QAccessible::ObjectDestroyed: {
1031 if (sendObject || sendObject_state_changed)
1032 notifyAboutDestruction(event->accessibleInterface());
1033 break;
1034 }
1035 case QAccessible::ObjectReorder: {
1036 if (sendObject || sendObject_children_changed)
1037 childrenChanged(event->accessibleInterface());
1038 break;
1039 }
1040 case QAccessible::NameChanged: {
1041 if (sendObject || sendObject_property_change || sendObject_property_change_accessible_name) {
1042 QAccessibleInterface *iface = event->accessibleInterface();
1043 if (!iface) {
1044 qCDebug(lcAccessibilityAtspi,
1045 "NameChanged event from invalid accessible.");
1046 return;
1047 }
1048
1049 QString path = pathForInterface(iface);
1050 QVariantList args = packDBusSignalArguments(
1051 "accessible-name"_L1, 0, 0,
1052 QVariant::fromValue(QDBusVariant(iface->text(QAccessible::Name))));
1053 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1,
1054 "PropertyChange"_L1, args);
1055 }
1056 break;
1057 }
1058 case QAccessible::RoleChanged: {
1059 if (sendObject || sendObject_property_change
1060 || sendObject_property_change_accessible_role) {
1061 QAccessibleInterface *iface = event->accessibleInterface();
1062 if (!iface || !iface->isValid()) {
1063 qCDebug(lcAccessibilityAtspi, "RoleChanged event from invalid accessible.");
1064 return;
1065 }
1066
1067 QString path = pathForInterface(iface);
1068 QVariantList args = packDBusSignalArguments(
1069 "accessible-role"_L1, 0, 0,
1070 QVariant::fromValue(QDBusVariant(uint(getRole(iface)))));
1071 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "PropertyChange"_L1,
1072 args);
1073 }
1074 break;
1075 }
1076 case QAccessible::DescriptionChanged: {
1077 if (sendObject || sendObject_property_change || sendObject_property_change_accessible_description) {
1078 QAccessibleInterface *iface = event->accessibleInterface();
1079 if (!iface) {
1080 qCDebug(lcAccessibilityAtspi,
1081 "DescriptionChanged event from invalid accessible.");
1082 return;
1083 }
1084
1085 QString path = pathForInterface(iface);
1086 QVariantList args = packDBusSignalArguments(
1087 "accessible-description"_L1, 0, 0,
1088 QVariant::fromValue(QDBusVariant(iface->text(QAccessible::Description))));
1089 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1,
1090 "PropertyChange"_L1, args);
1091 }
1092 break;
1093 }
1094 case QAccessible::Focus: {
1095 if (sendFocus || sendObject || sendObject_state_changed)
1096 sendFocusChanged(event->accessibleInterface());
1097 break;
1098 }
1099
1100 case QAccessible::Announcement: {
1101 if (sendObject || sendObject_announcement) {
1102 QAccessibleAnnouncementEvent *announcementEvent = static_cast<QAccessibleAnnouncementEvent*>(event);
1103 sendAnnouncement(announcementEvent);
1104 }
1105 break;
1106 }
1107 case QAccessible::TextInserted:
1108 case QAccessible::TextRemoved:
1109 case QAccessible::TextUpdated: {
1110 if (sendObject || sendObject_text_changed) {
1111 QAccessibleInterface * iface = event->accessibleInterface();
1112 if (!iface || !iface->textInterface()) {
1113 qCWarning(lcAccessibilityAtspi) << "Received text event for invalid interface.";
1114 return;
1115 }
1116 QString path = pathForInterface(iface);
1117
1118 int changePosition = 0;
1119 int cursorPosition = 0;
1120 QString textRemoved;
1121 QString textInserted;
1122
1123 if (event->type() == QAccessible::TextInserted) {
1124 QAccessibleTextInsertEvent *textEvent = static_cast<QAccessibleTextInsertEvent*>(event);
1125 textInserted = textEvent->textInserted();
1126 changePosition = textEvent->changePosition();
1127 cursorPosition = textEvent->cursorPosition();
1128 } else if (event->type() == QAccessible::TextRemoved) {
1129 QAccessibleTextRemoveEvent *textEvent = static_cast<QAccessibleTextRemoveEvent*>(event);
1130 textRemoved = textEvent->textRemoved();
1131 changePosition = textEvent->changePosition();
1132 cursorPosition = textEvent->cursorPosition();
1133 } else if (event->type() == QAccessible::TextUpdated) {
1134 QAccessibleTextUpdateEvent *textEvent = static_cast<QAccessibleTextUpdateEvent*>(event);
1135 textInserted = textEvent->textInserted();
1136 textRemoved = textEvent->textRemoved();
1137 changePosition = textEvent->changePosition();
1138 cursorPosition = textEvent->cursorPosition();
1139 }
1140
1141 QDBusVariant data;
1142
1143 if (!textRemoved.isEmpty()) {
1144 data.setVariant(QVariant::fromValue(textRemoved));
1145 QVariantList args = packDBusSignalArguments("delete"_L1, changePosition, textRemoved.size(), QVariant::fromValue(data));
1146 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1,
1147 "TextChanged"_L1, args);
1148 }
1149
1150 if (!textInserted.isEmpty()) {
1151 data.setVariant(QVariant::fromValue(textInserted));
1152 QVariantList args = packDBusSignalArguments("insert"_L1, changePosition, textInserted.size(), QVariant::fromValue(data));
1153 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1,
1154 "TextChanged"_L1, args);
1155 }
1156
1157 // send a cursor update
1158 Q_UNUSED(cursorPosition);
1159// QDBusVariant cursorData;
1160// cursorData.setVariant(QVariant::fromValue(cursorPosition));
1161// QVariantList args = packDBusSignalArguments(QString(), cursorPosition, 0, QVariant::fromValue(cursorData));
1162// sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1,
1163// "TextCaretMoved"_L1, args);
1164 }
1165 break;
1166 }
1167 case QAccessible::TextCaretMoved: {
1168 if (sendObject || sendObject_text_caret_moved) {
1169 QAccessibleInterface * iface = event->accessibleInterface();
1170 if (!iface || !iface->textInterface()) {
1171 qCWarning(lcAccessibilityAtspi) << "Sending TextCaretMoved from object that does not implement text interface: " << iface;
1172 return;
1173 }
1174
1175 QString path = pathForInterface(iface);
1176 QDBusVariant cursorData;
1177 int pos = iface->textInterface()->cursorPosition();
1178 cursorData.setVariant(QVariant::fromValue(pos));
1179 QVariantList args = packDBusSignalArguments(QString(), pos, 0, QVariant::fromValue(cursorData));
1180 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1,
1181 "TextCaretMoved"_L1, args);
1182 }
1183 break;
1184 }
1185 case QAccessible::TextSelectionChanged: {
1186 if (sendObject || sendObject_text_selection_changed) {
1187 QAccessibleInterface * iface = event->accessibleInterface();
1188 QString path = pathForInterface(iface);
1189 QVariantList args = packDBusSignalArguments(QString(), 0, 0, QVariant::fromValue(QDBusVariant(QVariant(QString()))));
1190 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1,
1191 "TextSelectionChanged"_L1, args);
1192 }
1193 break;
1194 }
1195 case QAccessible::ValueChanged: {
1196 if (sendObject || sendObject_value_changed || sendObject_property_change_accessible_value) {
1197 QAccessibleInterface * iface = event->accessibleInterface();
1198 if (!iface) {
1199 qCWarning(lcAccessibilityAtspi) << "ValueChanged event from invalid accessible.";
1200 return;
1201 }
1202 if (iface->valueInterface()) {
1203 QString path = pathForInterface(iface);
1204 QVariantList args = packDBusSignalArguments("accessible-value"_L1, 0, 0, variantForPath(path));
1205 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1,
1206 "PropertyChange"_L1, args);
1207 } else if (iface->role() == QAccessible::ComboBox) {
1208 // Combo Box with AT-SPI likes to be special
1209 // It requires a name-change to update caches and then selection-changed
1210 QString path = pathForInterface(iface);
1211 QVariantList args1 = packDBusSignalArguments(
1212 "accessible-name"_L1, 0, 0,
1213 QVariant::fromValue(QDBusVariant(iface->text(QAccessible::Name))));
1214 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1,
1215 "PropertyChange"_L1, args1);
1216 QVariantList args2 = packDBusSignalArguments(QString(), 0, 0, QVariant::fromValue(QDBusVariant(QVariant(0))));
1217 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1,
1218 "SelectionChanged"_L1, args2);
1219 } else {
1220 qCWarning(lcAccessibilityAtspi) << "ValueChanged event and no ValueInterface or ComboBox: " << iface;
1221 }
1222 }
1223 break;
1224 }
1225 case QAccessible::SelectionAdd:
1226 case QAccessible::SelectionRemove:
1227 case QAccessible::Selection: {
1228 QAccessibleInterface * iface = event->accessibleInterface();
1229 if (!iface) {
1230 qCWarning(lcAccessibilityAtspi) << "Selection event from invalid accessible.";
1231 return;
1232 }
1233 // send event for change of selected state for the interface itself
1234 QString path = pathForInterface(iface);
1235 int selected = iface->state().selected ? 1 : 0;
1236 QVariantList stateArgs = packDBusSignalArguments("selected"_L1, selected, 0, variantForPath(path));
1237 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "StateChanged"_L1, stateArgs);
1238
1239 // send SelectionChanged event for the parent
1240 QAccessibleInterface* parent = iface->parent();
1241 if (!parent) {
1242 qCDebug(lcAccessibilityAtspi) << "No valid parent in selection event.";
1243 return;
1244 }
1245
1246 QString parentPath = pathForInterface(parent);
1247 QVariantList args = packDBusSignalArguments(QString(), 0, 0, variantForPath(parentPath));
1248 sendDBusSignal(parentPath, QLatin1String(ATSPI_DBUS_INTERFACE_EVENT_OBJECT),
1249 QLatin1String("SelectionChanged"), args);
1250 break;
1251 }
1252 case QAccessible::SelectionWithin: {
1253 QAccessibleInterface * iface = event->accessibleInterface();
1254 if (!iface) {
1255 qCWarning(lcAccessibilityAtspi) << "SelectionWithin event from invalid accessible.";
1256 return;
1257 }
1258
1259 QString path = pathForInterface(iface);
1260 QVariantList args = packDBusSignalArguments(QString(), 0, 0, variantForPath(path));
1261 sendDBusSignal(path, QLatin1String(ATSPI_DBUS_INTERFACE_EVENT_OBJECT), QLatin1String("SelectionChanged"), args);
1262 break;
1263 }
1264 case QAccessible::StateChanged: {
1265 if (sendObject || sendObject_state_changed || sendWindow || sendWindow_activate) {
1266 QAccessible::State stateChange = static_cast<QAccessibleStateChangeEvent*>(event)->changedStates();
1267 if (stateChange.checked) {
1268 QAccessibleInterface * iface = event->accessibleInterface();
1269 if (!iface) {
1270 qCWarning(lcAccessibilityAtspi) << "StateChanged event from invalid accessible.";
1271 return;
1272 }
1273 int checked = iface->state().checked;
1274 notifyStateChange(iface, "checked"_L1, checked);
1275 } else if (stateChange.active) {
1276 QAccessibleInterface * iface = event->accessibleInterface();
1277 if (!iface || !(iface->role() == QAccessible::Window && (sendWindow || sendWindow_activate)))
1278 return;
1279 int isActive = iface->state().active;
1280 QString windowTitle = iface->text(QAccessible::Name);
1281 QDBusVariant data;
1282 data.setVariant(windowTitle);
1283 QVariantList args = packDBusSignalArguments(QString(), 0, 0, QVariant::fromValue(data));
1284 QString status = isActive ? "Activate"_L1 : "Deactivate"_L1;
1285 QString path = pathForInterface(iface);
1286 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_WINDOW ""_L1, status, args);
1287 notifyStateChange(iface, "active"_L1, isActive);
1288 } else if (stateChange.disabled) {
1289 QAccessibleInterface *iface = event->accessibleInterface();
1290 QAccessible::State state = iface->state();
1291 bool enabled = !state.disabled;
1292
1293 notifyStateChange(iface, "enabled"_L1, enabled);
1294 notifyStateChange(iface, "sensitive"_L1, enabled);
1295 } else if (stateChange.focused) {
1296 QAccessibleInterface *iface = event->accessibleInterface();
1297 QAccessible::State state = iface->state();
1298 bool focused = state.focused;
1299 notifyStateChange(iface, "focused"_L1, focused);
1300 } else if (stateChange.expanded) {
1301 QAccessibleInterface *iface = event->accessibleInterface();
1302 QAccessible::State state = iface->state();
1303 bool expanded = state.expanded;
1304 notifyStateChange(iface, "expanded"_L1, expanded);
1305 } else if (stateChange.collapsed) {
1306 QAccessibleInterface *iface = event->accessibleInterface();
1307 QAccessible::State state = iface->state();
1308 bool collapsed = state.collapsed;
1309 notifyStateChange(iface, "collapsed"_L1, collapsed);
1310 } else if (stateChange.expandable) {
1311 QAccessibleInterface *iface = event->accessibleInterface();
1312 QAccessible::State state = iface->state();
1313 bool expandable = state.expandable;
1314 notifyStateChange(iface, "expandable"_L1, expandable);
1315 }
1316 }
1317 break;
1318 }
1319 case QAccessible::TableModelChanged: {
1320 QAccessibleInterface *interface = event->accessibleInterface();
1321 if (!interface || !interface->isValid()) {
1322 qCWarning(lcAccessibilityAtspi) << "TableModelChanged event from invalid accessible.";
1323 return;
1324 }
1325
1326 const QString path = pathForInterface(interface);
1327 QAccessibleTableModelChangeEvent *tableModelEvent = static_cast<QAccessibleTableModelChangeEvent*>(event);
1328 switch (tableModelEvent->modelChangeType()) {
1329 case QAccessibleTableModelChangeEvent::ColumnsInserted: {
1330 if (sendObject || sendObject_column_inserted) {
1331 const int firstColumn = tableModelEvent->firstColumn();
1332 const int insertedColumnCount = tableModelEvent->lastColumn() - firstColumn + 1;
1333 QVariantList args = packDBusSignalArguments(QString(), firstColumn, insertedColumnCount, QVariant::fromValue(QDBusVariant(QVariant(QString()))));
1334 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "ColumnInserted"_L1, args);
1335 }
1336 break;
1337 }
1338 case QAccessibleTableModelChangeEvent::ColumnsRemoved: {
1339 if (sendObject || sendObject_column_deleted) {
1340 const int firstColumn = tableModelEvent->firstColumn();
1341 const int removedColumnCount = tableModelEvent->lastColumn() - firstColumn + 1;
1342 QVariantList args = packDBusSignalArguments(QString(), firstColumn, removedColumnCount, QVariant::fromValue(QDBusVariant(QVariant(QString()))));
1343 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "ColumnDeleted"_L1, args);
1344 }
1345 break;
1346 }
1347 case QAccessibleTableModelChangeEvent::RowsInserted: {
1348 if (sendObject || sendObject_row_inserted) {
1349 const int firstRow = tableModelEvent->firstRow();
1350 const int insertedRowCount = tableModelEvent->lastRow() - firstRow + 1;
1351 QVariantList args = packDBusSignalArguments(QString(), firstRow, insertedRowCount, QVariant::fromValue(QDBusVariant(QVariant(QString()))));
1352 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "RowInserted"_L1, args);
1353 }
1354 break;
1355 }
1356 case QAccessibleTableModelChangeEvent::RowsRemoved: {
1357 if (sendObject || sendObject_row_deleted) {
1358 const int firstRow = tableModelEvent->firstRow();
1359 const int removedRowCount = tableModelEvent->lastRow() - firstRow + 1;
1360 QVariantList args = packDBusSignalArguments(QString(), firstRow, removedRowCount, QVariant::fromValue(QDBusVariant(QVariant(QString()))));
1361 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "RowDeleted"_L1, args);
1362 }
1363 break;
1364 }
1365 case QAccessibleTableModelChangeEvent::ModelChangeType::ModelReset: {
1366 if (sendObject || sendObject_model_changed) {
1367 QVariantList args = packDBusSignalArguments(QString(), 0, 0, QVariant::fromValue(QDBusVariant(QVariant(QString()))));
1368 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "ModelChanged"_L1, args);
1369 }
1370 break;
1371 }
1372 case QAccessibleTableModelChangeEvent::DataChanged: {
1373 if (sendObject || sendObject_visible_data_changed) {
1374 QVariantList args = packDBusSignalArguments(QString(), 0, 0, QVariant::fromValue(QDBusVariant(QVariant(QString()))));
1375 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "VisibleDataChanged"_L1, args);
1376 }
1377 break;
1378 }
1379 }
1380 break;
1381 }
1382
1383 // For now we ignore these events
1384 case QAccessible::ParentChanged:
1385 case QAccessible::DialogStart:
1386 case QAccessible::DialogEnd:
1387 case QAccessible::PopupMenuStart:
1388 case QAccessible::PopupMenuEnd:
1389 case QAccessible::SoundPlayed:
1390 case QAccessible::Alert:
1391 case QAccessible::ForegroundChanged:
1392 case QAccessible::MenuStart:
1393 case QAccessible::MenuEnd:
1394 case QAccessible::ContextHelpStart:
1395 case QAccessible::ContextHelpEnd:
1396 case QAccessible::DragDropStart:
1397 case QAccessible::DragDropEnd:
1398 case QAccessible::ScrollingStart:
1399 case QAccessible::ScrollingEnd:
1400 case QAccessible::ScrollingPositionChanged:
1401 case QAccessible::MenuCommand:
1402 case QAccessible::ActionChanged:
1403 case QAccessible::ActiveDescendantChanged:
1404 case QAccessible::AttributeChanged:
1405 case QAccessible::DocumentContentChanged:
1406 case QAccessible::DocumentLoadComplete:
1407 case QAccessible::DocumentLoadStopped:
1408 case QAccessible::DocumentReload:
1409 case QAccessible::HyperlinkEndIndexChanged:
1410 case QAccessible::HyperlinkNumberOfAnchorsChanged:
1411 case QAccessible::HyperlinkSelectedLinkChanged:
1412 case QAccessible::HypertextLinkActivated:
1413 case QAccessible::HypertextLinkSelected:
1414 case QAccessible::HyperlinkStartIndexChanged:
1415 case QAccessible::HypertextChanged:
1416 case QAccessible::HypertextNLinksChanged:
1417 case QAccessible::ObjectAttributeChanged:
1418 case QAccessible::PageChanged:
1419 case QAccessible::SectionChanged:
1420 case QAccessible::TableCaptionChanged:
1421 case QAccessible::TableColumnDescriptionChanged:
1422 case QAccessible::TableColumnHeaderChanged:
1423 case QAccessible::TableRowDescriptionChanged:
1424 case QAccessible::TableRowHeaderChanged:
1425 case QAccessible::TableSummaryChanged:
1426 case QAccessible::TextAttributeChanged:
1427 case QAccessible::TextColumnChanged:
1428 case QAccessible::VisibleDataChanged:
1429 case QAccessible::LocationChanged:
1430 case QAccessible::HelpChanged:
1431 case QAccessible::DefaultActionChanged:
1432 case QAccessible::AcceleratorChanged:
1433 case QAccessible::IdentifierChanged:
1434 case QAccessible::InvalidEvent:
1435 break;
1436 }
1437}
1438
1439void AtSpiAdaptor::sendFocusChanged(QAccessibleInterface *interface) const
1440{
1441 static QString lastFocusPath;
1442 // "remove" old focus
1443 if (!lastFocusPath.isEmpty()) {
1444 QVariantList stateArgs = packDBusSignalArguments("focused"_L1, 0, 0, variantForPath(lastFocusPath));
1445 sendDBusSignal(lastFocusPath, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1,
1446 "StateChanged"_L1, stateArgs);
1447 }
1448 // send new focus
1449 {
1450 QString path = pathForInterface(interface);
1451
1452 QVariantList stateArgs = packDBusSignalArguments("focused"_L1, 1, 0, variantForPath(path));
1453 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1,
1454 "StateChanged"_L1, stateArgs);
1455
1456 QVariantList focusArgs = packDBusSignalArguments(QString(), 0, 0, variantForPath(path));
1457 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_FOCUS ""_L1, "Focus"_L1, focusArgs);
1458 lastFocusPath = path;
1459 }
1460}
1461
1462void AtSpiAdaptor::childrenChanged(QAccessibleInterface *interface) const
1463{
1464 QString parentPath = pathForInterface(interface);
1465 const int childCount = interface->childCount();
1466 for (int i = 0; i < childCount; ++i) {
1467 QString childPath = pathForInterface(interface->child(i));
1468 QVariantList args = packDBusSignalArguments("add"_L1, i, 0, childPath);
1469 sendDBusSignal(parentPath, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "ChildrenChanged"_L1, args);
1470 }
1471}
1472
1473void AtSpiAdaptor::notifyAboutCreation(QAccessibleInterface *interface) const
1474{
1475 // notify about the new child of our parent
1476 QAccessibleInterface * parent = interface->parent();
1477 if (!parent) {
1478 qCDebug(lcAccessibilityAtspi) << "AtSpiAdaptor::notifyAboutCreation: Could not find parent for " << interface->object();
1479 return;
1480 }
1481 QString path = pathForInterface(interface);
1482 const int childIndex = parent->indexOfChild(interface);
1483 QString parentPath = pathForInterface(parent);
1484 QVariantList args = packDBusSignalArguments("add"_L1, childIndex, 0, variantForPath(path));
1485 sendDBusSignal(parentPath, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "ChildrenChanged"_L1, args);
1486}
1487
1488void AtSpiAdaptor::notifyAboutDestruction(QAccessibleInterface *interface) const
1489{
1490 if (!interface || !interface->isValid())
1491 return;
1492
1493 QAccessibleInterface * parent = interface->parent();
1494 if (!parent) {
1495 qCDebug(lcAccessibilityAtspi) << "AtSpiAdaptor::notifyAboutDestruction: Could not find parent for " << interface->object();
1496 return;
1497 }
1498 QString path = pathForInterface(interface);
1499
1500 // this is in the destructor. we have no clue which child we used to be.
1501 // FIXME
1502 int childIndex = -1;
1503 // if (child) {
1504 // childIndex = child;
1505 // } else {
1506 // childIndex = parent->indexOfChild(interface);
1507 // }
1508
1509 QString parentPath = pathForInterface(parent);
1510 QVariantList args = packDBusSignalArguments("remove"_L1, childIndex, 0, variantForPath(path));
1511 sendDBusSignal(parentPath, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "ChildrenChanged"_L1, args);
1512}
1513
1514/*!
1515 Handle incoming DBus message.
1516 This function dispatches the dbus message to the right interface handler.
1517 */
1518bool AtSpiAdaptor::handleMessage(const QDBusMessage &message, const QDBusConnection &connection)
1519{
1520 // get accessible interface
1521 QAccessibleInterface * accessible = interfaceFromPath(message.path());
1522 if (!accessible) {
1523 qCWarning(lcAccessibilityAtspi) << "Could not find accessible on path:" << message.path();
1524 return false;
1525 }
1526 if (!accessible->isValid()) {
1527 qCWarning(lcAccessibilityAtspi) << "Accessible invalid:" << accessible << message.path();
1528 return false;
1529 }
1530
1531 QString interface = message.interface();
1532 QString function = message.member();
1533
1534 // qCDebug(lcAccessibilityAtspi) << "AtSpiAdaptor::handleMessage: " << interface << function;
1535
1536 if (function == "Introspect"_L1) {
1537 //introspect(message.path());
1538 return false;
1539 }
1540
1541 // handle properties like regular functions
1542 if (interface == "org.freedesktop.DBus.Properties"_L1) {
1543 const auto arguments = message.arguments();
1544 if (arguments.size() > 0) {
1545 interface = arguments.at(0).toString();
1546 if (arguments.size() > 1) // e.g. Get/Set + Name
1547 function = function + arguments.at(1).toString();
1548 }
1549 }
1550
1551 // switch interface to call
1552 if (interface == ATSPI_DBUS_INTERFACE_ACCESSIBLE ""_L1)
1553 return accessibleInterface(accessible, function, message, connection);
1554 if (interface == ATSPI_DBUS_INTERFACE_APPLICATION ""_L1)
1555 return applicationInterface(accessible, function, message, connection);
1556 if (interface == ATSPI_DBUS_INTERFACE_COLLECTION ""_L1)
1557 return collectionInterface(accessible, function, message, connection);
1558 if (interface == ATSPI_DBUS_INTERFACE_COMPONENT ""_L1)
1559 return componentInterface(accessible, function, message, connection);
1560 if (interface == ATSPI_DBUS_INTERFACE_ACTION ""_L1)
1561 return actionInterface(accessible, function, message, connection);
1562 if (interface == ATSPI_DBUS_INTERFACE_SELECTION ""_L1)
1563 return selectionInterface(accessible, function, message, connection);
1564 if (interface == ATSPI_DBUS_INTERFACE_TEXT ""_L1)
1565 return textInterface(accessible, function, message, connection);
1566 if (interface == ATSPI_DBUS_INTERFACE_EDITABLE_TEXT ""_L1)
1567 return editableTextInterface(accessible, function, message, connection);
1568 if (interface == ATSPI_DBUS_INTERFACE_VALUE ""_L1)
1569 return valueInterface(accessible, function, message, connection);
1570 if (interface == ATSPI_DBUS_INTERFACE_TABLE ""_L1)
1571 return tableInterface(accessible, function, message, connection);
1572 if (interface == ATSPI_DBUS_INTERFACE_TABLE_CELL ""_L1)
1573 return tableCellInterface(accessible, function, message, connection);
1574
1575 qCDebug(lcAccessibilityAtspi) << "AtSpiAdaptor::handleMessage with unknown interface: " << message.path() << interface << function;
1576 return false;
1577}
1578
1579// Application
1580bool AtSpiAdaptor::applicationInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection)
1581{
1582 if (message.path() != ATSPI_DBUS_PATH_ROOT ""_L1) {
1583 qCWarning(lcAccessibilityAtspi) << "Could not find application interface for:" << message.path() << interface;
1584 return false;
1585 }
1586
1587 if (function == "SetId"_L1) {
1588 Q_ASSERT(message.signature() == "ssv"_L1);
1589 QVariant value = qvariant_cast<QDBusVariant>(message.arguments().at(2)).variant();
1590
1591 m_applicationId = value.toInt();
1592 return true;
1593 }
1594 if (function == "GetId"_L1) {
1595 Q_ASSERT(message.signature() == "ss"_L1);
1596 QDBusMessage reply = message.createReply(QVariant::fromValue(QDBusVariant(m_applicationId)));
1597 return connection.send(reply);
1598 }
1599 if (function == "GetAtspiVersion"_L1) {
1600 Q_ASSERT(message.signature() == "ss"_L1);
1601 // return "2.1" as described in the Application interface spec
1602 QDBusMessage reply = message.createReply(QVariant::fromValue(QDBusVariant("2.1"_L1)));
1603 return connection.send(reply);
1604 }
1605 if (function == "GetToolkitName"_L1) {
1606 Q_ASSERT(message.signature() == "ss"_L1);
1607 QDBusMessage reply = message.createReply(QVariant::fromValue(QDBusVariant("Qt"_L1)));
1608 return connection.send(reply);
1609 }
1610 if (function == "GetVersion"_L1) {
1611 Q_ASSERT(message.signature() == "ss"_L1);
1612 QDBusMessage reply = message.createReply(QVariant::fromValue(QDBusVariant(QLatin1StringView(qVersion()))));
1613 return connection.send(reply);
1614 }
1615 if (function == "GetLocale"_L1) {
1616 Q_ASSERT(message.signature() == "u"_L1);
1617 QDBusMessage reply = message.createReply(QVariant::fromValue(QLocale().name()));
1618 return connection.send(reply);
1619 }
1620 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::applicationInterface does not implement"
1621 << function << message.path();
1622 return false;
1623}
1624
1625/*!
1626 Register this application as accessible on the accessibility DBus.
1627 */
1628void AtSpiAdaptor::registerApplication()
1629{
1630 OrgA11yAtspiSocketInterface registry(ATSPI_DBUS_NAME_REGISTRY ""_L1, ATSPI_DBUS_PATH_ROOT ""_L1,
1631 m_dbus->connection());
1632
1633 QDBusPendingReply<QSpiObjectReference> reply;
1634 QSpiObjectReference ref = QSpiObjectReference(m_dbus->connection(), QDBusObjectPath(ATSPI_DBUS_PATH_ROOT));
1635 reply = registry.Embed(ref);
1636 reply.waitForFinished(); // TODO: make this async
1637 if (reply.isValid ()) {
1638 const QSpiObjectReference &socket = reply.value();
1639 m_accessibilityRegistry = QSpiObjectReference(socket);
1640 } else {
1641 qCWarning(lcAccessibilityAtspi) << "Error in contacting registry:"
1642 << reply.error().name()
1643 << reply.error().message();
1644 }
1645}
1646
1647// Accessible
1648bool AtSpiAdaptor::accessibleInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection)
1649{
1650 if (function == "GetRole"_L1) {
1651 sendReply(connection, message, (uint) getRole(interface));
1652 } else if (function == "GetName"_L1) {
1653 sendReply(connection, message, QVariant::fromValue(QDBusVariant(interface->text(QAccessible::Name))));
1654 } else if (function == "GetRoleName"_L1) {
1655 sendReply(connection, message, QSpiAccessibleBridge::namesForRole(interface->role()).name());
1656 } else if (function == "GetLocalizedRoleName"_L1) {
1657 sendReply(connection, message, QVariant::fromValue(QSpiAccessibleBridge::namesForRole(interface->role()).localizedName()));
1658 } else if (function == "GetChildCount"_L1) {
1659 sendReply(connection, message, QVariant::fromValue(QDBusVariant(interface->childCount())));
1660 } else if (function == "GetIndexInParent"_L1) {
1661 int childIndex = -1;
1662 QAccessibleInterface * parent = interface->parent();
1663 if (parent) {
1664 childIndex = parent->indexOfChild(interface);
1665 if (childIndex < 0) {
1666 qCDebug(lcAccessibilityAtspi) << "GetIndexInParent get invalid index: " << childIndex << interface;
1667 }
1668 }
1669 sendReply(connection, message, childIndex);
1670 } else if (function == "GetParent"_L1) {
1671 QString path;
1672 QAccessibleInterface * parent = interface->parent();
1673 if (!parent) {
1674 if (interface->object() == qApp) {
1675 sendReply(connection, message,
1676 QVariant::fromValue(QDBusVariant(QVariant::fromValue(m_accessibilityRegistry))));
1677 return true;
1678 }
1679
1680 path = ATSPI_DBUS_PATH_NULL ""_L1;
1681 } else if (parent->role() == QAccessible::Application) {
1682 path = ATSPI_DBUS_PATH_ROOT ""_L1;
1683 } else {
1684 path = pathForInterface(parent);
1685 }
1686 // Parent is a property, so it needs to be wrapped inside an extra variant.
1687 sendReply(connection, message, QVariant::fromValue(
1688 QDBusVariant(QVariant::fromValue(QSpiObjectReference(connection, QDBusObjectPath(path))))));
1689 } else if (function == "GetChildAtIndex"_L1) {
1690 const int index = message.arguments().at(0).toInt();
1691 if (index < 0) {
1692 sendReply(connection, message, QVariant::fromValue(
1693 QSpiObjectReference(connection, QDBusObjectPath(ATSPI_DBUS_PATH_NULL))));
1694 } else {
1695 QAccessibleInterface * childInterface = interface->child(index);
1696 sendReply(connection, message, QVariant::fromValue(
1697 QSpiObjectReference(connection, QDBusObjectPath(pathForInterface(childInterface)))));
1698 }
1699 } else if (function == "GetInterfaces"_L1) {
1700 sendReply(connection, message, accessibleInterfaces(interface));
1701 } else if (function == "GetDescription"_L1) {
1702 sendReply(connection, message, QVariant::fromValue(QDBusVariant(interface->text(QAccessible::Description))));
1703 } else if (function == "GetHelpText"_L1) {
1704 sendReply(connection, message, QVariant::fromValue(QDBusVariant(interface->text(QAccessible::Help))));
1705 } else if (function == "GetState"_L1) {
1706 quint64 spiState = spiStatesFromQState(interface->state());
1707 if (QAccessibleAttributesInterface *attributesIface = interface->attributesInterface()) {
1708 const QVariant orientationVariant =
1709 attributesIface->attributeValue(QAccessible::Attribute::Orientation);
1710 if (orientationVariant.isValid()) {
1711 Q_ASSERT(orientationVariant.canConvert<Qt::Orientation>());
1712 const Qt::Orientation orientation = orientationVariant.value<Qt::Orientation>();
1713 setSpiStateBit(&spiState,
1714 orientation == Qt::Horizontal ? ATSPI_STATE_HORIZONTAL
1715 : ATSPI_STATE_VERTICAL);
1716 }
1717 }
1718 if (interface->tableInterface()) {
1719 // For tables, setting manages_descendants should
1720 // indicate to the client that it cannot cache these
1721 // interfaces.
1722 setSpiStateBit(&spiState, ATSPI_STATE_MANAGES_DESCENDANTS);
1723 }
1724 QAccessible::Role role = interface->role();
1725 if (role == QAccessible::TreeItem ||
1726 role == QAccessible::ListItem) {
1727 /* Transient means libatspi2 will not cache items.
1728 This is important because when adding/removing an item
1729 the cache becomes outdated and we don't change the paths of
1730 items in lists/trees/tables. */
1731 setSpiStateBit(&spiState, ATSPI_STATE_TRANSIENT);
1732 }
1733 sendReply(connection, message,
1734 QVariant::fromValue(spiStateSetFromSpiStates(spiState)));
1735 } else if (function == "GetAttributes"_L1) {
1736 sendReply(connection, message, QVariant::fromValue(getAttributes(interface)));
1737 } else if (function == "GetRelationSet"_L1) {
1738 sendReply(connection, message, QVariant::fromValue(relationSet(interface, connection)));
1739 } else if (function == "GetApplication"_L1) {
1740 sendReply(connection, message, QVariant::fromValue(
1741 QSpiObjectReference(connection, QDBusObjectPath(ATSPI_DBUS_PATH_ROOT))));
1742 } else if (function == "GetLocale"_L1) {
1743 QLocale locale;
1744 if (QAccessibleAttributesInterface *attributesIface = interface->attributesInterface()) {
1745 const QVariant localeVariant = attributesIface->attributeValue(QAccessible::Attribute::Locale);
1746 if (localeVariant.isValid()) {
1747 Q_ASSERT(localeVariant.canConvert<QLocale>());
1748 locale = localeVariant.toLocale();
1749 }
1750 }
1751 sendReply(connection, message, QVariant::fromValue(QDBusVariant(locale.name())));
1752 } else if (function == "GetChildren"_L1) {
1753 QSpiObjectReferenceArray children;
1754 const int numChildren = interface->childCount();
1755 children.reserve(numChildren);
1756 for (int i = 0; i < numChildren; ++i) {
1757 QString childPath = pathForInterface(interface->child(i));
1758 QSpiObjectReference ref(connection, QDBusObjectPath(childPath));
1759 children << ref;
1760 }
1761 connection.send(message.createReply(QVariant::fromValue(children)));
1762 } else if (function == "GetAccessibleId"_L1) {
1763 sendReply(connection, message,
1764 QVariant::fromValue(QDBusVariant(QAccessibleBridgeUtils::accessibleId(interface))));
1765 } else {
1766 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::accessibleInterface does not implement" << function << message.path();
1767 return false;
1768 }
1769 return true;
1770}
1771
1772AtspiRole AtSpiAdaptor::getRole(QAccessibleInterface *interface)
1773{
1774 if ((interface->role() == QAccessible::EditableText) && interface->state().passwordEdit)
1775 return ATSPI_ROLE_PASSWORD_TEXT;
1776 return QSpiAccessibleBridge::namesForRole(interface->role()).spiRole();
1777}
1778
1779QStringList AtSpiAdaptor::accessibleInterfaces(QAccessibleInterface *interface)
1780{
1781 QStringList ifaces;
1782 qCDebug(lcAccessibilityAtspiCreation) << "AtSpiAdaptor::accessibleInterfaces create: " << interface->object();
1783 ifaces << u"" ATSPI_DBUS_INTERFACE_ACCESSIBLE ""_s;
1784
1785 ifaces << u"" ATSPI_DBUS_INTERFACE_COLLECTION ""_s;
1786
1787 if ( (!interface->rect().isEmpty()) ||
1788 (interface->object() && interface->object()->isWidgetType()) ||
1789 (interface->role() == QAccessible::ListItem) ||
1790 (interface->role() == QAccessible::Cell) ||
1791 (interface->role() == QAccessible::TreeItem) ||
1792 (interface->role() == QAccessible::Row) ||
1793 (interface->object() && interface->object()->inherits("QSGItem"))
1794 ) {
1795 ifaces << u"" ATSPI_DBUS_INTERFACE_COMPONENT ""_s;
1796 } else {
1797 qCDebug(lcAccessibilityAtspiCreation) << " IS NOT a component";
1798 }
1799 if (interface->role() == QAccessible::Application)
1800 ifaces << u"" ATSPI_DBUS_INTERFACE_APPLICATION ""_s;
1801
1802 if (interface->actionInterface() || interface->valueInterface())
1803 ifaces << u"" ATSPI_DBUS_INTERFACE_ACTION ""_s;
1804
1805 if (interface->selectionInterface())
1806 ifaces << ATSPI_DBUS_INTERFACE_SELECTION ""_L1;
1807
1808 if (interface->textInterface())
1809 ifaces << u"" ATSPI_DBUS_INTERFACE_TEXT ""_s;
1810
1811 if (interface->editableTextInterface())
1812 ifaces << u"" ATSPI_DBUS_INTERFACE_EDITABLE_TEXT ""_s;
1813
1814 if (interface->valueInterface())
1815 ifaces << u"" ATSPI_DBUS_INTERFACE_VALUE ""_s;
1816
1817 if (interface->tableInterface())
1818 ifaces << u"" ATSPI_DBUS_INTERFACE_TABLE ""_s;
1819
1820 if (interface->tableCellInterface())
1821 ifaces << u"" ATSPI_DBUS_INTERFACE_TABLE_CELL ""_s;
1822
1823 return ifaces;
1824}
1825
1826QSpiRelationArray AtSpiAdaptor::relationSet(QAccessibleInterface *interface,
1827 const QDBusConnection &connection)
1828{
1829 typedef std::pair<QAccessibleInterface*, QAccessible::Relation> RelationPair;
1830 const QList<RelationPair> relationInterfaces = interface->relations();
1831
1832 QSpiRelationArray relations;
1833 for (const RelationPair &pair : relationInterfaces) {
1834// FIXME: this loop seems a bit strange... "related" always have one item when we check.
1835//And why is it a list, when it always have one item? And it seems to assume that the QAccessible::Relation enum maps directly to AtSpi
1836 QSpiObjectReferenceArray related;
1837
1838 QDBusObjectPath path = QDBusObjectPath(pathForInterface(pair.first));
1839 related.append(QSpiObjectReference(connection, path));
1840
1841 if (!related.isEmpty())
1842 relations.append(QSpiRelationArrayEntry(qAccessibleRelationToAtSpiRelation(pair.second), related));
1843 }
1844 return relations;
1845}
1846
1847void AtSpiAdaptor::sendReply(const QDBusConnection &connection, const QDBusMessage &message, const QVariant &argument) const
1848{
1849 QDBusMessage reply = message.createReply(argument);
1850 connection.send(reply);
1851}
1852
1853QString AtSpiAdaptor::pathForObject(QObject *object)
1854{
1855 Q_ASSERT(object);
1856
1857 if (inheritsQAction(object)) {
1858 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::pathForObject: Creating path with QAction as object.";
1859 }
1860
1861 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(object);
1862 return pathForInterface(iface);
1863}
1864
1865QString AtSpiAdaptor::pathForInterface(QAccessibleInterface *interface)
1866{
1867 if (!interface || !interface->isValid())
1868 return u"" ATSPI_DBUS_PATH_NULL ""_s;
1869 if (interface->role() == QAccessible::Application)
1870 return u"" ATSPI_DBUS_PATH_ROOT ""_s;
1871
1872 QAccessible::Id id = QAccessible::uniqueId(interface);
1873 Q_ASSERT((int)id < 0);
1874 return QSPI_OBJECT_PATH_PREFIX ""_L1 + QString::number(id);
1875}
1876
1877bool AtSpiAdaptor::inheritsQAction(QObject *object)
1878{
1879 const QMetaObject *mo = object->metaObject();
1880 while (mo) {
1881 const QLatin1StringView cn(mo->className());
1882 if (cn == "QAction"_L1)
1883 return true;
1884 mo = mo->superClass();
1885 }
1886 return false;
1887}
1888
1889// Component
1890static QAccessibleInterface * getWindow(QAccessibleInterface * interface)
1891{
1892 // find top-level window in a11y hierarchy (either has a
1893 // corresponding role or is a direct child of the application object)
1894 QAccessibleInterface* app = QAccessible::queryAccessibleInterface(qApp);
1895 while (interface && interface->role() != QAccessible::Dialog
1896 && interface->role() != QAccessible::Window && interface->parent() != app)
1897 interface = interface->parent();
1898
1899 return interface;
1900}
1901
1902void AtSpiAdaptor::addMatchingDescendants(QList<QAccessibleInterface *> &matches,
1903 QAccessibleInterface *accessible,
1904 const QSpiMatchRuleMatcher &matcher, bool invert,
1905 int count, bool traverse)
1906{
1907 if (!accessible || (count != 0 && matches.size() >= count))
1908 return;
1909
1910 const int childCount = accessible->childCount();
1911 for (int i = 0; i < childCount; ++i) {
1912 if (QAccessibleInterface *child = accessible->child(i)) {
1913 if (matcher.match(*child) != invert)
1914 matches.append(child);
1915
1916 if (traverse)
1917 addMatchingDescendants(matches, child, matcher, invert, count, traverse);
1918
1919 if (count != 0 && matches.size() >= count)
1920 return;
1921 }
1922 }
1923}
1924
1925bool AtSpiAdaptor::collectionInterface(QAccessibleInterface *interface, const QString &function,
1926 const QDBusMessage &message,
1927 const QDBusConnection &connection)
1928{
1929 if (function == "GetMatches"_L1) {
1930 if (message.signature() != u"(aiia{ss}iaiiasib)uib") {
1931 qCWarning(lcAccessibilityAtspi)
1932 << "AtSpiAdaptor::collectionInterface: Invalid signature for " << function
1933 << ": " << message.path();
1934 return false;
1935 }
1936
1937 const QSpiMatchRule matchRule = qdbus_cast<QSpiMatchRule>(message.arguments().at(0));
1938 const int count = message.arguments().at(2).toInt();
1939 const bool traverse = message.arguments().at(3).toBool();
1940
1941 QList<QAccessibleInterface *> matchedAccessibles;
1942 addMatchingDescendants(matchedAccessibles, interface, QSpiMatchRuleMatcher(matchRule),
1943 matchRule.invert, count, traverse);
1944
1945 QSpiObjectReferenceArray result;
1946 result.reserve(matchedAccessibles.size());
1947 for (QAccessibleInterface *iface : std::as_const(matchedAccessibles)) {
1948 QSpiObjectReference ref(connection, QDBusObjectPath(pathForInterface(iface)));
1949 result << ref;
1950 }
1951 connection.send(message.createReply(QVariant::fromValue(result)));
1952 return true;
1953 }
1954
1955 qCWarning(lcAccessibilityAtspi)
1956 << "AtSpiAdaptor::collectionInterface does not implement" << function << message.path();
1957 return false;
1958}
1959
1960bool AtSpiAdaptor::componentInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection)
1961{
1962 if (function == "Contains"_L1) {
1963 bool ret = false;
1964 int x = message.arguments().at(0).toInt();
1965 int y = message.arguments().at(1).toInt();
1966 uint coordType = message.arguments().at(2).toUInt();
1967 if (!isValidCoordType(coordType))
1968 return false;
1969 ret = getExtents(interface, coordType).contains(x, y);
1970 sendReply(connection, message, ret);
1971 } else if (function == "GetAccessibleAtPoint"_L1) {
1972 QPoint point(message.arguments().at(0).toInt(), message.arguments().at(1).toInt());
1973 uint coordType = message.arguments().at(2).toUInt();
1974 if (!isValidCoordType(coordType))
1975 return false;
1976 QPoint screenPos = translateToScreenCoordinates(interface, point, coordType);
1977
1978 QAccessibleInterface * childInterface(interface->childAt(screenPos.x(), screenPos.y()));
1979 QAccessibleInterface * iface = nullptr;
1980 while (childInterface) {
1981 iface = childInterface;
1982 childInterface = iface->childAt(screenPos.x(), screenPos.y());
1983 }
1984 if (iface) {
1985 QString path = pathForInterface(iface);
1986 sendReply(connection, message, QVariant::fromValue(
1987 QSpiObjectReference(connection, QDBusObjectPath(path))));
1988 } else {
1989 sendReply(connection, message, QVariant::fromValue(
1990 QSpiObjectReference(connection, QDBusObjectPath(ATSPI_DBUS_PATH_NULL))));
1991 }
1992 } else if (function == "GetAlpha"_L1) {
1993 sendReply(connection, message, (double) 1.0);
1994 } else if (function == "GetExtents"_L1) {
1995 uint coordType = message.arguments().at(0).toUInt();
1996 if (!isValidCoordType(coordType))
1997 return false;
1998 sendReply(connection, message, QVariant::fromValue(getExtents(interface, coordType)));
1999 } else if (function == "GetLayer"_L1) {
2000 sendReply(connection, message, QVariant::fromValue((uint)1));
2001 } else if (function == "GetMDIZOrder"_L1) {
2002 sendReply(connection, message, QVariant::fromValue((short)0));
2003 } else if (function == "GetPosition"_L1) {
2004 uint coordType = message.arguments().at(0).toUInt();
2005 if (!isValidCoordType(coordType))
2006 return false;
2007 QRect rect = getExtents(interface, coordType);
2008 QVariantList pos;
2009 pos << rect.x() << rect.y();
2010 connection.send(message.createReply(pos));
2011 } else if (function == "GetSize"_L1) {
2012 QRect rect = interface->rect();
2013 QVariantList size;
2014 size << rect.width() << rect.height();
2015 connection.send(message.createReply(size));
2016 } else if (function == "GrabFocus"_L1) {
2017 QAccessibleActionInterface *actionIface = interface->actionInterface();
2018 if (actionIface && actionIface->actionNames().contains(QAccessibleActionInterface::setFocusAction())) {
2019 actionIface->doAction(QAccessibleActionInterface::setFocusAction());
2020 sendReply(connection, message, true);
2021 } else {
2022 sendReply(connection, message, false);
2023 }
2024 } else if (function == "SetExtents"_L1) {
2025// int x = message.arguments().at(0).toInt();
2026// int y = message.arguments().at(1).toInt();
2027// int width = message.arguments().at(2).toInt();
2028// int height = message.arguments().at(3).toInt();
2029// uint coordinateType = message.arguments().at(4).toUInt();
2030 qCDebug(lcAccessibilityAtspi) << "SetExtents is not implemented.";
2031 sendReply(connection, message, false);
2032 } else if (function == "SetPosition"_L1) {
2033// int x = message.arguments().at(0).toInt();
2034// int y = message.arguments().at(1).toInt();
2035// uint coordinateType = message.arguments().at(2).toUInt();
2036 qCDebug(lcAccessibilityAtspi) << "SetPosition is not implemented.";
2037 sendReply(connection, message, false);
2038 } else if (function == "SetSize"_L1) {
2039// int width = message.arguments().at(0).toInt();
2040// int height = message.arguments().at(1).toInt();
2041 qCDebug(lcAccessibilityAtspi) << "SetSize is not implemented.";
2042 sendReply(connection, message, false);
2043 } else {
2044 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::componentInterface does not implement" << function << message.path();
2045 return false;
2046 }
2047 return true;
2048}
2049
2050QRect AtSpiAdaptor::getExtents(QAccessibleInterface *interface, uint coordType)
2051{
2052 return translateFromScreenCoordinates(interface, interface->rect(), coordType);
2053}
2054
2055// Action interface
2056bool AtSpiAdaptor::actionInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection)
2057{
2058 if (function == "GetNActions"_L1) {
2059 int count = QAccessibleBridgeUtils::effectiveActionNames(interface).size();
2060 sendReply(connection, message, QVariant::fromValue(QDBusVariant(QVariant::fromValue(count))));
2061 } else if (function == "DoAction"_L1) {
2062 int index = message.arguments().at(0).toInt();
2063 const QStringList actionNames = QAccessibleBridgeUtils::effectiveActionNames(interface);
2064 if (index < 0 || index >= actionNames.size())
2065 return false;
2066 const QString actionName = actionNames.at(index);
2067 bool success = QAccessibleBridgeUtils::performEffectiveAction(interface, actionName);
2068 sendReply(connection, message, success);
2069 } else if (function == "GetActions"_L1) {
2070 sendReply(connection, message, QVariant::fromValue(getActions(interface)));
2071 } else if (function == "GetName"_L1) {
2072 int index = message.arguments().at(0).toInt();
2073 const QStringList actionNames = QAccessibleBridgeUtils::effectiveActionNames(interface);
2074 if (index < 0 || index >= actionNames.size())
2075 return false;
2076 sendReply(connection, message, actionNames.at(index));
2077 } else if (function == "GetDescription"_L1) {
2078 int index = message.arguments().at(0).toInt();
2079 const QStringList actionNames = QAccessibleBridgeUtils::effectiveActionNames(interface);
2080 if (index < 0 || index >= actionNames.size())
2081 return false;
2082 QString description;
2083 if (QAccessibleActionInterface *actionIface = interface->actionInterface())
2084 description = actionIface->localizedActionDescription(actionNames.at(index));
2085 else
2086 description = qAccessibleLocalizedActionDescription(actionNames.at(index));
2087 sendReply(connection, message, description);
2088 } else if (function == "GetKeyBinding"_L1) {
2089 int index = message.arguments().at(0).toInt();
2090 const QStringList actionNames = QAccessibleBridgeUtils::effectiveActionNames(interface);
2091 if (index < 0 || index >= actionNames.size())
2092 return false;
2093 QStringList keyBindings;
2094 if (QAccessibleActionInterface *actionIface = interface->actionInterface())
2095 keyBindings = actionIface->keyBindingsForAction(actionNames.at(index));
2096 if (keyBindings.isEmpty()) {
2097 QString acc = interface->text(QAccessible::Accelerator);
2098 if (!acc.isEmpty())
2099 keyBindings.append(acc);
2100 }
2101 if (keyBindings.size() > 0)
2102 sendReply(connection, message, keyBindings.join(u';'));
2103 else
2104 sendReply(connection, message, QString());
2105 } else {
2106 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::actionInterface does not implement" << function << message.path();
2107 return false;
2108 }
2109 return true;
2110}
2111
2112QSpiActionArray AtSpiAdaptor::getActions(QAccessibleInterface *interface) const
2113{
2114 QAccessibleActionInterface *actionInterface = interface->actionInterface();
2115 QSpiActionArray actions;
2116 const QStringList actionNames = QAccessibleBridgeUtils::effectiveActionNames(interface);
2117 actions.reserve(actionNames.size());
2118 for (const QString &actionName : actionNames) {
2119 QSpiAction action;
2120
2121 action.name = actionName;
2122 if (actionInterface) {
2123 action.description = actionInterface->localizedActionDescription(actionName);
2124 const QStringList keyBindings = actionInterface->keyBindingsForAction(actionName);
2125 if (!keyBindings.isEmpty())
2126 action.keyBinding = keyBindings.front();
2127 } else {
2128 action.description = qAccessibleLocalizedActionDescription(actionName);
2129 }
2130
2131 actions.append(std::move(action));
2132 }
2133 return actions;
2134}
2135
2136// Text interface
2137bool AtSpiAdaptor::textInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection)
2138{
2139 if (!interface->textInterface())
2140 return false;
2141
2142 // properties
2143 if (function == "GetCaretOffset"_L1) {
2144 sendReply(connection, message, QVariant::fromValue(QDBusVariant(QVariant::fromValue(interface->textInterface()->cursorPosition()))));
2145 } else if (function == "GetCharacterCount"_L1) {
2146 sendReply(connection, message, QVariant::fromValue(QDBusVariant(QVariant::fromValue(interface->textInterface()->characterCount()))));
2147
2148 // functions
2149 } else if (function == "AddSelection"_L1) {
2150 int startOffset = message.arguments().at(0).toInt();
2151 int endOffset = message.arguments().at(1).toInt();
2152 int lastSelection = interface->textInterface()->selectionCount();
2153 interface->textInterface()->setSelection(lastSelection, startOffset, endOffset);
2154 sendReply(connection, message, (interface->textInterface()->selectionCount() > lastSelection));
2155 } else if (function == "GetAttributeRun"_L1) {
2156 int offset = message.arguments().at(0).toInt();
2157 bool includeDefaults = message.arguments().at(1).toBool();
2158 Q_UNUSED(includeDefaults);
2159 connection.send(message.createReply(getAttributes(interface, offset, includeDefaults)));
2160 } else if (function == "GetAttributeValue"_L1) {
2161 int offset = message.arguments().at(0).toInt();
2162 QString attributeName = message.arguments().at(1).toString();
2163 connection.send(message.createReply(QVariant(getAttributeValue(interface, offset, attributeName))));
2164 } else if (function == "GetAttributes"_L1) {
2165 int offset = message.arguments().at(0).toInt();
2166 connection.send(message.createReply(getAttributes(interface, offset, true)));
2167 } else if (function == "GetBoundedRanges"_L1) {
2168 int x = message.arguments().at(0).toInt();
2169 int y = message.arguments().at(1).toInt();
2170 int width = message.arguments().at(2).toInt();
2171 int height = message.arguments().at(3).toInt();
2172 uint coordType = message.arguments().at(4).toUInt();
2173 uint xClipType = message.arguments().at(5).toUInt();
2174 uint yClipType = message.arguments().at(6).toUInt();
2175 Q_UNUSED(x);
2176 Q_UNUSED(y);
2177 Q_UNUSED(width);
2178 Q_UNUSED(height);
2179 Q_UNUSED(coordType);
2180 Q_UNUSED(xClipType);
2181 Q_UNUSED(yClipType);
2182 qCDebug(lcAccessibilityAtspi) << "Not implemented: QSpiAdaptor::GetBoundedRanges";
2183 sendReply(connection, message, QVariant::fromValue(QSpiTextRangeList()));
2184 } else if (function == "GetCharacterAtOffset"_L1) {
2185 int offset = message.arguments().at(0).toInt();
2186 int start;
2187 int end;
2188 const QString charString = interface->textInterface()
2189 ->textAtOffset(offset, QAccessible::CharBoundary, &start, &end);
2190 int codePoint = 0;
2191 QStringIterator stringIt(charString);
2192 if (stringIt.hasNext())
2193 codePoint = static_cast<int>(stringIt.peekNext());
2194 sendReply(connection, message, codePoint);
2195 } else if (function == "GetCharacterExtents"_L1) {
2196 int offset = message.arguments().at(0).toInt();
2197 int coordType = message.arguments().at(1).toUInt();
2198 connection.send(message.createReply(getCharacterExtents(interface, offset, coordType)));
2199 } else if (function == "GetDefaultAttributeSet"_L1 || function == "GetDefaultAttributes"_L1) {
2200 // GetDefaultAttributes is deprecated in favour of GetDefaultAttributeSet.
2201 // Empty set seems reasonable. There is no default attribute set.
2202 sendReply(connection, message, QVariant::fromValue(QSpiAttributeSet()));
2203 } else if (function == "GetNSelections"_L1) {
2204 sendReply(connection, message, interface->textInterface()->selectionCount());
2205 } else if (function == "GetOffsetAtPoint"_L1) {
2206 qCDebug(lcAccessibilityAtspi) << message.signature();
2207 Q_ASSERT(!message.signature().isEmpty());
2208 QPoint point(message.arguments().at(0).toInt(), message.arguments().at(1).toInt());
2209 uint coordType = message.arguments().at(2).toUInt();
2210 if (!isValidCoordType(coordType))
2211 return false;
2212 QPoint screenPos = translateToScreenCoordinates(interface, point, coordType);
2213 int offset = interface->textInterface()->offsetAtPoint(screenPos);
2214 sendReply(connection, message, offset);
2215 } else if (function == "GetRangeExtents"_L1) {
2216 int startOffset = message.arguments().at(0).toInt();
2217 int endOffset = message.arguments().at(1).toInt();
2218 uint coordType = message.arguments().at(2).toUInt();
2219 connection.send(message.createReply(getRangeExtents(interface, startOffset, endOffset, coordType)));
2220 } else if (function == "GetSelection"_L1) {
2221 int selectionNum = message.arguments().at(0).toInt();
2222 int start, end;
2223 interface->textInterface()->selection(selectionNum, &start, &end);
2224 if (start < 0)
2225 start = end = interface->textInterface()->cursorPosition();
2226 QVariantList sel;
2227 sel << start << end;
2228 connection.send(message.createReply(sel));
2229 } else if (function == "GetStringAtOffset"_L1) {
2230 int offset = message.arguments().at(0).toInt();
2231 uint granularity = message.arguments().at(1).toUInt();
2232 if (!isValidAtspiTextGranularity(granularity))
2233 return false;
2234 int startOffset, endOffset;
2235 QString text = interface->textInterface()->textAtOffset(offset, qAccessibleBoundaryTypeFromAtspiTextGranularity(granularity), &startOffset, &endOffset);
2236 QVariantList ret;
2237 ret << text << startOffset << endOffset;
2238 connection.send(message.createReply(ret));
2239 } else if (function == "GetText"_L1) {
2240 int startOffset = message.arguments().at(0).toInt();
2241 int endOffset = message.arguments().at(1).toInt();
2242 if (endOffset == -1) // AT-SPI uses -1 to signal all characters
2243 endOffset = interface->textInterface()->characterCount();
2244 sendReply(connection, message, interface->textInterface()->text(startOffset, endOffset));
2245 } else if (function == "GetTextAfterOffset"_L1) {
2246 int offset = message.arguments().at(0).toInt();
2247 int type = message.arguments().at(1).toUInt();
2248 int startOffset, endOffset;
2249 QString text = interface->textInterface()->textAfterOffset(offset, qAccessibleBoundaryTypeFromAtspiBoundaryType(type), &startOffset, &endOffset);
2250 QVariantList ret;
2251 ret << text << startOffset << endOffset;
2252 connection.send(message.createReply(ret));
2253 } else if (function == "GetTextAtOffset"_L1) {
2254 int offset = message.arguments().at(0).toInt();
2255 int type = message.arguments().at(1).toUInt();
2256 int startOffset, endOffset;
2257 QString text = interface->textInterface()->textAtOffset(offset, qAccessibleBoundaryTypeFromAtspiBoundaryType(type), &startOffset, &endOffset);
2258 QVariantList ret;
2259 ret << text << startOffset << endOffset;
2260 connection.send(message.createReply(ret));
2261 } else if (function == "GetTextBeforeOffset"_L1) {
2262 int offset = message.arguments().at(0).toInt();
2263 int type = message.arguments().at(1).toUInt();
2264 int startOffset, endOffset;
2265 QString text = interface->textInterface()->textBeforeOffset(offset, qAccessibleBoundaryTypeFromAtspiBoundaryType(type), &startOffset, &endOffset);
2266 QVariantList ret;
2267 ret << text << startOffset << endOffset;
2268 connection.send(message.createReply(ret));
2269 } else if (function == "RemoveSelection"_L1) {
2270 int selectionNum = message.arguments().at(0).toInt();
2271 interface->textInterface()->removeSelection(selectionNum);
2272 sendReply(connection, message, true);
2273 } else if (function == "SetCaretOffset"_L1) {
2274 int offset = message.arguments().at(0).toInt();
2275 interface->textInterface()->setCursorPosition(offset);
2276 sendReply(connection, message, true);
2277 } else if (function == "ScrollSubstringTo"_L1) {
2278 int startOffset = message.arguments().at(0).toInt();
2279 int endOffset = message.arguments().at(1).toInt();
2280 // ignore third parameter (scroll type), since QAccessibleTextInterface::scrollToSubstring doesn't have that
2281 qCInfo(lcAccessibilityAtspi) << "AtSpiAdaptor::ScrollSubstringTo doesn'take take scroll type into account.";
2282 interface->textInterface()->scrollToSubstring(startOffset, endOffset);
2283 sendReply(connection, message, true);
2284 } else if (function == "SetSelection"_L1) {
2285 int selectionNum = message.arguments().at(0).toInt();
2286 int startOffset = message.arguments().at(1).toInt();
2287 int endOffset = message.arguments().at(2).toInt();
2288 interface->textInterface()->setSelection(selectionNum, startOffset, endOffset);
2289 sendReply(connection, message, true);
2290 } else {
2291 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::textInterface does not implement" << function << message.path();
2292 return false;
2293 }
2294 return true;
2295}
2296
2297QAccessible::TextBoundaryType AtSpiAdaptor::qAccessibleBoundaryTypeFromAtspiBoundaryType(int atspiTextBoundaryType)
2298{
2299 switch (atspiTextBoundaryType) {
2300 case ATSPI_TEXT_BOUNDARY_CHAR:
2301 return QAccessible::CharBoundary;
2302 case ATSPI_TEXT_BOUNDARY_WORD_START:
2303 case ATSPI_TEXT_BOUNDARY_WORD_END:
2304 return QAccessible::WordBoundary;
2305 case ATSPI_TEXT_BOUNDARY_SENTENCE_START:
2306 case ATSPI_TEXT_BOUNDARY_SENTENCE_END:
2307 return QAccessible::SentenceBoundary;
2308 case ATSPI_TEXT_BOUNDARY_LINE_START:
2309 case ATSPI_TEXT_BOUNDARY_LINE_END:
2310 return QAccessible::LineBoundary;
2311 }
2312 Q_ASSERT_X(0, "", "Requested invalid boundary type.");
2313 return QAccessible::CharBoundary;
2314}
2315
2316bool AtSpiAdaptor::isValidAtspiTextGranularity(uint atspiTextGranularity)
2317{
2318 if (atspiTextGranularity == ATSPI_TEXT_GRANULARITY_CHAR
2319 || atspiTextGranularity == ATSPI_TEXT_GRANULARITY_WORD
2320 || atspiTextGranularity == ATSPI_TEXT_GRANULARITY_SENTENCE
2321 || atspiTextGranularity == ATSPI_TEXT_GRANULARITY_LINE
2322 || atspiTextGranularity == ATSPI_TEXT_GRANULARITY_PARAGRAPH)
2323 return true;
2324
2325 qCWarning(lcAccessibilityAtspi) << "Unknown value" << atspiTextGranularity << "for AT-SPI text granularity type";
2326 return false;
2327}
2328
2329QAccessible::TextBoundaryType AtSpiAdaptor::qAccessibleBoundaryTypeFromAtspiTextGranularity(uint atspiTextGranularity)
2330{
2331 Q_ASSERT(isValidAtspiTextGranularity(atspiTextGranularity));
2332
2333 switch (atspiTextGranularity) {
2334 case ATSPI_TEXT_GRANULARITY_CHAR:
2335 return QAccessible::CharBoundary;
2336 case ATSPI_TEXT_GRANULARITY_WORD:
2337 return QAccessible::WordBoundary;
2338 case ATSPI_TEXT_GRANULARITY_SENTENCE:
2339 return QAccessible::SentenceBoundary;
2340 case ATSPI_TEXT_GRANULARITY_LINE:
2341 return QAccessible::LineBoundary;
2342 case ATSPI_TEXT_GRANULARITY_PARAGRAPH:
2343 return QAccessible::ParagraphBoundary;
2344 }
2345 return QAccessible::CharBoundary;
2346}
2347
2348namespace
2349{
2350 struct AtSpiAttribute {
2351 QString name;
2352 QString value;
2353 AtSpiAttribute(const QString &aName, const QString &aValue) : name(aName), value(aValue) {}
2354 bool isNull() const { return name.isNull() || value.isNull(); }
2355 };
2356
2357 QString atspiColor(const QString &ia2Color)
2358 {
2359 // "rgb(%u,%u,%u)" -> "%u,%u,%u"
2360 return ia2Color.mid(4, ia2Color.size() - (4+1)).replace(u"\\,"_s, u","_s);
2361 }
2362
2363 QString atspiSize(const QString &ia2Size)
2364 {
2365 // "%fpt" -> "%f"
2366 return ia2Size.left(ia2Size.size() - 2);
2367 }
2368
2369 AtSpiAttribute atspiTextAttribute(const QString &ia2Name, const QString &ia2Value)
2370 {
2371 QString name = ia2Name;
2372 QString value = ia2Value;
2373
2374 // IAccessible2: https://github.com/LinuxA11y/IAccessible2/blob/master/spec/textattributes.md
2375 // ATK attribute names: https://gitlab.gnome.org/GNOME/orca/-/blob/master/src/orca/text_attribute_names.py
2376 // ATK attribute values: https://gnome.pages.gitlab.gnome.org/atk/AtkText.html#AtkTextAttribute
2377
2378 // https://bugzilla.gnome.org/show_bug.cgi?id=744553 "ATK docs provide no guidance for allowed values of some text attributes"
2379 // specifically for "weight", "invalid", "language" and value range for colors
2380
2381 if (ia2Name == "background-color"_L1) {
2382 name = QStringLiteral("bg-color");
2383 value = atspiColor(value);
2384 } else if (ia2Name == "font-family"_L1) {
2385 name = QStringLiteral("family-name");
2386 } else if (ia2Name == "color"_L1) {
2387 name = QStringLiteral("fg-color");
2388 value = atspiColor(value);
2389 } else if (ia2Name == "text-align"_L1) {
2390 name = QStringLiteral("justification");
2391 if (value == "justify"_L1) {
2392 value = QStringLiteral("fill");
2393 } else if (value != "left"_L1 && value != "right"_L1 && value != "center"_L1) {
2394 qCDebug(lcAccessibilityAtspi) << "Unknown text-align attribute value \""
2395 << value << "\" cannot be translated to AT-SPI.";
2396 value = QString();
2397 }
2398 } else if (ia2Name == "font-size"_L1) {
2399 name = QStringLiteral("size");
2400 value = atspiSize(value);
2401 } else if (ia2Name == "font-style"_L1) {
2402 name = QStringLiteral("style");
2403 if (value != "normal"_L1 && value != "italic"_L1 && value != "oblique"_L1) {
2404 qCDebug(lcAccessibilityAtspi) << "Unknown font-style attribute value \"" << value
2405 << "\" cannot be translated to AT-SPI.";
2406 value = QString();
2407 }
2408 } else if (ia2Name == "text-underline-type"_L1) {
2409 name = QStringLiteral("underline");
2410 if (value != "none"_L1 && value != "single"_L1 && value != "double"_L1) {
2411 qCDebug(lcAccessibilityAtspi) << "Unknown text-underline-type attribute value \""
2412 << value << "\" cannot be translated to AT-SPI.";
2413 value = QString();
2414 }
2415 } else if (ia2Name == "font-weight"_L1) {
2416 name = QStringLiteral("weight");
2417 if (value == "normal"_L1)
2418 // Orca seems to accept all IAccessible2 values except for "normal"
2419 // (on which it produces traceback and fails to read any following text attributes),
2420 // but that is the default value, so omit it anyway
2421 value = QString();
2422 } else if (((ia2Name == "text-line-through-style"_L1 || ia2Name == "text-line-through-type"_L1) && (ia2Value != "none"_L1))
2423 || (ia2Name == "text-line-through-text"_L1 && !ia2Value.isEmpty())) {
2424 // if any of the above is set, set "strikethrough" to true, but don't explicitly set
2425 // to false otherwise, since any of the others might still be set to indicate strikethrough
2426 // and no strikethrough is assumed anyway when nothing is explicitly set
2427 name = QStringLiteral("strikethrough");
2428 value = QStringLiteral("true");
2429 } else if (ia2Name == "text-position"_L1) {
2430 name = QStringLiteral("vertical-align");
2431 if (value != "baseline"_L1 && value != "super"_L1 && value != "sub"_L1) {
2432 qCDebug(lcAccessibilityAtspi) << "Unknown text-position attribute value \"" << value
2433 << "\" cannot be translated to AT-SPI.";
2434 value = QString();
2435 }
2436 } else if (ia2Name == "writing-mode"_L1) {
2437 name = QStringLiteral("direction");
2438 if (value == "lr"_L1)
2439 value = QStringLiteral("ltr");
2440 else if (value == "rl"_L1)
2441 value = QStringLiteral("rtl");
2442 else if (value == "tb"_L1) {
2443 // IAccessible2 docs refer to XSL, which specifies "tb" is shorthand for "tb-rl"; so at least give a hint about the horizontal direction (ATK does not support vertical direction in this attribute (yet))
2444 value = QStringLiteral("rtl");
2445 qCDebug(lcAccessibilityAtspi) << "writing-mode attribute value \"tb\" translated only w.r.t. horizontal direction; vertical direction ignored";
2446 } else {
2447 qCDebug(lcAccessibilityAtspi) << "Unknown writing-mode attribute value \"" << value
2448 << "\" cannot be translated to AT-SPI.";
2449 value = QString();
2450 }
2451 } else if (ia2Name == "language"_L1) {
2452 // OK - ATK has no docs on the format of the value, IAccessible2 has reasonable format - leave it at that now
2453 } else if (ia2Name == "invalid"_L1) {
2454 // OK - ATK docs are vague but suggest they support the same range of values as IAccessible2
2455 } else {
2456 // attribute we know nothing about
2457 name = QString();
2458 value = QString();
2459 }
2460 return AtSpiAttribute(name, value);
2461 }
2462}
2463
2464QSpiAttributeSet AtSpiAdaptor::getAttributes(QAccessibleInterface *interface)
2465{
2466 QSpiAttributeSet set;
2467 QAccessibleAttributesInterface *attributesIface = interface->attributesInterface();
2468 if (!attributesIface)
2469 return set;
2470
2471 const QList<QAccessible::Attribute> attrKeys = attributesIface->attributeKeys();
2472 for (QAccessible::Attribute key : attrKeys) {
2473 const QVariant value = attributesIface->attributeValue(key);
2474 // see "Core Accessibility API Mappings" spec: https://www.w3.org/TR/core-aam-1.2/
2475 switch (key) {
2476 case QAccessible::Attribute::Custom:
2477 {
2478 // forward custom attributes to AT-SPI as-is
2479 Q_ASSERT((value.canConvert<QHash<QString, QString>>()));
2480 const QHash<QString, QString> attrMap = value.value<QHash<QString, QString>>();
2481 for (auto [name, val] : attrMap.asKeyValueRange())
2482 set.insert(name, val);
2483 break;
2484 }
2485 case QAccessible::Attribute::Level:
2486 Q_ASSERT(value.canConvert<int>());
2487 set.insert(QStringLiteral("level"), QString::number(value.toInt()));
2488 break;
2489 case QAccessible::Attribute::PositionInSet:
2490 Q_ASSERT(value.canConvert<int>());
2491 set.insert(QStringLiteral("posinset"), QString::number(value.toInt()));
2492 break;
2493 case QAccessible::Attribute::SizeOfSet:
2494 Q_ASSERT(value.canConvert<int>());
2495 set.insert(QStringLiteral("setsize"), QString::number(value.toInt()));
2496 break;
2497 default:
2498 break;
2499 }
2500 }
2501 return set;
2502}
2503
2504// FIXME all attribute methods below should share code
2505QVariantList AtSpiAdaptor::getAttributes(QAccessibleInterface *interface, int offset,
2506 bool includeDefaults)
2507{
2508 Q_UNUSED(includeDefaults);
2509
2510 QSpiAttributeSet set;
2511 int startOffset;
2512 int endOffset;
2513
2514 QString joined = interface->textInterface()->attributes(offset, &startOffset, &endOffset);
2515 const QStringList attributes = joined.split(u';', Qt::SkipEmptyParts, Qt::CaseSensitive);
2516 for (const QString &attr : attributes) {
2517 QStringList items = attr.split(u':', Qt::SkipEmptyParts, Qt::CaseSensitive);
2518 if (items.count() == 2)
2519 {
2520 AtSpiAttribute attribute = atspiTextAttribute(items[0], items[1]);
2521 if (!attribute.isNull())
2522 set[attribute.name] = attribute.value;
2523 }
2524 }
2525
2526 QVariantList list;
2527 list << QVariant::fromValue(set) << startOffset << endOffset;
2528
2529 return list;
2530}
2531
2532QString AtSpiAdaptor::getAttributeValue(QAccessibleInterface *interface, int offset,
2533 const QString &attributeName)
2534{
2535 QString joined;
2536 QSpiAttributeSet map;
2537 int startOffset;
2538 int endOffset;
2539
2540 joined = interface->textInterface()->attributes(offset, &startOffset, &endOffset);
2541 const QStringList attributes = joined.split (u';', Qt::SkipEmptyParts, Qt::CaseSensitive);
2542 for (const QString& attr : attributes) {
2543 QStringList items;
2544 items = attr.split(u':', Qt::SkipEmptyParts, Qt::CaseSensitive);
2545 AtSpiAttribute attribute = atspiTextAttribute(items[0], items[1]);
2546 if (!attribute.isNull())
2547 map[attribute.name] = attribute.value;
2548 }
2549 return map[attributeName];
2550}
2551
2552QList<QVariant> AtSpiAdaptor::getCharacterExtents(QAccessibleInterface *interface, int offset,
2553 uint coordType)
2554{
2555 QRect rect = interface->textInterface()->characterRect(offset);
2556 rect = translateFromScreenCoordinates(interface, rect, coordType);
2557 return QList<QVariant>() << rect.x() << rect.y() << rect.width() << rect.height();
2558}
2559
2560QList<QVariant> AtSpiAdaptor::getRangeExtents(QAccessibleInterface *interface, int startOffset,
2561 int endOffset, uint coordType)
2562{
2563 if (endOffset == -1)
2564 endOffset = interface->textInterface()->characterCount();
2565
2566 QAccessibleTextInterface *textInterface = interface->textInterface();
2567 if (endOffset <= startOffset || !textInterface)
2568 return QList<QVariant>() << -1 << -1 << 0 << 0;
2569
2570 QRect rect = textInterface->characterRect(startOffset);
2571 for (int i=startOffset + 1; i <= endOffset; i++)
2572 rect = rect | textInterface->characterRect(i);
2573
2574 rect = translateFromScreenCoordinates(interface, rect, coordType);
2575 return QList<QVariant>() << rect.x() << rect.y() << rect.width() << rect.height();
2576}
2577
2578bool AtSpiAdaptor::isValidCoordType(uint coordType)
2579{
2580 if (coordType == ATSPI_COORD_TYPE_SCREEN || coordType == ATSPI_COORD_TYPE_WINDOW || coordType == ATSPI_COORD_TYPE_PARENT)
2581 return true;
2582
2583 qCWarning(lcAccessibilityAtspi) << "Unknown value" << coordType << "for AT-SPI coord type";
2584 return false;
2585}
2586
2587QRect AtSpiAdaptor::translateFromScreenCoordinates(QAccessibleInterface *interface, const QRect &screenRect, uint targetCoordType)
2588{
2589 Q_ASSERT(isValidCoordType(targetCoordType));
2590
2591 QAccessibleInterface *upper = nullptr;
2592 if (targetCoordType == ATSPI_COORD_TYPE_WINDOW)
2593 upper = getWindow(interface);
2594 else if (targetCoordType == ATSPI_COORD_TYPE_PARENT)
2595 upper = interface->parent();
2596
2597 QRect rect = screenRect;
2598 if (upper)
2599 rect.translate(-upper->rect().x(), -upper->rect().y());
2600
2601 return rect;
2602}
2603
2604QPoint AtSpiAdaptor::translateToScreenCoordinates(QAccessibleInterface *interface, const QPoint &pos, uint fromCoordType)
2605{
2606 Q_ASSERT(isValidCoordType(fromCoordType));
2607
2608 QAccessibleInterface *upper = nullptr;
2609 if (fromCoordType == ATSPI_COORD_TYPE_WINDOW)
2610 upper = getWindow(interface);
2611 else if (fromCoordType == ATSPI_COORD_TYPE_PARENT)
2612 upper = interface->parent();
2613
2614 QPoint screenPos = pos;
2615 if (upper)
2616 screenPos += upper->rect().topLeft();
2617
2618 return screenPos;
2619}
2620
2621// Editable Text interface
2622static QString textForRange(QAccessibleInterface *accessible, int startOffset, int endOffset)
2623{
2624 if (QAccessibleTextInterface *textIface = accessible->textInterface()) {
2625 if (endOffset == -1)
2626 endOffset = textIface->characterCount();
2627 return textIface->text(startOffset, endOffset);
2628 }
2629 QString txt = accessible->text(QAccessible::Value);
2630 if (endOffset == -1)
2631 endOffset = txt.size();
2632 return txt.mid(startOffset, endOffset - startOffset);
2633}
2634
2635static void replaceTextFallback(QAccessibleInterface *accessible, long startOffset, long endOffset, const QString &txt)
2636{
2637 QString t = textForRange(accessible, 0, -1);
2638 if (endOffset == -1)
2639 endOffset = t.size();
2640 if (endOffset - startOffset == 0)
2641 t.insert(startOffset, txt);
2642 else
2643 t.replace(startOffset, endOffset - startOffset, txt);
2644 accessible->setText(QAccessible::Value, t);
2645}
2646
2647bool AtSpiAdaptor::editableTextInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection)
2648{
2649 if (function == "CopyText"_L1) {
2650#ifndef QT_NO_CLIPBOARD
2651 int startOffset = message.arguments().at(0).toInt();
2652 int endOffset = message.arguments().at(1).toInt();
2653 const QString t = textForRange(interface, startOffset, endOffset);
2654 QGuiApplication::clipboard()->setText(t);
2655#endif
2656 connection.send(message.createReply(true));
2657 } else if (function == "CutText"_L1) {
2658#ifndef QT_NO_CLIPBOARD
2659 int startOffset = message.arguments().at(0).toInt();
2660 int endOffset = message.arguments().at(1).toInt();
2661 const QString t = textForRange(interface, startOffset, endOffset);
2662 if (QAccessibleEditableTextInterface *editableTextIface = interface->editableTextInterface())
2663 editableTextIface->deleteText(startOffset, endOffset);
2664 else
2665 replaceTextFallback(interface, startOffset, endOffset, QString());
2666 QGuiApplication::clipboard()->setText(t);
2667#endif
2668 connection.send(message.createReply(true));
2669 } else if (function == "DeleteText"_L1) {
2670 int startOffset = message.arguments().at(0).toInt();
2671 int endOffset = message.arguments().at(1).toInt();
2672 if (QAccessibleEditableTextInterface *editableTextIface = interface->editableTextInterface())
2673 editableTextIface->deleteText(startOffset, endOffset);
2674 else
2675 replaceTextFallback(interface, startOffset, endOffset, QString());
2676 connection.send(message.createReply(true));
2677 } else if (function == "InsertText"_L1) {
2678 int position = message.arguments().at(0).toInt();
2679 QString text = message.arguments().at(1).toString();
2680 int length = message.arguments().at(2).toInt();
2681 text.resize(length);
2682 if (QAccessibleEditableTextInterface *editableTextIface = interface->editableTextInterface())
2683 editableTextIface->insertText(position, text);
2684 else
2685 replaceTextFallback(interface, position, position, text);
2686 connection.send(message.createReply(true));
2687 } else if (function == "PasteText"_L1) {
2688#ifndef QT_NO_CLIPBOARD
2689 int position = message.arguments().at(0).toInt();
2690 const QString txt = QGuiApplication::clipboard()->text();
2691 if (QAccessibleEditableTextInterface *editableTextIface = interface->editableTextInterface())
2692 editableTextIface->insertText(position, txt);
2693 else
2694 replaceTextFallback(interface, position, position, txt);
2695#endif
2696 connection.send(message.createReply(true));
2697 } else if (function == "SetTextContents"_L1) {
2698 QString newContents = message.arguments().at(0).toString();
2699 if (QAccessibleEditableTextInterface *editableTextIface = interface->editableTextInterface())
2700 editableTextIface->replaceText(0, interface->textInterface()->characterCount(), newContents);
2701 else
2702 replaceTextFallback(interface, 0, -1, newContents);
2703 connection.send(message.createReply(true));
2704 } else if (function.isEmpty()) {
2705 connection.send(message.createReply());
2706 } else {
2707 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::editableTextInterface does not implement" << function << message.path();
2708 return false;
2709 }
2710 return true;
2711}
2712
2713// Value interface
2714bool AtSpiAdaptor::valueInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection)
2715{
2716 QAccessibleValueInterface *valueIface = interface->valueInterface();
2717 if (!valueIface)
2718 return false;
2719
2720 if (function == "SetCurrentValue"_L1) {
2721 QDBusVariant v = qvariant_cast<QDBusVariant>(message.arguments().at(2));
2722 double value = v.variant().toDouble();
2723 //Temporary fix
2724 //See https://bugzilla.gnome.org/show_bug.cgi?id=652596
2725 valueIface->setCurrentValue(value);
2726 connection.send(message.createReply());
2727 } else {
2728 QVariant value;
2729 if (function == "GetCurrentValue"_L1)
2730 value = valueIface->currentValue();
2731 else if (function == "GetMaximumValue"_L1)
2732 value = valueIface->maximumValue();
2733 else if (function == "GetMinimumIncrement"_L1)
2734 value = valueIface->minimumStepSize();
2735 else if (function == "GetMinimumValue"_L1)
2736 value = valueIface->minimumValue();
2737 else {
2738 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::valueInterface does not implement" << function << message.path();
2739 return false;
2740 }
2741 if (!value.canConvert<double>()) {
2742 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::valueInterface: Could not convert to double:" << function;
2743 }
2744
2745 // explicitly convert to dbus-variant containing one double since atspi expects that
2746 // everything else might fail to convert back on the other end
2747 connection.send(message.createReply(
2748 QVariant::fromValue(QDBusVariant(QVariant::fromValue(value.toDouble())))));
2749 }
2750 return true;
2751}
2752
2753// Selection interface
2754bool AtSpiAdaptor::selectionInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection)
2755{
2756 QAccessibleSelectionInterface* selectionInterface = interface->selectionInterface();
2757 if (!selectionInterface) {
2758 qCWarning(lcAccessibilityAtspi) << "Could not find selection interface for: " << message.path() << interface;
2759 return false;
2760 }
2761
2762 if (function == "ClearSelection"_L1 ) {
2763 connection.send(message.createReply(QVariant::fromValue((selectionInterface->clear()))));
2764 } else if (function == "DeselectChild"_L1 ) {
2765 int childIndex = message.arguments().at(0).toInt();
2766 bool ret = false;
2767 QAccessibleInterface *child = interface->child(childIndex);
2768 if (child)
2769 ret = selectionInterface->unselect(child);
2770 connection.send(message.createReply(QVariant::fromValue(ret)));
2771 } else if (function == "DeselectSelectedChild"_L1 ) {
2772 int selectionIndex = message.arguments().at(0).toInt();
2773 bool ret = false;
2774 QAccessibleInterface *selectedChild = selectionInterface->selectedItem(selectionIndex);
2775 if (selectedChild)
2776 ret = selectionInterface->unselect(selectedChild);
2777 connection.send(message.createReply(QVariant::fromValue(ret)));
2778 } else if (function == "GetNSelectedChildren"_L1) {
2779 connection.send(message.createReply(QVariant::fromValue(QDBusVariant(
2780 QVariant::fromValue(selectionInterface->selectedItemCount())))));
2781 } else if (function == "GetSelectedChild"_L1) {
2782 int selectionIndex = message.arguments().at(0).toInt();
2783 QSpiObjectReference ref(connection, QDBusObjectPath(pathForInterface(selectionInterface->selectedItem(selectionIndex))));
2784 connection.send(message.createReply(QVariant::fromValue(ref)));
2785 } else if (function == "IsChildSelected"_L1 ) {
2786 int childIndex = message.arguments().at(0).toInt();
2787 bool ret = false;
2788 QAccessibleInterface *child = interface->child(childIndex);
2789 if (child)
2790 ret = selectionInterface->isSelected(child);
2791 connection.send(message.createReply(QVariant::fromValue(ret)));
2792 } else if (function == "SelectAll"_L1 ) {
2793 connection.send(message.createReply(QVariant::fromValue(selectionInterface->selectAll())));
2794 } else if (function == "SelectChild"_L1 ) {
2795 int childIndex = message.arguments().at(0).toInt();
2796 bool ret = false;
2797 QAccessibleInterface *child = interface->child(childIndex);
2798 if (child)
2799 ret = selectionInterface->select(child);
2800 connection.send(message.createReply(QVariant::fromValue(ret)));
2801 } else {
2802 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::selectionInterface does not implement " << function << message.path();
2803 return false;
2804 }
2805
2806 return true;
2807}
2808
2809
2810// Table interface
2811bool AtSpiAdaptor::tableInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection)
2812{
2813 if (!(interface->tableInterface() || interface->tableCellInterface())) {
2814 qCWarning(lcAccessibilityAtspi) << "Qt AtSpiAdaptor: Could not find table interface for:" << message.path() << interface;
2815 return false;
2816 }
2817
2818 if (function == "GetCaption"_L1) {
2819 QAccessibleInterface * captionInterface= interface->tableInterface()->caption();
2820 if (captionInterface) {
2821 QSpiObjectReference ref = QSpiObjectReference(connection, QDBusObjectPath(pathForInterface(captionInterface)));
2822 sendReply(connection, message, QVariant::fromValue(QDBusVariant(QVariant::fromValue(ref))));
2823 } else {
2824 sendReply(connection, message, QVariant::fromValue(QDBusVariant(QVariant::fromValue(
2825 QSpiObjectReference(connection, QDBusObjectPath(ATSPI_DBUS_PATH_NULL))))));
2826 }
2827 } else if (function == "GetNColumns"_L1) {
2828 connection.send(message.createReply(QVariant::fromValue(QDBusVariant(
2829 QVariant::fromValue(interface->tableInterface()->columnCount())))));
2830 } else if (function == "GetNRows"_L1) {
2831 connection.send(message.createReply(QVariant::fromValue(QDBusVariant(
2832 QVariant::fromValue(interface->tableInterface()->rowCount())))));
2833 } else if (function == "GetNSelectedColumns"_L1) {
2834 connection.send(message.createReply(QVariant::fromValue(QDBusVariant(
2835 QVariant::fromValue(interface->tableInterface()->selectedColumnCount())))));
2836 } else if (function == "GetNSelectedRows"_L1) {
2837 connection.send(message.createReply(QVariant::fromValue(QDBusVariant(
2838 QVariant::fromValue(interface->tableInterface()->selectedRowCount())))));
2839 } else if (function == "GetSummary"_L1) {
2840 QAccessibleInterface *summary = interface->tableInterface() ? interface->tableInterface()->summary() : nullptr;
2841 QSpiObjectReference ref(connection, QDBusObjectPath(pathForInterface(summary)));
2842 connection.send(message.createReply(QVariant::fromValue(QDBusVariant(QVariant::fromValue(ref)))));
2843 } else if (function == "GetAccessibleAt"_L1) {
2844 int row = message.arguments().at(0).toInt();
2845 int column = message.arguments().at(1).toInt();
2846 if ((row < 0) ||
2847 (column < 0) ||
2848 (row >= interface->tableInterface()->rowCount()) ||
2849 (column >= interface->tableInterface()->columnCount())) {
2850 qCWarning(lcAccessibilityAtspi) << "Invalid index for tableInterface GetAccessibleAt (" << row << "," << column << ')';
2851 return false;
2852 }
2853
2854 QSpiObjectReference ref;
2855 QAccessibleInterface * cell(interface->tableInterface()->cellAt(row, column));
2856 if (cell) {
2857 ref = QSpiObjectReference(connection, QDBusObjectPath(pathForInterface(cell)));
2858 } else {
2859 qCWarning(lcAccessibilityAtspi) << "No cell interface returned for" << interface->object() << row << column;
2860 ref = QSpiObjectReference();
2861 }
2862 connection.send(message.createReply(QVariant::fromValue(ref)));
2863
2864 } else if (function == "GetIndexAt"_L1) {
2865 int row = message.arguments().at(0).toInt();
2866 int column = message.arguments().at(1).toInt();
2867 QAccessibleInterface *cell = interface->tableInterface()->cellAt(row, column);
2868 if (!cell) {
2869 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::GetIndexAt(" << row << ',' << column << ") did not find a cell." << interface;
2870 return false;
2871 }
2872 int index = interface->indexOfChild(cell);
2873 qCDebug(lcAccessibilityAtspi) << "QSpiAdaptor::GetIndexAt row:" << row << " col:" << column << " logical index:" << index;
2874 Q_ASSERT(index > 0);
2875 connection.send(message.createReply(index));
2876 } else if ((function == "GetColumnAtIndex"_L1) || (function == "GetRowAtIndex"_L1)) {
2877 int index = message.arguments().at(0).toInt();
2878 int ret = -1;
2879 if (index >= 0) {
2880 QAccessibleInterface * cell = interface->child(index);
2881 if (cell) {
2882 if (function == "GetColumnAtIndex"_L1) {
2883 if (cell->role() == QAccessible::ColumnHeader) {
2884 ret = index;
2885 } else if (cell->role() == QAccessible::RowHeader) {
2886 ret = -1;
2887 } else {
2888 if (!cell->tableCellInterface()) {
2889 qCWarning(lcAccessibilityAtspi).nospace() << "AtSpiAdaptor::" << function << " No table cell interface: " << cell;
2890 return false;
2891 }
2892 ret = cell->tableCellInterface()->columnIndex();
2893 }
2894 } else {
2895 if (cell->role() == QAccessible::ColumnHeader) {
2896 ret = -1;
2897 } else if (cell->role() == QAccessible::RowHeader) {
2898 ret = index % interface->tableInterface()->columnCount();
2899 } else {
2900 if (!cell->tableCellInterface()) {
2901 qCWarning(lcAccessibilityAtspi).nospace() << "AtSpiAdaptor::" << function << " No table cell interface: " << cell;
2902 return false;
2903 }
2904 ret = cell->tableCellInterface()->rowIndex();
2905 }
2906 }
2907 } else {
2908 qCWarning(lcAccessibilityAtspi).nospace() << "AtSpiAdaptor::" << function << " No cell at index: " << index << " " << interface;
2909 return false;
2910 }
2911 }
2912 connection.send(message.createReply(ret));
2913
2914 } else if (function == "GetColumnDescription"_L1) {
2915 int column = message.arguments().at(0).toInt();
2916 connection.send(message.createReply(interface->tableInterface()->columnDescription(column)));
2917 } else if (function == "GetRowDescription"_L1) {
2918 int row = message.arguments().at(0).toInt();
2919 connection.send(message.createReply(interface->tableInterface()->rowDescription(row)));
2920
2921
2922
2923 } else if (function == "GetRowColumnExtentsAtIndex"_L1) {
2924 int index = message.arguments().at(0).toInt();
2925 bool success = false;
2926
2927 int row = -1;
2928 int col = -1;
2929 int rowExtents = -1;
2930 int colExtents = -1;
2931 bool isSelected = false;
2932
2933 int cols = interface->tableInterface()->columnCount();
2934 if (cols > 0) {
2935 row = index / cols;
2936 col = index % cols;
2937 if (QAccessibleInterface *cell = interface->tableInterface()->cellAt(row, col)) {
2938 if (QAccessibleTableCellInterface *cellIface = cell->tableCellInterface()) {
2939 row = cellIface->rowIndex();
2940 col = cellIface->columnIndex();
2941 rowExtents = cellIface->rowExtent();
2942 colExtents = cellIface->columnExtent();
2943 isSelected = cellIface->isSelected();
2944 success = true;
2945 }
2946 }
2947 }
2948 QVariantList list;
2949 list << success << row << col << rowExtents << colExtents << isSelected;
2950 connection.send(message.createReply(list));
2951
2952 } else if (function == "GetColumnExtentAt"_L1) {
2953 int row = message.arguments().at(0).toInt();
2954 int column = message.arguments().at(1).toInt();
2955 int columnExtent = 0;
2956 if (QAccessibleInterface *cell = interface->tableInterface()->cellAt(row, column)) {
2957 if (QAccessibleTableCellInterface *cellIface = cell->tableCellInterface())
2958 columnExtent = cellIface->columnExtent();
2959 }
2960 connection.send(message.createReply(columnExtent));
2961
2962 } else if (function == "GetRowExtentAt"_L1) {
2963 int row = message.arguments().at(0).toInt();
2964 int column = message.arguments().at(1).toInt();
2965 int rowExtent = 0;
2966 if (QAccessibleInterface *cell = interface->tableInterface()->cellAt(row, column)) {
2967 if (QAccessibleTableCellInterface *cellIface = cell->tableCellInterface())
2968 rowExtent = cellIface->rowExtent();
2969 }
2970 connection.send(message.createReply(rowExtent));
2971
2972 } else if (function == "GetColumnHeader"_L1) {
2973 int column = message.arguments().at(0).toInt();
2974 QSpiObjectReference ref;
2975
2976 QAccessibleInterface * cell(interface->tableInterface()->cellAt(0, column));
2977 if (cell && cell->tableCellInterface()) {
2978 QList<QAccessibleInterface*> header = cell->tableCellInterface()->columnHeaderCells();
2979 if (header.size() > 0) {
2980 ref = QSpiObjectReference(connection, QDBusObjectPath(pathForInterface(header.takeAt(0))));
2981 }
2982 }
2983 connection.send(message.createReply(QVariant::fromValue(ref)));
2984
2985 } else if (function == "GetRowHeader"_L1) {
2986 int row = message.arguments().at(0).toInt();
2987 QSpiObjectReference ref;
2988 QAccessibleInterface *cell = interface->tableInterface()->cellAt(row, 0);
2989 if (cell && cell->tableCellInterface()) {
2990 QList<QAccessibleInterface*> header = cell->tableCellInterface()->rowHeaderCells();
2991 if (header.size() > 0) {
2992 ref = QSpiObjectReference(connection, QDBusObjectPath(pathForInterface(header.takeAt(0))));
2993 }
2994 }
2995 connection.send(message.createReply(QVariant::fromValue(ref)));
2996
2997 } else if (function == "GetSelectedColumns"_L1) {
2998 connection.send(message.createReply(QVariant::fromValue(interface->tableInterface()->selectedColumns())));
2999 } else if (function == "GetSelectedRows"_L1) {
3000 connection.send(message.createReply(QVariant::fromValue(interface->tableInterface()->selectedRows())));
3001 } else if (function == "IsColumnSelected"_L1) {
3002 int column = message.arguments().at(0).toInt();
3003 connection.send(message.createReply(interface->tableInterface()->isColumnSelected(column)));
3004 } else if (function == "IsRowSelected"_L1) {
3005 int row = message.arguments().at(0).toInt();
3006 connection.send(message.createReply(interface->tableInterface()->isRowSelected(row)));
3007 } else if (function == "IsSelected"_L1) {
3008 int row = message.arguments().at(0).toInt();
3009 int column = message.arguments().at(1).toInt();
3010 bool selected = false;
3011 if (QAccessibleInterface* cell = interface->tableInterface()->cellAt(row, column)) {
3012 if (QAccessibleTableCellInterface *cellIface = cell->tableCellInterface())
3013 selected = cellIface->isSelected();
3014 }
3015 connection.send(message.createReply(selected));
3016 } else if (function == "AddColumnSelection"_L1) {
3017 int column = message.arguments().at(0).toInt();
3018 connection.send(message.createReply(interface->tableInterface()->selectColumn(column)));
3019 } else if (function == "AddRowSelection"_L1) {
3020 int row = message.arguments().at(0).toInt();
3021 connection.send(message.createReply(interface->tableInterface()->selectRow(row)));
3022 } else if (function == "RemoveColumnSelection"_L1) {
3023 int column = message.arguments().at(0).toInt();
3024 connection.send(message.createReply(interface->tableInterface()->unselectColumn(column)));
3025 } else if (function == "RemoveRowSelection"_L1) {
3026 int row = message.arguments().at(0).toInt();
3027 connection.send(message.createReply(interface->tableInterface()->unselectRow(row)));
3028 } else {
3029 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::tableInterface does not implement" << function << message.path();
3030 return false;
3031 }
3032 return true;
3033}
3034
3035// Table cell interface
3036bool AtSpiAdaptor::tableCellInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection)
3037{
3038 QAccessibleTableCellInterface* cellInterface = interface->tableCellInterface();
3039 if (!cellInterface) {
3040 qCWarning(lcAccessibilityAtspi) << "Could not find table cell interface for: " << message.path() << interface;
3041 return false;
3042 }
3043
3044 if (function == "GetColumnHeaderCells"_L1) {
3045 QSpiObjectReferenceArray headerCells;
3046 const auto headerCellInterfaces = cellInterface->columnHeaderCells();
3047 headerCells.reserve(headerCellInterfaces.size());
3048 for (QAccessibleInterface *cell : headerCellInterfaces) {
3049 const QString childPath = pathForInterface(cell);
3050 const QSpiObjectReference ref(connection, QDBusObjectPath(childPath));
3051 headerCells << ref;
3052 }
3053 connection.send(message.createReply(QVariant::fromValue(headerCells)));
3054 } else if (function == "GetColumnSpan"_L1) {
3055 connection.send(message.createReply(QVariant::fromValue(QDBusVariant(
3056 QVariant::fromValue(cellInterface->columnExtent())))));
3057 } else if (function == "GetPosition"_L1) {
3058 const int row = cellInterface->rowIndex();
3059 const int column = cellInterface->columnIndex();
3060 connection.send(message.createReply(QVariant::fromValue(QDBusVariant(
3061 QVariant::fromValue(QPoint(row, column))))));
3062 } else if (function == "GetRowHeaderCells"_L1) {
3063 QSpiObjectReferenceArray headerCells;
3064 const auto headerCellInterfaces = cellInterface->rowHeaderCells();
3065 headerCells.reserve(headerCellInterfaces.size());
3066 for (QAccessibleInterface *cell : headerCellInterfaces) {
3067 const QString childPath = pathForInterface(cell);
3068 const QSpiObjectReference ref(connection, QDBusObjectPath(childPath));
3069 headerCells << ref;
3070 }
3071 connection.send(message.createReply(QVariant::fromValue(headerCells)));
3072 } else if (function == "GetRowSpan"_L1) {
3073 connection.send(message.createReply(QVariant::fromValue(QDBusVariant(
3074 QVariant::fromValue(cellInterface->rowExtent())))));
3075 } else if (function == "GetRowColumnSpan"_L1) {
3076 QVariantList list;
3077 list << cellInterface->rowIndex() << cellInterface->columnIndex() << cellInterface->rowExtent() << cellInterface->columnExtent();
3078 connection.send(message.createReply(list));
3079 } else if (function == "GetTable"_L1) {
3080 QSpiObjectReference ref;
3081 QAccessibleInterface* table = cellInterface->table();
3082 if (table && table->tableInterface())
3083 ref = QSpiObjectReference(connection, QDBusObjectPath(pathForInterface(table)));
3084 connection.send(message.createReply(QVariant::fromValue(QDBusVariant(QVariant::fromValue(ref)))));
3085 } else {
3086 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::tableCellInterface does not implement" << function << message.path();
3087 return false;
3088 }
3089
3090 return true;
3091}
3092
3093QT_END_NAMESPACE
3094
3095#include "moc_atspiadaptor_p.cpp"
3096#endif // QT_CONFIG(accessibility)