Coverage Report

Created: 2026-08-25 06:40

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