Coverage Report

Created: 2026-06-07 08:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qtbase/src/gui/accessible/qaccessible_base.h
Line
Count
Source
1
// Copyright (C) 2022 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
#ifndef QACCESSIBLE_BASE_H
5
#define QACCESSIBLE_BASE_H
6
7
#include <QtGui/qtguiglobal.h>
8
#if QT_CONFIG(accessibility)
9
10
#if 0
11
// QAccessible class is handled in qaccessible.h
12
#pragma qt_sync_stop_processing
13
#endif
14
15
#include <QtCore/qobjectdefs.h>
16
17
#include <cstring> // memset, memcmp
18
19
QT_BEGIN_NAMESPACE
20
21
class QAccessibleInterface;
22
class QAccessibleEvent;
23
class QTextCursor;
24
25
class Q_GUI_EXPORT QAccessible
26
{
27
    Q_GADGET
28
public:
29
30
    enum Event {
31
        SoundPlayed              = 0x0001,
32
        Alert                    = 0x0002,
33
        ForegroundChanged        = 0x0003,
34
        MenuStart                = 0x0004,
35
        MenuEnd                  = 0x0005,
36
        PopupMenuStart           = 0x0006,
37
        PopupMenuEnd             = 0x0007,
38
        ContextHelpStart         = 0x000C,
39
        ContextHelpEnd           = 0x000D,
40
        DragDropStart            = 0x000E,
41
        DragDropEnd              = 0x000F,
42
        DialogStart              = 0x0010,
43
        DialogEnd                = 0x0011,
44
        ScrollingStart           = 0x0012,
45
        ScrollingEnd             = 0x0013,
46
        ScrollingPositionChanged = 0x0014,
47
48
        MenuCommand          = 0x0018,
49
50
        // Values from IAccessible2
51
        ActionChanged                    = 0x0101,
52
        ActiveDescendantChanged          = 0x0102,
53
        AttributeChanged                 = 0x0103,
54
        DocumentContentChanged           = 0x0104,
55
        DocumentLoadComplete             = 0x0105,
56
        DocumentLoadStopped              = 0x0106,
57
        DocumentReload                   = 0x0107,
58
        HyperlinkEndIndexChanged         = 0x0108,
59
        HyperlinkNumberOfAnchorsChanged  = 0x0109,
60
        HyperlinkSelectedLinkChanged     = 0x010A,
61
        HypertextLinkActivated           = 0x010B,
62
        HypertextLinkSelected            = 0x010C,
63
        HyperlinkStartIndexChanged       = 0x010D,
64
        HypertextChanged                 = 0x010E,
65
        HypertextNLinksChanged           = 0x010F,
66
        ObjectAttributeChanged           = 0x0110,
67
        PageChanged                      = 0x0111,
68
        SectionChanged                   = 0x0112,
69
        TableCaptionChanged              = 0x0113,
70
        TableColumnDescriptionChanged    = 0x0114,
71
        TableColumnHeaderChanged         = 0x0115,
72
        TableModelChanged                = 0x0116,
73
        TableRowDescriptionChanged       = 0x0117,
74
        TableRowHeaderChanged            = 0x0118,
75
        TableSummaryChanged              = 0x0119,
76
        TextAttributeChanged             = 0x011A,
77
        TextCaretMoved                   = 0x011B,
78
        // TextChanged = 0x011C, is deprecated in IA2, use TextUpdated
79
        TextColumnChanged                = 0x011D,
80
        TextInserted                     = 0x011E,
81
        TextRemoved                      = 0x011F,
82
        TextUpdated                      = 0x0120,
83
        TextSelectionChanged             = 0x0121,
84
        VisibleDataChanged               = 0x0122,
85
86
        ObjectCreated        = 0x8000,
87
        ObjectDestroyed      = 0x8001,
88
        ObjectShow           = 0x8002,
89
        ObjectHide           = 0x8003,
90
        ObjectReorder        = 0x8004,
91
        Focus                = 0x8005,
92
        Selection            = 0x8006,
93
        SelectionAdd         = 0x8007,
94
        SelectionRemove      = 0x8008,
95
        SelectionWithin      = 0x8009,
96
        StateChanged         = 0x800A,
97
        LocationChanged      = 0x800B,
98
        NameChanged          = 0x800C,
99
        DescriptionChanged   = 0x800D,
100
        ValueChanged         = 0x800E,
101
        ParentChanged        = 0x800F,
102
        HelpChanged          = 0x80A0,
103
        DefaultActionChanged = 0x80B0,
104
        AcceleratorChanged   = 0x80C0,
105
        Announcement         = 0x80D0,
106
        IdentifierChanged    = 0x80E0,
107
        RoleChanged          = 0x80E1,
108
109
        // was declared after AcceleratorChanged, without explicit value
110
        InvalidEvent                    = AcceleratorChanged + 1,
111
    };
112
0
    Q_ENUM(Event)
Unexecuted instantiation: qt_getEnumMetaObject(QAccessible::Event)
Unexecuted instantiation: qt_getEnumName(QAccessible::Event)
113
0
114
0
    // 64 bit enums seem hard on some platforms (windows...)
115
0
    // which makes using a bit field a sensible alternative
116
0
    struct State {
117
0
        // http://msdn.microsoft.com/en-us/library/ms697270.aspx
118
0
        quint64 disabled : 1; // used to be Unavailable
119
0
        quint64 selected : 1;
120
0
        quint64 focusable : 1;
121
0
        quint64 focused : 1;
122
0
        quint64 pressed : 1;
123
0
        quint64 checkable : 1;
124
0
        quint64 checked : 1;
125
0
        quint64 checkStateMixed : 1; // used to be Mixed
126
0
        quint64 readOnly : 1;
127
0
        quint64 hotTracked : 1;
128
0
        quint64 defaultButton : 1;
129
0
        quint64 expanded : 1;
130
0
        quint64 collapsed : 1;
131
0
        quint64 busy : 1;
132
0
        quint64 expandable : 1;
133
0
        quint64 marqueed : 1;
134
0
        quint64 animated : 1;
135
0
        quint64 invisible : 1;
136
0
        quint64 offscreen : 1;
137
0
        quint64 sizeable : 1;
138
0
        quint64 movable : 1;
139
0
        quint64 selfVoicing : 1;
140
0
        quint64 selectable : 1;
141
0
        quint64 linked : 1;
142
0
        quint64 traversed : 1;
143
0
        quint64 multiSelectable : 1;
144
0
        quint64 extSelectable : 1;
145
0
        quint64 passwordEdit : 1; // used to be Protected
146
0
        quint64 hasPopup : 1;
147
0
        quint64 modal : 1;
148
0
149
0
        // IA2 - we chose to not add some IA2 states for now
150
0
        // Below the ones that seem helpful
151
0
        quint64 active : 1;
152
0
        quint64 invalid : 1; // = defunct
153
0
        quint64 editable : 1;
154
0
        quint64 multiLine : 1;
155
0
        quint64 selectableText : 1;
156
0
        quint64 supportsAutoCompletion : 1;
157
0
158
0
        quint64 searchEdit : 1;
159
0
160
0
        // quint64 invalidEntry : 1;
161
0
        // quint64 managesDescendants : 1;
162
0
        // quint64 singleLine : 1; // we have multi line, this is redundant.
163
0
        // quint64 stale : 1;
164
0
        // quint64 transient : 1;
165
0
        // quint64 pinned : 1;
166
0
167
0
        // Apple - see http://mattgemmell.com/2010/12/19/accessibility-for-iphone-and-ipad-apps/
168
0
        // quint64 playsSound : 1;
169
0
        // quint64 summaryElement : 1;
170
0
        // quint64 updatesFrequently : 1;
171
0
        // quint64 adjustable : 1;
172
0
        // more and not included here: http://developer.apple.com/library/mac/#documentation/UserExperience/Reference/Accessibility_RoleAttribute_Ref/Attributes.html
173
0
174
0
        // MSAA
175
0
        // quint64 alertLow : 1;
176
0
        // quint64 alertMedium : 1;
177
0
        // quint64 alertHigh : 1;
178
0
179
0
        Q_DECL_UNUSED_MEMBER quint64 qt_reserved : 27;
180
0
181
0
        State() {
182
0
            std::memset(this, 0, sizeof(State));
183
0
        }
184
        friend inline bool operator==(const QAccessible::State &first, const QAccessible::State &second)
185
0
        {
186
0
            static_assert(std::has_unique_object_representations_v<State>,
187
0
                          "memcmp() cannot be used on types with padding");
188
0
            return std::memcmp(&first, &second, sizeof(QAccessible::State)) == 0;
189
0
        }
190
    };
191
192
193
194
195
196
    enum Role {
197
        NoRole         = 0x00000000,
198
        TitleBar       = 0x00000001,
199
        MenuBar        = 0x00000002,
200
        ScrollBar      = 0x00000003,
201
        Grip           = 0x00000004,
202
        Sound          = 0x00000005,
203
        Cursor         = 0x00000006,
204
        Caret          = 0x00000007,
205
        AlertMessage   = 0x00000008,
206
        Window         = 0x00000009,
207
        Client         = 0x0000000A,
208
        PopupMenu      = 0x0000000B,
209
        MenuItem       = 0x0000000C,
210
        ToolTip        = 0x0000000D,
211
        Application    = 0x0000000E,
212
        Document       = 0x0000000F,
213
        Pane           = 0x00000010,
214
        Chart          = 0x00000011,
215
        Dialog         = 0x00000012,
216
        Border         = 0x00000013,
217
        Grouping       = 0x00000014,
218
        Separator      = 0x00000015,
219
        ToolBar        = 0x00000016,
220
        StatusBar      = 0x00000017,
221
        Table          = 0x00000018,
222
        ColumnHeader   = 0x00000019,
223
        RowHeader      = 0x0000001A,
224
        Column         = 0x0000001B,
225
        Row            = 0x0000001C,
226
        Cell           = 0x0000001D,
227
        Link           = 0x0000001E,
228
        HelpBalloon    = 0x0000001F,
229
        Assistant      = 0x00000020,
230
        List           = 0x00000021,
231
        ListItem       = 0x00000022,
232
        Tree           = 0x00000023,
233
        TreeItem       = 0x00000024,
234
        PageTab        = 0x00000025,
235
        PropertyPage   = 0x00000026,
236
        Indicator      = 0x00000027,
237
        Graphic        = 0x00000028,
238
        StaticText     = 0x00000029,
239
        EditableText   = 0x0000002A,  // Editable, selectable, etc.
240
        Button         = 0x0000002B,
241
#ifndef Q_QDOC
242
        PushButton     = Button, // deprecated
243
#endif
244
        CheckBox       = 0x0000002C,
245
        RadioButton    = 0x0000002D,
246
        ComboBox       = 0x0000002E,
247
        // DropList       = 0x0000002F,
248
        ProgressBar    = 0x00000030,
249
        Dial           = 0x00000031,
250
        HotkeyField    = 0x00000032,
251
        Slider         = 0x00000033,
252
        SpinBox        = 0x00000034,
253
        Canvas         = 0x00000035, // MSAA: ROLE_SYSTEM_DIAGRAM - The object represents a graphical image that is used to diagram data.
254
        Animation      = 0x00000036,
255
        Equation       = 0x00000037,
256
        ButtonDropDown = 0x00000038, // The object represents a button that expands a grid.
257
        ButtonMenu     = 0x00000039,
258
        ButtonDropGrid = 0x0000003A,
259
        Whitespace     = 0x0000003B, // The object represents blank space between other objects.
260
        PageTabList    = 0x0000003C,
261
        Clock          = 0x0000003D,
262
        Splitter       = 0x0000003E,
263
        // Reserved space in case MSAA roles needs to be added
264
265
        // Additional Qt roles where enum value does not map directly to MSAA:
266
        LayeredPane    = 0x00000080,
267
        Terminal       = 0x00000081,
268
        Desktop        = 0x00000082,
269
        Paragraph      = 0x00000083,
270
        WebDocument    = 0x00000084,
271
        Section        = 0x00000085,
272
        Notification   = 0x00000086,
273
        Switch         = 0x00000087,
274
275
        // IAccessible2 roles
276
        // IA2_ROLE_CANVAS = 0x401, // An object that can be drawn into and to manage events from the objects drawn into it
277
        // IA2_ROLE_CAPTION = 0x402,
278
        // IA2_ROLE_CHECK_MENU_ITEM = 0x403,
279
        ColorChooser = 0x404,
280
        // IA2_ROLE_DATE_EDITOR = 0x405,
281
        // IA2_ROLE_DESKTOP_ICON = 0x406,
282
        // IA2_ROLE_DESKTOP_PANE = 0x407,
283
        // IA2_ROLE_DIRECTORY_PANE = 0x408,
284
        // IA2_ROLE_EDITBAR = 0x409,
285
        // IA2_ROLE_EMBEDDED_OBJECT = 0x40A,
286
        // IA2_ROLE_ENDNOTE = 0x40B,
287
        // IA2_ROLE_FILE_CHOOSER = 0x40C,
288
        // IA2_ROLE_FONT_CHOOSER = 0x40D,
289
        Footer      = 0x40E,
290
        // IA2_ROLE_FOOTNOTE = 0x40F,
291
        Form        = 0x410,
292
        // some platforms (windows and at-spi) use Frame for regular windows
293
        // because window was taken for tool/dock windows by MSAA
294
        // Frame = 0x411,
295
        // IA2_ROLE_GLASS_PANE = 0x412,
296
        // IA2_ROLE_HEADER = 0x413,
297
        Heading  = 0x414,
298
        // IA2_ROLE_ICON = 0x415,
299
        // IA2_ROLE_IMAGE_MAP = 0x416,
300
        // IA2_ROLE_INPUT_METHOD_WINDOW = 0x417,
301
        // IA2_ROLE_INTERNAL_FRAME = 0x418,
302
        // IA2_ROLE_LABEL = 0x419,
303
        // IA2_ROLE_LAYERED_PANE = 0x41A,
304
        Note = 0x41B,
305
        // IA2_ROLE_OPTION_PANE = 0x41C,
306
        // IA2_ROLE_PAGE = 0x41D,
307
        // IA2_ROLE_PARAGRAPH = 0x42E,
308
        // IA2_ROLE_RADIO_MENU_ITEM = 0x41F,
309
        // IA2_ROLE_REDUNDANT_OBJECT = 0x420,
310
        // IA2_ROLE_ROOT_PANE = 0x421,
311
        // IA2_ROLE_RULER = 0x422,
312
        // IA2_ROLE_SCROLL_PANE = 0x423,
313
        // IA2_ROLE_SECTION = 0x424,
314
        // IA2_ROLE_SHAPE = 0x425,
315
        // IA2_ROLE_SPLIT_PANE = 0x426,
316
        // IA2_ROLE_TEAR_OFF_MENU = 0x427,
317
        // IA2_ROLE_TERMINAL = 0x428,
318
        // IA2_ROLE_TEXT_FRAME = 0x429,
319
        // IA2_ROLE_TOGGLE_BUTTON = 0x42A,
320
        // IA2_ROLE_VIEW_PORT = 0x42B,
321
        ComplementaryContent = 0x42C,
322
        // IA2_ROLE_LANDMARK = 0x42D,
323
        // IA2_ROLE_LEVEL_BAR = 0x42E,
324
        // IA2_ROLE_CONTENT_DELETION = 0x42F,
325
        // IA2_ROLE_CONTENT_INSERTION = 0x430,
326
        BlockQuote = 0x431,
327
        // IA2_ROLE_MARK = 0x432,
328
        // IA2_ROLE_SUGGESTION = 0x433,
329
        // IA2_ROLE_COMMENT = = 0x434,
330
331
        UserRole       = 0x0000ffff
332
    };
333
0
    Q_ENUM(Role)
Unexecuted instantiation: qt_getEnumMetaObject(QAccessible::Role)
Unexecuted instantiation: qt_getEnumName(QAccessible::Role)
334
0
335
0
    enum Text {
336
0
        Name         = 0,
337
0
        Description,
338
0
        Value,
339
0
        Help,
340
0
        Accelerator,
341
0
        DebugDescription,
342
0
        Identifier,
343
0
        UserText     = 0x0000ffff
344
0
    };
345
0
346
0
    enum RelationFlag {
347
0
        Label         = 0x00000001,
348
0
        Labelled      = 0x00000002,
349
0
        Controller    = 0x00000004,
350
0
        Controlled    = 0x00000008,
351
0
        DescriptionFor = 0x00000010,
352
0
        Described     = 0x00000020,
353
0
        FlowsFrom     = 0x00000040,
354
0
        FlowsTo       = 0x00000080,
355
0
        AllRelations  = 0xffffffff
356
0
    };
357
0
    Q_DECLARE_FLAGS(Relation, RelationFlag)
358
0
359
0
    enum InterfaceType
360
0
    {
361
0
        TextInterface,
362
0
        EditableTextInterface,
363
0
        ValueInterface,
364
0
        ActionInterface,
365
0
        ImageInterface,
366
0
        TableInterface,
367
0
        TableCellInterface,
368
0
        HyperlinkInterface,
369
0
        SelectionInterface,
370
0
        AttributesInterface,
371
0
        ViewportInterface,
372
0
    };
373
0
374
0
    enum TextBoundaryType {
375
0
        CharBoundary,
376
0
        WordBoundary,
377
0
        SentenceBoundary,
378
0
        ParagraphBoundary,
379
0
        LineBoundary,
380
0
        NoBoundary
381
0
    };
382
0
383
0
    enum class Attribute {
384
0
        Custom,
385
0
        Level,
386
0
        Locale,
387
0
        Orientation,
388
0
    };
389
0
    Q_ENUM(Attribute)
Unexecuted instantiation: qt_getEnumMetaObject(QAccessible::Attribute)
Unexecuted instantiation: qt_getEnumName(QAccessible::Attribute)
390
0
391
0
    enum class AnnouncementPoliteness {
392
0
        Polite,
393
0
        Assertive,
394
0
    };
395
0
    Q_ENUM(AnnouncementPoliteness)
Unexecuted instantiation: qt_getEnumMetaObject(QAccessible::AnnouncementPoliteness)
Unexecuted instantiation: qt_getEnumName(QAccessible::AnnouncementPoliteness)
396
0
397
0
    typedef QAccessibleInterface*(*InterfaceFactory)(const QString &key, QObject*);
398
0
    typedef void(*UpdateHandler)(QAccessibleEvent *event);
399
0
    typedef void(*RootObjectHandler)(QObject*);
400
0
401
0
    typedef unsigned Id;
402
0
403
0
    static void installFactory(InterfaceFactory);
404
0
    static void removeFactory(InterfaceFactory);
405
0
    static UpdateHandler installUpdateHandler(UpdateHandler);
406
0
    static RootObjectHandler installRootObjectHandler(RootObjectHandler);
407
0
408
0
    class Q_GUI_EXPORT ActivationObserver
409
0
    {
410
0
    public:
411
0
        virtual ~ActivationObserver();
412
0
        virtual void accessibilityActiveChanged(bool active) = 0;
413
0
    };
414
0
    static void installActivationObserver(ActivationObserver *);
415
0
    static void removeActivationObserver(ActivationObserver *);
416
0
417
0
    static QAccessibleInterface *queryAccessibleInterface(QObject *);
418
0
    static Id uniqueId(QAccessibleInterface *iface);
419
0
    static QAccessibleInterface *accessibleInterface(Id uniqueId);
420
0
    static Id registerAccessibleInterface(QAccessibleInterface *iface);
421
0
    static void deleteAccessibleInterface(Id uniqueId);
422
0
423
0
    static void updateAccessibility(QAccessibleEvent *event);
424
0
425
0
    static bool isActive();
426
0
    static void setActive(bool active);
427
0
    static void setRootObject(QObject *object);
428
0
429
0
    static void cleanup();
430
0
431
0
    static std::pair< int, int > qAccessibleTextBoundaryHelper(const QTextCursor &cursor, TextBoundaryType boundaryType);
432
0
433
0
private:
434
0
    static UpdateHandler updateHandler;
435
0
    static RootObjectHandler rootObjectHandler;
436
0
437
0
    QAccessible() {}
438
439
    friend class QAccessibleCache;
440
};
441
442
Q_DECLARE_OPERATORS_FOR_FLAGS(QAccessible::Relation)
Unexecuted instantiation: operator|(QAccessible::RelationFlag, QAccessible::RelationFlag)
Unexecuted instantiation: operator|(QAccessible::RelationFlag, QFlags<QAccessible::RelationFlag>)
Unexecuted instantiation: operator&(QAccessible::RelationFlag, QAccessible::RelationFlag)
Unexecuted instantiation: operator&(QAccessible::RelationFlag, QFlags<QAccessible::RelationFlag>)
Unexecuted instantiation: operator^(QAccessible::RelationFlag, QAccessible::RelationFlag)
Unexecuted instantiation: operator^(QAccessible::RelationFlag, QFlags<QAccessible::RelationFlag>)
Unexecuted instantiation: operator|(QAccessible::RelationFlag, int)
443
444
QT_END_NAMESPACE
445
446
#endif // QT_CONFIG(accessibility)
447
#endif // QACCESSIBLE_BASE_H