Coverage Report

Created: 2026-11-10 07:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qtbase/src/gui/accessible/qaccessible.cpp
Line
Count
Source
1
// Copyright (C) 2020 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
// Qt-Security score:critical reason:data-parser
4
5
#include "qaccessible.h"
6
7
#include "qaccessiblecache_p.h"
8
#include "qaccessibleplugin.h"
9
#include "qaccessibleobject.h"
10
#include "qaccessiblebridge.h"
11
#include <QtCore/qtextboundaryfinder.h>
12
#include <QtGui/qclipboard.h>
13
#include <QtGui/qguiapplication.h>
14
#include <QtGui/qtextcursor.h>
15
#include <private/qguiapplication_p.h>
16
#include <qpa/qplatformaccessibility.h>
17
#include <qpa/qplatformintegration.h>
18
19
#include <QtCore/qdebug.h>
20
#include <QtCore/qloggingcategory.h>
21
#include <QtCore/qmetaobject.h>
22
#include <QtCore/private/qmetaobject_p.h>
23
#include <QtCore/qhash.h>
24
#include <private/qfactoryloader_p.h>
25
26
QT_BEGIN_NAMESPACE
27
28
using namespace Qt::StringLiterals;
29
30
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core");
31
32
/*!
33
    \class QAccessible
34
    \brief The QAccessible class provides enums and static functions
35
    related to accessibility.
36
37
    \ingroup accessibility
38
    \inmodule QtGui
39
40
    This class is part of \l {Accessibility for QWidget Applications}.
41
42
    Accessible applications can be used by people who are not able to
43
    use applications by conventional means.
44
45
    The functions in this class are used for communication between
46
    accessible applications (also called AT Servers) and
47
    accessibility tools (AT Clients), such as screen readers and
48
    braille displays. Clients and servers communicate in the following way:
49
50
    \list
51
    \li  \e{AT Servers} notify the clients about events through calls to the
52
        updateAccessibility() function.
53
54
    \li  \e{AT Clients} request information about the objects in the server.
55
        The QAccessibleInterface class is the core interface, and encapsulates
56
        this information in a pure virtual API. Implementations of the interface
57
        are provided by Qt through the queryAccessibleInterface() API.
58
    \endlist
59
60
    The communication between servers and clients is initialized by
61
    the setRootObject() function. Function pointers can be installed
62
    to replace or extend the default behavior of the static functions
63
    in QAccessible.
64
65
    Qt supports Microsoft Active Accessibility (MSAA), \macos
66
    Accessibility, and the Unix/X11 AT-SPI standard. Other backends
67
    can be supported using QAccessibleBridge.
68
69
    In the Unix/X11 AT-SPI implementation, applications become accessible
70
    when two conditions are met:
71
    \list
72
    \li org.a11y.Status.IsEnabled DBus property is true
73
    \li org.a11y.Status.ScreenReaderEnabled DBus property is true
74
    \endlist
75
    An alternative to setting the DBus AT-SPI properties is to set
76
    the QT_LINUX_ACCESSIBILITY_ALWAYS_ON environment variable.
77
78
    In addition to QAccessible's static functions, Qt offers one
79
    generic interface, QAccessibleInterface, that can be used to wrap
80
    all widgets and objects (e.g., QPushButton). This single
81
    interface provides all the metadata necessary for the assistive
82
    technologies. Qt provides implementations of this interface for
83
    its built-in widgets as plugins.
84
85
    When you develop custom widgets, you can create custom subclasses
86
    of QAccessibleInterface and distribute them as plugins (using
87
    QAccessiblePlugin) or compile them into the application.
88
    Likewise, Qt's predefined accessibility support can be built as
89
    plugin (the default) or directly into the Qt library. The main
90
    advantage of using plugins is that the accessibility classes are
91
    only loaded into memory if they are actually used; they don't
92
    slow down the common case where no assistive technology is being
93
    used.
94
95
    Qt also includes two convenience classes, QAccessibleObject and
96
    QAccessibleWidget, that inherit from QAccessibleInterface and
97
    provide the lowest common denominator of metadata (e.g., widget
98
    geometry, window title, basic help text). You can use them as
99
    base classes when wrapping your custom QObject or QWidget
100
    subclasses.
101
102
    \sa QAccessibleInterface
103
*/
104
105
106
/*!
107
    \class QAccessible::State
108
109
    \inmodule QtGui
110
111
    This structure defines bit flags that indicate
112
    the state of an accessible object. The values are:
113
114
    \value active                  The object is the active window or the active sub-element in a container (that would get focus when focusing the container).
115
    \value adjustable              The object represents an adjustable value, e.g. sliders.
116
    \value animated                The object's appearance changes frequently.
117
    \value busy                    The object cannot accept input at the moment.
118
    \value checkable               The object is checkable.
119
    \value checked                 The object's check box is checked.
120
    \value checkStateMixed         The third state of checkboxes (half checked in tri-state check boxes).
121
    \value collapsed               The object is collapsed, e.g. a closed listview item, or an iconified window.
122
    \value defaultButton           The object represents the default button in a dialog.
123
    \value defunct                 The object no longer exists.
124
    \value editable                The object has a text carret (and often implements the text interface).
125
    \value expandable              The object is expandable, mostly used for cells in a tree view.
126
    \value expanded                The object is expanded, currently its children are visible.
127
    \value extSelectable           The object supports extended selection.
128
    \value focusable               The object can receive focus. Only objects in the active window can receive focus.
129
    \value focused                 The object has keyboard focus.
130
    \value hasPopup                The object opens a popup.
131
    \value hotTracked              The object's appearance is sensitive to the mouse cursor position.
132
    \value invalid                 The object is no longer valid (because it has been deleted).
133
    \value invisible               The object is not visible to the user.
134
    \value linked                  The object is linked to another object, e.g. a hyperlink.
135
    \value marqueed                The object displays scrolling contents, e.g. a log view.
136
    \value modal                   The object blocks input from other objects.
137
    \value movable                 The object can be moved.
138
    \value multiLine               The object has multiple lines of text (word wrap), as opposed to a single line.
139
    \value multiSelectable         The object supports multiple selected items.
140
    \value offscreen               The object is clipped by the visible area. Objects that are off screen are also invisible.
141
    \value passwordEdit            The object is a password field, e.g. a line edit for entering a Password.
142
    \value playsSound              The object produces sound when interacted with.
143
    \value pressed                 The object is pressed.
144
    \value readOnly                The object can usually be edited, but is explicitly set to read-only.
145
    \value searchEdit              The object is a line edit that is the input for search queries.
146
    \value selectable              The object is selectable.
147
    \value selectableText          The object has text which can be selected. This is different from selectable which refers to the object's children.
148
    \value selected                The object is selected, this is independent of text selection.
149
    \value selfVoicing             The object describes itself through speech or sound.
150
    \value sizeable                The object can be resized, e.g. top-level windows.
151
    \value summaryElement          The object summarizes the state of the window and should be treated with priority.
152
    \value supportsAutoCompletion  The object has auto-completion, for example in line edits or combo boxes.
153
    \value traversed               The object is linked and has been visited.
154
    \value updatesFrequently       The object changes frequently and needs to be refreshed when accessing it.
155
    \value disabled                The object is unavailable to the user, e.g. a disabled widget.
156
157
    Implementations of QAccessibleInterface::state() return a combination
158
    of these flags.
159
*/
160
161
/*!
162
    \fn QAccessible::State::State()
163
164
    Constructs a new QAccessible::State with all states set to false.
165
*/
166
167
/*!
168
    \enum QAccessible::Event
169
170
    This enum type defines accessible event types.
171
172
    \omitvalue InvalidEvent                 \omit Internal: Used when creating subclasses of QAccessibleEvent. \endomit
173
    \value AcceleratorChanged               The keyboard accelerator for an action has been changed.
174
    \value ActionChanged                    An action has been changed.
175
    \value ActiveDescendantChanged
176
    \value Alert                            A system alert (e.g., a message from a QMessageBox)
177
    \value [since 6.8] Announcement         The announcement of a message is requested.
178
    \value AttributeChanged
179
    \value ContextHelpEnd                   Context help (QWhatsThis) for an object is finished.
180
    \value ContextHelpStart                 Context help (QWhatsThis) for an object is initiated.
181
    \value DefaultActionChanged             The default QAccessible::Action for the accessible
182
                                            object has changed.
183
    \value DescriptionChanged               The object's QAccessible::Description changed.
184
    \value DialogEnd                        A dialog (QDialog) has been hidden
185
    \value DialogStart                      A dialog (QDialog) has been set visible.
186
    \value DocumentContentChanged           The contents of a text document have changed.
187
    \value DocumentLoadComplete             A document has been loaded.
188
    \value DocumentLoadStopped              A document load has been stopped.
189
    \value DocumentReload                   A document reload has been initiated.
190
    \value DragDropEnd                      A drag and drop operation is about to finished.
191
    \value DragDropStart                    A drag and drop operation is about to be initiated.
192
    \value Focus                            An object has gained keyboard focus.
193
    \value ForegroundChanged                A window has been activated (i.e., a new window has
194
                                            gained focus on the desktop).
195
    \value HelpChanged                      The QAccessible::Help text property of an object has
196
                                            changed.
197
    \value HyperlinkEndIndexChanged         The end position of the display text for a hypertext
198
                                            link has changed.
199
    \value HyperlinkNumberOfAnchorsChanged  The number of anchors in a hypertext link has changed,
200
                                            perhaps because the display text has been split to
201
                                            provide more than one link.
202
    \value HyperlinkSelectedLinkChanged     The link for the selected hypertext link has changed.
203
    \value HyperlinkStartIndexChanged       The start position of the display text for a hypertext
204
                                            link has changed.
205
    \value HypertextChanged                 The display text for a hypertext link has changed.
206
    \value HypertextLinkActivated           A hypertext link has been activated, perhaps by being
207
                                            clicked or via a key press.
208
    \value HypertextLinkSelected            A hypertext link has been selected.
209
    \value HypertextNLinksChanged
210
    \value [since 6.8] IdentifierChanged    The identifier of an object has changed.
211
    \value LocationChanged                  An object's location on the screen has changed.
212
    \value MenuCommand                      A menu item is triggered.
213
    \value MenuEnd                          A menu has been closed (Qt uses PopupMenuEnd for all
214
                                            menus).
215
    \value MenuStart                        A menu has been opened on the menubar (Qt uses
216
                                            PopupMenuStart for all menus).
217
    \value NameChanged                      The QAccessible::Name property of an object has changed.
218
    \value ObjectAttributeChanged
219
    \value ObjectCreated                    A new object is created.
220
    \value ObjectDestroyed                  An object is deleted.
221
    \value ObjectHide                       An object is hidden; for example, with QWidget::hide().
222
                                            Any children the object that is hidden has do not send
223
                                            this event. It is not sent when an object is hidden as
224
                                            it is being obscured by others.
225
    \value ObjectReorder                    A layout or item view  has added, removed, or moved an
226
                                            object (Qt does not use this event).
227
    \value ObjectShow                       An object is displayed; for example, with
228
                                            QWidget::show().
229
    \value PageChanged
230
    \value ParentChanged                    An object's parent object changed.
231
    \value PopupMenuEnd                     A pop-up menu has closed.
232
    \value PopupMenuStart                   A pop-up menu has opened.
233
    \value [since 6.11] RoleChanged         The role of an object has changed.
234
    \value ScrollingEnd                     A scrollbar scroll operation has ended (the mouse has
235
                                            released the slider handle).
236
    \value ScrollingStart                   A scrollbar scroll operation is about to start; this may
237
                                            be caused by a mouse press on the slider handle, for
238
                                            example.
239
    \value [since 6.12] ScrollingPositionChanged
240
                                            The position changed during a scroll operation.
241
    \value SectionChanged
242
    \value SelectionAdd                     An item has been added to the selection in an item view.
243
    \value SelectionRemove                  An item has been removed from an item view selection.
244
    \value Selection                        The selection has changed in a menu or item view.
245
    \value SelectionWithin                  Several changes to a selection has occurred in an item
246
                                            view.
247
    \value SoundPlayed                      A sound has been played by an object
248
    \omitvalue StateChanged                 \omit The QAccessible::State of an object has changed.
249
                                            This value is used internally for the QAccessibleStateChangeEvent. \endomit
250
    \value TableCaptionChanged              A table caption has been changed.
251
    \value TableColumnDescriptionChanged    The description of a table column, typically found in
252
                                            the column's header, has been changed.
253
    \value TableColumnHeaderChanged         A table column header has been changed.
254
    \omitvalue TableModelChanged            \omit The model providing data for a table has been changed. \endomit
255
    \value TableRowDescriptionChanged       The description of a table row, typically found in the
256
                                            row's header, has been changed.
257
    \value TableRowHeaderChanged            A table row header has been changed.
258
    \value TableSummaryChanged              The summary of a table has been changed.
259
    \omitvalue TextAttributeChanged
260
    \omitvalue TextCaretMoved               \omit The caret has moved in an editable widget.
261
                                            The caret represents the cursor position in an editable
262
                                            widget with the input focus. \endomit
263
    \value TextColumnChanged                A text column has been changed.
264
    \omitvalue TextInserted                 \omit Text has been inserted into an editable widget. \endomit
265
    \omitvalue TextRemoved                  \omit Text has been removed from an editable widget. \endomit
266
    \omitvalue TextSelectionChanged         \omit The selected text has changed in an editable widget. \endomit
267
    \omitvalue TextUpdated                  \omit The text has been update in an editable widget. \endomit
268
    \omitvalue ValueChanged                 \omit The QAccessible::Value of an object has changed. \endomit
269
    \value VisibleDataChanged
270
271
    The values for this enum are defined to be the same as those defined in the
272
    \l{AccessibleEventID.idl File Reference}{IAccessible2} and
273
    \l{Microsoft Active Accessibility Event Constants}{MSAA} specifications.
274
*/
275
276
/*!
277
    \enum QAccessible::Role
278
279
    This enum defines the role of an accessible object. The roles are:
280
281
    \value AlertMessage     An object that is used to alert the user.
282
    \value Animation        An object that displays an animation.
283
    \value Application      An object that represents the application
284
    \value Assistant        An object that provides interactive help.
285
    \value [since 6.9] BlockQuote       A section of content that is quoted from another source.
286
    \value Border           An object that represents a border.
287
    \value ButtonDropDown   A button that drops down a list of items.
288
    \value ButtonDropGrid   A button that drops down a grid.
289
    \value ButtonMenu       A button that drops down a menu.
290
    \value Canvas           An object that displays graphics that the user can interact with.
291
    \value Caret            An object that represents the system caret (text cursor).
292
    \value Cell             A cell in a table.
293
    \value Chart            An object that displays a graphical representation of data.
294
    \value CheckBox         An object that represents an option that can be checked or unchecked. Some options provide a "mixed" state, e.g. neither checked nor unchecked.
295
    \value Client           The client area in a window.
296
    \value Clock            A clock displaying time.
297
    \value ColorChooser     A dialog that lets the user choose a color.
298
    \value Column           A column of cells, usually within a table.
299
    \value ColumnHeader     A header for a column of data.
300
    \value ComboBox         A list of choices that the user can select from.
301
    \value ComplementaryContent A part of the document or web page that is complementary to the main content, usually a landmark (see WAI-ARIA).
302
    \value Cursor           An object that represents the mouse cursor.
303
    \value Desktop          The object represents the desktop or workspace.
304
    \value Dial             An object that represents a dial or knob.
305
    \value Dialog           A dialog box.
306
    \value Document         A document, for example in an office application.
307
    \value EditableText     Editable text such as a line or text edit.
308
    \value Equation         An object that represents a mathematical equation.
309
    \value Footer           A footer in a page (usually in documents).
310
    \value Form             A web form containing controls.
311
    \value Graphic          A graphic or picture, e.g. an icon.
312
    \value Grip             A grip that the user can drag to change the size of widgets.
313
    \value Grouping         An object that represents a logical grouping of other objects.
314
    \value Heading          A heading in a document.
315
    \value HelpBalloon      An object that displays help in a separate, short lived window.
316
    \value HotkeyField      A hotkey field that allows the user to enter a key sequence.
317
    \value Indicator        An indicator that represents a current value or item.
318
    \value LayeredPane      An object that can contain layered children, e.g. in a stack.
319
    \value Link             A link to something else.
320
    \value List             A list of items, from which the user can select one or more items.
321
    \value ListItem         An item in a list of items.
322
    \value MenuBar          A menu bar from which menus are opened by the user.
323
    \value MenuItem         An item in a menu or menu bar.
324
    \value NoRole           The object has no role. This usually indicates an invalid object.
325
    \value Note             A section whose content is parenthetic or ancillary to the main content of the resource.
326
    \value Notification     An object that represents a notification (e.g. in the system tray). This role only has an effect on Linux.
327
    \value PageTab          A page tab that the user can select to switch to a different page in a dialog.
328
    \value PageTabList      A list of page tabs.
329
    \value Paragraph        A paragraph of text (usually found in documents).
330
    \value Pane             A generic container.
331
    \value PopupMenu        A menu which lists options that the user can select to perform an action.
332
    \value ProgressBar      The object displays the progress of an operation in progress.
333
    \value PropertyPage     A property page where the user can change options and settings.
334
    \value Button           A button.
335
    \value RadioButton      An object that represents an option that is mutually exclusive with other options.
336
    \value Row              A row of cells, usually within a table.
337
    \value RowHeader        A header for a row of data.
338
    \value ScrollBar        A scroll bar, which allows the user to scroll the visible area.
339
    \value Section          A section (in a document).
340
    \value Separator        A separator that divides space into logical areas.
341
    \value Slider           A slider that allows the user to select a value within a given range.
342
    \value Sound            An object that represents a sound.
343
    \value SpinBox          A spin box widget that allows the user to enter a value within a given range.
344
    \value Splitter         A splitter distributing available space between its child widgets.
345
    \value StaticText       Static text, such as labels for other widgets.
346
    \value StatusBar        A status bar.
347
    \value [since 6.11] Switch  A switch that can be toggled on or off.
348
    \value Table            A table representing data in a grid of rows and columns.
349
    \value Terminal         A terminal or command line interface.
350
    \value TitleBar         The title bar caption of a window.
351
    \value ToolBar          A tool bar, which groups widgets that the user accesses frequently.
352
    \value ToolTip          A tool tip which provides information about other objects.
353
    \value Tree             A list of items in a tree structure.
354
    \value TreeItem         An item in a tree structure.
355
    \value UserRole         The first value to be used for user defined roles.
356
    \value WebDocument      HTML document, usually in a browser.
357
    \value Whitespace       Blank space between other objects.
358
    \value Window           A top level window.
359
*/
360
361
/*!
362
    \enum QAccessible::RelationFlag
363
364
    This enum type defines bit flags that can be combined to indicate
365
    the relationship between two accessible objects. It is used by
366
    the relations() function, which returns a list of all the related
367
    interfaces of the calling object, together with the relations
368
    for each object.
369
370
    Each entry in the list is a std::pair where the \c second member stores
371
    the relation type(s) between the \c returned object represented by the
372
    \c first member and the \c origin (the caller) interface/object.
373
374
    In the table below, the \c returned object refers to the object in
375
    the returned list, and the \c origin object is the one represented
376
    by the calling interface.
377
378
    \value Label                        The \c returned object is the label for the \c origin object.
379
    \value Labelled                     The \c returned object is labelled by the \c origin object.
380
    \value Controller                   The \c returned object controls the \c origin object.
381
    \value Controlled                   The \c returned object is controlled by the \c origin object.
382
    \value [since 6.6] DescriptionFor   The \c returned object provides a description for the \c origin object.
383
    \value [since 6.6] Described        The \c returned object is described by the \c origin object.
384
    \value [since 6.6] FlowsFrom        Content logically flows from the \c returned object to the \c origin object.
385
    \value [since 6.6] FlowsTo          Content logically flows to the \c returned object from the \c origin object.
386
    \value AllRelations                 Used as a mask to specify that we are interesting in information
387
                                        about all relations
388
389
    Implementations of relations() return a combination of these flags.
390
    Some values are mutually exclusive.
391
*/
392
393
/*!
394
    \enum QAccessible::Text
395
396
    This enum specifies string information that an accessible object
397
    returns.
398
399
    \value Name                    The name of the object. This can be used both
400
                                   as an identifier or a short description by
401
                                   accessible clients.
402
    \value Description             A short text describing the object.
403
    \value Value                   The value of the object.
404
    \value Help                    A longer text giving information about how to use the object.
405
    \value Accelerator             The keyboard shortcut that executes the object's default action.
406
    \value UserText                The first value to be used for user defined text.
407
    \value [since 6.8] Identifier  An identifier for the object for e.g. UI tests.
408
    \omitvalue DebugDescription
409
*/
410
411
/*! \enum QAccessible::TextBoundaryType
412
    This enum describes different types of text boundaries. It follows the IAccessible2 API and is used in the \l QAccessibleTextInterface.
413
414
    \value CharBoundary         Use individual characters as boundary.
415
    \value WordBoundary         Use words as boundaries.
416
    \value SentenceBoundary     Use sentences as boundary.
417
    \value ParagraphBoundary    Use paragraphs as boundary.
418
    \value LineBoundary         Use newlines as boundary.
419
    \value NoBoundary           No boundary (use the whole text).
420
421
    \sa QAccessibleTextInterface
422
*/
423
424
/*! \enum QAccessible::Attribute
425
    This enum describes different types of attributes used by the
426
    \l QAccessibleAttributesInterface.
427
    \since 6.8
428
429
    These attributes are comparable to the concept of properties/(object)
430
    attributes found in ARIA, AT-SPI2, IAccessible, UIA and NSAccessibility
431
    and are mapped to their platform counterpart where applicable.
432
433
    Each attribute is handled as a key-value pair, with the values of this
434
    enumeration being used as keys.
435
436
    Attribute values are represented in a \l QVariant. The type of the value
437
    stored in the \l QVariant is fixed and specified below for each of the
438
    attribute types.
439
440
    \value Custom               value type: \a QHash<QString, QString>
441
                                The \a Custom attribute is special in that
442
                                it can effectively represent multiple attributes at
443
                                once, since it itself is a \l QHash used to represent
444
                                key-value pairs.
445
                                For platforms supporting custom key-value pairs for
446
                                attributes, those set in the \a Custom attribute
447
                                are bridged to the platform layer without applying any
448
                                translation to platform-specific attributes. In general,
449
                                the other, more strongly typed attributes should be used.
450
                                This attribute can e.g. be used for prototyping
451
                                before officially adding an official new enumeration value
452
                                for a specific feature.
453
    \value Level                value type: \a int
454
                                Defines the hierarchical level of an element within a structure,
455
                                e.g. the heading level of a heading. This attribute conceptually
456
                                matches the "aria-level" property in ARIA.
457
    \value [since 6.10] Locale  value type: \a QLocale
458
                                Locale of the element.
459
                                This can be used to specify that an element has a locale that
460
                                differs from the application's default locale, e.g. for documents
461
                                or paragraphs within a document that use a language that differs
462
                                from the application's user interface language.
463
    \value [since 6.11] Orientation value type: \a Qt::Orientation
464
                                Orientation of the element. This attribute conceptually matches
465
                                the "aria-orientation" property in ARIA.
466
    \value [since 6.13] PositionInSet value type: \a int
467
                                1-based position of the element within the set of elements it
468
                                belongs to, e.g. the position of an item in a list or of a radio
469
                                button in its group. Together with \a SizeOfSet, this lets
470
                                assistive technologies announce e.g. "item 2 of 10". This
471
                                attribute conceptually matches the "aria-posinset" property
472
                                in ARIA.
473
    \value [since 6.13] SizeOfSet value type: \a int
474
                                Number of elements in the set of elements the element belongs
475
                                to. This attribute conceptually matches the "aria-setsize"
476
                                property in ARIA.
477
478
    \sa QAccessibleAttributesInterface
479
*/
480
481
/*! \enum QAccessible::AnnouncementPoliteness
482
    This enum describes the priority for announcements used by the
483
    \l QAccessibleAnnouncementEvent.
484
    \since 6.8
485
486
    With \a QAccessible::AnouncementPoliteness::Polite, assistive technologies
487
    should announce the message at the next graceful opportunity such as at the
488
    end of speaking the current sentence or when the user pauses typing. A
489
    polite announcement might still interrupt an ongoing polite announcement.
490
491
    When specifying \a QAccessible::AnouncementPoliteness::Assertive, assistive
492
    technologies should notify the user immediately.
493
494
    Because an interruption might disorient users or cause them to not complete
495
    their current task, \a QAccessible::AnouncementPoliteness::Assertive should
496
    not be used unless the interruption is imperative.
497
498
    \value Polite      The announcement has normal priority.
499
    \value Assertive   The announcement has high priority and should notify
500
                       the user immediately, even if that means interrupting the user's
501
                       current task.
502
503
    \sa QAccessibleAnnouncementEvent
504
*/
505
506
507
/*!
508
    \enum QAccessible::InterfaceType
509
510
    \l QAccessibleInterface supports several sub interfaces.
511
    In order to provide more information about some objects, their accessible
512
    representation should implement one or more of these interfaces.
513
514
    \note When subclassing one of these interfaces, \l QAccessibleInterface::interface_cast() needs to be implemented.
515
516
    \value TextInterface            For text that supports selections or is more than one line. Simple labels do not need to implement this interface.
517
    \omitvalue EditableTextInterface    \omit For text that can be edited by the user. \endomit
518
    \value ValueInterface           For objects that are used to manipulate a value, for example slider or scroll bar.
519
    \value ActionInterface          For interactive objects that allow the user to trigger an action. Basically everything that allows for example mouse interaction.
520
    \omitvalue ImageInterface       \omit For objects that represent an image. This interface is generally less important. \endomit
521
    \value TableInterface           For lists, tables and trees.
522
    \value TableCellInterface       For cells in a TableInterface object.
523
    \value HyperlinkInterface       For hyperlink nodes (usually embedded as children of text nodes)
524
    \value [since 6.5] SelectionInterface For non-text objects that support selection of child objects.
525
    \value [since 6.8] AttributesInterface For objects that support object-specific attributes.
526
    \value [since 6.12] ViewportInterface For objects that allow 2-dimensional or indexed scrolling.
527
528
    \sa QAccessibleInterface::interface_cast(), QAccessibleTextInterface, QAccessibleValueInterface, QAccessibleActionInterface, QAccessibleTableInterface, QAccessibleTableCellInterface, QAccessibleSelectionInterface, QAccessibleAttributesInterface, QAccessibleViewportInterface
529
*/
530
531
#if QT_CONFIG(accessibility)
532
533
/*!
534
    Destroys the QAccessibleInterface.
535
*/
536
QAccessibleInterface::~QAccessibleInterface()
537
0
{
538
0
}
539
540
/*!
541
    \typedef QAccessible::Id
542
543
    Synonym for unsigned, used by the QAccessibleInterface cache.
544
*/
545
546
547
/* accessible widgets plugin discovery stuff */
548
Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, acLoader,
549
    (QAccessibleFactoryInterface_iid, "/accessible"_L1))
550
typedef QHash<QString, QAccessiblePlugin*> QAccessiblePluginsHash;
551
Q_GLOBAL_STATIC(QAccessiblePluginsHash, qAccessiblePlugins)
552
553
// FIXME turn this into one global static struct
554
Q_GLOBAL_STATIC(QList<QAccessible::InterfaceFactory>, qAccessibleFactories)
555
Q_GLOBAL_STATIC(QList<QAccessible::ActivationObserver *>, qAccessibleActivationObservers)
556
557
QAccessible::UpdateHandler QAccessible::updateHandler = nullptr;
558
QAccessible::RootObjectHandler QAccessible::rootObjectHandler = nullptr;
559
560
static bool cleanupAdded = false;
561
562
static QPlatformAccessibility *platformAccessibility()
563
0
{
564
0
    QPlatformIntegration *pfIntegration = QGuiApplicationPrivate::platformIntegration();
565
0
    return pfIntegration ? pfIntegration->accessibility() : nullptr;
566
0
}
567
568
/*!
569
    \fn QAccessible::QAccessible()
570
    \internal
571
572
    This class is purely a collection of enums and static functions,
573
    it is not supposed to be instantiated.
574
*/
575
576
577
/*!
578
    \internal
579
*/
580
void QAccessible::cleanup()
581
0
{
582
0
    if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
583
0
        pfAccessibility->cleanup();
584
0
}
585
586
static void qAccessibleCleanup()
587
0
{
588
0
    qAccessibleActivationObservers()->clear();
589
0
    qAccessibleFactories()->clear();
590
0
}
591
592
/*!
593
    \typedef QAccessible::InterfaceFactory
594
595
    This is a typedef for a pointer to a function with the following
596
    signature:
597
598
    \snippet code/src_gui_accessible_qaccessible.cpp 1
599
600
    The function receives a QString and a QObject pointer, where the
601
    QString is the key identifying the interface. The QObject is used
602
    to pass on to the QAccessibleInterface so that it can hold a reference
603
    to it.
604
605
    If the key and the QObject does not have a corresponding
606
    QAccessibleInterface, \nullptr will be returned.
607
608
    Installed factories are called by queryAccessibilityInterface() until
609
    one provides an interface.
610
*/
611
612
/*!
613
    \typedef QAccessible::UpdateHandler
614
615
    \internal
616
617
    A function pointer type. Use a function with this prototype to install
618
    your own update function.
619
620
    The function is called by updateAccessibility().
621
*/
622
623
/*!
624
    \typedef QAccessible::RootObjectHandler
625
626
    \internal
627
628
    A function pointer type. Use a function with this prototype to install
629
    your own root object handler.
630
631
    The function is called by setRootObject().
632
*/
633
634
635
/*!
636
    Installs the InterfaceFactory \a factory. The last factory added
637
    is the first one used by queryAccessibleInterface().
638
*/
639
void QAccessible::installFactory(InterfaceFactory factory)
640
0
{
641
0
    if (!factory)
642
0
        return;
643
644
0
    if (!cleanupAdded) {
645
0
        qAddPostRoutine(qAccessibleCleanup);
646
0
        cleanupAdded = true;
647
0
    }
648
0
    if (qAccessibleFactories()->contains(factory))
649
0
        return;
650
0
    qAccessibleFactories()->append(factory);
651
0
}
652
653
/*!
654
    Removes \a factory from the list of installed InterfaceFactories.
655
*/
656
void QAccessible::removeFactory(InterfaceFactory factory)
657
0
{
658
0
    qAccessibleFactories()->removeAll(factory);
659
0
}
660
661
/*!
662
    \internal
663
664
    Installs the given \a handler as the function to be used by
665
    updateAccessibility(), and returns the previously installed
666
    handler.
667
*/
668
QAccessible::UpdateHandler QAccessible::installUpdateHandler(UpdateHandler handler)
669
0
{
670
0
    UpdateHandler old = updateHandler;
671
0
    updateHandler = handler;
672
0
    return old;
673
0
}
674
675
/*!
676
    \internal
677
678
    Installs the given \a handler as the function to be used by setRootObject(),
679
    and returns the previously installed handler.
680
*/
681
QAccessible::RootObjectHandler QAccessible::installRootObjectHandler(RootObjectHandler handler)
682
0
{
683
0
    RootObjectHandler old = rootObjectHandler;
684
0
    rootObjectHandler = handler;
685
0
    return old;
686
0
}
687
688
/*!
689
    \class QAccessible::ActivationObserver
690
    \internal
691
692
    Interface to listen to activation or deactivation of the accessibility framework.
693
    \sa installActivationObserver()
694
*/
695
696
QAccessible::ActivationObserver::~ActivationObserver()
697
0
{
698
0
}
699
700
/*!
701
    \internal
702
703
    Install \a observer to get notified of activation or deactivation (global accessibility has been enabled or disabled).
704
*/
705
void QAccessible::installActivationObserver(QAccessible::ActivationObserver *observer)
706
0
{
707
0
    if (!observer)
708
0
        return;
709
710
0
    if (!cleanupAdded) {
711
0
        qAddPostRoutine(qAccessibleCleanup);
712
0
        cleanupAdded = true;
713
0
    }
714
0
    if (qAccessibleActivationObservers()->contains(observer))
715
0
        return;
716
0
    qAccessibleActivationObservers()->append(observer);
717
718
    // Make sure the newly added observer gets a callback on the next
719
    // QPlatformAccessibility::setActive() callback
720
0
    if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
721
0
        pfAccessibility->clearActiveNotificationState();
722
0
}
723
724
/*!
725
    \internal
726
727
    Remove an \a observer to no longer get notified of state changes.
728
    \sa installActivationObserver()
729
*/
730
void QAccessible::removeActivationObserver(ActivationObserver *observer)
731
0
{
732
0
    qAccessibleActivationObservers()->removeAll(observer);
733
0
}
734
735
/*!
736
    \internal
737
738
    Sends accessibility activation notifications to all registered observers.
739
*/
740
void qAccessibleNotifyActivationObservers(bool active)
741
0
{
742
0
    for (int i = 0; i < qAccessibleActivationObservers()->size(); ++i)
743
0
        qAccessibleActivationObservers()->at(i)->accessibilityActiveChanged(active);
744
0
}
745
746
/*!
747
    If a QAccessibleInterface implementation exists for the given \a object,
748
    this function returns a pointer to the implementation; otherwise it
749
    returns \nullptr.
750
751
    The function calls all installed factory functions (from most
752
    recently installed to least recently installed) until one is found
753
    that provides an interface for the class of \a object. If no
754
    factory can provide an accessibility implementation for the class
755
    the function loads installed accessibility plugins, and tests if
756
    any of the plugins can provide the implementation.
757
758
    If no implementation for the object's class is available, the
759
    function tries to find an implementation for the object's parent
760
    class, using the above strategy.
761
762
    All interfaces are managed by an internal cache and should not be deleted.
763
*/
764
QAccessibleInterface *QAccessible::queryAccessibleInterface(QObject *object)
765
0
{
766
0
    if (!object)
767
0
        return nullptr;
768
769
0
    if (Id id = QAccessibleCache::instance()->idForObject(object))
770
0
        return QAccessibleCache::instance()->interfaceForId(id);
771
772
    // Create a QAccessibleInterface for the object class. Start by the most
773
    // derived class and walk up the class hierarchy.
774
0
    const QMetaObject *mo = object->metaObject();
775
0
    const auto *objectPriv = QObjectPrivate::get(object);
776
    /*
777
     We do not want to cache each and every QML metaobject (Button_QMLTYPE_124,
778
     Button_QMLTYPE_125, etc.). Those dynamic metaobjects shouldn't have an
779
     accessible interface in any case. Instead, we start the whole checking
780
     with the first non-dynamic meta-object. To avoid potential regressions
781
     in other areas of Qt that also use dynamic metaobjects, we only do this
782
     for objects that are QML-related (approximated by checking whether they
783
     have ddata set).
784
    */
785
0
    const bool qmlRelated = !objectPriv->isDeletingChildren &&
786
0
                            objectPriv->declarativeData;
787
0
    while (qmlRelated && mo) {
788
0
        auto mop = QMetaObjectPrivate::get(mo);
789
0
        if (!mop || !(mop->flags & DynamicMetaObject))
790
0
            break;
791
792
0
        mo = mo->superClass();
793
0
    };
794
0
    while (mo) {
795
0
        const QString cn = QLatin1StringView(mo->className());
796
797
        // Check if the class has a InterfaceFactory installed.
798
0
        for (int i = qAccessibleFactories()->size(); i > 0; --i) {
799
0
            InterfaceFactory factory = qAccessibleFactories()->at(i - 1);
800
0
            if (QAccessibleInterface *iface = factory(cn, object)) {
801
0
                QAccessibleCache::instance()->insert(object, iface);
802
0
                Q_ASSERT(QAccessibleCache::instance()->containsObject(object));
803
0
                return iface;
804
0
            }
805
0
        }
806
        // Find a QAccessiblePlugin (factory) for the class name. If there's
807
        // no entry in the cache try to create it using the plugin loader.
808
0
        if (!qAccessiblePlugins()->contains(cn)) {
809
0
            QAccessiblePlugin *factory = nullptr; // 0 means "no plugin found". This is cached as well.
810
0
            const int index = acLoader()->indexOf(cn);
811
0
            if (index != -1)
812
0
                factory = qobject_cast<QAccessiblePlugin *>(acLoader()->instance(index));
813
0
            qAccessiblePlugins()->insert(cn, factory);
814
0
        }
815
816
        // At this point the cache should contain a valid factory pointer or 0:
817
0
        Q_ASSERT(qAccessiblePlugins()->contains(cn));
818
0
        QAccessiblePlugin *factory = qAccessiblePlugins()->value(cn);
819
0
        if (factory) {
820
0
            QAccessibleInterface *result = factory->create(cn, object);
821
0
            if (result) {
822
0
                QAccessibleCache::instance()->insert(object, result);
823
0
                Q_ASSERT(QAccessibleCache::instance()->containsObject(object));
824
0
            }
825
0
            return result;
826
0
        }
827
0
        mo = mo->superClass();
828
0
    }
829
830
0
    if (object == qApp) {
831
0
        QAccessibleInterface *appInterface = new QAccessibleApplication;
832
0
        QAccessibleCache::instance()->insert(object, appInterface);
833
0
        Q_ASSERT(QAccessibleCache::instance()->containsObject(qApp));
834
0
        return appInterface;
835
0
    }
836
837
0
    return nullptr;
838
0
}
839
840
/*!
841
    \brief Call this function to ensure that manually created interfaces
842
    are properly memory managed.
843
844
    Must only be called exactly once per interface \a iface.
845
    This is implicitly called when calling queryAccessibleInterface,
846
    calling this function is only required when QAccessibleInterfaces
847
    are instantiated with the "new" operator. This is not recommended,
848
    whenever possible use the default functions and let \l queryAccessibleInterface()
849
    take care of this.
850
851
    When it is necessary to reimplement the QAccessibleInterface::child() function
852
    and returning the child after constructing it, this function needs to be called.
853
 */
854
QAccessible::Id QAccessible::registerAccessibleInterface(QAccessibleInterface *iface)
855
0
{
856
0
    Q_ASSERT(iface);
857
0
    return QAccessibleCache::instance()->insert(iface->object(), iface);
858
0
}
859
860
/*!
861
    Removes the interface belonging to this \a id from the cache and
862
    deletes it. The id becomes invalid an may be re-used by the
863
    cache.
864
*/
865
void QAccessible::deleteAccessibleInterface(Id id)
866
0
{
867
0
    QAccessibleCache::instance()->deleteInterface(id);
868
0
}
869
870
/*!
871
    Returns the unique ID for the QAccessibleInterface \a iface.
872
*/
873
QAccessible::Id QAccessible::uniqueId(QAccessibleInterface *iface)
874
0
{
875
0
    Id id = QAccessibleCache::instance()->idForInterface(iface);
876
0
    if (!id)
877
0
        id = registerAccessibleInterface(iface);
878
0
    return id;
879
0
}
880
881
/*!
882
    Returns the QAccessibleInterface belonging to the \a id.
883
884
    Returns \nullptr if the id is invalid.
885
*/
886
QAccessibleInterface *QAccessible::accessibleInterface(Id id)
887
0
{
888
0
    return QAccessibleCache::instance()->interfaceForId(id);
889
0
}
890
891
892
/*!
893
    Returns \c true if the platform requested accessibility information.
894
895
    This function will return false until a tool such as a screen reader
896
    accessed the accessibility framework. It is still possible to use
897
    \l QAccessible::queryAccessibleInterface() even if accessibility is not
898
    active. But there will be no notifications sent to the platform.
899
900
    It is recommended to use this function to prevent expensive notifications
901
    via updateAccessibility() when they are not needed.
902
*/
903
bool QAccessible::isActive()
904
0
{
905
0
    if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
906
0
        return pfAccessibility->isActive();
907
0
    return false;
908
0
}
909
910
/*!
911
    \internal
912
*/
913
void QAccessible::setActive(bool active)
914
0
{
915
0
    if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
916
0
        pfAccessibility->setActive(active);
917
0
}
918
919
/*!
920
  Sets the root object of the accessible objects of this application
921
  to \a object.  All other accessible objects are reachable using object
922
  navigation from the root object.
923
924
  Normally, it isn't necessary to call this function, because Qt sets
925
  the QApplication object as the root object immediately before the
926
  event loop is entered in QApplication::exec().
927
928
  Use QAccessible::installRootObjectHandler() to redirect the function
929
  call to a customized handler function.
930
931
  \sa queryAccessibleInterface()
932
*/
933
void QAccessible::setRootObject(QObject *object)
934
0
{
935
0
    if (rootObjectHandler) {
936
0
        rootObjectHandler(object);
937
0
        return;
938
0
    }
939
940
0
    if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
941
0
        pfAccessibility->setRootObject(object);
942
0
}
943
944
/*!
945
  Notifies about a change that might be relevant for accessibility clients.
946
947
  \a event provides details about the change. These include the source
948
  of the change and the nature of the change.  The \a event should
949
  contain enough information give meaningful notifications.
950
951
  For example, the type \c ValueChange indicates that the position of
952
  a slider has been changed.
953
954
  Call this function whenever the state of your accessible object or
955
  one of its sub-elements has been changed either programmatically
956
  (e.g. by calling QLabel::setText()) or by user interaction.
957
958
  If there are no accessibility tools listening to this event, the
959
  performance penalty for calling this function is small, but if
960
  determining the parameters of the call is expensive you can test
961
  QAccessible::isActive() to avoid unnecessary computation.
962
*/
963
void QAccessible::updateAccessibility(QAccessibleEvent *event)
964
0
{
965
    // NOTE: Querying for the accessibleInterface below will result in
966
    // resolving and caching the interface, which in some cases will
967
    // cache the wrong information as updateAccessibility is called
968
    // during construction of widgets. If you see cases where the
969
    // cache seems wrong, this call is "to blame", but the code that
970
    // caches dynamic data should be updated to handle change events.
971
0
    if (isActive()) {
972
0
        QAccessibleInterface *iface = event->accessibleInterface();
973
0
        if (iface) {
974
0
            if (event->type() == QAccessible::TableModelChanged) {
975
0
                if (iface->tableInterface())
976
0
                    iface->tableInterface()->modelChange(static_cast<QAccessibleTableModelChangeEvent*>(event));
977
0
            }
978
0
        }
979
0
    }
980
0
    if (updateHandler) {
981
0
        updateHandler(event);
982
0
        return;
983
0
    }
984
985
0
    if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
986
0
        pfAccessibility->notifyAccessibilityUpdate(event);
987
0
}
988
989
static std::pair<int, int> qAccessibleTextBoundaryHelperHelper(QTextCursor &cursor,
990
                                                               QTextCursor::MoveOperation start,
991
                                                               QTextCursor::MoveOperation end)
992
0
{
993
0
    std::pair<int, int> result;
994
0
    cursor.movePosition(start, QTextCursor::MoveAnchor);
995
0
    result.first = cursor.position();
996
0
    cursor.movePosition(end, QTextCursor::KeepAnchor);
997
0
    result.second = cursor.position();
998
0
    return result;
999
0
}
1000
1001
/*!
1002
    \internal
1003
    \brief qAccessibleTextBoundaryHelper is a helper function to find the accessible text boundaries for QTextCursor based documents.
1004
    \param documentCursor a valid cursor bound to the document (not null). It needs to ba at the position to look for the boundary
1005
    \param boundaryType the type of boundary to find
1006
    \return the boundaries as pair
1007
*/
1008
std::pair< int, int > QAccessible::qAccessibleTextBoundaryHelper(const QTextCursor &offsetCursor, TextBoundaryType boundaryType)
1009
0
{
1010
0
    Q_ASSERT(!offsetCursor.isNull());
1011
1012
0
    QTextCursor cursor = offsetCursor;
1013
0
    switch (boundaryType) {
1014
0
    case CharBoundary:
1015
0
        return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::NoMove,
1016
0
                                                   QTextCursor::NextCharacter);
1017
0
    case WordBoundary:
1018
0
        return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::StartOfWord,
1019
0
                                                   QTextCursor::EndOfWord);
1020
0
    case SentenceBoundary: {
1021
        // QCursor does not provide functionality to move to next sentence.
1022
        // We therefore find the current block, then go through the block using
1023
        // QTextBoundaryFinder and find the sentence the \offset represents
1024
0
        std::pair<int, int> result = qAccessibleTextBoundaryHelperHelper(
1025
0
                cursor, QTextCursor::StartOfBlock, QTextCursor::EndOfBlock);
1026
0
        QString blockText = cursor.selectedText();
1027
0
        const int offsetWithinBlockText = offsetCursor.position() - result.first;
1028
0
        QTextBoundaryFinder sentenceFinder(QTextBoundaryFinder::Sentence, blockText);
1029
0
        sentenceFinder.setPosition(offsetWithinBlockText);
1030
0
        int prevBoundary = offsetWithinBlockText;
1031
0
        int nextBoundary = offsetWithinBlockText;
1032
0
        if (!(sentenceFinder.boundaryReasons() & QTextBoundaryFinder::StartOfItem))
1033
0
            prevBoundary = sentenceFinder.toPreviousBoundary();
1034
0
        nextBoundary = sentenceFinder.toNextBoundary();
1035
0
        if (nextBoundary != -1)
1036
0
            result.second = result.first + nextBoundary;
1037
0
        if (prevBoundary != -1)
1038
0
            result.first += prevBoundary;
1039
0
        return result;
1040
0
    }
1041
0
    case LineBoundary:
1042
0
        return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::StartOfLine,
1043
0
                                                   QTextCursor::EndOfLine);
1044
0
    case ParagraphBoundary:
1045
0
        return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::StartOfBlock,
1046
0
                                                   QTextCursor::EndOfBlock);
1047
0
    case NoBoundary:
1048
0
        return qAccessibleTextBoundaryHelperHelper(cursor, QTextCursor::Start, QTextCursor::End);
1049
0
    }
1050
1051
0
    Q_UNREACHABLE_RETURN({});
1052
0
}
1053
1054
/*!
1055
    \class QAccessibleInterface
1056
    \brief The QAccessibleInterface class defines an interface that exposes information
1057
    about accessible objects.
1058
1059
    \ingroup accessibility
1060
    \inmodule QtGui
1061
1062
    This class is part of \l {Accessibility for QWidget Applications}.
1063
1064
    Accessibility tools (also called AT Clients), such as screen readers
1065
    or braille displays, require high-level information about
1066
    accessible objects in an application. Accessible objects provide
1067
    specialized input and output methods, making it possible for users
1068
    to use accessibility tools with enabled applications (AT Servers).
1069
1070
    Every element that the user needs to interact with or react to is
1071
    an accessible object, and should provide this information. These
1072
    are mainly visual objects, such as widgets and widget elements, but
1073
    can also be content, such as sounds.
1074
1075
    The AT client uses three basic concepts to acquire information
1076
    about any accessible object in an application:
1077
    \list
1078
    \li \e Properties The client can read information about
1079
    accessible objects. In some cases the client can also modify these
1080
    properties; such as text in a line edit.
1081
    \li \e Actions The client can invoke actions like pressing a button
1082
    or .
1083
    \li \e{Relationships and Navigation} The client can traverse from one
1084
    accessible object to another, using the relationships between objects.
1085
    \endlist
1086
1087
    The QAccessibleInterface defines the API for these three concepts.
1088
1089
    \section1 Relationships and Navigation
1090
1091
    The functions childCount() and indexOfChild() return the number of
1092
    children of an accessible object and the index a child object has
1093
    in its parent. The childAt() function returns a child QAccessibleInterface
1094
    that is found at a position. The child does not have to be a direct
1095
    child. This allows bypassing intermediate layers when the parent already knows the
1096
    top-most child. childAt() is used for hit testing (finding the object
1097
    under the mouse).
1098
1099
    The relations() function provides information about the relations an
1100
    object has to other objects, and parent() and child() allows
1101
    traversing from one object to another object.
1102
1103
    \section1 Properties
1104
1105
    The central property of an accessible objects is what role() it
1106
    has. Different objects can have the same role, e.g. both the "Add
1107
    line" element in a scroll bar and the \c OK button in a dialog have
1108
    the same role, "button". The role implies what kind of
1109
    interaction the user can perform with the user interface element.
1110
1111
    An object's state() property is a combination of different state
1112
    flags and can describe both how the object's state differs from a
1113
    "normal" state, e.g. it might be unavailable, and also how it
1114
    behaves, e.g. it might be selectable.
1115
1116
    The text() property provides textual information about the object.
1117
    An object usually has a name, but can provide extended information
1118
    such as a description, help text, or information about any
1119
    keyboard accelerators it provides. Some objects allow changing the
1120
    text() property through the setText() function, but this
1121
    information is in most cases read-only.
1122
1123
    The rect() property provides information about the geometry of an
1124
    accessible object. This information is usually only available for
1125
    visual objects.
1126
1127
    \section1 Interfaces
1128
1129
    To enable the user to interact with an accessible object the
1130
    object must implement QAccessibleActionInterface in addition to
1131
    QAccessibleInterface.
1132
    Objects that support selections can define actions to change the selection.
1133
1134
    There are several other interfaces that should be implemented as required.
1135
    QAccessibleTextInterface should be used for bigger texts edits such as document views.
1136
    This interface should not be implemented for labels/single line edits.
1137
1138
    For sliders, scrollbars and other numerical value selectors QAccessibleValueInterface
1139
    should be implemented.
1140
1141
    Lists, tables and trees should implement QAccessibleTableInterface.
1142
1143
    Scrollable views should implement QAccessibleViewportInterface.
1144
1145
    \sa QAccessible, QAccessibleActionInterface, QAccessibleTextInterface, QAccessibleValueInterface, QAccessibleTableInterface, QAccessibleViewportInterface
1146
*/
1147
1148
/*!
1149
    \fn bool QAccessibleInterface::isValid() const
1150
1151
    Returns \c true if all the data necessary to use this interface
1152
    implementation is valid (e.g. all pointers are non-null);
1153
    otherwise returns \c false.
1154
1155
    \sa object()
1156
*/
1157
1158
/*!
1159
    \fn QObject *QAccessibleInterface::object() const
1160
1161
    Returns a pointer to the QObject this interface implementation provides
1162
    information for.
1163
1164
    \sa isValid()
1165
*/
1166
1167
/*!
1168
    \fn int QAccessibleInterface::childCount() const
1169
1170
    Returns the number of children that belong to this object. A child
1171
    can provide accessibility information on its own (e.g. a child
1172
    widget), or be a sub-element of this accessible object.
1173
1174
    All objects provide this information.
1175
1176
    \sa indexOfChild()
1177
*/
1178
1179
/*!
1180
    \fn int QAccessibleInterface::indexOfChild(const QAccessibleInterface *child) const
1181
1182
    Returns the 0-based index of the object \a child in this object's
1183
    children list, or -1 if \a child is not a child of this object.
1184
1185
    All objects provide this information about their children.
1186
1187
    \sa childCount()
1188
*/
1189
1190
/*!
1191
    Returns the meaningful relations to other widgets. Usually this will not return parent/child
1192
    relations, unless they are handled in a specific way such as in tree views.
1193
    It will typically return the labelled-by and label relations.
1194
1195
    It is possible to filter the relations by using the optional parameter \a match.
1196
    It should never return itself.
1197
1198
    \sa parent(), child()
1199
*/
1200
QList<std::pair<QAccessibleInterface*, QAccessible::Relation>>
1201
QAccessibleInterface::relations(QAccessible::Relation match) const
1202
0
{
1203
0
    Q_UNUSED(match);
1204
0
    return { };
1205
0
}
1206
1207
/*!
1208
    Returns the object that has the keyboard focus.
1209
1210
    The object returned can be any descendant, including itself.
1211
*/
1212
QAccessibleInterface *QAccessibleInterface::focusChild() const
1213
0
{
1214
0
    return nullptr;
1215
0
}
1216
1217
/*!
1218
    \fn QAccessibleInterface *QAccessibleInterface::childAt(int x, int y) const
1219
1220
    Returns the QAccessibleInterface of a child that contains the screen coordinates (\a x, \a y).
1221
    If there are no children at this position this function returns \nullptr.
1222
    The returned accessible must be a child, but not necessarily a direct child.
1223
1224
    This function is only reliable for visible objects (invisible
1225
    object might not be laid out correctly).
1226
1227
    All visual objects provide this information.
1228
1229
    A default implementation is provided for objects inheriting QAccessibleObject. This will iterate
1230
    over all children. If the widget manages its children (e.g. a table) it will be more efficient
1231
    to write a specialized implementation.
1232
1233
    \sa rect()
1234
*/
1235
1236
/*!
1237
    \fn QAccessibleInterface* QAccessibleInterface::parent() const
1238
1239
    Returns the QAccessibleInterface of the parent in the accessible object hierarchy.
1240
1241
    Returns \nullptr if no parent exists (e.g. for the top level application object).
1242
1243
    \sa child()
1244
*/
1245
1246
/*!
1247
    \fn QAccessibleInterface* QAccessibleInterface::child(int index) const
1248
1249
    Returns the accessible child with index \a index.
1250
    0-based index. The number of children of an object can be checked with childCount.
1251
1252
    Returns \nullptr when asking for an invalid child (e.g. when the child became invalid in the meantime).
1253
1254
    \sa childCount(), parent()
1255
*/
1256
1257
/*!
1258
    \fn QString QAccessibleInterface::text(QAccessible::Text t) const
1259
1260
    Returns the value of the text property \a t of the object.
1261
1262
    The \l QAccessible::Name is a string used by clients to identify, find, or
1263
    announce an accessible object for the user. All objects must have
1264
    a name that is unique within their container. The name can be
1265
    used differently by clients, so the name should both give a
1266
    short description of the object and be unique.
1267
1268
    An accessible object's \l QAccessible::Description provides textual information
1269
    about an object's visual appearance. The description is primarily
1270
    used to provide greater context for vision-impaired users, but is
1271
    also used for context searching or other applications. Not all
1272
    objects have a description. An "OK" button would not need a
1273
    description, but a tool button that shows a picture of a smiley
1274
    would.
1275
1276
    The \l QAccessible::Value of an accessible object represents visual information
1277
    contained by the object, e.g. the text in a line edit. Usually,
1278
    the value can be modified by the user. Not all objects have a
1279
    value, e.g. static text labels don't, and some objects have a
1280
    state that already is the value, e.g. toggle buttons.
1281
1282
    The \l QAccessible::Help text provides information about the function and
1283
    usage of an accessible object. Not all objects provide this
1284
    information.
1285
1286
    The \l QAccessible::Accelerator is a keyboard shortcut that activates the
1287
    object's default action. A keyboard shortcut is the underlined
1288
    character in the text of a menu, menu item or widget, and is
1289
    either the character itself, or a combination of this character
1290
    and a modifier key like Alt, Ctrl or Shift. Command controls like
1291
    tool buttons also have shortcut keys and usually display them in
1292
    their tooltip.
1293
1294
    The \l QAccessible::Identifier can be explicitly set to provide an
1295
    ID to assistive technologies. This can be especially useful for UI tests.
1296
    If no identifier has been explicitly set, the identifier is set by the
1297
    respective interface to an ID based on \l QObject::objectName or its
1298
    class name and \l QObject::objectName or class name of the parents
1299
    in its parents chain.
1300
1301
    All objects provide a string for \l QAccessible::Name.
1302
1303
    \sa role(), state()
1304
*/
1305
1306
/*!
1307
    \fn void QAccessibleInterface::setText(QAccessible::Text t, const QString &text)
1308
1309
    Sets the text property \a t of the object to \a text.
1310
1311
    Note that the text properties of most objects are read-only
1312
    so calling this function might have no effect.
1313
1314
    \sa text()
1315
*/
1316
1317
/*!
1318
    \fn QRect QAccessibleInterface::rect() const
1319
1320
    Returns the geometry of the object. The geometry is in screen coordinates.
1321
1322
    This function is only reliable for visible objects (invisible
1323
    objects might not be laid out correctly).
1324
1325
    All visual objects provide this information.
1326
1327
    \sa childAt()
1328
*/
1329
1330
/*!
1331
    \fn QAccessible::Role QAccessibleInterface::role() const
1332
1333
    Returns the role of the object.
1334
    The role of an object is usually static.
1335
1336
    All accessible objects have a role.
1337
1338
    \sa text(), state()
1339
*/
1340
1341
/*!
1342
    \fn QAccessible::State QAccessibleInterface::state() const
1343
1344
    Returns the current state of the object.
1345
    The returned value is a combination of the flags in
1346
    the QAccessible::StateFlag enumeration.
1347
1348
    All accessible objects have a state.
1349
1350
    \sa text(), role()
1351
*/
1352
1353
/*!
1354
    Returns the accessible's foreground color if applicable or an invalid QColor.
1355
1356
    \sa backgroundColor()
1357
*/
1358
QColor QAccessibleInterface::foregroundColor() const
1359
0
{
1360
0
    return QColor();
1361
0
}
1362
1363
/*!
1364
    Returns the accessible's background color if applicable or an invalid QColor.
1365
1366
    \sa foregroundColor()
1367
*/
1368
QColor QAccessibleInterface::backgroundColor() const
1369
0
{
1370
0
    return QColor();
1371
0
}
1372
1373
/*!
1374
    \fn QAccessibleTextInterface *QAccessibleInterface::textInterface()
1375
*/
1376
1377
/*!
1378
    \fn QAccessibleTextInterface *QAccessibleInterface::editableTextInterface()
1379
    \internal
1380
*/
1381
1382
/*!
1383
    \fn QAccessibleValueInterface *QAccessibleInterface::valueInterface()
1384
*/
1385
1386
/*!
1387
    \fn QAccessibleTableInterface *QAccessibleInterface::tableInterface()
1388
*/
1389
1390
/*!
1391
    \fn QAccessibleTableCellInterface *QAccessibleInterface::tableCellInterface()
1392
*/
1393
1394
/*!
1395
    \fn QAccessibleActionInterface *QAccessibleInterface::actionInterface()
1396
*/
1397
1398
/*!
1399
    \fn QAccessibleImageInterface *QAccessibleInterface::imageInterface()
1400
    \internal
1401
*/
1402
1403
/*!
1404
    \fn QAccessibleSelectionInterface *QAccessibleInterface::selectionInterface()
1405
    \since 6.5
1406
*/
1407
1408
/*!
1409
    \fn QAccessibleViewportInterface *QAccessibleInterface::viewportInterface()
1410
    \since 6.12
1411
*/
1412
1413
/*!
1414
    \class QAccessibleEvent
1415
    \ingroup accessibility
1416
    \inmodule QtGui
1417
1418
    \brief The QAccessibleEvent class is the base class for accessibility notifications.
1419
1420
    This class is used with \l QAccessible::updateAccessibility().
1421
1422
    The event type is one of the values of \l QAccessible::Event.
1423
    There are a number of subclasses that should be used to provide more details about the
1424
    event.
1425
1426
    For example to notify about a focus change when re-implementing QWidget::setFocus,
1427
    the event could be used as follows:
1428
    \snippet code/src_gui_accessible_qaccessible.cpp 2
1429
1430
    To enable in process screen readers, all events must be sent after the change has happened.
1431
*/
1432
1433
/*! \fn QAccessibleEvent::QAccessibleEvent(QObject *object, QAccessible::Event type)
1434
1435
    Constructs a QAccessibleEvent to notify that \a object has changed.
1436
    The event \a type describes what changed.
1437
*/
1438
1439
/*! \fn QAccessibleEvent::QAccessibleEvent(QAccessibleInterface *interface, QAccessible::Event type)
1440
1441
    Constructs a QAccessibleEvent to notify that \a interface has changed.
1442
    The event \a type describes what changed.
1443
    Use this function if you already have a QAccessibleInterface or no QObject, otherwise consider
1444
    the overload taking a \l QObject parameter as it might be cheaper.
1445
*/
1446
1447
/*!
1448
  Destroys the event.
1449
*/
1450
QAccessibleEvent::~QAccessibleEvent()
1451
0
{
1452
0
}
1453
1454
/*! \fn QAccessible::Event QAccessibleEvent::type() const
1455
  Returns the event type.
1456
*/
1457
1458
/*! \fn QObject* QAccessibleEvent::object() const
1459
  Returns the event object.
1460
*/
1461
1462
/*! \fn void QAccessibleEvent::setChild(int child)
1463
  Sets the child index to \a child.
1464
*/
1465
1466
/*! \fn int QAccessibleEvent::child() const
1467
  Returns the child index.
1468
*/
1469
1470
/*!
1471
    \internal
1472
    Returns the uniqueId of the QAccessibleInterface represented by this event.
1473
1474
    In case the object() function returns \nullptr, this is the only way to access the
1475
    interface.
1476
*/
1477
QAccessible::Id QAccessibleEvent::uniqueId() const
1478
0
{
1479
0
    if (!m_object)
1480
0
        return m_uniqueId;
1481
0
    QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(m_object);
1482
0
    if (!iface)
1483
0
        return 0;
1484
0
    if (m_child != -1) {
1485
0
        iface = iface->child(m_child);
1486
0
        if (Q_UNLIKELY(!iface)) {
1487
0
            qCWarning(lcAccessibilityCore) << "Invalid child in QAccessibleEvent:" << m_object << "child:" << m_child;
1488
0
            return 0;
1489
0
        }
1490
0
    }
1491
0
    return QAccessible::uniqueId(iface);
1492
0
}
1493
1494
void QAccessibleEvent::setChild(int chld)
1495
0
{
1496
0
    if (m_type == QAccessible::ObjectDestroyed)
1497
0
        qCWarning(lcAccessibilityCore) << "Calling QAccessibleEvent::setChild on ObjectDestroyed event " <<
1498
0
            "is not supported";
1499
0
    m_child = chld;
1500
0
}
1501
1502
/*!
1503
    \class QAccessibleValueChangeEvent
1504
    \ingroup accessibility
1505
    \inmodule QtGui
1506
1507
    \brief The QAccessibleValueChangeEvent describes a change in value for an accessible object.
1508
1509
    It contains the new value.
1510
1511
    This class is used with \l QAccessible::updateAccessibility().
1512
*/
1513
1514
/*! \fn QAccessibleValueChangeEvent::QAccessibleValueChangeEvent(QObject *object, const QVariant &value)
1515
1516
    Constructs a new QAccessibleValueChangeEvent for \a object.
1517
    The event contains the new \a value.
1518
*/
1519
/*! \fn QAccessibleValueChangeEvent::QAccessibleValueChangeEvent(QAccessibleInterface *iface, const QVariant &val)
1520
1521
    Constructs a new QAccessibleValueChangeEvent for \a iface.
1522
    The event contains the new value \a val.
1523
*/
1524
1525
/*! \fn void QAccessibleValueChangeEvent::setValue(const QVariant & value)
1526
1527
    Sets the new \a value for this event.
1528
*/
1529
/*!
1530
    \fn QVariant QAccessibleValueChangeEvent::value() const
1531
1532
    Returns the new value of the accessible object of this event.
1533
*/
1534
1535
/*!
1536
    \internal
1537
*/
1538
QAccessibleValueChangeEvent::~QAccessibleValueChangeEvent()
1539
0
{
1540
0
}
1541
1542
/*!
1543
    \class QAccessibleStateChangeEvent
1544
    \ingroup accessibility
1545
    \inmodule QtGui
1546
1547
    \brief The QAccessibleStateChangeEvent notfies the accessibility framework
1548
    that the state of an object has changed.
1549
1550
    This class is used with \l QAccessible::updateAccessibility().
1551
1552
    \sa QAccessibleInterface::state()
1553
*/
1554
/*! \fn QAccessibleStateChangeEvent::QAccessibleStateChangeEvent(QObject *object, QAccessible::State state)
1555
1556
    Constructs a new QAccessibleStateChangeEvent for \a object.
1557
    The difference to the object's previous state is in \a state.
1558
*/
1559
/*!
1560
    \fn QAccessibleStateChangeEvent::QAccessibleStateChangeEvent(QAccessibleInterface *iface, QAccessible::State state)
1561
1562
    Constructs a new QAccessibleStateChangeEvent.
1563
    \a iface is the interface associated with the event
1564
    \a state is the state of the accessible object.
1565
*/
1566
/*!
1567
    \fn QAccessible::State QAccessibleStateChangeEvent::changedStates() const
1568
    \brief Returns the states that have been changed.
1569
1570
    Keep in mind that the returned states are the ones that have changed.
1571
    To find out about the state of an object, use QAccessibleInterface::state().
1572
1573
    For example, if an object used to have the focus but loses it,
1574
    the object's state will have focused set to \c false. This event on the
1575
    other hand tells about the change and has focused set to \c true since
1576
    the focus state is changed from \c true to \c false.
1577
*/
1578
/*!
1579
    \internal
1580
*/
1581
QAccessibleStateChangeEvent::~QAccessibleStateChangeEvent()
1582
{
1583
}
1584
1585
/*!
1586
    \class QAccessibleTableModelChangeEvent
1587
    \ingroup accessibility
1588
    \inmodule QtGui
1589
1590
    \brief The QAccessibleTableModelChangeEvent signifies a change in a table, list, or tree where cells
1591
    are added or removed.
1592
    If the change affected a number of rows, firstColumn and lastColumn will return -1.
1593
    Likewise for columns, the row functions may return -1.
1594
1595
    This class is used with \l QAccessible::updateAccessibility().
1596
*/
1597
1598
/*! \enum QAccessibleTableModelChangeEvent::ModelChangeType
1599
    This enum describes the different types of changes in the table model.
1600
    \value ModelReset      The model has been reset, all previous knowledge about the model is now invalid.
1601
    \value DataChanged     No cells have been added or removed, but the data of the specified cell range is invalid.
1602
    \value RowsInserted    New rows have been inserted.
1603
    \value ColumnsInserted New columns have been inserted.
1604
    \value RowsRemoved     Rows have been removed.
1605
    \value ColumnsRemoved  Columns have been removed.
1606
*/
1607
/*! \fn QAccessibleTableModelChangeEvent::QAccessibleTableModelChangeEvent(QObject *object, ModelChangeType changeType)
1608
1609
    Constructs a new QAccessibleTableModelChangeEvent for \a object of with \a changeType.
1610
*/
1611
/*! \fn int QAccessibleTableModelChangeEvent::firstColumn() const
1612
1613
    Returns the first changed column.
1614
*/
1615
/*! \fn int QAccessibleTableModelChangeEvent::firstRow() const
1616
1617
    Returns the first changed row.
1618
*/
1619
/*! \fn int QAccessibleTableModelChangeEvent::lastColumn() const
1620
1621
    Returns the last changed column.
1622
*/
1623
/*! \fn int QAccessibleTableModelChangeEvent::lastRow() const
1624
1625
    Returns the last changed row.
1626
*/
1627
/*! \fn QAccessibleTableModelChangeEvent::ModelChangeType QAccessibleTableModelChangeEvent::modelChangeType() const
1628
1629
    Returns the type of change.
1630
*/
1631
/*! \fn void QAccessibleTableModelChangeEvent::setFirstColumn(int column)
1632
1633
    Sets the first changed \a column.
1634
*/
1635
/*! \fn void QAccessibleTableModelChangeEvent::setFirstRow(int row)
1636
1637
    Sets the first changed \a row.
1638
*/
1639
/*! \fn void QAccessibleTableModelChangeEvent::setLastColumn(int column)
1640
1641
    Sets the last changed \a column.
1642
*/
1643
/*! \fn void QAccessibleTableModelChangeEvent::setLastRow(int row)
1644
1645
    Sets the last changed \a row.
1646
*/
1647
/*! \fn void QAccessibleTableModelChangeEvent::setModelChangeType(ModelChangeType changeType)
1648
1649
    Sets the type of change to \a changeType.
1650
*/
1651
/*!
1652
    \fn QAccessibleTableModelChangeEvent::QAccessibleTableModelChangeEvent(QAccessibleInterface *iface, ModelChangeType changeType)
1653
1654
    Constructs a new QAccessibleTableModelChangeEvent for interface \a iface with a model
1655
    change type \a changeType.
1656
*/
1657
/*!
1658
    \internal
1659
*/
1660
QAccessibleTableModelChangeEvent::~QAccessibleTableModelChangeEvent()
1661
{
1662
}
1663
/*!
1664
    \class QAccessibleTextCursorEvent
1665
    \ingroup accessibility
1666
    \inmodule QtGui
1667
1668
    \brief The QAccessibleTextCursorEvent class notifies of cursor movements.
1669
1670
    This class is used with \l QAccessible::updateAccessibility().
1671
*/
1672
/*! \fn QAccessibleTextCursorEvent::QAccessibleTextCursorEvent(QObject *object, int cursorPos)
1673
1674
    Create a new QAccessibleTextCursorEvent for \a object.
1675
    The \a cursorPos is the new cursor position.
1676
*/
1677
/*! \fn int QAccessibleTextCursorEvent::cursorPosition() const
1678
1679
    Returns the cursor position.
1680
*/
1681
/*! \fn void QAccessibleTextCursorEvent::setCursorPosition(int position)
1682
1683
    Sets the cursor \a position for this event.
1684
*/
1685
/*!
1686
    \internal
1687
*/
1688
QAccessibleTextCursorEvent::~QAccessibleTextCursorEvent()
1689
{
1690
}
1691
1692
1693
/*!
1694
    \fn QAccessibleTextCursorEvent::QAccessibleTextCursorEvent(QAccessibleInterface *iface, int cursorPos)
1695
1696
    Create a new QAccessibleTextCursorEvent for \a iface,
1697
    The \a cursorPos is the new cursor position.
1698
*/
1699
1700
/*!
1701
    \class QAccessibleTextInsertEvent
1702
    \ingroup accessibility
1703
    \inmodule QtGui
1704
1705
    \brief The QAccessibleTextInsertEvent class notifies of text being inserted.
1706
1707
    This class is used with \l QAccessible::updateAccessibility().
1708
*/
1709
/*! \fn QAccessibleTextInsertEvent::QAccessibleTextInsertEvent(QObject *object, int position, const QString &text)
1710
1711
    Constructs a new QAccessibleTextInsertEvent event for \a object.
1712
    The \a text has been inserted at \a position.
1713
    By default, it is assumed that the cursor has moved to the end
1714
    of the selection. If that is not the case, one needs to manually
1715
    set it with \l QAccessibleTextCursorEvent::setCursorPosition() for this event.
1716
*/
1717
/*! \fn int QAccessibleTextInsertEvent::changePosition() const
1718
1719
    Returns the position where the text was inserted.
1720
*/
1721
/*! \fn QString QAccessibleTextInsertEvent::textInserted() const
1722
1723
    Returns the text that has been inserted.
1724
*/
1725
/*!
1726
    \internal
1727
*/
1728
QAccessibleTextInsertEvent::~QAccessibleTextInsertEvent()
1729
0
{
1730
0
}
1731
1732
1733
/*!
1734
    \class QAccessibleTextRemoveEvent
1735
    \ingroup accessibility
1736
    \inmodule QtGui
1737
1738
    \brief The QAccessibleTextRemoveEvent class notifies of text being deleted.
1739
1740
    This class is used with \l QAccessible::updateAccessibility().
1741
*/
1742
/*! \fn QAccessibleTextRemoveEvent::QAccessibleTextRemoveEvent(QObject *object, int position, const QString &text)
1743
1744
    Constructs a new QAccessibleTextRemoveEvent event for \a object.
1745
    The \a text has been removed at \a position.
1746
    By default it is assumed that the cursor has moved to \a position.
1747
    If that is not the case, one needs to manually
1748
    set it with \l QAccessibleTextCursorEvent::setCursorPosition() for this event.
1749
*/
1750
/*! \fn QAccessibleTextRemoveEvent::QAccessibleTextRemoveEvent(QAccessibleInterface *iface, int position, const QString &text)
1751
1752
    Constructs a new QAccessibleTextRemoveEvent event for \a iface.
1753
    The \a text has been removed at \a position.
1754
    By default it is assumed that the cursor has moved to \a position.
1755
    If that is not the case, one needs to manually
1756
    set it with \l QAccessibleTextCursorEvent::setCursorPosition() for this event.
1757
*/
1758
1759
/*! \fn int QAccessibleTextRemoveEvent::changePosition() const
1760
1761
    Returns the position where the text was removed.
1762
*/
1763
/*! \fn QString QAccessibleTextRemoveEvent::textRemoved() const
1764
1765
    Returns the text that has been removed.
1766
*/
1767
/*!
1768
    \internal
1769
*/
1770
QAccessibleTextRemoveEvent::~QAccessibleTextRemoveEvent()
1771
0
{
1772
0
}
1773
1774
/*!
1775
   \fn QAccessibleTextSelectionEvent::QAccessibleTextSelectionEvent(QAccessibleInterface *iface, int start, int end)
1776
1777
   Constructs a new QAccessibleTextSelectionEvent for \a iface. The new selection this
1778
   event notifies about is from position \a start to \a end.
1779
*/
1780
1781
/*!
1782
     \fn QAccessibleTextInsertEvent::QAccessibleTextInsertEvent(QAccessibleInterface *iface, int position, const QString &text)
1783
1784
     Constructs a new QAccessibleTextInsertEvent event for \a iface. The \a text has been inserted
1785
     at \a position.
1786
*/
1787
1788
/*!
1789
     \fn inline QAccessibleTextUpdateEvent::QAccessibleTextUpdateEvent(QAccessibleInterface *iface, int position, const QString &oldText,
1790
         const QString &text)
1791
1792
     Constructs a new QAccessibleTextUpdateEvent for \a iface. The text change takes place at
1793
     \a position where the \a oldText was removed and \a text inserted instead.
1794
1795
*/
1796
1797
1798
1799
/*!
1800
    \class QAccessibleTextUpdateEvent
1801
    \ingroup accessibility
1802
    \inmodule QtGui
1803
1804
    \brief The QAccessibleTextUpdateEvent class notifies about text changes.
1805
    This is for accessibles that support editable text such as line edits.
1806
    This event occurs for example when a portion of selected text
1807
    gets replaced by pasting a new text or in override mode of editors.
1808
1809
    This class is used with \l QAccessible::updateAccessibility().
1810
*/
1811
/*! \fn QAccessibleTextUpdateEvent::QAccessibleTextUpdateEvent(QObject *object, int position, const QString &oldText, const QString &text)
1812
1813
    Constructs a new QAccessibleTextUpdateEvent for \a object.
1814
    The text change takes place at \a position where the \a oldText was removed and \a text inserted instead.
1815
*/
1816
/*! \fn int QAccessibleTextUpdateEvent::changePosition() const
1817
1818
    Returns where the change took place.
1819
*/
1820
/*! \fn QString QAccessibleTextUpdateEvent::textInserted() const
1821
1822
    Returns the inserted text.
1823
*/
1824
/*! \fn QString QAccessibleTextUpdateEvent::textRemoved() const
1825
1826
    Returns the removed text.
1827
*/
1828
/*!
1829
    \internal
1830
*/
1831
QAccessibleTextUpdateEvent::~QAccessibleTextUpdateEvent()
1832
0
{
1833
0
}
1834
1835
1836
/*!
1837
    \class QAccessibleTextSelectionEvent
1838
    \ingroup accessibility
1839
    \inmodule QtGui
1840
1841
    \brief QAccessibleTextSelectionEvent signals a change in the text selection of an object.
1842
1843
    This class is used with \l QAccessible::updateAccessibility().
1844
*/
1845
/*! \fn QAccessibleTextSelectionEvent::QAccessibleTextSelectionEvent(QObject *object, int start, int end)
1846
1847
    Constructs a new QAccessibleTextSelectionEvent for \a object.
1848
    The new selection this event notifies about is from position \a start to \a end.
1849
*/
1850
/*! \fn int QAccessibleTextSelectionEvent::selectionEnd() const
1851
1852
    Returns the position of the last selected character.
1853
*/
1854
/*! \fn int QAccessibleTextSelectionEvent::selectionStart() const
1855
1856
    Returns the position of the first selected character.
1857
*/
1858
/*! \fn void QAccessibleTextSelectionEvent::setSelection(int start, int end)
1859
1860
    Sets the selection for this event from position \a start to \a end.
1861
*/
1862
/*!
1863
    \internal
1864
*/
1865
QAccessibleTextSelectionEvent::~QAccessibleTextSelectionEvent()
1866
{
1867
}
1868
1869
/*!
1870
    \since 6.8
1871
    \class QAccessibleAnnouncementEvent
1872
    \ingroup accessibility
1873
    \inmodule QtGui
1874
1875
    \brief The QAccessibleAnnouncementEvent is used to request the announcement
1876
    of a given message by assistive technologies.
1877
1878
    This class is used with \l QAccessible::updateAccessibility().
1879
*/
1880
1881
/*! \fn QAccessibleAnnouncementEvent::QAccessibleAnnouncementEvent(QObject *object, const QString &message)
1882
1883
    Constructs a new QAccessibleAnnouncementEvent event for \a object
1884
    to request the announcement of \a message with politeness
1885
    \l QAccessible::AnnouncementPoliteness::Polite.
1886
1887
    \l QAccessibleAnnouncementEvent::setPoliteness can be used to adjust the politeness.
1888
*/
1889
1890
/*! \fn QAccessibleAnnouncementEvent::QAccessibleAnnouncementEvent(QAccessibleInterface *iface, const QString &message)
1891
1892
    Constructs a new QAccessibleAnnouncementEvent event for \a iface
1893
    to request the announcement of \a message with politeness
1894
    \l QAccessible::AnnouncementPoliteness::Polite.
1895
1896
    \l QAccessibleAnnouncementEvent::setPoliteness can be used to adjust the politeness.
1897
*/
1898
1899
/*! \fn QString QAccessibleAnnouncementEvent::message() const
1900
1901
    Returns the message.
1902
*/
1903
1904
/*! \fn QAccessible::AnnouncementPoliteness QAccessibleAnnouncementEvent::politeness() const
1905
1906
    Returns the politeness.
1907
*/
1908
1909
/*! \fn void QAccessibleAnnouncementEvent::setPoliteness(QAccessible::AnnouncementPoliteness politeness)
1910
1911
    Sets the politeness with which the announcement will be requested to \a politeness.
1912
*/
1913
1914
1915
/*!
1916
    \internal
1917
*/
1918
QAccessibleAnnouncementEvent::~QAccessibleAnnouncementEvent()
1919
0
{
1920
0
}
1921
1922
/*!
1923
    Returns the QAccessibleInterface associated with the event.
1924
*/
1925
QAccessibleInterface *QAccessibleEvent::accessibleInterface() const
1926
0
{
1927
0
    if (m_object == nullptr)
1928
0
        return QAccessible::accessibleInterface(m_uniqueId);
1929
1930
0
    QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(m_object);
1931
0
    if (!iface || !iface->isValid())
1932
0
        return nullptr;
1933
1934
0
    if (m_child >= 0) {
1935
0
        QAccessibleInterface *child = iface->child(m_child);
1936
0
        if (child) {
1937
0
            iface = child;
1938
0
        } else {
1939
0
            qCWarning(lcAccessibilityCore) << "Cannot create accessible child interface for object: " << m_object << " index: " << m_child << "type: " << m_type;
1940
0
        }
1941
0
    }
1942
0
    return iface;
1943
0
}
1944
1945
/*!
1946
    Returns the window associated with the underlying object.
1947
    For instance, QAccessibleWidget reimplements this and returns
1948
    the windowHandle() of the QWidget.
1949
1950
    It is used on some platforms to be able to notify the AT client about
1951
    state changes.
1952
    The backend will traverse up all ancestors until it finds a window.
1953
    (This means that at least one interface among the ancestors should
1954
    return a valid QWindow pointer).
1955
1956
    The default implementation returns \nullptr.
1957
  */
1958
QWindow *QAccessibleInterface::window() const
1959
0
{
1960
0
    return nullptr;
1961
0
}
1962
1963
/*!
1964
    \internal
1965
    Method to allow extending this class without breaking binary compatibility.
1966
    The actual behavior and format of \a data depends on \a id argument
1967
    which must be defined if the class is to be extended with another virtual
1968
    function.
1969
    Currently, this is unused.
1970
*/
1971
void QAccessibleInterface::virtual_hook(int /*id*/, void * /*data*/)
1972
0
{
1973
0
}
1974
1975
/*!
1976
    \fn void *QAccessibleInterface::interface_cast(QAccessible::InterfaceType type)
1977
1978
    Returns a specialized accessibility interface \a type from the
1979
    generic QAccessibleInterface.
1980
1981
    This function must be reimplemented when providing more
1982
    information about a widget or object through the specialized
1983
    interfaces. For example a line edit should implement the
1984
    QAccessibleTextInterface.
1985
1986
    \sa QAccessible::InterfaceType, QAccessibleTextInterface,
1987
    QAccessibleValueInterface, QAccessibleActionInterface,
1988
    QAccessibleTableInterface, QAccessibleTableCellInterface,
1989
    QAccessibleViewportInterface
1990
*/
1991
1992
/*! \internal */
1993
const char *qAccessibleRoleString(QAccessible::Role role)
1994
0
{
1995
0
    if (role >= QAccessible::UserRole)
1996
0
         role = QAccessible::UserRole;
1997
0
    static int roleEnum = QAccessible::staticMetaObject.indexOfEnumerator("Role");
1998
0
    return QAccessible::staticMetaObject.enumerator(roleEnum).valueToKey(role);
1999
0
}
2000
2001
/*! \internal */
2002
const char *qAccessibleEventString(QAccessible::Event event)
2003
0
{
2004
0
    static int eventEnum = QAccessible::staticMetaObject.indexOfEnumerator("Event");
2005
0
    return QAccessible::staticMetaObject.enumerator(eventEnum).valueToKey(event);
2006
0
}
2007
2008
#ifndef QT_NO_DEBUG_STREAM
2009
static void qAccessiblePrintInterface(QDebug d, const QAccessibleInterface *iface)
2010
0
{
2011
0
    if (!iface) {
2012
0
        d << "QAccessibleInterface(0x0)";
2013
0
        return;
2014
0
    }
2015
2016
0
    d << "QAccessibleInterface(" << Qt::hex << (const void *) iface << Qt::dec;
2017
0
    if (iface->isValid()) {
2018
0
        d << " name=" << iface->text(QAccessible::Name);
2019
0
        d << " role=" << qAccessibleRoleString(iface->role());
2020
0
        if (iface->childCount())
2021
0
            d << " childc=" << iface->childCount();
2022
0
        if (iface->object()) {
2023
0
            d << " obj=" << iface->object();
2024
0
        }
2025
0
        QStringList stateStrings;
2026
0
        QAccessible::State st = iface->state();
2027
0
        if (st.focusable)
2028
0
            stateStrings << u"focusable"_s;
2029
0
        if (st.focused)
2030
0
            stateStrings << u"focused"_s;
2031
0
        if (st.selected)
2032
0
            stateStrings << u"selected"_s;
2033
0
        if (st.invisible)
2034
0
            stateStrings << u"invisible"_s;
2035
2036
0
        if (!stateStrings.isEmpty())
2037
0
            d << ' ' << qUtf8Printable(stateStrings.join(u'|'));
2038
2039
0
        if (!st.invisible)
2040
0
            d << " rect=" << iface->rect();
2041
2042
0
    } else {
2043
0
        d << " invalid";
2044
0
    }
2045
0
    d << ')';
2046
0
}
2047
2048
static void qAccessiblePrintInterface(QDebug d, const QAccessibleInterface *iface,
2049
                                      const QByteArray &prefix)
2050
0
{
2051
0
    qAccessiblePrintInterface(d, iface);
2052
2053
0
    if (d.verbosity() <= QDebug::DefaultVerbosity || !iface || !iface->isValid())
2054
0
        return;
2055
2056
0
    const int childCount = iface->childCount();
2057
0
    for (int i = 0; i < childCount; ++i) {
2058
0
        const bool isLastChild = i == childCount - 1;
2059
0
        d << '\n' << prefix.constData() << (isLastChild ? "└─ " : "├─ ");
2060
0
        qAccessiblePrintInterface(d, iface->child(i),
2061
0
                                  prefix + (isLastChild ? "   " : "│  "));
2062
0
    }
2063
0
}
2064
2065
/*!
2066
    \internal
2067
2068
    Streams \a iface as a single line. At a verbosity above
2069
    QDebug::DefaultVerbosity the accessible subtree below \a iface
2070
    is streamed as well, one line per node, connected up as a tree.
2071
*/
2072
Q_GUI_EXPORT QDebug operator<<(QDebug d, const QAccessibleInterface *iface)
2073
0
{
2074
0
    QDebugStateSaver saver(d);
2075
0
    d.nospace();
2076
0
    qAccessiblePrintInterface(d, iface, QByteArray());
2077
0
    return d;
2078
0
}
2079
2080
/*! \internal */
2081
QDebug operator<<(QDebug d, const QAccessibleEvent &ev)
2082
0
{
2083
0
    QDebugStateSaver saver(d);
2084
0
    d.nospace() << "QAccessibleEvent(";
2085
0
    if (ev.object()) {
2086
0
        d.nospace() << "object=" << Qt::hex << ev.object() << Qt::dec;
2087
0
        d.nospace() << "child=" << ev.child();
2088
0
    } else {
2089
0
        d.nospace() << "no object, uniqueId=" << ev.uniqueId();
2090
0
    }
2091
0
    d << " event=" << qAccessibleEventString(ev.type());
2092
0
    if (ev.type() == QAccessible::StateChanged) {
2093
0
        QAccessible::State changed = static_cast<const QAccessibleStateChangeEvent*>(&ev)->changedStates();
2094
0
        d << "State changed:";
2095
0
        if (changed.disabled) d << "disabled";
2096
0
        if (changed.selected) d << "selected";
2097
0
        if (changed.focusable) d << "focusable";
2098
0
        if (changed.focused) d << "focused";
2099
0
        if (changed.pressed) d << "pressed";
2100
0
        if (changed.checkable) d << "checkable";
2101
0
        if (changed.checked) d << "checked";
2102
0
        if (changed.checkStateMixed) d << "checkStateMixed";
2103
0
        if (changed.readOnly) d << "readOnly";
2104
0
        if (changed.hotTracked) d << "hotTracked";
2105
0
        if (changed.defaultButton) d << "defaultButton";
2106
0
        if (changed.expanded) d << "expanded";
2107
0
        if (changed.collapsed) d << "collapsed";
2108
0
        if (changed.busy) d << "busy";
2109
0
        if (changed.expandable) d << "expandable";
2110
0
        if (changed.marqueed) d << "marqueed";
2111
0
        if (changed.animated) d << "animated";
2112
0
        if (changed.invisible) d << "invisible";
2113
0
        if (changed.offscreen) d << "offscreen";
2114
0
        if (changed.sizeable) d << "sizeable";
2115
0
        if (changed.movable) d << "movable";
2116
0
        if (changed.selfVoicing) d << "selfVoicing";
2117
0
        if (changed.selectable) d << "selectable";
2118
0
        if (changed.linked) d << "linked";
2119
0
        if (changed.traversed) d << "traversed";
2120
0
        if (changed.multiSelectable) d << "multiSelectable";
2121
0
        if (changed.extSelectable) d << "extSelectable";
2122
0
        if (changed.passwordEdit) d << "passwordEdit"; // used to be Protected
2123
0
        if (changed.hasPopup) d << "hasPopup";
2124
0
        if (changed.modal) d << "modal";
2125
2126
        // IA2 - we chose to not add some IA2 states for now
2127
        // Below the ones that seem helpful
2128
0
        if (changed.active) d << "active";
2129
0
        if (changed.invalid) d << "invalid"; // = defunct
2130
0
        if (changed.editable) d << "editable";
2131
0
        if (changed.multiLine) d << "multiLine";
2132
0
        if (changed.selectableText) d << "selectableText";
2133
0
        if (changed.supportsAutoCompletion) d << "supportsAutoCompletion";
2134
2135
0
    }
2136
0
    d << ')';
2137
0
    return d;
2138
0
}
2139
#endif // QT_NO_DEBUGSTREAM
2140
2141
/*!
2142
    \class QAccessibleTextInterface
2143
    \inmodule QtGui
2144
2145
    \ingroup accessibility
2146
2147
    \brief The QAccessibleTextInterface class implements support for text handling.
2148
2149
    This interface corresponds to the IAccessibleText interface.
2150
    It should be implemented for widgets that display more text than a plain label.
2151
    Labels should be represented by only \l QAccessibleInterface
2152
    and return their text as name (\l QAccessibleInterface::text() with \l QAccessible::Name as type).
2153
    The QAccessibleTextInterface is typically for text that a screen reader
2154
    might want to read line by line, and for widgets that support text selection and input.
2155
    This interface is, for example, implemented for QLineEdit.
2156
2157
    \l{IAccessible2 Specification}
2158
*/
2159
2160
/*!
2161
2162
    Destroys the QAccessibleTextInterface.
2163
*/
2164
QAccessibleTextInterface::~QAccessibleTextInterface()
2165
0
{
2166
0
}
2167
2168
/*!
2169
    \fn void QAccessibleTextInterface::addSelection(int startOffset, int endOffset)
2170
2171
    Select the text from \a startOffset to \a endOffset.
2172
    The \a startOffset is the first character that will be selected.
2173
    The \a endOffset is the first character that will not be selected.
2174
2175
    When the object supports multiple selections (e.g. in a word processor),
2176
    this adds a new selection, otherwise it replaces the previous selection.
2177
2178
    The selection will be \a endOffset - \a startOffset characters long.
2179
*/
2180
2181
/*!
2182
    \fn QString QAccessibleTextInterface::attributes(int offset, int *startOffset, int *endOffset) const
2183
2184
    Returns the text attributes at the position \a offset.
2185
    In addition the range of the attributes is returned in \a startOffset and \a endOffset.
2186
*/
2187
2188
/*!
2189
    \fn int QAccessibleTextInterface::cursorPosition() const
2190
2191
    Returns the current cursor position.
2192
*/
2193
2194
/*!
2195
    \fn QRect QAccessibleTextInterface::characterRect(int offset) const
2196
2197
    Returns the position and size of the character at position \a offset in screen coordinates.
2198
*/
2199
2200
/*!
2201
    \fn int QAccessibleTextInterface::selectionCount() const
2202
2203
    Returns the number of selections in this text.
2204
*/
2205
2206
/*!
2207
    \fn int QAccessibleTextInterface::offsetAtPoint(const QPoint &point) const
2208
2209
    Returns the offset of the character at the \a point in screen coordinates.
2210
*/
2211
2212
/*!
2213
    \fn void QAccessibleTextInterface::selection(int selectionIndex, int *startOffset, int *endOffset) const
2214
2215
    Returns a selection. The size of the selection is returned in \a startOffset and \a endOffset.
2216
    If there is no selection both \a startOffset and \a endOffset are \nullptr.
2217
2218
    The accessibility APIs support multiple selections. For most widgets though, only one selection
2219
    is supported with \a selectionIndex equal to 0.
2220
*/
2221
2222
/*!
2223
    \fn QString QAccessibleTextInterface::text(int startOffset, int endOffset) const
2224
2225
    Returns the text from \a startOffset to \a endOffset.
2226
    The \a startOffset is the first character that will be returned.
2227
    The \a endOffset is the first character that will not be returned.
2228
*/
2229
2230
/*!
2231
    \internal
2232
    Helper for finding line breaks in textBeforeOffset/textAtOffset/textAfterOffset.
2233
    \a beforeAtAfter is the line we look for. -1 for before, 0 for at and 1 for after.
2234
*/
2235
static QString textLineBoundary(int beforeAtAfter, const QString &text, int offset, int *startOffset, int *endOffset)
2236
0
{
2237
0
    Q_ASSERT(beforeAtAfter >= -1 && beforeAtAfter <= 1);
2238
0
    Q_ASSERT(*startOffset == -1 && *endOffset == -1);
2239
0
    int length = text.size();
2240
0
    Q_ASSERT(offset >= 0 && offset <= length);
2241
2242
    // move offset into the right range (if asking for line before or after
2243
0
    if (beforeAtAfter == 1) {
2244
0
        offset = text.indexOf(QChar::LineFeed, qMin(offset, length - 1));
2245
0
        if (offset < 0)
2246
0
            return QString(); // after the last line comes nothing
2247
0
        ++offset; // move after the newline
2248
0
    } else if (beforeAtAfter == -1) {
2249
0
        offset = text.lastIndexOf(QChar::LineFeed, qMax(offset - 1, 0));
2250
0
        if (offset < 0)
2251
0
            return QString(); // before first line comes nothing
2252
0
    }
2253
2254
0
    if (offset > 0)
2255
0
        *startOffset = text.lastIndexOf(QChar::LineFeed, offset - 1);
2256
0
    ++*startOffset; // move to the char after the newline (0 if lastIndexOf returned -1)
2257
2258
0
    *endOffset = text.indexOf(QChar::LineFeed, qMin(offset, length - 1)) + 1; // include newline char
2259
0
    if (*endOffset <= 0 || *endOffset > length)
2260
0
        *endOffset = length; // if the text doesn't end with a newline it ends at length
2261
2262
0
    return text.mid(*startOffset, *endOffset - *startOffset);
2263
0
}
2264
2265
/*!
2266
    Returns the text item of type \a boundaryType that is close to offset \a offset
2267
    and sets \a startOffset and \a endOffset values to the start and end positions
2268
    of that item; returns an empty string if there is no such an item.
2269
    Sets \a startOffset and \a endOffset values to -1 on error.
2270
2271
    This default implementation is provided for small text edits. A word processor or
2272
    text editor should provide their own efficient implementations. This function makes no
2273
    distinction between paragraphs and lines.
2274
2275
    \note this function can not take the cursor position into account. By convention
2276
    an \a offset of -2 means that this function should use the cursor position as offset.
2277
    Thus an offset of -2 must be converted to the cursor position before calling this
2278
    function.
2279
    An offset of -1 is used for the text length and custom implementations of this function
2280
    have to return the result as if the length was passed in as offset.
2281
*/
2282
QString QAccessibleTextInterface::textBeforeOffset(int offset, QAccessible::TextBoundaryType boundaryType,
2283
                                                   int *startOffset, int *endOffset) const
2284
0
{
2285
0
    const QString txt = text(0, characterCount());
2286
2287
0
    if (offset == -1)
2288
0
        offset = txt.size();
2289
2290
0
    *startOffset = *endOffset = -1;
2291
0
    if (txt.isEmpty() || offset <= 0 || offset > txt.size())
2292
0
        return QString();
2293
2294
    // type initialized just to silence a compiler warning [-Werror=maybe-uninitialized]
2295
0
    QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2296
0
    switch (boundaryType) {
2297
0
    case QAccessible::CharBoundary:
2298
0
        type = QTextBoundaryFinder::Grapheme;
2299
0
        break;
2300
0
    case QAccessible::WordBoundary:
2301
0
        type = QTextBoundaryFinder::Word;
2302
0
        break;
2303
0
    case QAccessible::SentenceBoundary:
2304
0
        type = QTextBoundaryFinder::Sentence;
2305
0
        break;
2306
0
    case QAccessible::LineBoundary:
2307
0
    case QAccessible::ParagraphBoundary:
2308
        // Lines can not use QTextBoundaryFinder since Line there means any potential line-break.
2309
0
        return textLineBoundary(-1, txt, offset, startOffset, endOffset);
2310
0
    case QAccessible::NoBoundary:
2311
        // return empty, this function currently only supports single lines, so there can be no line before
2312
0
        return QString();
2313
0
    default:
2314
0
        Q_UNREACHABLE();
2315
0
    }
2316
2317
    // keep behavior in sync with QTextCursor::movePosition()!
2318
2319
0
    QTextBoundaryFinder boundary(type, txt);
2320
0
    boundary.setPosition(offset);
2321
2322
0
    do {
2323
0
        if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2324
0
            break;
2325
0
    } while (boundary.toPreviousBoundary() > 0);
2326
0
    Q_ASSERT(boundary.position() >= 0);
2327
0
    const int endPos = boundary.position();
2328
2329
0
    while (boundary.toPreviousBoundary() > 0) {
2330
0
        if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2331
0
            break;
2332
0
    }
2333
0
    if (boundary.position() < 0)
2334
0
        return QString();
2335
2336
0
    *endOffset = endPos;
2337
0
    *startOffset = boundary.position();
2338
2339
0
    return txt.mid(*startOffset, *endOffset - *startOffset);
2340
0
}
2341
2342
/*!
2343
    Returns the text item of type \a boundaryType that is right after offset \a offset
2344
    and sets \a startOffset and \a endOffset values to the start and end positions
2345
    of that item; returns an empty string if there is no such an item.
2346
    Sets \a startOffset and \a endOffset values to -1 on error.
2347
2348
    This default implementation is provided for small text edits. A word processor or
2349
    text editor should provide their own efficient implementations. This function makes no
2350
    distinction between paragraphs and lines.
2351
2352
    \note this function can not take the cursor position into account. By convention
2353
    an \a offset of -2 means that this function should use the cursor position as offset.
2354
    Thus an offset of -2 must be converted to the cursor position before calling this
2355
    function.
2356
    An offset of -1 is used for the text length and custom implementations of this function
2357
    have to return the result as if the length was passed in as offset.
2358
*/
2359
QString QAccessibleTextInterface::textAfterOffset(int offset, QAccessible::TextBoundaryType boundaryType,
2360
                                                  int *startOffset, int *endOffset) const
2361
0
{
2362
0
    const QString txt = text(0, characterCount());
2363
2364
0
    if (offset == -1)
2365
0
        offset = txt.size();
2366
2367
0
    *startOffset = *endOffset = -1;
2368
0
    if (txt.isEmpty() || offset < 0 || offset >= txt.size())
2369
0
        return QString();
2370
2371
    // type initialized just to silence a compiler warning [-Werror=maybe-uninitialized]
2372
0
    QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2373
0
    switch (boundaryType) {
2374
0
    case QAccessible::CharBoundary:
2375
0
        type = QTextBoundaryFinder::Grapheme;
2376
0
        break;
2377
0
    case QAccessible::WordBoundary:
2378
0
        type = QTextBoundaryFinder::Word;
2379
0
        break;
2380
0
    case QAccessible::SentenceBoundary:
2381
0
        type = QTextBoundaryFinder::Sentence;
2382
0
        break;
2383
0
    case QAccessible::LineBoundary:
2384
0
    case QAccessible::ParagraphBoundary:
2385
        // Lines can not use QTextBoundaryFinder since Line there means any potential line-break.
2386
0
        return textLineBoundary(1, txt, offset, startOffset, endOffset);
2387
0
    case QAccessible::NoBoundary:
2388
        // return empty, this function currently only supports single lines, so there can be no line after
2389
0
        return QString();
2390
0
    default:
2391
0
        Q_UNREACHABLE();
2392
0
    }
2393
2394
    // keep behavior in sync with QTextCursor::movePosition()!
2395
2396
0
    QTextBoundaryFinder boundary(type, txt);
2397
0
    boundary.setPosition(offset);
2398
2399
0
    while (true) {
2400
0
        int toNext = boundary.toNextBoundary();
2401
0
        if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2402
0
            break;
2403
0
        if (toNext < 0 || toNext >= txt.size())
2404
0
            break; // not found, the boundary might not exist
2405
0
    }
2406
0
    Q_ASSERT(boundary.position() <= txt.size());
2407
0
    *startOffset = boundary.position();
2408
2409
0
    while (true) {
2410
0
        int toNext = boundary.toNextBoundary();
2411
0
        if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2412
0
            break;
2413
0
        if (toNext < 0 || toNext >= txt.size())
2414
0
            break; // not found, the boundary might not exist
2415
0
    }
2416
0
    Q_ASSERT(boundary.position() <= txt.size());
2417
0
    *endOffset = boundary.position();
2418
2419
0
    if ((*startOffset == -1) || (*endOffset == -1) || (*startOffset == *endOffset)) {
2420
0
        *endOffset = -1;
2421
0
        *startOffset = -1;
2422
0
    }
2423
2424
0
    return txt.mid(*startOffset, *endOffset - *startOffset);
2425
0
}
2426
2427
/*!
2428
    Returns the text item of type \a boundaryType at offset \a offset
2429
    and sets \a startOffset and \a endOffset values to the start and end positions
2430
    of that item; returns an empty string if there is no such an item.
2431
    Sets \a startOffset and \a endOffset values to -1 on error.
2432
2433
    This default implementation is provided for small text edits. A word processor or
2434
    text editor should provide their own efficient implementations. This function makes no
2435
    distinction between paragraphs and lines.
2436
2437
    \note this function can not take the cursor position into account. By convention
2438
    an \a offset of -2 means that this function should use the cursor position as offset.
2439
    Thus an offset of -2 must be converted to the cursor position before calling this
2440
    function.
2441
    An offset of -1 is used for the text length and custom implementations of this function
2442
    have to return the result as if the length was passed in as offset.
2443
*/
2444
QString QAccessibleTextInterface::textAtOffset(int offset, QAccessible::TextBoundaryType boundaryType,
2445
                                               int *startOffset, int *endOffset) const
2446
0
{
2447
0
    const QString txt = text(0, characterCount());
2448
2449
0
    if (offset == -1)
2450
0
        offset = txt.size();
2451
2452
0
    *startOffset = *endOffset = -1;
2453
0
    if (txt.isEmpty() || offset < 0 || offset > txt.size())
2454
0
        return QString();
2455
2456
0
    if (offset == txt.size() && boundaryType == QAccessible::CharBoundary)
2457
0
        return QString();
2458
2459
    // type initialized just to silence a compiler warning [-Werror=maybe-uninitialized]
2460
0
    QTextBoundaryFinder::BoundaryType type = QTextBoundaryFinder::Grapheme;
2461
0
    switch (boundaryType) {
2462
0
    case QAccessible::CharBoundary:
2463
0
        type = QTextBoundaryFinder::Grapheme;
2464
0
        break;
2465
0
    case QAccessible::WordBoundary:
2466
0
        type = QTextBoundaryFinder::Word;
2467
0
        break;
2468
0
    case QAccessible::SentenceBoundary:
2469
0
        type = QTextBoundaryFinder::Sentence;
2470
0
        break;
2471
0
    case QAccessible::LineBoundary:
2472
0
    case QAccessible::ParagraphBoundary:
2473
        // Lines can not use QTextBoundaryFinder since Line there means any potential line-break.
2474
0
        return textLineBoundary(0, txt, offset, startOffset, endOffset);
2475
0
    case QAccessible::NoBoundary:
2476
0
        *startOffset = 0;
2477
0
        *endOffset = txt.size();
2478
0
        return txt;
2479
0
    default:
2480
0
        Q_UNREACHABLE();
2481
0
    }
2482
2483
    // keep behavior in sync with QTextCursor::movePosition()!
2484
2485
0
    QTextBoundaryFinder boundary(type, txt);
2486
0
    boundary.setPosition(offset);
2487
2488
0
    do {
2489
0
        if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2490
0
            break;
2491
0
    } while (boundary.toPreviousBoundary() > 0);
2492
0
    Q_ASSERT(boundary.position() >= 0);
2493
0
    const int startPos = boundary.position();
2494
2495
0
    while (boundary.toNextBoundary() < txt.size()) {
2496
0
        if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem)))
2497
0
            break;
2498
0
        if (boundary.position() == -1)
2499
0
            return QString();
2500
0
    }
2501
2502
0
    Q_ASSERT(boundary.position() <= txt.size());
2503
0
    *startOffset = startPos;
2504
0
    *endOffset = boundary.position();
2505
2506
0
    return txt.mid(*startOffset, *endOffset - *startOffset);
2507
0
}
2508
2509
/*!
2510
    \fn void QAccessibleTextInterface::removeSelection(int selectionIndex)
2511
2512
    Clears the selection with index \a selectionIndex.
2513
*/
2514
2515
/*!
2516
    \fn void QAccessibleTextInterface::setCursorPosition(int position)
2517
2518
    Moves the cursor to \a position.
2519
*/
2520
2521
/*!
2522
    \fn void QAccessibleTextInterface::setSelection(int selectionIndex, int startOffset, int endOffset)
2523
2524
    Set the selection \a selectionIndex to the range from \a startOffset to \a endOffset.
2525
2526
    \sa addSelection(), removeSelection()
2527
*/
2528
2529
/*!
2530
    \fn int QAccessibleTextInterface::characterCount() const
2531
2532
    Returns the length of the text (total size including spaces).
2533
*/
2534
2535
/*!
2536
    \fn void QAccessibleTextInterface::scrollToSubstring(int startIndex, int endIndex)
2537
2538
    Ensures that the text between \a startIndex and \a endIndex is visible.
2539
*/
2540
2541
/*!
2542
    \class QAccessibleEditableTextInterface
2543
    \ingroup accessibility
2544
    \inmodule QtGui
2545
2546
    \brief The QAccessibleEditableTextInterface class implements support for objects with editable text.
2547
2548
    When implementing this interface you will almost certainly also want to implement \l QAccessibleTextInterface.
2549
2550
    \sa QAccessibleInterface
2551
2552
    \l{IAccessible2 Specification}
2553
*/
2554
2555
/*!
2556
2557
    Destroys the QAccessibleEditableTextInterface.
2558
*/
2559
QAccessibleEditableTextInterface::~QAccessibleEditableTextInterface()
2560
0
{
2561
0
}
2562
2563
/*!
2564
    \fn void QAccessibleEditableTextInterface::deleteText(int startOffset, int endOffset)
2565
2566
    Deletes the text from \a startOffset to \a endOffset.
2567
*/
2568
2569
/*!
2570
    \fn void QAccessibleEditableTextInterface::insertText(int offset, const QString &text)
2571
2572
    Inserts \a text at position \a offset.
2573
*/
2574
2575
/*!
2576
    \fn void QAccessibleEditableTextInterface::replaceText(int startOffset, int endOffset, const QString &text)
2577
2578
    Removes the text from \a startOffset to \a endOffset and instead inserts \a text.
2579
*/
2580
2581
/*!
2582
    \class QAccessibleValueInterface
2583
    \inmodule QtGui
2584
    \ingroup accessibility
2585
2586
    \brief The QAccessibleValueInterface class implements support for objects that manipulate a value.
2587
2588
    This interface should be implemented by accessible objects that represent a value.
2589
    Examples are spinner, slider, dial and scroll bar.
2590
2591
    Instead of forcing the user to deal with the individual parts of the widgets, this interface
2592
    gives an easier approach to the kind of widget it represents.
2593
2594
    Usually this interface is implemented by classes that also implement \l QAccessibleInterface.
2595
2596
    \l{IAccessible2 Specification}
2597
*/
2598
2599
/*!
2600
    Destroys the QAccessibleValueInterface.
2601
2602
*/
2603
QAccessibleValueInterface::~QAccessibleValueInterface()
2604
0
{
2605
0
}
2606
2607
/*!
2608
    \fn QVariant QAccessibleValueInterface::currentValue() const
2609
2610
    Returns the current value of the widget. This is usually a double or int.
2611
    \sa setCurrentValue()
2612
*/
2613
2614
/*!
2615
    \fn void QAccessibleValueInterface::setCurrentValue(const QVariant &value)
2616
2617
    Sets the \a value. If the desired \a value is out of the range of permissible values,
2618
    this call will be ignored.
2619
2620
    \sa currentValue(), minimumValue(), maximumValue()
2621
*/
2622
2623
/*!
2624
    \fn QVariant QAccessibleValueInterface::maximumValue() const
2625
2626
    Returns the maximum value this object accepts.
2627
    \sa minimumValue(), currentValue()
2628
*/
2629
2630
/*!
2631
    \fn QVariant QAccessibleValueInterface::minimumValue() const
2632
2633
    Returns the minimum value this object accepts.
2634
    \sa maximumValue(), currentValue()
2635
*/
2636
2637
/*!
2638
    \fn QVariant QAccessibleValueInterface::minimumStepSize() const
2639
2640
    Returns the minimum step size for the accessible.
2641
    This is the smallest increment that makes sense when changing the value.
2642
    When programmatically changing the value it should always be a multiple
2643
    of the minimum step size.
2644
2645
    Some tools use this value even when the setCurrentValue does not
2646
    perform any action. Progress bars for example are read-only but
2647
    should return their range divided by 100.
2648
*/
2649
2650
/*!
2651
    \class QAccessibleImageInterface
2652
    \inmodule QtGui
2653
    \ingroup accessibility
2654
    \internal
2655
    \preliminary
2656
2657
    \brief The QAccessibleImageInterface class implements support for
2658
    the IAccessibleImage interface.
2659
2660
    \l{IAccessible2 Specification}
2661
*/
2662
2663
/*!
2664
    Destroys the QAccessibleImageInterface.
2665
*/
2666
QAccessibleImageInterface::~QAccessibleImageInterface()
2667
0
{
2668
0
}
2669
2670
/*!
2671
    \class QAccessibleTableCellInterface
2672
    \inmodule QtGui
2673
    \ingroup accessibility
2674
2675
    \brief The QAccessibleTableCellInterface class implements support for
2676
    the IAccessibleTable2 Cell interface.
2677
2678
    \l{IAccessible2 Specification}
2679
*/
2680
2681
/*!
2682
2683
    Destroys the QAccessibleTableCellInterface.
2684
*/
2685
QAccessibleTableCellInterface::~QAccessibleTableCellInterface()
2686
0
{
2687
0
}
2688
2689
/*!
2690
    \fn virtual int QAccessibleTableCellInterface::columnExtent() const
2691
2692
    Returns the number of columns occupied by this cell accessible.
2693
*/
2694
2695
/*!
2696
    \fn virtual QList<QAccessibleInterface*> QAccessibleTableCellInterface::columnHeaderCells() const
2697
2698
    Returns the column headers as an array of cell accessibles.
2699
*/
2700
2701
/*!
2702
    \fn virtual int QAccessibleTableCellInterface::columnIndex() const
2703
2704
    Translates this cell accessible into the corresponding column index.
2705
*/
2706
2707
/*!
2708
    \fn virtual int QAccessibleTableCellInterface::rowExtent() const
2709
2710
    Returns the number of rows occupied by this cell accessible.
2711
*/
2712
2713
/*!
2714
    \fn virtual QList<QAccessibleInterface*> QAccessibleTableCellInterface::rowHeaderCells() const
2715
2716
    Returns the row headers as an array of cell accessibles.
2717
*/
2718
2719
/*!
2720
    \fn virtual int QAccessibleTableCellInterface::rowIndex() const
2721
2722
    Translates this cell accessible into the corresponding row index.
2723
*/
2724
2725
/*!
2726
    \fn virtual bool QAccessibleTableCellInterface::isSelected() const
2727
2728
    Returns a boolean value indicating whether this cell is selected.
2729
*/
2730
2731
/*!
2732
    \fn virtual QAccessibleInterface *QAccessibleTableCellInterface::table() const
2733
2734
    Returns the QAccessibleInterface of the table containing this cell.
2735
*/
2736
2737
2738
/*!
2739
    \class QAccessibleTableInterface
2740
    \inmodule QtGui
2741
    \ingroup accessibility
2742
2743
    \brief The QAccessibleTableInterface class implements support for
2744
    the IAccessibleTable2 interface.
2745
2746
    \l{IAccessible2 Specification}
2747
*/
2748
2749
/*!
2750
2751
    Destroys the QAccessibleTableInterface.
2752
*/
2753
QAccessibleTableInterface::~QAccessibleTableInterface()
2754
0
{
2755
0
}
2756
2757
/*!
2758
    \fn virtual QAccessibleInterface *QAccessibleTableInterface::cellAt(int row, int column) const
2759
2760
    Returns the cell at the specified \a row and \a column in the table.
2761
*/
2762
2763
/*!
2764
    \fn virtual QAccessibleInterface *QAccessibleTableInterface::caption() const
2765
2766
    Returns the caption for the table.
2767
*/
2768
2769
/*!
2770
    \fn virtual QString QAccessibleTableInterface::columnDescription(int column) const
2771
2772
    Returns the description text of the specified \a column in the table.
2773
*/
2774
2775
/*!
2776
    \fn virtual int QAccessibleTableInterface::columnCount() const
2777
2778
    Returns the total number of columns in table.
2779
*/
2780
2781
/*!
2782
    \fn virtual int QAccessibleTableInterface::rowCount() const
2783
2784
    Returns the total number of rows in table.
2785
*/
2786
2787
/*!
2788
    \fn virtual int QAccessibleTableInterface::selectedCellCount() const
2789
2790
    Returns the total number of selected cells.
2791
*/
2792
2793
/*!
2794
    \fn virtual int QAccessibleTableInterface::selectedColumnCount() const
2795
2796
    Returns the total number of selected columns.
2797
*/
2798
2799
/*!
2800
    \fn virtual int QAccessibleTableInterface::selectedRowCount() const
2801
2802
    Returns the total number of selected rows.
2803
*/
2804
2805
/*!
2806
    \fn virtual QString QAccessibleTableInterface::rowDescription(int row) const
2807
2808
    Returns the description text of the specified \a row in the table.
2809
*/
2810
2811
/*!
2812
    \fn virtual QList<int> QAccessibleTableInterface::selectedCells() const
2813
2814
    Returns the list of selected cell (by their index as \l QAccessibleInterface::child() accepts).
2815
*/
2816
2817
/*!
2818
    \fn virtual QList<int> QAccessibleTableInterface::selectedColumns() const
2819
2820
    Returns the list of currently selected columns.
2821
*/
2822
2823
/*!
2824
    \fn virtual QList<int> QAccessibleTableInterface::selectedRows() const
2825
2826
    Returns the list of currently selected rows.
2827
*/
2828
2829
/*!
2830
    \fn virtual QAccessibleInterface *QAccessibleTableInterface::summary() const
2831
2832
    Returns a QAccessibleInterface that represents a summary of the table.
2833
    This function may return 0 if no such interface exists.
2834
*/
2835
2836
/*!
2837
    \fn virtual bool QAccessibleTableInterface::isColumnSelected(int column) const
2838
2839
    Returns a boolean value indicating whether the specified \a column is completely selected.
2840
*/
2841
2842
/*!
2843
    \fn virtual bool QAccessibleTableInterface::isRowSelected(int row) const
2844
2845
    Returns a boolean value indicating whether the specified \a row is completely selected.
2846
*/
2847
2848
/*!
2849
    \fn virtual bool QAccessibleTableInterface::selectRow(int row)
2850
2851
    Selects \a row. This function might unselect all previously selected rows.
2852
    Returns \c true if the selection was successful.
2853
*/
2854
2855
/*!
2856
    \fn virtual bool QAccessibleTableInterface::selectColumn(int column)
2857
2858
    Selects \a column. This function might unselect all previously selected columns.
2859
    Returns \c true if the selection was successful.
2860
*/
2861
2862
/*!
2863
    \fn virtual bool QAccessibleTableInterface::unselectRow(int row)
2864
2865
    Unselects \a row, leaving other selected rows selected (if any).
2866
    Returns \c true if the selection was successful.
2867
*/
2868
2869
/*!
2870
    \fn virtual bool QAccessibleTableInterface::unselectColumn(int column)
2871
2872
    Unselects \a column, leaving other selected columns selected (if any).
2873
    Returns \c true if the selection was successful.
2874
*/
2875
2876
/*!
2877
    \fn virtual void QAccessibleTableInterface::modelChange(QAccessibleTableModelChangeEvent *event)
2878
2879
    Informs about a change in the model's layout.
2880
    The \a event contains the details.
2881
    \sa QAccessibleTableModelChangeEvent
2882
*/
2883
2884
2885
/*!
2886
    \class QAccessibleActionInterface
2887
    \inmodule QtGui
2888
    \ingroup accessibility
2889
2890
    \brief The QAccessibleActionInterface class implements support for
2891
    invocable actions in the interface.
2892
2893
    Accessible objects should implement the action interface if they support user interaction.
2894
    Usually this interface is implemented by classes that also implement \l QAccessibleInterface.
2895
2896
    The supported actions should use the predefined actions offered in this class unless they do not
2897
    fit a predefined action. In that case a custom action can be added.
2898
2899
    When subclassing QAccessibleActionInterface you need to provide a list of actionNames which
2900
    is the primary means to discover the available actions. Action names are never localized.
2901
    In order to present actions to the user there are two functions that need to return localized versions
2902
    of the name and give a description of the action. For the predefined action names use
2903
    \l QAccessibleActionInterface::localizedActionName() and \l QAccessibleActionInterface::localizedActionDescription()
2904
    to return their localized counterparts.
2905
2906
    In general you should use one of the predefined action names, unless describing an action that does not fit these:
2907
    \table
2908
    \header \li Action name         \li Description
2909
    \row    \li \l toggleAction()   \li toggles the item (checkbox, radio button, switch, ...)
2910
    \row    \li \l decreaseAction() \li decrease the value of the accessible (e.g. spinbox)
2911
    \row    \li \l increaseAction() \li increase the value of the accessible (e.g. spinbox)
2912
    \row    \li \l pressAction()    \li press or click or activate the accessible (should correspond to clicking the object with the mouse)
2913
    \row    \li \l setFocusAction() \li set the focus to this accessible
2914
    \row    \li \l showOnScreenAction() \li move this accessible into the viewport
2915
    \row    \li \l showMenuAction() \li show a context menu, corresponds to right-clicks
2916
    \endtable
2917
2918
    In order to invoke the action, \l doAction() is called with an action name.
2919
2920
    Most widgets will simply implement \l pressAction(). This is what happens when the widget is activated by
2921
    being clicked, space pressed or similar.
2922
2923
    \l{IAccessible2 Specification}
2924
*/
2925
2926
/*!
2927
2928
    Destroys the QAccessibleActionInterface.
2929
*/
2930
QAccessibleActionInterface::~QAccessibleActionInterface()
2931
0
{
2932
0
}
2933
2934
/*!
2935
    \fn QStringList QAccessibleActionInterface::actionNames() const
2936
2937
    Returns the list of actions supported by this accessible object.
2938
    The actions returned should be in preferred order,
2939
    i.e. the action that the user most likely wants to trigger should be returned first,
2940
    while the least likely action should be returned last.
2941
2942
    The list does only contain actions that can be invoked.
2943
    It won't return disabled actions, or actions associated with disabled UI controls.
2944
2945
    The list can be empty.
2946
2947
    Note that this list is not localized. For a localized representation re-implement \l localizedActionName()
2948
    and \l localizedActionDescription()
2949
2950
    \sa doAction(), localizedActionName(), localizedActionDescription()
2951
*/
2952
2953
/*!
2954
    \fn QString QAccessibleActionInterface::localizedActionName(const QString &actionName) const
2955
2956
    Returns a localized action name of \a actionName.
2957
2958
    For custom actions this function has to be re-implemented.
2959
    When using one of the default names, you can call this function in QAccessibleActionInterface
2960
    to get the localized string.
2961
2962
    \sa actionNames(), localizedActionDescription()
2963
*/
2964
2965
/*!
2966
    \fn QString QAccessibleActionInterface::localizedActionDescription(const QString &actionName) const
2967
2968
    Returns a localized action description of the action \a actionName.
2969
2970
    When using one of the default names, you can call this function in QAccessibleActionInterface
2971
    to get the localized string.
2972
2973
    \sa actionNames(), localizedActionName()
2974
*/
2975
2976
/*!
2977
    \fn void QAccessibleActionInterface::doAction(const QString &actionName)
2978
2979
    Invokes the action specified by \a actionName.
2980
    Note that \a actionName is the non-localized name as returned by \l actionNames()
2981
    This function is usually implemented by calling the same functions
2982
    that other user interaction, such as clicking the object, would trigger.
2983
2984
    \sa actionNames()
2985
*/
2986
2987
/*!
2988
    \fn QStringList QAccessibleActionInterface::keyBindingsForAction(const QString &actionName) const
2989
2990
    Returns a list of the keyboard shortcuts available for invoking the action named \a actionName.
2991
2992
    This is important to let users learn alternative ways of using the application by emphasizing the keyboard.
2993
2994
    \sa actionNames()
2995
*/
2996
2997
2998
struct QAccessibleActionStrings
2999
{
3000
    QAccessibleActionStrings() :
3001
0
        pressAction(QStringLiteral(QT_TRANSLATE_NOOP("QAccessibleActionInterface", "Press"))),
3002
0
        increaseAction(QStringLiteral(QT_TRANSLATE_NOOP("QAccessibleActionInterface", "Increase"))),
3003
0
        decreaseAction(QStringLiteral(QT_TRANSLATE_NOOP("QAccessibleActionInterface", "Decrease"))),
3004
0
        showMenuAction(QStringLiteral(QT_TRANSLATE_NOOP("QAccessibleActionInterface", "Show Menu"))),
3005
0
        setFocusAction(QStringLiteral(QT_TRANSLATE_NOOP("QAccessibleActionInterface", "Set Focus"))),
3006
0
        showOnScreenAction(QStringLiteral(QT_TRANSLATE_NOOP("QAccessibleActionInterface", "Show on Screen"))),
3007
0
        toggleAction(QStringLiteral(QT_TRANSLATE_NOOP("QAccessibleActionInterface", "Toggle"))),
3008
0
        scrollLeftAction(QStringLiteral(QT_TRANSLATE_NOOP("QAccessibleActionInterface", "Scroll Left"))),
3009
0
        scrollRightAction(QStringLiteral(QT_TRANSLATE_NOOP("QAccessibleActionInterface", "Scroll Right"))),
3010
0
        scrollUpAction(QStringLiteral(QT_TRANSLATE_NOOP("QAccessibleActionInterface", "Scroll Up"))),
3011
0
        scrollDownAction(QStringLiteral(QT_TRANSLATE_NOOP("QAccessibleActionInterface", "Scroll Down"))),
3012
0
        previousPageAction(QStringLiteral(QT_TRANSLATE_NOOP("QAccessibleActionInterface", "Previous Page"))),
3013
0
        nextPageAction(QStringLiteral(QT_TRANSLATE_NOOP("QAccessibleActionInterface", "Next Page")))
3014
0
    {}
3015
3016
    const QString pressAction;
3017
    const QString increaseAction;
3018
    const QString decreaseAction;
3019
    const QString showMenuAction;
3020
    const QString setFocusAction;
3021
    const QString showOnScreenAction;
3022
    const QString toggleAction;
3023
    const QString scrollLeftAction;
3024
    const QString scrollRightAction;
3025
    const QString scrollUpAction;
3026
    const QString scrollDownAction;
3027
    const QString previousPageAction;
3028
    const QString nextPageAction;
3029
3030
    QString localizedDescription(const QString &actionName)
3031
0
    {
3032
0
        if (actionName == pressAction)
3033
0
            return QAccessibleActionInterface::tr("Triggers the action");
3034
0
        else if (actionName == increaseAction)
3035
0
            return QAccessibleActionInterface::tr("Increase the value");
3036
0
        else if (actionName == decreaseAction)
3037
0
            return QAccessibleActionInterface::tr("Decrease the value");
3038
0
        else if (actionName == showMenuAction)
3039
0
            return QAccessibleActionInterface::tr("Shows the menu");
3040
0
        else if (actionName == setFocusAction)
3041
0
            return QAccessibleActionInterface::tr("Sets the focus");
3042
0
        else if (actionName == showOnScreenAction)
3043
0
            return QAccessibleActionInterface::tr("Moves the element into the visible area");
3044
0
        else if (actionName == toggleAction)
3045
0
            return QAccessibleActionInterface::tr("Toggles the state");
3046
0
        else if (actionName == scrollLeftAction)
3047
0
            return QAccessibleActionInterface::tr("Scrolls to the left");
3048
0
        else if (actionName == scrollRightAction)
3049
0
            return QAccessibleActionInterface::tr("Scrolls to the right");
3050
0
        else if (actionName == scrollUpAction)
3051
0
            return QAccessibleActionInterface::tr("Scrolls up");
3052
0
        else if (actionName == scrollDownAction)
3053
0
            return QAccessibleActionInterface::tr("Scrolls down");
3054
0
        else if (actionName == previousPageAction)
3055
0
            return QAccessibleActionInterface::tr("Goes back a page");
3056
0
        else if (actionName == nextPageAction)
3057
0
            return QAccessibleActionInterface::tr("Goes to the next page");
3058
3059
3060
0
        return QString();
3061
0
    }
3062
};
3063
3064
Q_GLOBAL_STATIC(QAccessibleActionStrings, accessibleActionStrings)
3065
3066
QString QAccessibleActionInterface::localizedActionName(const QString &actionName) const
3067
0
{
3068
0
    return QAccessibleActionInterface::tr(qPrintable(actionName));
3069
0
}
3070
3071
QString QAccessibleActionInterface::localizedActionDescription(const QString &actionName) const
3072
0
{
3073
0
    return accessibleActionStrings()->localizedDescription(actionName);
3074
0
}
3075
3076
/*!
3077
    Returns the name of the press default action.
3078
    \sa actionNames(), localizedActionName()
3079
  */
3080
const QString &QAccessibleActionInterface::pressAction()
3081
0
{
3082
0
    return accessibleActionStrings()->pressAction;
3083
0
}
3084
3085
/*!
3086
    Returns the name of the increase default action.
3087
    \sa actionNames(), localizedActionName()
3088
  */
3089
const QString &QAccessibleActionInterface::increaseAction()
3090
0
{
3091
0
    return accessibleActionStrings()->increaseAction;
3092
0
}
3093
3094
/*!
3095
    Returns the name of the decrease default action.
3096
    \sa actionNames(), localizedActionName()
3097
  */
3098
const QString &QAccessibleActionInterface::decreaseAction()
3099
0
{
3100
0
    return accessibleActionStrings()->decreaseAction;
3101
0
}
3102
3103
/*!
3104
    Returns the name of the show menu default action.
3105
    \sa actionNames(), localizedActionName()
3106
  */
3107
const QString &QAccessibleActionInterface::showMenuAction()
3108
0
{
3109
0
    return accessibleActionStrings()->showMenuAction;
3110
0
}
3111
3112
/*!
3113
    Returns the name of the set focus default action.
3114
    \sa actionNames(), localizedActionName()
3115
  */
3116
const QString &QAccessibleActionInterface::setFocusAction()
3117
0
{
3118
0
    return accessibleActionStrings()->setFocusAction;
3119
0
}
3120
3121
/*!
3122
    \since 6.12
3123
    Returns the name of the show on screen default action.
3124
    \sa actionNames(), localizedActionName()
3125
  */
3126
const QString &QAccessibleActionInterface::showOnScreenAction()
3127
0
{
3128
0
    return accessibleActionStrings()->showOnScreenAction;
3129
0
}
3130
3131
/*!
3132
    Returns the name of the toggle default action.
3133
    \sa actionNames(), localizedActionName()
3134
  */
3135
const QString &QAccessibleActionInterface::toggleAction()
3136
0
{
3137
0
    return accessibleActionStrings()->toggleAction;
3138
0
}
3139
3140
/*!
3141
    Returns the name of the scroll left default action.
3142
    \sa actionNames(), localizedActionName()
3143
  */
3144
QString QAccessibleActionInterface::scrollLeftAction()
3145
0
{
3146
0
    return accessibleActionStrings()->scrollLeftAction;
3147
0
}
3148
3149
/*!
3150
    Returns the name of the scroll right default action.
3151
    \sa actionNames(), localizedActionName()
3152
  */
3153
QString QAccessibleActionInterface::scrollRightAction()
3154
0
{
3155
0
    return accessibleActionStrings()->scrollRightAction;
3156
0
}
3157
3158
/*!
3159
    Returns the name of the scroll up default action.
3160
    \sa actionNames(), localizedActionName()
3161
  */
3162
QString QAccessibleActionInterface::scrollUpAction()
3163
0
{
3164
0
    return accessibleActionStrings()->scrollUpAction;
3165
0
}
3166
3167
/*!
3168
    Returns the name of the scroll down default action.
3169
    \sa actionNames(), localizedActionName()
3170
  */
3171
QString QAccessibleActionInterface::scrollDownAction()
3172
0
{
3173
0
    return accessibleActionStrings()->scrollDownAction;
3174
0
}
3175
3176
/*!
3177
    Returns the name of the previous page default action.
3178
    \sa actionNames(), localizedActionName()
3179
  */
3180
QString QAccessibleActionInterface::previousPageAction()
3181
0
{
3182
0
    return accessibleActionStrings()->previousPageAction;
3183
0
}
3184
3185
/*!
3186
    Returns the name of the next page default action.
3187
    \sa actionNames(), localizedActionName()
3188
  */
3189
QString QAccessibleActionInterface::nextPageAction()
3190
0
{
3191
0
    return accessibleActionStrings()->nextPageAction;
3192
0
}
3193
3194
3195
/*!
3196
    \since 6.5
3197
    \class QAccessibleSelectionInterface
3198
    \inmodule QtGui
3199
    \ingroup accessibility
3200
3201
    \brief The QAccessibleSelectionInterface class implements support for
3202
    selection handling.
3203
3204
    It provides methods for both, retrieving the current selection
3205
    as well as modifying the selection.
3206
3207
    Only selections of direct children are supported.
3208
*/
3209
3210
/*!
3211
3212
    Destroys the QAccessibleSelectionInterface.
3213
*/
3214
QAccessibleSelectionInterface::~QAccessibleSelectionInterface()
3215
0
{
3216
0
}
3217
3218
/*!
3219
    \fn virtual int QAccessibleSelectionInterface::selectedItemCount() const
3220
3221
    Returns the total number of selected accessible items.
3222
*/
3223
3224
/*!
3225
    \fn virtual QList<QAccessibleInterface *> QAccessibleSelectionInterface::selectedItems() const
3226
3227
    Returns the list of selected accessible items.
3228
*/
3229
3230
/*!
3231
    Returns the selected accessible item at index \a selectionIndex in the selection.
3232
3233
    Note that the index refers to the n-th selected accessible item (i.e. the index in the current selection),
3234
    which generally differs from the index that would be passed to \l QAccessibleInterface::child()
3235
    in order to retrieve the same item.
3236
3237
    The default implementation uses \a selectionIndex to retrieve the item from the list
3238
    of selected items retrieved by \l QAccessibleSelectionInterface::selectedItems().
3239
3240
    In particular for implementations dealing with many selected items, reimplementing
3241
    this method in a more efficient way may be desirable for performance reasons.
3242
*/
3243
QAccessibleInterface* QAccessibleSelectionInterface::selectedItem(int selectionIndex) const
3244
0
{
3245
0
    QList<QAccessibleInterface*> items = selectedItems();
3246
0
    if (selectionIndex < 0 || selectionIndex > items.length() -1) {
3247
0
        qCWarning(lcAccessibilityCore) << "Selection index" << selectionIndex << "out of range.";
3248
0
        return nullptr;
3249
0
    }
3250
3251
0
    return items.at(selectionIndex);
3252
0
}
3253
3254
/*!
3255
    Returns whether \a childItem is part of the current selection.
3256
3257
    The default implementation checks whether \a childItem is contained
3258
    in the list of items retrieved by \l QAccessibleSelectionInterface::selectedItems.
3259
*/
3260
bool QAccessibleSelectionInterface::isSelected(QAccessibleInterface *childItem) const
3261
0
{
3262
0
    return selectedItems().contains(childItem);
3263
0
}
3264
3265
/*!
3266
    \fn virtual bool QAccessibleSelectionInterface::select(QAccessibleInterface *childItem)
3267
3268
    Adds \a childItem to the selection.
3269
    Returns whether \a childItem has actually been added to the selection.
3270
3271
    For implementations that only allow single selections,
3272
    this may replace the current selection.
3273
*/
3274
3275
/*!
3276
    \fn virtual bool QAccessibleSelectionInterface::unselect(QAccessibleInterface *childItem)
3277
3278
    Removes \a childItem from the selection.
3279
3280
    Returns whether the accessible item has actually been removed from the selection.
3281
*/
3282
3283
/*!
3284
    \fn virtual bool QAccessibleSelectionInterface::selectAll()
3285
3286
    Selects all accessible child items.
3287
3288
    Returns whether all accessible child items have actually been added to the selection.
3289
*/
3290
3291
/*!
3292
    \fn virtual bool QAccessibleSelectionInterface::clear()
3293
3294
    Unselects all accessible child items.
3295
3296
    Returns whether all accessible child items have actually been removed from the selection,
3297
    i.e. whether the selection is empty after this method has been called.
3298
*/
3299
3300
3301
/*!
3302
    \since 6.8
3303
    \class QAccessibleAttributesInterface
3304
    \inmodule QtGui
3305
    \ingroup accessibility
3306
3307
 \brief The QAccessibleAttributesInterface class implements support for
3308
 reporting attributes for an accessible object.
3309
3310
 Attributes are key-value pairs. Values are stored in \l QVariant.
3311
3312
 The \l QAccessible::Attribute enumeration describes the available keys and
3313
 documents which type to use for the value of each key.
3314
3315
 While the text-specific attributes handled by \l QAccessibleTextInterface::attributes
3316
 are specific to objects implementing text and are specific to a specific text
3317
 position/offset, the attributes handled by the \l QAccessibleAttributesInterface
3318
 can be used for objects of any role and apply for the whole object.
3319
3320
 Classes already implementing \l QAccessibleTextInterface for text-specific attrtibutes
3321
 may want to implement \l QAccessibleAttributesInterface in addition for object-specific
3322
 attributes.
3323
*/
3324
3325
/*!
3326
3327
 Destroys the QAccessibleAttributesInterface.
3328
*/
3329
QAccessibleAttributesInterface::~QAccessibleAttributesInterface()
3330
0
{
3331
0
}
3332
3333
/*!
3334
    \fn QList<QAccessible::Attribute> QAccessibleAttributesInterface::attributeKeys() const
3335
3336
 Returns the keys of all attributes currently set for the object. For each returned
3337
 key, attributeValue() returns a valid QVariant. The \l QAccessible::Attribute
3338
 enumeration describes available keys.
3339
*/
3340
3341
/*!
3342
    \fn QVariant QAccessibleAttributesInterface::attributeValue(QAccessible::Attribute key) const
3343
3344
 Returns the value of the attribute \a key of this object.
3345
3346
 If the attribute is set for this object, a value of the type documented for the
3347
 given key in the documentation of the \l QAccessible::Attribute enumeration is
3348
 returned in the \l QVariant.
3349
3350
 Otherwise, an invalid \l QVariant is returned.
3351
*/
3352
3353
/*! \internal */
3354
QString qAccessibleLocalizedActionDescription(const QString &actionName)
3355
0
{
3356
0
    return accessibleActionStrings()->localizedDescription(actionName);
3357
0
}
3358
3359
/*!
3360
    \internal
3361
    \fn QString QAccessibleHyperlinkInterface::anchor() const
3362
3363
    The logical/human readable name of the hyperlink
3364
*/
3365
3366
/*!
3367
    \internal
3368
    \fn QString QAccessibleHyperlinkInterface::anchorTarget() const
3369
3370
    The target url of the hyperlink
3371
*/
3372
3373
/*!
3374
    \internal
3375
    \fn int QAccessibleHyperlinkInterface::startIndex() const
3376
3377
    Returns the start index that will refer to the first character in the text where the hyperlink
3378
    begins. The index corresponds to the index that the QAccessibleTextInterface needs in order
3379
    to find the start of the hyperlink.
3380
3381
*/
3382
3383
/*!
3384
    \internal
3385
    \fn int QAccessibleHyperlinkInterface::endIndex() const
3386
3387
    Returns the end index that will refer to the first character in the text where the hyperlink
3388
    begins. The index corresponds to the index that the QAccessibleTextInterface needs in order
3389
    to find the end of the hyperlink.
3390
*/
3391
3392
QAccessibleHyperlinkInterface::~QAccessibleHyperlinkInterface()
3393
0
{
3394
3395
0
}
3396
3397
/*!
3398
    \since 6.12
3399
    \class QAccessibleViewportInterface
3400
    \inmodule QtGui
3401
    \ingroup accessibility
3402
    \preliminary
3403
3404
    \brief The QAccessibleViewportInterface class implements support for viewports.
3405
3406
    This interface should be implemented by accessible objects that allow an 2-dimensional
3407
    or indexed viewports (e.g. by scrolling). For example lists or flickable views.
3408
*/
3409
3410
/*!
3411
    Destroys the QAccessibleViewportInterface.
3412
3413
*/
3414
QAccessibleViewportInterface::~QAccessibleViewportInterface()
3415
0
{
3416
0
}
3417
3418
/*!
3419
    \fn QSizeF QAccessibleViewportInterface::contentSize() const
3420
3421
    Returns the total size of the content in absolute values. For non-indexed viewports this will return
3422
    the absolute size of the underlying content, for indexed viewports the count of rows and columns is
3423
    returned.
3424
*/
3425
3426
/*!
3427
    \fn QPointF QAccessibleViewportInterface::position() const
3428
3429
    Returns the current position within the viewport in normalized values.
3430
*/
3431
3432
/*!
3433
    \fn QSizeF QAccessibleViewportInterface::viewportSize() const
3434
3435
    Returns the currently visible portion of the content in normalized values.
3436
*/
3437
3438
/*!
3439
    \fn bool QAccessibleViewportInterface::isIndexed() const
3440
3441
    Returns true if the underlying content is indexed (e.g. a list of items).
3442
*/
3443
3444
/*!
3445
    \fn void QAccessibleViewportInterface::setPosition(QPointF position)
3446
3447
    Sets the viewport's position to the given \a position defined in normalized values.
3448
*/
3449
3450
#endif // QT_CONFIG(accessibility)
3451
3452
QT_END_NAMESPACE
3453
3454
#include "moc_qaccessible_base.cpp"