Commit 93b6b693 authored by James Cook's avatar James Cook Committed by Commit Bot

Eliminate AXTreeSourceAura by merging into AXTreeSourceViews

This pushes more functionality out of //chrome and down into
//ui/views. It will make it easier to share the code with
//ash, and possibly also for chromecast.

There are AXTreeSourceAura unit tests in //chrome that exercise
the integration of AXTreeSource with AXRootObjWrapper. I left
those in place but converted to ChromeViewsTestBase. This
eliminates a chrome-to-ash dependency. The tests can be moved
into //ui/views in a follow-up CL. I didn't do it now so the
diffs would be easier to read.

BUG=910672
TEST=unit_tests, views_unittests

Change-Id: Ib1483bc6b8e792409b106e0cdd12bff415032ef6
Reviewed-on: https://chromium-review.googlesource.com/c/1357499Reviewed-by: default avatarSergey Volk <servolk@chromium.org>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612870}
parent 8c9abe01
......@@ -2985,8 +2985,6 @@ jumbo_split_static_library("ui") {
sources += [
"aura/accessibility/automation_manager_aura.cc",
"aura/accessibility/automation_manager_aura.h",
"aura/accessibility/ax_tree_source_aura.cc",
"aura/accessibility/ax_tree_source_aura.h",
"aura/native_window_tracker_aura.cc",
"aura/native_window_tracker_aura.h",
"aura/tab_contents/web_drag_bookmark_handler_aura.cc",
......
......@@ -6,10 +6,9 @@
#include <vector>
#include "ash/test/ash_test_base.h"
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/aura/accessibility/ax_tree_source_aura.h"
#include "chrome/test/views/chrome_views_test_base.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/accessibility/ax_action_data.h"
#include "ui/accessibility/ax_enums.mojom.h"
......@@ -20,12 +19,15 @@
#include "ui/aura/window.h"
#include "ui/views/accessibility/ax_aura_obj_cache.h"
#include "ui/views/accessibility/ax_aura_obj_wrapper.h"
#include "ui/views/accessibility/ax_root_obj_wrapper.h"
#include "ui/views/accessibility/ax_tree_source_views.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/widget/widget.h"
using views::AXAuraObjCache;
using views::AXAuraObjWrapper;
using views::AXTreeSourceViews;
using views::Textfield;
using views::View;
using views::Widget;
......@@ -46,20 +48,20 @@ size_t GetSize(AXAuraObjWrapper* tree) {
return count;
}
class AXTreeSourceAuraTest : public ash::AshTestBase {
// Tests integration of AXTreeSourceViews with AXRootObjWrapper.
// TODO(jamescook): Move into //ui/views/accessibility and combine with
// AXTreeSourceViewsTest.
class AXTreeSourceAuraTest : public ChromeViewsTestBase {
public:
AXTreeSourceAuraTest() {}
~AXTreeSourceAuraTest() override {}
void SetUp() override {
AshTestBase::SetUp();
// This code is running outside of Ash.
SetRunningOutsideAsh();
ChromeViewsTestBase::SetUp();
widget_ = new Widget();
Widget::InitParams init_params(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
init_params.context = CurrentContext();
init_params.context = GetContext();
widget_->Init(init_params);
content_ = new View();
......@@ -71,10 +73,18 @@ class AXTreeSourceAuraTest : public ash::AshTestBase {
widget_->Show();
}
void TearDown() override {
// ViewsTestBase requires all Widgets to be closed before shutdown.
widget_->CloseNow();
ChromeViewsTestBase::TearDown();
}
protected:
Widget* widget_;
View* content_;
Textfield* textfield_;
// A simulated desktop root with no delegate.
AXRootObjWrapper root_wrapper_{nullptr};
private:
DISALLOW_COPY_AND_ASSIGN(AXTreeSourceAuraTest);
......@@ -84,7 +94,7 @@ TEST_F(AXTreeSourceAuraTest, Accessors) {
// Focus the textfield so the cursor does not disappear.
textfield_->RequestFocus();
AXTreeSourceAura ax_tree;
AXTreeSourceViews ax_tree(&root_wrapper_, ui::DesktopAXTreeID());
ASSERT_TRUE(ax_tree.GetRoot());
// ID's should be > 0.
......@@ -121,7 +131,7 @@ TEST_F(AXTreeSourceAuraTest, Accessors) {
}
TEST_F(AXTreeSourceAuraTest, DoDefault) {
AXTreeSourceAura ax_tree;
AXTreeSourceViews ax_tree(&root_wrapper_, ui::DesktopAXTreeID());
// Grab a wrapper to |DoDefault| (click).
AXAuraObjWrapper* textfield_wrapper =
......@@ -137,7 +147,7 @@ TEST_F(AXTreeSourceAuraTest, DoDefault) {
}
TEST_F(AXTreeSourceAuraTest, Focus) {
AXTreeSourceAura ax_tree;
AXTreeSourceViews ax_tree(&root_wrapper_, ui::DesktopAXTreeID());
// Grab a wrapper to focus.
AXAuraObjWrapper* textfield_wrapper =
......@@ -153,7 +163,7 @@ TEST_F(AXTreeSourceAuraTest, Focus) {
}
TEST_F(AXTreeSourceAuraTest, Serialize) {
AXTreeSourceAura ax_tree;
AXTreeSourceViews ax_tree(&root_wrapper_, ui::DesktopAXTreeID());
AuraAXTreeSerializer ax_serializer(&ax_tree);
ui::AXTreeUpdate out_update;
......@@ -180,7 +190,7 @@ TEST_F(AXTreeSourceAuraTest, Serialize) {
size_t node_count = out_update2.nodes.size();
// We should have far more updates this time around.
ASSERT_GE(node_count, 10U);
ASSERT_GE(node_count, 8U);
int text_field_update_index = -1;
for (size_t i = 0; i < node_count; ++i) {
......@@ -194,7 +204,7 @@ TEST_F(AXTreeSourceAuraTest, Serialize) {
}
TEST_F(AXTreeSourceAuraTest, SerializeWindowSetsClipsChildren) {
AXTreeSourceAura ax_tree;
AXTreeSourceViews ax_tree(&root_wrapper_, ui::DesktopAXTreeID());
AuraAXTreeSerializer ax_serializer(&ax_tree);
AXAuraObjWrapper* widget_wrapper =
AXAuraObjCache::GetInstance()->GetOrCreate(widget_);
......
......@@ -22,6 +22,7 @@
#include "ui/aura/window_tree_host.h"
#include "ui/views/accessibility/ax_aura_obj_wrapper.h"
#include "ui/views/accessibility/ax_event_manager.h"
#include "ui/views/accessibility/ax_root_obj_wrapper.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
......@@ -173,8 +174,11 @@ AutomationManagerAura::~AutomationManagerAura() {
}
void AutomationManagerAura::Reset(bool reset_serializer) {
if (!current_tree_)
current_tree_.reset(new AXTreeSourceAura());
if (!current_tree_) {
desktop_root_ = std::make_unique<AXRootObjWrapper>(this);
current_tree_ = std::make_unique<views::AXTreeSourceViews>(
desktop_root_.get(), ui::DesktopAXTreeID());
}
reset_serializer ? current_tree_serializer_.reset()
: current_tree_serializer_.reset(
new AuraAXTreeSerializer(current_tree_.get()));
......
......@@ -14,11 +14,13 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/aura/accessibility/ax_tree_source_aura.h"
#include "ui/accessibility/ax_host_delegate.h"
#include "ui/accessibility/ax_tree_serializer.h"
#include "ui/views/accessibility/ax_aura_obj_cache.h"
#include "ui/views/accessibility/ax_event_observer.h"
#include "ui/views/accessibility/ax_tree_source_views.h"
class AXRootObjWrapper;
namespace base {
template <typename T>
......@@ -94,10 +96,13 @@ class AutomationManagerAura : public ui::AXHostDelegate,
// Whether automation support for views is enabled.
bool enabled_;
// Root object representing the entire desktop. Must outlive |current_tree_|.
std::unique_ptr<AXRootObjWrapper> desktop_root_;
// Holds the active views-based accessibility tree. A tree currently consists
// of all views descendant to a |Widget| (see |AXTreeSourceViews|).
// A tree becomes active when an event is fired on a descendant view.
std::unique_ptr<AXTreeSourceAura> current_tree_;
std::unique_ptr<views::AXTreeSourceViews> current_tree_;
// Serializes incremental updates on the currently active tree
// |current_tree_|.
......
......@@ -16,17 +16,19 @@
#include "content/public/test/browser_test_utils.h"
#include "extensions/common/extension_messages.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/views/accessibility/ax_aura_obj_wrapper.h"
#include "ui/views/accessibility/ax_tree_source_views.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
namespace {
// Given an AXTreeSourceAura and a node within that tree, recursively search
// Given an AXTreeSourceViews and a node within that tree, recursively search
// for all nodes who have a child tree id of |target_ax_tree_id|, meaning
// that they're a parent of a particular web contents.
void FindAllHostsOfWebContentsWithAXTreeID(
AXTreeSourceAura* tree,
views::AXTreeSourceViews* tree,
views::AXAuraObjWrapper* node,
ui::AXTreeID target_ax_tree_id,
std::vector<views::AXAuraObjWrapper*>* web_hosts) {
......
// Copyright 2014 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/ui/aura/accessibility/ax_tree_source_aura.h"
#include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h"
#include "ui/accessibility/ax_tree_id.h"
#include "ui/views/accessibility/ax_aura_obj_wrapper.h"
AXTreeSourceAura::AXTreeSourceAura()
: desktop_root_(std::make_unique<AXRootObjWrapper>(
AutomationManagerAura::GetInstance())) {
Init(desktop_root_.get(), ui::DesktopAXTreeID());
}
AXTreeSourceAura::~AXTreeSourceAura() = default;
void AXTreeSourceAura::SerializeNode(views::AXAuraObjWrapper* node,
ui::AXNodeData* out_data) const {
AXTreeSourceViews::SerializeNode(node, out_data);
if (out_data->role == ax::mojom::Role::kWindow ||
out_data->role == ax::mojom::Role::kDialog) {
// Add clips children flag by default to these roles.
out_data->AddBoolAttribute(ax::mojom::BoolAttribute::kClipsChildren, true);
}
}
// Copyright 2014 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.
#ifndef CHROME_BROWSER_UI_AURA_ACCESSIBILITY_AX_TREE_SOURCE_AURA_H_
#define CHROME_BROWSER_UI_AURA_ACCESSIBILITY_AX_TREE_SOURCE_AURA_H_
#include <memory>
#include "base/macros.h"
#include "ui/views/accessibility/ax_root_obj_wrapper.h"
#include "ui/views/accessibility/ax_tree_source_views.h"
// This class exposes the views hierarchy as an accessibility tree permitting
// use with other accessibility classes.
class AXTreeSourceAura : public views::AXTreeSourceViews {
public:
AXTreeSourceAura();
~AXTreeSourceAura() override;
// AXTreeSource:
void SerializeNode(views::AXAuraObjWrapper* node,
ui::AXNodeData* out_data) const override;
private:
// A root object representing the entire desktop.
std::unique_ptr<AXRootObjWrapper> desktop_root_;
DISALLOW_COPY_AND_ASSIGN(AXTreeSourceAura);
};
#endif // CHROME_BROWSER_UI_AURA_ACCESSIBILITY_AX_TREE_SOURCE_AURA_H_
......@@ -24,6 +24,7 @@
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/views/accessibility/ax_aura_obj_wrapper.h"
#include "ui/views/accessibility/ax_root_obj_wrapper.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
......@@ -123,8 +124,11 @@ AutomationManagerAura::AutomationManagerAura()
AutomationManagerAura::~AutomationManagerAura() {}
void AutomationManagerAura::Reset(bool reset_serializer) {
if (!current_tree_)
current_tree_.reset(new AXTreeSourceAura());
if (!current_tree_) {
desktop_root_ = std::make_unique<AXRootObjWrapper>(this);
current_tree_ = std::make_unique<AXTreeSourceAura>(desktop_root_.get(),
ui::DesktopAXTreeID());
}
reset_serializer ? current_tree_serializer_.reset()
: current_tree_serializer_.reset(
new AuraAXTreeSerializer(current_tree_.get()));
......
......@@ -18,6 +18,8 @@
#include "ui/accessibility/ax_tree_serializer.h"
#include "ui/views/accessibility/ax_aura_obj_cache.h"
class AXRootObjWrapper;
namespace base {
template <typename T>
struct DefaultSingletonTraits;
......@@ -83,6 +85,9 @@ class AutomationManagerAura : public ui::AXHostDelegate,
// Whether automation support for views is enabled.
bool enabled_;
// Root object representing the entire desktop. Must outlive |current_tree_|.
std::unique_ptr<AXRootObjWrapper> desktop_root_;
// Holds the active views-based accessibility tree. A tree currently consists
// of all views descendant to a |Widget| (see |AXTreeSourceViews|).
// A tree becomes active when an event is fired on a descendant view.
......
......@@ -4,23 +4,18 @@
#include "chromecast/browser/ui/aura/accessibility/ax_tree_source_aura.h"
#include <stddef.h>
#include "chromecast/browser/ui/aura/accessibility/automation_manager_aura.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "ui/accessibility/ax_action_data.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/accessibility/ax_tree_data.h"
#include "ui/views/accessibility/ax_aura_obj_wrapper.h"
#include "ui/views/accessibility/ax_view_obj_wrapper.h"
AXTreeSourceAura::AXTreeSourceAura()
: desktop_root_(std::make_unique<AXRootObjWrapper>(
AutomationManagerAura::GetInstance())) {}
AXTreeSourceAura::AXTreeSourceAura(views::AXAuraObjWrapper* root,
const ui::AXTreeID& tree_id)
: AXTreeSourceViews(root, tree_id) {}
AXTreeSourceAura::~AXTreeSourceAura() = default;
bool AXTreeSourceAura::GetTreeData(ui::AXTreeData* tree_data) const {
tree_data->tree_id = ui::DesktopAXTreeID();
AXTreeSourceViews::GetTreeData(tree_data);
// TODO(b/111911092): AXTreeData::focus_id represents the node within the
......@@ -39,10 +34,6 @@ bool AXTreeSourceAura::GetTreeData(ui::AXTreeData* tree_data) const {
return true;
}
views::AXAuraObjWrapper* AXTreeSourceAura::GetRoot() const {
return desktop_root_.get();
}
void AXTreeSourceAura::SerializeNode(views::AXAuraObjWrapper* node,
ui::AXNodeData* out_data) const {
AXTreeSourceViews::SerializeNode(node, out_data);
......@@ -51,10 +42,5 @@ void AXTreeSourceAura::SerializeNode(views::AXAuraObjWrapper* node,
// TODO(rmrossi) : Figure out whether this will ever be required
// for chromecast.
LOG(FATAL) << "Unhandled role";
} else if (out_data->role == ax::mojom::Role::kWindow ||
out_data->role == ax::mojom::Role::kDialog) {
// Add clips children flag by default to these roles.
out_data->AddBoolAttribute(ax::mojom::BoolAttribute::kClipsChildren, true);
}
}
......@@ -8,26 +8,21 @@
#include <memory>
#include "base/macros.h"
#include "ui/views/accessibility/ax_root_obj_wrapper.h"
#include "ui/views/accessibility/ax_tree_source_views.h"
// This class exposes the views hierarchy as an accessibility tree permitting
// use with other accessibility classes.
class AXTreeSourceAura : public views::AXTreeSourceViews {
public:
AXTreeSourceAura();
AXTreeSourceAura(views::AXAuraObjWrapper* root, const ui::AXTreeID& tree_id);
~AXTreeSourceAura() override;
// AXTreeSource:
bool GetTreeData(ui::AXTreeData* data) const override;
views::AXAuraObjWrapper* GetRoot() const override;
void SerializeNode(views::AXAuraObjWrapper* node,
ui::AXNodeData* out_data) const override;
private:
// A root object representing the entire desktop.
std::unique_ptr<AXRootObjWrapper> desktop_root_;
DISALLOW_COPY_AND_ASSIGN(AXTreeSourceAura);
};
......
......@@ -17,6 +17,15 @@
namespace views {
AXTreeSourceViews::AXTreeSourceViews(AXAuraObjWrapper* root,
const ui::AXTreeID& tree_id)
: root_(root), tree_id_(tree_id) {
DCHECK(root_);
DCHECK_NE(tree_id_, ui::AXTreeIDUnknown());
}
AXTreeSourceViews::~AXTreeSourceViews() = default;
void AXTreeSourceViews::HandleAccessibleAction(const ui::AXActionData& action) {
int id = action.target_node_id;
......@@ -96,6 +105,12 @@ void AXTreeSourceViews::SerializeNode(AXAuraObjWrapper* node,
ui::AXNodeData* out_data) const {
node->Serialize(out_data);
if (out_data->role == ax::mojom::Role::kWindow ||
out_data->role == ax::mojom::Role::kDialog) {
// Add clips children flag by default to these roles.
out_data->AddBoolAttribute(ax::mojom::BoolAttribute::kClipsChildren, true);
}
// Converts 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
......@@ -127,16 +142,4 @@ std::string AXTreeSourceViews::ToString(AXAuraObjWrapper* root,
return output;
}
AXTreeSourceViews::AXTreeSourceViews() = default;
AXTreeSourceViews::~AXTreeSourceViews() = default;
void AXTreeSourceViews::Init(AXAuraObjWrapper* root,
const ui::AXTreeID& tree_id) {
DCHECK(root);
DCHECK_NE(tree_id, ui::AXTreeIDUnknown());
root_ = root;
tree_id_ = tree_id;
}
} // namespace views
......@@ -29,6 +29,9 @@ class VIEWS_EXPORT AXTreeSourceViews
: public ui::
AXTreeSource<AXAuraObjWrapper*, ui::AXNodeData, ui::AXTreeData> {
public:
AXTreeSourceViews(AXAuraObjWrapper* root, const ui::AXTreeID& tree_id);
~AXTreeSourceViews() override;
// Invokes an action on an Aura object.
void HandleAccessibleAction(const ui::AXActionData& action);
......@@ -49,18 +52,12 @@ class VIEWS_EXPORT AXTreeSourceViews
// Useful for debugging.
std::string ToString(views::AXAuraObjWrapper* root, std::string prefix);
protected:
AXTreeSourceViews();
~AXTreeSourceViews() override;
void Init(AXAuraObjWrapper* root, const ui::AXTreeID& tree_id);
private:
// The top-level object to use for the AX tree. See class comment.
AXAuraObjWrapper* root_ = nullptr;
AXAuraObjWrapper* const root_ = nullptr;
// ID to use for the AX tree.
ui::AXTreeID tree_id_;
const ui::AXTreeID tree_id_;
DISALLOW_COPY_AND_ASSIGN(AXTreeSourceViews);
};
......
......@@ -26,9 +26,8 @@ namespace {
// TestAXTreeSourceViews provides a root with a default tree ID.
class TestAXTreeSourceViews : public AXTreeSourceViews {
public:
TestAXTreeSourceViews(AXAuraObjWrapper* root) {
Init(root, ui::AXTreeID::FromString("123"));
}
TestAXTreeSourceViews(AXAuraObjWrapper* root)
: AXTreeSourceViews(root, ui::AXTreeID::FromString("123")) {}
~TestAXTreeSourceViews() override = default;
......
......@@ -12,9 +12,8 @@
namespace views {
AXTreeSourceMus::AXTreeSourceMus(AXAuraObjWrapper* root,
const ui::AXTreeID& tree_id) {
Init(root, tree_id);
}
const ui::AXTreeID& tree_id)
: AXTreeSourceViews(root, tree_id) {}
AXTreeSourceMus::~AXTreeSourceMus() = default;
......
......@@ -16,7 +16,7 @@ class AXAuraObjWrapper;
// This class exposes the views hierarchy as an accessibility tree permitting
// use with other accessibility classes. Only used for out-of-process views
// apps (e.g. Chrome OS shortcut_viewer app). The browser process uses
// AXTreeSourceAura.
// AXTreeSourceViews directly.
class VIEWS_MUS_EXPORT AXTreeSourceMus : public AXTreeSourceViews {
public:
// |root| must outlive this object.
......
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