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
qaccessible_base.h
Go to the documentation of this file.
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
19QT_BEGIN_NAMESPACE
20
21class QAccessibleInterface;
22class QAccessibleEvent;
23class QTextCursor;
24
25class Q_GUI_EXPORT QAccessible
26{
27 Q_GADGET
28public:
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 Q_ENUM(Event)
113
114 // 64 bit enums seem hard on some platforms (windows...)
115 // which makes using a bit field a sensible alternative
116 struct State {
117 // http://msdn.microsoft.com/en-us/library/ms697270.aspx
118 quint64 disabled : 1; // used to be Unavailable
119 quint64 selected : 1;
120 quint64 focusable : 1;
121 quint64 focused : 1;
122 quint64 pressed : 1;
123 quint64 checkable : 1;
124 quint64 checked : 1;
125 quint64 checkStateMixed : 1; // used to be Mixed
126 quint64 readOnly : 1;
127 quint64 hotTracked : 1;
128 quint64 defaultButton : 1;
129 quint64 expanded : 1;
130 quint64 collapsed : 1;
131 quint64 busy : 1;
132 quint64 expandable : 1;
133 quint64 marqueed : 1;
134 quint64 animated : 1;
135 quint64 invisible : 1;
136 quint64 offscreen : 1;
137 quint64 sizeable : 1;
138 quint64 movable : 1;
139 quint64 selfVoicing : 1;
140 quint64 selectable : 1;
141 quint64 linked : 1;
142 quint64 traversed : 1;
143 quint64 multiSelectable : 1;
144 quint64 extSelectable : 1;
145 quint64 passwordEdit : 1; // used to be Protected
146 quint64 hasPopup : 1;
147 quint64 modal : 1;
148
149 // IA2 - we chose to not add some IA2 states for now
150 // Below the ones that seem helpful
151 quint64 active : 1;
152 quint64 invalid : 1; // = defunct
153 quint64 editable : 1;
154 quint64 multiLine : 1;
155 quint64 selectableText : 1;
156 quint64 supportsAutoCompletion : 1;
157
158 quint64 searchEdit : 1;
159
160 // quint64 invalidEntry : 1;
161 // quint64 managesDescendants : 1;
162 // quint64 singleLine : 1; // we have multi line, this is redundant.
163 // quint64 stale : 1;
164 // quint64 transient : 1;
165 // quint64 pinned : 1;
166
167 // Apple - see http://mattgemmell.com/2010/12/19/accessibility-for-iphone-and-ipad-apps/
168 // quint64 playsSound : 1;
169 // quint64 summaryElement : 1;
170 // quint64 updatesFrequently : 1;
171 // quint64 adjustable : 1;
172 // more and not included here: http://developer.apple.com/library/mac/#documentation/UserExperience/Reference/Accessibility_RoleAttribute_Ref/Attributes.html
173
174 // MSAA
175 // quint64 alertLow : 1;
176 // quint64 alertMedium : 1;
177 // quint64 alertHigh : 1;
178
179 Q_DECL_UNUSED_MEMBER quint64 qt_reserved : 27;
180
181 State() {
182 std::memset(this, 0, sizeof(State));
183 }
184 friend inline bool operator==(const QAccessible::State &first, const QAccessible::State &second)
185 {
186 static_assert(std::has_unique_object_representations_v<State>,
187 "memcmp() cannot be used on types with padding");
188 return std::memcmp(&first, &second, sizeof(QAccessible::State)) == 0;
189 }
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 Q_ENUM(Role)
334
335 enum Text {
336 Name = 0,
337 Description,
338 Value,
339 Help,
340 Accelerator,
341 DebugDescription,
342 Identifier,
343 UserText = 0x0000ffff
344 };
345
346 enum RelationFlag {
347 Label = 0x00000001,
348 Labelled = 0x00000002,
349 Controller = 0x00000004,
350 Controlled = 0x00000008,
351 DescriptionFor = 0x00000010,
352 Described = 0x00000020,
353 FlowsFrom = 0x00000040,
354 FlowsTo = 0x00000080,
355 AllRelations = 0xffffffff
356 };
357 Q_DECLARE_FLAGS(Relation, RelationFlag)
358
359 enum InterfaceType
360 {
361 TextInterface,
362 EditableTextInterface,
363 ValueInterface,
364 ActionInterface,
365 ImageInterface,
366 TableInterface,
367 TableCellInterface,
368 HyperlinkInterface,
369 SelectionInterface,
370 AttributesInterface,
371 ViewportInterface,
372 };
373
374 enum TextBoundaryType {
375 CharBoundary,
376 WordBoundary,
377 SentenceBoundary,
378 ParagraphBoundary,
379 LineBoundary,
380 NoBoundary
381 };
382
383 enum class Attribute {
384 Custom,
385 Level,
386 Locale,
387 Orientation,
388 };
389 Q_ENUM(Attribute)
390
391 enum class AnnouncementPoliteness {
392 Polite,
393 Assertive,
394 };
395 Q_ENUM(AnnouncementPoliteness)
396
397 typedef QAccessibleInterface*(*InterfaceFactory)(const QString &key, QObject*);
398 typedef void(*UpdateHandler)(QAccessibleEvent *event);
399 typedef void(*RootObjectHandler)(QObject*);
400
401 typedef unsigned Id;
402
403 static void installFactory(InterfaceFactory);
404 static void removeFactory(InterfaceFactory);
405 static UpdateHandler installUpdateHandler(UpdateHandler);
406 static RootObjectHandler installRootObjectHandler(RootObjectHandler);
407
408 class Q_GUI_EXPORT ActivationObserver
409 {
410 public:
411 virtual ~ActivationObserver();
412 virtual void accessibilityActiveChanged(bool active) = 0;
413 };
414 static void installActivationObserver(ActivationObserver *);
415 static void removeActivationObserver(ActivationObserver *);
416
417 static QAccessibleInterface *queryAccessibleInterface(QObject *);
418 static Id uniqueId(QAccessibleInterface *iface);
419 static QAccessibleInterface *accessibleInterface(Id uniqueId);
420 static Id registerAccessibleInterface(QAccessibleInterface *iface);
421 static void deleteAccessibleInterface(Id uniqueId);
422
423 static void updateAccessibility(QAccessibleEvent *event);
424
425 static bool isActive();
426 static void setActive(bool active);
427 static void setRootObject(QObject *object);
428
429 static void cleanup();
430
431 static std::pair< int, int > qAccessibleTextBoundaryHelper(const QTextCursor &cursor, TextBoundaryType boundaryType);
432
433private:
434 static UpdateHandler updateHandler;
435 static RootObjectHandler rootObjectHandler;
436
437 QAccessible() {}
438
439 friend class QAccessibleCache;
440};
441
442Q_DECLARE_OPERATORS_FOR_FLAGS(QAccessible::Relation)
443
444QT_END_NAMESPACE
445
446#endif // QT_CONFIG(accessibility)
447#endif // QACCESSIBLE_BASE_H