1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
5#ifndef ATSPIADAPTOR_H
6#define ATSPIADAPTOR_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <atspi/atspi-constants.h>
20
21#include <QtGui/private/qtguiglobal_p.h>
22#include <QtDBus/qdbusvirtualobject.h>
23#include <QtGui/qaccessible.h>
24
25#include "dbusconnection_p.h"
26#include "qspi_struct_marshallers_p.h"
27
28QT_REQUIRE_CONFIG(accessibility);
29
30QT_BEGIN_NAMESPACE
31
32class QAccessibleInterface;
33class QSpiApplicationAdaptor;
34
35
36class AtSpiAdaptor :public QDBusVirtualObject
37{
38 Q_OBJECT
39
40public:
41 explicit AtSpiAdaptor(DBusConnection *connection, QObject *parent = nullptr);
42 ~AtSpiAdaptor();
43
44 void registerApplication();
45 QString introspect(const QString &path) const override;
46 bool handleMessage(const QDBusMessage &message, const QDBusConnection &connection) override;
47 void notify(QAccessibleEvent *event);
48
49public Q_SLOTS:
50 void eventListenerRegistered(const QString &bus, const QString &path);
51 void eventListenerDeregistered(const QString &bus, const QString &path);
52 void windowActivated(QObject* window, bool active);
53
54private:
55 void updateEventListeners();
56 void setBitFlag(const QString &flag);
57
58 // sending messages
59 QVariantList packDBusSignalArguments(const QString &type, int data1, int data2, const QVariant &variantData) const;
60 bool sendDBusSignal(const QString &path, const QString &interface, const QString &name, const QVariantList &arguments) const;
61 QVariant variantForPath(const QString &path) const;
62
63 void sendFocusChanged(QAccessibleInterface *interface) const;
64 void notifyAboutCreation(QAccessibleInterface *interface) const;
65 void notifyAboutDestruction(QAccessibleInterface *interface) const;
66 void childrenChanged(QAccessibleInterface *interface) const;
67
68 // handlers for the different accessible interfaces
69 bool applicationInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection);
70 bool accessibleInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection);
71 bool componentInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection);
72 bool actionInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection);
73 bool textInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection);
74 bool editableTextInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection);
75 bool valueInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection);
76 bool selectionInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection);
77 bool tableInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection);
78 bool tableCellInterface(QAccessibleInterface *interface, const QString &function, const QDBusMessage &message, const QDBusConnection &connection);
79
80 void sendReply(const QDBusConnection &connection, const QDBusMessage &message, const QVariant &argument) const;
81
82 QAccessibleInterface *interfaceFromPath(const QString& dbusPath) const;
83 QString pathForInterface(QAccessibleInterface *interface) const;
84 QString pathForObject(QObject *object) const;
85
86 void notifyStateChange(QAccessibleInterface *interface, const QString& state, int value);
87
88 // accessible helper functions
89 AtspiRole getRole(QAccessibleInterface *interface) const;
90 QSpiRelationArray relationSet(QAccessibleInterface *interface, const QDBusConnection &connection) const;
91 QStringList accessibleInterfaces(QAccessibleInterface *interface) const;
92
93 // component helper functions
94 static QRect getExtents(QAccessibleInterface *interface, uint coordType);
95 static bool isValidCoordType(uint coordType);
96 static QRect translateFromScreenCoordinates(QAccessibleInterface *interface, const QRect &rect, uint targetCoordType);
97 static QPoint translateToScreenCoordinates(QAccessibleInterface *interface, const QPoint &pos, uint fromCoordType);
98
99 // action helper functions
100 QSpiActionArray getActions(QAccessibleInterface *interface) const;
101
102 // text helper functions
103 QVariantList getAttributes(QAccessibleInterface *, int offset, bool includeDefaults) const;
104 QString getAttributeValue(QAccessibleInterface *, int offset, const QString &attributeName) const;
105 QList<QVariant> getCharacterExtents(QAccessibleInterface *, int offset, uint coordType) const;
106 QList<QVariant> getRangeExtents(QAccessibleInterface *, int startOffset, int endOffset, uint coordType) const;
107 static QAccessible::TextBoundaryType qAccessibleBoundaryTypeFromAtspiBoundaryType(int atspiTextBoundaryType);
108 static bool isValidAtspiTextGranularity(uint coordType);
109 static QAccessible::TextBoundaryType qAccessibleBoundaryTypeFromAtspiTextGranularity(uint atspiTextGranularity);
110 static bool inheritsQAction(QObject *object);
111
112 // private vars
113 QSpiObjectReference accessibilityRegistry;
114 DBusConnection *m_dbus;
115 QSpiApplicationAdaptor *m_applicationAdaptor;
116
117 /// Assigned from the accessibility registry.
118 int m_applicationId;
119
120 // Bit fields - which updates to send
121
122 // AT-SPI has some events that we do not care about:
123 // document
124 // document-load-complete
125 // document-load-stopped
126 // document-reload
127 uint sendFocus : 1;
128 // mouse abs/rel/button
129
130 // all of object
131 uint sendObject : 1;
132 uint sendObject_active_descendant_changed : 1;
133 uint sendObject_attributes_changed : 1;
134 uint sendObject_bounds_changed : 1;
135 uint sendObject_children_changed : 1;
136// uint sendObject_children_changed_add : 1;
137// uint sendObject_children_changed_remove : 1;
138 uint sendObject_column_deleted : 1;
139 uint sendObject_column_inserted : 1;
140 uint sendObject_column_reordered : 1;
141 uint sendObject_link_selected : 1;
142 uint sendObject_model_changed : 1;
143 uint sendObject_property_change : 1;
144 uint sendObject_property_change_accessible_description : 1;
145 uint sendObject_property_change_accessible_name : 1;
146 uint sendObject_property_change_accessible_parent : 1;
147 uint sendObject_property_change_accessible_role : 1;
148 uint sendObject_property_change_accessible_table_caption : 1;
149 uint sendObject_property_change_accessible_table_column_description : 1;
150 uint sendObject_property_change_accessible_table_column_header : 1;
151 uint sendObject_property_change_accessible_table_row_description : 1;
152 uint sendObject_property_change_accessible_table_row_header : 1;
153 uint sendObject_property_change_accessible_table_summary : 1;
154 uint sendObject_property_change_accessible_value : 1;
155 uint sendObject_row_deleted : 1;
156 uint sendObject_row_inserted : 1;
157 uint sendObject_row_reordered : 1;
158 uint sendObject_selection_changed : 1;
159 uint sendObject_state_changed : 1;
160 uint sendObject_text_attributes_changed : 1;
161 uint sendObject_text_bounds_changed : 1;
162 uint sendObject_text_caret_moved : 1;
163 uint sendObject_text_changed : 1;
164// uint sendObject_text_changed_delete : 1;
165// uint sendObject_text_changed_insert : 1;
166 uint sendObject_text_selection_changed : 1;
167 uint sendObject_value_changed : 1;
168 uint sendObject_visible_data_changed : 1;
169
170 // we don't implement terminal
171 // terminal-application_changed/charwidth_changed/columncount_changed/line_changed/linecount_changed
172 uint sendWindow : 1;
173 uint sendWindow_activate : 1;
174 uint sendWindow_close: 1;
175 uint sendWindow_create : 1;
176 uint sendWindow_deactivate : 1;
177// uint sendWindow_desktop_create : 1;
178// uint sendWindow_desktop_destroy : 1;
179 uint sendWindow_lower : 1;
180 uint sendWindow_maximize : 1;
181 uint sendWindow_minimize : 1;
182 uint sendWindow_move : 1;
183 uint sendWindow_raise : 1;
184 uint sendWindow_reparent : 1;
185 uint sendWindow_resize : 1;
186 uint sendWindow_restore : 1;
187 uint sendWindow_restyle : 1;
188 uint sendWindow_shade : 1;
189 uint sendWindow_unshade : 1;
190};
191
192QT_END_NAMESPACE
193
194#endif
195

source code of qtbase/src/gui/accessible/linux/atspiadaptor_p.h