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.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 static const QLatin1StringView 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 );
186
187 static const QLatin1StringView 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 );
212
213 static const QLatin1StringView 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 );
227
228 static const QLatin1StringView 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 );
270
271 static const QLatin1StringView 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 );
333
334 static const QLatin1StringView 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 );
366
367 static const QLatin1StringView 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 );
399
400 static const QLatin1StringView 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 );
507
508 static const QLatin1StringView 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 );
535
536 static const QLatin1StringView 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 );
674
675 static const QLatin1StringView 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 );
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 }
1301 }
1302 break;
1303 }
1304 case QAccessible::TableModelChanged: {
1305 QAccessibleInterface *interface = event->accessibleInterface();
1306 if (!interface || !interface->isValid()) {
1307 qCWarning(lcAccessibilityAtspi) << "TableModelChanged event from invalid accessible.";
1308 return;
1309 }
1310
1311 const QString path = pathForInterface(interface);
1312 QAccessibleTableModelChangeEvent *tableModelEvent = static_cast<QAccessibleTableModelChangeEvent*>(event);
1313 switch (tableModelEvent->modelChangeType()) {
1314 case QAccessibleTableModelChangeEvent::ColumnsInserted: {
1315 if (sendObject || sendObject_column_inserted) {
1316 const int firstColumn = tableModelEvent->firstColumn();
1317 const int insertedColumnCount = tableModelEvent->lastColumn() - firstColumn + 1;
1318 QVariantList args = packDBusSignalArguments(QString(), firstColumn, insertedColumnCount, QVariant::fromValue(QDBusVariant(QVariant(QString()))));
1319 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "ColumnInserted"_L1, args);
1320 }
1321 break;
1322 }
1323 case QAccessibleTableModelChangeEvent::ColumnsRemoved: {
1324 if (sendObject || sendObject_column_deleted) {
1325 const int firstColumn = tableModelEvent->firstColumn();
1326 const int removedColumnCount = tableModelEvent->lastColumn() - firstColumn + 1;
1327 QVariantList args = packDBusSignalArguments(QString(), firstColumn, removedColumnCount, QVariant::fromValue(QDBusVariant(QVariant(QString()))));
1328 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "ColumnDeleted"_L1, args);
1329 }
1330 break;
1331 }
1332 case QAccessibleTableModelChangeEvent::RowsInserted: {
1333 if (sendObject || sendObject_row_inserted) {
1334 const int firstRow = tableModelEvent->firstRow();
1335 const int insertedRowCount = tableModelEvent->lastRow() - firstRow + 1;
1336 QVariantList args = packDBusSignalArguments(QString(), firstRow, insertedRowCount, QVariant::fromValue(QDBusVariant(QVariant(QString()))));
1337 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "RowInserted"_L1, args);
1338 }
1339 break;
1340 }
1341 case QAccessibleTableModelChangeEvent::RowsRemoved: {
1342 if (sendObject || sendObject_row_deleted) {
1343 const int firstRow = tableModelEvent->firstRow();
1344 const int removedRowCount = tableModelEvent->lastRow() - firstRow + 1;
1345 QVariantList args = packDBusSignalArguments(QString(), firstRow, removedRowCount, QVariant::fromValue(QDBusVariant(QVariant(QString()))));
1346 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "RowDeleted"_L1, args);
1347 }
1348 break;
1349 }
1350 case QAccessibleTableModelChangeEvent::ModelChangeType::ModelReset: {
1351 if (sendObject || sendObject_model_changed) {
1352 QVariantList args = packDBusSignalArguments(QString(), 0, 0, QVariant::fromValue(QDBusVariant(QVariant(QString()))));
1353 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "ModelChanged"_L1, args);
1354 }
1355 break;
1356 }
1357 case QAccessibleTableModelChangeEvent::DataChanged: {
1358 if (sendObject || sendObject_visible_data_changed) {
1359 QVariantList args = packDBusSignalArguments(QString(), 0, 0, QVariant::fromValue(QDBusVariant(QVariant(QString()))));
1360 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "VisibleDataChanged"_L1, args);
1361 }
1362 break;
1363 }
1364 }
1365 break;
1366 }
1367
1368 // For now we ignore these events
1369 case QAccessible::ParentChanged:
1370 case QAccessible::DialogStart:
1371 case QAccessible::DialogEnd:
1372 case QAccessible::PopupMenuStart:
1373 case QAccessible::PopupMenuEnd:
1374 case QAccessible::SoundPlayed:
1375 case QAccessible::Alert:
1376 case QAccessible::ForegroundChanged:
1377 case QAccessible::MenuStart:
1378 case QAccessible::MenuEnd:
1379 case QAccessible::ContextHelpStart:
1380 case QAccessible::ContextHelpEnd:
1381 case QAccessible::DragDropStart:
1382 case QAccessible::DragDropEnd:
1383 case QAccessible::ScrollingStart:
1384 case QAccessible::ScrollingEnd:
1385 case QAccessible::MenuCommand:
1386 case QAccessible::ActionChanged:
1387 case QAccessible::ActiveDescendantChanged:
1388 case QAccessible::AttributeChanged:
1389 case QAccessible::DocumentContentChanged:
1390 case QAccessible::DocumentLoadComplete:
1391 case QAccessible::DocumentLoadStopped:
1392 case QAccessible::DocumentReload:
1393 case QAccessible::HyperlinkEndIndexChanged:
1394 case QAccessible::HyperlinkNumberOfAnchorsChanged:
1395 case QAccessible::HyperlinkSelectedLinkChanged:
1396 case QAccessible::HypertextLinkActivated:
1397 case QAccessible::HypertextLinkSelected:
1398 case QAccessible::HyperlinkStartIndexChanged:
1399 case QAccessible::HypertextChanged:
1400 case QAccessible::HypertextNLinksChanged:
1401 case QAccessible::ObjectAttributeChanged:
1402 case QAccessible::PageChanged:
1403 case QAccessible::SectionChanged:
1404 case QAccessible::TableCaptionChanged:
1405 case QAccessible::TableColumnDescriptionChanged:
1406 case QAccessible::TableColumnHeaderChanged:
1407 case QAccessible::TableRowDescriptionChanged:
1408 case QAccessible::TableRowHeaderChanged:
1409 case QAccessible::TableSummaryChanged:
1410 case QAccessible::TextAttributeChanged:
1411 case QAccessible::TextColumnChanged:
1412 case QAccessible::VisibleDataChanged:
1413 case QAccessible::LocationChanged:
1414 case QAccessible::HelpChanged:
1415 case QAccessible::DefaultActionChanged:
1416 case QAccessible::AcceleratorChanged:
1417 case QAccessible::IdentifierChanged:
1418 case QAccessible::InvalidEvent:
1419 break;
1420 }
1421}
1422
1423void AtSpiAdaptor::sendFocusChanged(QAccessibleInterface *interface) const
1424{
1425 static QString lastFocusPath;
1426 // "remove" old focus
1427 if (!lastFocusPath.isEmpty()) {
1428 QVariantList stateArgs = packDBusSignalArguments("focused"_L1, 0, 0, variantForPath(lastFocusPath));
1429 sendDBusSignal(lastFocusPath, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1,
1430 "StateChanged"_L1, stateArgs);
1431 }
1432 // send new focus
1433 {
1434 QString path = pathForInterface(interface);
1435
1436 QVariantList stateArgs = packDBusSignalArguments("focused"_L1, 1, 0, variantForPath(path));
1437 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1,
1438 "StateChanged"_L1, stateArgs);
1439
1440 QVariantList focusArgs = packDBusSignalArguments(QString(), 0, 0, variantForPath(path));
1441 sendDBusSignal(path, ATSPI_DBUS_INTERFACE_EVENT_FOCUS ""_L1, "Focus"_L1, focusArgs);
1442 lastFocusPath = path;
1443 }
1444}
1445
1446void AtSpiAdaptor::childrenChanged(QAccessibleInterface *interface) const
1447{
1448 QString parentPath = pathForInterface(interface);
1449 const int childCount = interface->childCount();
1450 for (int i = 0; i < childCount; ++i) {
1451 QString childPath = pathForInterface(interface->child(i));
1452 QVariantList args = packDBusSignalArguments("add"_L1, i, 0, childPath);
1453 sendDBusSignal(parentPath, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "ChildrenChanged"_L1, args);
1454 }
1455}
1456
1457void AtSpiAdaptor::notifyAboutCreation(QAccessibleInterface *interface) const
1458{
1459 // notify about the new child of our parent
1460 QAccessibleInterface * parent = interface->parent();
1461 if (!parent) {
1462 qCDebug(lcAccessibilityAtspi) << "AtSpiAdaptor::notifyAboutCreation: Could not find parent for " << interface->object();
1463 return;
1464 }
1465 QString path = pathForInterface(interface);
1466 const int childIndex = parent->indexOfChild(interface);
1467 QString parentPath = pathForInterface(parent);
1468 QVariantList args = packDBusSignalArguments("add"_L1, childIndex, 0, variantForPath(path));
1469 sendDBusSignal(parentPath, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "ChildrenChanged"_L1, args);
1470}
1471
1472void AtSpiAdaptor::notifyAboutDestruction(QAccessibleInterface *interface) const
1473{
1474 if (!interface || !interface->isValid())
1475 return;
1476
1477 QAccessibleInterface * parent = interface->parent();
1478 if (!parent) {
1479 qCDebug(lcAccessibilityAtspi) << "AtSpiAdaptor::notifyAboutDestruction: Could not find parent for " << interface->object();
1480 return;
1481 }
1482 QString path = pathForInterface(interface);
1483
1484 // this is in the destructor. we have no clue which child we used to be.
1485 // FIXME
1486 int childIndex = -1;
1487 // if (child) {
1488 // childIndex = child;
1489 // } else {
1490 // childIndex = parent->indexOfChild(interface);
1491 // }
1492
1493 QString parentPath = pathForInterface(parent);
1494 QVariantList args = packDBusSignalArguments("remove"_L1, childIndex, 0, variantForPath(path));
1495 sendDBusSignal(parentPath, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "ChildrenChanged"_L1, args);
1496}
1497
1498/*!
1499 Handle incoming DBus message.
1500 This function dispatches the dbus message to the right interface handler.
1501 */
1502bool AtSpiAdaptor::handleMessage(const QDBusMessage &message, const QDBusConnection &connection)
1503{
1504 // get accessible interface
1505 QAccessibleInterface * accessible = interfaceFromPath(message.path());
1506 if (!accessible) {
1507 qCWarning(lcAccessibilityAtspi) << "Could not find accessible on path:" << message.path();
1508 return false;
1509 }
1510 if (!accessible->isValid()) {
1511 qCWarning(lcAccessibilityAtspi) << "Accessible invalid:" << accessible << message.path();
1512 return false;
1513 }
1514
1515 QString interface = message.interface();
1516 QString function = message.member();
1517
1518 // qCDebug(lcAccessibilityAtspi) << "AtSpiAdaptor::handleMessage: " << interface << function;
1519
1520 if (function == "Introspect"_L1) {
1521 //introspect(message.path());
1522 return false;
1523 }
1524
1525 // handle properties like regular functions
1526 if (interface == "org.freedesktop.DBus.Properties"_L1) {
1527 const auto arguments = message.arguments();
1528 if (arguments.size() > 0) {
1529 interface = arguments.at(0).toString();
1530 if (arguments.size() > 1) // e.g. Get/Set + Name
1531 function = function + arguments.at(1).toString();
1532 }
1533 }
1534
1535 // switch interface to call
1536 if (interface == ATSPI_DBUS_INTERFACE_ACCESSIBLE ""_L1)
1537 return accessibleInterface(accessible, function, message, connection);
1538 if (interface == ATSPI_DBUS_INTERFACE_APPLICATION ""_L1)
1539 return applicationInterface(accessible, function, message, connection);
1540 if (interface == ATSPI_DBUS_INTERFACE_COLLECTION ""_L1)
1541 return collectionInterface(accessible, function, message, connection);
1542 if (interface == ATSPI_DBUS_INTERFACE_COMPONENT ""_L1)
1543 return componentInterface(accessible, function, message, connection);
1544 if (interface == ATSPI_DBUS_INTERFACE_ACTION ""_L1)
1545 return actionInterface(accessible, function, message, connection);
1546 if (interface == ATSPI_DBUS_INTERFACE_SELECTION ""_L1)
1547 return selectionInterface(accessible, function, message, connection);
1548 if (interface == ATSPI_DBUS_INTERFACE_TEXT ""_L1)
1549 return textInterface(accessible, function, message, connection);
1550 if (interface == ATSPI_DBUS_INTERFACE_EDITABLE_TEXT ""_L1)
1551 return editableTextInterface(accessible, function, message, connection);
1552 if (interface == ATSPI_DBUS_INTERFACE_VALUE ""_L1)
1553 return valueInterface(accessible, function, message, connection);
1554 if (interface == ATSPI_DBUS_INTERFACE_TABLE ""_L1)
1555 return tableInterface(accessible, function, message, connection);
1556 if (interface == ATSPI_DBUS_INTERFACE_TABLE_CELL ""_L1)
1557 return tableCellInterface(accessible, function, message, connection);
1558
1559 qCDebug(lcAccessibilityAtspi) << "AtSpiAdaptor::handleMessage with unknown interface: " << message.path() << interface << function;
1560 return false;
1561}
1562
1563// Application
1564bool AtSpiAdaptor::applicationInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection)
1565{
1566 if (message.path() != ATSPI_DBUS_PATH_ROOT ""_L1) {
1567 qCWarning(lcAccessibilityAtspi) << "Could not find application interface for:" << message.path() << interface;
1568 return false;
1569 }
1570
1571 if (function == "SetId"_L1) {
1572 Q_ASSERT(message.signature() == "ssv"_L1);
1573 QVariant value = qvariant_cast<QDBusVariant>(message.arguments().at(2)).variant();
1574
1575 m_applicationId = value.toInt();
1576 return true;
1577 }
1578 if (function == "GetId"_L1) {
1579 Q_ASSERT(message.signature() == "ss"_L1);
1580 QDBusMessage reply = message.createReply(QVariant::fromValue(QDBusVariant(m_applicationId)));
1581 return connection.send(reply);
1582 }
1583 if (function == "GetAtspiVersion"_L1) {
1584 Q_ASSERT(message.signature() == "ss"_L1);
1585 // return "2.1" as described in the Application interface spec
1586 QDBusMessage reply = message.createReply(QVariant::fromValue(QDBusVariant("2.1"_L1)));
1587 return connection.send(reply);
1588 }
1589 if (function == "GetToolkitName"_L1) {
1590 Q_ASSERT(message.signature() == "ss"_L1);
1591 QDBusMessage reply = message.createReply(QVariant::fromValue(QDBusVariant("Qt"_L1)));
1592 return connection.send(reply);
1593 }
1594 if (function == "GetVersion"_L1) {
1595 Q_ASSERT(message.signature() == "ss"_L1);
1596 QDBusMessage reply = message.createReply(QVariant::fromValue(QDBusVariant(QLatin1StringView(qVersion()))));
1597 return connection.send(reply);
1598 }
1599 if (function == "GetLocale"_L1) {
1600 Q_ASSERT(message.signature() == "u"_L1);
1601 QDBusMessage reply = message.createReply(QVariant::fromValue(QLocale().name()));
1602 return connection.send(reply);
1603 }
1604 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::applicationInterface does not implement"
1605 << function << message.path();
1606 return false;
1607}
1608
1609/*!
1610 Register this application as accessible on the accessibility DBus.
1611 */
1612void AtSpiAdaptor::registerApplication()
1613{
1614 OrgA11yAtspiSocketInterface registry(ATSPI_DBUS_NAME_REGISTRY ""_L1, ATSPI_DBUS_PATH_ROOT ""_L1,
1615 m_dbus->connection());
1616
1617 QDBusPendingReply<QSpiObjectReference> reply;
1618 QSpiObjectReference ref = QSpiObjectReference(m_dbus->connection(), QDBusObjectPath(ATSPI_DBUS_PATH_ROOT));
1619 reply = registry.Embed(ref);
1620 reply.waitForFinished(); // TODO: make this async
1621 if (reply.isValid ()) {
1622 const QSpiObjectReference &socket = reply.value();
1623 m_accessibilityRegistry = QSpiObjectReference(socket);
1624 } else {
1625 qCWarning(lcAccessibilityAtspi) << "Error in contacting registry:"
1626 << reply.error().name()
1627 << reply.error().message();
1628 }
1629}
1630
1631// Accessible
1632bool AtSpiAdaptor::accessibleInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection)
1633{
1634 if (function == "GetRole"_L1) {
1635 sendReply(connection, message, (uint) getRole(interface));
1636 } else if (function == "GetName"_L1) {
1637 sendReply(connection, message, QVariant::fromValue(QDBusVariant(interface->text(QAccessible::Name))));
1638 } else if (function == "GetRoleName"_L1) {
1639 sendReply(connection, message, QSpiAccessibleBridge::namesForRole(interface->role()).name());
1640 } else if (function == "GetLocalizedRoleName"_L1) {
1641 sendReply(connection, message, QVariant::fromValue(QSpiAccessibleBridge::namesForRole(interface->role()).localizedName()));
1642 } else if (function == "GetChildCount"_L1) {
1643 sendReply(connection, message, QVariant::fromValue(QDBusVariant(interface->childCount())));
1644 } else if (function == "GetIndexInParent"_L1) {
1645 int childIndex = -1;
1646 QAccessibleInterface * parent = interface->parent();
1647 if (parent) {
1648 childIndex = parent->indexOfChild(interface);
1649 if (childIndex < 0) {
1650 qCDebug(lcAccessibilityAtspi) << "GetIndexInParent get invalid index: " << childIndex << interface;
1651 }
1652 }
1653 sendReply(connection, message, childIndex);
1654 } else if (function == "GetParent"_L1) {
1655 QString path;
1656 QAccessibleInterface * parent = interface->parent();
1657 if (!parent) {
1658 if (interface->object() == qApp) {
1659 sendReply(connection, message,
1660 QVariant::fromValue(QDBusVariant(QVariant::fromValue(m_accessibilityRegistry))));
1661 return true;
1662 }
1663
1664 path = ATSPI_DBUS_PATH_NULL ""_L1;
1665 } else if (parent->role() == QAccessible::Application) {
1666 path = ATSPI_DBUS_PATH_ROOT ""_L1;
1667 } else {
1668 path = pathForInterface(parent);
1669 }
1670 // Parent is a property, so it needs to be wrapped inside an extra variant.
1671 sendReply(connection, message, QVariant::fromValue(
1672 QDBusVariant(QVariant::fromValue(QSpiObjectReference(connection, QDBusObjectPath(path))))));
1673 } else if (function == "GetChildAtIndex"_L1) {
1674 const int index = message.arguments().at(0).toInt();
1675 if (index < 0) {
1676 sendReply(connection, message, QVariant::fromValue(
1677 QSpiObjectReference(connection, QDBusObjectPath(ATSPI_DBUS_PATH_NULL))));
1678 } else {
1679 QAccessibleInterface * childInterface = interface->child(index);
1680 sendReply(connection, message, QVariant::fromValue(
1681 QSpiObjectReference(connection, QDBusObjectPath(pathForInterface(childInterface)))));
1682 }
1683 } else if (function == "GetInterfaces"_L1) {
1684 sendReply(connection, message, accessibleInterfaces(interface));
1685 } else if (function == "GetDescription"_L1) {
1686 sendReply(connection, message, QVariant::fromValue(QDBusVariant(interface->text(QAccessible::Description))));
1687 } else if (function == "GetHelpText"_L1) {
1688 sendReply(connection, message, QVariant::fromValue(QDBusVariant(interface->text(QAccessible::Help))));
1689 } else if (function == "GetState"_L1) {
1690 quint64 spiState = spiStatesFromQState(interface->state());
1691 if (QAccessibleAttributesInterface *attributesIface = interface->attributesInterface()) {
1692 const QVariant orientationVariant =
1693 attributesIface->attributeValue(QAccessible::Attribute::Orientation);
1694 if (orientationVariant.isValid()) {
1695 Q_ASSERT(orientationVariant.canConvert<Qt::Orientation>());
1696 const Qt::Orientation orientation = orientationVariant.value<Qt::Orientation>();
1697 setSpiStateBit(&spiState,
1698 orientation == Qt::Horizontal ? ATSPI_STATE_HORIZONTAL
1699 : ATSPI_STATE_VERTICAL);
1700 }
1701 }
1702 if (interface->tableInterface()) {
1703 // For tables, setting manages_descendants should
1704 // indicate to the client that it cannot cache these
1705 // interfaces.
1706 setSpiStateBit(&spiState, ATSPI_STATE_MANAGES_DESCENDANTS);
1707 }
1708 QAccessible::Role role = interface->role();
1709 if (role == QAccessible::TreeItem ||
1710 role == QAccessible::ListItem) {
1711 /* Transient means libatspi2 will not cache items.
1712 This is important because when adding/removing an item
1713 the cache becomes outdated and we don't change the paths of
1714 items in lists/trees/tables. */
1715 setSpiStateBit(&spiState, ATSPI_STATE_TRANSIENT);
1716 }
1717 sendReply(connection, message,
1718 QVariant::fromValue(spiStateSetFromSpiStates(spiState)));
1719 } else if (function == "GetAttributes"_L1) {
1720 sendReply(connection, message, QVariant::fromValue(getAttributes(interface)));
1721 } else if (function == "GetRelationSet"_L1) {
1722 sendReply(connection, message, QVariant::fromValue(relationSet(interface, connection)));
1723 } else if (function == "GetApplication"_L1) {
1724 sendReply(connection, message, QVariant::fromValue(
1725 QSpiObjectReference(connection, QDBusObjectPath(ATSPI_DBUS_PATH_ROOT))));
1726 } else if (function == "GetLocale"_L1) {
1727 QLocale locale;
1728 if (QAccessibleAttributesInterface *attributesIface = interface->attributesInterface()) {
1729 const QVariant localeVariant = attributesIface->attributeValue(QAccessible::Attribute::Locale);
1730 if (localeVariant.isValid()) {
1731 Q_ASSERT(localeVariant.canConvert<QLocale>());
1732 locale = localeVariant.toLocale();
1733 }
1734 }
1735 sendReply(connection, message, QVariant::fromValue(QDBusVariant(locale.name())));
1736 } else if (function == "GetChildren"_L1) {
1737 QSpiObjectReferenceArray children;
1738 const int numChildren = interface->childCount();
1739 children.reserve(numChildren);
1740 for (int i = 0; i < numChildren; ++i) {
1741 QString childPath = pathForInterface(interface->child(i));
1742 QSpiObjectReference ref(connection, QDBusObjectPath(childPath));
1743 children << ref;
1744 }
1745 connection.send(message.createReply(QVariant::fromValue(children)));
1746 } else if (function == "GetAccessibleId"_L1) {
1747 sendReply(connection, message,
1748 QVariant::fromValue(QDBusVariant(QAccessibleBridgeUtils::accessibleId(interface))));
1749 } else {
1750 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::accessibleInterface does not implement" << function << message.path();
1751 return false;
1752 }
1753 return true;
1754}
1755
1756AtspiRole AtSpiAdaptor::getRole(QAccessibleInterface *interface)
1757{
1758 if ((interface->role() == QAccessible::EditableText) && interface->state().passwordEdit)
1759 return ATSPI_ROLE_PASSWORD_TEXT;
1760 return QSpiAccessibleBridge::namesForRole(interface->role()).spiRole();
1761}
1762
1763QStringList AtSpiAdaptor::accessibleInterfaces(QAccessibleInterface *interface)
1764{
1765 QStringList ifaces;
1766 qCDebug(lcAccessibilityAtspiCreation) << "AtSpiAdaptor::accessibleInterfaces create: " << interface->object();
1767 ifaces << u"" ATSPI_DBUS_INTERFACE_ACCESSIBLE ""_s;
1768
1769 ifaces << u"" ATSPI_DBUS_INTERFACE_COLLECTION ""_s;
1770
1771 if ( (!interface->rect().isEmpty()) ||
1772 (interface->object() && interface->object()->isWidgetType()) ||
1773 (interface->role() == QAccessible::ListItem) ||
1774 (interface->role() == QAccessible::Cell) ||
1775 (interface->role() == QAccessible::TreeItem) ||
1776 (interface->role() == QAccessible::Row) ||
1777 (interface->object() && interface->object()->inherits("QSGItem"))
1778 ) {
1779 ifaces << u"" ATSPI_DBUS_INTERFACE_COMPONENT ""_s;
1780 } else {
1781 qCDebug(lcAccessibilityAtspiCreation) << " IS NOT a component";
1782 }
1783 if (interface->role() == QAccessible::Application)
1784 ifaces << u"" ATSPI_DBUS_INTERFACE_APPLICATION ""_s;
1785
1786 if (interface->actionInterface() || interface->valueInterface())
1787 ifaces << u"" ATSPI_DBUS_INTERFACE_ACTION ""_s;
1788
1789 if (interface->selectionInterface())
1790 ifaces << ATSPI_DBUS_INTERFACE_SELECTION ""_L1;
1791
1792 if (interface->textInterface())
1793 ifaces << u"" ATSPI_DBUS_INTERFACE_TEXT ""_s;
1794
1795 if (interface->editableTextInterface())
1796 ifaces << u"" ATSPI_DBUS_INTERFACE_EDITABLE_TEXT ""_s;
1797
1798 if (interface->valueInterface())
1799 ifaces << u"" ATSPI_DBUS_INTERFACE_VALUE ""_s;
1800
1801 if (interface->tableInterface())
1802 ifaces << u"" ATSPI_DBUS_INTERFACE_TABLE ""_s;
1803
1804 if (interface->tableCellInterface())
1805 ifaces << u"" ATSPI_DBUS_INTERFACE_TABLE_CELL ""_s;
1806
1807 return ifaces;
1808}
1809
1810QSpiRelationArray AtSpiAdaptor::relationSet(QAccessibleInterface *interface,
1811 const QDBusConnection &connection)
1812{
1813 typedef std::pair<QAccessibleInterface*, QAccessible::Relation> RelationPair;
1814 const QList<RelationPair> relationInterfaces = interface->relations();
1815
1816 QSpiRelationArray relations;
1817 for (const RelationPair &pair : relationInterfaces) {
1818// FIXME: this loop seems a bit strange... "related" always have one item when we check.
1819//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
1820 QSpiObjectReferenceArray related;
1821
1822 QDBusObjectPath path = QDBusObjectPath(pathForInterface(pair.first));
1823 related.append(QSpiObjectReference(connection, path));
1824
1825 if (!related.isEmpty())
1826 relations.append(QSpiRelationArrayEntry(qAccessibleRelationToAtSpiRelation(pair.second), related));
1827 }
1828 return relations;
1829}
1830
1831void AtSpiAdaptor::sendReply(const QDBusConnection &connection, const QDBusMessage &message, const QVariant &argument) const
1832{
1833 QDBusMessage reply = message.createReply(argument);
1834 connection.send(reply);
1835}
1836
1837QString AtSpiAdaptor::pathForObject(QObject *object)
1838{
1839 Q_ASSERT(object);
1840
1841 if (inheritsQAction(object)) {
1842 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::pathForObject: Creating path with QAction as object.";
1843 }
1844
1845 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(object);
1846 return pathForInterface(iface);
1847}
1848
1849QString AtSpiAdaptor::pathForInterface(QAccessibleInterface *interface)
1850{
1851 if (!interface || !interface->isValid())
1852 return u"" ATSPI_DBUS_PATH_NULL ""_s;
1853 if (interface->role() == QAccessible::Application)
1854 return u"" ATSPI_DBUS_PATH_ROOT ""_s;
1855
1856 QAccessible::Id id = QAccessible::uniqueId(interface);
1857 Q_ASSERT((int)id < 0);
1858 return QSPI_OBJECT_PATH_PREFIX ""_L1 + QString::number(id);
1859}
1860
1861bool AtSpiAdaptor::inheritsQAction(QObject *object)
1862{
1863 const QMetaObject *mo = object->metaObject();
1864 while (mo) {
1865 const QLatin1StringView cn(mo->className());
1866 if (cn == "QAction"_L1)
1867 return true;
1868 mo = mo->superClass();
1869 }
1870 return false;
1871}
1872
1873// Component
1874static QAccessibleInterface * getWindow(QAccessibleInterface * interface)
1875{
1876 // find top-level window in a11y hierarchy (either has a
1877 // corresponding role or is a direct child of the application object)
1878 QAccessibleInterface* app = QAccessible::queryAccessibleInterface(qApp);
1879 while (interface && interface->role() != QAccessible::Dialog
1880 && interface->role() != QAccessible::Window && interface->parent() != app)
1881 interface = interface->parent();
1882
1883 return interface;
1884}
1885
1886void AtSpiAdaptor::addMatchingDescendants(QList<QAccessibleInterface *> &matches,
1887 QAccessibleInterface *accessible,
1888 const QSpiMatchRuleMatcher &matcher, bool invert,
1889 int count, bool traverse)
1890{
1891 if (!accessible || (count != 0 && matches.size() >= count))
1892 return;
1893
1894 const int childCount = accessible->childCount();
1895 for (int i = 0; i < childCount; ++i) {
1896 if (QAccessibleInterface *child = accessible->child(i)) {
1897 if (matcher.match(*child) != invert)
1898 matches.append(child);
1899
1900 if (traverse)
1901 addMatchingDescendants(matches, child, matcher, invert, count, traverse);
1902
1903 if (count != 0 && matches.size() >= count)
1904 return;
1905 }
1906 }
1907}
1908
1909bool AtSpiAdaptor::collectionInterface(QAccessibleInterface *interface, const QString &function,
1910 const QDBusMessage &message,
1911 const QDBusConnection &connection)
1912{
1913 if (function == "GetMatches"_L1) {
1914 if (message.signature() != u"(aiia{ss}iaiiasib)uib") {
1915 qCWarning(lcAccessibilityAtspi)
1916 << "AtSpiAdaptor::collectionInterface: Invalid signature for " << function
1917 << ": " << message.path();
1918 return false;
1919 }
1920
1921 const QSpiMatchRule matchRule = qdbus_cast<QSpiMatchRule>(message.arguments().at(0));
1922 const int count = message.arguments().at(2).toInt();
1923 const bool traverse = message.arguments().at(3).toBool();
1924
1925 QList<QAccessibleInterface *> matchedAccessibles;
1926 addMatchingDescendants(matchedAccessibles, interface, QSpiMatchRuleMatcher(matchRule),
1927 matchRule.invert, count, traverse);
1928
1929 QSpiObjectReferenceArray result;
1930 result.reserve(matchedAccessibles.size());
1931 for (QAccessibleInterface *iface : std::as_const(matchedAccessibles)) {
1932 QSpiObjectReference ref(connection, QDBusObjectPath(pathForInterface(iface)));
1933 result << ref;
1934 }
1935 connection.send(message.createReply(QVariant::fromValue(result)));
1936 return true;
1937 }
1938
1939 qCWarning(lcAccessibilityAtspi)
1940 << "AtSpiAdaptor::collectionInterface does not implement" << function << message.path();
1941 return false;
1942}
1943
1944bool AtSpiAdaptor::componentInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection)
1945{
1946 if (function == "Contains"_L1) {
1947 bool ret = false;
1948 int x = message.arguments().at(0).toInt();
1949 int y = message.arguments().at(1).toInt();
1950 uint coordType = message.arguments().at(2).toUInt();
1951 if (!isValidCoordType(coordType))
1952 return false;
1953 ret = getExtents(interface, coordType).contains(x, y);
1954 sendReply(connection, message, ret);
1955 } else if (function == "GetAccessibleAtPoint"_L1) {
1956 QPoint point(message.arguments().at(0).toInt(), message.arguments().at(1).toInt());
1957 uint coordType = message.arguments().at(2).toUInt();
1958 if (!isValidCoordType(coordType))
1959 return false;
1960 QPoint screenPos = translateToScreenCoordinates(interface, point, coordType);
1961
1962 QAccessibleInterface * childInterface(interface->childAt(screenPos.x(), screenPos.y()));
1963 QAccessibleInterface * iface = nullptr;
1964 while (childInterface) {
1965 iface = childInterface;
1966 childInterface = iface->childAt(screenPos.x(), screenPos.y());
1967 }
1968 if (iface) {
1969 QString path = pathForInterface(iface);
1970 sendReply(connection, message, QVariant::fromValue(
1971 QSpiObjectReference(connection, QDBusObjectPath(path))));
1972 } else {
1973 sendReply(connection, message, QVariant::fromValue(
1974 QSpiObjectReference(connection, QDBusObjectPath(ATSPI_DBUS_PATH_NULL))));
1975 }
1976 } else if (function == "GetAlpha"_L1) {
1977 sendReply(connection, message, (double) 1.0);
1978 } else if (function == "GetExtents"_L1) {
1979 uint coordType = message.arguments().at(0).toUInt();
1980 if (!isValidCoordType(coordType))
1981 return false;
1982 sendReply(connection, message, QVariant::fromValue(getExtents(interface, coordType)));
1983 } else if (function == "GetLayer"_L1) {
1984 sendReply(connection, message, QVariant::fromValue((uint)1));
1985 } else if (function == "GetMDIZOrder"_L1) {
1986 sendReply(connection, message, QVariant::fromValue((short)0));
1987 } else if (function == "GetPosition"_L1) {
1988 uint coordType = message.arguments().at(0).toUInt();
1989 if (!isValidCoordType(coordType))
1990 return false;
1991 QRect rect = getExtents(interface, coordType);
1992 QVariantList pos;
1993 pos << rect.x() << rect.y();
1994 connection.send(message.createReply(pos));
1995 } else if (function == "GetSize"_L1) {
1996 QRect rect = interface->rect();
1997 QVariantList size;
1998 size << rect.width() << rect.height();
1999 connection.send(message.createReply(size));
2000 } else if (function == "GrabFocus"_L1) {
2001 QAccessibleActionInterface *actionIface = interface->actionInterface();
2002 if (actionIface && actionIface->actionNames().contains(QAccessibleActionInterface::setFocusAction())) {
2003 actionIface->doAction(QAccessibleActionInterface::setFocusAction());
2004 sendReply(connection, message, true);
2005 } else {
2006 sendReply(connection, message, false);
2007 }
2008 } else if (function == "SetExtents"_L1) {
2009// int x = message.arguments().at(0).toInt();
2010// int y = message.arguments().at(1).toInt();
2011// int width = message.arguments().at(2).toInt();
2012// int height = message.arguments().at(3).toInt();
2013// uint coordinateType = message.arguments().at(4).toUInt();
2014 qCDebug(lcAccessibilityAtspi) << "SetExtents is not implemented.";
2015 sendReply(connection, message, false);
2016 } else if (function == "SetPosition"_L1) {
2017// int x = message.arguments().at(0).toInt();
2018// int y = message.arguments().at(1).toInt();
2019// uint coordinateType = message.arguments().at(2).toUInt();
2020 qCDebug(lcAccessibilityAtspi) << "SetPosition is not implemented.";
2021 sendReply(connection, message, false);
2022 } else if (function == "SetSize"_L1) {
2023// int width = message.arguments().at(0).toInt();
2024// int height = message.arguments().at(1).toInt();
2025 qCDebug(lcAccessibilityAtspi) << "SetSize is not implemented.";
2026 sendReply(connection, message, false);
2027 } else {
2028 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::componentInterface does not implement" << function << message.path();
2029 return false;
2030 }
2031 return true;
2032}
2033
2034QRect AtSpiAdaptor::getExtents(QAccessibleInterface *interface, uint coordType)
2035{
2036 return translateFromScreenCoordinates(interface, interface->rect(), coordType);
2037}
2038
2039// Action interface
2040bool AtSpiAdaptor::actionInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection)
2041{
2042 if (function == "GetNActions"_L1) {
2043 int count = QAccessibleBridgeUtils::effectiveActionNames(interface).size();
2044 sendReply(connection, message, QVariant::fromValue(QDBusVariant(QVariant::fromValue(count))));
2045 } else if (function == "DoAction"_L1) {
2046 int index = message.arguments().at(0).toInt();
2047 const QStringList actionNames = QAccessibleBridgeUtils::effectiveActionNames(interface);
2048 if (index < 0 || index >= actionNames.size())
2049 return false;
2050 const QString actionName = actionNames.at(index);
2051 bool success = QAccessibleBridgeUtils::performEffectiveAction(interface, actionName);
2052 sendReply(connection, message, success);
2053 } else if (function == "GetActions"_L1) {
2054 sendReply(connection, message, QVariant::fromValue(getActions(interface)));
2055 } else if (function == "GetName"_L1) {
2056 int index = message.arguments().at(0).toInt();
2057 const QStringList actionNames = QAccessibleBridgeUtils::effectiveActionNames(interface);
2058 if (index < 0 || index >= actionNames.size())
2059 return false;
2060 sendReply(connection, message, actionNames.at(index));
2061 } else if (function == "GetDescription"_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 QString description;
2067 if (QAccessibleActionInterface *actionIface = interface->actionInterface())
2068 description = actionIface->localizedActionDescription(actionNames.at(index));
2069 else
2070 description = qAccessibleLocalizedActionDescription(actionNames.at(index));
2071 sendReply(connection, message, description);
2072 } else if (function == "GetKeyBinding"_L1) {
2073 int index = message.arguments().at(0).toInt();
2074 const QStringList actionNames = QAccessibleBridgeUtils::effectiveActionNames(interface);
2075 if (index < 0 || index >= actionNames.size())
2076 return false;
2077 QStringList keyBindings;
2078 if (QAccessibleActionInterface *actionIface = interface->actionInterface())
2079 keyBindings = actionIface->keyBindingsForAction(actionNames.at(index));
2080 if (keyBindings.isEmpty()) {
2081 QString acc = interface->text(QAccessible::Accelerator);
2082 if (!acc.isEmpty())
2083 keyBindings.append(acc);
2084 }
2085 if (keyBindings.size() > 0)
2086 sendReply(connection, message, keyBindings.join(u';'));
2087 else
2088 sendReply(connection, message, QString());
2089 } else {
2090 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::actionInterface does not implement" << function << message.path();
2091 return false;
2092 }
2093 return true;
2094}
2095
2096QSpiActionArray AtSpiAdaptor::getActions(QAccessibleInterface *interface) const
2097{
2098 QAccessibleActionInterface *actionInterface = interface->actionInterface();
2099 QSpiActionArray actions;
2100 const QStringList actionNames = QAccessibleBridgeUtils::effectiveActionNames(interface);
2101 actions.reserve(actionNames.size());
2102 for (const QString &actionName : actionNames) {
2103 QSpiAction action;
2104
2105 action.name = actionName;
2106 if (actionInterface) {
2107 action.description = actionInterface->localizedActionDescription(actionName);
2108 const QStringList keyBindings = actionInterface->keyBindingsForAction(actionName);
2109 if (!keyBindings.isEmpty())
2110 action.keyBinding = keyBindings.front();
2111 } else {
2112 action.description = qAccessibleLocalizedActionDescription(actionName);
2113 }
2114
2115 actions.append(std::move(action));
2116 }
2117 return actions;
2118}
2119
2120// Text interface
2121bool AtSpiAdaptor::textInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection)
2122{
2123 if (!interface->textInterface())
2124 return false;
2125
2126 // properties
2127 if (function == "GetCaretOffset"_L1) {
2128 sendReply(connection, message, QVariant::fromValue(QDBusVariant(QVariant::fromValue(interface->textInterface()->cursorPosition()))));
2129 } else if (function == "GetCharacterCount"_L1) {
2130 sendReply(connection, message, QVariant::fromValue(QDBusVariant(QVariant::fromValue(interface->textInterface()->characterCount()))));
2131
2132 // functions
2133 } else if (function == "AddSelection"_L1) {
2134 int startOffset = message.arguments().at(0).toInt();
2135 int endOffset = message.arguments().at(1).toInt();
2136 int lastSelection = interface->textInterface()->selectionCount();
2137 interface->textInterface()->setSelection(lastSelection, startOffset, endOffset);
2138 sendReply(connection, message, (interface->textInterface()->selectionCount() > lastSelection));
2139 } else if (function == "GetAttributeRun"_L1) {
2140 int offset = message.arguments().at(0).toInt();
2141 bool includeDefaults = message.arguments().at(1).toBool();
2142 Q_UNUSED(includeDefaults);
2143 connection.send(message.createReply(getAttributes(interface, offset, includeDefaults)));
2144 } else if (function == "GetAttributeValue"_L1) {
2145 int offset = message.arguments().at(0).toInt();
2146 QString attributeName = message.arguments().at(1).toString();
2147 connection.send(message.createReply(QVariant(getAttributeValue(interface, offset, attributeName))));
2148 } else if (function == "GetAttributes"_L1) {
2149 int offset = message.arguments().at(0).toInt();
2150 connection.send(message.createReply(getAttributes(interface, offset, true)));
2151 } else if (function == "GetBoundedRanges"_L1) {
2152 int x = message.arguments().at(0).toInt();
2153 int y = message.arguments().at(1).toInt();
2154 int width = message.arguments().at(2).toInt();
2155 int height = message.arguments().at(3).toInt();
2156 uint coordType = message.arguments().at(4).toUInt();
2157 uint xClipType = message.arguments().at(5).toUInt();
2158 uint yClipType = message.arguments().at(6).toUInt();
2159 Q_UNUSED(x);
2160 Q_UNUSED(y);
2161 Q_UNUSED(width);
2162 Q_UNUSED(height);
2163 Q_UNUSED(coordType);
2164 Q_UNUSED(xClipType);
2165 Q_UNUSED(yClipType);
2166 qCDebug(lcAccessibilityAtspi) << "Not implemented: QSpiAdaptor::GetBoundedRanges";
2167 sendReply(connection, message, QVariant::fromValue(QSpiTextRangeList()));
2168 } else if (function == "GetCharacterAtOffset"_L1) {
2169 int offset = message.arguments().at(0).toInt();
2170 int start;
2171 int end;
2172 const QString charString = interface->textInterface()
2173 ->textAtOffset(offset, QAccessible::CharBoundary, &start, &end);
2174 int codePoint = 0;
2175 QStringIterator stringIt(charString);
2176 if (stringIt.hasNext())
2177 codePoint = static_cast<int>(stringIt.peekNext());
2178 sendReply(connection, message, codePoint);
2179 } else if (function == "GetCharacterExtents"_L1) {
2180 int offset = message.arguments().at(0).toInt();
2181 int coordType = message.arguments().at(1).toUInt();
2182 connection.send(message.createReply(getCharacterExtents(interface, offset, coordType)));
2183 } else if (function == "GetDefaultAttributeSet"_L1 || function == "GetDefaultAttributes"_L1) {
2184 // GetDefaultAttributes is deprecated in favour of GetDefaultAttributeSet.
2185 // Empty set seems reasonable. There is no default attribute set.
2186 sendReply(connection, message, QVariant::fromValue(QSpiAttributeSet()));
2187 } else if (function == "GetNSelections"_L1) {
2188 sendReply(connection, message, interface->textInterface()->selectionCount());
2189 } else if (function == "GetOffsetAtPoint"_L1) {
2190 qCDebug(lcAccessibilityAtspi) << message.signature();
2191 Q_ASSERT(!message.signature().isEmpty());
2192 QPoint point(message.arguments().at(0).toInt(), message.arguments().at(1).toInt());
2193 uint coordType = message.arguments().at(2).toUInt();
2194 if (!isValidCoordType(coordType))
2195 return false;
2196 QPoint screenPos = translateToScreenCoordinates(interface, point, coordType);
2197 int offset = interface->textInterface()->offsetAtPoint(screenPos);
2198 sendReply(connection, message, offset);
2199 } else if (function == "GetRangeExtents"_L1) {
2200 int startOffset = message.arguments().at(0).toInt();
2201 int endOffset = message.arguments().at(1).toInt();
2202 uint coordType = message.arguments().at(2).toUInt();
2203 connection.send(message.createReply(getRangeExtents(interface, startOffset, endOffset, coordType)));
2204 } else if (function == "GetSelection"_L1) {
2205 int selectionNum = message.arguments().at(0).toInt();
2206 int start, end;
2207 interface->textInterface()->selection(selectionNum, &start, &end);
2208 if (start < 0)
2209 start = end = interface->textInterface()->cursorPosition();
2210 QVariantList sel;
2211 sel << start << end;
2212 connection.send(message.createReply(sel));
2213 } else if (function == "GetStringAtOffset"_L1) {
2214 int offset = message.arguments().at(0).toInt();
2215 uint granularity = message.arguments().at(1).toUInt();
2216 if (!isValidAtspiTextGranularity(granularity))
2217 return false;
2218 int startOffset, endOffset;
2219 QString text = interface->textInterface()->textAtOffset(offset, qAccessibleBoundaryTypeFromAtspiTextGranularity(granularity), &startOffset, &endOffset);
2220 QVariantList ret;
2221 ret << text << startOffset << endOffset;
2222 connection.send(message.createReply(ret));
2223 } else if (function == "GetText"_L1) {
2224 int startOffset = message.arguments().at(0).toInt();
2225 int endOffset = message.arguments().at(1).toInt();
2226 if (endOffset == -1) // AT-SPI uses -1 to signal all characters
2227 endOffset = interface->textInterface()->characterCount();
2228 sendReply(connection, message, interface->textInterface()->text(startOffset, endOffset));
2229 } else if (function == "GetTextAfterOffset"_L1) {
2230 int offset = message.arguments().at(0).toInt();
2231 int type = message.arguments().at(1).toUInt();
2232 int startOffset, endOffset;
2233 QString text = interface->textInterface()->textAfterOffset(offset, qAccessibleBoundaryTypeFromAtspiBoundaryType(type), &startOffset, &endOffset);
2234 QVariantList ret;
2235 ret << text << startOffset << endOffset;
2236 connection.send(message.createReply(ret));
2237 } else if (function == "GetTextAtOffset"_L1) {
2238 int offset = message.arguments().at(0).toInt();
2239 int type = message.arguments().at(1).toUInt();
2240 int startOffset, endOffset;
2241 QString text = interface->textInterface()->textAtOffset(offset, qAccessibleBoundaryTypeFromAtspiBoundaryType(type), &startOffset, &endOffset);
2242 QVariantList ret;
2243 ret << text << startOffset << endOffset;
2244 connection.send(message.createReply(ret));
2245 } else if (function == "GetTextBeforeOffset"_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()->textBeforeOffset(offset, qAccessibleBoundaryTypeFromAtspiBoundaryType(type), &startOffset, &endOffset);
2250 QVariantList ret;
2251 ret << text << startOffset << endOffset;
2252 connection.send(message.createReply(ret));
2253 } else if (function == "RemoveSelection"_L1) {
2254 int selectionNum = message.arguments().at(0).toInt();
2255 interface->textInterface()->removeSelection(selectionNum);
2256 sendReply(connection, message, true);
2257 } else if (function == "SetCaretOffset"_L1) {
2258 int offset = message.arguments().at(0).toInt();
2259 interface->textInterface()->setCursorPosition(offset);
2260 sendReply(connection, message, true);
2261 } else if (function == "ScrollSubstringTo"_L1) {
2262 int startOffset = message.arguments().at(0).toInt();
2263 int endOffset = message.arguments().at(1).toInt();
2264 // ignore third parameter (scroll type), since QAccessibleTextInterface::scrollToSubstring doesn't have that
2265 qCInfo(lcAccessibilityAtspi) << "AtSpiAdaptor::ScrollSubstringTo doesn'take take scroll type into account.";
2266 interface->textInterface()->scrollToSubstring(startOffset, endOffset);
2267 sendReply(connection, message, true);
2268 } else if (function == "SetSelection"_L1) {
2269 int selectionNum = message.arguments().at(0).toInt();
2270 int startOffset = message.arguments().at(1).toInt();
2271 int endOffset = message.arguments().at(2).toInt();
2272 interface->textInterface()->setSelection(selectionNum, startOffset, endOffset);
2273 sendReply(connection, message, true);
2274 } else {
2275 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::textInterface does not implement" << function << message.path();
2276 return false;
2277 }
2278 return true;
2279}
2280
2281QAccessible::TextBoundaryType AtSpiAdaptor::qAccessibleBoundaryTypeFromAtspiBoundaryType(int atspiTextBoundaryType)
2282{
2283 switch (atspiTextBoundaryType) {
2284 case ATSPI_TEXT_BOUNDARY_CHAR:
2285 return QAccessible::CharBoundary;
2286 case ATSPI_TEXT_BOUNDARY_WORD_START:
2287 case ATSPI_TEXT_BOUNDARY_WORD_END:
2288 return QAccessible::WordBoundary;
2289 case ATSPI_TEXT_BOUNDARY_SENTENCE_START:
2290 case ATSPI_TEXT_BOUNDARY_SENTENCE_END:
2291 return QAccessible::SentenceBoundary;
2292 case ATSPI_TEXT_BOUNDARY_LINE_START:
2293 case ATSPI_TEXT_BOUNDARY_LINE_END:
2294 return QAccessible::LineBoundary;
2295 }
2296 Q_ASSERT_X(0, "", "Requested invalid boundary type.");
2297 return QAccessible::CharBoundary;
2298}
2299
2300bool AtSpiAdaptor::isValidAtspiTextGranularity(uint atspiTextGranularity)
2301{
2302 if (atspiTextGranularity == ATSPI_TEXT_GRANULARITY_CHAR
2303 || atspiTextGranularity == ATSPI_TEXT_GRANULARITY_WORD
2304 || atspiTextGranularity == ATSPI_TEXT_GRANULARITY_SENTENCE
2305 || atspiTextGranularity == ATSPI_TEXT_GRANULARITY_LINE
2306 || atspiTextGranularity == ATSPI_TEXT_GRANULARITY_PARAGRAPH)
2307 return true;
2308
2309 qCWarning(lcAccessibilityAtspi) << "Unknown value" << atspiTextGranularity << "for AT-SPI text granularity type";
2310 return false;
2311}
2312
2313QAccessible::TextBoundaryType AtSpiAdaptor::qAccessibleBoundaryTypeFromAtspiTextGranularity(uint atspiTextGranularity)
2314{
2315 Q_ASSERT(isValidAtspiTextGranularity(atspiTextGranularity));
2316
2317 switch (atspiTextGranularity) {
2318 case ATSPI_TEXT_GRANULARITY_CHAR:
2319 return QAccessible::CharBoundary;
2320 case ATSPI_TEXT_GRANULARITY_WORD:
2321 return QAccessible::WordBoundary;
2322 case ATSPI_TEXT_GRANULARITY_SENTENCE:
2323 return QAccessible::SentenceBoundary;
2324 case ATSPI_TEXT_GRANULARITY_LINE:
2325 return QAccessible::LineBoundary;
2326 case ATSPI_TEXT_GRANULARITY_PARAGRAPH:
2327 return QAccessible::ParagraphBoundary;
2328 }
2329 return QAccessible::CharBoundary;
2330}
2331
2332namespace
2333{
2334 struct AtSpiAttribute {
2335 QString name;
2336 QString value;
2337 AtSpiAttribute(const QString &aName, const QString &aValue) : name(aName), value(aValue) {}
2338 bool isNull() const { return name.isNull() || value.isNull(); }
2339 };
2340
2341 QString atspiColor(const QString &ia2Color)
2342 {
2343 // "rgb(%u,%u,%u)" -> "%u,%u,%u"
2344 return ia2Color.mid(4, ia2Color.size() - (4+1)).replace(u"\\,"_s, u","_s);
2345 }
2346
2347 QString atspiSize(const QString &ia2Size)
2348 {
2349 // "%fpt" -> "%f"
2350 return ia2Size.left(ia2Size.size() - 2);
2351 }
2352
2353 AtSpiAttribute atspiTextAttribute(const QString &ia2Name, const QString &ia2Value)
2354 {
2355 QString name = ia2Name;
2356 QString value = ia2Value;
2357
2358 // IAccessible2: https://github.com/LinuxA11y/IAccessible2/blob/master/spec/textattributes.md
2359 // ATK attribute names: https://gitlab.gnome.org/GNOME/orca/-/blob/master/src/orca/text_attribute_names.py
2360 // ATK attribute values: https://gnome.pages.gitlab.gnome.org/atk/AtkText.html#AtkTextAttribute
2361
2362 // https://bugzilla.gnome.org/show_bug.cgi?id=744553 "ATK docs provide no guidance for allowed values of some text attributes"
2363 // specifically for "weight", "invalid", "language" and value range for colors
2364
2365 if (ia2Name == "background-color"_L1) {
2366 name = QStringLiteral("bg-color");
2367 value = atspiColor(value);
2368 } else if (ia2Name == "font-family"_L1) {
2369 name = QStringLiteral("family-name");
2370 } else if (ia2Name == "color"_L1) {
2371 name = QStringLiteral("fg-color");
2372 value = atspiColor(value);
2373 } else if (ia2Name == "text-align"_L1) {
2374 name = QStringLiteral("justification");
2375 if (value == "justify"_L1) {
2376 value = QStringLiteral("fill");
2377 } else if (value != "left"_L1 && value != "right"_L1 && value != "center"_L1) {
2378 qCDebug(lcAccessibilityAtspi) << "Unknown text-align attribute value \""
2379 << value << "\" cannot be translated to AT-SPI.";
2380 value = QString();
2381 }
2382 } else if (ia2Name == "font-size"_L1) {
2383 name = QStringLiteral("size");
2384 value = atspiSize(value);
2385 } else if (ia2Name == "font-style"_L1) {
2386 name = QStringLiteral("style");
2387 if (value != "normal"_L1 && value != "italic"_L1 && value != "oblique"_L1) {
2388 qCDebug(lcAccessibilityAtspi) << "Unknown font-style attribute value \"" << value
2389 << "\" cannot be translated to AT-SPI.";
2390 value = QString();
2391 }
2392 } else if (ia2Name == "text-underline-type"_L1) {
2393 name = QStringLiteral("underline");
2394 if (value != "none"_L1 && value != "single"_L1 && value != "double"_L1) {
2395 qCDebug(lcAccessibilityAtspi) << "Unknown text-underline-type attribute value \""
2396 << value << "\" cannot be translated to AT-SPI.";
2397 value = QString();
2398 }
2399 } else if (ia2Name == "font-weight"_L1) {
2400 name = QStringLiteral("weight");
2401 if (value == "normal"_L1)
2402 // Orca seems to accept all IAccessible2 values except for "normal"
2403 // (on which it produces traceback and fails to read any following text attributes),
2404 // but that is the default value, so omit it anyway
2405 value = QString();
2406 } else if (((ia2Name == "text-line-through-style"_L1 || ia2Name == "text-line-through-type"_L1) && (ia2Value != "none"_L1))
2407 || (ia2Name == "text-line-through-text"_L1 && !ia2Value.isEmpty())) {
2408 // if any of the above is set, set "strikethrough" to true, but don't explicitly set
2409 // to false otherwise, since any of the others might still be set to indicate strikethrough
2410 // and no strikethrough is assumed anyway when nothing is explicitly set
2411 name = QStringLiteral("strikethrough");
2412 value = QStringLiteral("true");
2413 } else if (ia2Name == "text-position"_L1) {
2414 name = QStringLiteral("vertical-align");
2415 if (value != "baseline"_L1 && value != "super"_L1 && value != "sub"_L1) {
2416 qCDebug(lcAccessibilityAtspi) << "Unknown text-position attribute value \"" << value
2417 << "\" cannot be translated to AT-SPI.";
2418 value = QString();
2419 }
2420 } else if (ia2Name == "writing-mode"_L1) {
2421 name = QStringLiteral("direction");
2422 if (value == "lr"_L1)
2423 value = QStringLiteral("ltr");
2424 else if (value == "rl"_L1)
2425 value = QStringLiteral("rtl");
2426 else if (value == "tb"_L1) {
2427 // 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))
2428 value = QStringLiteral("rtl");
2429 qCDebug(lcAccessibilityAtspi) << "writing-mode attribute value \"tb\" translated only w.r.t. horizontal direction; vertical direction ignored";
2430 } else {
2431 qCDebug(lcAccessibilityAtspi) << "Unknown writing-mode attribute value \"" << value
2432 << "\" cannot be translated to AT-SPI.";
2433 value = QString();
2434 }
2435 } else if (ia2Name == "language"_L1) {
2436 // OK - ATK has no docs on the format of the value, IAccessible2 has reasonable format - leave it at that now
2437 } else if (ia2Name == "invalid"_L1) {
2438 // OK - ATK docs are vague but suggest they support the same range of values as IAccessible2
2439 } else {
2440 // attribute we know nothing about
2441 name = QString();
2442 value = QString();
2443 }
2444 return AtSpiAttribute(name, value);
2445 }
2446}
2447
2448QSpiAttributeSet AtSpiAdaptor::getAttributes(QAccessibleInterface *interface)
2449{
2450 QSpiAttributeSet set;
2451 QAccessibleAttributesInterface *attributesIface = interface->attributesInterface();
2452 if (!attributesIface)
2453 return set;
2454
2455 const QList<QAccessible::Attribute> attrKeys = attributesIface->attributeKeys();
2456 for (QAccessible::Attribute key : attrKeys) {
2457 const QVariant value = attributesIface->attributeValue(key);
2458 // see "Core Accessibility API Mappings" spec: https://www.w3.org/TR/core-aam-1.2/
2459 switch (key) {
2460 case QAccessible::Attribute::Custom:
2461 {
2462 // forward custom attributes to AT-SPI as-is
2463 Q_ASSERT((value.canConvert<QHash<QString, QString>>()));
2464 const QHash<QString, QString> attrMap = value.value<QHash<QString, QString>>();
2465 for (auto [name, val] : attrMap.asKeyValueRange())
2466 set.insert(name, val);
2467 break;
2468 }
2469 case QAccessible::Attribute::Level:
2470 Q_ASSERT(value.canConvert<int>());
2471 set.insert(QStringLiteral("level"), QString::number(value.toInt()));
2472 break;
2473 default:
2474 break;
2475 }
2476 }
2477 return set;
2478}
2479
2480// FIXME all attribute methods below should share code
2481QVariantList AtSpiAdaptor::getAttributes(QAccessibleInterface *interface, int offset,
2482 bool includeDefaults)
2483{
2484 Q_UNUSED(includeDefaults);
2485
2486 QSpiAttributeSet set;
2487 int startOffset;
2488 int endOffset;
2489
2490 QString joined = interface->textInterface()->attributes(offset, &startOffset, &endOffset);
2491 const QStringList attributes = joined.split(u';', Qt::SkipEmptyParts, Qt::CaseSensitive);
2492 for (const QString &attr : attributes) {
2493 QStringList items = attr.split(u':', Qt::SkipEmptyParts, Qt::CaseSensitive);
2494 if (items.count() == 2)
2495 {
2496 AtSpiAttribute attribute = atspiTextAttribute(items[0], items[1]);
2497 if (!attribute.isNull())
2498 set[attribute.name] = attribute.value;
2499 }
2500 }
2501
2502 QVariantList list;
2503 list << QVariant::fromValue(set) << startOffset << endOffset;
2504
2505 return list;
2506}
2507
2508QString AtSpiAdaptor::getAttributeValue(QAccessibleInterface *interface, int offset,
2509 const QString &attributeName)
2510{
2511 QString joined;
2512 QSpiAttributeSet map;
2513 int startOffset;
2514 int endOffset;
2515
2516 joined = interface->textInterface()->attributes(offset, &startOffset, &endOffset);
2517 const QStringList attributes = joined.split (u';', Qt::SkipEmptyParts, Qt::CaseSensitive);
2518 for (const QString& attr : attributes) {
2519 QStringList items;
2520 items = attr.split(u':', Qt::SkipEmptyParts, Qt::CaseSensitive);
2521 AtSpiAttribute attribute = atspiTextAttribute(items[0], items[1]);
2522 if (!attribute.isNull())
2523 map[attribute.name] = attribute.value;
2524 }
2525 return map[attributeName];
2526}
2527
2528QList<QVariant> AtSpiAdaptor::getCharacterExtents(QAccessibleInterface *interface, int offset,
2529 uint coordType)
2530{
2531 QRect rect = interface->textInterface()->characterRect(offset);
2532 rect = translateFromScreenCoordinates(interface, rect, coordType);
2533 return QList<QVariant>() << rect.x() << rect.y() << rect.width() << rect.height();
2534}
2535
2536QList<QVariant> AtSpiAdaptor::getRangeExtents(QAccessibleInterface *interface, int startOffset,
2537 int endOffset, uint coordType)
2538{
2539 if (endOffset == -1)
2540 endOffset = interface->textInterface()->characterCount();
2541
2542 QAccessibleTextInterface *textInterface = interface->textInterface();
2543 if (endOffset <= startOffset || !textInterface)
2544 return QList<QVariant>() << -1 << -1 << 0 << 0;
2545
2546 QRect rect = textInterface->characterRect(startOffset);
2547 for (int i=startOffset + 1; i <= endOffset; i++)
2548 rect = rect | textInterface->characterRect(i);
2549
2550 rect = translateFromScreenCoordinates(interface, rect, coordType);
2551 return QList<QVariant>() << rect.x() << rect.y() << rect.width() << rect.height();
2552}
2553
2554bool AtSpiAdaptor::isValidCoordType(uint coordType)
2555{
2556 if (coordType == ATSPI_COORD_TYPE_SCREEN || coordType == ATSPI_COORD_TYPE_WINDOW || coordType == ATSPI_COORD_TYPE_PARENT)
2557 return true;
2558
2559 qCWarning(lcAccessibilityAtspi) << "Unknown value" << coordType << "for AT-SPI coord type";
2560 return false;
2561}
2562
2563QRect AtSpiAdaptor::translateFromScreenCoordinates(QAccessibleInterface *interface, const QRect &screenRect, uint targetCoordType)
2564{
2565 Q_ASSERT(isValidCoordType(targetCoordType));
2566
2567 QAccessibleInterface *upper = nullptr;
2568 if (targetCoordType == ATSPI_COORD_TYPE_WINDOW)
2569 upper = getWindow(interface);
2570 else if (targetCoordType == ATSPI_COORD_TYPE_PARENT)
2571 upper = interface->parent();
2572
2573 QRect rect = screenRect;
2574 if (upper)
2575 rect.translate(-upper->rect().x(), -upper->rect().y());
2576
2577 return rect;
2578}
2579
2580QPoint AtSpiAdaptor::translateToScreenCoordinates(QAccessibleInterface *interface, const QPoint &pos, uint fromCoordType)
2581{
2582 Q_ASSERT(isValidCoordType(fromCoordType));
2583
2584 QAccessibleInterface *upper = nullptr;
2585 if (fromCoordType == ATSPI_COORD_TYPE_WINDOW)
2586 upper = getWindow(interface);
2587 else if (fromCoordType == ATSPI_COORD_TYPE_PARENT)
2588 upper = interface->parent();
2589
2590 QPoint screenPos = pos;
2591 if (upper)
2592 screenPos += upper->rect().topLeft();
2593
2594 return screenPos;
2595}
2596
2597// Editable Text interface
2598static QString textForRange(QAccessibleInterface *accessible, int startOffset, int endOffset)
2599{
2600 if (QAccessibleTextInterface *textIface = accessible->textInterface()) {
2601 if (endOffset == -1)
2602 endOffset = textIface->characterCount();
2603 return textIface->text(startOffset, endOffset);
2604 }
2605 QString txt = accessible->text(QAccessible::Value);
2606 if (endOffset == -1)
2607 endOffset = txt.size();
2608 return txt.mid(startOffset, endOffset - startOffset);
2609}
2610
2611static void replaceTextFallback(QAccessibleInterface *accessible, long startOffset, long endOffset, const QString &txt)
2612{
2613 QString t = textForRange(accessible, 0, -1);
2614 if (endOffset == -1)
2615 endOffset = t.size();
2616 if (endOffset - startOffset == 0)
2617 t.insert(startOffset, txt);
2618 else
2619 t.replace(startOffset, endOffset - startOffset, txt);
2620 accessible->setText(QAccessible::Value, t);
2621}
2622
2623bool AtSpiAdaptor::editableTextInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection)
2624{
2625 if (function == "CopyText"_L1) {
2626#ifndef QT_NO_CLIPBOARD
2627 int startOffset = message.arguments().at(0).toInt();
2628 int endOffset = message.arguments().at(1).toInt();
2629 const QString t = textForRange(interface, startOffset, endOffset);
2630 QGuiApplication::clipboard()->setText(t);
2631#endif
2632 connection.send(message.createReply(true));
2633 } else if (function == "CutText"_L1) {
2634#ifndef QT_NO_CLIPBOARD
2635 int startOffset = message.arguments().at(0).toInt();
2636 int endOffset = message.arguments().at(1).toInt();
2637 const QString t = textForRange(interface, startOffset, endOffset);
2638 if (QAccessibleEditableTextInterface *editableTextIface = interface->editableTextInterface())
2639 editableTextIface->deleteText(startOffset, endOffset);
2640 else
2641 replaceTextFallback(interface, startOffset, endOffset, QString());
2642 QGuiApplication::clipboard()->setText(t);
2643#endif
2644 connection.send(message.createReply(true));
2645 } else if (function == "DeleteText"_L1) {
2646 int startOffset = message.arguments().at(0).toInt();
2647 int endOffset = message.arguments().at(1).toInt();
2648 if (QAccessibleEditableTextInterface *editableTextIface = interface->editableTextInterface())
2649 editableTextIface->deleteText(startOffset, endOffset);
2650 else
2651 replaceTextFallback(interface, startOffset, endOffset, QString());
2652 connection.send(message.createReply(true));
2653 } else if (function == "InsertText"_L1) {
2654 int position = message.arguments().at(0).toInt();
2655 QString text = message.arguments().at(1).toString();
2656 int length = message.arguments().at(2).toInt();
2657 text.resize(length);
2658 if (QAccessibleEditableTextInterface *editableTextIface = interface->editableTextInterface())
2659 editableTextIface->insertText(position, text);
2660 else
2661 replaceTextFallback(interface, position, position, text);
2662 connection.send(message.createReply(true));
2663 } else if (function == "PasteText"_L1) {
2664#ifndef QT_NO_CLIPBOARD
2665 int position = message.arguments().at(0).toInt();
2666 const QString txt = QGuiApplication::clipboard()->text();
2667 if (QAccessibleEditableTextInterface *editableTextIface = interface->editableTextInterface())
2668 editableTextIface->insertText(position, txt);
2669 else
2670 replaceTextFallback(interface, position, position, txt);
2671#endif
2672 connection.send(message.createReply(true));
2673 } else if (function == "SetTextContents"_L1) {
2674 QString newContents = message.arguments().at(0).toString();
2675 if (QAccessibleEditableTextInterface *editableTextIface = interface->editableTextInterface())
2676 editableTextIface->replaceText(0, interface->textInterface()->characterCount(), newContents);
2677 else
2678 replaceTextFallback(interface, 0, -1, newContents);
2679 connection.send(message.createReply(true));
2680 } else if (function.isEmpty()) {
2681 connection.send(message.createReply());
2682 } else {
2683 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::editableTextInterface does not implement" << function << message.path();
2684 return false;
2685 }
2686 return true;
2687}
2688
2689// Value interface
2690bool AtSpiAdaptor::valueInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection)
2691{
2692 QAccessibleValueInterface *valueIface = interface->valueInterface();
2693 if (!valueIface)
2694 return false;
2695
2696 if (function == "SetCurrentValue"_L1) {
2697 QDBusVariant v = qvariant_cast<QDBusVariant>(message.arguments().at(2));
2698 double value = v.variant().toDouble();
2699 //Temporary fix
2700 //See https://bugzilla.gnome.org/show_bug.cgi?id=652596
2701 valueIface->setCurrentValue(value);
2702 connection.send(message.createReply());
2703 } else {
2704 QVariant value;
2705 if (function == "GetCurrentValue"_L1)
2706 value = valueIface->currentValue();
2707 else if (function == "GetMaximumValue"_L1)
2708 value = valueIface->maximumValue();
2709 else if (function == "GetMinimumIncrement"_L1)
2710 value = valueIface->minimumStepSize();
2711 else if (function == "GetMinimumValue"_L1)
2712 value = valueIface->minimumValue();
2713 else {
2714 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::valueInterface does not implement" << function << message.path();
2715 return false;
2716 }
2717 if (!value.canConvert<double>()) {
2718 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::valueInterface: Could not convert to double:" << function;
2719 }
2720
2721 // explicitly convert to dbus-variant containing one double since atspi expects that
2722 // everything else might fail to convert back on the other end
2723 connection.send(message.createReply(
2724 QVariant::fromValue(QDBusVariant(QVariant::fromValue(value.toDouble())))));
2725 }
2726 return true;
2727}
2728
2729// Selection interface
2730bool AtSpiAdaptor::selectionInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection)
2731{
2732 QAccessibleSelectionInterface* selectionInterface = interface->selectionInterface();
2733 if (!selectionInterface) {
2734 qCWarning(lcAccessibilityAtspi) << "Could not find selection interface for: " << message.path() << interface;
2735 return false;
2736 }
2737
2738 if (function == "ClearSelection"_L1 ) {
2739 connection.send(message.createReply(QVariant::fromValue((selectionInterface->clear()))));
2740 } else if (function == "DeselectChild"_L1 ) {
2741 int childIndex = message.arguments().at(0).toInt();
2742 bool ret = false;
2743 QAccessibleInterface *child = interface->child(childIndex);
2744 if (child)
2745 ret = selectionInterface->unselect(child);
2746 connection.send(message.createReply(QVariant::fromValue(ret)));
2747 } else if (function == "DeselectSelectedChild"_L1 ) {
2748 int selectionIndex = message.arguments().at(0).toInt();
2749 bool ret = false;
2750 QAccessibleInterface *selectedChild = selectionInterface->selectedItem(selectionIndex);
2751 if (selectedChild)
2752 ret = selectionInterface->unselect(selectedChild);
2753 connection.send(message.createReply(QVariant::fromValue(ret)));
2754 } else if (function == "GetNSelectedChildren"_L1) {
2755 connection.send(message.createReply(QVariant::fromValue(QDBusVariant(
2756 QVariant::fromValue(selectionInterface->selectedItemCount())))));
2757 } else if (function == "GetSelectedChild"_L1) {
2758 int selectionIndex = message.arguments().at(0).toInt();
2759 QSpiObjectReference ref(connection, QDBusObjectPath(pathForInterface(selectionInterface->selectedItem(selectionIndex))));
2760 connection.send(message.createReply(QVariant::fromValue(ref)));
2761 } else if (function == "IsChildSelected"_L1 ) {
2762 int childIndex = message.arguments().at(0).toInt();
2763 bool ret = false;
2764 QAccessibleInterface *child = interface->child(childIndex);
2765 if (child)
2766 ret = selectionInterface->isSelected(child);
2767 connection.send(message.createReply(QVariant::fromValue(ret)));
2768 } else if (function == "SelectAll"_L1 ) {
2769 connection.send(message.createReply(QVariant::fromValue(selectionInterface->selectAll())));
2770 } else if (function == "SelectChild"_L1 ) {
2771 int childIndex = message.arguments().at(0).toInt();
2772 bool ret = false;
2773 QAccessibleInterface *child = interface->child(childIndex);
2774 if (child)
2775 ret = selectionInterface->select(child);
2776 connection.send(message.createReply(QVariant::fromValue(ret)));
2777 } else {
2778 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::selectionInterface does not implement " << function << message.path();
2779 return false;
2780 }
2781
2782 return true;
2783}
2784
2785
2786// Table interface
2787bool AtSpiAdaptor::tableInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection)
2788{
2789 if (!(interface->tableInterface() || interface->tableCellInterface())) {
2790 qCWarning(lcAccessibilityAtspi) << "Qt AtSpiAdaptor: Could not find table interface for:" << message.path() << interface;
2791 return false;
2792 }
2793
2794 if (function == "GetCaption"_L1) {
2795 QAccessibleInterface * captionInterface= interface->tableInterface()->caption();
2796 if (captionInterface) {
2797 QSpiObjectReference ref = QSpiObjectReference(connection, QDBusObjectPath(pathForInterface(captionInterface)));
2798 sendReply(connection, message, QVariant::fromValue(QDBusVariant(QVariant::fromValue(ref))));
2799 } else {
2800 sendReply(connection, message, QVariant::fromValue(QDBusVariant(QVariant::fromValue(
2801 QSpiObjectReference(connection, QDBusObjectPath(ATSPI_DBUS_PATH_NULL))))));
2802 }
2803 } else if (function == "GetNColumns"_L1) {
2804 connection.send(message.createReply(QVariant::fromValue(QDBusVariant(
2805 QVariant::fromValue(interface->tableInterface()->columnCount())))));
2806 } else if (function == "GetNRows"_L1) {
2807 connection.send(message.createReply(QVariant::fromValue(QDBusVariant(
2808 QVariant::fromValue(interface->tableInterface()->rowCount())))));
2809 } else if (function == "GetNSelectedColumns"_L1) {
2810 connection.send(message.createReply(QVariant::fromValue(QDBusVariant(
2811 QVariant::fromValue(interface->tableInterface()->selectedColumnCount())))));
2812 } else if (function == "GetNSelectedRows"_L1) {
2813 connection.send(message.createReply(QVariant::fromValue(QDBusVariant(
2814 QVariant::fromValue(interface->tableInterface()->selectedRowCount())))));
2815 } else if (function == "GetSummary"_L1) {
2816 QAccessibleInterface *summary = interface->tableInterface() ? interface->tableInterface()->summary() : nullptr;
2817 QSpiObjectReference ref(connection, QDBusObjectPath(pathForInterface(summary)));
2818 connection.send(message.createReply(QVariant::fromValue(QDBusVariant(QVariant::fromValue(ref)))));
2819 } else if (function == "GetAccessibleAt"_L1) {
2820 int row = message.arguments().at(0).toInt();
2821 int column = message.arguments().at(1).toInt();
2822 if ((row < 0) ||
2823 (column < 0) ||
2824 (row >= interface->tableInterface()->rowCount()) ||
2825 (column >= interface->tableInterface()->columnCount())) {
2826 qCWarning(lcAccessibilityAtspi) << "Invalid index for tableInterface GetAccessibleAt (" << row << "," << column << ')';
2827 return false;
2828 }
2829
2830 QSpiObjectReference ref;
2831 QAccessibleInterface * cell(interface->tableInterface()->cellAt(row, column));
2832 if (cell) {
2833 ref = QSpiObjectReference(connection, QDBusObjectPath(pathForInterface(cell)));
2834 } else {
2835 qCWarning(lcAccessibilityAtspi) << "No cell interface returned for" << interface->object() << row << column;
2836 ref = QSpiObjectReference();
2837 }
2838 connection.send(message.createReply(QVariant::fromValue(ref)));
2839
2840 } else if (function == "GetIndexAt"_L1) {
2841 int row = message.arguments().at(0).toInt();
2842 int column = message.arguments().at(1).toInt();
2843 QAccessibleInterface *cell = interface->tableInterface()->cellAt(row, column);
2844 if (!cell) {
2845 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::GetIndexAt(" << row << ',' << column << ") did not find a cell." << interface;
2846 return false;
2847 }
2848 int index = interface->indexOfChild(cell);
2849 qCDebug(lcAccessibilityAtspi) << "QSpiAdaptor::GetIndexAt row:" << row << " col:" << column << " logical index:" << index;
2850 Q_ASSERT(index > 0);
2851 connection.send(message.createReply(index));
2852 } else if ((function == "GetColumnAtIndex"_L1) || (function == "GetRowAtIndex"_L1)) {
2853 int index = message.arguments().at(0).toInt();
2854 int ret = -1;
2855 if (index >= 0) {
2856 QAccessibleInterface * cell = interface->child(index);
2857 if (cell) {
2858 if (function == "GetColumnAtIndex"_L1) {
2859 if (cell->role() == QAccessible::ColumnHeader) {
2860 ret = index;
2861 } else if (cell->role() == QAccessible::RowHeader) {
2862 ret = -1;
2863 } else {
2864 if (!cell->tableCellInterface()) {
2865 qCWarning(lcAccessibilityAtspi).nospace() << "AtSpiAdaptor::" << function << " No table cell interface: " << cell;
2866 return false;
2867 }
2868 ret = cell->tableCellInterface()->columnIndex();
2869 }
2870 } else {
2871 if (cell->role() == QAccessible::ColumnHeader) {
2872 ret = -1;
2873 } else if (cell->role() == QAccessible::RowHeader) {
2874 ret = index % interface->tableInterface()->columnCount();
2875 } else {
2876 if (!cell->tableCellInterface()) {
2877 qCWarning(lcAccessibilityAtspi).nospace() << "AtSpiAdaptor::" << function << " No table cell interface: " << cell;
2878 return false;
2879 }
2880 ret = cell->tableCellInterface()->rowIndex();
2881 }
2882 }
2883 } else {
2884 qCWarning(lcAccessibilityAtspi).nospace() << "AtSpiAdaptor::" << function << " No cell at index: " << index << " " << interface;
2885 return false;
2886 }
2887 }
2888 connection.send(message.createReply(ret));
2889
2890 } else if (function == "GetColumnDescription"_L1) {
2891 int column = message.arguments().at(0).toInt();
2892 connection.send(message.createReply(interface->tableInterface()->columnDescription(column)));
2893 } else if (function == "GetRowDescription"_L1) {
2894 int row = message.arguments().at(0).toInt();
2895 connection.send(message.createReply(interface->tableInterface()->rowDescription(row)));
2896
2897
2898
2899 } else if (function == "GetRowColumnExtentsAtIndex"_L1) {
2900 int index = message.arguments().at(0).toInt();
2901 bool success = false;
2902
2903 int row = -1;
2904 int col = -1;
2905 int rowExtents = -1;
2906 int colExtents = -1;
2907 bool isSelected = false;
2908
2909 int cols = interface->tableInterface()->columnCount();
2910 if (cols > 0) {
2911 row = index / cols;
2912 col = index % cols;
2913 if (QAccessibleInterface *cell = interface->tableInterface()->cellAt(row, col)) {
2914 if (QAccessibleTableCellInterface *cellIface = cell->tableCellInterface()) {
2915 row = cellIface->rowIndex();
2916 col = cellIface->columnIndex();
2917 rowExtents = cellIface->rowExtent();
2918 colExtents = cellIface->columnExtent();
2919 isSelected = cellIface->isSelected();
2920 success = true;
2921 }
2922 }
2923 }
2924 QVariantList list;
2925 list << success << row << col << rowExtents << colExtents << isSelected;
2926 connection.send(message.createReply(list));
2927
2928 } else if (function == "GetColumnExtentAt"_L1) {
2929 int row = message.arguments().at(0).toInt();
2930 int column = message.arguments().at(1).toInt();
2931 int columnExtent = 0;
2932 if (QAccessibleInterface *cell = interface->tableInterface()->cellAt(row, column)) {
2933 if (QAccessibleTableCellInterface *cellIface = cell->tableCellInterface())
2934 columnExtent = cellIface->columnExtent();
2935 }
2936 connection.send(message.createReply(columnExtent));
2937
2938 } else if (function == "GetRowExtentAt"_L1) {
2939 int row = message.arguments().at(0).toInt();
2940 int column = message.arguments().at(1).toInt();
2941 int rowExtent = 0;
2942 if (QAccessibleInterface *cell = interface->tableInterface()->cellAt(row, column)) {
2943 if (QAccessibleTableCellInterface *cellIface = cell->tableCellInterface())
2944 rowExtent = cellIface->rowExtent();
2945 }
2946 connection.send(message.createReply(rowExtent));
2947
2948 } else if (function == "GetColumnHeader"_L1) {
2949 int column = message.arguments().at(0).toInt();
2950 QSpiObjectReference ref;
2951
2952 QAccessibleInterface * cell(interface->tableInterface()->cellAt(0, column));
2953 if (cell && cell->tableCellInterface()) {
2954 QList<QAccessibleInterface*> header = cell->tableCellInterface()->columnHeaderCells();
2955 if (header.size() > 0) {
2956 ref = QSpiObjectReference(connection, QDBusObjectPath(pathForInterface(header.takeAt(0))));
2957 }
2958 }
2959 connection.send(message.createReply(QVariant::fromValue(ref)));
2960
2961 } else if (function == "GetRowHeader"_L1) {
2962 int row = message.arguments().at(0).toInt();
2963 QSpiObjectReference ref;
2964 QAccessibleInterface *cell = interface->tableInterface()->cellAt(row, 0);
2965 if (cell && cell->tableCellInterface()) {
2966 QList<QAccessibleInterface*> header = cell->tableCellInterface()->rowHeaderCells();
2967 if (header.size() > 0) {
2968 ref = QSpiObjectReference(connection, QDBusObjectPath(pathForInterface(header.takeAt(0))));
2969 }
2970 }
2971 connection.send(message.createReply(QVariant::fromValue(ref)));
2972
2973 } else if (function == "GetSelectedColumns"_L1) {
2974 connection.send(message.createReply(QVariant::fromValue(interface->tableInterface()->selectedColumns())));
2975 } else if (function == "GetSelectedRows"_L1) {
2976 connection.send(message.createReply(QVariant::fromValue(interface->tableInterface()->selectedRows())));
2977 } else if (function == "IsColumnSelected"_L1) {
2978 int column = message.arguments().at(0).toInt();
2979 connection.send(message.createReply(interface->tableInterface()->isColumnSelected(column)));
2980 } else if (function == "IsRowSelected"_L1) {
2981 int row = message.arguments().at(0).toInt();
2982 connection.send(message.createReply(interface->tableInterface()->isRowSelected(row)));
2983 } else if (function == "IsSelected"_L1) {
2984 int row = message.arguments().at(0).toInt();
2985 int column = message.arguments().at(1).toInt();
2986 bool selected = false;
2987 if (QAccessibleInterface* cell = interface->tableInterface()->cellAt(row, column)) {
2988 if (QAccessibleTableCellInterface *cellIface = cell->tableCellInterface())
2989 selected = cellIface->isSelected();
2990 }
2991 connection.send(message.createReply(selected));
2992 } else if (function == "AddColumnSelection"_L1) {
2993 int column = message.arguments().at(0).toInt();
2994 connection.send(message.createReply(interface->tableInterface()->selectColumn(column)));
2995 } else if (function == "AddRowSelection"_L1) {
2996 int row = message.arguments().at(0).toInt();
2997 connection.send(message.createReply(interface->tableInterface()->selectRow(row)));
2998 } else if (function == "RemoveColumnSelection"_L1) {
2999 int column = message.arguments().at(0).toInt();
3000 connection.send(message.createReply(interface->tableInterface()->unselectColumn(column)));
3001 } else if (function == "RemoveRowSelection"_L1) {
3002 int row = message.arguments().at(0).toInt();
3003 connection.send(message.createReply(interface->tableInterface()->unselectRow(row)));
3004 } else {
3005 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::tableInterface does not implement" << function << message.path();
3006 return false;
3007 }
3008 return true;
3009}
3010
3011// Table cell interface
3012bool AtSpiAdaptor::tableCellInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection)
3013{
3014 QAccessibleTableCellInterface* cellInterface = interface->tableCellInterface();
3015 if (!cellInterface) {
3016 qCWarning(lcAccessibilityAtspi) << "Could not find table cell interface for: " << message.path() << interface;
3017 return false;
3018 }
3019
3020 if (function == "GetColumnHeaderCells"_L1) {
3021 QSpiObjectReferenceArray headerCells;
3022 const auto headerCellInterfaces = cellInterface->columnHeaderCells();
3023 headerCells.reserve(headerCellInterfaces.size());
3024 for (QAccessibleInterface *cell : headerCellInterfaces) {
3025 const QString childPath = pathForInterface(cell);
3026 const QSpiObjectReference ref(connection, QDBusObjectPath(childPath));
3027 headerCells << ref;
3028 }
3029 connection.send(message.createReply(QVariant::fromValue(headerCells)));
3030 } else if (function == "GetColumnSpan"_L1) {
3031 connection.send(message.createReply(QVariant::fromValue(QDBusVariant(
3032 QVariant::fromValue(cellInterface->columnExtent())))));
3033 } else if (function == "GetPosition"_L1) {
3034 const int row = cellInterface->rowIndex();
3035 const int column = cellInterface->columnIndex();
3036 connection.send(message.createReply(QVariant::fromValue(QDBusVariant(
3037 QVariant::fromValue(QPoint(row, column))))));
3038 } else if (function == "GetRowHeaderCells"_L1) {
3039 QSpiObjectReferenceArray headerCells;
3040 const auto headerCellInterfaces = cellInterface->rowHeaderCells();
3041 headerCells.reserve(headerCellInterfaces.size());
3042 for (QAccessibleInterface *cell : headerCellInterfaces) {
3043 const QString childPath = pathForInterface(cell);
3044 const QSpiObjectReference ref(connection, QDBusObjectPath(childPath));
3045 headerCells << ref;
3046 }
3047 connection.send(message.createReply(QVariant::fromValue(headerCells)));
3048 } else if (function == "GetRowSpan"_L1) {
3049 connection.send(message.createReply(QVariant::fromValue(QDBusVariant(
3050 QVariant::fromValue(cellInterface->rowExtent())))));
3051 } else if (function == "GetRowColumnSpan"_L1) {
3052 QVariantList list;
3053 list << cellInterface->rowIndex() << cellInterface->columnIndex() << cellInterface->rowExtent() << cellInterface->columnExtent();
3054 connection.send(message.createReply(list));
3055 } else if (function == "GetTable"_L1) {
3056 QSpiObjectReference ref;
3057 QAccessibleInterface* table = cellInterface->table();
3058 if (table && table->tableInterface())
3059 ref = QSpiObjectReference(connection, QDBusObjectPath(pathForInterface(table)));
3060 connection.send(message.createReply(QVariant::fromValue(QDBusVariant(QVariant::fromValue(ref)))));
3061 } else {
3062 qCWarning(lcAccessibilityAtspi) << "AtSpiAdaptor::tableCellInterface does not implement" << function << message.path();
3063 return false;
3064 }
3065
3066 return true;
3067}
3068
3069QT_END_NAMESPACE
3070
3071#include "moc_atspiadaptor_p.cpp"
3072#endif // QT_CONFIG(accessibility)