| 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.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 | |
| 28 | QT_REQUIRE_CONFIG(accessibility); |
| 29 | |
| 30 | QT_BEGIN_NAMESPACE |
| 31 | |
| 32 | class QAccessibleInterface; |
| 33 | class QSpiApplicationAdaptor; |
| 34 | |
| 35 | |
| 36 | class AtSpiAdaptor :public QDBusVirtualObject |
| 37 | { |
| 38 | Q_OBJECT |
| 39 | |
| 40 | public: |
| 41 | explicit AtSpiAdaptor(QAtSpiDBusConnection *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 | |
| 49 | public 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 | |
| 54 | private: |
| 55 | void updateEventListeners(); |
| 56 | void setBitFlag(const QString &flag); |
| 57 | |
| 58 | // sending messages |
| 59 | static QVariantList packDBusSignalArguments(const QString &type, int data1, int data2, const QVariant &variantData); |
| 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 | void sendAnnouncement(QAccessibleAnnouncementEvent *event); |
| 89 | |
| 90 | // accessible helper functions |
| 91 | AtspiRole getRole(QAccessibleInterface *interface) const; |
| 92 | QSpiAttributeSet getAttributes(QAccessibleInterface *) const; |
| 93 | QSpiRelationArray relationSet(QAccessibleInterface *interface, const QDBusConnection &connection) const; |
| 94 | QStringList accessibleInterfaces(QAccessibleInterface *interface) const; |
| 95 | |
| 96 | // component helper functions |
| 97 | static QRect getExtents(QAccessibleInterface *interface, uint coordType); |
| 98 | static bool isValidCoordType(uint coordType); |
| 99 | static QRect translateFromScreenCoordinates(QAccessibleInterface *interface, const QRect &rect, uint targetCoordType); |
| 100 | static QPoint translateToScreenCoordinates(QAccessibleInterface *interface, const QPoint &pos, uint fromCoordType); |
| 101 | |
| 102 | // action helper functions |
| 103 | QSpiActionArray getActions(QAccessibleInterface *interface) const; |
| 104 | |
| 105 | // text helper functions |
| 106 | QVariantList getAttributes(QAccessibleInterface *, int offset, bool includeDefaults) const; |
| 107 | QString getAttributeValue(QAccessibleInterface *, int offset, const QString &attributeName) const; |
| 108 | QList<QVariant> getCharacterExtents(QAccessibleInterface *, int offset, uint coordType) const; |
| 109 | QList<QVariant> getRangeExtents(QAccessibleInterface *, int startOffset, int endOffset, uint coordType) const; |
| 110 | static QAccessible::TextBoundaryType qAccessibleBoundaryTypeFromAtspiBoundaryType(int atspiTextBoundaryType); |
| 111 | static bool isValidAtspiTextGranularity(uint coordType); |
| 112 | static QAccessible::TextBoundaryType qAccessibleBoundaryTypeFromAtspiTextGranularity(uint atspiTextGranularity); |
| 113 | static bool inheritsQAction(QObject *object); |
| 114 | |
| 115 | // private vars |
| 116 | QSpiObjectReference accessibilityRegistry; |
| 117 | QAtSpiDBusConnection *m_dbus; |
| 118 | QSpiApplicationAdaptor *m_applicationAdaptor; |
| 119 | |
| 120 | /// Assigned from the accessibility registry. |
| 121 | int m_applicationId; |
| 122 | |
| 123 | // Bit fields - which updates to send |
| 124 | |
| 125 | // AT-SPI has some events that we do not care about: |
| 126 | // document |
| 127 | // document-load-complete |
| 128 | // document-load-stopped |
| 129 | // document-reload |
| 130 | uint sendFocus : 1; |
| 131 | // mouse abs/rel/button |
| 132 | |
| 133 | // all of object |
| 134 | uint sendObject : 1; |
| 135 | uint sendObject_active_descendant_changed : 1; |
| 136 | uint sendObject_announcement : 1; |
| 137 | uint sendObject_attributes_changed : 1; |
| 138 | uint sendObject_bounds_changed : 1; |
| 139 | uint sendObject_children_changed : 1; |
| 140 | // uint sendObject_children_changed_add : 1; |
| 141 | // uint sendObject_children_changed_remove : 1; |
| 142 | uint sendObject_column_deleted : 1; |
| 143 | uint sendObject_column_inserted : 1; |
| 144 | uint sendObject_column_reordered : 1; |
| 145 | uint sendObject_link_selected : 1; |
| 146 | uint sendObject_model_changed : 1; |
| 147 | uint sendObject_property_change : 1; |
| 148 | uint sendObject_property_change_accessible_description : 1; |
| 149 | uint sendObject_property_change_accessible_name : 1; |
| 150 | uint sendObject_property_change_accessible_parent : 1; |
| 151 | uint sendObject_property_change_accessible_role : 1; |
| 152 | uint sendObject_property_change_accessible_table_caption : 1; |
| 153 | uint sendObject_property_change_accessible_table_column_description : 1; |
| 154 | uint sendObject_property_change_accessible_table_column_header : 1; |
| 155 | uint sendObject_property_change_accessible_table_row_description : 1; |
| 156 | uint : 1; |
| 157 | uint sendObject_property_change_accessible_table_summary : 1; |
| 158 | uint sendObject_property_change_accessible_value : 1; |
| 159 | uint sendObject_row_deleted : 1; |
| 160 | uint sendObject_row_inserted : 1; |
| 161 | uint sendObject_row_reordered : 1; |
| 162 | uint sendObject_selection_changed : 1; |
| 163 | uint sendObject_state_changed : 1; |
| 164 | uint sendObject_text_attributes_changed : 1; |
| 165 | uint sendObject_text_bounds_changed : 1; |
| 166 | uint sendObject_text_caret_moved : 1; |
| 167 | uint sendObject_text_changed : 1; |
| 168 | // uint sendObject_text_changed_delete : 1; |
| 169 | // uint sendObject_text_changed_insert : 1; |
| 170 | uint sendObject_text_selection_changed : 1; |
| 171 | uint sendObject_value_changed : 1; |
| 172 | uint sendObject_visible_data_changed : 1; |
| 173 | |
| 174 | // we don't implement terminal |
| 175 | // terminal-application_changed/charwidth_changed/columncount_changed/line_changed/linecount_changed |
| 176 | uint sendWindow : 1; |
| 177 | uint sendWindow_activate : 1; |
| 178 | uint sendWindow_close: 1; |
| 179 | uint sendWindow_create : 1; |
| 180 | uint sendWindow_deactivate : 1; |
| 181 | // uint sendWindow_desktop_create : 1; |
| 182 | // uint sendWindow_desktop_destroy : 1; |
| 183 | uint sendWindow_lower : 1; |
| 184 | uint sendWindow_maximize : 1; |
| 185 | uint sendWindow_minimize : 1; |
| 186 | uint sendWindow_move : 1; |
| 187 | uint sendWindow_raise : 1; |
| 188 | uint sendWindow_reparent : 1; |
| 189 | uint sendWindow_resize : 1; |
| 190 | uint sendWindow_restore : 1; |
| 191 | uint sendWindow_restyle : 1; |
| 192 | uint sendWindow_shade : 1; |
| 193 | uint sendWindow_unshade : 1; |
| 194 | }; |
| 195 | |
| 196 | QT_END_NAMESPACE |
| 197 | |
| 198 | #endif |
| 199 | |