OLD | NEW |
---|---|
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 if (!node->booleanProperties) | 76 if (!node->booleanProperties) |
77 return false; | 77 return false; |
78 | 78 |
79 auto it = node->booleanProperties->find(prop); | 79 auto it = node->booleanProperties->find(prop); |
80 if (it == node->booleanProperties->end()) | 80 if (it == node->booleanProperties->end()) |
81 return false; | 81 return false; |
82 | 82 |
83 return it->second; | 83 return it->second; |
84 } | 84 } |
85 | 85 |
86 bool GetIntProperty(arc::mojom::AccessibilityNodeInfoData* node, | |
87 arc::mojom::AccessibilityIntProperty prop, | |
dmazzoni
2017/03/17 03:22:37
nit: indentation
David Tseng
2017/03/17 15:38:32
Done.
| |
88 int32_t* out_value) { | |
89 if (!node->intProperties) | |
90 return false; | |
91 | |
92 auto it = node->intProperties->find(prop); | |
93 if (it == node->intProperties->end()) | |
94 return false; | |
95 | |
96 *out_value = it->second; | |
97 return true; | |
98 } | |
99 | |
86 bool GetStringProperty(arc::mojom::AccessibilityNodeInfoData* node, | 100 bool GetStringProperty(arc::mojom::AccessibilityNodeInfoData* node, |
87 arc::mojom::AccessibilityStringProperty prop, | 101 arc::mojom::AccessibilityStringProperty prop, |
88 std::string* out_value) { | 102 std::string* out_value) { |
89 if (!node->stringProperties) | 103 if (!node->stringProperties) |
90 return false; | 104 return false; |
91 | 105 |
92 auto it = node->stringProperties->find(prop); | 106 auto it = node->stringProperties->find(prop); |
93 if (it == node->stringProperties->end()) | 107 if (it == node->stringProperties->end()) |
94 return false; | 108 return false; |
95 | 109 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 mojom::AccessibilityNodeInfoData* AXTreeSourceArc::GetNull() const { | 313 mojom::AccessibilityNodeInfoData* AXTreeSourceArc::GetNull() const { |
300 return nullptr; | 314 return nullptr; |
301 } | 315 } |
302 | 316 |
303 void AXTreeSourceArc::SerializeNode(mojom::AccessibilityNodeInfoData* node, | 317 void AXTreeSourceArc::SerializeNode(mojom::AccessibilityNodeInfoData* node, |
304 ui::AXNodeData* out_data) const { | 318 ui::AXNodeData* out_data) const { |
305 if (!node) | 319 if (!node) |
306 return; | 320 return; |
307 out_data->id = node->id; | 321 out_data->id = node->id; |
308 | 322 |
323 using AXIntProperty = arc::mojom::AccessibilityIntProperty; | |
309 using AXStringProperty = arc::mojom::AccessibilityStringProperty; | 324 using AXStringProperty = arc::mojom::AccessibilityStringProperty; |
310 std::string text; | 325 std::string text; |
311 if (GetStringProperty(node, AXStringProperty::TEXT, &text)) | 326 if (GetStringProperty(node, AXStringProperty::TEXT, &text)) |
312 out_data->SetName(text); | 327 out_data->SetName(text); |
313 else if (GetStringProperty(node, AXStringProperty::CONTENT_DESCRIPTION, | 328 else if (GetStringProperty(node, AXStringProperty::CONTENT_DESCRIPTION, |
314 &text)) | 329 &text)) |
315 out_data->SetName(text); | 330 out_data->SetName(text); |
316 | 331 |
317 int32_t id = node->id; | 332 int32_t id = node->id; |
318 if (id == root_id_) | 333 if (id == root_id_) |
319 out_data->role = ui::AX_ROLE_ROOT_WEB_AREA; | 334 out_data->role = ui::AX_ROLE_ROOT_WEB_AREA; |
320 else | 335 else |
321 PopulateAXRole(node, out_data); | 336 PopulateAXRole(node, out_data); |
322 | 337 |
323 PopulateAXState(node, out_data); | 338 PopulateAXState(node, out_data); |
324 | 339 |
325 const gfx::Rect bounds_in_screen = GetBounds(node); | 340 const gfx::Rect bounds_in_screen = GetBounds(node); |
326 out_data->location.SetRect(bounds_in_screen.x(), bounds_in_screen.y(), | 341 out_data->location.SetRect(bounds_in_screen.x(), bounds_in_screen.y(), |
327 bounds_in_screen.width(), | 342 bounds_in_screen.width(), |
328 bounds_in_screen.height()); | 343 bounds_in_screen.height()); |
329 | 344 |
330 if (out_data->role == ui::AX_ROLE_TEXT_FIELD && !text.empty()) | 345 if (out_data->role == ui::AX_ROLE_TEXT_FIELD && !text.empty()) |
331 out_data->AddStringAttribute(ui::AX_ATTR_VALUE, text); | 346 out_data->AddStringAttribute(ui::AX_ATTR_VALUE, text); |
347 | |
348 // Integer properties. | |
349 int32_t val; | |
350 if (GetIntProperty(node, AXIntProperty::TEXT_SELECTION_START, | |
yawano
2017/03/17 08:38:23
Node can have both TEXT_SELECTION_START and TEXT_S
David Tseng
2017/03/17 15:38:32
Done.
| |
351 &val) && val >= 0) { | |
352 out_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_START, val); | |
353 out_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_END, val); | |
yawano
2017/03/17 08:38:23
This line of setting AX_ATTR_TEXT_SEL_END would be
David Tseng
2017/03/17 15:38:32
Yeah totally; was wip while I was trying to figure
| |
354 } else if (GetIntProperty(node, AXIntProperty::TEXT_SELECTION_END, | |
355 &val) && val >= 0) { | |
356 out_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_END, val); | |
357 } | |
332 } | 358 } |
333 | 359 |
334 void AXTreeSourceArc::Reset() { | 360 void AXTreeSourceArc::Reset() { |
335 tree_map_.clear(); | 361 tree_map_.clear(); |
336 parent_map_.clear(); | 362 parent_map_.clear(); |
337 current_tree_serializer_.reset(new AXTreeArcSerializer(this)); | 363 current_tree_serializer_.reset(new AXTreeArcSerializer(this)); |
338 root_id_ = -1; | 364 root_id_ = -1; |
339 focused_node_id_ = -1; | 365 focused_node_id_ = -1; |
340 extensions::AutomationEventRouter* router = | 366 extensions::AutomationEventRouter* router = |
341 extensions::AutomationEventRouter::GetInstance(); | 367 extensions::AutomationEventRouter::GetInstance(); |
342 router->DispatchTreeDestroyedEvent(tree_id_, nullptr); | 368 router->DispatchTreeDestroyedEvent(tree_id_, nullptr); |
343 } | 369 } |
344 | 370 |
345 } // namespace arc | 371 } // namespace arc |
OLD | NEW |