Commit f3d287f6 authored by Randy Rossi's avatar Randy Rossi Committed by Commit Bot

Remove more duplicate ax tree code

Part of ongoing effort to eliminate duplicate code
introduced when automation API was added to Chromecast.

Making Chromecast's copy of AXTreeSourceAura derive from
AXTreeSourceViews.  The two now nearly identical copies of
ax_tree_source_aura.cc will be merged and moved up to
ui/views in a subsequent CL.

Bug: 837773
Test: Manual verification on chromecast and chromeos (tidus)
Change-Id: I1b083280ce280ec0bd25324778f5d84ec3a7e9cf
Reviewed-on: https://chromium-review.googlesource.com/1249682
Commit-Queue: Randy Rossi <rmrossi@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarAlex Sakhartchouk <alexst@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595511}
parent 4be648d3
...@@ -8,133 +8,44 @@ ...@@ -8,133 +8,44 @@
#include "chromecast/browser/ui/aura/accessibility/automation_manager_aura.h" #include "chromecast/browser/ui/aura/accessibility/automation_manager_aura.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "ui/accessibility/ax_action_data.h" #include "ui/accessibility/ax_action_data.h"
#include "ui/views/accessibility/ax_aura_obj_cache.h"
#include "ui/views/accessibility/ax_aura_obj_wrapper.h" #include "ui/views/accessibility/ax_aura_obj_wrapper.h"
#include "ui/views/accessibility/ax_view_obj_wrapper.h" #include "ui/views/accessibility/ax_view_obj_wrapper.h"
#if defined(TOOLKIT_VIEWS) AXTreeSourceAura::AXTreeSourceAura()
#include "ui/views/controls/webview/webview.h" // nogncheck : desktop_root_(std::make_unique<AXRootObjWrapper>(
#endif AutomationManagerAura::GetInstance())) {}
using views::AXAuraObjCache; AXTreeSourceAura::~AXTreeSourceAura() = default;
using views::AXAuraObjWrapper;
AXTreeSourceAura::AXTreeSourceAura() {
root_.reset(new AXRootObjWrapper(AutomationManagerAura::GetInstance()));
}
AXTreeSourceAura::~AXTreeSourceAura() {
root_.reset();
}
bool AXTreeSourceAura::HandleAccessibleAction(const ui::AXActionData& action) {
int id = action.target_node_id;
// In Views, we only support setting the selection within a single node,
// not across multiple nodes like on the web.
if (action.action == ax::mojom::Action::kSetSelection) {
if (action.anchor_node_id != action.focus_node_id) {
NOTREACHED();
return false;
}
id = action.anchor_node_id;
}
AXAuraObjWrapper* obj = AXAuraObjCache::GetInstance()->Get(id);
if (obj)
return obj->HandleAccessibleAction(action);
return false;
}
bool AXTreeSourceAura::GetTreeData(ui::AXTreeData* tree_data) const { bool AXTreeSourceAura::GetTreeData(ui::AXTreeData* tree_data) const {
tree_data->tree_id = ui::DesktopAXTreeID(); tree_data->tree_id = ui::DesktopAXTreeID();
tree_data->loaded = true; AXTreeSourceViews::GetTreeData(tree_data);
tree_data->loading_progress = 1.0;
AXAuraObjWrapper* focus = AXAuraObjCache::GetInstance()->GetFocus();
// TODO(b/111911092): AXTreeData::focus_id represents the node within the // TODO(b/111911092): AXTreeData::focus_id represents the node within the
// tree with 'keyboard focus'. We have no keyboard focus on chromecast so // tree with 'keyboard focus'. We have no keyboard focus on chromecast so
// this is being left as -1. This prevents getFocus calls from the chromevox // this is being left as -1. This prevents getFocus calls from the chromevox
// background page from finding any window in focus and interferes with // background page from finding any window in focus and interferes with
// gesture event processing. Since we only ever have one top level window // gesture event processing. Since we only ever have one top level window
// and one ax tree, temporarily returning 1 here to indicate the root node is // and one ax tree, temporarily returning 1 here to indicate the root node
// always the focused window. A better solution would be to fix the focus // is always the focused window. A better solution would be to fix the focus
// issues on chromecast which relies on a) the root window to be focused via // issues on chromecast which relies on a) the root window to be focused via
// Focus() and 2) a native widget being registered with the root window so // Focus() and 2) a native widget being registered with the root window so
// the above GetFocus call will work. When this code is re-unified with // the above GetFocus call will work. When this code is re-unified with
// chrome, this will need to be a special case for chromecast unless the // chrome, this will need to be a special case for chromecast unless the
// better solution described above is implemented. // better solution described above is implemented.
if (focus) tree_data->focus_id = 1;
tree_data->focus_id = focus->GetUniqueId().Get();
else
tree_data->focus_id = 1; // root node
return true; return true;
} }
AXAuraObjWrapper* AXTreeSourceAura::GetRoot() const { views::AXAuraObjWrapper* AXTreeSourceAura::GetRoot() const {
return root_.get(); return desktop_root_.get();
}
AXAuraObjWrapper* AXTreeSourceAura::GetFromId(int32_t id) const {
if (id == root_->GetUniqueId().Get())
return root_.get();
return AXAuraObjCache::GetInstance()->Get(id);
}
int32_t AXTreeSourceAura::GetId(AXAuraObjWrapper* node) const {
return node->GetUniqueId().Get();
}
void AXTreeSourceAura::GetChildren(
AXAuraObjWrapper* node,
std::vector<AXAuraObjWrapper*>* out_children) const {
node->GetChildren(out_children);
}
AXAuraObjWrapper* AXTreeSourceAura::GetParent(AXAuraObjWrapper* node) const {
AXAuraObjWrapper* parent = node->GetParent();
if (!parent && node->GetUniqueId() != root_->GetUniqueId())
parent = root_.get();
return parent;
}
bool AXTreeSourceAura::IsValid(AXAuraObjWrapper* node) const {
return node != nullptr;
}
bool AXTreeSourceAura::IsEqual(AXAuraObjWrapper* node1,
AXAuraObjWrapper* node2) const {
if (!node1 || !node2)
return false;
return node1->GetUniqueId() == node2->GetUniqueId();
}
AXAuraObjWrapper* AXTreeSourceAura::GetNull() const {
return NULL;
} }
void AXTreeSourceAura::SerializeNode(AXAuraObjWrapper* node, void AXTreeSourceAura::SerializeNode(views::AXAuraObjWrapper* node,
ui::AXNodeData* out_data) const { ui::AXNodeData* out_data) const {
node->Serialize(out_data); AXTreeSourceViews::SerializeNode(node, out_data);
// Convert the global coordinates reported by each AXAuraObjWrapper
// into parent-relative coordinates to be used in the accessibility
// tree. That way when any Window, Widget, or View moves (and fires
// a location changed event), its descendants all move relative to
// it by default.
AXAuraObjWrapper* parent = node->GetParent();
if (parent) {
ui::AXNodeData parent_data;
parent->Serialize(&parent_data);
out_data->location.Offset(-parent_data.location.OffsetFromOrigin());
out_data->offset_container_id = parent->GetUniqueId().Get();
}
if (out_data->role == ax::mojom::Role::kWebView) { if (out_data->role == ax::mojom::Role::kWebView) {
// TODO(rmrossi) : Figure out whether this will ever be required // TODO(rmrossi) : Figure out whether this will ever be required
...@@ -147,18 +58,3 @@ void AXTreeSourceAura::SerializeNode(AXAuraObjWrapper* node, ...@@ -147,18 +58,3 @@ void AXTreeSourceAura::SerializeNode(AXAuraObjWrapper* node,
} }
} }
std::string AXTreeSourceAura::ToString(AXAuraObjWrapper* root,
std::string prefix) {
ui::AXNodeData data;
root->Serialize(&data);
std::string output = prefix + data.ToString() + '\n';
std::vector<AXAuraObjWrapper*> children;
root->GetChildren(&children);
prefix += prefix[0];
for (size_t i = 0; i < children.size(); ++i)
output += ToString(children[i], prefix);
return output;
}
...@@ -5,60 +5,28 @@ ...@@ -5,60 +5,28 @@
#ifndef CHROMECAST_BROWSER_UI_AURA_ACCESSIBILITY_AX_TREE_SOURCE_AURA_H_ #ifndef CHROMECAST_BROWSER_UI_AURA_ACCESSIBILITY_AX_TREE_SOURCE_AURA_H_
#define CHROMECAST_BROWSER_UI_AURA_ACCESSIBILITY_AX_TREE_SOURCE_AURA_H_ #define CHROMECAST_BROWSER_UI_AURA_ACCESSIBILITY_AX_TREE_SOURCE_AURA_H_
#include <stdint.h>
#include <map>
#include <memory> #include <memory>
#include <string>
#include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "ui/accessibility/ax_tree_data.h"
#include "ui/accessibility/ax_tree_source.h"
#include "ui/views/accessibility/ax_root_obj_wrapper.h" #include "ui/views/accessibility/ax_root_obj_wrapper.h"
#include "ui/views/accessibility/ax_tree_source_views.h"
namespace ui {
struct AXActionData;
} // namespace ui
namespace views {
class AXAuraObjWrapper;
} // namespace views
// This class exposes the views hierarchy as an accessibility tree permitting // This class exposes the views hierarchy as an accessibility tree permitting
// use with other accessibility classes. // use with other accessibility classes.
class AXTreeSourceAura : public ui::AXTreeSource<views::AXAuraObjWrapper*, class AXTreeSourceAura : public views::AXTreeSourceViews {
ui::AXNodeData,
ui::AXTreeData> {
public: public:
AXTreeSourceAura(); AXTreeSourceAura();
~AXTreeSourceAura() override; ~AXTreeSourceAura() override;
// Invoke actions on an Aura view. // AXTreeSource:
bool HandleAccessibleAction(const ui::AXActionData& action);
// AXTreeSource implementation.
bool GetTreeData(ui::AXTreeData* data) const override; bool GetTreeData(ui::AXTreeData* data) const override;
views::AXAuraObjWrapper* GetRoot() const override; views::AXAuraObjWrapper* GetRoot() const override;
views::AXAuraObjWrapper* GetFromId(int32_t id) const override;
int32_t GetId(views::AXAuraObjWrapper* node) const override;
void GetChildren(
views::AXAuraObjWrapper* node,
std::vector<views::AXAuraObjWrapper*>* out_children) const override;
views::AXAuraObjWrapper* GetParent(
views::AXAuraObjWrapper* node) const override;
bool IsValid(views::AXAuraObjWrapper* node) const override;
bool IsEqual(views::AXAuraObjWrapper* node1,
views::AXAuraObjWrapper* node2) const override;
views::AXAuraObjWrapper* GetNull() const override;
void SerializeNode(views::AXAuraObjWrapper* node, void SerializeNode(views::AXAuraObjWrapper* node,
ui::AXNodeData* out_data) const override; ui::AXNodeData* out_data) const override;
// Useful for debugging.
std::string ToString(views::AXAuraObjWrapper* root, std::string prefix);
private: private:
std::unique_ptr<AXRootObjWrapper> root_; // A root object representing the entire desktop.
std::unique_ptr<AXRootObjWrapper> desktop_root_;
DISALLOW_COPY_AND_ASSIGN(AXTreeSourceAura); DISALLOW_COPY_AND_ASSIGN(AXTreeSourceAura);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment