1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <osx/a11yfactory.h>
23 #include "a11yrolehelper.h"
25 #include <com/sun/star/accessibility/AccessibleRole.hpp>
26 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
27 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
29 #include <sal/log.hxx>
31 using namespace ::com::sun::star::accessibility;
32 using namespace ::com::sun::star::lang;
33 using namespace ::com::sun::star::uno;
35 @implementation AquaA11yRoleHelper
37 +(id)simpleMapNativeRoleFrom: (XAccessibleContext *) accessibleContext {
40 if (accessibleContext == nullptr)
43 switch( accessibleContext -> getAccessibleRole() ) {
45 case a: nativeRole = b; break
47 MAP( AccessibleRole::UNKNOWN, NSAccessibilityUnknownRole );
48 MAP( AccessibleRole::ALERT, NSAccessibilityUnknownRole ); // FIXME
49 MAP( AccessibleRole::BLOCK_QUOTE, NSAccessibilityTextAreaRole );
50 MAP( AccessibleRole::COLUMN_HEADER, NSAccessibilityColumnRole );
51 MAP( AccessibleRole::CANVAS, NSAccessibilityUnknownRole ); // FIXME
52 MAP( AccessibleRole::CHECK_BOX, NSAccessibilityCheckBoxRole );
53 MAP( AccessibleRole::CHECK_MENU_ITEM, NSAccessibilityUnknownRole ); // FIXME
54 MAP( AccessibleRole::COLOR_CHOOSER, NSAccessibilityColorWellRole ); // FIXME
55 MAP( AccessibleRole::COMBO_BOX, NSAccessibilityComboBoxRole );
56 MAP( AccessibleRole::DATE_EDITOR, NSAccessibilityUnknownRole ); // FIXME
57 MAP( AccessibleRole::DESKTOP_ICON, NSAccessibilityUnknownRole ); // FIXME
58 MAP( AccessibleRole::DESKTOP_PANE, NSAccessibilityUnknownRole ); // FIXME
59 MAP( AccessibleRole::DIRECTORY_PANE, NSAccessibilityUnknownRole ); // FIXME
60 MAP( AccessibleRole::DIALOG, NSAccessibilityGroupRole );
61 MAP( AccessibleRole::DOCUMENT, NSAccessibilityGroupRole );
62 MAP( AccessibleRole::EMBEDDED_OBJECT, NSAccessibilityUnknownRole ); // FIXME
63 MAP( AccessibleRole::END_NOTE, NSAccessibilityUnknownRole ); // FIXME
64 MAP( AccessibleRole::FILE_CHOOSER, NSAccessibilityUnknownRole ); // FIXME
65 MAP( AccessibleRole::FILLER, NSAccessibilityUnknownRole ); // FIXME
66 MAP( AccessibleRole::FONT_CHOOSER, NSAccessibilityUnknownRole ); // FIXME
67 MAP( AccessibleRole::FOOTER, NSAccessibilityGroupRole ); // FIXME
68 MAP( AccessibleRole::FOOTNOTE, NSAccessibilityUnknownRole ); // FIXME
69 MAP( AccessibleRole::FRAME, NSAccessibilityWindowRole );
70 MAP( AccessibleRole::GLASS_PANE, NSAccessibilityUnknownRole ); // FIXME
71 MAP( AccessibleRole::GRAPHIC, NSAccessibilityImageRole );
72 MAP( AccessibleRole::GROUP_BOX, NSAccessibilityGroupRole );
73 MAP( AccessibleRole::HEADER, NSAccessibilityGroupRole ); // FIXME
74 MAP( AccessibleRole::HEADING, NSAccessibilityTextAreaRole ); // FIXME
75 MAP( AccessibleRole::HYPER_LINK, NSAccessibilityLinkRole );
76 MAP( AccessibleRole::ICON, NSAccessibilityImageRole );
77 MAP( AccessibleRole::INTERNAL_FRAME, NSAccessibilityUnknownRole ); // FIXME
78 MAP( AccessibleRole::LABEL, NSAccessibilityStaticTextRole );
79 MAP( AccessibleRole::LAYERED_PANE, NSAccessibilityUnknownRole ); // FIXME
80 MAP( AccessibleRole::LIST, NSAccessibilityMenuRole );
81 MAP( AccessibleRole::LIST_ITEM, NSAccessibilityMenuItemRole );
82 MAP( AccessibleRole::MENU, NSAccessibilityMenuRole );
83 MAP( AccessibleRole::MENU_BAR, NSAccessibilityMenuBarRole );
84 MAP( AccessibleRole::MENU_ITEM, NSAccessibilityMenuItemRole );
85 MAP( AccessibleRole::OPTION_PANE, NSAccessibilityUnknownRole ); // FIXME
86 // tdf#67943 tabs must have radio button role and tab button subrole
87 MAP( AccessibleRole::PAGE_TAB, NSAccessibilityRadioButtonRole );
88 MAP( AccessibleRole::PAGE_TAB_LIST, NSAccessibilityTabGroupRole );
89 MAP( AccessibleRole::PANEL, NSAccessibilityGroupRole );
90 MAP( AccessibleRole::PARAGRAPH, NSAccessibilityTextAreaRole );
91 MAP( AccessibleRole::PASSWORD_TEXT, NSAccessibilityTextFieldRole );
92 MAP( AccessibleRole::POPUP_MENU, NSAccessibilityMenuRole );
93 MAP( AccessibleRole::PUSH_BUTTON, NSAccessibilityButtonRole );
94 MAP( AccessibleRole::PROGRESS_BAR, NSAccessibilityProgressIndicatorRole );
95 MAP( AccessibleRole::RADIO_BUTTON, NSAccessibilityRadioButtonRole );
96 MAP( AccessibleRole::RADIO_MENU_ITEM, NSAccessibilityUnknownRole ); // FIXME
97 MAP( AccessibleRole::ROW_HEADER, NSAccessibilityRowRole );
98 MAP( AccessibleRole::ROOT_PANE, NSAccessibilityUnknownRole ); // FIXME
99 MAP( AccessibleRole::SCROLL_BAR, NSAccessibilityScrollBarRole );
100 MAP( AccessibleRole::SCROLL_PANE, NSAccessibilityScrollAreaRole );
101 MAP( AccessibleRole::SHAPE, NSAccessibilityUnknownRole ); // FIXME
102 MAP( AccessibleRole::SEPARATOR, NSAccessibilitySplitterRole ); // FIXME
103 MAP( AccessibleRole::SLIDER, NSAccessibilitySliderRole );
104 MAP( AccessibleRole::SPIN_BOX, NSAccessibilityUnknownRole ); // FIXME
105 MAP( AccessibleRole::SPLIT_PANE, NSAccessibilitySplitGroupRole );
106 MAP( AccessibleRole::STATUS_BAR, NSAccessibilityGroupRole ); // FIXME
107 MAP( AccessibleRole::TABLE, NSAccessibilityTableRole );
108 MAP( AccessibleRole::TABLE_CELL, NSAccessibilityTextFieldRole );
109 MAP( AccessibleRole::TEXT, NSAccessibilityTextAreaRole );
110 MAP( AccessibleRole::TEXT_FRAME, NSAccessibilityGroupRole );
111 MAP( AccessibleRole::TOGGLE_BUTTON, NSAccessibilityCheckBoxRole );
112 MAP( AccessibleRole::TOOL_BAR, NSAccessibilityToolbarRole );
113 MAP( AccessibleRole::TOOL_TIP, NSAccessibilityUnknownRole ); // FIXME
114 MAP( AccessibleRole::TREE, NSAccessibilityGroupRole );
115 MAP( AccessibleRole::VIEW_PORT, NSAccessibilityUnknownRole ); // FIXME
116 MAP( AccessibleRole::WINDOW, NSAccessibilityWindowRole );
118 MAP( AccessibleRole::BUTTON_DROPDOWN, NSAccessibilityMenuButtonRole );
119 MAP( AccessibleRole::BUTTON_MENU, NSAccessibilityMenuButtonRole );
120 MAP( AccessibleRole::CAPTION, NSAccessibilityUnknownRole );
121 MAP( AccessibleRole::CHART, NSAccessibilityUnknownRole );
122 MAP( AccessibleRole::FORM, NSAccessibilityUnknownRole );
123 MAP( AccessibleRole::IMAGE_MAP, NSAccessibilityUnknownRole );
124 MAP( AccessibleRole::NOTE, NSAccessibilityUnknownRole );
125 MAP( AccessibleRole::PAGE, NSAccessibilityUnknownRole );
126 MAP( AccessibleRole::RULER, NSAccessibilityUnknownRole );
127 MAP( AccessibleRole::SECTION, NSAccessibilityUnknownRole );
128 MAP( AccessibleRole::TREE_ITEM, NSAccessibilityUnknownRole );
129 MAP( AccessibleRole::TREE_TABLE, NSAccessibilityUnknownRole );
131 MAP( AccessibleRole::DOCUMENT_PRESENTATION, NSAccessibilityGroupRole );
132 MAP( AccessibleRole::DOCUMENT_SPREADSHEET, NSAccessibilityGroupRole );
133 MAP( AccessibleRole::DOCUMENT_TEXT, NSAccessibilityGroupRole );
134 MAP( AccessibleRole::STATIC, NSAccessibilityStaticTextRole );
135 MAP( AccessibleRole::NOTIFICATION, NSAccessibilityStaticTextRole );
144 +(id)getNativeRoleFrom: (XAccessibleContext *) accessibleContext {
145 id nativeRole = [ AquaA11yRoleHelper simpleMapNativeRoleFrom: accessibleContext ];
146 if ( accessibleContext -> getAccessibleRole() == AccessibleRole::LABEL ) {
147 if ( accessibleContext -> getAccessibleChildCount() > 0 ) {
148 nativeRole = NSAccessibilityOutlineRole;
149 } else if ( accessibleContext -> getAccessibleParent().is() ) {
150 Reference < XAccessibleContext > rxParentContext = accessibleContext -> getAccessibleParent() -> getAccessibleContext();
151 if ( rxParentContext.is() ) {
152 NSString * roleParent = static_cast<NSString *>([ AquaA11yRoleHelper simpleMapNativeRoleFrom: rxParentContext.get() ]);
153 if ( [ roleParent isEqualToString: NSAccessibilityOutlineRole ] ) {
154 nativeRole = NSAccessibilityRowRole;
158 } else if ( accessibleContext -> getAccessibleRole() == AccessibleRole::COMBO_BOX ) {
160 Reference < XAccessible > rxAccessible = accessibleContext -> getAccessibleChild(0);
161 if ( rxAccessible.is() ) {
162 Reference < XAccessibleContext > rxAccessibleContext = rxAccessible -> getAccessibleContext();
163 if ( rxAccessibleContext.is() && rxAccessibleContext -> getAccessibleRole() == AccessibleRole::TEXT ) {
164 sal_Int64 nStateSet = rxAccessibleContext -> getAccessibleStateSet();
165 if ( !(nStateSet & AccessibleStateType::EDITABLE ) ) {
166 nativeRole = NSAccessibilityPopUpButtonRole;
171 catch (const IndexOutOfBoundsException&)
173 SAL_WARN("vcl", "No valid accessible objects in parent");
179 +(id)getNativeSubroleFrom: (sal_Int16) nRole {
180 id nativeSubrole = nil;
183 case a: nativeSubrole = b; break
185 MAP( AccessibleRole::UNKNOWN, NSAccessibilityUnknownSubrole );
186 MAP( AccessibleRole::ALERT, NSAccessibilitySystemDialogSubrole );
187 MAP( AccessibleRole::BLOCK_QUOTE, @"" );
188 MAP( AccessibleRole::COLUMN_HEADER, @"" );
189 MAP( AccessibleRole::CANVAS, @"" );
190 MAP( AccessibleRole::CHECK_BOX, @"" );
191 MAP( AccessibleRole::CHECK_MENU_ITEM, @"" );
192 MAP( AccessibleRole::COLOR_CHOOSER, @"" );
193 MAP( AccessibleRole::COMBO_BOX, @"" );
194 MAP( AccessibleRole::DATE_EDITOR, @"" );
195 MAP( AccessibleRole::DESKTOP_ICON, @"" );
196 MAP( AccessibleRole::DESKTOP_PANE, @"" );
197 MAP( AccessibleRole::DIRECTORY_PANE, @"" );
198 MAP( AccessibleRole::DIALOG, NSAccessibilityDialogSubrole );
199 MAP( AccessibleRole::DOCUMENT, @"" );
200 MAP( AccessibleRole::EMBEDDED_OBJECT, @"" );
201 MAP( AccessibleRole::END_NOTE, @"" );
202 MAP( AccessibleRole::FILE_CHOOSER, @"" );
203 MAP( AccessibleRole::FILLER, @"" );
204 MAP( AccessibleRole::FONT_CHOOSER, @"" );
205 MAP( AccessibleRole::FOOTER, @"" );
206 MAP( AccessibleRole::FOOTNOTE, @"" );
207 MAP( AccessibleRole::FRAME, @"" );
208 MAP( AccessibleRole::GLASS_PANE, @"" );
209 MAP( AccessibleRole::GRAPHIC, @"" );
210 MAP( AccessibleRole::GROUP_BOX, @"" );
211 MAP( AccessibleRole::HEADER, @"" );
212 MAP( AccessibleRole::HEADING, @"" );
213 MAP( AccessibleRole::HYPER_LINK, NSAccessibilityTextLinkSubrole );
214 MAP( AccessibleRole::ICON, @"" );
215 MAP( AccessibleRole::INTERNAL_FRAME, @"" );
216 MAP( AccessibleRole::LABEL, @"" );
217 MAP( AccessibleRole::LAYERED_PANE, @"" );
218 MAP( AccessibleRole::LIST, @"" );
219 MAP( AccessibleRole::LIST_ITEM, NSAccessibilityOutlineRowSubrole );
220 MAP( AccessibleRole::MENU, @"" );
221 MAP( AccessibleRole::MENU_BAR, @"" );
222 MAP( AccessibleRole::MENU_ITEM, @"" );
223 MAP( AccessibleRole::OPTION_PANE, @"" );
224 // tdf#67943 tabs must have radio button role and tab button subrole
225 MAP( AccessibleRole::PAGE_TAB, NSAccessibilityTabButtonSubrole );
226 MAP( AccessibleRole::PAGE_TAB_LIST, @"" );
227 MAP( AccessibleRole::PANEL, @"" );
228 MAP( AccessibleRole::PARAGRAPH, @"" );
229 MAP( AccessibleRole::PASSWORD_TEXT, NSAccessibilitySecureTextFieldSubrole );
230 MAP( AccessibleRole::POPUP_MENU, @"" );
231 MAP( AccessibleRole::PUSH_BUTTON, @"" );
232 MAP( AccessibleRole::PROGRESS_BAR, @"" );
233 MAP( AccessibleRole::RADIO_BUTTON, @"" );
234 MAP( AccessibleRole::RADIO_MENU_ITEM, @"" );
235 MAP( AccessibleRole::ROW_HEADER, @"" );
236 MAP( AccessibleRole::ROOT_PANE, @"" );
237 MAP( AccessibleRole::SCROLL_BAR, @"" );
238 MAP( AccessibleRole::SCROLL_PANE, @"" );
239 MAP( AccessibleRole::SHAPE, @"" );
240 MAP( AccessibleRole::SEPARATOR, @"" );
241 MAP( AccessibleRole::SLIDER, @"" );
242 MAP( AccessibleRole::SPIN_BOX, @"" );
243 MAP( AccessibleRole::SPLIT_PANE, @"" );
244 MAP( AccessibleRole::STATUS_BAR, @"" );
245 MAP( AccessibleRole::TABLE, @"" );
246 MAP( AccessibleRole::TABLE_CELL, @"" );
247 MAP( AccessibleRole::TEXT, @"" );
248 MAP( AccessibleRole::TEXT_FRAME, @"" );
249 MAP( AccessibleRole::TOGGLE_BUTTON, @"" );
250 MAP( AccessibleRole::TOOL_BAR, @"" );
251 MAP( AccessibleRole::TOOL_TIP, @"" );
252 MAP( AccessibleRole::TREE, @"" );
253 MAP( AccessibleRole::VIEW_PORT, @"" );
254 MAP( AccessibleRole::WINDOW, NSAccessibilityStandardWindowSubrole );
256 MAP( AccessibleRole::BUTTON_DROPDOWN, @"" );
257 MAP( AccessibleRole::BUTTON_MENU, @"" );
258 MAP( AccessibleRole::CAPTION, @"" );
259 MAP( AccessibleRole::CHART, @"" );
260 MAP( AccessibleRole::FORM, @"" );
261 MAP( AccessibleRole::IMAGE_MAP, @"" );
262 MAP( AccessibleRole::NOTE, @"" );
263 MAP( AccessibleRole::PAGE, @"" );
264 MAP( AccessibleRole::RULER, @"" );
265 MAP( AccessibleRole::SECTION, @"" );
266 MAP( AccessibleRole::TREE_ITEM, @"" );
267 MAP( AccessibleRole::TREE_TABLE, @"" );
269 MAP( AccessibleRole::DOCUMENT_PRESENTATION, @"" );
270 MAP( AccessibleRole::DOCUMENT_SPREADSHEET, @"" );
271 MAP( AccessibleRole::DOCUMENT_TEXT, @"" );
273 MAP( AccessibleRole::STATIC, @"" );
274 MAP( AccessibleRole::NOTIFICATION, @"" );
280 return nativeSubrole;
283 +(id)getRoleDescriptionFrom: (NSString *) role with: (NSString *) subRole {
285 if ( [ subRole length ] == 0 )
286 roleDescription = NSAccessibilityRoleDescription( role, nil );
288 roleDescription = NSAccessibilityRoleDescription( role, subRole );
289 return roleDescription;
294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */