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

Side by Side Diff: ui/accessibility/ax_node_data.cc

Issue 2873373005: Add custom action support (Closed)
Patch Set: Migrate to DataObjectBuilder. Created 3 years, 6 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
« no previous file with comments | « ui/accessibility/ax_node_data.h ('k') | ui/accessibility/ax_tree.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 "ui/accessibility/ax_node_data.h" 5 #include "ui/accessibility/ax_node_data.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 std::string IntVectorToString(const std::vector<int>& items) { 55 std::string IntVectorToString(const std::vector<int>& items) {
56 std::string str; 56 std::string str;
57 for (size_t i = 0; i < items.size(); ++i) { 57 for (size_t i = 0; i < items.size(); ++i) {
58 if (i > 0) 58 if (i > 0)
59 str += ","; 59 str += ",";
60 str += IntToString(items[i]); 60 str += IntToString(items[i]);
61 } 61 }
62 return str; 62 return str;
63 } 63 }
64 64
65 std::string StringVectorToString(const std::vector<std::string>& items) {
66 std::string str;
67 for (size_t i = 0; i < items.size(); ++i) {
68 if (i > 0)
69 str += ",";
70 str += items[i];
71 }
72 return str;
73 }
74
65 // Predicate that returns true if the first value of a pair is |first|. 75 // Predicate that returns true if the first value of a pair is |first|.
66 template<typename FirstType, typename SecondType> 76 template<typename FirstType, typename SecondType>
67 struct FirstIs { 77 struct FirstIs {
68 FirstIs(FirstType first) 78 FirstIs(FirstType first)
69 : first_(first) {} 79 : first_(first) {}
70 bool operator()(std::pair<FirstType, SecondType> const& p) { 80 bool operator()(std::pair<FirstType, SecondType> const& p) {
71 return p.first == first_; 81 return p.first == first_;
72 } 82 }
73 FirstType first_; 83 FirstType first_;
74 }; 84 };
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // a node id attribute or not. 181 // a node id attribute or not.
172 case AX_INT_LIST_ATTRIBUTE_NONE: 182 case AX_INT_LIST_ATTRIBUTE_NONE:
173 case AX_ATTR_LINE_BREAKS: 183 case AX_ATTR_LINE_BREAKS:
174 case AX_ATTR_MARKER_TYPES: 184 case AX_ATTR_MARKER_TYPES:
175 case AX_ATTR_MARKER_STARTS: 185 case AX_ATTR_MARKER_STARTS:
176 case AX_ATTR_MARKER_ENDS: 186 case AX_ATTR_MARKER_ENDS:
177 case AX_ATTR_CHARACTER_OFFSETS: 187 case AX_ATTR_CHARACTER_OFFSETS:
178 case AX_ATTR_CACHED_LINE_STARTS: 188 case AX_ATTR_CACHED_LINE_STARTS:
179 case AX_ATTR_WORD_STARTS: 189 case AX_ATTR_WORD_STARTS:
180 case AX_ATTR_WORD_ENDS: 190 case AX_ATTR_WORD_ENDS:
191 case AX_ATTR_CUSTOM_ACTION_IDS:
181 return false; 192 return false;
182 } 193 }
183 194
184 NOTREACHED(); 195 NOTREACHED();
185 return false; 196 return false;
186 } 197 }
187 198
188 AXNodeData::AXNodeData() 199 AXNodeData::AXNodeData()
189 : id(-1), 200 : id(-1),
190 role(AX_ROLE_UNKNOWN), 201 role(AX_ROLE_UNKNOWN),
191 state(AX_STATE_NONE), 202 state(AX_STATE_NONE),
192 actions(AX_ACTION_NONE), 203 actions(AX_ACTION_NONE),
193 offset_container_id(-1) {} 204 offset_container_id(-1) {}
194 205
195 AXNodeData::~AXNodeData() { 206 AXNodeData::~AXNodeData() {
196 } 207 }
197 208
198 AXNodeData::AXNodeData(const AXNodeData& other) { 209 AXNodeData::AXNodeData(const AXNodeData& other) {
199 id = other.id; 210 id = other.id;
200 role = other.role; 211 role = other.role;
201 state = other.state; 212 state = other.state;
202 actions = other.actions; 213 actions = other.actions;
203 string_attributes = other.string_attributes; 214 string_attributes = other.string_attributes;
204 int_attributes = other.int_attributes; 215 int_attributes = other.int_attributes;
205 float_attributes = other.float_attributes; 216 float_attributes = other.float_attributes;
206 bool_attributes = other.bool_attributes; 217 bool_attributes = other.bool_attributes;
207 intlist_attributes = other.intlist_attributes; 218 intlist_attributes = other.intlist_attributes;
219 stringlist_attributes = other.stringlist_attributes;
208 html_attributes = other.html_attributes; 220 html_attributes = other.html_attributes;
209 child_ids = other.child_ids; 221 child_ids = other.child_ids;
210 location = other.location; 222 location = other.location;
211 offset_container_id = other.offset_container_id; 223 offset_container_id = other.offset_container_id;
212 if (other.transform) 224 if (other.transform)
213 transform.reset(new gfx::Transform(*other.transform)); 225 transform.reset(new gfx::Transform(*other.transform));
214 } 226 }
215 227
216 AXNodeData& AXNodeData::operator=(AXNodeData other) { 228 AXNodeData& AXNodeData::operator=(AXNodeData other) {
217 id = other.id; 229 id = other.id;
218 role = other.role; 230 role = other.role;
219 state = other.state; 231 state = other.state;
220 actions = other.actions; 232 actions = other.actions;
221 string_attributes = other.string_attributes; 233 string_attributes = other.string_attributes;
222 int_attributes = other.int_attributes; 234 int_attributes = other.int_attributes;
223 float_attributes = other.float_attributes; 235 float_attributes = other.float_attributes;
224 bool_attributes = other.bool_attributes; 236 bool_attributes = other.bool_attributes;
225 intlist_attributes = other.intlist_attributes; 237 intlist_attributes = other.intlist_attributes;
238 stringlist_attributes = other.stringlist_attributes;
226 html_attributes = other.html_attributes; 239 html_attributes = other.html_attributes;
227 child_ids = other.child_ids; 240 child_ids = other.child_ids;
228 location = other.location; 241 location = other.location;
229 offset_container_id = other.offset_container_id; 242 offset_container_id = other.offset_container_id;
230 if (other.transform) 243 if (other.transform)
231 transform.reset(new gfx::Transform(*other.transform)); 244 transform.reset(new gfx::Transform(*other.transform));
232 else 245 else
233 transform.reset(nullptr); 246 transform.reset(nullptr);
234 return *this; 247 return *this;
235 } 248 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 std::vector<int32_t>* value) const { 375 std::vector<int32_t>* value) const {
363 auto iter = FindInVectorOfPairs(attribute, intlist_attributes); 376 auto iter = FindInVectorOfPairs(attribute, intlist_attributes);
364 if (iter != intlist_attributes.end()) { 377 if (iter != intlist_attributes.end()) {
365 *value = iter->second; 378 *value = iter->second;
366 return true; 379 return true;
367 } 380 }
368 381
369 return false; 382 return false;
370 } 383 }
371 384
385 bool AXNodeData::HasStringListAttribute(AXStringListAttribute attribute) const {
386 auto iter = FindInVectorOfPairs(attribute, stringlist_attributes);
387 return iter != stringlist_attributes.end();
388 }
389
390 const std::vector<std::string>& AXNodeData::GetStringListAttribute(
391 AXStringListAttribute attribute) const {
392 CR_DEFINE_STATIC_LOCAL(std::vector<std::string>, empty_vector, ());
393 auto iter = FindInVectorOfPairs(attribute, stringlist_attributes);
394 if (iter != stringlist_attributes.end())
395 return iter->second;
396 return empty_vector;
397 }
398
399 bool AXNodeData::GetStringListAttribute(AXStringListAttribute attribute,
400 std::vector<std::string>* value) const {
401 auto iter = FindInVectorOfPairs(attribute, stringlist_attributes);
402 if (iter != stringlist_attributes.end()) {
403 *value = iter->second;
404 return true;
405 }
406
407 return false;
408 }
409
372 bool AXNodeData::GetHtmlAttribute( 410 bool AXNodeData::GetHtmlAttribute(
373 const char* html_attr, std::string* value) const { 411 const char* html_attr, std::string* value) const {
374 for (size_t i = 0; i < html_attributes.size(); ++i) { 412 for (size_t i = 0; i < html_attributes.size(); ++i) {
375 const std::string& attr = html_attributes[i].first; 413 const std::string& attr = html_attributes[i].first;
376 if (base::LowerCaseEqualsASCII(attr, html_attr)) { 414 if (base::LowerCaseEqualsASCII(attr, html_attr)) {
377 *value = html_attributes[i].second; 415 *value = html_attributes[i].second;
378 return true; 416 return true;
379 } 417 }
380 } 418 }
381 419
(...skipping 27 matching lines...) Expand all
409 void AXNodeData::AddBoolAttribute( 447 void AXNodeData::AddBoolAttribute(
410 AXBoolAttribute attribute, bool value) { 448 AXBoolAttribute attribute, bool value) {
411 bool_attributes.push_back(std::make_pair(attribute, value)); 449 bool_attributes.push_back(std::make_pair(attribute, value));
412 } 450 }
413 451
414 void AXNodeData::AddIntListAttribute(AXIntListAttribute attribute, 452 void AXNodeData::AddIntListAttribute(AXIntListAttribute attribute,
415 const std::vector<int32_t>& value) { 453 const std::vector<int32_t>& value) {
416 intlist_attributes.push_back(std::make_pair(attribute, value)); 454 intlist_attributes.push_back(std::make_pair(attribute, value));
417 } 455 }
418 456
457 void AXNodeData::AddStringListAttribute(AXStringListAttribute attribute,
458 const std::vector<std::string>& value) {
459 stringlist_attributes.push_back(std::make_pair(attribute, value));
460 }
461
419 void AXNodeData::SetName(const std::string& name) { 462 void AXNodeData::SetName(const std::string& name) {
420 for (size_t i = 0; i < string_attributes.size(); ++i) { 463 for (size_t i = 0; i < string_attributes.size(); ++i) {
421 if (string_attributes[i].first == AX_ATTR_NAME) { 464 if (string_attributes[i].first == AX_ATTR_NAME) {
422 string_attributes[i].second = name; 465 string_attributes[i].second = name;
423 return; 466 return;
424 } 467 }
425 } 468 }
426 469
427 string_attributes.push_back(std::make_pair(AX_ATTR_NAME, name)); 470 string_attributes.push_back(std::make_pair(AX_ATTR_NAME, name));
428 } 471 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 // Note: all of the attributes are included here explicitly, rather than 511 // Note: all of the attributes are included here explicitly, rather than
469 // using "default:", so that it's a compiler error to add a new action 512 // using "default:", so that it's a compiler error to add a new action
470 // without explicitly considering whether there are mutually exclusive 513 // without explicitly considering whether there are mutually exclusive
471 // actions that can be performed on a UI control at the same time. 514 // actions that can be performed on a UI control at the same time.
472 case AX_ACTION_BLUR: 515 case AX_ACTION_BLUR:
473 case AX_ACTION_FOCUS: { 516 case AX_ACTION_FOCUS: {
474 AXAction excluded_action = 517 AXAction excluded_action =
475 (action_enum == AX_ACTION_BLUR) ? AX_ACTION_FOCUS : AX_ACTION_BLUR; 518 (action_enum == AX_ACTION_BLUR) ? AX_ACTION_FOCUS : AX_ACTION_BLUR;
476 DCHECK(HasAction(excluded_action)); 519 DCHECK(HasAction(excluded_action));
477 } break; 520 } break;
521 case AX_ACTION_CUSTOM_ACTION:
478 case AX_ACTION_DECREMENT: 522 case AX_ACTION_DECREMENT:
479 case AX_ACTION_DO_DEFAULT: 523 case AX_ACTION_DO_DEFAULT:
480 case AX_ACTION_GET_IMAGE_DATA: 524 case AX_ACTION_GET_IMAGE_DATA:
481 case AX_ACTION_HIT_TEST: 525 case AX_ACTION_HIT_TEST:
482 case AX_ACTION_INCREMENT: 526 case AX_ACTION_INCREMENT:
483 case AX_ACTION_REPLACE_SELECTED_TEXT: 527 case AX_ACTION_REPLACE_SELECTED_TEXT:
484 case AX_ACTION_SCROLL_TO_MAKE_VISIBLE: 528 case AX_ACTION_SCROLL_TO_MAKE_VISIBLE:
485 case AX_ACTION_SCROLL_TO_POINT: 529 case AX_ACTION_SCROLL_TO_POINT:
486 case AX_ACTION_SET_ACCESSIBILITY_FOCUS: 530 case AX_ACTION_SET_ACCESSIBILITY_FOCUS:
487 case AX_ACTION_SET_SCROLL_OFFSET: 531 case AX_ACTION_SET_SCROLL_OFFSET:
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 break; 995 break;
952 case AX_ATTR_CACHED_LINE_STARTS: 996 case AX_ATTR_CACHED_LINE_STARTS:
953 result += " cached_line_start_offsets=" + IntVectorToString(values); 997 result += " cached_line_start_offsets=" + IntVectorToString(values);
954 break; 998 break;
955 case AX_ATTR_WORD_STARTS: 999 case AX_ATTR_WORD_STARTS:
956 result += " word_starts=" + IntVectorToString(values); 1000 result += " word_starts=" + IntVectorToString(values);
957 break; 1001 break;
958 case AX_ATTR_WORD_ENDS: 1002 case AX_ATTR_WORD_ENDS:
959 result += " word_ends=" + IntVectorToString(values); 1003 result += " word_ends=" + IntVectorToString(values);
960 break; 1004 break;
1005 case AX_ATTR_CUSTOM_ACTION_IDS:
1006 result += " custom_action_ids=" + IntVectorToString(values);
1007 break;
961 case AX_INT_LIST_ATTRIBUTE_NONE: 1008 case AX_INT_LIST_ATTRIBUTE_NONE:
962 break; 1009 break;
963 } 1010 }
964 } 1011 }
965 1012
1013 for (size_t i = 0; i < stringlist_attributes.size(); ++i) {
1014 const std::vector<std::string>& values = stringlist_attributes[i].second;
1015 switch (stringlist_attributes[i].first) {
1016 case AX_ATTR_CUSTOM_ACTION_DESCRIPTIONS:
1017 result +=
1018 " custom_action_descriptions: " + StringVectorToString(values);
1019 break;
1020 case AX_STRING_LIST_ATTRIBUTE_NONE:
1021 break;
1022 }
1023 }
1024
966 result += " actions=" + ActionsBitfieldToString(actions); 1025 result += " actions=" + ActionsBitfieldToString(actions);
967 1026
968 if (!child_ids.empty()) 1027 if (!child_ids.empty())
969 result += " child_ids=" + IntVectorToString(child_ids); 1028 result += " child_ids=" + IntVectorToString(child_ids);
970 1029
971 return result; 1030 return result;
972 } 1031 }
973 1032
974 } // namespace ui 1033 } // namespace ui
OLDNEW
« no previous file with comments | « ui/accessibility/ax_node_data.h ('k') | ui/accessibility/ax_tree.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698