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

Side by Side Diff: chrome/browser/chromeos/arc/accessibility/ax_tree_source_arc.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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "chrome/browser/chromeos/arc/accessibility/ax_tree_source_arc.h" 5 #include "chrome/browser/chromeos/arc/accessibility/ax_tree_source_arc.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "chrome/browser/extensions/api/automation_internal/automation_event_rou ter.h" 9 #include "chrome/browser/extensions/api/automation_internal/automation_event_rou ter.h"
10 #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h" 10 #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 return false; 108 return false;
109 109
110 auto it = node->string_properties->find(prop); 110 auto it = node->string_properties->find(prop);
111 if (it == node->string_properties->end()) 111 if (it == node->string_properties->end())
112 return false; 112 return false;
113 113
114 *out_value = it->second; 114 *out_value = it->second;
115 return true; 115 return true;
116 } 116 }
117 117
118 bool GetIntListProperty(arc::mojom::AccessibilityNodeInfoData* node,
119 arc::mojom::AccessibilityIntListProperty prop,
120 std::vector<int32_t>* out_value) {
121 if (!node->int_list_properties)
122 return false;
123
124 auto it = node->int_list_properties->find(prop);
125 if (it == node->int_list_properties->end())
126 return false;
127
128 *out_value = it->second;
129 return true;
130 }
131
132 bool GetStringListProperty(arc::mojom::AccessibilityNodeInfoData* node,
133 arc::mojom::AccessibilityStringListProperty prop,
134 std::vector<std::string>* out_value) {
135 if (!node->string_list_properties)
136 return false;
137
138 auto it = node->string_list_properties->find(prop);
139 if (it == node->string_list_properties->end())
140 return false;
141
142 *out_value = it->second;
143 return true;
144 }
145
118 void PopulateAXRole(arc::mojom::AccessibilityNodeInfoData* node, 146 void PopulateAXRole(arc::mojom::AccessibilityNodeInfoData* node,
119 ui::AXNodeData* out_data) { 147 ui::AXNodeData* out_data) {
120 std::string class_name; 148 std::string class_name;
121 GetStringProperty(node, arc::mojom::AccessibilityStringProperty::CLASS_NAME, 149 GetStringProperty(node, arc::mojom::AccessibilityStringProperty::CLASS_NAME,
122 &class_name); 150 &class_name);
123 151
124 #define MAP_ROLE(android_class_name, chrome_role) \ 152 #define MAP_ROLE(android_class_name, chrome_role) \
125 if (class_name == android_class_name) { \ 153 if (class_name == android_class_name) { \
126 out_data->role = chrome_role; \ 154 out_data->role = chrome_role; \
127 return; \ 155 return; \
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 mojom::AccessibilityNodeInfoData* AXTreeSourceArc::GetNull() const { 385 mojom::AccessibilityNodeInfoData* AXTreeSourceArc::GetNull() const {
358 return nullptr; 386 return nullptr;
359 } 387 }
360 388
361 void AXTreeSourceArc::SerializeNode(mojom::AccessibilityNodeInfoData* node, 389 void AXTreeSourceArc::SerializeNode(mojom::AccessibilityNodeInfoData* node,
362 ui::AXNodeData* out_data) const { 390 ui::AXNodeData* out_data) const {
363 if (!node) 391 if (!node)
364 return; 392 return;
365 out_data->id = node->id; 393 out_data->id = node->id;
366 394
395 using AXIntListProperty = arc::mojom::AccessibilityIntListProperty;
367 using AXIntProperty = arc::mojom::AccessibilityIntProperty; 396 using AXIntProperty = arc::mojom::AccessibilityIntProperty;
397 using AXStringListProperty = arc::mojom::AccessibilityStringListProperty;
368 using AXStringProperty = arc::mojom::AccessibilityStringProperty; 398 using AXStringProperty = arc::mojom::AccessibilityStringProperty;
399
369 std::string text; 400 std::string text;
370 if (GetStringProperty(node, AXStringProperty::TEXT, &text)) 401 if (GetStringProperty(node, AXStringProperty::TEXT, &text))
371 out_data->SetName(text); 402 out_data->SetName(text);
372 else if (GetStringProperty(node, AXStringProperty::CONTENT_DESCRIPTION, 403 else if (GetStringProperty(node, AXStringProperty::CONTENT_DESCRIPTION,
373 &text)) 404 &text))
374 out_data->SetName(text); 405 out_data->SetName(text);
375 406
376 int32_t id = node->id; 407 int32_t id = node->id;
377 if (id == root_id_) 408 if (id == root_id_)
378 out_data->role = ui::AX_ROLE_ROOT_WEB_AREA; 409 out_data->role = ui::AX_ROLE_ROOT_WEB_AREA;
(...skipping 11 matching lines...) Expand all
390 out_data->AddStringAttribute(ui::AX_ATTR_VALUE, text); 421 out_data->AddStringAttribute(ui::AX_ATTR_VALUE, text);
391 422
392 // Integer properties. 423 // Integer properties.
393 int32_t val; 424 int32_t val;
394 if (GetIntProperty(node, AXIntProperty::TEXT_SELECTION_START, &val) && 425 if (GetIntProperty(node, AXIntProperty::TEXT_SELECTION_START, &val) &&
395 val >= 0) 426 val >= 0)
396 out_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_START, val); 427 out_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_START, val);
397 428
398 if (GetIntProperty(node, AXIntProperty::TEXT_SELECTION_END, &val) && val >= 0) 429 if (GetIntProperty(node, AXIntProperty::TEXT_SELECTION_END, &val) && val >= 0)
399 out_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_END, val); 430 out_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_END, val);
431
432 // Custom actions.
433 std::vector<int32_t> custom_action_ids;
434 if (GetIntListProperty(node, AXIntListProperty::CUSTOM_ACTION_IDS,
435 &custom_action_ids)) {
436 std::vector<std::string> custom_action_descriptions;
437
438 CHECK(GetStringListProperty(
439 node, AXStringListProperty::CUSTOM_ACTION_DESCRIPTIONS,
440 &custom_action_descriptions));
441 CHECK(!custom_action_ids.empty());
442 CHECK_EQ(custom_action_ids.size(), custom_action_descriptions.size());
443
444 out_data->AddAction(ui::AX_ACTION_CUSTOM_ACTION);
445 out_data->AddIntListAttribute(ui::AX_ATTR_CUSTOM_ACTION_IDS,
446 custom_action_ids);
447 out_data->AddStringListAttribute(ui::AX_ATTR_CUSTOM_ACTION_DESCRIPTIONS,
448 custom_action_descriptions);
449 }
400 } 450 }
401 451
402 void AXTreeSourceArc::PerformAction(const ui::AXActionData& data) { 452 void AXTreeSourceArc::PerformAction(const ui::AXActionData& data) {
403 delegate_->OnAction(data); 453 delegate_->OnAction(data);
404 } 454 }
405 455
406 void AXTreeSourceArc::Reset() { 456 void AXTreeSourceArc::Reset() {
407 tree_map_.clear(); 457 tree_map_.clear();
408 parent_map_.clear(); 458 parent_map_.clear();
409 current_tree_serializer_.reset(new AXTreeArcSerializer(this)); 459 current_tree_serializer_.reset(new AXTreeArcSerializer(this));
410 root_id_ = -1; 460 root_id_ = -1;
411 focused_node_id_ = -1; 461 focused_node_id_ = -1;
412 extensions::AutomationEventRouter* router = 462 extensions::AutomationEventRouter* router =
413 extensions::AutomationEventRouter::GetInstance(); 463 extensions::AutomationEventRouter::GetInstance();
414 if (!router) 464 if (!router)
415 return; 465 return;
416 466
417 router->DispatchTreeDestroyedEvent(tree_id(), nullptr); 467 router->DispatchTreeDestroyedEvent(tree_id(), nullptr);
418 } 468 }
419 469
420 } // namespace arc 470 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698