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