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