| 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 QtGui module 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 | #include "qaccessible.h"
|
|---|
| 44 | #include "qaccessible_mac_p.h"
|
|---|
| 45 | #include "qdebug.h"
|
|---|
| 46 | #include "qtabwidget.h"
|
|---|
| 47 |
|
|---|
| 48 | #include <private/qt_mac_p.h>
|
|---|
| 49 | #include <private/qcocoaview_mac_p.h>
|
|---|
| 50 | #include <private/qwidget_p.h>
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 | #ifndef QT_NO_ACCESSIBILITY
|
|---|
| 54 |
|
|---|
| 55 | #ifdef QT_MAC_USE_COCOA
|
|---|
| 56 |
|
|---|
| 57 | QT_BEGIN_NAMESPACE
|
|---|
| 58 |
|
|---|
| 59 | //#define MAC_ACCESSIBILTY_DEVELOPER_MODE
|
|---|
| 60 |
|
|---|
| 61 | #ifdef MAC_ACCESSIBILTY_DEVELOPER_MODE
|
|---|
| 62 | #define MAC_ACCESSIBILTY_DEBUG QT_PREPEND_NAMESPACE(qDebug)
|
|---|
| 63 | #else
|
|---|
| 64 | #define MAC_ACCESSIBILTY_DEBUG if (0) QT_PREPEND_NAMESPACE(qDebug)
|
|---|
| 65 | #endif
|
|---|
| 66 |
|
|---|
| 67 | typedef QMap<QAccessible::Role, NSString *> QMacAccessibiltyRoleMap;
|
|---|
| 68 | Q_GLOBAL_STATIC(QMacAccessibiltyRoleMap, qMacAccessibiltyRoleMap);
|
|---|
| 69 |
|
|---|
| 70 | static QAInterface interfaceForView(QT_MANGLE_NAMESPACE(QCocoaView) *view)
|
|---|
| 71 | {
|
|---|
| 72 | return QAInterface(QAccessible::queryAccessibleInterface([view qt_qwidget]));
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | /*
|
|---|
| 76 | Set up mappings from Qt accessibilty roles to Mac accessibilty roles.
|
|---|
| 77 | */
|
|---|
| 78 | static void populateRoleMap()
|
|---|
| 79 | {
|
|---|
| 80 | QMacAccessibiltyRoleMap &roleMap = *qMacAccessibiltyRoleMap();
|
|---|
| 81 | roleMap[QAccessible::MenuItem] = NSAccessibilityMenuItemRole;
|
|---|
| 82 | roleMap[QAccessible::MenuBar] = NSAccessibilityMenuBarRole;
|
|---|
| 83 | roleMap[QAccessible::ScrollBar] = NSAccessibilityScrollBarRole;
|
|---|
| 84 | roleMap[QAccessible::Grip] = NSAccessibilityGrowAreaRole;
|
|---|
| 85 | roleMap[QAccessible::Window] = NSAccessibilityWindowRole;
|
|---|
| 86 | roleMap[QAccessible::Dialog] = NSAccessibilityWindowRole;
|
|---|
| 87 | roleMap[QAccessible::AlertMessage] = NSAccessibilityWindowRole;
|
|---|
| 88 | roleMap[QAccessible::ToolTip] = NSAccessibilityWindowRole;
|
|---|
| 89 | roleMap[QAccessible::HelpBalloon] = NSAccessibilityWindowRole;
|
|---|
| 90 | roleMap[QAccessible::PopupMenu] = NSAccessibilityMenuRole;
|
|---|
| 91 | roleMap[QAccessible::Application] = NSAccessibilityApplicationRole;
|
|---|
| 92 | roleMap[QAccessible::Pane] = NSAccessibilityGroupRole;
|
|---|
| 93 | roleMap[QAccessible::Grouping] = NSAccessibilityGroupRole;
|
|---|
| 94 | roleMap[QAccessible::Separator] = NSAccessibilitySplitterRole;
|
|---|
| 95 | roleMap[QAccessible::ToolBar] = NSAccessibilityToolbarRole;
|
|---|
| 96 | roleMap[QAccessible::PageTab] = NSAccessibilityRadioButtonRole;
|
|---|
| 97 | roleMap[QAccessible::ButtonMenu] = NSAccessibilityMenuButtonRole;
|
|---|
| 98 | roleMap[QAccessible::ButtonDropDown] = NSAccessibilityPopUpButtonRole;
|
|---|
| 99 | roleMap[QAccessible::SpinBox] = NSAccessibilityIncrementorRole;
|
|---|
| 100 | roleMap[QAccessible::Slider] = NSAccessibilitySliderRole;
|
|---|
| 101 | roleMap[QAccessible::ProgressBar] = NSAccessibilityProgressIndicatorRole;
|
|---|
| 102 | roleMap[QAccessible::ComboBox] = NSAccessibilityPopUpButtonRole;
|
|---|
| 103 | roleMap[QAccessible::RadioButton] = NSAccessibilityRadioButtonRole;
|
|---|
| 104 | roleMap[QAccessible::CheckBox] = NSAccessibilityCheckBoxRole;
|
|---|
| 105 | roleMap[QAccessible::StaticText] = NSAccessibilityStaticTextRole;
|
|---|
| 106 | roleMap[QAccessible::Table] = NSAccessibilityTableRole;
|
|---|
| 107 | roleMap[QAccessible::StatusBar] = NSAccessibilityStaticTextRole;
|
|---|
| 108 | roleMap[QAccessible::Column] = NSAccessibilityColumnRole;
|
|---|
| 109 | roleMap[QAccessible::ColumnHeader] = NSAccessibilityColumnRole;
|
|---|
| 110 | roleMap[QAccessible::Row] = NSAccessibilityRowRole;
|
|---|
| 111 | roleMap[QAccessible::RowHeader] = NSAccessibilityRowRole;
|
|---|
| 112 | roleMap[QAccessible::Cell] = NSAccessibilityTextFieldRole;
|
|---|
| 113 | roleMap[QAccessible::PushButton] = NSAccessibilityButtonRole;
|
|---|
| 114 | roleMap[QAccessible::EditableText] = NSAccessibilityTextFieldRole;
|
|---|
| 115 | roleMap[QAccessible::Link] = NSAccessibilityTextFieldRole;
|
|---|
| 116 | roleMap[QAccessible::Indicator] = NSAccessibilityValueIndicatorRole;
|
|---|
| 117 | roleMap[QAccessible::Splitter] = NSAccessibilitySplitGroupRole;
|
|---|
| 118 | roleMap[QAccessible::List] = NSAccessibilityListRole;
|
|---|
| 119 | roleMap[QAccessible::ListItem] = NSAccessibilityStaticTextRole;
|
|---|
| 120 | roleMap[QAccessible::Cell] = NSAccessibilityStaticTextRole;
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | /*
|
|---|
| 124 | Returns a Mac accessibility role for the given interface, or
|
|---|
| 125 | NSAccessibilityUnknownRole if no role mapping is found.
|
|---|
| 126 | */
|
|---|
| 127 | static NSString *macRoleForInterface(QAInterface interface)
|
|---|
| 128 | {
|
|---|
| 129 | const QAccessible::Role qtRole = interface.role();
|
|---|
| 130 | QMacAccessibiltyRoleMap &roleMap = *qMacAccessibiltyRoleMap();
|
|---|
| 131 |
|
|---|
| 132 | if (roleMap.isEmpty())
|
|---|
| 133 | populateRoleMap();
|
|---|
| 134 |
|
|---|
| 135 | MAC_ACCESSIBILTY_DEBUG() << "role for" << interface.object() << "interface role" << hex << qtRole;
|
|---|
| 136 |
|
|---|
| 137 | if (roleMap.contains(qtRole)) {
|
|---|
| 138 | MAC_ACCESSIBILTY_DEBUG() << "return" << roleMap[qtRole];
|
|---|
| 139 | return roleMap[qtRole];
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | MAC_ACCESSIBILTY_DEBUG() << "return NSAccessibilityUnknownRole";
|
|---|
| 143 | return NSAccessibilityUnknownRole;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | /*
|
|---|
| 147 | Is the interface a QTabBar embedded in a QTabWidget?
|
|---|
| 148 | (as opposed to a stand-alone tab bar)
|
|---|
| 149 | */
|
|---|
| 150 | static bool isEmbeddedTabBar(const QAInterface &interface)
|
|---|
| 151 | {
|
|---|
| 152 | QObject *object = interface.object();
|
|---|
| 153 | if (interface.role() == QAccessible::PageTabList && object)
|
|---|
| 154 | return (qobject_cast<QTabWidget *>(object->parent()));
|
|---|
| 155 |
|
|---|
| 156 | return false;
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | static bool isInterfaceIgnored(QAInterface interface)
|
|---|
| 160 | {
|
|---|
| 161 | // Mac accessibility does not have an attribute that corresponds to the
|
|---|
| 162 | // Invisible/Offscreen state. Use the ignore facility to disable them.
|
|---|
| 163 | const QAccessible::State state = interface.state();
|
|---|
| 164 | if (state & QAccessible::Invisible ||
|
|---|
| 165 | state & QAccessible::Offscreen )
|
|---|
| 166 | return false;
|
|---|
| 167 |
|
|---|
| 168 | // Hide QTabBars that has a QTabWidget parent (the QTabWidget handles the accessibility)
|
|---|
| 169 | if (isEmbeddedTabBar(interface))
|
|---|
| 170 | return false;
|
|---|
| 171 |
|
|---|
| 172 | if (QObject * const object = interface.object()) {
|
|---|
| 173 | const QString className = QLatin1String(object->metaObject()->className());
|
|---|
| 174 |
|
|---|
| 175 | // Prevent VoiceOver from focusing on tool tips by ignoring those
|
|---|
| 176 | // interfaces. Shifting VoiceOver focus to the tool tip is confusing
|
|---|
| 177 | // and the contents of the tool tip is avalible through the description
|
|---|
| 178 | // attribute anyway.
|
|---|
| 179 | if (className == QLatin1String("QTipLabel"))
|
|---|
| 180 | return false;
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | // Hide interfaces with an unknown role. When developing it's often useful to disable
|
|---|
| 184 | // this check to see all interfaces in the hierarchy.
|
|---|
| 185 | #ifndef MAC_ACCESSIBILTY_DEVELOPER_MODE
|
|---|
| 186 | return [macRoleForInterface(interface) isEqualToString: NSAccessibilityUnknownRole];
|
|---|
| 187 | #else
|
|---|
| 188 | return NO;
|
|---|
| 189 | #endif
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | QT_END_NAMESPACE
|
|---|
| 193 |
|
|---|
| 194 | @implementation QT_MANGLE_NAMESPACE(QCocoaView) (Accessibility)
|
|---|
| 195 |
|
|---|
| 196 | - (BOOL)accessibilityIsIgnored
|
|---|
| 197 | {
|
|---|
| 198 | QT_PREPEND_NAMESPACE(QAInterface) interface = QT_PREPEND_NAMESPACE(interfaceForView)(self);
|
|---|
| 199 | return isInterfaceIgnored(interface);
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | - (NSArray *)accessibilityAttributeNames
|
|---|
| 203 | {
|
|---|
| 204 | QT_PREPEND_NAMESPACE(QAInterface) interface = QT_PREPEND_NAMESPACE(interfaceForView)(self);
|
|---|
| 205 |
|
|---|
| 206 | static NSArray *attributes = nil;
|
|---|
| 207 | if (attributes == nil) {
|
|---|
| 208 | attributes = [super accessibilityAttributeNames];
|
|---|
| 209 |
|
|---|
| 210 | }
|
|---|
| 211 | return attributes;
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | - (id)accessibilityAttributeValue:(NSString *)attribute
|
|---|
| 215 | {
|
|---|
| 216 | MAC_ACCESSIBILTY_DEBUG() << "accessibilityAttributeValue" << self <<
|
|---|
| 217 | QT_PREPEND_NAMESPACE(QCFString)::toQString(reinterpret_cast<CFStringRef>(attribute));
|
|---|
| 218 |
|
|---|
| 219 | QT_PREPEND_NAMESPACE(QAInterface) interface = QT_PREPEND_NAMESPACE(interfaceForView)(self);
|
|---|
| 220 |
|
|---|
| 221 | // Switch on the attribute name and call the appropriate handler function.
|
|---|
| 222 | // Pass the call on to the NSView class for attributes we don't handle.
|
|---|
| 223 | if ([attribute isEqualToString:@"AXRole"]) {
|
|---|
| 224 | return macRoleForInterface(interface);
|
|---|
| 225 | } else {
|
|---|
| 226 | return [super accessibilityAttributeValue:attribute];
|
|---|
| 227 | }
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | @end
|
|---|
| 231 |
|
|---|
| 232 | #endif // QT_MAC_USE_COCOA
|
|---|
| 233 |
|
|---|
| 234 | #endif // QT_NO_ACCESSIBILITY
|
|---|
| 235 |
|
|---|