1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | /*!
|
---|
43 | \group accessibility
|
---|
44 | \title Accessibility Classes
|
---|
45 | */
|
---|
46 |
|
---|
47 | /*!
|
---|
48 | \page accessible.html
|
---|
49 | \title Accessibility
|
---|
50 |
|
---|
51 | \ingroup frameworks-technologies
|
---|
52 |
|
---|
53 | \tableofcontents
|
---|
54 |
|
---|
55 | \section1 Introduction
|
---|
56 |
|
---|
57 | Accessibility in computer software is making applications usable
|
---|
58 | for people with disabilities. This could be achieved by providing
|
---|
59 | keyboard shortcuts, a high-contrast user interface that uses
|
---|
60 | specially selected colors and fonts, or support for assistive tools
|
---|
61 | such as screen readers and braille displays.
|
---|
62 |
|
---|
63 | An application does not usually communicate directly with
|
---|
64 | assistive tools but through an assistive technology, which is a
|
---|
65 | bridge for exchange of information between the applications and
|
---|
66 | the tools. Information about user interface elements, such
|
---|
67 | as buttons and scroll bars, is exposed to the assistive technologies.
|
---|
68 | Qt supports Microsoft Active Accessibility (MSAA) on Windows and
|
---|
69 | Mac OS X Accessibility on Mac OS X.
|
---|
70 | On Unix/X11, support is preliminary. The individual technologies
|
---|
71 | are abstracted from Qt, and there is only a single interface to
|
---|
72 | consider. We will use MSAA throughout this document when we need
|
---|
73 | to address technology related issues.
|
---|
74 |
|
---|
75 | In this overview document, we will examine the overall Qt
|
---|
76 | accessibility architecture, and how to implement accessibility for
|
---|
77 | custom widgets and elements.
|
---|
78 |
|
---|
79 | \section1 Architecture
|
---|
80 |
|
---|
81 | Providing accessibility is a collaboration between accessibility
|
---|
82 | compliant applications, the assistive technology, and the
|
---|
83 | assistive tools.
|
---|
84 |
|
---|
85 | \image accessibilityarchitecture.png
|
---|
86 |
|
---|
87 | Accessibility compliant applications are called AT-Servers while
|
---|
88 | assistive tools are called AT-Clients. A Qt application will
|
---|
89 | typically be an AT-Server, but specialized programs might also
|
---|
90 | function like AT-Clients. We will refer to clients and servers
|
---|
91 | when talking about AT-Clients and AT-Servers in the rest of this
|
---|
92 | document.
|
---|
93 |
|
---|
94 | We will from now on focus on the Qt accessibility interface and
|
---|
95 | how it is implemented to create Qt applications that support
|
---|
96 | accessibility.
|
---|
97 |
|
---|
98 | \section2 Accessibility in Qt
|
---|
99 |
|
---|
100 | These classes provide support for accessible applications.
|
---|
101 |
|
---|
102 | \annotatedlist accessibility
|
---|
103 |
|
---|
104 | When we communicate with the assistive technologies, we need to
|
---|
105 | describe Qt's user interface in a way that they can understand. Qt
|
---|
106 | applications use QAccessibleInterface to expose information about the
|
---|
107 | individual UI elements. Currently, Qt provides support for its widgets
|
---|
108 | and widget parts, e.g., slider handles, but the interface could
|
---|
109 | also be implemented for any QObject if necessary. QAccessible
|
---|
110 | contains enums that describe the UI. The description is mainly
|
---|
111 | based on MSAA and is independent of Qt. We will examine the enums
|
---|
112 | in the course of this document.
|
---|
113 |
|
---|
114 | The structure of the UI is represented as a tree of
|
---|
115 | QAccessibleInterface subclasses. You can think of this as a
|
---|
116 | representation of a UI like the QObject tree built by Qt. Objects
|
---|
117 | can be widgets or widget parts (such as scroll bar handles). We
|
---|
118 | examine the tree in detail in the next section.
|
---|
119 |
|
---|
120 | Servers notify clients through \l{QAccessible::}{updateAccessibility()}
|
---|
121 | about changes in objects by sending events, and the clients
|
---|
122 | register to receive the events. The available events are defined
|
---|
123 | by the QAccessible::Event enum. The clients may then query for
|
---|
124 | the object that generated the event through
|
---|
125 | QAccessible::queryAccessibleInterface().
|
---|
126 |
|
---|
127 | Three of the enums in QAccessible help clients query and alter
|
---|
128 | accessible objects:
|
---|
129 |
|
---|
130 | \list
|
---|
131 | \o \l{QAccessible::}{Role}: Describes the role the object
|
---|
132 | fills in the user interface, e.g., if it is a main
|
---|
133 | window, a text caret, or a cell in an item view.
|
---|
134 | \o \l{QAccessible::}{Action}: The actions that the
|
---|
135 | clients can perform on the objects, e.g., pushing a
|
---|
136 | button.
|
---|
137 | \o \l{QAccessible::}{Relation}: Describes the relationship
|
---|
138 | between objects in the object tree.
|
---|
139 | This is used for navigation.
|
---|
140 | \endlist
|
---|
141 |
|
---|
142 | The clients also have some possibilities to get the content of
|
---|
143 | objects, e.g., a button's text; the object provides strings
|
---|
144 | defined by the QAccessible::Text enum, that give information
|
---|
145 | about content.
|
---|
146 |
|
---|
147 | The objects can be in a number of different states as defined by
|
---|
148 | the \l{QAccessible::}{State} enum. Examples of states are whether
|
---|
149 | the object is disabled, if it has focus, or if it provides a pop-up
|
---|
150 | menu.
|
---|
151 |
|
---|
152 | \section2 The Accessible Object Tree
|
---|
153 |
|
---|
154 | As mentioned, a tree structure is built from the accessible
|
---|
155 | objects of an application. By navigating through the tree, the
|
---|
156 | clients can access all elements in the UI. Object relations give
|
---|
157 | clients information about the UI. For instance, a slider handle is
|
---|
158 | a child of the slider to which it belongs. QAccessible::Relation
|
---|
159 | describes the various relationships the clients can ask objects
|
---|
160 | for.
|
---|
161 |
|
---|
162 | Note that there are no direct mapping between the Qt QObject tree
|
---|
163 | and the accessible object tree. For instance, scroll bar handles
|
---|
164 | are accessible objects but are not widgets or objects in Qt.
|
---|
165 |
|
---|
166 | AT-Clients have access to the accessibility object tree through
|
---|
167 | the root object in the tree, which is the QApplication. They can
|
---|
168 | query other objects through QAccessible::navigate(), which fetches
|
---|
169 | objects based on \l{QAccessible::}{Relation}s. The children of any
|
---|
170 | node is 1-based numbered. The child numbered 0 is the object
|
---|
171 | itself. The children of all interfaces are numbered this way,
|
---|
172 | i.e., it is not a fixed numbering from the root node in the entire
|
---|
173 | tree.
|
---|
174 |
|
---|
175 | Qt provides accessible interfaces for its widgets. Interfaces for
|
---|
176 | any QObject subclass can be requested through
|
---|
177 | QAccessible::queryInterface(). A default implementation is
|
---|
178 | provided if a more specialized interface is not defined. An
|
---|
179 | AT-Client cannot acquire an interface for accessible objects that
|
---|
180 | do not have an equivalent QObject, e.g., scroll bar handles, but
|
---|
181 | they appear as normal objects through interfaces of parent
|
---|
182 | accessible objects, e.g., you can query their relationships with
|
---|
183 | QAccessible::relationTo().
|
---|
184 |
|
---|
185 | To illustrate, we present an image of an accessible object tree.
|
---|
186 | Beneath the tree is a table with examples of object relationships.
|
---|
187 |
|
---|
188 | \image accessibleobjecttree.png
|
---|
189 |
|
---|
190 | The labels in top-down order are: the QAccessibleInterface class
|
---|
191 | name, the widget for which an interface is provided, and the
|
---|
192 | \l{QAccessible::}{Role} of the object. The Position, PageLeft and
|
---|
193 | PageRight correspond to the slider handle, the slider groove left
|
---|
194 | and the slider groove right, respectively. These accessible objects
|
---|
195 | do not have an equivalent QObject.
|
---|
196 |
|
---|
197 | \table 40%
|
---|
198 | \header
|
---|
199 | \o Source Object
|
---|
200 | \o Target Object
|
---|
201 | \o Relation
|
---|
202 | \row
|
---|
203 | \o Slider
|
---|
204 | \o Indicator
|
---|
205 | \o Controller
|
---|
206 | \row
|
---|
207 | \o Indicator
|
---|
208 | \o Slider
|
---|
209 | \o Controlled
|
---|
210 | \row
|
---|
211 | \o Slider
|
---|
212 | \o Application
|
---|
213 | \o Ancestor
|
---|
214 | \row
|
---|
215 | \o Application
|
---|
216 | \o Slider
|
---|
217 | \o Child
|
---|
218 | \row
|
---|
219 | \o PushButton
|
---|
220 | \o Indicator
|
---|
221 | \o Sibling
|
---|
222 | \endtable
|
---|
223 |
|
---|
224 | \section2 The Static QAccessible Functions
|
---|
225 |
|
---|
226 | The accessibility is managed by QAccessible's static functions,
|
---|
227 | which we will examine shortly. They produce QAccessible
|
---|
228 | interfaces, build the object tree, and initiate the connection
|
---|
229 | with MSAA or the other platform specific technologies. If you are
|
---|
230 | only interested in learning how to make your application
|
---|
231 | accessible, you can safely skip over this section to
|
---|
232 | \l{Implementing Accessibility}.
|
---|
233 |
|
---|
234 | The communication between clients and the server is initiated when
|
---|
235 | \l{QAccessible::}{setRootObject()} is called. This is done when
|
---|
236 | the QApplication instance is instantiated and you should not have
|
---|
237 | to do this yourself.
|
---|
238 |
|
---|
239 | When a QObject calls \l{QAccessible::}{updateAccessibility()},
|
---|
240 | clients that are listening to events are notified of the
|
---|
241 | change. The function is used to post events to the assistive
|
---|
242 | technology, and accessible \l{QAccessible::Event}{events} are
|
---|
243 | posted by \l{QAccessible::}{updateAccessibility()}.
|
---|
244 |
|
---|
245 | \l{QAccessible::}{queryAccessibleInterface()} returns accessible
|
---|
246 | interfaces for \l{QObject}s. All widgets in Qt provide interfaces;
|
---|
247 | if you need interfaces to control the behavior of other \l{QObject}
|
---|
248 | subclasses, you must implement the interfaces yourself, although
|
---|
249 | the QAccessibleObject convenience class implements parts of the
|
---|
250 | functionality for you.
|
---|
251 |
|
---|
252 | The factory that produces accessibility interfaces for QObjects is
|
---|
253 | a function of type QAccessible::InterfaceFactory. It is possible
|
---|
254 | to have several factories installed. The last factory installed
|
---|
255 | will be the first to be asked for interfaces.
|
---|
256 | \l{QAccessible::}{queryAccessibleInterface()} uses the factories
|
---|
257 | to create interfaces for \l{QObject}s. Normally, you need not be
|
---|
258 | concerned about factories because you can implement plugins that
|
---|
259 | produce interfaces. We will give examples of both approaches
|
---|
260 | later.
|
---|
261 |
|
---|
262 | \section2 Enabling Accessibility Support
|
---|
263 |
|
---|
264 | By default, Qt applications are run with accessibility support
|
---|
265 | enabled on Windows and Mac OS X. On Unix/X11 platforms, applications
|
---|
266 | must be launched in an environment with the \c QT_ACCESSIBILITY
|
---|
267 | variable set to 1. For example, this is set in the following way with
|
---|
268 | the bash shell:
|
---|
269 |
|
---|
270 | \snippet doc/src/snippets/code/doc_src_qt4-accessibility.qdoc environment
|
---|
271 |
|
---|
272 | Accessibility features are built into Qt by default when the libraries
|
---|
273 | are configured and built.
|
---|
274 |
|
---|
275 | \section1 Implementing Accessibility
|
---|
276 |
|
---|
277 | To provide accessibility support for a widget or other user
|
---|
278 | interface element, you need to implement the QAccessibleInterface
|
---|
279 | and distribute it in a QAccessiblePlugin. It is also possible to
|
---|
280 | compile the interface into the application and provide a
|
---|
281 | QAccessible::InterfaceFactory for it. The factory can be used if
|
---|
282 | you link statically or do not want the added complexity of
|
---|
283 | plugins. This can be an advantage if you, for instance, are
|
---|
284 | delivering a 3-rd party library.
|
---|
285 |
|
---|
286 | All widgets and other user interface elements should have
|
---|
287 | interfaces and plugins. If you want your application to support
|
---|
288 | accessibility, you will need to consider the following:
|
---|
289 |
|
---|
290 | \list
|
---|
291 | \o Qt already implements accessibility for its own widgets.
|
---|
292 | We therefore recommend that you use Qt widgets where possible.
|
---|
293 | \o A QAccessibleInterface needs to be implemented for each element
|
---|
294 | that you want to make available to accessibility clients.
|
---|
295 | \o You need to send accessibility events from the custom
|
---|
296 | user interface elements that you implement.
|
---|
297 | \endlist
|
---|
298 |
|
---|
299 | In general, it is recommended that you are somewhat familiar with
|
---|
300 | MSAA, which Qt's accessibility support originally was built for.
|
---|
301 | You should also study the enum values of QAccessible, which
|
---|
302 | describe the roles, actions, relationships, and events that you
|
---|
303 | need to consider.
|
---|
304 |
|
---|
305 | Note that you can examine how Qt's widgets implement their
|
---|
306 | accessibility. One major problem with the MSAA standard is that
|
---|
307 | interfaces are often implemented in an inconsistent way. This
|
---|
308 | makes life difficult for clients and often leads to guesswork on
|
---|
309 | object functionality.
|
---|
310 |
|
---|
311 | It is possible to implement interfaces by inheriting
|
---|
312 | QAccessibleInterface and implementing its pure virtual functions.
|
---|
313 | In practice, however, it is usually preferable to inherit
|
---|
314 | QAccessibleObject or QAccessibleWidget, which implement part of
|
---|
315 | the functionality for you. In the next section, we will see an
|
---|
316 | example of implementing accessibility for a widget by inheriting
|
---|
317 | the QAccessibleWidget class.
|
---|
318 |
|
---|
319 | \section2 The QAccessibleObject and QAccessibleWidget Convenience Classes
|
---|
320 |
|
---|
321 | When implementing an accessibility interface for widgets, one would
|
---|
|
---|