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.
5 #include "content/common/accessibility_node_data.h"
9 #include "base/string_number_conversions.h"
10 #include "base/string_util.h"
11 #include "base/utf_string_conversions.h"
13 using base::DoubleToString
;
14 using base::IntToString
;
19 std::string
IntVectorToString(const std::vector
<int>& items
) {
21 for (size_t i
= 0; i
< items
.size(); ++i
) {
24 str
+= IntToString(items
[i
]);
30 } // Anonymous namespace
34 AccessibilityNodeData::AccessibilityNodeData()
40 AccessibilityNodeData::~AccessibilityNodeData() {
44 std::string
AccessibilityNodeData::DebugString(bool recursive
) const {
46 static int indent
= 0;
48 for (int i
= 0; i
< indent
; ++i
)
51 result
+= "id=" + IntToString(id
);
54 case ROLE_ALERT
: result
+= " ALERT"; break;
55 case ROLE_ALERT_DIALOG
: result
+= " ALERT_DIALOG"; break;
56 case ROLE_ANNOTATION
: result
+= " ANNOTATION"; break;
57 case ROLE_APPLICATION
: result
+= " APPLICATION"; break;
58 case ROLE_ARTICLE
: result
+= " ARTICLE"; break;
59 case ROLE_BROWSER
: result
+= " BROWSER"; break;
60 case ROLE_BUSY_INDICATOR
: result
+= " BUSY_INDICATOR"; break;
61 case ROLE_BUTTON
: result
+= " BUTTON"; break;
62 case ROLE_CANVAS
: result
+= " CANVAS"; break;
63 case ROLE_CANVAS_WITH_FALLBACK_CONTENT
: result
+= " CANVAS_FALLBACK"; break;
64 case ROLE_CELL
: result
+= " CELL"; break;
65 case ROLE_CHECKBOX
: result
+= " CHECKBOX"; break;
66 case ROLE_COLOR_WELL
: result
+= " COLOR_WELL"; break;
67 case ROLE_COLUMN
: result
+= " COLUMN"; break;
68 case ROLE_COLUMN_HEADER
: result
+= " COLUMN_HEADER"; break;
69 case ROLE_COMBO_BOX
: result
+= " COMBO_BOX"; break;
70 case ROLE_DEFINITION_LIST_DEFINITION
: result
+= " DL_DEFINITION"; break;
71 case ROLE_DEFINITION_LIST_TERM
: result
+= " DL_TERM"; break;
72 case ROLE_DIALOG
: result
+= " DIALOG"; break;
73 case ROLE_DIRECTORY
: result
+= " DIRECTORY"; break;
74 case ROLE_DISCLOSURE_TRIANGLE
: result
+= " DISCLOSURE_TRIANGLE"; break;
75 case ROLE_DIV
: result
+= " DIV"; break;
76 case ROLE_DOCUMENT
: result
+= " DOCUMENT"; break;
77 case ROLE_DRAWER
: result
+= " DRAWER"; break;
78 case ROLE_EDITABLE_TEXT
: result
+= " EDITABLE_TEXT"; break;
79 case ROLE_FOOTER
: result
+= " FOOTER"; break;
80 case ROLE_FORM
: result
+= " FORM"; break;
81 case ROLE_GRID
: result
+= " GRID"; break;
82 case ROLE_GROUP
: result
+= " GROUP"; break;
83 case ROLE_GROW_AREA
: result
+= " GROW_AREA"; break;
84 case ROLE_HEADING
: result
+= " HEADING"; break;
85 case ROLE_HELP_TAG
: result
+= " HELP_TAG"; break;
86 case ROLE_HORIZONTAL_RULE
: result
+= " HORIZONTAL_RULE"; break;
87 case ROLE_IGNORED
: result
+= " IGNORED"; break;
88 case ROLE_IMAGE
: result
+= " IMAGE"; break;
89 case ROLE_IMAGE_MAP
: result
+= " IMAGE_MAP"; break;
90 case ROLE_IMAGE_MAP_LINK
: result
+= " IMAGE_MAP_LINK"; break;
91 case ROLE_INCREMENTOR
: result
+= " INCREMENTOR"; break;
92 case ROLE_LABEL
: result
+= " LABEL"; break;
93 case ROLE_LANDMARK_APPLICATION
: result
+= " L_APPLICATION"; break;
94 case ROLE_LANDMARK_BANNER
: result
+= " L_BANNER"; break;
95 case ROLE_LANDMARK_COMPLEMENTARY
: result
+= " L_COMPLEMENTARY"; break;
96 case ROLE_LANDMARK_CONTENTINFO
: result
+= " L_CONTENTINFO"; break;
97 case ROLE_LANDMARK_MAIN
: result
+= " L_MAIN"; break;
98 case ROLE_LANDMARK_NAVIGATION
: result
+= " L_NAVIGATION"; break;
99 case ROLE_LANDMARK_SEARCH
: result
+= " L_SEARCH"; break;
100 case ROLE_LINK
: result
+= " LINK"; break;
101 case ROLE_LIST
: result
+= " LIST"; break;
102 case ROLE_LISTBOX
: result
+= " LISTBOX"; break;
103 case ROLE_LISTBOX_OPTION
: result
+= " LISTBOX_OPTION"; break;
104 case ROLE_LIST_ITEM
: result
+= " LIST_ITEM"; break;
105 case ROLE_LIST_MARKER
: result
+= " LIST_MARKER"; break;
106 case ROLE_LOG
: result
+= " LOG"; break;
107 case ROLE_MARQUEE
: result
+= " MARQUEE"; break;
108 case ROLE_MATH
: result
+= " MATH"; break;
109 case ROLE_MATTE
: result
+= " MATTE"; break;
110 case ROLE_MENU
: result
+= " MENU"; break;
111 case ROLE_MENU_BAR
: result
+= " MENU_BAR"; break;
112 case ROLE_MENU_BUTTON
: result
+= " MENU_BUTTON"; break;
113 case ROLE_MENU_ITEM
: result
+= " MENU_ITEM"; break;
114 case ROLE_MENU_LIST_OPTION
: result
+= " MENU_LIST_OPTION"; break;
115 case ROLE_MENU_LIST_POPUP
: result
+= " MENU_LIST_POPUP"; break;
116 case ROLE_NOTE
: result
+= " NOTE"; break;
117 case ROLE_OUTLINE
: result
+= " OUTLINE"; break;
118 case ROLE_PARAGRAPH
: result
+= " PARAGRAPH"; break;
119 case ROLE_POPUP_BUTTON
: result
+= " POPUP_BUTTON"; break;
120 case ROLE_PRESENTATIONAL
: result
+= " PRESENTATIONAL"; break;
121 case ROLE_PROGRESS_INDICATOR
: result
+= " PROGRESS_INDICATOR"; break;
122 case ROLE_RADIO_BUTTON
: result
+= " RADIO_BUTTON"; break;
123 case ROLE_RADIO_GROUP
: result
+= " RADIO_GROUP"; break;
124 case ROLE_REGION
: result
+= " REGION"; break;
125 case ROLE_ROOT_WEB_AREA
: result
+= " ROOT_WEB_AREA"; break;
126 case ROLE_ROW
: result
+= " ROW"; break;
127 case ROLE_ROW_HEADER
: result
+= " ROW_HEADER"; break;
128 case ROLE_RULER
: result
+= " RULER"; break;
129 case ROLE_RULER_MARKER
: result
+= " RULER_MARKER"; break;
130 case ROLE_SCROLLAREA
: result
+= " SCROLLAREA"; break;
131 case ROLE_SCROLLBAR
: result
+= " SCROLLBAR"; break;
132 case ROLE_SHEET
: result
+= " SHEET"; break;
133 case ROLE_SLIDER
: result
+= " SLIDER"; break;
134 case ROLE_SLIDER_THUMB
: result
+= " SLIDER_THUMB"; break;
135 case ROLE_SPIN_BUTTON
: result
+= " SPIN_BUTTON"; break;
136 case ROLE_SPIN_BUTTON_PART
: result
+= " SPIN_BUTTON_PART"; break;
137 case ROLE_SPLITTER
: result
+= " SPLITTER"; break;
138 case ROLE_SPLIT_GROUP
: result
+= " SPLIT_GROUP"; break;
139 case ROLE_STATIC_TEXT
: result
+= " STATIC_TEXT"; break;
140 case ROLE_STATUS
: result
+= " STATUS"; break;
141 case ROLE_SYSTEM_WIDE
: result
+= " SYSTEM_WIDE"; break;
142 case ROLE_TAB
: result
+= " TAB"; break;
143 case ROLE_TABLE
: result
+= " TABLE"; break;
144 case ROLE_TABLE_HEADER_CONTAINER
: result
+= " TABLE_HDR_CONTAINER"; break;
145 case ROLE_TAB_GROUP_UNUSED
: result
+= " TAB_GROUP_UNUSED"; break;
146 case ROLE_TAB_LIST
: result
+= " TAB_LIST"; break;
147 case ROLE_TAB_PANEL
: result
+= " TAB_PANEL"; break;
148 case ROLE_TEXTAREA
: result
+= " TEXTAREA"; break;
149 case ROLE_TEXT_FIELD
: result
+= " TEXT_FIELD"; break;
150 case ROLE_TIMER
: result
+= " TIMER"; break;
151 case ROLE_TOGGLE_BUTTON
: result
+= " TOGGLE_BUTTON"; break;
152 case ROLE_TOOLBAR
: result
+= " TOOLBAR"; break;
153 case ROLE_TOOLTIP
: result
+= " TOOLTIP"; break;
154 case ROLE_TREE
: result
+= " TREE"; break;
155 case ROLE_TREE_GRID
: result
+= " TREE_GRID"; break;
156 case ROLE_TREE_ITEM
: result
+= " TREE_ITEM"; break;
157 case ROLE_UNKNOWN
: result
+= " UNKNOWN"; break;
158 case ROLE_VALUE_INDICATOR
: result
+= " VALUE_INDICATOR"; break;
159 case ROLE_WEBCORE_LINK
: result
+= " WEBCORE_LINK"; break;
160 case ROLE_WEB_AREA
: result
+= " WEB_AREA"; break;
161 case ROLE_WINDOW
: result
+= " WINDOW"; break;
166 if (state
& (1 << STATE_BUSY
))
168 if (state
& (1 << STATE_CHECKED
))
169 result
+= " CHECKED";
170 if (state
& (1 << STATE_COLLAPSED
))
171 result
+= " COLLAPSED";
172 if (state
& (1 << STATE_EXPANDED
))
173 result
+= " EXPANDED";
174 if (state
& (1 << STATE_FOCUSABLE
))
175 result
+= " FOCUSABLE";
176 if (state
& (1 << STATE_FOCUSED
))
177 result
+= " FOCUSED";
178 if (state
& (1 << STATE_HASPOPUP
))
179 result
+= " HASPOPUP";
180 if (state
& (1 << STATE_HOTTRACKED
))
181 result
+= " HOTTRACKED";
182 if (state
& (1 << STATE_INDETERMINATE
))
183 result
+= " INDETERMINATE";
184 if (state
& (1 << STATE_INVISIBLE
))
185 result
+= " INVISIBLE";
186 if (state
& (1 << STATE_LINKED
))
188 if (state
& (1 << STATE_MULTISELECTABLE
))
189 result
+= " MULTISELECTABLE";
190 if (state
& (1 << STATE_OFFSCREEN
))
191 result
+= " OFFSCREEN";
192 if (state
& (1 << STATE_PRESSED
))
193 result
+= " PRESSED";
194 if (state
& (1 << STATE_PROTECTED
))
195 result
+= " PROTECTED";
196 if (state
& (1 << STATE_READONLY
))
197 result
+= " READONLY";
198 if (state
& (1 << STATE_REQUIRED
))
199 result
+= " REQUIRED";
200 if (state
& (1 << STATE_SELECTABLE
))
201 result
+= " SELECTABLE";
202 if (state
& (1 << STATE_SELECTED
))
203 result
+= " SELECTED";
204 if (state
& (1 << STATE_TRAVERSED
))
205 result
+= " TRAVERSED";
206 if (state
& (1 << STATE_UNAVAILABLE
))
207 result
+= " UNAVAILABLE";
208 if (state
& (1 << STATE_VERTICAL
))
209 result
+= " VERTICAL";
210 if (state
& (1 << STATE_VISITED
))
211 result
+= " VISITED";
213 std::string tmp
= UTF16ToUTF8(name
);
214 RemoveChars(tmp
, "\n", &tmp
);
216 result
+= " name=" + tmp
;
218 tmp
= UTF16ToUTF8(value
);
219 RemoveChars(tmp
, "\n", &tmp
);
221 result
+= " value=" + tmp
;
223 result
+= " (" + IntToString(location
.x()) + ", " +
224 IntToString(location
.y()) + ")-(" +
225 IntToString(location
.width()) + ", " +
226 IntToString(location
.height()) + ")";
228 for (std::map
<IntAttribute
, int32
>::const_iterator iter
=
229 int_attributes
.begin();
230 iter
!= int_attributes
.end();
232 std::string value
= IntToString(iter
->second
);
233 switch (iter
->first
) {
235 result
+= " scroll_x=" + value
;
237 case ATTR_SCROLL_X_MIN
:
238 result
+= " scroll_x_min=" + value
;
240 case ATTR_SCROLL_X_MAX
:
241 result
+= " scroll_x_max=" + value
;
244 result
+= " scroll_y=" + value
;
246 case ATTR_SCROLL_Y_MIN
:
247 result
+= " scroll_y_min=" + value
;
249 case ATTR_SCROLL_Y_MAX
:
250 result
+= " scroll_y_max=" + value
;
252 case ATTR_HIERARCHICAL_LEVEL
:
253 result
+= " level=" + value
;
255 case ATTR_TEXT_SEL_START
:
256 result
+= " sel_start=" + value
;
258 case ATTR_TEXT_SEL_END
:
259 result
+= " sel_end=" + value
;
261 case ATTR_TABLE_ROW_COUNT
:
262 result
+= " rows=" + value
;
264 case ATTR_TABLE_COLUMN_COUNT
:
265 result
+= " cols=" + value
;
267 case ATTR_TABLE_CELL_COLUMN_INDEX
:
268 result
+= " col=" + value
;
270 case ATTR_TABLE_CELL_ROW_INDEX
:
271 result
+= " row=" + value
;
273 case ATTR_TABLE_CELL_COLUMN_SPAN
:
274 result
+= " colspan=" + value
;
276 case ATTR_TABLE_CELL_ROW_SPAN
:
277 result
+= " rowspan=" + value
;
279 case ATTR_TITLE_UI_ELEMENT
:
280 result
+= " title_elem=" + value
;
285 for (std::map
<StringAttribute
, string16
>::const_iterator iter
=
286 string_attributes
.begin();
287 iter
!= string_attributes
.end();
289 std::string value
= UTF16ToUTF8(iter
->second
);
290 switch (iter
->first
) {
292 result
+= " doc_url=" + value
;
295 result
+= " doc_title=" + value
;
297 case ATTR_DOC_MIMETYPE
:
298 result
+= " doc_mimetype=" + value
;
300 case ATTR_DOC_DOCTYPE
:
301 result
+= " doc_doctype=" + value
;
303 case ATTR_ACCESS_KEY
:
304 result
+= " access_key=" + value
;
307 result
+= " action=" + value
;
309 case ATTR_DESCRIPTION
:
310 result
+= " description=" + value
;
313 result
+= " display=" + value
;
316 result
+= " help=" + value
;
319 result
+= " html_tag=" + value
;
321 case ATTR_LIVE_RELEVANT
:
322 result
+= " relevant=" + value
;
324 case ATTR_LIVE_STATUS
:
325 result
+= " live=" + value
;
327 case ATTR_CONTAINER_LIVE_RELEVANT
:
328 result
+= " container_relevant=" + value
;
330 case ATTR_CONTAINER_LIVE_STATUS
:
331 result
+= " container_live=" + value
;
334 result
+= " role=" + value
;
337 result
+= " shortcut=" + value
;
340 result
+= " url=" + value
;
345 for (std::map
<FloatAttribute
, float>::const_iterator iter
=
346 float_attributes
.begin();
347 iter
!= float_attributes
.end();
349 std::string value
= DoubleToString(iter
->second
);
350 switch (iter
->first
) {
351 case ATTR_DOC_LOADING_PROGRESS
:
352 result
+= " doc_progress=" + value
;
354 case ATTR_VALUE_FOR_RANGE
:
355 result
+= " value_for_range=" + value
;
357 case ATTR_MAX_VALUE_FOR_RANGE
:
358 result
+= " max_value=" + value
;
360 case ATTR_MIN_VALUE_FOR_RANGE
:
361 result
+= " min_value=" + value
;
366 for (std::map
<BoolAttribute
, bool>::const_iterator iter
=
367 bool_attributes
.begin();
368 iter
!= bool_attributes
.end();
370 std::string value
= iter
->second
? "true" : "false";
371 switch (iter
->first
) {
372 case ATTR_DOC_LOADED
:
373 result
+= " doc_loaded=" + value
;
375 case ATTR_BUTTON_MIXED
:
376 result
+= " mixed=" + value
;
378 case ATTR_LIVE_ATOMIC
:
379 result
+= " atomic=" + value
;
382 result
+= " busy=" + value
;
384 case ATTR_CONTAINER_LIVE_ATOMIC
:
385 result
+= " container_atomic=" + value
;
387 case ATTR_CONTAINER_LIVE_BUSY
:
388 result
+= " container_busy=" + value
;
390 case ATTR_ARIA_READONLY
:
391 result
+= " aria_readonly=" + value
;
393 case ATTR_CAN_SET_VALUE
:
394 result
+= " can_set_value=" + value
;
399 if (!children
.empty())
400 result
+= " children=" + IntToString(children
.size());
402 if (!indirect_child_ids
.empty())
403 result
+= " indirect_child_ids=" + IntVectorToString(indirect_child_ids
);
405 if (!line_breaks
.empty())
406 result
+= " line_breaks=" + IntVectorToString(line_breaks
);
408 if (!cell_ids
.empty())
409 result
+= " cell_ids=" + IntVectorToString(cell_ids
);
414 for (size_t i
= 0; i
< children
.size(); ++i
)
415 result
+= children
[i
].DebugString(true);
421 #endif // ifndef NDEBUG
423 } // namespace content