1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements.  See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership.  The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License.  You may obtain a copy of the License at
10 *
11 *   http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied.  See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24// MARKER(update_precomp.py): autogen include statement, do not remove
25#include "precompiled_vcl.hxx"
26
27#include "aqua/aqua11yfactory.h"
28
29#include "aqua11yrolehelper.h"
30
31#include <com/sun/star/accessibility/AccessibleRole.hpp>
32#include <com/sun/star/accessibility/AccessibleStateType.hpp>
33
34using namespace ::com::sun::star::accessibility;
35using namespace ::com::sun::star::uno;
36
37@implementation AquaA11yRoleHelper
38
39+(id)simpleMapNativeRoleFrom: (XAccessibleContext *) accessibleContext {
40    id nativeRole = nil;
41    switch( accessibleContext -> getAccessibleRole() ) {
42#define MAP(a,b) \
43        case a: nativeRole = b; break
44
45        MAP( AccessibleRole::UNKNOWN, NSAccessibilityUnknownRole );
46        MAP( AccessibleRole::ALERT, NSAccessibilityUnknownRole ); // FIXME
47        MAP( AccessibleRole::COLUMN_HEADER, NSAccessibilityColumnRole );
48        MAP( AccessibleRole::CANVAS, NSAccessibilityUnknownRole ); // FIXME
49        MAP( AccessibleRole::CHECK_BOX, NSAccessibilityCheckBoxRole );
50        MAP( AccessibleRole::CHECK_MENU_ITEM, NSAccessibilityUnknownRole ); // FIXME
51        MAP( AccessibleRole::COLOR_CHOOSER, NSAccessibilityColorWellRole ); // FIXME
52        MAP( AccessibleRole::COMBO_BOX, NSAccessibilityComboBoxRole );
53        MAP( AccessibleRole::DATE_EDITOR, NSAccessibilityUnknownRole ); // FIXME
54        MAP( AccessibleRole::DESKTOP_ICON, NSAccessibilityUnknownRole ); // FIXME
55        MAP( AccessibleRole::DESKTOP_PANE, NSAccessibilityUnknownRole ); // FIXME
56        MAP( AccessibleRole::DIRECTORY_PANE, NSAccessibilityUnknownRole ); // FIXME
57        MAP( AccessibleRole::DIALOG, NSAccessibilityGroupRole );
58        MAP( AccessibleRole::DOCUMENT, NSAccessibilityGroupRole );
59        MAP( AccessibleRole::EMBEDDED_OBJECT, NSAccessibilityUnknownRole ); // FIXME
60        MAP( AccessibleRole::END_NOTE, NSAccessibilityUnknownRole ); // FIXME
61        MAP( AccessibleRole::FILE_CHOOSER, NSAccessibilityUnknownRole ); // FIXME
62        MAP( AccessibleRole::FILLER, NSAccessibilityUnknownRole ); // FIXME
63        MAP( AccessibleRole::FONT_CHOOSER, NSAccessibilityUnknownRole ); // FIXME
64        MAP( AccessibleRole::FOOTER, NSAccessibilityUnknownRole ); // FIXME
65        MAP( AccessibleRole::FOOTNOTE, NSAccessibilityUnknownRole ); // FIXME
66        MAP( AccessibleRole::FRAME, NSAccessibilityWindowRole );
67        MAP( AccessibleRole::GLASS_PANE, NSAccessibilityUnknownRole ); // FIXME
68        MAP( AccessibleRole::GRAPHIC, NSAccessibilityImageRole );
69        MAP( AccessibleRole::GROUP_BOX, NSAccessibilityGroupRole );
70        MAP( AccessibleRole::HEADER, NSAccessibilityUnknownRole ); // FIXME
71        MAP( AccessibleRole::HEADING, NSAccessibilityUnknownRole ); // FIXME
72        MAP( AccessibleRole::HYPER_LINK, NSAccessibilityLinkRole );
73        MAP( AccessibleRole::ICON, NSAccessibilityImageRole );
74        MAP( AccessibleRole::INTERNAL_FRAME, NSAccessibilityUnknownRole ); // FIXME
75        MAP( AccessibleRole::LABEL, NSAccessibilityStaticTextRole );
76        MAP( AccessibleRole::LAYERED_PANE, NSAccessibilityUnknownRole ); // FIXME
77        MAP( AccessibleRole::LIST, NSAccessibilityMenuRole );
78        MAP( AccessibleRole::LIST_ITEM, NSAccessibilityMenuItemRole );
79        MAP( AccessibleRole::MENU, NSAccessibilityMenuRole );
80        MAP( AccessibleRole::MENU_BAR, NSAccessibilityMenuBarRole );
81        MAP( AccessibleRole::MENU_ITEM, NSAccessibilityMenuItemRole );
82        MAP( AccessibleRole::OPTION_PANE, NSAccessibilityUnknownRole ); // FIXME
83        MAP( AccessibleRole::PAGE_TAB, NSAccessibilityButtonRole );
84        MAP( AccessibleRole::PAGE_TAB_LIST, NSAccessibilityTabGroupRole );
85        MAP( AccessibleRole::PANEL, NSAccessibilityGroupRole );
86        MAP( AccessibleRole::PARAGRAPH, NSAccessibilityTextAreaRole );
87        MAP( AccessibleRole::PASSWORD_TEXT, NSAccessibilityTextFieldRole );
88        MAP( AccessibleRole::POPUP_MENU, NSAccessibilityMenuRole );
89        MAP( AccessibleRole::PUSH_BUTTON, NSAccessibilityButtonRole );
90        MAP( AccessibleRole::PROGRESS_BAR, NSAccessibilityProgressIndicatorRole );
91        MAP( AccessibleRole::RADIO_BUTTON, NSAccessibilityRadioButtonRole );
92        MAP( AccessibleRole::RADIO_MENU_ITEM, NSAccessibilityUnknownRole ); // FIXME
93        MAP( AccessibleRole::ROW_HEADER, NSAccessibilityRowRole );
94        MAP( AccessibleRole::ROOT_PANE, NSAccessibilityUnknownRole ); // FIXME
95        MAP( AccessibleRole::SCROLL_BAR, NSAccessibilityScrollBarRole );
96        MAP( AccessibleRole::SCROLL_PANE, NSAccessibilityScrollAreaRole );
97        MAP( AccessibleRole::SHAPE, NSAccessibilityUnknownRole ); // FIXME
98        MAP( AccessibleRole::SEPARATOR, NSAccessibilitySplitterRole ); // FIXME
99        MAP( AccessibleRole::SLIDER, NSAccessibilitySliderRole );
100        MAP( AccessibleRole::SPIN_BOX, NSAccessibilityUnknownRole ); // FIXME
101        MAP( AccessibleRole::SPLIT_PANE, NSAccessibilitySplitterRole );
102        MAP( AccessibleRole::STATUS_BAR, NSAccessibilityGroupRole ); // FIXME
103        MAP( AccessibleRole::TABLE, NSAccessibilityTableRole );
104        MAP( AccessibleRole::TABLE_CELL, NSAccessibilityTextFieldRole );
105        MAP( AccessibleRole::TEXT, NSAccessibilityTextAreaRole );
106        MAP( AccessibleRole::TEXT_FRAME, NSAccessibilityGroupRole );
107        MAP( AccessibleRole::TOGGLE_BUTTON, NSAccessibilityCheckBoxRole );
108        MAP( AccessibleRole::TOOL_BAR, NSAccessibilityToolbarRole );
109        MAP( AccessibleRole::TOOL_TIP, NSAccessibilityUnknownRole ); // FIXME
110        MAP( AccessibleRole::TREE, NSAccessibilityGroupRole );
111        MAP( AccessibleRole::VIEW_PORT, NSAccessibilityUnknownRole ); // FIXME
112        MAP( AccessibleRole::WINDOW, NSAccessibilityWindowRole );
113
114        MAP( AccessibleRole::BUTTON_DROPDOWN, NSAccessibilityMenuButtonRole );
115        MAP( AccessibleRole::BUTTON_MENU, NSAccessibilityMenuButtonRole );
116        MAP( AccessibleRole::CAPTION, NSAccessibilityUnknownRole );
117        MAP( AccessibleRole::CHART, NSAccessibilityUnknownRole );
118        MAP( AccessibleRole::FORM, NSAccessibilityUnknownRole );
119        MAP( AccessibleRole::IMAGE_MAP, NSAccessibilityUnknownRole );
120        MAP( AccessibleRole::NOTE, NSAccessibilityUnknownRole );
121        MAP( AccessibleRole::PAGE, NSAccessibilityUnknownRole );
122        MAP( AccessibleRole::RULER, NSAccessibilityUnknownRole );
123        MAP( AccessibleRole::SECTION, NSAccessibilityUnknownRole );
124        MAP( AccessibleRole::TREE_ITEM, NSAccessibilityUnknownRole );
125        MAP( AccessibleRole::TREE_TABLE, NSAccessibilityUnknownRole );
126
127#undef MAP
128        default:
129            break;
130    }
131    return nativeRole;
132}
133
134+(id)getNativeRoleFrom: (XAccessibleContext *) accessibleContext {
135    id nativeRole = [ AquaA11yRoleHelper simpleMapNativeRoleFrom: accessibleContext ];
136    if ( accessibleContext -> getAccessibleRole() == AccessibleRole::LABEL ) {
137        if ( accessibleContext -> getAccessibleChildCount() > 0 ) {
138            [ nativeRole release ];
139            nativeRole = NSAccessibilityOutlineRole;
140        } else if ( accessibleContext -> getAccessibleParent().is() ) {
141            Reference < XAccessibleContext > rxParentContext = accessibleContext -> getAccessibleParent() -> getAccessibleContext();
142            if ( rxParentContext.is() ) {
143                NSString * roleParent = (NSString *) [ AquaA11yRoleHelper simpleMapNativeRoleFrom: rxParentContext.get() ];
144                if ( [ roleParent isEqualToString: NSAccessibilityOutlineRole ] ) {
145                    [ nativeRole release ];
146                    nativeRole = NSAccessibilityRowRole;
147                }
148                [ roleParent release ];
149            }
150        }
151    } else if ( accessibleContext -> getAccessibleRole() == AccessibleRole::COMBO_BOX ) {
152        Reference < XAccessible > rxAccessible = accessibleContext -> getAccessibleChild(0);
153        if ( rxAccessible.is() ) {
154            Reference < XAccessibleContext > rxAccessibleContext = rxAccessible -> getAccessibleContext();
155            if ( rxAccessibleContext.is() && rxAccessibleContext -> getAccessibleRole() == AccessibleRole::TEXT ) {
156                if ( ! rxAccessibleContext -> getAccessibleStateSet() -> contains ( AccessibleStateType::EDITABLE ) ) {
157                    [ nativeRole release ];
158                    nativeRole = NSAccessibilityPopUpButtonRole;
159                }
160            }
161        }
162    }
163    return nativeRole;
164}
165
166+(id)getNativeSubroleFrom: (sal_Int16) nRole {
167    id nativeSubrole = nil;
168    switch( nRole ) {
169#define MAP(a,b) \
170        case a: nativeSubrole = b; break
171
172        MAP( AccessibleRole::UNKNOWN, NSAccessibilityUnknownSubrole );
173        MAP( AccessibleRole::ALERT, NSAccessibilitySystemDialogSubrole );
174        MAP( AccessibleRole::COLUMN_HEADER, @"" );
175        MAP( AccessibleRole::CANVAS, @"" );
176        MAP( AccessibleRole::CHECK_BOX, @"" );
177        MAP( AccessibleRole::CHECK_MENU_ITEM, @"" );
178        MAP( AccessibleRole::COLOR_CHOOSER, @"" );
179        MAP( AccessibleRole::COMBO_BOX, @"" );
180        MAP( AccessibleRole::DATE_EDITOR, @"" );
181        MAP( AccessibleRole::DESKTOP_ICON, @"" );
182        MAP( AccessibleRole::DESKTOP_PANE, @"" );
183        MAP( AccessibleRole::DIRECTORY_PANE, @"" );
184        MAP( AccessibleRole::DIALOG, NSAccessibilityDialogSubrole );
185        MAP( AccessibleRole::DOCUMENT, @"" );
186        MAP( AccessibleRole::EMBEDDED_OBJECT, @"" );
187        MAP( AccessibleRole::END_NOTE, @"" );
188        MAP( AccessibleRole::FILE_CHOOSER, @"" );
189        MAP( AccessibleRole::FILLER, @"" );
190        MAP( AccessibleRole::FONT_CHOOSER, @"" );
191        MAP( AccessibleRole::FOOTER, @"" );
192        MAP( AccessibleRole::FOOTNOTE, @"" );
193        MAP( AccessibleRole::FRAME, @"" );
194        MAP( AccessibleRole::GLASS_PANE, @"" );
195        MAP( AccessibleRole::GRAPHIC, @"" );
196        MAP( AccessibleRole::GROUP_BOX, @"" );
197        MAP( AccessibleRole::HEADER, @"" );
198        MAP( AccessibleRole::HEADING, @"" );
199        MAP( AccessibleRole::HYPER_LINK, NSAccessibilityTextLinkSubrole );
200        MAP( AccessibleRole::ICON, @"" );
201        MAP( AccessibleRole::INTERNAL_FRAME, @"" );
202        MAP( AccessibleRole::LABEL, @"" );
203        MAP( AccessibleRole::LAYERED_PANE, @"" );
204        MAP( AccessibleRole::LIST, @"" );
205        MAP( AccessibleRole::LIST_ITEM, NSAccessibilityOutlineRowSubrole );
206        MAP( AccessibleRole::MENU, @"" );
207        MAP( AccessibleRole::MENU_BAR, @"" );
208        MAP( AccessibleRole::MENU_ITEM, @"" );
209        MAP( AccessibleRole::OPTION_PANE, @"" );
210        MAP( AccessibleRole::PAGE_TAB, @"" );
211        MAP( AccessibleRole::PAGE_TAB_LIST, @"" );
212        MAP( AccessibleRole::PANEL, @"" );
213        MAP( AccessibleRole::PARAGRAPH, @"" );
214        MAP( AccessibleRole::PASSWORD_TEXT, NSAccessibilitySecureTextFieldSubrole );
215        MAP( AccessibleRole::POPUP_MENU, @"" );
216        MAP( AccessibleRole::PUSH_BUTTON, @"" );
217        MAP( AccessibleRole::PROGRESS_BAR, @"" );
218        MAP( AccessibleRole::RADIO_BUTTON, @"" );
219        MAP( AccessibleRole::RADIO_MENU_ITEM, @"" );
220        MAP( AccessibleRole::ROW_HEADER, @"" );
221        MAP( AccessibleRole::ROOT_PANE, @"" );
222        MAP( AccessibleRole::SCROLL_BAR, @"" );
223        MAP( AccessibleRole::SCROLL_PANE, @"" );
224        MAP( AccessibleRole::SHAPE, @"" );
225        MAP( AccessibleRole::SEPARATOR, @"" );
226        MAP( AccessibleRole::SLIDER, @"" );
227        MAP( AccessibleRole::SPIN_BOX, @"" );
228        MAP( AccessibleRole::SPLIT_PANE, @"" );
229        MAP( AccessibleRole::STATUS_BAR, @"" );
230        MAP( AccessibleRole::TABLE, @"" );
231        MAP( AccessibleRole::TABLE_CELL, @"" );
232        MAP( AccessibleRole::TEXT, @"" );
233        MAP( AccessibleRole::TEXT_FRAME, @"" );
234        MAP( AccessibleRole::TOGGLE_BUTTON, @"" );
235        MAP( AccessibleRole::TOOL_BAR, @"" );
236        MAP( AccessibleRole::TOOL_TIP, @"" );
237        MAP( AccessibleRole::TREE, @"" );
238        MAP( AccessibleRole::VIEW_PORT, @"" );
239        MAP( AccessibleRole::WINDOW, NSAccessibilityStandardWindowSubrole );
240
241        MAP( AccessibleRole::BUTTON_DROPDOWN, @"" );
242        MAP( AccessibleRole::BUTTON_MENU, @"" );
243        MAP( AccessibleRole::CAPTION, @"" );
244        MAP( AccessibleRole::CHART, @"" );
245        MAP( AccessibleRole::FORM, @"" );
246        MAP( AccessibleRole::IMAGE_MAP, @"" );
247        MAP( AccessibleRole::NOTE, @"" );
248        MAP( AccessibleRole::PAGE, @"" );
249        MAP( AccessibleRole::RULER, @"" );
250        MAP( AccessibleRole::SECTION, @"" );
251        MAP( AccessibleRole::TREE_ITEM, @"" );
252        MAP( AccessibleRole::TREE_TABLE, @"" );
253
254#undef MAP
255        default:
256            break;
257    }
258    return nativeSubrole;
259}
260
261+(id)getRoleDescriptionFrom: (NSString *) role with: (NSString *) subRole {
262	id roleDescription;
263	if ( [ subRole length ] == 0 )
264		roleDescription = NSAccessibilityRoleDescription( role, nil );
265	else
266		roleDescription = NSAccessibilityRoleDescription( role, subRole );
267    return roleDescription;
268}
269
270@end
271