• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "content/renderer/accessibility/blink_ax_enum_conversion.h"
6 
7 #include "base/logging.h"
8 
9 namespace content {
10 
AXStateFromBlink(const blink::WebAXObject & o)11 uint32 AXStateFromBlink(const blink::WebAXObject& o) {
12   uint32 state = 0;
13   if (o.isChecked())
14     state |= (1 << ui::AX_STATE_CHECKED);
15 
16   if (o.isCollapsed())
17     state |= (1 << ui::AX_STATE_COLLAPSED);
18 
19   if (o.canSetFocusAttribute())
20     state |= (1 << ui::AX_STATE_FOCUSABLE);
21 
22   if (o.isFocused())
23     state |= (1 << ui::AX_STATE_FOCUSED);
24 
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);
30   }
31 
32   if (o.isHovered())
33     state |= (1 << ui::AX_STATE_HOVERED);
34 
35   if (o.isIndeterminate())
36     state |= (1 << ui::AX_STATE_INDETERMINATE);
37 
38   if (!o.isVisible())
39     state |= (1 << ui::AX_STATE_INVISIBLE);
40 
41   if (o.isLinked())
42     state |= (1 << ui::AX_STATE_LINKED);
43 
44   if (o.isMultiSelectable())
45     state |= (1 << ui::AX_STATE_MULTISELECTABLE);
46 
47   if (o.isOffScreen())
48     state |= (1 << ui::AX_STATE_OFFSCREEN);
49 
50   if (o.isPressed())
51     state |= (1 << ui::AX_STATE_PRESSED);
52 
53   if (o.isPasswordField())
54     state |= (1 << ui::AX_STATE_PROTECTED);
55 
56   if (o.isReadOnly())
57     state |= (1 << ui::AX_STATE_READ_ONLY);
58 
59   if (o.isRequired())
60     state |= (1 << ui::AX_STATE_REQUIRED);
61 
62   if (o.canSetSelectedAttribute())
63     state |= (1 << ui::AX_STATE_SELECTABLE);
64 
65   if (o.isSelected())
66     state |= (1 << ui::AX_STATE_SELECTED);
67 
68   if (o.isVisited())
69     state |= (1 << ui::AX_STATE_VISITED);
70 
71   if (o.isEnabled())
72     state |= (1 << ui::AX_STATE_ENABLED);
73 
74   if (o.isVertical())
75     state |= (1 << ui::AX_STATE_VERTICAL);
76 
77   if (o.isVisited())
78     state |= (1 << ui::AX_STATE_VISITED);
79 
80   return state;
81 }
82 
AXRoleFromBlink(blink::WebAXRole role)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::WebAXRoleFigcaption:
144       return ui::AX_ROLE_FIGCAPTION;
145     case blink::WebAXRoleFigure:
146       return ui::AX_ROLE_FIGURE;
147     case blink::WebAXRoleFooter:
148       return ui::AX_ROLE_FOOTER;
149     case blink::WebAXRoleForm:
150       return ui::AX_ROLE_FORM;
151     case blink::WebAXRoleGrid:
152       return ui::AX_ROLE_GRID;
153     case blink::WebAXRoleGroup:
154       return ui::AX_ROLE_GROUP;
155     case blink::WebAXRoleGrowArea:
156       return ui::AX_ROLE_GROW_AREA;
157     case blink::WebAXRoleHeading:
158       return ui::AX_ROLE_HEADING;
159     case blink::WebAXRoleHelpTag:
160       return ui::AX_ROLE_HELP_TAG;
161     case blink::WebAXRoleHorizontalRule:
162       return ui::AX_ROLE_HORIZONTAL_RULE;
163     case blink::WebAXRoleIframe:
164       return ui::AX_ROLE_IFRAME;
165     case blink::WebAXRoleIgnored:
166       return ui::AX_ROLE_IGNORED;
167     case blink::WebAXRoleImage:
168       return ui::AX_ROLE_IMAGE;
169     case blink::WebAXRoleImageMap:
170       return ui::AX_ROLE_IMAGE_MAP;
171     case blink::WebAXRoleImageMapLink:
172       return ui::AX_ROLE_IMAGE_MAP_LINK;
173     case blink::WebAXRoleIncrementor:
174       return ui::AX_ROLE_INCREMENTOR;
175     case blink::WebAXRoleInlineTextBox:
176       return ui::AX_ROLE_INLINE_TEXT_BOX;
177     case blink::WebAXRoleLabel:
178       return ui::AX_ROLE_LABEL_TEXT;
179     case blink::WebAXRoleLegend:
180       return ui::AX_ROLE_LEGEND;
181     case blink::WebAXRoleLink:
182       return ui::AX_ROLE_LINK;
183     case blink::WebAXRoleList:
184       return ui::AX_ROLE_LIST;
185     case blink::WebAXRoleListBox:
186       return ui::AX_ROLE_LIST_BOX;
187     case blink::WebAXRoleListBoxOption:
188       return ui::AX_ROLE_LIST_BOX_OPTION;
189     case blink::WebAXRoleListItem:
190       return ui::AX_ROLE_LIST_ITEM;
191     case blink::WebAXRoleListMarker:
192       return ui::AX_ROLE_LIST_MARKER;
193     case blink::WebAXRoleLog:
194       return ui::AX_ROLE_LOG;
195     case blink::WebAXRoleMain:
196       return ui::AX_ROLE_MAIN;
197     case blink::WebAXRoleMarquee:
198       return ui::AX_ROLE_MARQUEE;
199     case blink::WebAXRoleMath:
200       return ui::AX_ROLE_MATH;
201     case blink::WebAXRoleMathElement:
202       return ui::AX_ROLE_MATH_ELEMENT;
203     case blink::WebAXRoleMatte:
204       return ui::AX_ROLE_MATTE;
205     case blink::WebAXRoleMenu:
206       return ui::AX_ROLE_MENU;
207     case blink::WebAXRoleMenuBar:
208       return ui::AX_ROLE_MENU_BAR;
209     case blink::WebAXRoleMenuButton:
210       return ui::AX_ROLE_MENU_BUTTON;
211     case blink::WebAXRoleMenuItem:
212       return ui::AX_ROLE_MENU_ITEM;
213     case blink::WebAXRoleMenuListOption:
214       return ui::AX_ROLE_MENU_LIST_OPTION;
215     case blink::WebAXRoleMenuListPopup:
216       return ui::AX_ROLE_MENU_LIST_POPUP;
217     case blink::WebAXRoleNavigation:
218       return ui::AX_ROLE_NAVIGATION;
219     case blink::WebAXRoleNone:
220       return ui::AX_ROLE_NONE;
221     case blink::WebAXRoleNote:
222       return ui::AX_ROLE_NOTE;
223     case blink::WebAXRoleOutline:
224       return ui::AX_ROLE_OUTLINE;
225     case blink::WebAXRoleParagraph:
226       return ui::AX_ROLE_PARAGRAPH;
227     case blink::WebAXRolePopUpButton:
228       return ui::AX_ROLE_POP_UP_BUTTON;
229     case blink::WebAXRolePresentational:
230       return ui::AX_ROLE_PRESENTATIONAL;
231     case blink::WebAXRoleProgressIndicator:
232       return ui::AX_ROLE_PROGRESS_INDICATOR;
233     case blink::WebAXRoleRadioButton:
234       return ui::AX_ROLE_RADIO_BUTTON;
235     case blink::WebAXRoleRadioGroup:
236       return ui::AX_ROLE_RADIO_GROUP;
237     case blink::WebAXRoleRegion:
238       return ui::AX_ROLE_REGION;
239     case blink::WebAXRoleRootWebArea:
240       return ui::AX_ROLE_ROOT_WEB_AREA;
241     case blink::WebAXRoleRow:
242       return ui::AX_ROLE_ROW;
243     case blink::WebAXRoleRowHeader:
244       return ui::AX_ROLE_ROW_HEADER;
245     case blink::WebAXRoleRuler:
246       return ui::AX_ROLE_RULER;
247     case blink::WebAXRoleRulerMarker:
248       return ui::AX_ROLE_RULER_MARKER;
249     case blink::WebAXRoleSVGRoot:
250       return ui::AX_ROLE_SVG_ROOT;
251     case blink::WebAXRoleScrollArea:
252       return ui::AX_ROLE_SCROLL_AREA;
253     case blink::WebAXRoleScrollBar:
254       return ui::AX_ROLE_SCROLL_BAR;
255     case blink::WebAXRoleSeamlessWebArea:
256       return ui::AX_ROLE_SEAMLESS_WEB_AREA;
257     case blink::WebAXRoleSearch:
258       return ui::AX_ROLE_SEARCH;
259     case blink::WebAXRoleSheet:
260       return ui::AX_ROLE_SHEET;
261     case blink::WebAXRoleSlider:
262       return ui::AX_ROLE_SLIDER;
263     case blink::WebAXRoleSliderThumb:
264       return ui::AX_ROLE_SLIDER_THUMB;
265     case blink::WebAXRoleSpinButton:
266       return ui::AX_ROLE_SPIN_BUTTON;
267     case blink::WebAXRoleSpinButtonPart:
268       return ui::AX_ROLE_SPIN_BUTTON_PART;
269     case blink::WebAXRoleSplitGroup:
270       return ui::AX_ROLE_SPLIT_GROUP;
271     case blink::WebAXRoleSplitter:
272       return ui::AX_ROLE_SPLITTER;
273     case blink::WebAXRoleStaticText:
274       return ui::AX_ROLE_STATIC_TEXT;
275     case blink::WebAXRoleStatus:
276       return ui::AX_ROLE_STATUS;
277     case blink::WebAXRoleSystemWide:
278       return ui::AX_ROLE_SYSTEM_WIDE;
279     case blink::WebAXRoleTab:
280       return ui::AX_ROLE_TAB;
281     case blink::WebAXRoleTabGroup:
282       return ui::AX_ROLE_TAB_GROUP;
283     case blink::WebAXRoleTabList:
284       return ui::AX_ROLE_TAB_LIST;
285     case blink::WebAXRoleTabPanel:
286       return ui::AX_ROLE_TAB_PANEL;
287     case blink::WebAXRoleTable:
288       return ui::AX_ROLE_TABLE;
289     case blink::WebAXRoleTableHeaderContainer:
290       return ui::AX_ROLE_TABLE_HEADER_CONTAINER;
291     case blink::WebAXRoleTextArea:
292       return ui::AX_ROLE_TEXT_AREA;
293     case blink::WebAXRoleTextField:
294       return ui::AX_ROLE_TEXT_FIELD;
295     case blink::WebAXRoleTimer:
296       return ui::AX_ROLE_TIMER;
297     case blink::WebAXRoleToggleButton:
298       return ui::AX_ROLE_TOGGLE_BUTTON;
299     case blink::WebAXRoleToolbar:
300       return ui::AX_ROLE_TOOLBAR;
301     case blink::WebAXRoleTree:
302       return ui::AX_ROLE_TREE;
303     case blink::WebAXRoleTreeGrid:
304       return ui::AX_ROLE_TREE_GRID;
305     case blink::WebAXRoleTreeItem:
306       return ui::AX_ROLE_TREE_ITEM;
307     case blink::WebAXRoleUnknown:
308       return ui::AX_ROLE_UNKNOWN;
309     case blink::WebAXRoleUserInterfaceTooltip:
310       return ui::AX_ROLE_TOOLTIP;
311     case blink::WebAXRoleValueIndicator:
312       return ui::AX_ROLE_VALUE_INDICATOR;
313     case blink::WebAXRoleWebArea:
314       return ui::AX_ROLE_WEB_AREA;
315     case blink::WebAXRoleWindow:
316       return ui::AX_ROLE_WINDOW;
317     default:
318       // We can't add an assertion here, that prevents us
319       // from adding new role enums in Blink.
320       return static_cast<ui::AXRole>(-1);
321   }
322 }
323 
AXEventFromBlink(blink::WebAXEvent event)324 ui::AXEvent AXEventFromBlink(blink::WebAXEvent event) {
325   switch (event) {
326     case blink::WebAXEventActiveDescendantChanged:
327       return ui::AX_EVENT_ACTIVEDESCENDANTCHANGED;
328     case blink::WebAXEventAlert:
329       return ui::AX_EVENT_ALERT;
330     case blink::WebAXEventAriaAttributeChanged:
331       return ui::AX_EVENT_ARIA_ATTRIBUTE_CHANGED;
332     case blink::WebAXEventAutocorrectionOccured:
333       return ui::AX_EVENT_AUTOCORRECTION_OCCURED;
334     case blink::WebAXEventCheckedStateChanged:
335       return ui::AX_EVENT_CHECKED_STATE_CHANGED;
336     case blink::WebAXEventChildrenChanged:
337       return ui::AX_EVENT_CHILDREN_CHANGED;
338     case blink::WebAXEventFocus:
339       return ui::AX_EVENT_FOCUS;
340     case blink::WebAXEventInvalidStatusChanged:
341       return ui::AX_EVENT_INVALID_STATUS_CHANGED;
342     case blink::WebAXEventLayoutComplete:
343       return ui::AX_EVENT_LAYOUT_COMPLETE;
344     case blink::WebAXEventLiveRegionChanged:
345       return ui::AX_EVENT_LIVE_REGION_CHANGED;
346     case blink::WebAXEventLoadComplete:
347       return ui::AX_EVENT_LOAD_COMPLETE;
348     case blink::WebAXEventLocationChanged:
349       return ui::AX_EVENT_LOCATION_CHANGED;
350     case blink::WebAXEventMenuListItemSelected:
351       return ui::AX_EVENT_MENU_LIST_ITEM_SELECTED;
352     case blink::WebAXEventMenuListValueChanged:
353         return ui::AX_EVENT_MENU_LIST_VALUE_CHANGED;
354     case blink::WebAXEventRowCollapsed:
355       return ui::AX_EVENT_ROW_COLLAPSED;
356     case blink::WebAXEventRowCountChanged:
357       return ui::AX_EVENT_ROW_COUNT_CHANGED;
358     case blink::WebAXEventRowExpanded:
359       return ui::AX_EVENT_ROW_EXPANDED;
360     case blink::WebAXEventScrollPositionChanged:
361       return ui::AX_EVENT_SCROLL_POSITION_CHANGED;
362     case blink::WebAXEventScrolledToAnchor:
363       return ui::AX_EVENT_SCROLLED_TO_ANCHOR;
364     case blink::WebAXEventSelectedChildrenChanged:
365       return ui::AX_EVENT_SELECTED_CHILDREN_CHANGED;
366     case blink::WebAXEventSelectedTextChanged:
367       return ui::AX_EVENT_TEXT_SELECTION_CHANGED;
368     case blink::WebAXEventTextChanged:
369       return ui::AX_EVENT_TEXT_CHANGED;
370     case blink::WebAXEventValueChanged:
371       return ui::AX_EVENT_VALUE_CHANGED;
372     default:
373       // We can't add an assertion here, that prevents us
374       // from adding new event enums in Blink.
375       return ui::AX_EVENT_NONE;
376   }
377 }
378 
AXTextDirectionFromBlink(blink::WebAXTextDirection text_direction)379 ui::AXTextDirection AXTextDirectionFromBlink(
380     blink::WebAXTextDirection text_direction) {
381   switch (text_direction) {
382     case blink::WebAXTextDirectionLR:
383       return ui::AX_TEXT_DIRECTION_LR;
384     case blink::WebAXTextDirectionRL:
385       return ui::AX_TEXT_DIRECTION_RL;
386     case blink::WebAXTextDirectionTB:
387       return ui::AX_TEXT_DIRECTION_TB;
388     case blink::WebAXTextDirectionBT:
389       return ui::AX_TEXT_DIRECTION_BT;
390     default:
391       NOTREACHED();
392   }
393 
394   return ui::AX_TEXT_DIRECTION_NONE;
395 }
396 
397 }  // namespace content
398