Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / renderer / accessibility / blink_ax_enum_conversion.cc
blobe5e7e0b235d3ed5b72767d3b5d6be486cc2f31ae
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 blink::WebAXExpanded expanded = o.isExpanded();
17 if (expanded) {
18 if (expanded == blink::WebAXExpandedCollapsed)
19 state |= (1 << ui::AX_STATE_COLLAPSED);
20 else if (expanded == blink::WebAXExpandedExpanded)
21 state |= (1 << ui::AX_STATE_EXPANDED);
24 if (o.canSetFocusAttribute())
25 state |= (1 << ui::AX_STATE_FOCUSABLE);
27 if (o.isFocused())
28 state |= (1 << ui::AX_STATE_FOCUSED);
30 if (o.role() == blink::WebAXRolePopUpButton ||
31 o.ariaHasPopup())
32 state |= (1 << ui::AX_STATE_HASPOPUP);
34 if (o.isHovered())
35 state |= (1 << ui::AX_STATE_HOVERED);
37 if (o.isIndeterminate())
38 state |= (1 << ui::AX_STATE_INDETERMINATE);
40 if (!o.isVisible())
41 state |= (1 << ui::AX_STATE_INVISIBLE);
43 if (o.isLinked())
44 state |= (1 << ui::AX_STATE_LINKED);
46 if (o.isMultiline())
47 state |= (1 << ui::AX_STATE_MULTILINE);
49 if (o.isMultiSelectable())
50 state |= (1 << ui::AX_STATE_MULTISELECTABLE);
52 if (o.isOffScreen())
53 state |= (1 << ui::AX_STATE_OFFSCREEN);
55 if (o.isPressed())
56 state |= (1 << ui::AX_STATE_PRESSED);
58 if (o.isPasswordField())
59 state |= (1 << ui::AX_STATE_PROTECTED);
61 if (o.isReadOnly())
62 state |= (1 << ui::AX_STATE_READ_ONLY);
64 if (o.isRequired())
65 state |= (1 << ui::AX_STATE_REQUIRED);
67 if (o.canSetSelectedAttribute())
68 state |= (1 << ui::AX_STATE_SELECTABLE);
70 if (o.isEditable())
71 state |= (1 << ui::AX_STATE_EDITABLE);
73 if (o.isEnabled())
74 state |= (1 << ui::AX_STATE_ENABLED);
76 if (o.isSelected())
77 state |= (1 << ui::AX_STATE_SELECTED);
79 if (o.isRichlyEditable())
80 state |= (1 << ui::AX_STATE_RICHLY_EDITABLE);
82 if (o.isVisited())
83 state |= (1 << ui::AX_STATE_VISITED);
85 if (o.orientation() == blink::WebAXOrientationVertical)
86 state |= (1 << ui::AX_STATE_VERTICAL);
87 else if (o.orientation() == blink::WebAXOrientationHorizontal)
88 state |= (1 << ui::AX_STATE_HORIZONTAL);
90 if (o.isVisited())
91 state |= (1 << ui::AX_STATE_VISITED);
93 return state;
96 ui::AXRole AXRoleFromBlink(blink::WebAXRole role) {
97 switch (role) {
98 case blink::WebAXRoleAlert:
99 return ui::AX_ROLE_ALERT;
100 case blink::WebAXRoleAlertDialog:
101 return ui::AX_ROLE_ALERT_DIALOG;
102 case blink::WebAXRoleAnnotation:
103 return ui::AX_ROLE_ANNOTATION;
104 case blink::WebAXRoleApplication:
105 return ui::AX_ROLE_APPLICATION;
106 case blink::WebAXRoleArticle:
107 return ui::AX_ROLE_ARTICLE;
108 case blink::WebAXRoleBanner:
109 return ui::AX_ROLE_BANNER;
110 case blink::WebAXRoleBlockquote:
111 return ui::AX_ROLE_BLOCKQUOTE;
112 case blink::WebAXRoleBusyIndicator:
113 return ui::AX_ROLE_BUSY_INDICATOR;
114 case blink::WebAXRoleButton:
115 return ui::AX_ROLE_BUTTON;
116 case blink::WebAXRoleCanvas:
117 return ui::AX_ROLE_CANVAS;
118 case blink::WebAXRoleCaption:
119 return ui::AX_ROLE_CAPTION;
120 case blink::WebAXRoleCell:
121 return ui::AX_ROLE_CELL;
122 case blink::WebAXRoleCheckBox:
123 return ui::AX_ROLE_CHECK_BOX;
124 case blink::WebAXRoleColorWell:
125 return ui::AX_ROLE_COLOR_WELL;
126 case blink::WebAXRoleColumn:
127 return ui::AX_ROLE_COLUMN;
128 case blink::WebAXRoleColumnHeader:
129 return ui::AX_ROLE_COLUMN_HEADER;
130 case blink::WebAXRoleComboBox:
131 return ui::AX_ROLE_COMBO_BOX;
132 case blink::WebAXRoleComplementary:
133 return ui::AX_ROLE_COMPLEMENTARY;
134 case blink::WebAXRoleContentInfo:
135 return ui::AX_ROLE_CONTENT_INFO;
136 case blink::WebAXRoleDate:
137 return ui::AX_ROLE_DATE;
138 case blink::WebAXRoleDateTime:
139 return ui::AX_ROLE_DATE_TIME;
140 case blink::WebAXRoleDefinition:
141 return ui::AX_ROLE_DEFINITION;
142 case blink::WebAXRoleDescriptionListDetail:
143 return ui::AX_ROLE_DESCRIPTION_LIST_DETAIL;
144 case blink::WebAXRoleDescriptionList:
145 return ui::AX_ROLE_DESCRIPTION_LIST;
146 case blink::WebAXRoleDescriptionListTerm:
147 return ui::AX_ROLE_DESCRIPTION_LIST_TERM;
148 case blink::WebAXRoleDetails:
149 return ui::AX_ROLE_DETAILS;
150 case blink::WebAXRoleDialog:
151 return ui::AX_ROLE_DIALOG;
152 case blink::WebAXRoleDirectory:
153 return ui::AX_ROLE_DIRECTORY;
154 case blink::WebAXRoleDisclosureTriangle:
155 return ui::AX_ROLE_DISCLOSURE_TRIANGLE;
156 case blink::WebAXRoleDiv:
157 return ui::AX_ROLE_DIV;
158 case blink::WebAXRoleDocument:
159 return ui::AX_ROLE_DOCUMENT;
160 case blink::WebAXRoleEmbeddedObject:
161 return ui::AX_ROLE_EMBEDDED_OBJECT;
162 case blink::WebAXRoleFigcaption:
163 return ui::AX_ROLE_FIGCAPTION;
164 case blink::WebAXRoleFigure:
165 return ui::AX_ROLE_FIGURE;
166 case blink::WebAXRoleFooter:
167 return ui::AX_ROLE_FOOTER;
168 case blink::WebAXRoleForm:
169 return ui::AX_ROLE_FORM;
170 case blink::WebAXRoleGrid:
171 return ui::AX_ROLE_GRID;
172 case blink::WebAXRoleGroup:
173 return ui::AX_ROLE_GROUP;
174 case blink::WebAXRoleHeading:
175 return ui::AX_ROLE_HEADING;
176 case blink::WebAXRoleIframe:
177 return ui::AX_ROLE_IFRAME;
178 case blink::WebAXRoleIframePresentational:
179 return ui::AX_ROLE_IFRAME_PRESENTATIONAL;
180 case blink::WebAXRoleIgnored:
181 return ui::AX_ROLE_IGNORED;
182 case blink::WebAXRoleImage:
183 return ui::AX_ROLE_IMAGE;
184 case blink::WebAXRoleImageMap:
185 return ui::AX_ROLE_IMAGE_MAP;
186 case blink::WebAXRoleImageMapLink:
187 return ui::AX_ROLE_IMAGE_MAP_LINK;
188 case blink::WebAXRoleInlineTextBox:
189 return ui::AX_ROLE_INLINE_TEXT_BOX;
190 case blink::WebAXRoleInputTime:
191 return ui::AX_ROLE_INPUT_TIME;
192 case blink::WebAXRoleLabel:
193 return ui::AX_ROLE_LABEL_TEXT;
194 case blink::WebAXRoleLegend:
195 return ui::AX_ROLE_LEGEND;
196 case blink::WebAXRoleLink:
197 return ui::AX_ROLE_LINK;
198 case blink::WebAXRoleList:
199 return ui::AX_ROLE_LIST;
200 case blink::WebAXRoleListBox:
201 return ui::AX_ROLE_LIST_BOX;
202 case blink::WebAXRoleListBoxOption:
203 return ui::AX_ROLE_LIST_BOX_OPTION;
204 case blink::WebAXRoleListItem:
205 return ui::AX_ROLE_LIST_ITEM;
206 case blink::WebAXRoleListMarker:
207 return ui::AX_ROLE_LIST_MARKER;
208 case blink::WebAXRoleLog:
209 return ui::AX_ROLE_LOG;
210 case blink::WebAXRoleMain:
211 return ui::AX_ROLE_MAIN;
212 case blink::WebAXRoleMarquee:
213 return ui::AX_ROLE_MARQUEE;
214 case blink::WebAXRoleMark:
215 return ui::AX_ROLE_MARK;
216 case blink::WebAXRoleMath:
217 return ui::AX_ROLE_MATH;
218 case blink::WebAXRoleMenu:
219 return ui::AX_ROLE_MENU;
220 case blink::WebAXRoleMenuBar:
221 return ui::AX_ROLE_MENU_BAR;
222 case blink::WebAXRoleMenuButton:
223 return ui::AX_ROLE_MENU_BUTTON;
224 case blink::WebAXRoleMenuItem:
225 return ui::AX_ROLE_MENU_ITEM;
226 case blink::WebAXRoleMenuItemCheckBox:
227 return ui::AX_ROLE_MENU_ITEM_CHECK_BOX;
228 case blink::WebAXRoleMenuItemRadio:
229 return ui::AX_ROLE_MENU_ITEM_RADIO;
230 case blink::WebAXRoleMenuListOption:
231 return ui::AX_ROLE_MENU_LIST_OPTION;
232 case blink::WebAXRoleMenuListPopup:
233 return ui::AX_ROLE_MENU_LIST_POPUP;
234 case blink::WebAXRoleMeter:
235 return ui::AX_ROLE_METER;
236 case blink::WebAXRoleNavigation:
237 return ui::AX_ROLE_NAVIGATION;
238 case blink::WebAXRoleNone:
239 return ui::AX_ROLE_NONE;
240 case blink::WebAXRoleNote:
241 return ui::AX_ROLE_NOTE;
242 case blink::WebAXRoleOutline:
243 return ui::AX_ROLE_OUTLINE;
244 case blink::WebAXRoleParagraph:
245 return ui::AX_ROLE_PARAGRAPH;
246 case blink::WebAXRolePopUpButton:
247 return ui::AX_ROLE_POP_UP_BUTTON;
248 case blink::WebAXRolePre:
249 return ui::AX_ROLE_PRE;
250 case blink::WebAXRolePresentational:
251 return ui::AX_ROLE_PRESENTATIONAL;
252 case blink::WebAXRoleProgressIndicator:
253 return ui::AX_ROLE_PROGRESS_INDICATOR;
254 case blink::WebAXRoleRadioButton:
255 return ui::AX_ROLE_RADIO_BUTTON;
256 case blink::WebAXRoleRadioGroup:
257 return ui::AX_ROLE_RADIO_GROUP;
258 case blink::WebAXRoleRegion:
259 return ui::AX_ROLE_REGION;
260 case blink::WebAXRoleRootWebArea:
261 return ui::AX_ROLE_ROOT_WEB_AREA;
262 case blink::WebAXRoleRow:
263 return ui::AX_ROLE_ROW;
264 case blink::WebAXRoleRuby:
265 return ui::AX_ROLE_RUBY;
266 case blink::WebAXRoleRowHeader:
267 return ui::AX_ROLE_ROW_HEADER;
268 case blink::WebAXRoleRuler:
269 return ui::AX_ROLE_RULER;
270 case blink::WebAXRoleSVGRoot:
271 return ui::AX_ROLE_SVG_ROOT;
272 case blink::WebAXRoleScrollArea:
273 return ui::AX_ROLE_SCROLL_AREA;
274 case blink::WebAXRoleScrollBar:
275 return ui::AX_ROLE_SCROLL_BAR;
276 case blink::WebAXRoleSeamlessWebArea:
277 return ui::AX_ROLE_SEAMLESS_WEB_AREA;
278 case blink::WebAXRoleSearch:
279 return ui::AX_ROLE_SEARCH;
280 case blink::WebAXRoleSearchBox:
281 return ui::AX_ROLE_SEARCH_BOX;
282 case blink::WebAXRoleSlider:
283 return ui::AX_ROLE_SLIDER;
284 case blink::WebAXRoleSliderThumb:
285 return ui::AX_ROLE_SLIDER_THUMB;
286 case blink::WebAXRoleSpinButton:
287 return ui::AX_ROLE_SPIN_BUTTON;
288 case blink::WebAXRoleSpinButtonPart:
289 return ui::AX_ROLE_SPIN_BUTTON_PART;
290 case blink::WebAXRoleSplitter:
291 return ui::AX_ROLE_SPLITTER;
292 case blink::WebAXRoleStaticText:
293 return ui::AX_ROLE_STATIC_TEXT;
294 case blink::WebAXRoleStatus:
295 return ui::AX_ROLE_STATUS;
296 case blink::WebAXRoleSwitch:
297 return ui::AX_ROLE_SWITCH;
298 case blink::WebAXRoleTab:
299 return ui::AX_ROLE_TAB;
300 case blink::WebAXRoleTabGroup:
301 return ui::AX_ROLE_TAB_GROUP;
302 case blink::WebAXRoleTabList:
303 return ui::AX_ROLE_TAB_LIST;
304 case blink::WebAXRoleTabPanel:
305 return ui::AX_ROLE_TAB_PANEL;
306 case blink::WebAXRoleTable:
307 return ui::AX_ROLE_TABLE;
308 case blink::WebAXRoleTableHeaderContainer:
309 return ui::AX_ROLE_TABLE_HEADER_CONTAINER;
310 case blink::WebAXRoleTextField:
311 return ui::AX_ROLE_TEXT_FIELD;
312 case blink::WebAXRoleTime:
313 return ui::AX_ROLE_TIME;
314 case blink::WebAXRoleTimer:
315 return ui::AX_ROLE_TIMER;
316 case blink::WebAXRoleToggleButton:
317 return ui::AX_ROLE_TOGGLE_BUTTON;
318 case blink::WebAXRoleToolbar:
319 return ui::AX_ROLE_TOOLBAR;
320 case blink::WebAXRoleTree:
321 return ui::AX_ROLE_TREE;
322 case blink::WebAXRoleTreeGrid:
323 return ui::AX_ROLE_TREE_GRID;
324 case blink::WebAXRoleTreeItem:
325 return ui::AX_ROLE_TREE_ITEM;
326 case blink::WebAXRoleUnknown:
327 return ui::AX_ROLE_UNKNOWN;
328 case blink::WebAXRoleUserInterfaceTooltip:
329 return ui::AX_ROLE_TOOLTIP;
330 case blink::WebAXRoleWebArea:
331 return ui::AX_ROLE_WEB_AREA;
332 case blink::WebAXRoleLineBreak:
333 return ui::AX_ROLE_LINE_BREAK;
334 case blink::WebAXRoleWindow:
335 return ui::AX_ROLE_WINDOW;
336 default:
337 // We can't add an assertion here, that prevents us
338 // from adding new role enums in Blink.
339 LOG(WARNING) << "Warning: Blink WebAXRole " << role
340 << " not handled by Chromium yet.";
341 return ui::AX_ROLE_UNKNOWN;
345 ui::AXEvent AXEventFromBlink(blink::WebAXEvent event) {
346 switch (event) {
347 case blink::WebAXEventActiveDescendantChanged:
348 return ui::AX_EVENT_ACTIVEDESCENDANTCHANGED;
349 case blink::WebAXEventAlert:
350 return ui::AX_EVENT_ALERT;
351 case blink::WebAXEventAriaAttributeChanged:
352 return ui::AX_EVENT_ARIA_ATTRIBUTE_CHANGED;
353 case blink::WebAXEventAutocorrectionOccured:
354 return ui::AX_EVENT_AUTOCORRECTION_OCCURED;
355 case blink::WebAXEventCheckedStateChanged:
356 return ui::AX_EVENT_CHECKED_STATE_CHANGED;
357 case blink::WebAXEventChildrenChanged:
358 return ui::AX_EVENT_CHILDREN_CHANGED;
359 case blink::WebAXEventFocus:
360 return ui::AX_EVENT_FOCUS;
361 case blink::WebAXEventInvalidStatusChanged:
362 return ui::AX_EVENT_INVALID_STATUS_CHANGED;
363 case blink::WebAXEventLayoutComplete:
364 return ui::AX_EVENT_LAYOUT_COMPLETE;
365 case blink::WebAXEventLiveRegionChanged:
366 return ui::AX_EVENT_LIVE_REGION_CHANGED;
367 case blink::WebAXEventLoadComplete:
368 return ui::AX_EVENT_LOAD_COMPLETE;
369 case blink::WebAXEventLocationChanged:
370 return ui::AX_EVENT_LOCATION_CHANGED;
371 case blink::WebAXEventMenuListItemSelected:
372 return ui::AX_EVENT_MENU_LIST_ITEM_SELECTED;
373 case blink::WebAXEventMenuListItemUnselected:
374 return ui::AX_EVENT_MENU_LIST_ITEM_SELECTED;
375 case blink::WebAXEventMenuListValueChanged:
376 return ui::AX_EVENT_MENU_LIST_VALUE_CHANGED;
377 case blink::WebAXEventRowCollapsed:
378 return ui::AX_EVENT_ROW_COLLAPSED;
379 case blink::WebAXEventRowCountChanged:
380 return ui::AX_EVENT_ROW_COUNT_CHANGED;
381 case blink::WebAXEventRowExpanded:
382 return ui::AX_EVENT_ROW_EXPANDED;
383 case blink::WebAXEventScrollPositionChanged:
384 return ui::AX_EVENT_SCROLL_POSITION_CHANGED;
385 case blink::WebAXEventScrolledToAnchor:
386 return ui::AX_EVENT_SCROLLED_TO_ANCHOR;
387 case blink::WebAXEventSelectedChildrenChanged:
388 return ui::AX_EVENT_SELECTED_CHILDREN_CHANGED;
389 case blink::WebAXEventSelectedTextChanged:
390 return ui::AX_EVENT_TEXT_SELECTION_CHANGED;
391 case blink::WebAXEventTextChanged:
392 return ui::AX_EVENT_TEXT_CHANGED;
393 case blink::WebAXEventValueChanged:
394 return ui::AX_EVENT_VALUE_CHANGED;
395 default:
396 // We can't add an assertion here, that prevents us
397 // from adding new event enums in Blink.
398 return ui::AX_EVENT_NONE;
402 ui::AXTextDirection AXTextDirectionFromBlink(
403 blink::WebAXTextDirection text_direction) {
404 switch (text_direction) {
405 case blink::WebAXTextDirectionLR:
406 return ui::AX_TEXT_DIRECTION_LTR;
407 case blink::WebAXTextDirectionRL:
408 return ui::AX_TEXT_DIRECTION_RTL;
409 case blink::WebAXTextDirectionTB:
410 return ui::AX_TEXT_DIRECTION_TTB;
411 case blink::WebAXTextDirectionBT:
412 return ui::AX_TEXT_DIRECTION_BTT;
413 default:
414 NOTREACHED();
417 return ui::AX_TEXT_DIRECTION_NONE;
420 ui::AXTextStyle AXTextStyleFromBlink(blink::WebAXTextStyle text_style) {
421 unsigned int browser_text_style = ui::AX_TEXT_STYLE_NONE;
422 if (text_style & blink::WebAXTextStyleBold)
423 browser_text_style |= ui::AX_TEXT_STYLE_BOLD;
424 if (text_style & blink::WebAXTextStyleItalic)
425 browser_text_style |= ui::AX_TEXT_STYLE_ITALIC;
426 if (text_style & blink::WebAXTextStyleUnderline)
427 browser_text_style |= ui::AX_TEXT_STYLE_UNDERLINE;
428 if (text_style & blink::WebAXTextStyleLineThrough)
429 browser_text_style |= ui::AX_TEXT_STYLE_LINE_THROUGH;
430 return static_cast<ui::AXTextStyle>(browser_text_style);
433 ui::AXInvalidState AXInvalidStateFromBlink(
434 blink::WebAXInvalidState invalid_state) {
435 switch (invalid_state) {
436 case blink::WebAXInvalidStateUndefined:
437 return ui::AX_INVALID_STATE_NONE;
438 case blink::WebAXInvalidStateFalse:
439 return ui::AX_INVALID_STATE_FALSE;
440 case blink::WebAXInvalidStateTrue:
441 return ui::AX_INVALID_STATE_TRUE;
442 case blink::WebAXInvalidStateSpelling:
443 return ui::AX_INVALID_STATE_SPELLING;
444 case blink::WebAXInvalidStateGrammar:
445 return ui::AX_INVALID_STATE_GRAMMAR;
446 case blink::WebAXInvalidStateOther:
447 return ui::AX_INVALID_STATE_OTHER;
448 default:
449 NOTREACHED();
452 return ui::AX_INVALID_STATE_NONE;
455 ui::AXSortDirection AXSortDirectionFromBlink(
456 blink::WebAXSortDirection sort_direction) {
457 switch (sort_direction) {
458 case blink::WebAXSortDirectionUndefined:
459 return ui::AX_SORT_DIRECTION_NONE;
460 case blink::WebAXSortDirectionNone:
461 return ui::AX_SORT_DIRECTION_UNSORTED;
462 case blink::WebAXSortDirectionAscending:
463 return ui::AX_SORT_DIRECTION_ASCENDING;
464 case blink::WebAXSortDirectionDescending:
465 return ui::AX_SORT_DIRECTION_DESCENDING;
466 case blink::WebAXSortDirectionOther:
467 return ui::AX_SORT_DIRECTION_OTHER;
468 default:
469 NOTREACHED();
472 return ui::AX_SORT_DIRECTION_NONE;
475 } // Namespace content.