Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / accessibility / ax_node_data.cc
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.
4
5 #include "ui/accessibility/ax_node_data.h"
6
7 #include <set>
8
9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h"
12
13 using base::DoubleToString;
14 using base::IntToString;
15
16 namespace ui {
17
18 namespace {
19
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]);
26   }
27   return str;
28 }
29
30 }  // Anonymous namespace
31
32 AXNodeData::AXNodeData()
33     : id(-1),
34       role(AX_ROLE_UNKNOWN),
35       state(0xFFFFFFFF) {
36 }
37
38 AXNodeData::~AXNodeData() {
39 }
40
41 void AXNodeData::AddStringAttribute(
42     AXStringAttribute attribute, const std::string& value) {
43   string_attributes.push_back(std::make_pair(attribute, value));
44 }
45
46 void AXNodeData::AddIntAttribute(
47     AXIntAttribute attribute, int value) {
48   int_attributes.push_back(std::make_pair(attribute, value));
49 }
50
51 void AXNodeData::AddFloatAttribute(
52     AXFloatAttribute attribute, float value) {
53   float_attributes.push_back(std::make_pair(attribute, value));
54 }
55
56 void AXNodeData::AddBoolAttribute(
57     AXBoolAttribute attribute, bool value) {
58   bool_attributes.push_back(std::make_pair(attribute, value));
59 }
60
61 void AXNodeData::AddIntListAttribute(
62     AXIntListAttribute attribute, const std::vector<int32>& value) {
63   intlist_attributes.push_back(std::make_pair(attribute, value));
64 }
65
66 void AXNodeData::SetName(std::string name) {
67   string_attributes.push_back(std::make_pair(AX_ATTR_NAME, name));
68 }
69
70 void AXNodeData::SetValue(std::string value) {
71   string_attributes.push_back(std::make_pair(AX_ATTR_VALUE, value));
72 }
73
74 std::string AXNodeData::ToString() const {
75   std::string result;
76
77   result += "id=" + IntToString(id);
78   result += " " + ui::ToString(role);
79
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";
122
123   result += " (" + IntToString(location.x()) + ", " +
124                    IntToString(location.y()) + ")-(" +
125                    IntToString(location.width()) + ", " +
126                    IntToString(location.height()) + ")";
127
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_TITLE_UI_ELEMENT:
192         result += " title_elem=" + value;
193         break;
194       case AX_ATTR_ACTIVEDESCENDANT_ID:
195         result += " activedescendant=" + value;
196         break;
197       case AX_ATTR_COLOR_VALUE_RED:
198         result += " color_value_red=" + value;
199         break;
200       case AX_ATTR_COLOR_VALUE_GREEN:
201         result += " color_value_green=" + value;
202         break;
203       case AX_ATTR_COLOR_VALUE_BLUE:
204         result += " color_value_blue=" + value;
205         break;
206       case AX_ATTR_TREE_ID:
207         result += " tree_id=" + value;
208         break;
209       case AX_ATTR_CHILD_TREE_ID:
210         result += " child_tree_id=" + value;
211         break;
212       case AX_ATTR_TEXT_DIRECTION:
213         switch (int_attributes[i].second) {
214           case AX_TEXT_DIRECTION_LR:
215           default:
216             result += " text_direction=lr";
217             break;
218           case AX_TEXT_DIRECTION_RL:
219             result += " text_direction=rl";
220             break;
221           case AX_TEXT_DIRECTION_TB:
222             result += " text_direction=tb";
223             break;
224           case AX_TEXT_DIRECTION_BT:
225             result += " text_direction=bt";
226             break;
227         }
228         break;
229       case AX_INT_ATTRIBUTE_NONE:
230         break;
231     }
232   }
233
234   for (size_t i = 0; i < string_attributes.size(); ++i) {
235     std::string value = string_attributes[i].second;
236     switch (string_attributes[i].first) {
237       case AX_ATTR_DOC_URL:
238         result += " doc_url=" + value;
239         break;
240       case AX_ATTR_DOC_TITLE:
241         result += " doc_title=" + value;
242         break;
243       case AX_ATTR_DOC_MIMETYPE:
244         result += " doc_mimetype=" + value;
245         break;
246       case AX_ATTR_DOC_DOCTYPE:
247         result += " doc_doctype=" + value;
248         break;
249       case AX_ATTR_ACCESS_KEY:
250         result += " access_key=" + value;
251         break;
252       case AX_ATTR_ACTION:
253         result += " action=" + value;
254         break;
255       case AX_ATTR_DESCRIPTION:
256         result += " description=" + value;
257         break;
258       case AX_ATTR_DISPLAY:
259         result += " display=" + value;
260         break;
261       case AX_ATTR_HELP:
262         result += " help=" + value;
263         break;
264       case AX_ATTR_HTML_TAG:
265         result += " html_tag=" + value;
266         break;
267       case AX_ATTR_LIVE_RELEVANT:
268         result += " relevant=" + value;
269         break;
270       case AX_ATTR_LIVE_STATUS:
271         result += " live=" + value;
272         break;
273       case AX_ATTR_CONTAINER_LIVE_RELEVANT:
274         result += " container_relevant=" + value;
275         break;
276       case AX_ATTR_CONTAINER_LIVE_STATUS:
277         result += " container_live=" + value;
278         break;
279       case AX_ATTR_ROLE:
280         result += " role=" + value;
281         break;
282       case AX_ATTR_SHORTCUT:
283         result += " shortcut=" + value;
284         break;
285      case AX_ATTR_TEXT_INPUT_TYPE:
286         result += " text_input_type=" + value;
287         break;
288       case AX_ATTR_URL:
289         result += " url=" + value;
290         break;
291       case AX_ATTR_NAME:
292         result += " name=" + value;
293         break;
294       case AX_ATTR_VALUE:
295         result += " value=" + value;
296         break;
297       case AX_STRING_ATTRIBUTE_NONE:
298         break;
299     }
300   }
301
302   for (size_t i = 0; i < float_attributes.size(); ++i) {
303     std::string value = DoubleToString(float_attributes[i].second);
304     switch (float_attributes[i].first) {
305       case AX_ATTR_DOC_LOADING_PROGRESS:
306         result += " doc_progress=" + value;
307         break;
308       case AX_ATTR_VALUE_FOR_RANGE:
309         result += " value_for_range=" + value;
310         break;
311       case AX_ATTR_MAX_VALUE_FOR_RANGE:
312         result += " max_value=" + value;
313         break;
314       case AX_ATTR_MIN_VALUE_FOR_RANGE:
315         result += " min_value=" + value;
316         break;
317       case AX_FLOAT_ATTRIBUTE_NONE:
318         break;
319     }
320   }
321
322   for (size_t i = 0; i < bool_attributes.size(); ++i) {
323     std::string value = bool_attributes[i].second ? "true" : "false";
324     switch (bool_attributes[i].first) {
325       case AX_ATTR_DOC_LOADED:
326         result += " doc_loaded=" + value;
327         break;
328       case AX_ATTR_BUTTON_MIXED:
329         result += " mixed=" + value;
330         break;
331       case AX_ATTR_LIVE_ATOMIC:
332         result += " atomic=" + value;
333         break;
334       case AX_ATTR_LIVE_BUSY:
335         result += " busy=" + value;
336         break;
337       case AX_ATTR_CONTAINER_LIVE_ATOMIC:
338         result += " container_atomic=" + value;
339         break;
340       case AX_ATTR_CONTAINER_LIVE_BUSY:
341         result += " container_busy=" + value;
342         break;
343       case AX_ATTR_ARIA_READONLY:
344         result += " aria_readonly=" + value;
345         break;
346       case AX_ATTR_CAN_SET_VALUE:
347         result += " can_set_value=" + value;
348         break;
349       case AX_ATTR_UPDATE_LOCATION_ONLY:
350         result += " update_location_only=" + value;
351         break;
352       case AX_ATTR_CANVAS_HAS_FALLBACK:
353         result += " has_fallback=" + value;
354         break;
355       case AX_ATTR_IS_AX_TREE_HOST:
356         result += " is_ax_tree_host=" + value;
357         break;
358       case AX_BOOL_ATTRIBUTE_NONE:
359         break;
360     }
361   }
362
363   for (size_t i = 0; i < intlist_attributes.size(); ++i) {
364     const std::vector<int32>& values = intlist_attributes[i].second;
365     switch (intlist_attributes[i].first) {
366       case AX_ATTR_INDIRECT_CHILD_IDS:
367         result += " indirect_child_ids=" + IntVectorToString(values);
368         break;
369       case AX_ATTR_CONTROLS_IDS:
370         result += " controls_ids=" + IntVectorToString(values);
371         break;
372       case AX_ATTR_DESCRIBEDBY_IDS:
373         result += " describedby_ids=" + IntVectorToString(values);
374         break;
375       case AX_ATTR_FLOWTO_IDS:
376         result += " flowto_ids=" + IntVectorToString(values);
377         break;
378       case AX_ATTR_LABELLEDBY_IDS:
379         result += " labelledby_ids=" + IntVectorToString(values);
380         break;
381       case AX_ATTR_OWNS_IDS:
382         result += " owns_ids=" + IntVectorToString(values);
383         break;
384       case AX_ATTR_LINE_BREAKS:
385         result += " line_breaks=" + IntVectorToString(values);
386         break;
387       case AX_ATTR_CELL_IDS:
388         result += " cell_ids=" + IntVectorToString(values);
389         break;
390       case AX_ATTR_UNIQUE_CELL_IDS:
391         result += " unique_cell_ids=" + IntVectorToString(values);
392         break;
393       case AX_ATTR_CHARACTER_OFFSETS:
394         result += " character_offsets=" + IntVectorToString(values);
395         break;
396       case AX_ATTR_WORD_STARTS:
397         result += " word_starts=" + IntVectorToString(values);
398         break;
399       case AX_ATTR_WORD_ENDS:
400         result += " word_ends=" + IntVectorToString(values);
401         break;
402       case AX_INT_LIST_ATTRIBUTE_NONE:
403         break;
404     }
405   }
406
407   if (!child_ids.empty())
408     result += " child_ids=" + IntVectorToString(child_ids);
409
410   return result;
411 }
412
413 }  // namespace ui