OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 #ifndef WEBKIT_GLUE_WEBACCESSIBILITY_H_ | |
6 #define WEBKIT_GLUE_WEBACCESSIBILITY_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 #include <vector> | |
11 | |
12 #include "base/string16.h" | |
13 #include "ui/gfx/rect.h" | |
14 #include "webkit/glue/webkit_glue_export.h" | |
15 | |
16 namespace WebKit { | |
17 class WebAccessibilityObject; | |
18 } | |
19 | |
20 namespace webkit_glue { | |
21 | |
22 // A compact representation of the accessibility information for a | |
23 // single web object, in a form that can be serialized and sent from | |
24 // the renderer process to the browser process. | |
25 struct WEBKIT_GLUE_EXPORT WebAccessibility { | |
26 public: | |
27 // An enumeration of accessibility roles. | |
28 enum Role { | |
29 ROLE_UNKNOWN = 0, | |
30 | |
31 // Used by Chromium to distinguish between the root of the tree | |
32 // for this page, and a web area for a frame within this page. | |
33 ROLE_ROOT_WEB_AREA, | |
34 | |
35 // These roles all directly correspond to WebKit accessibility roles, | |
36 // keep these alphabetical. | |
37 ROLE_ALERT, | |
38 ROLE_ALERT_DIALOG, | |
39 ROLE_ANNOTATION, | |
40 ROLE_APPLICATION, | |
41 ROLE_ARTICLE, | |
42 ROLE_BROWSER, | |
43 ROLE_BUSY_INDICATOR, | |
44 ROLE_BUTTON, | |
45 ROLE_CELL, | |
46 ROLE_CHECKBOX, | |
47 ROLE_COLOR_WELL, | |
48 ROLE_COLUMN, | |
49 ROLE_COLUMN_HEADER, | |
50 ROLE_COMBO_BOX, | |
51 ROLE_DEFINITION_LIST_DEFINITION, | |
52 ROLE_DEFINITION_LIST_TERM, | |
53 ROLE_DIALOG, | |
54 ROLE_DIRECTORY, | |
55 ROLE_DISCLOSURE_TRIANGLE, | |
56 ROLE_DOCUMENT, | |
57 ROLE_DRAWER, | |
58 ROLE_EDITABLE_TEXT, | |
59 ROLE_FOOTER, | |
60 ROLE_GRID, | |
61 ROLE_GROUP, | |
62 ROLE_GROW_AREA, | |
63 ROLE_HEADING, | |
64 ROLE_HELP_TAG, | |
65 ROLE_IGNORED, | |
66 ROLE_IMAGE, | |
67 ROLE_IMAGE_MAP, | |
68 ROLE_IMAGE_MAP_LINK, | |
69 ROLE_INCREMENTOR, | |
70 ROLE_LANDMARK_APPLICATION, | |
71 ROLE_LANDMARK_BANNER, | |
72 ROLE_LANDMARK_COMPLEMENTARY, | |
73 ROLE_LANDMARK_CONTENTINFO, | |
74 ROLE_LANDMARK_MAIN, | |
75 ROLE_LANDMARK_NAVIGATION, | |
76 ROLE_LANDMARK_SEARCH, | |
77 ROLE_LINK, | |
78 ROLE_LIST, | |
79 ROLE_LISTBOX, | |
80 ROLE_LISTBOX_OPTION, | |
81 ROLE_LIST_ITEM, | |
82 ROLE_LIST_MARKER, | |
83 ROLE_LOG, | |
84 ROLE_MARQUEE, | |
85 ROLE_MATH, | |
86 ROLE_MATTE, | |
87 ROLE_MENU, | |
88 ROLE_MENU_BAR, | |
89 ROLE_MENU_ITEM, | |
90 ROLE_MENU_BUTTON, | |
91 ROLE_MENU_LIST_OPTION, | |
92 ROLE_MENU_LIST_POPUP, | |
93 ROLE_NOTE, | |
94 ROLE_OUTLINE, | |
95 ROLE_POPUP_BUTTON, | |
96 ROLE_PROGRESS_INDICATOR, | |
97 ROLE_RADIO_BUTTON, | |
98 ROLE_RADIO_GROUP, | |
99 ROLE_REGION, | |
100 ROLE_ROW, | |
101 ROLE_ROW_HEADER, | |
102 ROLE_RULER, | |
103 ROLE_RULER_MARKER, | |
104 ROLE_SCROLLAREA, | |
105 ROLE_SCROLLBAR, | |
106 ROLE_SHEET, | |
107 ROLE_SLIDER, | |
108 ROLE_SLIDER_THUMB, | |
109 ROLE_SPLITTER, | |
110 ROLE_SPLIT_GROUP, | |
111 ROLE_STATIC_TEXT, | |
112 ROLE_STATUS, | |
113 ROLE_SYSTEM_WIDE, | |
114 ROLE_TAB, | |
115 ROLE_TABLE, | |
116 ROLE_TABLE_HEADER_CONTAINER, | |
117 ROLE_TAB_GROUP_UNUSED, // WebKit doesn't use (uses ROLE_TAB_LIST) | |
118 ROLE_TAB_LIST, | |
119 ROLE_TAB_PANEL, | |
120 ROLE_TEXTAREA, | |
121 ROLE_TEXT_FIELD, | |
122 ROLE_TIMER, | |
123 ROLE_TOOLBAR, | |
124 ROLE_TOOLTIP, | |
125 ROLE_TREE, | |
126 ROLE_TREE_GRID, | |
127 ROLE_TREE_ITEM, | |
128 ROLE_VALUE_INDICATOR, | |
129 ROLE_WEBCORE_LINK, | |
130 ROLE_WEB_AREA, | |
131 ROLE_WINDOW, | |
132 NUM_ROLES | |
133 }; | |
134 | |
135 // An alphabetical enumeration of accessibility states. | |
136 // A state bitmask is formed by shifting 1 to the left by each state, | |
137 // for example: | |
138 // int mask = (1 << STATE_CHECKED) | (1 << STATE_FOCUSED); | |
139 enum State { | |
140 STATE_BUSY, | |
141 STATE_CHECKED, | |
142 STATE_COLLAPSED, | |
143 STATE_EXPANDED, | |
144 STATE_FOCUSABLE, | |
145 STATE_FOCUSED, | |
146 STATE_HASPOPUP, | |
147 STATE_HOTTRACKED, | |
148 STATE_INDETERMINATE, | |
149 STATE_INVISIBLE, | |
150 STATE_LINKED, | |
151 STATE_MULTISELECTABLE, | |
152 STATE_OFFSCREEN, | |
153 STATE_PRESSED, | |
154 STATE_PROTECTED, | |
155 STATE_READONLY, | |
156 STATE_REQUIRED, | |
157 STATE_SELECTABLE, | |
158 STATE_SELECTED, | |
159 STATE_TRAVERSED, | |
160 STATE_UNAVAILABLE, | |
161 STATE_VERTICAL, | |
162 STATE_VISITED, | |
163 NUM_STATES | |
164 }; | |
165 | |
166 COMPILE_ASSERT(NUM_STATES <= 31, state_enum_not_too_large); | |
167 | |
168 // Additional optional attributes that can be optionally attached to | |
169 // a node. | |
170 enum StringAttribute { | |
171 // Document attributes. | |
172 ATTR_DOC_URL, | |
173 ATTR_DOC_TITLE, | |
174 ATTR_DOC_MIMETYPE, | |
175 ATTR_DOC_DOCTYPE, | |
176 | |
177 // Attributes that could apply to any node. | |
178 ATTR_ACCESS_KEY, | |
179 ATTR_ACTION, | |
180 ATTR_CONTAINER_LIVE_RELEVANT, | |
181 ATTR_CONTAINER_LIVE_STATUS, | |
182 ATTR_DESCRIPTION, | |
183 ATTR_DISPLAY, | |
184 ATTR_HELP, | |
185 ATTR_HTML_TAG, | |
186 ATTR_LIVE_RELEVANT, | |
187 ATTR_LIVE_STATUS, | |
188 ATTR_ROLE, | |
189 ATTR_SHORTCUT, | |
190 ATTR_URL, | |
191 }; | |
192 | |
193 enum IntAttribute { | |
194 // Scrollable container attributes. | |
195 ATTR_SCROLL_X, | |
196 ATTR_SCROLL_X_MIN, | |
197 ATTR_SCROLL_X_MAX, | |
198 ATTR_SCROLL_Y, | |
199 ATTR_SCROLL_Y_MIN, | |
200 ATTR_SCROLL_Y_MAX, | |
201 | |
202 // Editable text attributes. | |
203 ATTR_TEXT_SEL_START, | |
204 ATTR_TEXT_SEL_END, | |
205 | |
206 // Table attributes. | |
207 ATTR_TABLE_ROW_COUNT, | |
208 ATTR_TABLE_COLUMN_COUNT, | |
209 | |
210 // Table cell attributes. | |
211 ATTR_TABLE_CELL_COLUMN_INDEX, | |
212 ATTR_TABLE_CELL_COLUMN_SPAN, | |
213 ATTR_TABLE_CELL_ROW_INDEX, | |
214 ATTR_TABLE_CELL_ROW_SPAN, | |
215 | |
216 // Tree control attributes. | |
217 ATTR_HIERARCHICAL_LEVEL, | |
218 | |
219 // Relationships between this element and other elements. | |
220 ATTR_TITLE_UI_ELEMENT, | |
221 }; | |
222 | |
223 enum FloatAttribute { | |
224 // Document attributes. | |
225 ATTR_DOC_LOADING_PROGRESS, | |
226 | |
227 // Range attributes. | |
228 ATTR_VALUE_FOR_RANGE, | |
229 ATTR_MIN_VALUE_FOR_RANGE, | |
230 ATTR_MAX_VALUE_FOR_RANGE, | |
231 }; | |
232 | |
233 enum BoolAttribute { | |
234 // Document attributes. | |
235 ATTR_DOC_LOADED, | |
236 | |
237 // True if a checkbox or radio button is in the "mixed" state. | |
238 ATTR_BUTTON_MIXED, | |
239 | |
240 // Live region attributes. | |
241 ATTR_CONTAINER_LIVE_ATOMIC, | |
242 ATTR_CONTAINER_LIVE_BUSY, | |
243 ATTR_LIVE_ATOMIC, | |
244 ATTR_LIVE_BUSY, | |
245 | |
246 // ARIA readonly flag. | |
247 ATTR_ARIA_READONLY, | |
248 | |
249 // Writeable attributes | |
250 ATTR_CAN_SET_VALUE, | |
251 }; | |
252 | |
253 enum IncludeChildren { | |
254 NO_CHILDREN, | |
255 INCLUDE_CHILDREN | |
256 }; | |
257 | |
258 enum IncludeLineBreaks { | |
259 NO_LINE_BREAKS, | |
260 INCLUDE_LINE_BREAKS | |
261 }; | |
262 | |
263 // Empty constructor, for serialization. | |
264 WebAccessibility(); | |
265 | |
266 // Construct from a WebAccessibilityObject. Recursively creates child | |
267 // nodes as needed to complete the tree. | |
268 WebAccessibility(const WebKit::WebAccessibilityObject& src, | |
269 IncludeChildren include_children, | |
270 IncludeLineBreaks include_line_breaks); | |
271 | |
272 ~WebAccessibility(); | |
273 | |
274 // Initialize an already-created struct, same as the constructor above. | |
275 void Init(const WebKit::WebAccessibilityObject& src, | |
276 IncludeChildren include_children, | |
277 IncludeLineBreaks include_line_breaks); | |
278 | |
279 #ifndef NDEBUG | |
280 std::string DebugString(bool recursive) const; | |
281 #endif | |
282 | |
283 private: | |
284 // Returns true if |ancestor| is the first unignored parent of |child|, | |
285 // which means that when walking up the parent chain from |child|, | |
286 // |ancestor| is the *first* ancestor that isn't marked as | |
287 // accessibilityIsIgnored(). | |
288 bool IsParentUnignoredOf(const WebKit::WebAccessibilityObject& ancestor, | |
289 const WebKit::WebAccessibilityObject& child); | |
290 | |
291 public: | |
292 // This is a simple serializable struct. All member variables should be | |
293 // copyable. | |
294 int32 id; | |
295 string16 name; | |
296 string16 value; | |
297 Role role; | |
298 uint32 state; | |
299 gfx::Rect location; | |
300 std::map<StringAttribute, string16> string_attributes; | |
301 std::map<IntAttribute, int32> int_attributes; | |
302 std::map<FloatAttribute, float> float_attributes; | |
303 std::map<BoolAttribute, bool> bool_attributes; | |
304 std::vector<WebAccessibility> children; | |
305 std::vector<int32> indirect_child_ids; | |
306 std::vector<std::pair<string16, string16> > html_attributes; | |
307 std::vector<int32> line_breaks; | |
308 | |
309 // For a table, the cell ids in row-major order, with duplicate entries | |
310 // when there's a rowspan or colspan, and with -1 for missing cells. | |
311 // There are always exactly rows * columns entries. | |
312 std::vector<int32> cell_ids; | |
313 | |
314 // For a table, the unique cell ids in row-major order of their first | |
315 // occurrence. | |
316 std::vector<int32> unique_cell_ids; | |
317 }; | |
318 | |
319 } // namespace webkit_glue | |
320 | |
321 #endif // WEBKIT_GLUE_WEBACCESSIBILITY_H_ | |
OLD | NEW |