1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
42 #include "qaccessible.h"
44 #include "qaccessibleplugin.h"
45 #include "qaccessibleobject.h"
46 #include "qaccessiblebridge.h"
47 #include <QtGui/QGuiApplication>
48 #include <private/qguiapplication_p.h>
49 #include <qpa/qplatformaccessibility.h>
50 #include <qpa/qplatformintegration.h>
52 #include <QtCore/qdebug.h>
53 #include <QtCore/qmetaobject.h>
54 #include <private/qfactoryloader_p.h>
60 \brief The QAccessible class provides enums and static functions
61 related to accessibility.
64 \ingroup accessibility
67 This class is part of \l {Accessibility for QWidget Applications}.
69 Accessible applications can be used by people who are not able to
70 use applications by conventional means.
72 The functions in this class are used for communication between
73 accessible applications (also called AT Servers) and
74 accessibility tools (AT Clients), such as screen readers and
75 braille displays. Clients and servers communicate in the following way:
78 \li \e{AT Servers} notify the clients about events through calls to the
79 updateAccessibility() function.
81 \li \e{AT Clients} request information about the objects in the server.
82 The QAccessibleInterface class is the core interface, and encapsulates
83 this information in a pure virtual API. Implementations of the interface
84 are provided by Qt through the queryAccessibleInterface() API.
87 The communication between servers and clients is initialized by
88 the setRootObject() function. Function pointers can be installed
89 to replace or extend the default behavior of the static functions
92 Qt supports Microsoft Active Accessibility (MSAA), Mac OS X
93 Accessibility, and the Unix/X11 AT-SPI standard. Other backends
94 can be supported using QAccessibleBridge.
96 In addition to QAccessible's static functions, Qt offers one
97 generic interface, QAccessibleInterface, that can be used to wrap
98 all widgets and objects (e.g., QPushButton). This single
99 interface provides all the metadata necessary for the assistive
100 technologies. Qt provides implementations of this interface for
101 its built-in widgets as plugins.
103 When you develop custom widgets, you can create custom subclasses
104 of QAccessibleInterface and distribute them as plugins (using
105 QAccessiblePlugin) or compile them into the application.
106 Likewise, Qt's predefined accessibility support can be built as
107 plugin (the default) or directly into the Qt library. The main
108 advantage of using plugins is that the accessibility classes are
109 only loaded into memory if they are actually used; they don't
110 slow down the common case where no assistive technology is being
113 Qt also includes two convenience classes, QAccessibleObject and
114 QAccessibleWidget, that inherit from QAccessibleInterface and
115 provide the lowest common denominator of metadata (e.g., widget
116 geometry, window title, basic help text). You can use them as
117 base classes when wrapping your custom QObject or QWidget
120 \sa QAccessibleInterface
125 \class QAccessible::State
129 This structure defines bit flags that indicate
130 the state of an accessible object. The values are:
132 \value active The object is the active window or the active sub-element in a container (that would get focus when focusing the container).
133 \value adjustable The object represents an adjustable value, e.g. sliders.
134 \value animated The object's appearance changes frequently.
135 \value busy The object cannot accept input at the moment.
136 \value checkable The object is checkable.
137 \value checked The object's check box is checked.
138 \value checkStateMixed The third state of checkboxes (half checked in tri-state check boxes).
139 \value collapsed The object is collapsed, e.g. a closed listview item, or an iconified window.
140 \value defaultButton The object represents the default button in a dialog.
141 \value defunct The object no longer exists.
142 \value editable The object has a text carret (and often implements the text interface).
143 \value expandable The object is expandable, mostly used for cells in a tree view.
144 \value expanded The object is expanded, currently its children are visible.
145 \value extSelectable The object supports extended selection.
146 \value focusable The object can receive focus. Only objects in the active window can receive focus.
147 \value focused The object has keyboard focus.
148 \value hasPopup The object opens a popup.
149 \value hotTracked The object's appearance is sensitive to the mouse cursor position.
150 \value invalid The object is no longer valid (because it has been deleted).
151 \value invalidEntry Input validation current input invalid.
152 \value invisible The object is not visible to the user.
153 \value linked The object is linked to another object, e.g. a hyperlink.
154 \value marqueed The object displays scrolling contents, e.g. a log view.
155 \value modal The object blocks input from other objects.
156 \value movable The object can be moved.
157 \value multiLine The object has multiple lines of text (word wrap), as opposed to a single line.
158 \value multiSelectable The object supports multiple selected items.
159 \value offscreen The object is clipped by the visible area. Objects that are off screen are also invisible.
160 \value passwordEdit The object is a password field, e.g. a line edit for entering a Password.
161 \value playsSound The object produces sound when interacted with.
162 \value pressed The object is pressed.
163 \value readOnly The object can usually be edited, but is explicitly set to read-only.
164 \value selectable The object is selectable.
165 \value selectableText The object has text which can be selected. This is different from selectable which refers to the object's children.
166 \value selected The object is selected.
167 \value selfVoicing The object describes itself through speech or sound.
168 \value sizeable The object can be resized, e.g. top-level windows.
169 \value summaryElement The object summarizes the state of the window and should be treated with priority.
170 \value supportsAutoCompletion The object has auto-completion, for example in line edits or combo boxes.
171 \value traversed The object is linked and has been visited.
172 \value updatesFrequently The object changes frequently and needs to be refreshed when accessing it.
173 \value disabled The object is unavailable to the user, e.g. a disabled widget.
175 Implementations of QAccessibleInterface::state() return a combination
180 \fn QAccessible::State::State()
182 Creates a new QAccessible::State with all states set to false.
186 \enum QAccessible::Event
188 This enum type defines accessible event types.
190 \value AcceleratorChanged The keyboard accelerator for an action has been changed.
191 \value ActionChanged An action has been changed.
192 \value ActiveDescendantChanged
193 \value Alert A system alert (e.g., a message from a QMessageBox)
194 \value AttributeChanged
195 \value ContextHelpEnd Context help (QWhatsThis) for an object is finished.
196 \value ContextHelpStart Context help (QWhatsThis) for an object is initiated.
197 \value DefaultActionChanged The default QAccessible::Action for the accessible
199 \value DescriptionChanged The object's QAccessible::Description changed.
200 \value DialogEnd A dialog (QDialog) has been hidden
201 \value DialogStart A dialog (QDialog) has been set visible.
202 \value DocumentContentChanged The contents of a text document have changed.
203 \value DocumentLoadComplete A document has been loaded.
204 \value DocumentLoadStopped A document load has been stopped.
205 \value DocumentReload A document reload has been initiated.
206 \value DragDropEnd A drag and drop operation is about to finished.
207 \value DragDropStart A drag and drop operation is about to be initiated.
208 \value Focus An object has gained keyboard focus.
209 \value ForegroundChanged A window has been activated (i.e., a new window has
210 gained focus on the desktop).
211 \value HelpChanged The QAccessible::Help text property of an object has
213 \value HyperlinkEndIndexChanged The end position of the display text for a hypertext
215 \value HyperlinkNumberOfAnchorsChanged The number of anchors in a hypertext link has changed,
216 perhaps because the display text has been split to
217 provide more than one link.
218 \value HyperlinkSelectedLinkChanged The link for the selected hypertext link has changed.
219 \value HyperlinkStartIndexChanged The start position of the display text for a hypertext
221 \value HypertextChanged The display text for a hypertext link has changed.
222 \value HypertextLinkActivated A hypertext link has been activated, perhaps by being
223 clicked or via a key press.
224 \value HypertextLinkSelected A hypertext link has been selected.
225 \value HypertextNLinksChanged
226 \value LocationChanged An object's location on the screen has changed.
227 \value MenuCommand A menu item is triggered.
228 \value MenuEnd A menu has been closed (Qt uses PopupMenuEnd for all
230 \value MenuStart A menu has been opened on the menubar (Qt uses
231 PopupMenuStart for all menus).
232 \value NameChanged The QAccessible::Name property of an object has changed.
233 \value ObjectAttributeChanged
234 \value ObjectCreated A new object is created.
235 \value ObjectDestroyed An object is deleted.
236 \value ObjectHide An object is hidden; for example, with QWidget::hide().
237 Any children the object that is hidden has do not send
238 this event. It is not sent when an object is hidden as
239 it is being obcured by others.
240 \value ObjectReorder A layout or item view has added, removed, or moved an
241 object (Qt does not use this event).
242 \value ObjectShow An object is displayed; for example, with
245 \value ParentChanged An object's parent object changed.
246 \value PopupMenuEnd A pop-up menu has closed.
247 \value PopupMenuStart A pop-up menu has opened.
248 \value ScrollingEnd A scrollbar scroll operation has ended (the mouse has
249 released the slider handle).
250 \value ScrollingStart A scrollbar scroll operation is about to start; this may
251 be caused by a mouse press on the slider handle, for
253 \value SectionChanged
254 \value SelectionAdd An item has been added to the selection in an item view.
255 \value SelectionRemove An item has been removed from an item view selection.
256 \value Selection The selection has changed in a menu or item view.
257 \value SelectionWithin Several changes to a selection has occurred in an item
259 \value SoundPlayed A sound has been played by an object
260 \omitvalue StateChanged The QAccessible::State of an object has changed.
261 This value is used internally for the QAccessibleStateChangeEvent.
262 \value TableCaptionChanged A table caption has been changed.
263 \value TableColumnDescriptionChanged The description of a table column, typically found in
264 the column's header, has been changed.
265 \value TableColumnHeaderChanged A table column header has been changed.
266 \value TableModelChanged The model providing data for a table has been changed.
267 \value TableRowDescriptionChanged The description of a table row, typically found in the
268 row's header, has been changed.
269 \value TableRowHeaderChanged A table row header has been changed.
270 \value TableSummaryChanged The summary of a table has been changed.
271 \omitvalue TextAttributeChanged
272 \omitvalue TextCaretMoved The caret has moved in an editable widget.
273 The caret represents the cursor position in an editable
274 widget with the input focus.
275 \value TextColumnChanged A text column has been changed.
276 \omitvalue TextInserted Text has been inserted into an editable widget.
277 \omitvalue TextRemoved Text has been removed from an editable widget.
278 \omitvalue TextSelectionChanged The selected text has changed in an editable widget.
279 \omitvalue TextUpdated The text has been update in an editable widget.
280 \omitvalue ValueChanged The QAccessible::Value of an object has changed.
281 \value VisibleDataChanged
283 The values for this enum are defined to be the same as those defined in the
284 \l{AccessibleEventID.idl File Reference}{IAccessible2} and
285 \l{Microsoft Active Accessibility Event Constants}{MSAA} specifications.
289 \enum QAccessible::Role
291 This enum defines the role of an accessible object. The roles are:
293 \value AlertMessage An object that is used to alert the user.
294 \value Animation An object that displays an animation.
295 \value Application The application's main window.
296 \value Assistant An object that provids interactive help.
297 \value Border An object that represents a border.
298 \value ButtonDropDown A button that drops down a list of items.
299 \value ButtonDropGrid A button that drops down a grid.
300 \value ButtonMenu A button that drops down a menu.
301 \value Canvas An object that displays graphics that the user can interact with.
302 \value Caret An object that represents the system caret (text cursor).
303 \value Cell A cell in a table.
304 \value Chart An object that displays a graphical representation of data.
305 \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.
306 \value Client The client area in a window.
307 \value Clock A clock displaying time.
308 \value Column A column of cells, usually within a table.
309 \value ColumnHeader A header for a column of data.
310 \value ComboBox A list of choices that the user can select from.
311 \value Cursor An object that represents the mouse cursor.
312 \value Desktop The object represents the desktop or workspace.
313 \value Dial An object that represents a dial or knob.
314 \value Dialog A dialog box.
315 \value Document A document window, usually in an MDI environment.
316 \value EditableText Editable text
317 \value Equation An object that represents a mathematical equation.
318 \value Graphic A graphic or picture, e.g. an icon.
319 \value Grip A grip that the user can drag to change the size of widgets.
320 \value Grouping An object that represents a logical grouping of other objects.
321 \value HelpBalloon An object that displays help in a separate, short lived window.
322 \value HotkeyField A hotkey field that allows the user to enter a key sequence.
323 \value Indicator An indicator that represents a current value or item.
324 \value LayeredPane An object that can contain layered children, e.g. in a stack.
325 \value Link A link to something else.
326 \value List A list of items, from which the user can select one or more items.
327 \value ListItem An item in a list of items.
328 \value MenuBar A menu bar from which menus are opened by the user.
329 \value MenuItem An item in a menu or menu bar.
330 \value NoRole The object has no role. This usually indicates an invalid object.
331 \value PageTab A page tab that the user can select to switch to a different page in a dialog.
332 \value PageTabList A list of page tabs.
333 \value Pane A generic container.
334 \value PopupMenu A menu which lists options that the user can select to perform an action.
335 \value ProgressBar The object displays the progress of an operation in progress.
336 \value PropertyPage A property page where the user can change options and settings.
337 \value Button A button.
338 \value RadioButton An object that represents an option that is mutually exclusive with other options.
339 \value Row A row of cells, usually within a table.
340 \value RowHeader A header for a row of data.
341 \value ScrollBar A scroll bar, which allows the user to scroll the visible area.
342 \value Separator A separator that divides space into logical areas.
343 \value Slider A slider that allows the user to select a value within a given range.
344 \value Sound An object that represents a sound.
345 \value SpinBox A spin box widget that allows the user to enter a value within a given range.
346 \value Splitter A splitter distributing available space between its child widgets.
347 \value StaticText Static text, such as labels for other widgets.
348 \value StatusBar A status bar.
349 \value Table A table representing data in a grid of rows and columns.
350 \value Terminal A terminal or command line interface.
351 \value TitleBar The title bar caption of a window.
352 \value ToolBar A tool bar, which groups widgets that the user accesses frequently.
353 \value ToolTip A tool tip which provides information about other objects.
354 \value Tree A list of items in a tree structure.
355 \value TreeItem An item in a tree structure.
356 \value UserRole The first value to be used for user defined roles.
357 \value Whitespace Blank space between other objects.
358 \value Window A top level window.
362 \enum QAccessible::RelationFlag
364 This enum type defines bit flags that can be combined to indicate
365 the relationship between two accessible objects.
367 \value Label The first object is the label of the second object.
368 \value Labelled The first object is labelled by the second object.
369 \value Controller The first object controls the second object.
370 \value Controlled The first object is controlled by the second object.
371 \value AllRelations Used as a mask to specify that we are interesting in information
374 Implementations of relations() return a combination of these flags.
375 Some values are mutually exclusive.
379 \enum QAccessible::Text
381 This enum specifies string information that an accessible object
384 \value Name The name of the object. This can be used both
385 as an identifier or a short description by
387 \value Description A short text describing the object.
388 \value Value The value of the object.
389 \value Help A longer text giving information about how to use the object.
390 \value Accelerator The keyboard shortcut that executes the object's default action.
391 \value UserText The first value to be used for user defined text.
392 \omitvalue DebugDescription
396 \enum QAccessible::InterfaceType
398 \l QAccessibleInterface supports several sub interfaces.
399 In order to provide more information about some objects, their accessible
400 representation should implement one or more of these interfaces.
401 When subclassing one of these interfaces, \l QAccessibleInterface::interface_cast also needs to be implemented.
403 \value TextInterface For text that supports selections or is more than one line. Simple labels do not need to implement this interface.
404 \value EditableTextInterface For text that can be edited by the user.
405 \value ValueInterface For objects that are used to manipulate a value, for example slider or scroll bar.
406 \value ActionInterface For interactive objects that allow the user to trigger an action. Basically everything that allows for example mouse interaction.
407 \omitvalue ImageInterface For objects that represent an image. This interface is generally less important.
408 \value TableInterface For lists, tables and trees.
409 \value TableCellInterface For cells in a TableInterface object.
411 \sa QAccessibleInterface::interface_cast, QAccessibleTextInterface, QAccessibleEditableTextInterface, QAccessibleValueInterface, QAccessibleActionInterface, QAccessibleTableInterface, QAccessibleTableCellInterface
415 \fn QAccessibleInterface::~QAccessibleInterface()
423 /* accessible widgets plugin discovery stuff */
424 #ifndef QT_NO_LIBRARY
425 Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
426 (QAccessibleFactoryInterface_iid, QLatin1String("/accessible")))
429 Q_GLOBAL_STATIC(QList<QAccessible::InterfaceFactory>, qAccessibleFactories)
431 QAccessible::UpdateHandler QAccessible::updateHandler = 0;
432 QAccessible::RootObjectHandler QAccessible::rootObjectHandler = 0;
434 static bool accessibility_active = false;
435 static bool cleanupAdded = false;
437 static QPlatformAccessibility *platformAccessibility()
439 QPlatformIntegration *pfIntegration = QGuiApplicationPrivate::platformIntegration();
440 return pfIntegration ? pfIntegration->accessibility() : 0;
446 void QAccessible::cleanup()
448 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
449 pfAccessibility->cleanup();
452 static void qAccessibleCleanup()
454 qAccessibleFactories()->clear();
458 \typedef QAccessible::InterfaceFactory
460 This is a typedef for a pointer to a function with the following
463 \snippet code/src_gui_accessible_qaccessible.cpp 1
465 The function receives a QString and a QObject pointer, where the
466 QString is the key identifying the interface. The QObject is used
467 to pass on to the QAccessibleInterface so that it can hold a reference
470 If the key and the QObject does not have a corresponding
471 QAccessibleInterface, a null-pointer will be returned.
473 Installed factories are called by queryAccessibilityInterface() until
474 one provides an interface.
478 \typedef QAccessible::UpdateHandler
482 A function pointer type. Use a function with this prototype to install
483 your own update function.
485 The function is called by updateAccessibility().
489 \typedef QAccessible::RootObjectHandler
493 A function pointer type. Use a function with this prototype to install
494 your own root object handler.
496 The function is called by setRootObject().
501 Installs the InterfaceFactory \a factory. The last factory added
502 is the first one used by queryAccessibleInterface().
504 void QAccessible::installFactory(InterfaceFactory factory)
510 qAddPostRoutine(qAccessibleCleanup);
513 if (qAccessibleFactories()->contains(factory))
515 qAccessibleFactories()->append(factory);
519 Removes \a factory from the list of installed InterfaceFactories.
521 void QAccessible::removeFactory(InterfaceFactory factory)
523 qAccessibleFactories()->removeAll(factory);
529 Installs the given \a handler as the function to be used by
530 updateAccessibility(), and returns the previously installed
533 QAccessible::UpdateHandler QAccessible::installUpdateHandler(UpdateHandler handler)
535 UpdateHandler old = updateHandler;
536 updateHandler = handler;
541 Installs the given \a handler as the function to be used by setRootObject(),
542 and returns the previously installed handler.
544 QAccessible::RootObjectHandler QAccessible::installRootObjectHandler(RootObjectHandler handler)
546 RootObjectHandler old = rootObjectHandler;
547 rootObjectHandler = handler;
552 If a QAccessibleInterface implementation exists for the given \a object,
553 this function returns a pointer to the implementation; otherwise it
556 The function calls all installed factory functions (from most
557 recently installed to least recently installed) until one is found
558 that provides an interface for the class of \a object. If no
559 factory can provide an accessibility implementation for the class
560 the function loads installed accessibility plugins, and tests if
561 any of the plugins can provide the implementation.
563 If no implementation for the object's class is available, the
564 function tries to find an implementation for the object's parent
565 class, using the above strategy.
567 \warning The caller is responsible for deleting the returned
570 QAccessibleInterface *QAccessible::queryAccessibleInterface(QObject *object)
572 accessibility_active = true;
576 const QMetaObject *mo = object->metaObject();
578 const QString cn = QLatin1String(mo->className());
579 for (int i = qAccessibleFactories()->count(); i > 0; --i) {
580 InterfaceFactory factory = qAccessibleFactories()->at(i - 1);
581 if (QAccessibleInterface *iface = factory(cn, object))
584 #ifndef QT_NO_LIBRARY
585 if (QAccessibleInterface * iface = qLoadPlugin1<QAccessibleInterface, QAccessiblePlugin>(loader(), cn, object))
588 mo = mo->superClass();
592 return new QAccessibleApplication;
598 Returns true if an accessibility implementation has been requested
599 during the runtime of the application; otherwise returns false.
601 Use this function to prevent potentially expensive notifications via
602 updateAccessibility().
604 bool QAccessible::isActive()
606 return accessibility_active;
612 Sets the root object of the accessible objects of this application
613 to \a object. All other accessible objects are reachable using object
614 navigation from the root object.
616 Normally, it isn't necessary to call this function, because Qt sets
617 the QApplication object as the root object immediately before the
618 event loop is entered in QApplication::exec().
620 Use QAccessible::installRootObjectHandler() to redirect the function
621 call to a customized handler function.
623 \sa queryAccessibleInterface()
625 void QAccessible::setRootObject(QObject *object)
627 if (rootObjectHandler) {
628 rootObjectHandler(object);
632 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
633 pfAccessibility->setRootObject(object);
637 Notifies about a change that might be relevant for accessibility clients.
639 \a event provides details about the change. These include the source
640 of the change and the nature of the change. The \a event should
641 contain enough information give meaningful notifications.
643 For example, the type \c ValueChange indicates that the position of
644 a slider has been changed.
646 Call this function whenever the state of your accessible object or
647 one of its sub-elements has been changed either programmatically
648 (e.g. by calling QLabel::setText()) or by user interaction.
650 If there are no accessibility tools listening to this event, the
651 performance penalty for calling this function is small, but if
652 determining the parameters of the call is expensive you can test
653 isActive() to avoid unnecessary computation.
655 void QAccessible::updateAccessibility(QAccessibleEvent *event)
658 updateHandler(event);
665 if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
666 pfAccessibility->notifyAccessibilityUpdate(event);
670 \class QAccessibleInterface
671 \brief The QAccessibleInterface class defines an interface that exposes information
672 about accessible objects.
675 \ingroup accessibility
678 This class is part of \l {Accessibility for QWidget Applications}.
680 Accessibility tools (also called AT Clients), such as screen readers
681 or braille displays, require high-level information about
682 accessible objects in an application. Accessible objects provide
683 specialized input and output methods, making it possible for users
684 to use accessibility tools with enabled applications (AT Servers).
686 Every element that the user needs to interact with or react to is
687 an accessible object, and should provide this information. These
688 are mainly visual objects, such as widgets and widget elements, but
689 can also be content, such as sounds.
691 The AT client uses three basic concepts to acquire information
692 about any accessible object in an application:
694 \li \e Properties The client can read information about
695 accessible objects. In some cases the client can also modify these
696 properties; such as text in a line edit.
697 \li \e Actions The client can invoke actions like pressing a button
699 \li \e{Relationships and Navigation} The client can traverse from one
700 accessible object to another, using the relationships between objects.
703 The QAccessibleInterface defines the API for these three concepts.
705 \section1 Relationships and Navigation
707 The functions childCount() and indexOfChild() return the number of
708 children of an accessible object and the index a child object has
709 in its parent. The childAt() function returns a child QAccessibleInterface
710 that is found at a position. The child does not have to be a direct
711 child. This allows bypassing intermediate layers when the parent already knows the
712 top-most child. childAt() is used for hit testing (finding the object
715 The relations() function provides information about the relations an
716 object has to other objects, and parent() and child() allows
717 traversing from one object to another object.
721 The central property of an accessible objects is what role() it
722 has. Different objects can have the same role, e.g. both the "Add
723 line" element in a scroll bar and the \c OK button in a dialog have
724 the same role, "button". The role implies what kind of
725 interaction the user can perform with the user interface element.
727 An object's state() property is a combination of different state
728 flags and can describe both how the object's state differs from a
729 "normal" state, e.g. it might be unavailable, and also how it
730 behaves, e.g. it might be selectable.
732 The text() property provides textual information about the object.
733 An object usually has a name, but can provide extended information
734 such as a description, help text, or information about any
735 keyboard accelerators it provides. Some objects allow changing the
736 text() property through the setText() function, but this
737 information is in most cases read-only.
739 The rect() property provides information about the geometry of an
740 accessible object. This information is usually only available for
745 To enable the user to interact with an accessible object the
746 object must implement QAccessibleActionInterface in addition to
747 QAccessibleInterface.
748 Objects that support selections can define actions to change the selection.
750 There are several other interfaces that should be implemented as required.
751 QAccessibleTextInterface should be used for bigger texts edits such as document views.
752 This interface should not be implemented for labels/single line edits.
753 The complementary QAccessibleEditableTextInterface should be added when the
756 For sliders, scrollbars and other numerical value selectors QAccessibleValueInterface
757 should be implemented.
759 Lists, tables and trees should implement QAccessibleTableInterface.
761 \sa QAccessible, QAccessibleActionInterface, QAccessibleTextInterface, QAccessibleEditableTextInterface, QAccessibleValueInterface, QAccessibleTableInterface
765 \fn bool QAccessibleInterface::isValid() const
767 Returns true if all the data necessary to use this interface
768 implementation is valid (e.g. all pointers are non-null);
769 otherwise returns false.
775 \fn QObject *QAccessibleInterface::object() const
777 Returns a pointer to the QObject this interface implementation provides
784 \fn int QAccessibleInterface::childCount() const
786 Returns the number of children that belong to this object. A child
787 can provide accessibility information on its own (e.g. a child
788 widget), or be a sub-element of this accessible object.
790 All objects provide this information.
796 \fn int QAccessibleInterface::indexOfChild(const QAccessibleInterface *child) const
798 Returns the 0-based index of the object \a child in this object's
799 children list, or -1 if \a child is not a child of this object.
801 All objects provide this information about their children.
807 Returns the meaningful relations to other widgets. Usually this will not return parent/child
808 relations, unless they are handled in a specific way such as in tree views.
809 It will typically return the labelled-by and label relations.
810 It should never return itself.
812 \sa parent(), child()
814 QVector<QPair<QAccessibleInterface*, QAccessible::Relation> >
815 QAccessibleInterface::relations(QAccessible::Relation /*match = QAccessible::AllRelations*/) const
817 return QVector<QPair<QAccessibleInterface*, QAccessible::Relation> >();
821 Returns the object that has the keyboard focus.
823 The object returned can be any descendant, including itself.
825 QAccessibleInterface *QAccessibleInterface::focusChild() const
831 \fn QAccessibleInterface *QAccessibleInterface::childAt(int x, int y) const
833 Returns the QAccessibleInterface of a child that contains the screen coordinates (\a x, \a y).
834 If there are no children at this position this function returns 0.
835 The returned accessible must be a child, but not necessarily a direct child.
837 This function is only relyable for visible objects (invisible
838 object might not be laid out correctly).
840 All visual objects provide this information.
842 A default implementation is provided for objects inheriting QAccessibleObject. This will iterate
843 over all children. If the widget manages its children (e.g. a table) it will be more efficient
844 to write a specialized implementation.
850 \fn QAccessibleInterface* QAccessibleInterface::parent() const
852 Returns the QAccessibleInterface of the parent in the accessible object hierarchy.
854 Returns 0 if no parent exists (e.g. for the top level application object).
860 \fn QAccessibleInterface* QAccessibleInterface::child(int index) const
862 Returns the accessible child with index \a index.
863 0-based index. The number of children of an object can be checked with childCount.
865 Returns 0 when asking for an invalid child (e.g. when the child became invalid in the meantime).
867 \sa childCount(), parent()
871 \fn QString QAccessibleInterface::text(QAccessible::Text t) const
873 Returns the value of the text property \a t of the object.
875 The \l QAccessible::Name is a string used by clients to identify, find, or
876 announce an accessible object for the user. All objects must have
877 a name that is unique within their container. The name can be
878 used differently by clients, so the name should both give a
879 short description of the object and be unique.
881 An accessible object's \l QAccessible::Description provides textual information
882 about an object's visual appearance. The description is primarily
883 used to provide greater context for vision-impaired users, but is
884 also used for context searching or other applications. Not all
885 objects have a description. An "OK" button would not need a
886 description, but a tool button that shows a picture of a smiley
889 The \l QAccessible::Value of an accessible object represents visual information
890 contained by the object, e.g. the text in a line edit. Usually,
891 the value can be modified by the user. Not all objects have a
892 value, e.g. static text labels don't, and some objects have a
893 state that already is the value, e.g. toggle buttons.
895 The \l QAccessible::Help text provides information about the function and
896 usage of an accessible object. Not all objects provide this
899 The \l QAccessible::Accelerator is a keyboard shortcut that activates the
900 object's default action. A keyboard shortcut is the underlined
901 character in the text of a menu, menu item or widget, and is
902 either the character itself, or a combination of this character
903 and a modifier key like Alt, Ctrl or Shift. Command controls like
904 tool buttons also have shortcut keys and usually display them in
907 All objects provide a string for \l QAccessible::Name.
913 \fn void QAccessibleInterface::setText(QAccessible::Text t, const QString &text)
915 Sets the text property \a t of the object to \a text.
917 Note that the text properties of most objects are read-only
918 so calling this function might have no effect.
924 \fn QRect QAccessibleInterface::rect() const
926 Returns the geometry of the object. The geometry is in screen coordinates.
928 This function is only reliable for visible objects (invisible
929 objects might not be laid out correctly).
931 All visual objects provide this information.
937 \fn QAccessible::Role QAccessibleInterface::role() const
939 Returns the role of the object.
940 The role of an object is usually static.
942 All accessible objects have a role.
948 \fn QAccessible::State QAccessibleInterface::state() const
950 Returns the current state of the object.
951 The returned value is a combination of the flags in
952 the QAccessible::StateFlag enumeration.
954 All accessible objects have a state.
961 \fn QAccessibleEditableTextInterface *QAccessibleInterface::editableTextInterface()
966 Returns the accessible's foreground color if applicable or an invalid QColor.
968 \sa backgroundColor()
970 QColor QAccessibleInterface::foregroundColor() const
976 Returns the accessible's background color if applicable or an invalid QColor.
978 \sa foregroundColor()
980 QColor QAccessibleInterface::backgroundColor() const
986 \fn QAccessibleTextInterface *QAccessibleInterface::textInterface()
991 \fn QAccessibleValueInterface *QAccessibleInterface::valueInterface()
996 \fn QAccessibleTableInterface *QAccessibleInterface::tableInterface()
1001 \fn QAccessibleTableCellInterface *QAccessibleInterface::tableCellInterface()
1006 \fn QAccessibleActionInterface *QAccessibleInterface::actionInterface()
1011 \fn QAccessibleImageInterface *QAccessibleInterface::imageInterface()
1016 \class QAccessibleEvent
1019 \brief The QAccessibleEvent class provides detailed updates to the
1020 accessibility framework.
1022 This class is used with \l QAccessible::updateAccessibility().
1024 The event type is one of the values of \l QAccessible::Event, which
1025 determines the subclass of QAccessibleEvent that applies.
1027 \ingroup accessibility
1031 /*! \fn QAccessibleEvent::QAccessibleEvent(QObject *obj, QAccessible::Event type)
1032 Constructs a QAccessibleEvent of the specified \a type. It also
1033 expects an \a object, which is the source of the event.
1036 /*! \fn QAccessibleEvent::~QAccessibleEvent()
1040 /*! \fn QAccessible::Event QAccessibleEvent::type() const
1041 Returns the event type.
1044 /*! \fn QObject* QAccessibleEvent::object() const
1045 Returns the event object.
1048 /*! \fn void QAccessibleEvent::setChild(int child)
1049 Sets the child index to \a child.
1052 /*! \fn int QAccessibleEvent::child() const
1053 Returns the child index.
1057 Returns the QAccessibleInterface associated with the event.
1058 The caller of this function takes ownership of the returned interface.
1060 QAccessibleInterface *QAccessibleEvent::accessibleInterface() const
1062 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(m_object);
1067 QAccessibleInterface *child = iface->child(m_child);
1072 qWarning() << "Cannot creat accessible child interface for object: " << m_object << " index: " << m_child;
1079 Returns the window associated with the underlying object.
1080 For instance, QAccessibleWidget reimplements this and returns
1081 the windowHandle() of the QWidget.
1083 It is used on some platforms to be able to notify the AT client about
1085 The backend will traverse up all ancestors until it finds a window.
1086 (This means that at least one interface among the ancestors should
1087 return a valid QWindow pointer).
1089 The default implementation of this returns 0.
1092 QWindow *QAccessibleInterface::window() const
1099 Method to allow extending this class without breaking binary compatibility.
1100 The actual behavior and format of \a data depends on \a id argument
1101 which must be defined if the class is to be extended with another virtual
1103 Currently, this is unused.
1105 void QAccessibleInterface::virtual_hook(int /*id*/, void * /*data*/)
1110 \fn void *QAccessibleInterface::interface_cast(QAccessible::InterfaceType type)
1112 Returns a specialized accessibility interface \a type from the
1113 generic QAccessibleInterface.
1115 This function must be reimplemented when providing more
1116 information about a widget or object through the specialized
1117 interfaces. For example a line edit should implement the
1118 QAccessibleTextInterface and QAccessibleEditableTextInterface.
1120 Qt's QLineEdit for example has its accessibility support
1121 implemented in QAccessibleLineEdit.
1124 void *QAccessibleLineEdit::interface_cast(QAccessible::InterfaceType t)
1126 if (t == QAccessible::TextInterface)
1127 return static_cast<QAccessibleTextInterface*>(this);
1128 else if (t == QAccessible::EditableTextInterface)
1129 return static_cast<QAccessibleEditableTextInterface*>(this);
1130 return QAccessibleWidget::interface_cast(t);
1134 \sa QAccessible::InterfaceType, QAccessibleTextInterface,
1135 QAccessibleEditableTextInterface, QAccessibleValueInterface,
1136 QAccessibleActionInterface, QAccessibleTableInterface,
1137 QAccessibleTableCellInterface
1141 const char *qAccessibleRoleString(QAccessible::Role role)
1144 role = QAccessible::UserRole;
1145 static int roleEnum = QAccessible::staticMetaObject.indexOfEnumerator("Role");
1146 return QAccessible::staticMetaObject.enumerator(roleEnum).valueToKey(role);
1150 const char *qAccessibleEventString(QAccessible::Event event)
1152 static int eventEnum = QAccessible::staticMetaObject.indexOfEnumerator("Event");
1153 return QAccessible::staticMetaObject.enumerator(eventEnum).valueToKey(event);
1157 bool operator==(const QAccessible::State &first, const QAccessible::State &second)
1159 return memcmp(&first, &second, sizeof(QAccessible::State)) == 0;
1162 #ifndef QT_NO_DEBUG_STREAM
1163 Q_GUI_EXPORT QDebug operator<<(QDebug d, const QAccessibleInterface *iface)
1166 d << "QAccessibleInterface(null)";
1170 d << "QAccessibleInterface(" << hex << (void *) iface << dec;
1171 if (iface->isValid()) {
1172 d << " name=" << iface->text(QAccessible::Name) << " ";
1173 d << "role=" << qAccessibleRoleString(iface->role()) << " ";
1174 if (iface->childCount())
1175 d << "childc=" << iface->childCount() << " ";
1176 if (iface->object()) {
1177 d << "obj=" << iface->object();
1179 QStringList stateStrings;
1180 QAccessible::State st = iface->state();
1182 stateStrings << QLatin1String("focusable");
1184 stateStrings << QLatin1String("focused");
1186 stateStrings << QLatin1String("selected");
1188 stateStrings << QLatin1String("invisible");
1190 if (!stateStrings.isEmpty())
1191 d << stateStrings.join(QLatin1Char('|'));
1194 d << "rect=" << iface->rect();
1204 QDebug operator<<(QDebug d, const QAccessibleEvent &ev)
1207 d << "QAccessibleEvent(null)";
1210 d.nospace() << "QAccessibleEvent(object=" << hex << ev.object();
1212 d.nospace() << "child=" << ev.child();
1213 d << " event=" << qAccessibleEventString(ev.type());
1214 if (ev.type() == QAccessible::StateChanged) {
1215 QAccessible::State changed = static_cast<const QAccessibleStateChangeEvent*>(&ev)->changedStates();
1216 d << "State changed:";
1217 if (changed.disabled) d << "disabled";
1218 if (changed.selected) d << "selected";
1219 if (changed.focusable) d << "focusable";
1220 if (changed.focused) d << "focused";
1221 if (changed.pressed) d << "pressed";
1222 if (changed.checkable) d << "checkable";
1223 if (changed.checked) d << "checked";
1224 if (changed.checkStateMixed) d << "checkStateMixed";
1225 if (changed.readOnly) d << "readOnly";
1226 if (changed.hotTracked) d << "hotTracked";
1227 if (changed.defaultButton) d << "defaultButton";
1228 if (changed.expanded) d << "expanded";
1229 if (changed.collapsed) d << "collapsed";
1230 if (changed.busy) d << "busy";
1231 if (changed.expandable) d << "expandable";
1232 if (changed.marqueed) d << "marqueed";
1233 if (changed.animated) d << "animated";
1234 if (changed.invisible) d << "invisible";
1235 if (changed.offscreen) d << "offscreen";
1236 if (changed.sizeable) d << "sizeable";
1237 if (changed.movable) d << "movable";
1238 if (changed.selfVoicing) d << "selfVoicing";
1239 if (changed.selectable) d << "selectable";
1240 if (changed.linked) d << "linked";
1241 if (changed.traversed) d << "traversed";
1242 if (changed.multiSelectable) d << "multiSelectable";
1243 if (changed.extSelectable) d << "extSelectable";
1244 if (changed.passwordEdit) d << "passwordEdit"; // used to be Protected
1245 if (changed.hasPopup) d << "hasPopup";
1246 if (changed.modal) d << "modal";
1248 // IA2 - we chose to not add some IA2 states for now
1249 // Below the ones that seem helpful
1250 if (changed.active) d << "active";
1251 if (changed.invalid) d << "invalid"; // = defunct
1252 if (changed.editable) d << "editable";
1253 if (changed.multiLine) d << "multiLine";
1254 if (changed.selectableText) d << "selectableText";
1255 if (changed.supportsAutoCompletion) d << "supportsAutoCompletion";