| Index: chrome/browser/chromeos/arc/accessibility/ax_tree_source_arc.cc
|
| diff --git a/chrome/browser/chromeos/arc/accessibility/ax_tree_source_arc.cc b/chrome/browser/chromeos/arc/accessibility/ax_tree_source_arc.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a384eb3d6361f8fa4a32c274fb07ba115468e27f
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/arc/accessibility/ax_tree_source_arc.cc
|
| @@ -0,0 +1,175 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/chromeos/arc/accessibility/ax_tree_source_arc.h"
|
| +
|
| +#include "chrome/browser/extensions/api/automation_internal/automation_event_router.h"
|
| +#include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h"
|
| +#include "chrome/common/extensions/chrome_extension_messages.h"
|
| +#include "components/exo/shell_surface.h"
|
| +#include "components/exo/surface.h"
|
| +#include "ui/accessibility/ax_tree_id_registry.h"
|
| +#include "ui/aura/window.h"
|
| +
|
| +namespace {
|
| +
|
| +exo::Surface* GetArcSurface(const aura::Window* window) {
|
| + exo::Surface* arc_surface = exo::Surface::AsSurface(window);
|
| + if (!arc_surface)
|
| + arc_surface = exo::ShellSurface::GetMainSurface(window);
|
| + return arc_surface;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +namespace arc {
|
| +
|
| +AXTreeSourceArc::AXTreeSourceArc()
|
| + : id_(ui::AXTreeIDRegistry::GetInstance()->CreateID()),
|
| + current_tree_serializer_(new AXTreeArcSerializer(this)) {}
|
| +
|
| +AXTreeSourceArc::~AXTreeSourceArc() {}
|
| +
|
| +void AXTreeSourceArc::NotifyAccessibilityEvent(
|
| + mojom::AccessibilityEventData* event_data) {
|
| + if (exo::WMHelper::GetInstance())
|
| + exo::WMHelper::GetInstance()->AddFocusObserver(this);
|
| +
|
| + tree_map_.clear();
|
| + parent_map_.clear();
|
| + for (size_t i = 0; i < event_data->nodeData.size(); ++i) {
|
| + for (size_t j = 0; j < event_data->nodeData[i]->childIds.size(); ++j)
|
| + parent_map_[event_data->nodeData[i]->childIds[j]] =
|
| + event_data->nodeData[i]->id;
|
| + }
|
| +
|
| + for (size_t i = 0; i < event_data->nodeData.size(); ++i) {
|
| + int32_t id = event_data->nodeData[i]->id;
|
| + tree_map_[id] = event_data->nodeData[i].get();
|
| + if (parent_map_.find(id) == parent_map_.end())
|
| + root_ = id;
|
| + }
|
| +
|
| + ExtensionMsg_AccessibilityEventParams params;
|
| + current_tree_serializer_->SerializeChanges(GetFromId(event_data->sourceId),
|
| + ¶ms.update);
|
| +
|
| + params.tree_id = id_;
|
| + params.id = event_data->sourceId;
|
| + params.event_type = ui::AX_EVENT_FOCUS;
|
| +
|
| + extensions::AutomationEventRouter* router =
|
| + extensions::AutomationEventRouter::GetInstance();
|
| + router->DispatchAccessibilityEvent(params);
|
| +}
|
| +
|
| +bool AXTreeSourceArc::GetTreeData(ui::AXTreeData* data) const {
|
| + data->tree_id = id_;
|
| + return true;
|
| +}
|
| +
|
| +mojom::AccessibilityNodeInfoData* AXTreeSourceArc::GetRoot() const {
|
| + mojom::AccessibilityNodeInfoData* root = GetFromId(root_);
|
| + return root;
|
| +}
|
| +
|
| +mojom::AccessibilityNodeInfoData* AXTreeSourceArc::GetFromId(int32_t id) const {
|
| + auto it = tree_map_.find(id);
|
| + if (it == tree_map_.end())
|
| + return nullptr;
|
| + return it->second;
|
| +}
|
| +
|
| +int32_t AXTreeSourceArc::GetId(mojom::AccessibilityNodeInfoData* node) const {
|
| + if (!node)
|
| + return -11;
|
| + return node->id;
|
| +}
|
| +
|
| +void AXTreeSourceArc::GetChildren(
|
| + mojom::AccessibilityNodeInfoData* node,
|
| + std::vector<mojom::AccessibilityNodeInfoData*>* out_children) const {
|
| + if (!node)
|
| + return;
|
| + for (size_t i = 0; i < node->childIds.size(); ++i) {
|
| + out_children->push_back(GetFromId(node->childIds[i]));
|
| + }
|
| +}
|
| +
|
| +mojom::AccessibilityNodeInfoData* AXTreeSourceArc::GetParent(
|
| + mojom::AccessibilityNodeInfoData* node) const {
|
| + if (!node)
|
| + return nullptr;
|
| + auto it = parent_map_.find(node->id);
|
| + if (it != parent_map_.end())
|
| + return GetFromId(it->second);
|
| + return nullptr;
|
| +}
|
| +
|
| +bool AXTreeSourceArc::IsValid(mojom::AccessibilityNodeInfoData* node) const {
|
| + return node;
|
| +}
|
| +
|
| +bool AXTreeSourceArc::IsEqual(mojom::AccessibilityNodeInfoData* node1,
|
| + mojom::AccessibilityNodeInfoData* node2) const {
|
| + if (!node1 || !node2)
|
| + return false;
|
| + return node1->id == node2->id;
|
| +}
|
| +
|
| +mojom::AccessibilityNodeInfoData* AXTreeSourceArc::GetNull() const {
|
| + return nullptr;
|
| +}
|
| +
|
| +void AXTreeSourceArc::SerializeNode(mojom::AccessibilityNodeInfoData* node,
|
| + ui::AXNodeData* out_data) const {
|
| + if (!node)
|
| + return;
|
| + out_data->id = node->id;
|
| + out_data->state = 0;
|
| + if (!node->text.empty())
|
| + out_data->SetName(node->text);
|
| + else if (!node->contentDescription.empty())
|
| + out_data->SetName(node->contentDescription);
|
| +
|
| + int32_t id = node->id;
|
| + if (id == root_)
|
| + out_data->role = ui::AX_ROLE_ROOT_WEB_AREA;
|
| + else if (!node->text.empty())
|
| + out_data->role = ui::AX_ROLE_STATIC_TEXT;
|
| + else
|
| + out_data->role = ui::AX_ROLE_DIV;
|
| + out_data->location.SetRect(node->boundsInScreen.x(), node->boundsInScreen.y(),
|
| + node->boundsInScreen.width(),
|
| + node->boundsInScreen.height());
|
| +}
|
| +
|
| +void AXTreeSourceArc::Reset() {
|
| + tree_map_.clear();
|
| + parent_map_.clear();
|
| + current_tree_serializer_.reset(new AXTreeArcSerializer(this));
|
| + extensions::AutomationEventRouter* router =
|
| + extensions::AutomationEventRouter::GetInstance();
|
| + router->DispatchTreeDestroyedEvent(id_, nullptr);
|
| +}
|
| +
|
| +void AXTreeSourceArc::OnWindowFocused(aura::Window* gained_focus,
|
| + aura::Window* lost_focus) {
|
| + exo::Surface* focused_surface = GetArcSurface(gained_focus);
|
| + if (gained_focus == lost_focus)
|
| + return;
|
| +
|
| + exo::Surface* unfocused_surface = GetArcSurface(lost_focus);
|
| + if (unfocused_surface) {
|
| + unfocused_surface->UpdateAXTreeID(0);
|
| + }
|
| +
|
| + Reset();
|
| + if (!focused_surface)
|
| + return;
|
| +
|
| + focused_surface->UpdateAXTreeID(id_);
|
| +}
|
| +
|
| +} // namespace arc
|
|
|