Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / accessibility / ax_node_data.cc
blob99ff3321bdd784c13970f4058333f6b3f64708e2
1 // Copyright 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 "ui/accessibility/ax_node_data.h"
7 #include <set>
9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h"
13 using base::DoubleToString;
14 using base::IntToString;
16 namespace ui {
18 namespace {
20 std::string IntVectorToString(const std::vector<int>& items) {
21 std::string str;
22 for (size_t i = 0; i < items.size(); ++i) {
23 if (i > 0)
24 str += ",";
25 str += IntToString(items[i]);
27 return str;
30 } // Anonymous namespace
32 AXNodeData::AXNodeData()
33 : id(-1),
34 role(AX_ROLE_UNKNOWN),
35 state(0xFFFFFFFF) {
38 AXNodeData::~AXNodeData() {
41 void AXNodeData::AddStringAttribute(
42 AXStringAttribute attribute, const std::string& value) {
43 string_attributes.push_back(std::make_pair(attribute, value));
46 void AXNodeData::AddIntAttribute(
47 AXIntAttribute attribute, int value) {
48 int_attributes.push_back(std::make_pair(attribute, value));
51 void AXNodeData::AddFloatAttribute(
52 AXFloatAttribute attribute, float value) {
53 float_attributes.push_back(std::make_pair(attribute, value));
56 void AXNodeData::AddBoolAttribute(
57 AXBoolAttribute attribute, bool value) {
58 bool_attributes.push_back(std::make_pair(attribute, value));
61 void AXNodeData::AddIntListAttribute(
62 AXIntListAttribute attribute, const std::vector<int32>& value) {
63 intlist_attributes.push_back(std::make_pair(attribute, value));
66 void AXNodeData::SetName(std::string name) {
67 string_attributes.push_back(std::make_pair(AX_ATTR_NAME, name));
70 void AXNodeData::SetValue(std::string value) {
71 string_attributes.push_back(std::make_pair(AX_ATTR_VALUE, value));
74 std::string AXNodeData::ToString() const {
75 std::string result;
77 result += "id=" + IntToString(id);
78 result += " " + ui::ToString(role);
80 if (state & (1 << ui::AX_STATE_BUSY))
81 result += " BUSY";
82 if (state & (1 << ui::AX_STATE_CHECKED))
83 result += " CHECKED";
84 if (state & (1 << ui::AX_STATE_COLLAPSED))
85 result += " COLLAPSED";
86 if (state & (1 << ui::AX_STATE_EXPANDED))
87 result += " EXPANDED";
88 if (state & (1 << ui::AX_STATE_FOCUSABLE))
89 result += " FOCUSABLE";
90 if (state & (1 << ui::AX_STATE_FOCUSED))
91 result += " FOCUSED";
92 if (state & (1 << ui::AX_STATE_HASPOPUP))
93 result += " HASPOPUP";
94 if (state & (1 << ui::AX_STATE_HOVERED))
95 result += " HOVERED";
96 if (state & (1 << ui::AX_STATE_INDETERMINATE))
97 result += " INDETERMINATE";
98 if (state & (1 << ui::AX_STATE_INVISIBLE))
99 result += " INVISIBLE";
100 if (state & (1 << ui::AX_STATE_LINKED))
101 result += " LINKED";
102 if (state & (1 << ui::AX_STATE_MULTISELECTABLE))
103 result += " MULTISELECTABLE";
104 if (state & (1 << ui::AX_STATE_OFFSCREEN))
105 result += " OFFSCREEN";
106 if (state & (1 << ui::AX_STATE_PRESSED))
107 result += " PRESSED";
108 if (state & (1 << ui::AX_STATE_PROTECTED))
109 result += " PROTECTED";
110 if (state & (1 << ui::AX_STATE_READ_ONLY))
111 result += " READONLY";
112 if (state & (1 << ui::AX_STATE_REQUIRED))
113 result += " REQUIRED";
114 if (state & (1 << ui::AX_STATE_SELECTABLE))
115 result += " SELECTABLE";
116 if (state & (1 << ui::AX_STATE_SELECTED))
117 result += " SELECTED";
118 if (state & (1 << ui::AX_STATE_VERTICAL))
119 result += " VERTICAL";
120 if (state & (1 << ui::AX_STATE_VISITED))
121 result += " VISITED";
123 result += " (" + IntToString(location.x()) + ", " +
124 IntToString(location.y()) + ")-(" +
125 IntToString(location.width()) + ", " +
126 IntToString(location.height()) + ")";
128 for (size_t i = 0; i < int_attributes.size(); ++i) {
129 std::string value = IntToString(int_attributes[i].second);
130 switch (int_attributes[i].first) {
131 case AX_ATTR_SCROLL_X:
132 result += " scroll_x=" + value;
133 break;
134 case AX_ATTR_SCROLL_X_MIN:
135 result += " scroll_x_min=" + value;
136 break;
137 case AX_ATTR_SCROLL_X_MAX:
138 result += " scroll_x_max=" + value;
139 break;
140 case AX_ATTR_SCROLL_Y:
141 result += " scroll_y=" + value;
142 break;
143 case AX_ATTR_SCROLL_Y_MIN:
144 result += " scroll_y_min=" + value;
145 break;
146 case AX_ATTR_SCROLL_Y_MAX:
147 result += " scroll_y_max=" + value;
148 break;
149 case AX_ATTR_HIERARCHICAL_LEVEL:
150 result += " level=" + value;
151 break;
152 case AX_ATTR_TEXT_SEL_START:
153 result += " sel_start=" + value;
154 break;
155 case AX_ATTR_TEXT_SEL_END:
156 result += " sel_end=" + value;
157 break;
158 case AX_ATTR_TABLE_ROW_COUNT:
159 result += " rows=" + value;
160 break;
161 case AX_ATTR_TABLE_COLUMN_COUNT:
162 result += " cols=" + value;
163 break;
164 case AX_ATTR_TABLE_CELL_COLUMN_INDEX:
165 result += " col=" + value;
166 break;
167 case AX_ATTR_TABLE_CELL_ROW_INDEX:
168 result += " row=" + value;
169 break;
170 case AX_ATTR_TABLE_CELL_COLUMN_SPAN:
171 result += " colspan=" + value;
172 break;
173 case AX_ATTR_TABLE_CELL_ROW_SPAN:
174 result += " rowspan=" + value;
175 break;
176 case AX_ATTR_TABLE_COLUMN_HEADER_ID:
177 result += " column_header_id=" + value;
178 break;
179 case AX_ATTR_TABLE_COLUMN_INDEX:
180 result += " column_index=" + value;
181 break;
182 case AX_ATTR_TABLE_HEADER_ID:
183 result += " header_id=" + value;
184 break;
185 case AX_ATTR_TABLE_ROW_HEADER_ID:
186 result += " row_header_id=" + value;
187 break;
188 case AX_ATTR_TABLE_ROW_INDEX:
189 result += " row_index=" + value;
190 break;
191 case AX_ATTR_SORT_DIRECTION:
192 switch (int_attributes[i].second) {
193 case AX_SORT_DIRECTION_UNSORTED:
194 result += " sort_direction=none";
195 break;
196 case AX_SORT_DIRECTION_ASCENDING:
197 result += " sort_direction=ascending";
198 break;
199 case AX_SORT_DIRECTION_DESCENDING:
200 result += " sort_direction=descending";
201 break;
202 case AX_SORT_DIRECTION_OTHER:
203 result += " sort_direction=other";
204 break;
206 break;
207 case AX_ATTR_TITLE_UI_ELEMENT:
208 result += " title_elem=" + value;
209 break;
210 case AX_ATTR_ACTIVEDESCENDANT_ID:
211 result += " activedescendant=" + value;
212 break;
213 case AX_ATTR_COLOR_VALUE_RED:
214 result += " color_value_red=" + value;
215 break;
216 case AX_ATTR_COLOR_VALUE_GREEN:
217 result += " color_value_green=" + value;
218 break;
219 case AX_ATTR_COLOR_VALUE_BLUE:
220 result += " color_value_blue=" + value;
221 break;
222 case AX_ATTR_TREE_ID:
223 result += " tree_id=" + value;
224 break;
225 case AX_ATTR_CHILD_TREE_ID:
226 result += " child_tree_id=" + value;
227 break;
228 case AX_ATTR_TEXT_DIRECTION:
229 switch (int_attributes[i].second) {
230 case AX_TEXT_DIRECTION_LR:
231 default:
232 result += " text_direction=lr";
233 break;
234 case AX_TEXT_DIRECTION_RL:
235 result += " text_direction=rl";
236 break;
237 case AX_TEXT_DIRECTION_TB:
238 result += " text_direction=tb";
239 break;
240 case AX_TEXT_DIRECTION_BT:
241 result += " text_direction=bt";
242 break;
244 break;
245 case AX_ATTR_SET_SIZE:
246 result += " setsize=" + value;
247 break;
248 case AX_ATTR_POS_IN_SET:
249 result += " posinset=" + value;
250 break;
251 case AX_ATTR_INVALID_STATE:
252 switch (int_attributes[i].second) {
253 case AX_INVALID_STATE_FALSE:
254 result += " invalid_state=false";
255 break;
256 case AX_INVALID_STATE_TRUE:
257 result += " invalid_state=true";
258 break;
259 case AX_INVALID_STATE_SPELLING:
260 result += " invalid_state=spelling";
261 break;
262 case AX_INVALID_STATE_GRAMMAR:
263 result += " invalid_state=grammar";
264 break;
265 case AX_INVALID_STATE_OTHER:
266 result += " invalid_state=other";
267 break;
269 break;
270 case AX_INT_ATTRIBUTE_NONE:
271 break;
275 for (size_t i = 0; i < string_attributes.size(); ++i) {
276 std::string value = string_attributes[i].second;
277 switch (string_attributes[i].first) {
278 case AX_ATTR_DOC_URL:
279 result += " doc_url=" + value;
280 break;
281 case AX_ATTR_DOC_TITLE:
282 result += " doc_title=" + value;
283 break;
284 case AX_ATTR_DOC_MIMETYPE:
285 result += " doc_mimetype=" + value;
286 break;
287 case AX_ATTR_DOC_DOCTYPE:
288 result += " doc_doctype=" + value;
289 break;
290 case AX_ATTR_ACCESS_KEY:
291 result += " access_key=" + value;
292 break;
293 case AX_ATTR_ACTION:
294 result += " action=" + value;
295 break;
296 case AX_ATTR_AUTO_COMPLETE:
297 result += " autocomplete=" + value;
298 break;
299 case AX_ATTR_DESCRIPTION:
300 result += " description=" + value;
301 break;
302 case AX_ATTR_DISPLAY:
303 result += " display=" + value;
304 break;
305 case AX_ATTR_DROPEFFECT:
306 result += " dropeffect=" + value;
307 break;
308 case AX_ATTR_HELP:
309 result += " help=" + value;
310 break;
311 case AX_ATTR_HTML_TAG:
312 result += " html_tag=" + value;
313 break;
314 case AX_ATTR_ARIA_INVALID_VALUE:
315 result += " aria_invalid_value=" + value;
316 break;
317 case AX_ATTR_LIVE_RELEVANT:
318 result += " relevant=" + value;
319 break;
320 case AX_ATTR_LIVE_STATUS:
321 result += " live=" + value;
322 break;
323 case AX_ATTR_CONTAINER_LIVE_RELEVANT:
324 result += " container_relevant=" + value;
325 break;
326 case AX_ATTR_CONTAINER_LIVE_STATUS:
327 result += " container_live=" + value;
328 break;
329 case AX_ATTR_PLACEHOLDER:
330 result += "placeholder" + value;
331 break;
332 case AX_ATTR_ROLE:
333 result += " role=" + value;
334 break;
335 case AX_ATTR_SHORTCUT:
336 result += " shortcut=" + value;
337 break;
338 case AX_ATTR_TEXT_INPUT_TYPE:
339 result += " text_input_type=" + value;
340 break;
341 case AX_ATTR_URL:
342 result += " url=" + value;
343 break;
344 case AX_ATTR_NAME:
345 result += " name=" + value;
346 break;
347 case AX_ATTR_VALUE:
348 result += " value=" + value;
349 break;
350 case AX_STRING_ATTRIBUTE_NONE:
351 break;
355 for (size_t i = 0; i < float_attributes.size(); ++i) {
356 std::string value = DoubleToString(float_attributes[i].second);
357 switch (float_attributes[i].first) {
358 case AX_ATTR_DOC_LOADING_PROGRESS:
359 result += " doc_progress=" + value;
360 break;
361 case AX_ATTR_VALUE_FOR_RANGE:
362 result += " value_for_range=" + value;
363 break;
364 case AX_ATTR_MAX_VALUE_FOR_RANGE:
365 result += " max_value=" + value;
366 break;
367 case AX_ATTR_MIN_VALUE_FOR_RANGE:
368 result += " min_value=" + value;
369 break;
370 case AX_FLOAT_ATTRIBUTE_NONE:
371 break;
375 for (size_t i = 0; i < bool_attributes.size(); ++i) {
376 std::string value = bool_attributes[i].second ? "true" : "false";
377 switch (bool_attributes[i].first) {
378 case AX_ATTR_DOC_LOADED:
379 result += " doc_loaded=" + value;
380 break;
381 case AX_ATTR_BUTTON_MIXED:
382 result += " mixed=" + value;
383 break;
384 case AX_ATTR_LIVE_ATOMIC:
385 result += " atomic=" + value;
386 break;
387 case AX_ATTR_LIVE_BUSY:
388 result += " busy=" + value;
389 break;
390 case AX_ATTR_CONTAINER_LIVE_ATOMIC:
391 result += " container_atomic=" + value;
392 break;
393 case AX_ATTR_CONTAINER_LIVE_BUSY:
394 result += " container_busy=" + value;
395 break;
396 case AX_ATTR_ARIA_READONLY:
397 result += " aria_readonly=" + value;
398 break;
399 case AX_ATTR_CAN_SET_VALUE:
400 result += " can_set_value=" + value;
401 break;
402 case AX_ATTR_UPDATE_LOCATION_ONLY:
403 result += " update_location_only=" + value;
404 break;
405 case AX_ATTR_CANVAS_HAS_FALLBACK:
406 result += " has_fallback=" + value;
407 break;
408 case AX_ATTR_IS_AX_TREE_HOST:
409 result += " is_ax_tree_host=" + value;
410 break;
411 case AX_ATTR_GRABBED:
412 result += " grabbed=" + value;
413 break;
414 case AX_BOOL_ATTRIBUTE_NONE:
415 break;
419 for (size_t i = 0; i < intlist_attributes.size(); ++i) {
420 const std::vector<int32>& values = intlist_attributes[i].second;
421 switch (intlist_attributes[i].first) {
422 case AX_ATTR_INDIRECT_CHILD_IDS:
423 result += " indirect_child_ids=" + IntVectorToString(values);
424 break;
425 case AX_ATTR_CONTROLS_IDS:
426 result += " controls_ids=" + IntVectorToString(values);
427 break;
428 case AX_ATTR_DESCRIBEDBY_IDS:
429 result += " describedby_ids=" + IntVectorToString(values);
430 break;
431 case AX_ATTR_FLOWTO_IDS:
432 result += " flowto_ids=" + IntVectorToString(values);
433 break;
434 case AX_ATTR_LABELLEDBY_IDS:
435 result += " labelledby_ids=" + IntVectorToString(values);
436 break;
437 case AX_ATTR_OWNS_IDS:
438 result += " owns_ids=" + IntVectorToString(values);
439 break;
440 case AX_ATTR_LINE_BREAKS:
441 result += " line_breaks=" + IntVectorToString(values);
442 break;
443 case AX_ATTR_CELL_IDS:
444 result += " cell_ids=" + IntVectorToString(values);
445 break;
446 case AX_ATTR_UNIQUE_CELL_IDS:
447 result += " unique_cell_ids=" + IntVectorToString(values);
448 break;
449 case AX_ATTR_CHARACTER_OFFSETS:
450 result += " character_offsets=" + IntVectorToString(values);
451 break;
452 case AX_ATTR_WORD_STARTS:
453 result += " word_starts=" + IntVectorToString(values);
454 break;
455 case AX_ATTR_WORD_ENDS:
456 result += " word_ends=" + IntVectorToString(values);
457 break;
458 case AX_INT_LIST_ATTRIBUTE_NONE:
459 break;
463 if (!child_ids.empty())
464 result += " child_ids=" + IntVectorToString(child_ids);
466 return result;
469 } // namespace ui