Coverage Report

Created: 2025-07-23 08:13

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