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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 } | 58 } |
59 return ui::AX_EVENT_CHILDREN_CHANGED; | 59 return ui::AX_EVENT_CHILDREN_CHANGED; |
60 } | 60 } |
61 | 61 |
62 const gfx::Rect GetBounds(arc::mojom::AccessibilityNodeInfoData* node) { | 62 const gfx::Rect GetBounds(arc::mojom::AccessibilityNodeInfoData* node) { |
63 exo::WMHelper* wm_helper = exo::WMHelper::GetInstance(); | 63 exo::WMHelper* wm_helper = exo::WMHelper::GetInstance(); |
64 if (!wm_helper) | 64 if (!wm_helper) |
65 return gfx::Rect(); | 65 return gfx::Rect(); |
66 | 66 |
67 aura::Window* focused_window = wm_helper->GetFocusedWindow(); | 67 aura::Window* focused_window = wm_helper->GetFocusedWindow(); |
68 gfx::Rect bounds_in_screen = node->boundsInScreen; | 68 gfx::Rect bounds_in_screen = node->bounds_in_screen; |
69 if (focused_window) { | 69 if (focused_window) { |
70 aura::Window* toplevel_window = focused_window->GetToplevelWindow(); | 70 aura::Window* toplevel_window = focused_window->GetToplevelWindow(); |
71 return gfx::ScaleToEnclosingRect( | 71 return gfx::ScaleToEnclosingRect( |
72 bounds_in_screen, | 72 bounds_in_screen, |
73 1.0f / toplevel_window->layer()->device_scale_factor()); | 73 1.0f / toplevel_window->layer()->device_scale_factor()); |
74 } | 74 } |
75 return bounds_in_screen; | 75 return bounds_in_screen; |
76 } | 76 } |
77 | 77 |
78 bool GetBooleanProperty(arc::mojom::AccessibilityNodeInfoData* node, | 78 bool GetBooleanProperty(arc::mojom::AccessibilityNodeInfoData* node, |
79 arc::mojom::AccessibilityBooleanProperty prop) { | 79 arc::mojom::AccessibilityBooleanProperty prop) { |
80 if (!node->booleanProperties) | 80 if (!node->boolean_properties) |
81 return false; | 81 return false; |
82 | 82 |
83 auto it = node->booleanProperties->find(prop); | 83 auto it = node->boolean_properties->find(prop); |
84 if (it == node->booleanProperties->end()) | 84 if (it == node->boolean_properties->end()) |
85 return false; | 85 return false; |
86 | 86 |
87 return it->second; | 87 return it->second; |
88 } | 88 } |
89 | 89 |
90 bool GetIntProperty(arc::mojom::AccessibilityNodeInfoData* node, | 90 bool GetIntProperty(arc::mojom::AccessibilityNodeInfoData* node, |
91 arc::mojom::AccessibilityIntProperty prop, | 91 arc::mojom::AccessibilityIntProperty prop, |
92 int32_t* out_value) { | 92 int32_t* out_value) { |
93 if (!node->intProperties) | 93 if (!node->int_properties) |
94 return false; | 94 return false; |
95 | 95 |
96 auto it = node->intProperties->find(prop); | 96 auto it = node->int_properties->find(prop); |
97 if (it == node->intProperties->end()) | 97 if (it == node->int_properties->end()) |
98 return false; | 98 return false; |
99 | 99 |
100 *out_value = it->second; | 100 *out_value = it->second; |
101 return true; | 101 return true; |
102 } | 102 } |
103 | 103 |
104 bool GetStringProperty(arc::mojom::AccessibilityNodeInfoData* node, | 104 bool GetStringProperty(arc::mojom::AccessibilityNodeInfoData* node, |
105 arc::mojom::AccessibilityStringProperty prop, | 105 arc::mojom::AccessibilityStringProperty prop, |
106 std::string* out_value) { | 106 std::string* out_value) { |
107 if (!node->stringProperties) | 107 if (!node->string_properties) |
108 return false; | 108 return false; |
109 | 109 |
110 auto it = node->stringProperties->find(prop); | 110 auto it = node->string_properties->find(prop); |
111 if (it == node->stringProperties->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 void PopulateAXRole(arc::mojom::AccessibilityNodeInfoData* node, | 118 void PopulateAXRole(arc::mojom::AccessibilityNodeInfoData* node, |
119 ui::AXNodeData* out_data) { | 119 ui::AXNodeData* out_data) { |
120 std::string class_name; | 120 std::string class_name; |
121 GetStringProperty(node, arc::mojom::AccessibilityStringProperty::CLASS_NAME, | 121 GetStringProperty(node, arc::mojom::AccessibilityStringProperty::CLASS_NAME, |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 239 |
240 AXTreeSourceArc::~AXTreeSourceArc() { | 240 AXTreeSourceArc::~AXTreeSourceArc() { |
241 Reset(); | 241 Reset(); |
242 } | 242 } |
243 | 243 |
244 void AXTreeSourceArc::NotifyAccessibilityEvent( | 244 void AXTreeSourceArc::NotifyAccessibilityEvent( |
245 mojom::AccessibilityEventData* event_data) { | 245 mojom::AccessibilityEventData* event_data) { |
246 tree_map_.clear(); | 246 tree_map_.clear(); |
247 parent_map_.clear(); | 247 parent_map_.clear(); |
248 root_id_ = -1; | 248 root_id_ = -1; |
249 for (size_t i = 0; i < event_data->nodeData.size(); ++i) { | 249 for (size_t i = 0; i < event_data->node_data.size(); ++i) { |
250 if (!event_data->nodeData[i]->intListProperties) | 250 if (!event_data->node_data[i]->int_list_properties) |
251 continue; | 251 continue; |
252 auto it = event_data->nodeData[i]->intListProperties->find( | 252 auto it = event_data->node_data[i]->int_list_properties->find( |
253 arc::mojom::AccessibilityIntListProperty::CHILD_NODE_IDS); | 253 arc::mojom::AccessibilityIntListProperty::CHILD_NODE_IDS); |
254 if (it != event_data->nodeData[i]->intListProperties->end()) { | 254 if (it != event_data->node_data[i]->int_list_properties->end()) { |
255 for (size_t j = 0; j < it->second.size(); ++j) | 255 for (size_t j = 0; j < it->second.size(); ++j) |
256 parent_map_[it->second[j]] = event_data->nodeData[i]->id; | 256 parent_map_[it->second[j]] = event_data->node_data[i]->id; |
257 } | 257 } |
258 } | 258 } |
259 | 259 |
260 for (size_t i = 0; i < event_data->nodeData.size(); ++i) { | 260 for (size_t i = 0; i < event_data->node_data.size(); ++i) { |
261 int32_t id = event_data->nodeData[i]->id; | 261 int32_t id = event_data->node_data[i]->id; |
262 tree_map_[id] = event_data->nodeData[i].get(); | 262 tree_map_[id] = event_data->node_data[i].get(); |
263 if (parent_map_.find(id) == parent_map_.end()) { | 263 if (parent_map_.find(id) == parent_map_.end()) { |
264 CHECK_EQ(-1, root_id_) << "Duplicated root"; | 264 CHECK_EQ(-1, root_id_) << "Duplicated root"; |
265 root_id_ = id; | 265 root_id_ = id; |
266 } | 266 } |
267 } | 267 } |
268 | 268 |
269 ExtensionMsg_AccessibilityEventParams params; | 269 ExtensionMsg_AccessibilityEventParams params; |
270 params.event_type = ToAXEvent(event_data->eventType); | 270 params.event_type = ToAXEvent(event_data->event_type); |
271 | 271 |
272 if (params.event_type == ui::AX_EVENT_FOCUS) | 272 if (params.event_type == ui::AX_EVENT_FOCUS) |
273 focused_node_id_ = event_data->sourceId; | 273 focused_node_id_ = event_data->source_id; |
274 | 274 |
275 params.tree_id = tree_id(); | 275 params.tree_id = tree_id(); |
276 params.id = event_data->sourceId; | 276 params.id = event_data->source_id; |
277 | 277 |
278 current_tree_serializer_->SerializeChanges(GetFromId(event_data->sourceId), | 278 current_tree_serializer_->SerializeChanges(GetFromId(event_data->source_id), |
279 ¶ms.update); | 279 ¶ms.update); |
280 | 280 |
281 extensions::AutomationEventRouter* router = | 281 extensions::AutomationEventRouter* router = |
282 extensions::AutomationEventRouter::GetInstance(); | 282 extensions::AutomationEventRouter::GetInstance(); |
283 router->DispatchAccessibilityEvent(params); | 283 router->DispatchAccessibilityEvent(params); |
284 } | 284 } |
285 | 285 |
286 void AXTreeSourceArc::Focus(aura::Window* window) { | 286 void AXTreeSourceArc::Focus(aura::Window* window) { |
287 views::Widget* widget = views::Widget::GetWidgetForNativeView(window); | 287 views::Widget* widget = views::Widget::GetWidgetForNativeView(window); |
288 if (!widget || !widget->GetContentsView()) | 288 if (!widget || !widget->GetContentsView()) |
(...skipping 26 matching lines...) Expand all Loading... |
315 | 315 |
316 int32_t AXTreeSourceArc::GetId(mojom::AccessibilityNodeInfoData* node) const { | 316 int32_t AXTreeSourceArc::GetId(mojom::AccessibilityNodeInfoData* node) const { |
317 if (!node) | 317 if (!node) |
318 return -1; | 318 return -1; |
319 return node->id; | 319 return node->id; |
320 } | 320 } |
321 | 321 |
322 void AXTreeSourceArc::GetChildren( | 322 void AXTreeSourceArc::GetChildren( |
323 mojom::AccessibilityNodeInfoData* node, | 323 mojom::AccessibilityNodeInfoData* node, |
324 std::vector<mojom::AccessibilityNodeInfoData*>* out_children) const { | 324 std::vector<mojom::AccessibilityNodeInfoData*>* out_children) const { |
325 if (!node || !node->intListProperties) | 325 if (!node || !node->int_list_properties) |
326 return; | 326 return; |
327 | 327 |
328 auto it = node->intListProperties->find( | 328 auto it = node->int_list_properties->find( |
329 arc::mojom::AccessibilityIntListProperty::CHILD_NODE_IDS); | 329 arc::mojom::AccessibilityIntListProperty::CHILD_NODE_IDS); |
330 if (it == node->intListProperties->end()) | 330 if (it == node->int_list_properties->end()) |
331 return; | 331 return; |
332 | 332 |
333 for (size_t i = 0; i < it->second.size(); ++i) { | 333 for (size_t i = 0; i < it->second.size(); ++i) { |
334 out_children->push_back(GetFromId(it->second[i])); | 334 out_children->push_back(GetFromId(it->second[i])); |
335 } | 335 } |
336 } | 336 } |
337 | 337 |
338 mojom::AccessibilityNodeInfoData* AXTreeSourceArc::GetParent( | 338 mojom::AccessibilityNodeInfoData* AXTreeSourceArc::GetParent( |
339 mojom::AccessibilityNodeInfoData* node) const { | 339 mojom::AccessibilityNodeInfoData* node) const { |
340 if (!node) | 340 if (!node) |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 focused_node_id_ = -1; | 413 focused_node_id_ = -1; |
414 extensions::AutomationEventRouter* router = | 414 extensions::AutomationEventRouter* router = |
415 extensions::AutomationEventRouter::GetInstance(); | 415 extensions::AutomationEventRouter::GetInstance(); |
416 if (!router) | 416 if (!router) |
417 return; | 417 return; |
418 | 418 |
419 router->DispatchTreeDestroyedEvent(tree_id(), nullptr); | 419 router->DispatchTreeDestroyedEvent(tree_id(), nullptr); |
420 } | 420 } |
421 | 421 |
422 } // namespace arc | 422 } // namespace arc |
OLD | NEW |