Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(995)

Side by Side Diff: content/browser/accessibility/accessibility_tree_formatter_win.cc

Issue 13479003: Modify AccessibilityTreeFormatter to build up an internal representation of the tree (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Those pesky string types Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/accessibility/accessibility_tree_formatter.h" 5 #include "content/browser/accessibility/accessibility_tree_formatter.h"
6 6
7 #include <oleacc.h> 7 #include <oleacc.h>
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "content/browser/accessibility/accessibility_tree_formatter_utils_win.h " 15 #include "content/browser/accessibility/accessibility_tree_formatter_utils_win.h "
16 #include "content/browser/accessibility/browser_accessibility_manager.h" 16 #include "content/browser/accessibility/browser_accessibility_manager.h"
17 #include "content/browser/accessibility/browser_accessibility_win.h" 17 #include "content/browser/accessibility/browser_accessibility_win.h"
18 #include "content/common/accessibility_node_data.h" 18 #include "content/common/accessibility_node_data.h"
19 #include "third_party/iaccessible2/ia2_api_all.h" 19 #include "third_party/iaccessible2/ia2_api_all.h"
20 #include "ui/base/win/atl_module.h" 20 #include "ui/base/win/atl_module.h"
21 21
22 using base::StringPrintf;
23
22 namespace content { 24 namespace content {
23 25
26 const char* ALL_ATTRIBUTES[] = {
27 "name",
28 "value",
29 "states",
30 "attributes",
31 "role_name",
32 "currentValue",
33 "minimumValue",
34 "maximumValue",
35 "description",
36 "default_action",
37 "keyboard_shortcut",
38 "location",
39 "size",
40 "index_in_parent",
41 "n_relations",
42 "group_level",
43 "similar_items_in_group",
44 "position_in_group",
45 "table_rows",
46 "table_columns",
47 "row_index",
48 "column_index",
49 "n_characters",
50 "caret_offset",
51 "n_selections",
52 "selection_start",
53 "selection_end"
54 };
55
24 void AccessibilityTreeFormatter::Initialize() { 56 void AccessibilityTreeFormatter::Initialize() {
25 ui::win::CreateATLModuleIfNeeded(); 57 ui::win::CreateATLModuleIfNeeded();
26 } 58 }
27 59
28 string16 AccessibilityTreeFormatter::ToString( 60 void AccessibilityTreeFormatter::AddProperties(
29 BrowserAccessibility* node, char* prefix) { 61 const BrowserAccessibility& node, DictionaryValue* dict) {
30 BrowserAccessibilityWin* acc_obj = node->ToBrowserAccessibilityWin(); 62 BrowserAccessibilityWin* acc_obj =
31 63 const_cast<BrowserAccessibility*>(&node)->ToBrowserAccessibilityWin();
32 // Get the computed name. 64
33 VARIANT variant_self; 65 VARIANT variant_self;
34 variant_self.vt = VT_I4; 66 variant_self.vt = VT_I4;
35 variant_self.lVal = CHILDID_SELF; 67 variant_self.lVal = CHILDID_SELF;
68
69 dict->SetString("role", IAccessible2RoleToString(acc_obj->ia2_role()));
70
36 CComBSTR msaa_variant; 71 CComBSTR msaa_variant;
37 HRESULT hresult = acc_obj->get_accName(variant_self, &msaa_variant); 72 HRESULT hresult = acc_obj->get_accName(variant_self, &msaa_variant);
38 string16 name; 73 if (hresult == S_OK)
39 if (S_OK == hresult) 74 dict->SetString("name", msaa_variant.m_str);
40 name = msaa_variant.m_str;
41
42 hresult = acc_obj->get_accValue(variant_self, &msaa_variant); 75 hresult = acc_obj->get_accValue(variant_self, &msaa_variant);
43 string16 value; 76 if (hresult == S_OK)
44 if (S_OK == hresult) 77 dict->SetString("value", msaa_variant.m_str);
45 value = msaa_variant.m_str; 78
46
47 hresult = acc_obj->get_accDescription(variant_self, &msaa_variant);
48 string16 description;
49 if (S_OK == hresult)
50 description = msaa_variant.m_str;
51
52 hresult = acc_obj->get_accHelp(variant_self, &msaa_variant);
53 string16 help;
54 if (S_OK == hresult)
55 help = msaa_variant.m_str;
56
57 hresult = acc_obj->get_accDefaultAction(variant_self, &msaa_variant);
58 string16 default_action;
59 if (S_OK == hresult)
60 default_action = msaa_variant.m_str;
61
62 hresult = acc_obj->get_accKeyboardShortcut(variant_self, &msaa_variant);
63 string16 keyboard_shortcut;
64 if (S_OK == hresult)
65 keyboard_shortcut = msaa_variant.m_str;
66
67 // Get state strings.
68 std::vector<string16> state_strings; 79 std::vector<string16> state_strings;
69 IAccessibleStateToStringVector(acc_obj->ia_state(), &state_strings); 80 IAccessibleStateToStringVector(acc_obj->ia_state(), &state_strings);
70 IAccessible2StateToStringVector(acc_obj->ia2_state(), &state_strings); 81 IAccessible2StateToStringVector(acc_obj->ia2_state(), &state_strings);
71 82 ListValue* states = new ListValue;
72 // Get the attributes.
73 const std::vector<string16>& ia2_attributes = acc_obj->ia2_attributes();
74
75 // Build the line.
76 StartLine();
77 Add(true, IAccessible2RoleToString(acc_obj->ia2_role()));
78 Add(true, L"name='" + name + L"'");
79 Add(false, L"value='" + value + L"'");
80 for (std::vector<string16>::const_iterator it = state_strings.begin(); 83 for (std::vector<string16>::const_iterator it = state_strings.begin();
81 it != state_strings.end(); 84 it != state_strings.end();
82 ++it) { 85 ++it) {
83 Add(false, *it); 86 states->AppendString(UTF16ToUTF8(*it));
84 } 87 }
88 dict->Set("states", states);
89
90 const std::vector<string16>& ia2_attributes = acc_obj->ia2_attributes();
91 ListValue* attributes = new ListValue;
85 for (std::vector<string16>::const_iterator it = ia2_attributes.begin(); 92 for (std::vector<string16>::const_iterator it = ia2_attributes.begin();
86 it != ia2_attributes.end(); 93 it != ia2_attributes.end();
87 ++it) { 94 ++it) {
88 Add(false, *it); 95 attributes->AppendString(UTF16ToUTF8(*it));
89 } 96 }
90 Add(false, L"role_name='" + acc_obj->role_name() + L"'"); 97 dict->Set("attributes", attributes);
98
99 dict->SetString("role_name", acc_obj->role_name());
100
91 VARIANT currentValue; 101 VARIANT currentValue;
92 if (acc_obj->get_currentValue(&currentValue) == S_OK) 102 if (acc_obj->get_currentValue(&currentValue) == S_OK)
93 Add(false, base::StringPrintf(L"currentValue=%.2f", V_R8(&currentValue))); 103 dict->SetDouble("currentValue", V_R8(&currentValue));
104
94 VARIANT minimumValue; 105 VARIANT minimumValue;
95 if (acc_obj->get_minimumValue(&minimumValue) == S_OK) 106 if (acc_obj->get_minimumValue(&minimumValue) == S_OK)
96 Add(false, base::StringPrintf(L"minimumValue=%.2f", V_R8(&minimumValue))); 107 dict->SetDouble("minimumValue", V_R8(&minimumValue));
108
97 VARIANT maximumValue; 109 VARIANT maximumValue;
98 if (acc_obj->get_maximumValue(&maximumValue) == S_OK) 110 if (acc_obj->get_maximumValue(&maximumValue) == S_OK)
99 Add(false, base::StringPrintf(L"maximumValue=%.2f", V_R8(&maximumValue))); 111 dict->SetDouble("maximumValue", V_R8(&maximumValue));
100 Add(false, L"description='" + description + L"'"); 112
101 Add(false, L"default_action='" + default_action + L"'"); 113 hresult = acc_obj->get_accDescription(variant_self, &msaa_variant);
102 Add(false, L"keyboard_shortcut='" + keyboard_shortcut + L"'"); 114 if (hresult == S_OK)
103 BrowserAccessibility* root = node->manager()->GetRoot(); 115 dict->SetString("description", msaa_variant.m_str);
116
117 hresult = acc_obj->get_accDefaultAction(variant_self, &msaa_variant);
118 if (hresult == S_OK)
119 dict->SetString("default_action", msaa_variant.m_str);
120
121 hresult = acc_obj->get_accKeyboardShortcut(variant_self, &msaa_variant);
122 if (hresult == S_OK)
123 dict->SetString("keyboard_shortcut", msaa_variant.m_str);
124
125 hresult = acc_obj->get_accHelp(variant_self, &msaa_variant);
126 if (S_OK == hresult)
127 dict->SetString("help", msaa_variant.m_str);
128
129 BrowserAccessibility* root = node.manager()->GetRoot();
104 LONG left, top, width, height; 130 LONG left, top, width, height;
105 LONG root_left, root_top, root_width, root_height; 131 LONG root_left, root_top, root_width, root_height;
106 if (S_FALSE != acc_obj->accLocation( 132 if (acc_obj->accLocation(&left, &top, &width, &height, variant_self)
107 &left, &top, &width, &height, variant_self) && 133 != S_FALSE
108 S_FALSE != root->ToBrowserAccessibilityWin()->accLocation( 134 && root->ToBrowserAccessibilityWin()->accLocation(
109 &root_left, &root_top, &root_width, &root_height, variant_self)) { 135 &root_left, &root_top, &root_width, &root_height, variant_self)
110 Add(false, base::StringPrintf(L"location=(%d, %d)", 136 != S_FALSE) {
111 left - root_left, top - root_top)); 137 DictionaryValue* location = new DictionaryValue;
112 Add(false, base::StringPrintf(L"size=(%d, %d)", width, height)); 138 location->SetInteger("x", left - root_left);
113 } 139 location->SetInteger("y", top - root_top);
140 dict->Set("location", location);
141
142 DictionaryValue* size = new DictionaryValue;
143 size->SetInteger("width", width);
144 size->SetInteger("height", height);
145 dict->Set("size", size);
146 }
147
114 LONG index_in_parent; 148 LONG index_in_parent;
115 if (acc_obj->get_indexInParent(&index_in_parent) == S_OK) 149 if (acc_obj->get_indexInParent(&index_in_parent) == S_OK)
116 Add(false, base::StringPrintf(L"index_in_parent=%d", index_in_parent)); 150 dict->SetInteger("index_in_parent", index_in_parent);
151
117 LONG n_relations; 152 LONG n_relations;
118 if (acc_obj->get_nRelations(&n_relations) == S_OK) 153 if (acc_obj->get_nRelations(&n_relations) == S_OK)
119 Add(false, base::StringPrintf(L"n_relations=%d", n_relations)); 154 dict->SetInteger("n_relations", n_relations);
155
120 LONG group_level, similar_items_in_group, position_in_group; 156 LONG group_level, similar_items_in_group, position_in_group;
121 if (acc_obj->get_groupPosition(&group_level, 157 if (acc_obj->get_groupPosition(&group_level,
122 &similar_items_in_group, 158 &similar_items_in_group,
123 &position_in_group) == S_OK) { 159 &position_in_group) == S_OK) {
124 Add(false, base::StringPrintf(L"group_level=%d", group_level)); 160 dict->SetInteger("group_level", group_level);
125 Add(false, base::StringPrintf(L"similar_items_in_group=%d", 161 dict->SetInteger("similar_items_in_group", similar_items_in_group);
126 similar_items_in_group)); 162 dict->SetInteger("position_in_group", position_in_group);
127 Add(false, base::StringPrintf(L"position_in_group=%d", position_in_group));
128 } 163 }
129 LONG table_rows; 164 LONG table_rows;
130 if (acc_obj->get_nRows(&table_rows) == S_OK) 165 if (acc_obj->get_nRows(&table_rows) == S_OK)
131 Add(false, base::StringPrintf(L"table_rows=%d", table_rows)); 166 dict->SetInteger("table_rows", table_rows);
132 LONG table_columns; 167 LONG table_columns;
133 if (acc_obj->get_nRows(&table_columns) == S_OK) 168 if (acc_obj->get_nRows(&table_columns) == S_OK)
134 Add(false, base::StringPrintf(L"table_columns=%d", table_columns)); 169 dict->SetInteger("table_columns", table_columns);
135 LONG row_index; 170 LONG row_index;
136 if (acc_obj->get_rowIndex(&row_index) == S_OK) 171 if (acc_obj->get_rowIndex(&row_index) == S_OK)
137 Add(false, base::StringPrintf(L"row_index=%d", row_index)); 172 dict->SetInteger("row_index", row_index);
138 LONG column_index; 173 LONG column_index;
139 if (acc_obj->get_columnIndex(&column_index) == S_OK) 174 if (acc_obj->get_columnIndex(&column_index) == S_OK)
140 Add(false, base::StringPrintf(L"column_index=%d", column_index)); 175 dict->SetInteger("column_index", column_index);
141 LONG n_characters; 176 LONG n_characters;
142 if (acc_obj->get_nCharacters(&n_characters) == S_OK) 177 if (acc_obj->get_nCharacters(&n_characters) == S_OK)
143 Add(false, base::StringPrintf(L"n_characters=%d", n_characters)); 178 dict->SetInteger("n_characters", n_characters);
144 LONG caret_offset; 179 LONG caret_offset;
145 if (acc_obj->get_caretOffset(&caret_offset) == S_OK) 180 if (acc_obj->get_caretOffset(&caret_offset) == S_OK)
146 Add(false, base::StringPrintf(L"caret_offset=%d", caret_offset)); 181 dict->SetInteger("caret_offset", caret_offset);
147 LONG n_selections; 182 LONG n_selections;
148 if (acc_obj->get_nSelections(&n_selections) == S_OK) { 183 if (acc_obj->get_nSelections(&n_selections) == S_OK) {
149 Add(false, base::StringPrintf(L"n_selections=%d", n_selections)); 184 dict->SetInteger("n_selections", n_selections);
150 if (n_selections > 0) { 185 if (n_selections > 0) {
151 LONG start, end; 186 LONG start, end;
152 if (acc_obj->get_selection(0, &start, &end) == S_OK) { 187 if (acc_obj->get_selection(0, &start, &end) == S_OK) {
153 Add(false, base::StringPrintf(L"selection_start=%d", start)); 188 dict->SetInteger("selection_start", start);
154 Add(false, base::StringPrintf(L"selection_end=%d", end)); 189 dict->SetInteger("selection_end", end);
155 } 190 }
156 } 191 }
157 } 192 }
158
159 return UTF8ToUTF16(prefix) + FinishLine() + ASCIIToUTF16("\n");
160 } 193 }
161 194
195 string16 AccessibilityTreeFormatter::ToString(const DictionaryValue& dict,
196 const string16& indent) {
197 string16 line;
198
199 string16 role_value;
200 dict.GetString("role", &role_value);
201 WriteAttribute(true, UTF16ToUTF8(role_value), &line);
202
203 string16 name_value;
204 dict.GetString("name", &name_value);
205 WriteAttribute(true, base::StringPrintf(L"name='%ls'", name_value.c_str()),
206 &line);
207
208 for (int i = 0; i < arraysize(ALL_ATTRIBUTES); i++) {
209 const char* attribute_name = ALL_ATTRIBUTES[i];
210 const Value* value;
211 if (!dict.Get(attribute_name, &value))
212 continue;
213
214 switch (value->GetType()) {
215 case Value::TYPE_STRING: {
216 string16 string_value;
217 value->GetAsString(&string_value);
218 WriteAttribute(false,
219 StringPrintf(L"%ls='%ls'",
220 UTF8ToUTF16(attribute_name).c_str(),
221 string_value.c_str()),
222 &line);
223 break;
224 }
225 case Value::TYPE_INTEGER: {
226 int int_value;
227 value->GetAsInteger(&int_value);
228 WriteAttribute(false,
229 base::StringPrintf(L"%ls=%d",
230 UTF8ToUTF16(attribute_name).c_str(),
231 int_value),
232 &line);
233 break;
234 }
235 case Value::TYPE_DOUBLE: {
236 double double_value;
237 value->GetAsDouble(&double_value);
238 WriteAttribute(false,
239 base::StringPrintf(L"%ls=%.2f",
240 UTF8ToUTF16(attribute_name).c_str(),
241 double_value),
242 &line);
243 break;
244 }
245 case Value::TYPE_LIST: {
246 // Currently all list values are string and are written without
247 // attribute names.
248 const ListValue* list_value;
249 value->GetAsList(&list_value);
250 for (ListValue::const_iterator it = list_value->begin();
251 it != list_value->end();
252 ++it) {
253 string16 string_value;
254 if ((*it)->GetAsString(&string_value))
255 WriteAttribute(false, string_value, &line);
256 }
257 break;
258 }
259 case Value::TYPE_DICTIONARY: {
260 // Currently all dictionary values are coordinates.
dmazzoni 2013/04/15 04:47:48 Does this handle both position and size? I thought
aboxhall 2013/04/15 07:00:10 Oh, you're right! Not sure how I missed that. Fix
261 // Revisit this if that changes.
262 const DictionaryValue* dict_value;
263 value->GetAsDictionary(&dict_value);
264 WriteAttribute(false,
265 FormatCoordinates(attribute_name, "x", "y", *dict_value),
266 &line);
267 break;
268 }
269 default:
dmazzoni 2013/04/15 04:47:48 NOTREACHED()
aboxhall 2013/04/15 07:00:10 Done.
270 break;
271 }
272 }
273
274 return indent + line + ASCIIToUTF16("\n");
275 }
276
162 // static 277 // static
163 const base::FilePath::StringType 278 const base::FilePath::StringType
164 AccessibilityTreeFormatter::GetActualFileSuffix() { 279 AccessibilityTreeFormatter::GetActualFileSuffix() {
165 return FILE_PATH_LITERAL("-actual-win.txt"); 280 return FILE_PATH_LITERAL("-actual-win.txt");
166 } 281 }
167 282
168 // static 283 // static
169 const base::FilePath::StringType 284 const base::FilePath::StringType
170 AccessibilityTreeFormatter::GetExpectedFileSuffix() { 285 AccessibilityTreeFormatter::GetExpectedFileSuffix() {
171 return FILE_PATH_LITERAL("-expected-win.txt"); 286 return FILE_PATH_LITERAL("-expected-win.txt");
172 } 287 }
173 288
174 // static 289 // static
175 const std::string AccessibilityTreeFormatter::GetAllowEmptyString() { 290 const std::string AccessibilityTreeFormatter::GetAllowEmptyString() {
176 return "@WIN-ALLOW-EMPTY:"; 291 return "@WIN-ALLOW-EMPTY:";
177 } 292 }
178 293
179 // static 294 // static
180 const std::string AccessibilityTreeFormatter::GetAllowString() { 295 const std::string AccessibilityTreeFormatter::GetAllowString() {
181 return "@WIN-ALLOW:"; 296 return "@WIN-ALLOW:";
182 } 297 }
183 298
184 // static 299 // static
185 const std::string AccessibilityTreeFormatter::GetDenyString() { 300 const std::string AccessibilityTreeFormatter::GetDenyString() {
186 return "@WIN-DENY:"; 301 return "@WIN-DENY:";
187 } 302 }
188 303
189 } // namespace content 304 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/accessibility/accessibility_tree_formatter_mac.mm ('k') | content/test/data/accessibility/a-expected-mac.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698