Commit 1e66f47c authored by James Cook's avatar James Cook Committed by Commit Bot

Simplify AXTreeSourceViews class hierarchy

Push some functionality down from AXTreeSourceAura and AXTreeSourceMus
into AXTreeSourceViews.

This allows AXTreeSourceViews to completely implement the AXTreeSource
interface, eliminating the weird "subclasses must implement GetRoot"
condition.

Just cleanup, no functional changes.

Bug: 888145
Test: views_unittests, views_mus_unittests
Change-Id: I1c1b2cfa856fe6f5e5bcf8dfff172a7ffb6e5339
Reviewed-on: https://chromium-review.googlesource.com/c/1351776Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611112}
parent 4a5b059d
......@@ -7,23 +7,14 @@
#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"
#include "ui/views/accessibility/ax_view_obj_wrapper.h"
#include "ui/views/controls/webview/webview.h"
AXTreeSourceAura::AXTreeSourceAura()
: desktop_root_(std::make_unique<AXRootObjWrapper>(
AutomationManagerAura::GetInstance())) {}
AXTreeSourceAura::~AXTreeSourceAura() = default;
bool AXTreeSourceAura::GetTreeData(ui::AXTreeData* tree_data) const {
tree_data->tree_id = ui::DesktopAXTreeID();
return AXTreeSourceViews::GetTreeData(tree_data);
AutomationManagerAura::GetInstance())) {
Init(desktop_root_.get(), ui::DesktopAXTreeID());
}
views::AXAuraObjWrapper* AXTreeSourceAura::GetRoot() const {
return desktop_root_.get();
}
AXTreeSourceAura::~AXTreeSourceAura() = default;
void AXTreeSourceAura::SerializeNode(views::AXAuraObjWrapper* node,
ui::AXNodeData* out_data) const {
......
......@@ -19,8 +19,6 @@ class AXTreeSourceAura : public views::AXTreeSourceViews {
~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;
......
......@@ -7,6 +7,8 @@
#include <vector>
#include "ui/accessibility/ax_action_data.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/accessibility/ax_tree_data.h"
#include "ui/accessibility/platform/ax_unique_id.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/transform.h"
......@@ -34,6 +36,7 @@ void AXTreeSourceViews::HandleAccessibleAction(const ui::AXActionData& action) {
}
bool AXTreeSourceViews::GetTreeData(ui::AXTreeData* tree_data) const {
tree_data->tree_id = tree_id_;
tree_data->loaded = true;
tree_data->loading_progress = 1.0;
AXAuraObjWrapper* focus = AXAuraObjCache::GetInstance()->GetFocus();
......@@ -42,6 +45,10 @@ bool AXTreeSourceViews::GetTreeData(ui::AXTreeData* tree_data) const {
return true;
}
AXAuraObjWrapper* AXTreeSourceViews::GetRoot() const {
return root_;
}
AXAuraObjWrapper* AXTreeSourceViews::GetFromId(int32_t id) const {
AXAuraObjWrapper* root = GetRoot();
// Root might not be in the cache.
......@@ -124,4 +131,12 @@ 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
......@@ -6,13 +6,14 @@
#define UI_VIEWS_ACCESSIBILITY_AX_TREE_SOURCE_VIEWS_H_
#include "base/macros.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/accessibility/ax_tree_data.h"
#include "ui/accessibility/ax_tree_id.h"
#include "ui/accessibility/ax_tree_source.h"
#include "ui/views/views_export.h"
namespace ui {
struct AXActionData;
struct AXNodeData;
struct AXTreeData;
}
namespace views {
......@@ -33,7 +34,7 @@ class VIEWS_EXPORT AXTreeSourceViews
// AXTreeSource:
bool GetTreeData(ui::AXTreeData* data) const override;
// GetRoot() must be implemented by subclasses.
AXAuraObjWrapper* GetRoot() const override;
AXAuraObjWrapper* GetFromId(int32_t id) const override;
int32_t GetId(AXAuraObjWrapper* node) const override;
void GetChildren(AXAuraObjWrapper* node,
......@@ -52,7 +53,15 @@ class VIEWS_EXPORT AXTreeSourceViews
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;
// ID to use for the AX tree.
ui::AXTreeID tree_id_;
DISALLOW_COPY_AND_ASSIGN(AXTreeSourceViews);
};
......
......@@ -9,6 +9,7 @@
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/accessibility/ax_tree_data.h"
#include "ui/accessibility/platform/ax_unique_id.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/views/accessibility/ax_aura_obj_cache.h"
......@@ -22,17 +23,16 @@
namespace views {
namespace {
// TestAXTreeSourceViews provides a root object for testing.
// TestAXTreeSourceViews provides a root with a default tree ID.
class TestAXTreeSourceViews : public AXTreeSourceViews {
public:
TestAXTreeSourceViews(AXAuraObjWrapper* root) : root_(root) {}
~TestAXTreeSourceViews() override = default;
TestAXTreeSourceViews(AXAuraObjWrapper* root) {
Init(root, ui::AXTreeID::FromString("123"));
}
// AXTreeSource:
AXAuraObjWrapper* GetRoot() const override { return root_; }
~TestAXTreeSourceViews() override = default;
private:
AXAuraObjWrapper* root_;
DISALLOW_COPY_AND_ASSIGN(TestAXTreeSourceViews);
};
......@@ -71,8 +71,8 @@ class AXTreeSourceViewsTest : public ViewsTestBase {
}
std::unique_ptr<Widget> widget_;
Label* label1_ = nullptr; // Owned by views hierarchy.
Label* label2_ = nullptr; // Owned by views hierarchy.
Label* label1_ = nullptr; // Owned by views hierarchy.
Label* label2_ = nullptr; // Owned by views hierarchy.
Textfield* textfield_ = nullptr; // Owned by views hierarchy.
private:
......
......@@ -4,34 +4,23 @@
#include "ui/views/mus/ax_tree_source_mus.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/transform.h"
#include "ui/views/accessibility/ax_aura_obj_wrapper.h"
#include "ui/views/mus/ax_remote_host.h"
namespace views {
AXTreeSourceMus::AXTreeSourceMus(AXAuraObjWrapper* root,
const ui::AXTreeID& tree_id)
: root_(root), tree_id_(tree_id) {
DCHECK(root_);
DCHECK_NE(tree_id_, ui::AXTreeIDUnknown());
const ui::AXTreeID& tree_id) {
Init(root, tree_id);
}
AXTreeSourceMus::~AXTreeSourceMus() = default;
bool AXTreeSourceMus::GetTreeData(ui::AXTreeData* tree_data) const {
tree_data->tree_id = tree_id_;
return AXTreeSourceViews::GetTreeData(tree_data);
}
AXAuraObjWrapper* AXTreeSourceMus::GetRoot() const {
return root_;
}
void AXTreeSourceMus::SerializeNode(AXAuraObjWrapper* node,
ui::AXNodeData* out_data) const {
if (IsEqual(node, root_)) {
if (IsEqual(node, GetRoot())) {
node->Serialize(out_data);
// Root is a contents view with an offset from the containing Widget.
// However, the contents view in the host (browser) already has an offset
......
......@@ -6,7 +6,6 @@
#define UI_VIEWS_MUS_AX_TREE_SOURCE_MUS_H_
#include "base/macros.h"
#include "ui/accessibility/ax_tree_id.h"
#include "ui/views/accessibility/ax_tree_source_views.h"
#include "ui/views/mus/mus_export.h"
......@@ -27,18 +26,10 @@ class VIEWS_MUS_EXPORT AXTreeSourceMus : public AXTreeSourceViews {
void set_device_scale_factor(float scale) { device_scale_factor_ = scale; }
// AXTreeSource:
bool GetTreeData(ui::AXTreeData* data) const override;
AXAuraObjWrapper* GetRoot() const override;
void SerializeNode(AXAuraObjWrapper* node,
ui::AXNodeData* out_data) const override;
private:
// The top-level object to use for the AX tree.
AXAuraObjWrapper* root_;
// ID to use for the AX tree.
const ui::AXTreeID tree_id_;
// The display device scale factor to use while serializing this update.
float device_scale_factor_ = 1.f;
......
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