| 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" |
| 11 #include "chrome/common/extensions/chrome_extension_messages.h" | 11 #include "chrome/common/extensions/chrome_extension_messages.h" |
| 12 #include "components/exo/wm_helper.h" | 12 #include "components/exo/wm_helper.h" |
| 13 #include "ui/accessibility/platform/ax_android_constants.h" | 13 #include "ui/accessibility/platform/ax_android_constants.h" |
| 14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 ui::AXEvent ToAXEvent(arc::mojom::AccessibilityEventType arc_event_type) { | 18 ui::AXEvent ToAXEvent(arc::mojom::AccessibilityEventType arc_event_type) { |
| 19 switch (arc_event_type) { | 19 switch (arc_event_type) { |
| 20 case arc::mojom::AccessibilityEventType::VIEW_FOCUSED: | 20 case arc::mojom::AccessibilityEventType::VIEW_FOCUSED: |
| 21 case arc::mojom::AccessibilityEventType::VIEW_ACCESSIBILITY_FOCUSED: | 21 case arc::mojom::AccessibilityEventType::VIEW_ACCESSIBILITY_FOCUSED: |
| 22 return ui::AX_EVENT_FOCUS; | 22 return ui::AX_EVENT_FOCUS; |
| 23 case arc::mojom::AccessibilityEventType::VIEW_ACCESSIBILITY_FOCUS_CLEARED: | |
| 24 return ui::AX_EVENT_BLUR; | |
| 25 case arc::mojom::AccessibilityEventType::VIEW_CLICKED: | 23 case arc::mojom::AccessibilityEventType::VIEW_CLICKED: |
| 26 case arc::mojom::AccessibilityEventType::VIEW_LONG_CLICKED: | 24 case arc::mojom::AccessibilityEventType::VIEW_LONG_CLICKED: |
| 27 return ui::AX_EVENT_CLICKED; | 25 return ui::AX_EVENT_CLICKED; |
| 28 case arc::mojom::AccessibilityEventType::VIEW_TEXT_CHANGED: | 26 case arc::mojom::AccessibilityEventType::VIEW_TEXT_CHANGED: |
| 29 return ui::AX_EVENT_TEXT_CHANGED; | 27 return ui::AX_EVENT_TEXT_CHANGED; |
| 30 case arc::mojom::AccessibilityEventType::VIEW_TEXT_SELECTION_CHANGED: | 28 case arc::mojom::AccessibilityEventType::VIEW_TEXT_SELECTION_CHANGED: |
| 31 return ui::AX_EVENT_TEXT_SELECTION_CHANGED; | 29 return ui::AX_EVENT_TEXT_SELECTION_CHANGED; |
| 32 case arc::mojom::AccessibilityEventType::WINDOW_STATE_CHANGED: | 30 case arc::mojom::AccessibilityEventType::WINDOW_STATE_CHANGED: |
| 33 case arc::mojom::AccessibilityEventType::NOTIFICATION_STATE_CHANGED: | 31 case arc::mojom::AccessibilityEventType::NOTIFICATION_STATE_CHANGED: |
| 34 case arc::mojom::AccessibilityEventType::WINDOW_CONTENT_CHANGED: | 32 case arc::mojom::AccessibilityEventType::WINDOW_CONTENT_CHANGED: |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 if (!node->booleanProperties) | 74 if (!node->booleanProperties) |
| 77 return false; | 75 return false; |
| 78 | 76 |
| 79 auto it = node->booleanProperties->find(prop); | 77 auto it = node->booleanProperties->find(prop); |
| 80 if (it == node->booleanProperties->end()) | 78 if (it == node->booleanProperties->end()) |
| 81 return false; | 79 return false; |
| 82 | 80 |
| 83 return it->second; | 81 return it->second; |
| 84 } | 82 } |
| 85 | 83 |
| 84 bool GetIntProperty(arc::mojom::AccessibilityNodeInfoData* node, |
| 85 arc::mojom::AccessibilityIntProperty prop, |
| 86 int32_t* out_value) { |
| 87 if (!node->intProperties) |
| 88 return false; |
| 89 |
| 90 auto it = node->intProperties->find(prop); |
| 91 if (it == node->intProperties->end()) |
| 92 return false; |
| 93 |
| 94 *out_value = it->second; |
| 95 return true; |
| 96 } |
| 97 |
| 86 bool GetStringProperty(arc::mojom::AccessibilityNodeInfoData* node, | 98 bool GetStringProperty(arc::mojom::AccessibilityNodeInfoData* node, |
| 87 arc::mojom::AccessibilityStringProperty prop, | 99 arc::mojom::AccessibilityStringProperty prop, |
| 88 std::string* out_value) { | 100 std::string* out_value) { |
| 89 if (!node->stringProperties) | 101 if (!node->stringProperties) |
| 90 return false; | 102 return false; |
| 91 | 103 |
| 92 auto it = node->stringProperties->find(prop); | 104 auto it = node->stringProperties->find(prop); |
| 93 if (it == node->stringProperties->end()) | 105 if (it == node->stringProperties->end()) |
| 94 return false; | 106 return false; |
| 95 | 107 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 int32_t id = event_data->nodeData[i]->id; | 224 int32_t id = event_data->nodeData[i]->id; |
| 213 tree_map_[id] = event_data->nodeData[i].get(); | 225 tree_map_[id] = event_data->nodeData[i].get(); |
| 214 if (parent_map_.find(id) == parent_map_.end()) { | 226 if (parent_map_.find(id) == parent_map_.end()) { |
| 215 CHECK_EQ(-1, root_id_) << "Duplicated root"; | 227 CHECK_EQ(-1, root_id_) << "Duplicated root"; |
| 216 root_id_ = id; | 228 root_id_ = id; |
| 217 } | 229 } |
| 218 } | 230 } |
| 219 | 231 |
| 220 ExtensionMsg_AccessibilityEventParams params; | 232 ExtensionMsg_AccessibilityEventParams params; |
| 221 params.event_type = ToAXEvent(event_data->eventType); | 233 params.event_type = ToAXEvent(event_data->eventType); |
| 234 |
| 222 if (params.event_type == ui::AX_EVENT_FOCUS) | 235 if (params.event_type == ui::AX_EVENT_FOCUS) |
| 223 focused_node_id_ = params.id; | 236 focused_node_id_ = event_data->sourceId; |
| 224 else if (params.event_type == ui::AX_EVENT_BLUR) | 237 |
| 225 focused_node_id_ = -1; | |
| 226 params.tree_id = tree_id_; | 238 params.tree_id = tree_id_; |
| 227 params.id = event_data->sourceId; | 239 params.id = event_data->sourceId; |
| 228 | 240 |
| 229 current_tree_serializer_->SerializeChanges(GetFromId(event_data->sourceId), | 241 current_tree_serializer_->SerializeChanges(GetFromId(event_data->sourceId), |
| 230 ¶ms.update); | 242 ¶ms.update); |
| 231 | 243 |
| 232 extensions::AutomationEventRouter* router = | 244 extensions::AutomationEventRouter* router = |
| 233 extensions::AutomationEventRouter::GetInstance(); | 245 extensions::AutomationEventRouter::GetInstance(); |
| 234 router->DispatchAccessibilityEvent(params); | 246 router->DispatchAccessibilityEvent(params); |
| 235 } | 247 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 mojom::AccessibilityNodeInfoData* AXTreeSourceArc::GetNull() const { | 311 mojom::AccessibilityNodeInfoData* AXTreeSourceArc::GetNull() const { |
| 300 return nullptr; | 312 return nullptr; |
| 301 } | 313 } |
| 302 | 314 |
| 303 void AXTreeSourceArc::SerializeNode(mojom::AccessibilityNodeInfoData* node, | 315 void AXTreeSourceArc::SerializeNode(mojom::AccessibilityNodeInfoData* node, |
| 304 ui::AXNodeData* out_data) const { | 316 ui::AXNodeData* out_data) const { |
| 305 if (!node) | 317 if (!node) |
| 306 return; | 318 return; |
| 307 out_data->id = node->id; | 319 out_data->id = node->id; |
| 308 | 320 |
| 321 using AXIntProperty = arc::mojom::AccessibilityIntProperty; |
| 309 using AXStringProperty = arc::mojom::AccessibilityStringProperty; | 322 using AXStringProperty = arc::mojom::AccessibilityStringProperty; |
| 310 std::string text; | 323 std::string text; |
| 311 if (GetStringProperty(node, AXStringProperty::TEXT, &text)) | 324 if (GetStringProperty(node, AXStringProperty::TEXT, &text)) |
| 312 out_data->SetName(text); | 325 out_data->SetName(text); |
| 313 else if (GetStringProperty(node, AXStringProperty::CONTENT_DESCRIPTION, | 326 else if (GetStringProperty(node, AXStringProperty::CONTENT_DESCRIPTION, |
| 314 &text)) | 327 &text)) |
| 315 out_data->SetName(text); | 328 out_data->SetName(text); |
| 316 | 329 |
| 317 int32_t id = node->id; | 330 int32_t id = node->id; |
| 318 if (id == root_id_) | 331 if (id == root_id_) |
| 319 out_data->role = ui::AX_ROLE_ROOT_WEB_AREA; | 332 out_data->role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 320 else | 333 else |
| 321 PopulateAXRole(node, out_data); | 334 PopulateAXRole(node, out_data); |
| 322 | 335 |
| 323 PopulateAXState(node, out_data); | 336 PopulateAXState(node, out_data); |
| 324 | 337 |
| 325 const gfx::Rect bounds_in_screen = GetBounds(node); | 338 const gfx::Rect bounds_in_screen = GetBounds(node); |
| 326 out_data->location.SetRect(bounds_in_screen.x(), bounds_in_screen.y(), | 339 out_data->location.SetRect(bounds_in_screen.x(), bounds_in_screen.y(), |
| 327 bounds_in_screen.width(), | 340 bounds_in_screen.width(), |
| 328 bounds_in_screen.height()); | 341 bounds_in_screen.height()); |
| 329 | 342 |
| 330 if (out_data->role == ui::AX_ROLE_TEXT_FIELD && !text.empty()) | 343 if (out_data->role == ui::AX_ROLE_TEXT_FIELD && !text.empty()) |
| 331 out_data->AddStringAttribute(ui::AX_ATTR_VALUE, text); | 344 out_data->AddStringAttribute(ui::AX_ATTR_VALUE, text); |
| 345 |
| 346 // Integer properties. |
| 347 int32_t val; |
| 348 if (GetIntProperty(node, AXIntProperty::TEXT_SELECTION_START, &val) && |
| 349 val >= 0) |
| 350 out_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_START, val); |
| 351 |
| 352 if (GetIntProperty(node, AXIntProperty::TEXT_SELECTION_END, &val) && val >= 0) |
| 353 out_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_END, val); |
| 332 } | 354 } |
| 333 | 355 |
| 334 void AXTreeSourceArc::Reset() { | 356 void AXTreeSourceArc::Reset() { |
| 335 tree_map_.clear(); | 357 tree_map_.clear(); |
| 336 parent_map_.clear(); | 358 parent_map_.clear(); |
| 337 current_tree_serializer_.reset(new AXTreeArcSerializer(this)); | 359 current_tree_serializer_.reset(new AXTreeArcSerializer(this)); |
| 338 root_id_ = -1; | 360 root_id_ = -1; |
| 339 focused_node_id_ = -1; | 361 focused_node_id_ = -1; |
| 340 extensions::AutomationEventRouter* router = | 362 extensions::AutomationEventRouter* router = |
| 341 extensions::AutomationEventRouter::GetInstance(); | 363 extensions::AutomationEventRouter::GetInstance(); |
| 342 router->DispatchTreeDestroyedEvent(tree_id_, nullptr); | 364 router->DispatchTreeDestroyedEvent(tree_id_, nullptr); |
| 343 } | 365 } |
| 344 | 366 |
| 345 } // namespace arc | 367 } // namespace arc |
| OLD | NEW |