Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / renderer / accessibility / blink_ax_enum_conversion.cc
blobf21ce8824b2f9617066f57d669faa2f1458a2b8d
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/accessibility/blink_ax_enum_conversion.h"
7 #include "base/logging.h"
9 namespace content {
11 uint32 AXStateFromBlink(const blink::WebAXObject& o) {
12 uint32 state = 0;
13 if (o.isChecked())
14 state |= (1 << ui::AX_STATE_CHECKED);
16 if (o.isCollapsed())
17 state |= (1 << ui::AX_STATE_COLLAPSED);
19 if (o.canSetFocusAttribute())
20 state |= (1 << ui::AX_STATE_FOCUSABLE);
22 if (o.isFocused())
23 state |= (1 << ui::AX_STATE_FOCUSED);
25 if (o.role() == blink::WebAXRolePopUpButton ||
26 o.ariaHasPopup()) {
27 state |= (1 << ui::AX_STATE_HASPOPUP);
28 if (!o.isCollapsed())
29 state |= (1 << ui::AX_STATE_EXPANDED);
32 if (o.isHovered())
33 state |= (1 << ui::AX_STATE_HOVERED);
35 if (o.isIndeterminate())
36 state |= (1 << ui::AX_STATE_INDETERMINATE);
38 if (!o.isVisible())
39 state |= (1 << ui::AX_STATE_INVISIBLE);
41 if (o.isLinked())
42 state |= (1 << ui::AX_STATE_LINKED);
44 if (o.isMultiSelectable())
45 state |= (1 << ui::AX_STATE_MULTISELECTABLE);
47 if (o.isOffScreen())
48 state |= (1 << ui::AX_STATE_OFFSCREEN);
50 if (o.isPressed())
51 state |= (1 << ui::AX_STATE_PRESSED);
53 if (o.isPasswordField())
54 state |= (1 << ui::AX_STATE_PROTECTED);
56 if (o.isReadOnly())
57 state |= (1 << ui::AX_STATE_READ_ONLY);
59 if (o.isRequired())
60 state |= (1 << ui::AX_STATE_REQUIRED);
62 if (o.canSetSelectedAttribute())
63 state |= (1 << ui::AX_STATE_SELECTABLE);
65 if (o.isSelected())
66 state |= (1 << ui::AX_STATE_SELECTED);
68 if (o.isVisited())
69 state |= (1 << ui::AX_STATE_VISITED);
71 if (o.isEnabled())
72 state |= (1 << ui::AX_STATE_ENABLED);
74 if (o.isVertical())
75 state |= (1 << ui::AX_STATE_VERTICAL);
77 if (o.isVisited())
78 state |= (1 << ui::AX_STATE_VISITED);
80 return state;
83 ui::AXRole AXRoleFromBlink(blink::WebAXRole role) {
84 switch (role) {
85 case blink::WebAXRoleAlert:
86 return ui::AX_ROLE_ALERT;
87 case blink::WebAXRoleAlertDialog:
88 return ui::AX_ROLE_ALERT_DIALOG;
89 case blink::WebAXRoleAnnotation:
90 return ui::AX_ROLE_ANNOTATION;
91 case blink::WebAXRoleApplication:
92 return ui::AX_ROLE_APPLICATION;
93 case blink::WebAXRoleArticle:
94 return ui::AX_ROLE_ARTICLE;
95 case blink::WebAXRoleBanner:
96 return ui::AX_ROLE_BANNER;
97 case blink::WebAXRoleBrowser:
98 return ui::AX_ROLE_BROWSER;
99 case blink::WebAXRoleBusyIndicator:
100 return ui::AX_ROLE_BUSY_INDICATOR;
101 case blink::WebAXRoleButton:
102 return ui::AX_ROLE_BUTTON;
103 case blink::WebAXRoleCanvas:
104 return ui::AX_ROLE_CANVAS;
105 case blink::WebAXRoleCell:
106 return ui::AX_ROLE_CELL;
107 case blink::WebAXRoleCheckBox:
108 return ui::AX_ROLE_CHECK_BOX;
109 case blink::WebAXRoleColorWell:
110 return ui::AX_ROLE_COLOR_WELL;
111 case blink::WebAXRoleColumn:
112 return ui::AX_ROLE_COLUMN;
113 case blink::WebAXRoleColumnHeader:
114 return ui::AX_ROLE_COLUMN_HEADER;
115 case blink::WebAXRoleComboBox:
116 return ui::AX_ROLE_COMBO_BOX;
117 case blink::WebAXRoleComplementary:
118 return ui::AX_ROLE_COMPLEMENTARY;
119 case blink::WebAXRoleContentInfo:
120 return ui::AX_ROLE_CONTENT_INFO;
121 case blink::WebAXRoleDefinition:
122 return ui::AX_ROLE_DEFINITION;
123 case blink::WebAXRoleDescriptionListDetail:
124 return ui::AX_ROLE_DESCRIPTION_LIST_DETAIL;
125 case blink::WebAXRoleDescriptionListTerm:
126 return ui::AX_ROLE_DESCRIPTION_LIST_TERM;
127 case blink::WebAXRoleDialog:
128 return ui::AX_ROLE_DIALOG;
129 case blink::WebAXRoleDirectory:
130 return ui::AX_ROLE_DIRECTORY;
131 case blink::WebAXRoleDisclosureTriangle:
132 return ui::AX_ROLE_DISCLOSURE_TRIANGLE;
133 case blink::WebAXRoleDiv:
134 return ui::AX_ROLE_DIV;
135 case blink::WebAXRoleDocument:
136 return ui::AX_ROLE_DOCUMENT;
137 case blink::WebAXRoleDrawer:
138 return ui::AX_ROLE_DRAWER;
139 case blink::WebAXRoleEditableText:
140 return ui::AX_ROLE_EDITABLE_TEXT;
141 case blink::WebAXRoleEmbeddedObject:
142 return ui::AX_ROLE_EMBEDDED_OBJECT;
143 case blink::WebAXRoleFooter:
144 return ui::AX_ROLE_FOOTER;
145 case blink::WebAXRoleForm:
146 return ui::AX_ROLE_FORM;
147 case blink::WebAXRoleGrid:
148 return ui::AX_ROLE_GRID;
149 case blink::WebAXRoleGroup:
150 return ui::AX_ROLE_GROUP;
151 case blink::WebAXRoleGrowArea:
152 return ui::AX_ROLE_GROW_AREA;
153 case blink::WebAXRoleHeading:
154 return ui::AX_ROLE_HEADING;
155 case blink::WebAXRoleHelpTag:
156 return ui::AX_ROLE_HELP_TAG;
157 case blink::WebAXRoleHorizontalRule:
158 return ui::AX_ROLE_HORIZONTAL_RULE;
159 case blink::WebAXRoleIframe:
160 return ui::AX_ROLE_IFRAME;
161 case blink::WebAXRoleIgnored:
162 return ui::AX_ROLE_IGNORED;
163 case blink::WebAXRoleImage:
164 return ui::AX_ROLE_IMAGE;
165 case blink::WebAXRoleImageMap:
166 return ui::AX_ROLE_IMAGE_MAP;
167 case blink::WebAXRoleImageMapLink:
168 return ui::AX_ROLE_IMAGE_MAP_LINK;
169 case blink::WebAXRoleIncrementor:
170 return ui::AX_ROLE_INCREMENTOR;
171 case blink::WebAXRoleInlineTextBox:
172 return ui::AX_ROLE_INLINE_TEXT_BOX;
173 case blink::WebAXRoleLabel:
174 return ui::AX_ROLE_LABEL_TEXT;
175 case blink::WebAXRoleLegend:
176 return ui::AX_ROLE_LEGEND;
177 case blink::WebAXRoleLink:
178 return ui::AX_ROLE_LINK;
179 case blink::WebAXRoleList:
180 return ui::AX_ROLE_LIST;
181 case blink::WebAXRoleListBox:
182 return ui::AX_ROLE_LIST_BOX;
183 case blink::WebAXRoleListBoxOption:
184 return ui::AX_ROLE_LIST_BOX_OPTION;
185 case blink::WebAXRoleListItem:
186 return ui::AX_ROLE_LIST_ITEM;
187 case blink::WebAXRoleListMarker:
188 return ui::AX_ROLE_LIST_MARKER;
189 case blink::WebAXRoleLog:
190 return ui::AX_ROLE_LOG;
191 case blink::WebAXRoleMain:
192 return ui::AX_ROLE_MAIN;
193 case blink::WebAXRoleMarquee:
194 return ui::AX_ROLE_MARQUEE;
195 case blink::WebAXRoleMath:
196 return ui::AX_ROLE_MATH;
197 case blink::WebAXRoleMathElement:
198 return ui::AX_ROLE_MATH_ELEMENT;
199 case blink::WebAXRoleMatte:
200 return ui::AX_ROLE_MATTE;
201 case blink::WebAXRoleMenu:
202 return ui::AX_ROLE_MENU;
203 case blink::WebAXRoleMenuBar:
204 return ui::AX_ROLE_MENU_BAR;
205 case blink::WebAXRoleMenuButton:
206 return ui::AX_ROLE_MENU_BUTTON;
207 case blink::WebAXRoleMenuItem:
208 return ui::AX_ROLE_MENU_ITEM;
209 case blink::WebAXRoleMenuListOption:
210 return ui::AX_ROLE_MENU_LIST_OPTION;
211 case blink::WebAXRoleMenuListPopup:
212 return ui::AX_ROLE_MENU_LIST_POPUP;
213 case blink::WebAXRoleNavigation:
214 return ui::AX_ROLE_NAVIGATION;
215 case blink::WebAXRoleNote:
216 return ui::AX_ROLE_NOTE;
217 case blink::WebAXRoleOutline:
218 return ui::AX_ROLE_OUTLINE;
219 case blink::WebAXRoleParagraph:
220 return ui::AX_ROLE_PARAGRAPH;
221 case blink::WebAXRolePopUpButton:
222 return ui::AX_ROLE_POP_UP_BUTTON;
223 case blink::WebAXRolePresentational:
224 return ui::AX_ROLE_PRESENTATIONAL;
225 case blink::WebAXRoleProgressIndicator:
226 return ui::AX_ROLE_PROGRESS_INDICATOR;
227 case blink::WebAXRoleRadioButton:
228 return ui::AX_ROLE_RADIO_BUTTON;
229 case blink::WebAXRoleRadioGroup:
230 return ui::AX_ROLE_RADIO_GROUP;
231 case blink::WebAXRoleRegion:
232 return ui::AX_ROLE_REGION;
233 case blink::WebAXRoleRootWebArea:
234 return ui::AX_ROLE_ROOT_WEB_AREA;
235 case blink::WebAXRoleRow:
236 return ui::AX_ROLE_ROW;
237 case blink::WebAXRoleRowHeader:
238 return ui::AX_ROLE_ROW_HEADER;
239 case blink::WebAXRoleRuler:
240 return ui::AX_ROLE_RULER;
241 case blink::WebAXRoleRulerMarker:
242 return ui::AX_ROLE_RULER_MARKER;
243 case blink::WebAXRoleSVGRoot:
244 return ui::AX_ROLE_SVG_ROOT;
245 case blink::WebAXRoleScrollArea:
246 return ui::AX_ROLE_SCROLL_AREA;
247 case blink::WebAXRoleScrollBar:
248 return ui::AX_ROLE_SCROLL_BAR;
249 case blink::WebAXRoleSeamlessWebArea:
250 return ui::AX_ROLE_SEAMLESS_WEB_AREA;
251 case blink::WebAXRoleSearch:
252 return ui::AX_ROLE_SEARCH;
253 case blink::WebAXRoleSheet:
254 return ui::AX_ROLE_SHEET;
255 case blink::WebAXRoleSlider:
256 return ui::AX_ROLE_SLIDER;
257 case blink::WebAXRoleSliderThumb:
258 return ui::AX_ROLE_SLIDER_THUMB;
259 case blink::WebAXRoleSpinButton:
260 return ui::AX_ROLE_SPIN_BUTTON;
261 case blink::WebAXRoleSpinButtonPart:
262 return ui::AX_ROLE_SPIN_BUTTON_PART;
263 case blink::WebAXRoleSplitGroup:
264 return ui::AX_ROLE_SPLIT_GROUP;
265 case blink::WebAXRoleSplitter:
266 return ui::AX_ROLE_SPLITTER;
267 case blink::WebAXRoleStaticText:
268 return ui::AX_ROLE_STATIC_TEXT;
269 case blink::WebAXRoleStatus:
270 return ui::AX_ROLE_STATUS;
271 case blink::WebAXRoleSystemWide:
272 return ui::AX_ROLE_SYSTEM_WIDE;
273 case blink::WebAXRoleTab:
274 return ui::AX_ROLE_TAB;
275 case blink::WebAXRoleTabGroup:
276 return ui::AX_ROLE_TAB_GROUP;
277 case blink::WebAXRoleTabList:
278 return ui::AX_ROLE_TAB_LIST;
279 case blink::WebAXRoleTabPanel:
280 return ui::AX_ROLE_TAB_PANEL;
281 case blink::WebAXRoleTable:
282 return ui::AX_ROLE_TABLE;
283 case blink::WebAXRoleTableHeaderContainer:
284 return ui::AX_ROLE_TABLE_HEADER_CONTAINER;
285 case blink::WebAXRoleTextArea:
286 return ui::AX_ROLE_TEXT_AREA;
287 case blink::WebAXRoleTextField:
288 return ui::AX_ROLE_TEXT_FIELD;
289 case blink::WebAXRoleTimer:
290 return ui::AX_ROLE_TIMER;
291 case blink::WebAXRoleToggleButton:
292 return ui::AX_ROLE_TOGGLE_BUTTON;
293 case blink::WebAXRoleToolbar:
294 return ui::AX_ROLE_TOOLBAR;
295 case blink::WebAXRoleTree:
296 return ui::AX_ROLE_TREE;
297 case blink::WebAXRoleTreeGrid:
298 return ui::AX_ROLE_TREE_GRID;
299 case blink::WebAXRoleTreeItem:
300 return ui::AX_ROLE_TREE_ITEM;
301 case blink::WebAXRoleUnknown:
302 return ui::AX_ROLE_UNKNOWN;
303 case blink::WebAXRoleUserInterfaceTooltip:
304 return ui::AX_ROLE_TOOLTIP;
305 case blink::WebAXRoleValueIndicator:
306 return ui::AX_ROLE_VALUE_INDICATOR;
307 case blink::WebAXRoleWebArea:
308 return ui::AX_ROLE_WEB_AREA;
309 case blink::WebAXRoleWindow:
310 return ui::AX_ROLE_WINDOW;
311 default:
312 // We can't add an assertion here, that prevents us
313 // from adding new role enums in Blink.
314 return static_cast<ui::AXRole>(-1);
318 ui::AXEvent AXEventFromBlink(blink::WebAXEvent event) {
319 switch (event) {
320 case blink::WebAXEventActiveDescendantChanged:
321 return ui::AX_EVENT_ACTIVEDESCENDANTCHANGED;
322 case blink::WebAXEventAlert:
323 return ui::AX_EVENT_ALERT;
324 case blink::WebAXEventAriaAttributeChanged:
325 return ui::AX_EVENT_ARIA_ATTRIBUTE_CHANGED;
326 case blink::WebAXEventAutocorrectionOccured:
327 return ui::AX_EVENT_AUTOCORRECTION_OCCURED;
328 case blink::WebAXEventCheckedStateChanged:
329 return ui::AX_EVENT_CHECKED_STATE_CHANGED;
330 case blink::WebAXEventChildrenChanged:
331 return ui::AX_EVENT_CHILDREN_CHANGED;
332 case blink::WebAXEventFocus:
333 return ui::AX_EVENT_FOCUS;
334 case blink::WebAXEventInvalidStatusChanged:
335 return ui::AX_EVENT_INVALID_STATUS_CHANGED;
336 case blink::WebAXEventLayoutComplete:
337 return ui::AX_EVENT_LAYOUT_COMPLETE;
338 case blink::WebAXEventLiveRegionChanged:
339 return ui::AX_EVENT_LIVE_REGION_CHANGED;
340 case blink::WebAXEventLoadComplete:
341 return ui::AX_EVENT_LOAD_COMPLETE;
342 case blink::WebAXEventLocationChanged:
343 return ui::AX_EVENT_LOCATION_CHANGED;
344 case blink::WebAXEventMenuListItemSelected:
345 return ui::AX_EVENT_MENU_LIST_ITEM_SELECTED;
346 case blink::WebAXEventMenuListValueChanged:
347 return ui::AX_EVENT_MENU_LIST_VALUE_CHANGED;
348 case blink::WebAXEventRowCollapsed:
349 return ui::AX_EVENT_ROW_COLLAPSED;
350 case blink::WebAXEventRowCountChanged:
351 return ui::AX_EVENT_ROW_COUNT_CHANGED;
352 case blink::WebAXEventRowExpanded:
353 return ui::AX_EVENT_ROW_EXPANDED;
354 case blink::WebAXEventScrollPositionChanged:
355 return ui::AX_EVENT_SCROLL_POSITION_CHANGED;
356 case blink::WebAXEventScrolledToAnchor:
357 return ui::AX_EVENT_SCROLLED_TO_ANCHOR;
358 case blink::WebAXEventSelectedChildrenChanged:
359 return ui::AX_EVENT_SELECTED_CHILDREN_CHANGED;
360 case blink::WebAXEventSelectedTextChanged:
361 return ui::AX_EVENT_TEXT_SELECTION_CHANGED;
362 case blink::WebAXEventTextChanged:
363 return ui::AX_EVENT_TEXT_CHANGED;
364 case blink::WebAXEventValueChanged:
365 return ui::AX_EVENT_VALUE_CHANGED;
366 default:
367 // We can't add an assertion here, that prevents us
368 // from adding new event enums in Blink.
369 return ui::AX_EVENT_NONE;
373 ui::AXTextDirection AXTextDirectionFromBlink(
374 blink::WebAXTextDirection text_direction) {
375 switch (text_direction) {
376 case blink::WebAXTextDirectionLR:
377 return ui::AX_TEXT_DIRECTION_LR;
378 case blink::WebAXTextDirectionRL:
379 return ui::AX_TEXT_DIRECTION_RL;
380 case blink::WebAXTextDirectionTB:
381 return ui::AX_TEXT_DIRECTION_TB;
382 case blink::WebAXTextDirectionBT:
383 return ui::AX_TEXT_DIRECTION_BT;
384 default:
385 NOTREACHED();
388 return ui::AX_TEXT_DIRECTION_NONE;
391 } // namespace content