summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-30 21:22:07 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-30 21:22:07 +0000
commit5f7e2b3d7e0212322d3b06b9623e9adb6ef37e67 (patch)
treed169d3dfe15aee1dd21ec7483747ea0da24d66d2
parente0b0abd0cd90ba1ce625bba08fe151c999bf3255 (diff)
downloadchromium_src-5f7e2b3d7e0212322d3b06b9623e9adb6ef37e67.zip
chromium_src-5f7e2b3d7e0212322d3b06b9623e9adb6ef37e67.tar.gz
chromium_src-5f7e2b3d7e0212322d3b06b9623e9adb6ef37e67.tar.bz2
Revert 267297 "Extend AXTreeSourceViews to handle aura::Window a..."
> Extend AXTreeSourceViews to handle aura::Window and views::Widget. > > > initial patch > > BUG= > > Review URL: https://codereview.chromium.org/246433012 TBR=dtseng@chromium.org Review URL: https://codereview.chromium.org/264693002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267336 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/ash/accessibility/OWNERS2
-rw-r--r--chrome/browser/ui/ash/accessibility/ax_root_obj_wrapper.cc48
-rw-r--r--chrome/browser/ui/ash/accessibility/ax_root_obj_wrapper.h32
-rw-r--r--chrome/browser/ui/ash/accessibility/ax_tree_source_views.cc85
-rw-r--r--chrome/browser/ui/ash/accessibility/ax_tree_source_views.h51
-rw-r--r--chrome/browser/ui/ash/accessibility/ax_tree_source_views_unittest.cc137
-rw-r--r--chrome/browser/ui/views/accessibility/automation_manager_views.cc (renamed from chrome/browser/ui/ash/accessibility/automation_manager_views.cc)39
-rw-r--r--chrome/browser/ui/views/accessibility/automation_manager_views.h (renamed from chrome/browser/ui/ash/accessibility/automation_manager_views.h)23
-rw-r--r--chrome/browser/ui/views/chrome_views_delegate.cc4
-rw-r--r--chrome/chrome_browser_ui.gypi8
-rw-r--r--chrome/chrome_tests_unit.gypi1
-rw-r--r--chrome/renderer/resources/extensions/automation_custom_bindings.js2
-rw-r--r--ui/accessibility/ax_enums.idl1
-rw-r--r--ui/accessibility/ax_view_state.h7
-rw-r--r--ui/views/accessibility/ax_aura_obj_cache.cc126
-rw-r--r--ui/views/accessibility/ax_aura_obj_cache.h83
-rw-r--r--ui/views/accessibility/ax_aura_obj_wrapper.h36
-rw-r--r--ui/views/accessibility/ax_tree_source_views.cc156
-rw-r--r--ui/views/accessibility/ax_tree_source_views.h56
-rw-r--r--ui/views/accessibility/ax_tree_source_views_unittest.cc85
-rw-r--r--ui/views/accessibility/ax_view_obj_wrapper.cc65
-rw-r--r--ui/views/accessibility/ax_view_obj_wrapper.h34
-rw-r--r--ui/views/accessibility/ax_widget_obj_wrapper.cc55
-rw-r--r--ui/views/accessibility/ax_widget_obj_wrapper.h44
-rw-r--r--ui/views/accessibility/ax_window_obj_wrapper.cc64
-rw-r--r--ui/views/accessibility/ax_window_obj_wrapper.h42
-rw-r--r--ui/views/views.gyp12
27 files changed, 327 insertions, 971 deletions
diff --git a/chrome/browser/ui/ash/accessibility/OWNERS b/chrome/browser/ui/ash/accessibility/OWNERS
deleted file mode 100644
index 11e8fd8..0000000
--- a/chrome/browser/ui/ash/accessibility/OWNERS
+++ /dev/null
@@ -1,2 +0,0 @@
-dmazzoni@chromium.org
-dtseng@chromium.org
diff --git a/chrome/browser/ui/ash/accessibility/ax_root_obj_wrapper.cc b/chrome/browser/ui/ash/accessibility/ax_root_obj_wrapper.cc
deleted file mode 100644
index 39a5b8d..0000000
--- a/chrome/browser/ui/ash/accessibility/ax_root_obj_wrapper.cc
+++ /dev/null
@@ -1,48 +0,0 @@
-// 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/ash/accessibility/ax_root_obj_wrapper.h"
-
-#include "ash/shell.h"
-#include "ui/accessibility/ax_node_data.h"
-#include "ui/accessibility/ax_view_state.h"
-#include "ui/aura/window.h"
-#include "ui/views/accessibility/ax_aura_obj_cache.h"
-
-AXRootObjWrapper::AXRootObjWrapper(int32 id) : id_(id) {
-}
-
-AXRootObjWrapper::~AXRootObjWrapper() {}
-
-bool AXRootObjWrapper::HasChild(views::AXAuraObjWrapper* child) {
- std::vector<views::AXAuraObjWrapper*> children;
- GetChildren(&children);
- return std::find(children.begin(), children.end(), child) != children.end();
-}
-
-views::AXAuraObjWrapper* AXRootObjWrapper::GetParent() {
- return NULL;
-}
-
-void AXRootObjWrapper::GetChildren(
- std::vector<views::AXAuraObjWrapper*>* out_children) {
- // Only on ash is there a notion of a root with children.
- aura::Window::Windows children =
- ash::Shell::GetInstance()->GetAllRootWindows();
- for (size_t i = 0; i < children.size(); ++i) {
- out_children->push_back(
- views::AXAuraObjCache::GetInstance()->GetOrCreate(children[i]));
- }
-}
-
-void AXRootObjWrapper::Serialize(ui::AXNodeData* out_node_data) {
- out_node_data->id = id_;
- out_node_data->role = ui::AX_ROLE_DESKTOP;
- // TODO(dtseng): Apply a richer set of states.
- out_node_data->state = 0;
-}
-
-int32 AXRootObjWrapper::GetID() {
- return id_;
-}
diff --git a/chrome/browser/ui/ash/accessibility/ax_root_obj_wrapper.h b/chrome/browser/ui/ash/accessibility/ax_root_obj_wrapper.h
deleted file mode 100644
index d75c377..0000000
--- a/chrome/browser/ui/ash/accessibility/ax_root_obj_wrapper.h
+++ /dev/null
@@ -1,32 +0,0 @@
-// 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_ASH_ACCESSIBILITY_AX_ROOT_OBJ_WRAPPER_H_
-#define CHROME_BROWSER_UI_ASH_ACCESSIBILITY_AX_ROOT_OBJ_WRAPPER_H_
-
-#include "base/basictypes.h"
-#include "ui/views/accessibility/ax_aura_obj_wrapper.h"
-
-class AXRootObjWrapper : public views::AXAuraObjWrapper {
- public:
- explicit AXRootObjWrapper(int32 id);
- virtual ~AXRootObjWrapper();
-
- // Convenience method to check for existence of a child.
- bool HasChild(views::AXAuraObjWrapper* child);
-
- // views::AXAuraObjWrapper overrides.
- virtual views::AXAuraObjWrapper* GetParent() OVERRIDE;
- virtual void GetChildren(
- std::vector<views::AXAuraObjWrapper*>* out_children) OVERRIDE;
- virtual void Serialize(ui::AXNodeData* out_node_data) OVERRIDE;
- virtual int32 GetID() OVERRIDE;
-
- private:
- int32 id_;
-
- DISALLOW_COPY_AND_ASSIGN(AXRootObjWrapper);
-};
-
-#endif // CHROME_BROWSER_UI_ASH_ACCESSIBILITY_AX_ROOT_OBJ_WRAPPER_H_
diff --git a/chrome/browser/ui/ash/accessibility/ax_tree_source_views.cc b/chrome/browser/ui/ash/accessibility/ax_tree_source_views.cc
deleted file mode 100644
index 820310a..0000000
--- a/chrome/browser/ui/ash/accessibility/ax_tree_source_views.cc
+++ /dev/null
@@ -1,85 +0,0 @@
-// 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/ash/accessibility/ax_tree_source_views.h"
-
-#include <vector>
-
-#include "ui/views/accessibility/ax_aura_obj_cache.h"
-#include "ui/views/accessibility/ax_aura_obj_wrapper.h"
-
-using views::AXAuraObjCache;
-using views::AXAuraObjWrapper;
-
-AXTreeSourceViews::AXTreeSourceViews() {
- root_.reset(
- new AXRootObjWrapper(AXAuraObjCache::GetInstance()->GetNextID()));
-}
-
-AXTreeSourceViews::~AXTreeSourceViews() {
- root_.reset();
-}
-
-AXAuraObjWrapper* AXTreeSourceViews::GetRoot() const {
- return root_.get();
-}
-
-AXAuraObjWrapper* AXTreeSourceViews::GetFromId(int32 id) const {
- if (id == root_->GetID())
- return root_.get();
- return AXAuraObjCache::GetInstance()->Get(id);
-}
-
-int32 AXTreeSourceViews::GetId(AXAuraObjWrapper* node) const {
- return node->GetID();
-}
-
-void AXTreeSourceViews::GetChildren(AXAuraObjWrapper* node,
- std::vector<AXAuraObjWrapper*>* out_children) const {
- node->GetChildren(out_children);
-}
-
-AXAuraObjWrapper* AXTreeSourceViews::GetParent(AXAuraObjWrapper* node) const {
- AXAuraObjWrapper* parent = node->GetParent();
- if (!parent && root_->HasChild(node))
- parent = root_.get();
- return parent;
-}
-
-bool AXTreeSourceViews::IsValid(AXAuraObjWrapper* node) const {
- return node && node->GetID() != -1;
-}
-
-bool AXTreeSourceViews::IsEqual(AXAuraObjWrapper* node1,
- AXAuraObjWrapper* node2) const {
- if (!node1 || !node2)
- return false;
-
- return node1->GetID() == node2->GetID() && node1->GetID() != -1;
-}
-
-AXAuraObjWrapper* AXTreeSourceViews::GetNull() const {
- return NULL;
-}
-
-void AXTreeSourceViews::SerializeNode(
- AXAuraObjWrapper* node, ui::AXNodeData* out_data) const {
- node->Serialize(out_data);
-}
-
-std::string AXTreeSourceViews::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;
-}
diff --git a/chrome/browser/ui/ash/accessibility/ax_tree_source_views.h b/chrome/browser/ui/ash/accessibility/ax_tree_source_views.h
deleted file mode 100644
index 5a1a6d0..0000000
--- a/chrome/browser/ui/ash/accessibility/ax_tree_source_views.h
+++ /dev/null
@@ -1,51 +0,0 @@
-// 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_ASH_ACCESSIBILITY_AX_TREE_SOURCE_VIEWS_H_
-#define CHROME_BROWSER_UI_ASH_ACCESSIBILITY_AX_TREE_SOURCE_VIEWS_H_
-
-#include <map>
-
-#include "base/basictypes.h"
-#include "base/memory/scoped_ptr.h"
-#include "chrome/browser/ui/ash/accessibility/ax_root_obj_wrapper.h"
-#include "ui/accessibility/ax_tree_source.h"
-
-namespace views {
-class AXAuraObjWrapper;
-} // namespace views
-
-// This class exposes the views hierarchy as an accessibility tree permitting
-// use with other accessibility classes.
-class AXTreeSourceViews
- : public ui::AXTreeSource<views::AXAuraObjWrapper*> {
- public:
- AXTreeSourceViews();
- virtual ~AXTreeSourceViews();
-
- // AXTreeSource implementation.
- virtual views::AXAuraObjWrapper* GetRoot() const OVERRIDE;
- virtual views::AXAuraObjWrapper* GetFromId(int32 id) const OVERRIDE;
- virtual int32 GetId(views::AXAuraObjWrapper* node) const OVERRIDE;
- virtual void GetChildren(views::AXAuraObjWrapper* node,
- std::vector<views::AXAuraObjWrapper*>* out_children) const OVERRIDE;
- virtual views::AXAuraObjWrapper* GetParent(
- views::AXAuraObjWrapper* node) const OVERRIDE;
- virtual bool IsValid(views::AXAuraObjWrapper* node) const OVERRIDE;
- virtual bool IsEqual(views::AXAuraObjWrapper* node1,
- views::AXAuraObjWrapper* node2) const OVERRIDE;
- virtual views::AXAuraObjWrapper* GetNull() const OVERRIDE;
- virtual void SerializeNode(
- views::AXAuraObjWrapper* node, ui::AXNodeData* out_data) const OVERRIDE;
-
- // Useful for debugging.
- std::string ToString(views::AXAuraObjWrapper* root, std::string prefix);
-
- private:
- scoped_ptr<AXRootObjWrapper> root_;
-
- DISALLOW_COPY_AND_ASSIGN(AXTreeSourceViews);
-};
-
-#endif // CHROME_BROWSER_UI_ASH_ACCESSIBILITY_AX_TREE_SOURCE_VIEWS_H_
diff --git a/chrome/browser/ui/ash/accessibility/ax_tree_source_views_unittest.cc b/chrome/browser/ui/ash/accessibility/ax_tree_source_views_unittest.cc
deleted file mode 100644
index b1d2570..0000000
--- a/chrome/browser/ui/ash/accessibility/ax_tree_source_views_unittest.cc
+++ /dev/null
@@ -1,137 +0,0 @@
-// 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 <vector>
-
-#include "ash/test/ash_test_base.h"
-#include "base/strings/utf_string_conversions.h"
-#include "chrome/browser/ui/ash/accessibility/ax_tree_source_views.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/accessibility/ax_enums.h"
-#include "ui/accessibility/ax_node.h"
-#include "ui/accessibility/ax_serializable_tree.h"
-#include "ui/accessibility/ax_tree_serializer.h"
-#include "ui/accessibility/ax_tree_update.h"
-#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/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::Textfield;
-using views::View;
-using views::Widget;
-
-// Helper to count the number of nodes in a tree.
-size_t GetSize(AXAuraObjWrapper* tree) {
- size_t count = 1;
-
- std::vector<AXAuraObjWrapper*> out_children;
- tree->GetChildren(&out_children);
-
- for (size_t i = 0; i < out_children.size(); ++i)
- count += GetSize(out_children[i]);
-
- return count;
-}
-
-class AXTreeSourceViewsTest : public ash::test::AshTestBase {
- public:
- AXTreeSourceViewsTest() {}
- virtual ~AXTreeSourceViewsTest() {}
-
- virtual void SetUp() OVERRIDE {
- AshTestBase::SetUp();
-
- widget_ = new Widget();
- Widget::InitParams init_params(Widget::InitParams::TYPE_POPUP);
- init_params.parent = CurrentContext();
- widget_->Init(init_params);
-
- content_ = new View();
- widget_->SetContentsView(content_);
-
- textfield_ = new Textfield();
- textfield_->SetText(base::ASCIIToUTF16("Value"));
- content_->AddChildView(textfield_);
- }
-
- protected:
- Widget* widget_;
- View* content_;
- Textfield* textfield_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(AXTreeSourceViewsTest);
-};
-
-TEST_F(AXTreeSourceViewsTest, Accessors) {
- AXTreeSourceViews ax_tree;
- ASSERT_TRUE(ax_tree.GetRoot());
-
- // ID's should start at 1 and there should be a root.
- ASSERT_EQ(1, ax_tree.GetRoot()->GetID());
-
- // Grab the content view directly from cache to avoid walking down the tree.
- AXAuraObjWrapper* content =
- AXAuraObjCache::GetInstance()->GetOrCreate(content_);
- std::vector<AXAuraObjWrapper*> content_children;
- ax_tree.GetChildren(content, &content_children);
- ASSERT_EQ(1U, content_children.size());
-
- // Walk down to the text field and assert it is what we expect.
- AXAuraObjWrapper* textfield = content_children[0];
- AXAuraObjWrapper* cached_textfield =
- AXAuraObjCache::GetInstance()->GetOrCreate(textfield_);
- ASSERT_EQ(cached_textfield, textfield);
- std::vector<AXAuraObjWrapper*> textfield_children;
- ax_tree.GetChildren(textfield, &textfield_children);
- ASSERT_EQ(0U, textfield_children.size());
-
- ASSERT_EQ(content, textfield->GetParent());
-
- // Try walking up the tree to the root.
- AXAuraObjWrapper* root_finder = content;
- AXAuraObjWrapper* test_root = NULL;
- while ((root_finder = ax_tree.GetParent(root_finder)))
- test_root = root_finder;
- ASSERT_EQ(ax_tree.GetRoot(), test_root);
-}
-
-TEST_F(AXTreeSourceViewsTest, Serialization) {
- AXTreeSourceViews ax_tree;
- ui::AXTreeSerializer<AXAuraObjWrapper*> ax_serializer(&ax_tree);
- ui::AXTreeUpdate out_update;
-
- // This is the initial serialization.
- ax_serializer.SerializeChanges(ax_tree.GetRoot(), &out_update);
-
- // We should get an update per node.
- ASSERT_EQ(GetSize(ax_tree.GetRoot()), out_update.nodes.size());
-
- // Try removing some child views and re-adding.
- content_->RemoveAllChildViews(false /* delete_children */);
- content_->AddChildView(textfield_);
-
- // Grab the textfield since serialization only walks up the tree (not down
- // from root).
- AXAuraObjWrapper* textfield_wrapper =
- AXAuraObjCache::GetInstance()->GetOrCreate(textfield_);
-
- // Now, re-serialize.
- ui::AXTreeUpdate out_update2;
- ax_serializer.SerializeChanges(textfield_wrapper, &out_update2);
-
- // We should have far fewer updates this time around.
- ASSERT_EQ(2U, out_update2.nodes.size());
- ASSERT_EQ(ui::AX_ROLE_CLIENT,
- out_update2.nodes[0].role);
-
- ASSERT_EQ(textfield_wrapper->GetID(), out_update2.nodes[1].id);
- ASSERT_EQ(ui::AX_ROLE_TEXT_FIELD,
- out_update2.nodes[1].role);
-}
diff --git a/chrome/browser/ui/ash/accessibility/automation_manager_views.cc b/chrome/browser/ui/views/accessibility/automation_manager_views.cc
index 92c8085..9b4812e 100644
--- a/chrome/browser/ui/ash/accessibility/automation_manager_views.cc
+++ b/chrome/browser/ui/views/accessibility/automation_manager_views.cc
@@ -2,18 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/ui/ash/accessibility/automation_manager_views.h"
+#include "chrome/browser/ui/views/accessibility/automation_manager_views.h"
#include <vector>
+#include "base/command_line.h"
#include "base/memory/singleton.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/automation_internal/automation_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/common/chrome_switches.h"
#include "content/public/browser/ax_event_notification_details.h"
-#include "ui/views/accessibility/ax_aura_obj_cache.h"
-#include "ui/views/accessibility/ax_aura_obj_wrapper.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
@@ -22,21 +22,11 @@ AutomationManagerViews* AutomationManagerViews::GetInstance() {
return Singleton<AutomationManagerViews>::get();
}
-void AutomationManagerViews::Enable() {
- enabled_ = true;
- if (current_tree_serializer_.get())
- current_tree_serializer_->Reset();
-}
-
-void AutomationManagerViews::Disable() {
- enabled_ = false;
- current_tree_serializer_->Reset();
-}
-
void AutomationManagerViews::HandleEvent(Profile* profile,
views::View* view,
ui::AXEvent event_type) {
- if (!enabled_) {
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableAutomationAPI)) {
return;
}
@@ -54,24 +44,25 @@ void AutomationManagerViews::HandleEvent(Profile* profile,
return;
}
- if (!current_tree_.get()) {
- current_tree_.reset(new AXTreeSourceViews());
+ if (!current_tree_.get() ||
+ current_tree_->GetRoot()->GetWidget() != widget) {
+ current_tree_.reset(new views::AXTreeSourceViews(widget));
current_tree_serializer_.reset(
- new ui::AXTreeSerializer<views::AXAuraObjWrapper*>(
- current_tree_.get()));
+ new ui::AXTreeSerializer<views::View*>(current_tree_.get()));
+ // TODO(dtseng): Need to send a load complete and clear any previous desktop
+ // trees.
}
ui::AXTreeUpdate out_update;
- views::AXAuraObjWrapper* aura_obj =
- views::AXAuraObjCache::GetInstance()->GetOrCreate(view);
- current_tree_serializer_->SerializeChanges(aura_obj, &out_update);
+ current_tree_serializer_->SerializeChanges(view, &out_update);
// Route this event to special process/routing ids recognized by the
// Automation API as the desktop tree.
+
// TODO(dtseng): Would idealy define these special desktop constants in idl.
content::AXEventNotificationDetails detail(out_update.nodes,
event_type,
- aura_obj->GetID(),
+ current_tree_->GetId(view),
0, /* process_id */
0 /* routing_id */);
std::vector<content::AXEventNotificationDetails> details;
@@ -80,6 +71,6 @@ void AutomationManagerViews::HandleEvent(Profile* profile,
details, profile);
}
-AutomationManagerViews::AutomationManagerViews() : enabled_(false) {}
+AutomationManagerViews::AutomationManagerViews() {}
AutomationManagerViews:: ~AutomationManagerViews() {}
diff --git a/chrome/browser/ui/ash/accessibility/automation_manager_views.h b/chrome/browser/ui/views/accessibility/automation_manager_views.h
index af34ff7..d2592ae 100644
--- a/chrome/browser/ui/ash/accessibility/automation_manager_views.h
+++ b/chrome/browser/ui/views/accessibility/automation_manager_views.h
@@ -2,21 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_UI_ASH_ACCESSIBILITY_AUTOMATION_MANAGER_VIEWS_H_
-#define CHROME_BROWSER_UI_ASH_ACCESSIBILITY_AUTOMATION_MANAGER_VIEWS_H_
+#ifndef CHROME_BROWSER_UI_VIEWS_ACCESSIBILITY_AUTOMATION_MANAGER_VIEWS_H_
+#define CHROME_BROWSER_UI_VIEWS_ACCESSIBILITY_AUTOMATION_MANAGER_VIEWS_H_
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
-#include "chrome/browser/ui/ash/accessibility/ax_tree_source_views.h"
#include "ui/accessibility/ax_tree_serializer.h"
+#include "ui/views/accessibility/ax_tree_source_views.h"
template <typename T> struct DefaultSingletonTraits;
class Profile;
namespace views {
-class AXAuraObjWrapper;
class View;
} // namespace views
@@ -26,12 +25,6 @@ class AutomationManagerViews {
// Get the single instance of this class.
static AutomationManagerViews* GetInstance();
- // Enable automation support for views.
- void Enable();
-
- // Disable automation support for views.
- void Disable();
-
// Handle an event fired upon a |View|.
void HandleEvent(Profile* profile, views::View* view, ui::AXEvent event_type);
@@ -41,20 +34,16 @@ class AutomationManagerViews {
AutomationManagerViews();
~AutomationManagerViews();
- // Whether Views-based automation is enabled.
- bool enabled_;
-
// 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.
- scoped_ptr <AXTreeSourceViews> current_tree_;
+ scoped_ptr <views::AXTreeSourceViews> current_tree_;
// Serializes incremental updates on the currently active tree
// |current_tree_|.
- scoped_ptr<ui::AXTreeSerializer<views::AXAuraObjWrapper*> >
- current_tree_serializer_;
+ scoped_ptr<ui::AXTreeSerializer<views::View*> > current_tree_serializer_;
DISALLOW_COPY_AND_ASSIGN(AutomationManagerViews);
};
-#endif // CHROME_BROWSER_UI_ASH_ACCESSIBILITY_AUTOMATION_MANAGER_VIEWS_H_
+#endif // CHROME_BROWSER_UI_VIEWS_ACCESSIBILITY_AUTOMATION_MANAGER_VIEWS_H_
diff --git a/chrome/browser/ui/views/chrome_views_delegate.cc b/chrome/browser/ui/views/chrome_views_delegate.cc
index 3626587..4635223 100644
--- a/chrome/browser/ui/views/chrome_views_delegate.cc
+++ b/chrome/browser/ui/views/chrome_views_delegate.cc
@@ -13,6 +13,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/views/accessibility/accessibility_event_router_views.h"
+#include "chrome/browser/ui/views/accessibility/automation_manager_views.h"
#include "chrome/common/pref_names.h"
#include "grit/chrome_unscaled_resources.h"
#include "ui/base/resource/resource_bundle.h"
@@ -50,7 +51,6 @@
#if defined(USE_ASH)
#include "ash/shell.h"
#include "ash/wm/window_state.h"
-#include "chrome/browser/ui/ash/accessibility/automation_manager_views.h"
#include "chrome/browser/ui/ash/ash_init.h"
#include "chrome/browser/ui/ash/ash_util.h"
#endif
@@ -199,10 +199,8 @@ void ChromeViewsDelegate::NotifyAccessibilityEvent(
AccessibilityEventRouterViews::GetInstance()->HandleAccessibilityEvent(
view, event_type);
-#if defined(USE_ASH)
AutomationManagerViews::GetInstance()->HandleEvent(
GetProfileForWindow(view->GetWidget()), view, event_type);
-#endif
}
void ChromeViewsDelegate::NotifyMenuItemFocused(
diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi
index 591b728..2dcf5d5 100644
--- a/chrome/chrome_browser_ui.gypi
+++ b/chrome/chrome_browser_ui.gypi
@@ -257,12 +257,6 @@
'browser/ui/apps/chrome_app_window_delegate.h',
'browser/ui/apps/directory_access_confirmation_dialog.cc',
'browser/ui/apps/directory_access_confirmation_dialog.h',
- 'browser/ui/ash/accessibility/automation_manager_views.cc',
- 'browser/ui/ash/accessibility/automation_manager_views.h',
- 'browser/ui/ash/accessibility/ax_root_obj_wrapper.cc',
- 'browser/ui/ash/accessibility/ax_root_obj_wrapper.h',
- 'browser/ui/ash/accessibility/ax_tree_source_views.cc',
- 'browser/ui/ash/accessibility/ax_tree_source_views.h',
'browser/ui/ash/ash_keyboard_controller_proxy.cc',
'browser/ui/ash/ash_keyboard_controller_proxy.h',
'browser/ui/ash/app_list/app_list_controller_ash.cc',
@@ -1445,6 +1439,8 @@
'browser/ui/views/accessibility/accessibility_event_router_views.h',
'browser/ui/views/accessibility/invert_bubble_view.cc',
'browser/ui/views/accessibility/invert_bubble_view.h',
+ 'browser/ui/views/accessibility/automation_manager_views.cc',
+ 'browser/ui/views/accessibility/automation_manager_views.h',
'browser/ui/views/app_list/linux/app_list_controller_delegate_linux.cc',
'browser/ui/views/app_list/linux/app_list_controller_delegate_linux.h',
'browser/ui/views/app_list/linux/app_list_linux.cc',
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index d1339915..b1d773c0 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -1421,7 +1421,6 @@
'browser/translate/translate_service_unittest.cc',
'browser/ui/android/tab_model/tab_model_unittest.cc',
'browser/ui/ash/ime_controller_chromeos_unittest.cc',
- 'browser/ui/ash/accessibility/ax_tree_source_views_unittest.cc',
'browser/ui/ash/launcher/chrome_launcher_controller_unittest.cc',
'browser/ui/ash/launcher/launcher_context_menu_unittest.cc',
'browser/ui/ash/multi_user/multi_user_context_menu_chromeos_unittest.cc',
diff --git a/chrome/renderer/resources/extensions/automation_custom_bindings.js b/chrome/renderer/resources/extensions/automation_custom_bindings.js
index fae3ee1..8a8bf1b8 100644
--- a/chrome/renderer/resources/extensions/automation_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/automation_custom_bindings.js
@@ -28,7 +28,7 @@ var createAutomationTreeID = function(pid, rid) {
automation.registerCustomHook(function(bindingsAPI) {
var apiFunctions = bindingsAPI.apiFunctions;
- // TODO(aboxhall, dtseng): Make this return the speced AutomationRootNode obj.
+ // TODO(aboxhall/dtseng): Re-work once 'desktop' object is fully specced
apiFunctions.setHandleRequest('getTree', function(callback) {
// enableCurrentTab() ensures the renderer for the current tab has
// accessibility enabled, and fetches its process and routing ids to use as
diff --git a/ui/accessibility/ax_enums.idl b/ui/accessibility/ax_enums.idl
index ea46143..77287e3 100644
--- a/ui/accessibility/ax_enums.idl
+++ b/ui/accessibility/ax_enums.idl
@@ -65,7 +65,6 @@ namespace ui {
definition,
description_list_detail,
description_list_term,
- desktop,
dialog,
directory,
disclosure_triangle,
diff --git a/ui/accessibility/ax_view_state.h b/ui/accessibility/ax_view_state.h
index 2f1aab09..5d72d47 100644
--- a/ui/accessibility/ax_view_state.h
+++ b/ui/accessibility/ax_view_state.h
@@ -30,11 +30,6 @@ struct AX_EXPORT AXViewState {
void AddStateFlag(ui::AXState state);
bool HasStateFlag(ui::AXState state) const;
- // The view's state, a bitmask containing fields such as checked
- // (for a checkbox) and protected (for a password text box). This "state"
- // should not be confused with the class's name.
- uint32 state() { return state_; }
-
// The view's role, like button or list box.
AXRole role;
@@ -73,6 +68,8 @@ struct AX_EXPORT AXViewState {
base::Callback<void(const base::string16&)> set_value_callback;
private:
+ // The view's state, a bitmask containing fields such as checked
+ // (for a checkbox) and protected (for a password text box).
uint32 state_;
};
diff --git a/ui/views/accessibility/ax_aura_obj_cache.cc b/ui/views/accessibility/ax_aura_obj_cache.cc
deleted file mode 100644
index f91760c..0000000
--- a/ui/views/accessibility/ax_aura_obj_cache.cc
+++ /dev/null
@@ -1,126 +0,0 @@
-// 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 "ui/views/accessibility/ax_aura_obj_cache.h"
-
-#include "base/memory/singleton.h"
-#include "ui/aura/window.h"
-#include "ui/views/accessibility/ax_aura_obj_wrapper.h"
-#include "ui/views/accessibility/ax_view_obj_wrapper.h"
-#include "ui/views/accessibility/ax_widget_obj_wrapper.h"
-#include "ui/views/accessibility/ax_window_obj_wrapper.h"
-#include "ui/views/view.h"
-#include "ui/views/widget/widget.h"
-
-namespace views {
-
-// static
-AXAuraObjCache* AXAuraObjCache::GetInstance() {
- return Singleton<AXAuraObjCache>::get();
-}
-
-AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(View* view) {
- return CreateInternal<AXViewObjWrapper>(view, view_to_id_map_);
-}
-
-AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(Widget* widget) {
- return CreateInternal<AXWidgetObjWrapper>(widget, widget_to_id_map_);
-}
-
-AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(aura::Window* window) {
- return CreateInternal<AXWindowObjWrapper>(window, window_to_id_map_);
-}
-
-int32 AXAuraObjCache::GetID(View* view) {
- return GetIDInternal(view, view_to_id_map_);
-}
-
-int32 AXAuraObjCache::GetID(Widget* widget) {
- return GetIDInternal(widget, widget_to_id_map_);
-}
-
-int32 AXAuraObjCache::GetID(aura::Window* window) {
- return GetIDInternal(window, window_to_id_map_);
-}
-
-void AXAuraObjCache::Remove(View* view) {
- RemoveInternal(view, view_to_id_map_);
-}
-
-void AXAuraObjCache::Remove(Widget* widget) {
- RemoveInternal(widget, widget_to_id_map_);
-}
-
-void AXAuraObjCache::Remove(aura::Window* window) {
- RemoveInternal(window, window_to_id_map_);
-}
-
-AXAuraObjWrapper* AXAuraObjCache::Get(int32 id) {
- std::map<int32, AXAuraObjWrapper*>::iterator it = cache_.find(id);
-
- if (it == cache_.end())
- return NULL;
-
- return it->second;
-}
-
-void AXAuraObjCache::Remove(int32 id) {
- AXAuraObjWrapper* obj = Get(id);
-
- if (id == -1 || !obj)
- return;
-
- cache_.erase(id);
- delete obj;
-}
-
-AXAuraObjCache::AXAuraObjCache() : current_id_(1) {
-}
-
-AXAuraObjCache::~AXAuraObjCache() {}
-
-template <typename AuraViewWrapper, typename AuraView>
-AXAuraObjWrapper* AXAuraObjCache::CreateInternal(
- AuraView* aura_view, std::map<AuraView*, int32>& aura_view_to_id_map) {
- if (!aura_view)
- return NULL;
-
- typename std::map<AuraView*, int32>::iterator it =
- aura_view_to_id_map.find(aura_view);
-
- if (it != aura_view_to_id_map.end())
- return Get(it->second);
-
- AXAuraObjWrapper* wrapper = new AuraViewWrapper(aura_view);
- aura_view_to_id_map[aura_view] = current_id_;
- cache_[current_id_] = wrapper;
- current_id_++;
- return wrapper;
-}
-
-template<typename AuraView> int32 AXAuraObjCache::GetIDInternal(
- AuraView* aura_view, std::map<AuraView*, int32>& aura_view_to_id_map) {
- if (!aura_view)
- return -1;
-
- typename std::map<AuraView*, int32>::iterator it =
- aura_view_to_id_map.find(aura_view);
-
- if (it != aura_view_to_id_map.end())
- return it->second;
-
- return -1;
-}
-
-template<typename AuraView>
-void AXAuraObjCache::RemoveInternal(
- AuraView* aura_view, std::map<AuraView*, int32>& aura_view_to_id_map) {
- int32 id = GetID(aura_view);
- if (id == -1)
- return;
- aura_view_to_id_map.erase(aura_view);
- Remove(id);
-}
-
-} // namespace views
diff --git a/ui/views/accessibility/ax_aura_obj_cache.h b/ui/views/accessibility/ax_aura_obj_cache.h
deleted file mode 100644
index 6e5d9e8..0000000
--- a/ui/views/accessibility/ax_aura_obj_cache.h
+++ /dev/null
@@ -1,83 +0,0 @@
-// 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 UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_CACHE_H_
-#define UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_CACHE_H_
-
-#include <map>
-
-#include "base/basictypes.h"
-#include "ui/views/views_export.h"
-
-template <typename T> struct DefaultSingletonTraits;
-
-namespace aura {
-class Window;
-} // namespace aura
-
-namespace views {
-class AXAuraObjWrapper;
-class View;
-class Widget;
-
-// A cache responsible for assigning id's to a set of interesting Aura views.
-class VIEWS_EXPORT AXAuraObjCache {
- public:
- // Get the single instance of this class.
- static AXAuraObjCache* GetInstance();
-
- // Get or create an entry in the cache based on an Aura view.
- AXAuraObjWrapper* GetOrCreate(View* view);
- AXAuraObjWrapper* GetOrCreate(Widget* widget);
- AXAuraObjWrapper* GetOrCreate(aura::Window* window);
-
- // Gets an id given an Aura view.
- int32 GetID(View* view);
- int32 GetID(Widget* widget);
- int32 GetID(aura::Window* window);
-
- // Gets the next unique id for this cache. Useful for non-Aura view backed
- // views.
- int32 GetNextID() { return current_id_++; }
-
- // Removes an entry from this cache based on an Aura view.
- void Remove(View* view);
- void Remove(Widget* widget);
- void Remove(aura::Window* window);
-
- // Lookup a cached entry based on an id.
- AXAuraObjWrapper* Get(int32 id);
-
- // Remove a cached entry based on an id.
- void Remove(int32 id);
-
- private:
- friend struct DefaultSingletonTraits<AXAuraObjCache>;
-
- AXAuraObjCache();
- virtual ~AXAuraObjCache();
-
- template <typename AuraViewWrapper, typename AuraView>
- AXAuraObjWrapper* CreateInternal(
- AuraView* aura_view, std::map<AuraView*, int32>& aura_view_to_id_map);
-
- template<typename AuraView> int32 GetIDInternal(
- AuraView* aura_view, std::map<AuraView*, int32>& aura_view_to_id_map);
-
- template<typename AuraView> void RemoveInternal(
- AuraView* aura_view, std::map<AuraView*, int32>& aura_view_to_id_map);
-
- std::map<views::View*, int32> view_to_id_map_;
- std::map<views::Widget*, int32> widget_to_id_map_;
- std::map<aura::Window*, int32> window_to_id_map_;
-
- std::map<int32, AXAuraObjWrapper*> cache_;
- int32 current_id_;
-
- DISALLOW_COPY_AND_ASSIGN(AXAuraObjCache);
-};
-
-} // namespace views
-
-#endif // UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_CACHE_H_
diff --git a/ui/views/accessibility/ax_aura_obj_wrapper.h b/ui/views/accessibility/ax_aura_obj_wrapper.h
deleted file mode 100644
index 551b107..0000000
--- a/ui/views/accessibility/ax_aura_obj_wrapper.h
+++ /dev/null
@@ -1,36 +0,0 @@
-// 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 UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_WRAPPER_H_
-#define UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_WRAPPER_H_
-
-#include <vector>
-
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "base/macros.h"
-#include "ui/views/views_export.h"
-
-namespace ui {
-struct AXNodeData;
-} // namespace ui
-
-namespace views {
-
-// An interface abstraction for Aura views that exposes the view-tree formed
-// by the implementing view types.
-class VIEWS_EXPORT AXAuraObjWrapper {
- public:
- virtual ~AXAuraObjWrapper() {}
-
- virtual AXAuraObjWrapper* GetParent() = 0;
- virtual void GetChildren(
- std::vector<AXAuraObjWrapper*>* out_children) = 0;
- virtual void Serialize(ui::AXNodeData* out_node_data) = 0;
- virtual int32 GetID() = 0;
-};
-
-} // namespace views
-
-#endif // UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_WRAPPER_H_
diff --git a/ui/views/accessibility/ax_tree_source_views.cc b/ui/views/accessibility/ax_tree_source_views.cc
new file mode 100644
index 0000000..80c1125
--- /dev/null
+++ b/ui/views/accessibility/ax_tree_source_views.cc
@@ -0,0 +1,156 @@
+// 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 "ui/views/accessibility/ax_tree_source_views.h"
+
+#include <vector>
+
+#include "base/strings/utf_string_conversions.h"
+#include "ui/accessibility/ax_view_state.h"
+#include "ui/views/widget/widget.h"
+
+namespace views {
+
+// A simple store associating each |View| with a unique id.
+class AXViewStore {
+ public:
+ AXViewStore() : view_id_(0) {}
+
+ int32 GetOrStoreView(View* view) {
+ int32 current_id = RetrieveId(view);
+ if (current_id != -1)
+ return current_id;
+ id_to_view_[++view_id_] = view;
+ view_to_id_[view] = view_id_;
+ return view_id_;
+ }
+
+ void RemoveView(View* view) {
+ std::map<View*, int32>::iterator view_it = view_to_id_.find(view);
+ if (view_it == view_to_id_.end())
+ return;
+ int32 view_id = view_it->second;
+ view_to_id_.erase(view_it);
+ std::map<int32, View*>::iterator id_it = id_to_view_.find(view_id);
+ if (id_it == id_to_view_.end()) {
+ NOTREACHED();
+ return;
+ }
+ id_to_view_.erase(id_it);
+ }
+
+ View* RetrieveView(int32 id) {
+ std::map<int32, View*>::iterator it = id_to_view_.find(id);
+ if (it != id_to_view_.end())
+ return it->second;
+ return NULL;
+ }
+
+ int32 RetrieveId(View* view) {
+ if (!view)
+ return -1;
+ std::map<View*, int32>::iterator it = view_to_id_.find(view);
+ if (it != view_to_id_.end())
+ return it->second;
+ return -1;
+ }
+
+ private:
+ // Unique id assigned to a view.
+ int32 view_id_;
+
+ // Maps from id to |View*| and |View*| to id.
+ std::map<int32, View*> id_to_view_;
+ std::map<View*, int32> view_to_id_;
+};
+
+AXTreeSourceViews::AXTreeSourceViews(Widget* root)
+ : view_store_(new AXViewStore()),
+ root_(root) {
+ root->AddObserver(this);
+ root->AddRemovalsObserver(this);
+}
+
+AXTreeSourceViews::~AXTreeSourceViews() {
+ if (root_) {
+ root_->RemoveObserver(this);
+ root_->RemoveRemovalsObserver(this);
+ }
+}
+
+View* AXTreeSourceViews::GetRoot() const {
+ if (!root_)
+ return NULL;
+ return root_->GetRootView();
+}
+
+View* AXTreeSourceViews::GetFromId(int32 id) const {
+ return view_store_->RetrieveView(id);
+}
+
+int32 AXTreeSourceViews::GetId(View* node) const {
+ return view_store_->GetOrStoreView(node);
+}
+
+void AXTreeSourceViews::GetChildren(View* node,
+ std::vector<View*>* out_children) const {
+ for (int i = 0; i < node->child_count(); ++i) {
+ View* child_view = node->child_at(i);
+ out_children->push_back(child_view);
+ }
+}
+
+View* AXTreeSourceViews::GetParent(View* node) const {
+ return node->parent();
+}
+
+bool AXTreeSourceViews::IsValid(View* node) const {
+ if (root_ && root_->GetRootView())
+ return root_->GetRootView()->Contains(node);
+ return false;
+}
+
+bool AXTreeSourceViews::IsEqual(View* node1,
+ View* node2) const {
+ return node1 == node2;
+}
+
+View* AXTreeSourceViews::GetNull() const {
+ return NULL;
+}
+
+void AXTreeSourceViews::SerializeNode(
+ View* node, ui::AXNodeData* out_data) const {
+ ui::AXViewState view_data;
+ const_cast<View*>(node)->GetAccessibleState(&view_data);
+ out_data->id = view_store_->GetOrStoreView(node);
+ out_data->role = view_data.role;
+
+ out_data->state = 0;
+ for (int32 state = ui::AX_STATE_NONE;
+ state <= ui::AX_STATE_LAST;
+ ++state) {
+ ui::AXState state_flag = static_cast<ui::AXState>(state);
+ if (view_data.HasStateFlag(state_flag))
+ out_data->state |= 1 << state;
+ }
+
+ out_data->location = node->GetBoundsInScreen();
+ out_data->AddStringAttribute(
+ ui::AX_ATTR_NAME, base::UTF16ToUTF8(view_data.name));
+ out_data->AddStringAttribute(
+ ui::AX_ATTR_VALUE, base::UTF16ToUTF8(view_data.value));
+}
+
+void AXTreeSourceViews::OnWillRemoveView(Widget* widget, View* view) {
+ if (widget == root_)
+ view_store_->RemoveView(view);
+}
+
+void AXTreeSourceViews::OnWidgetDestroyed(Widget* widget) {
+ if (widget == root_)
+ root_ = NULL;
+}
+
+} // namespace views
diff --git a/ui/views/accessibility/ax_tree_source_views.h b/ui/views/accessibility/ax_tree_source_views.h
new file mode 100644
index 0000000..d2e9502
--- /dev/null
+++ b/ui/views/accessibility/ax_tree_source_views.h
@@ -0,0 +1,56 @@
+// 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 UI_VIEWS_ACCESSIBILITY_AX_TREE_SOURCE_VIEWS_H_
+#define UI_VIEWS_ACCESSIBILITY_AX_TREE_SOURCE_VIEWS_H_
+
+#include <map>
+
+#include "base/memory/scoped_ptr.h"
+#include "ui/accessibility/ax_tree_source.h"
+#include "ui/views/view.h"
+#include "ui/views/widget/widget_observer.h"
+#include "ui/views/widget/widget_removals_observer.h"
+
+namespace views {
+class AXViewStore;
+
+// This class exposes the views hierarchy as an accessibility tree permitting
+// use with other accessibility classes.
+class VIEWS_EXPORT AXTreeSourceViews : public ui::AXTreeSource<View*>,
+ public WidgetObserver,
+ public WidgetRemovalsObserver {
+ public:
+ explicit AXTreeSourceViews(Widget* root);
+ virtual ~AXTreeSourceViews();
+
+ // AXTreeSource implementation.
+ virtual View* GetRoot() const OVERRIDE;
+ virtual View* GetFromId(int32 id) const OVERRIDE;
+ virtual int32 GetId(View* node) const OVERRIDE;
+ virtual void GetChildren(View* node,
+ std::vector<View*>* out_children) const OVERRIDE;
+ virtual View* GetParent(View* node) const OVERRIDE;
+ virtual bool IsValid(View* node) const OVERRIDE;
+ virtual bool IsEqual(View* node1,
+ View* node2) const OVERRIDE;
+ virtual View* GetNull() const OVERRIDE;
+ virtual void SerializeNode(
+ View* node, ui::AXNodeData* out_data) const OVERRIDE;
+
+ // WidgetObserver overrides.
+ virtual void OnWidgetDestroyed(Widget* widget) OVERRIDE;
+
+ // WidgetRemovalsObserver overrides.
+ virtual void OnWillRemoveView(Widget* widget, View* view) OVERRIDE;
+
+ private:
+ scoped_ptr<AXViewStore> view_store_;
+
+ views::Widget* root_;
+};
+
+} // namespace views
+
+#endif // UI_VIEWS_ACCESSIBILITY_AX_TREE_SOURCE_VIEWS_H_
diff --git a/ui/views/accessibility/ax_tree_source_views_unittest.cc b/ui/views/accessibility/ax_tree_source_views_unittest.cc
new file mode 100644
index 0000000..7b46bfe
--- /dev/null
+++ b/ui/views/accessibility/ax_tree_source_views_unittest.cc
@@ -0,0 +1,85 @@
+// 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 <vector>
+
+#include "base/memory/scoped_ptr.h"
+#include "base/strings/utf_string_conversions.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/accessibility/ax_enums.h"
+#include "ui/accessibility/ax_node.h"
+#include "ui/accessibility/ax_serializable_tree.h"
+#include "ui/accessibility/ax_tree_serializer.h"
+#include "ui/accessibility/ax_tree_update.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"
+
+namespace views {
+
+class AXTreeSourceViewsTest : public ViewsTestBase {
+ public:
+ AXTreeSourceViewsTest() {}
+ virtual ~AXTreeSourceViewsTest() {}
+
+ virtual void SetUp() OVERRIDE {
+ ViewsTestBase::SetUp();
+ widget_.reset(new Widget());
+ Widget::InitParams init_params =
+ CreateParams(Widget::InitParams::TYPE_POPUP);
+ init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+ widget_->Init(init_params);
+
+ content_.reset(new View());
+ widget_->SetContentsView(content_.get());
+
+ textfield_.reset(new Textfield());
+ textfield_->SetText(base::ASCIIToUTF16("Value"));
+ content_->AddChildView(textfield_.get());
+ }
+
+ protected:
+ scoped_ptr<Widget> widget_;
+ scoped_ptr<View> content_;
+ scoped_ptr<Textfield> textfield_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AXTreeSourceViewsTest);
+};
+
+TEST_F(AXTreeSourceViewsTest, SimpleAccessers) {
+ AXTreeSourceViews ax_tree(widget_.get());
+ ASSERT_EQ(widget_->GetRootView(), ax_tree.GetRoot());
+ std::vector<View*> content_children;
+ ax_tree.GetChildren(content_.get(), &content_children);
+ ASSERT_EQ(1U, content_children.size());
+ std::vector<View*> textfield_children;
+ ax_tree.GetChildren(textfield_.get(), &textfield_children);
+ ASSERT_EQ(0U, textfield_children.size());
+
+ int root_id = ax_tree.GetId(widget_->GetRootView());
+ int content_id = ax_tree.GetId(content_.get());
+ int textfield_id = ax_tree.GetId(textfield_.get());
+
+ ASSERT_EQ(1, root_id);
+ ASSERT_EQ(2, content_id);
+ ASSERT_EQ(3, textfield_id);
+}
+
+TEST_F(AXTreeSourceViewsTest, SimpleSerialization) {
+ AXTreeSourceViews ax_tree(widget_.get());
+ ui::AXTreeSerializer<View*> ax_serializer(&ax_tree);
+ ui::AXTreeUpdate out_update;
+ ax_serializer.SerializeChanges(ax_tree.GetRoot(), &out_update);
+ ASSERT_EQ(3U, out_update.nodes.size());
+ ASSERT_EQ("id=1 root_web_area (0, 0)-(0, 0) name= value= child_ids=2",
+ out_update.nodes[0].ToString());
+ ASSERT_EQ("id=2 client (0, 0)-(0, 0) name= value= child_ids=3",
+ out_update.nodes[1].ToString());
+ ASSERT_EQ("id=3 text_field (0, 0)-(0, 0) name= value=Value",
+ out_update.nodes[2].ToString());
+}
+
+} // namespace views
diff --git a/ui/views/accessibility/ax_view_obj_wrapper.cc b/ui/views/accessibility/ax_view_obj_wrapper.cc
deleted file mode 100644
index 56b2540..0000000
--- a/ui/views/accessibility/ax_view_obj_wrapper.cc
+++ /dev/null
@@ -1,65 +0,0 @@
-// 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 "ui/views/accessibility/ax_view_obj_wrapper.h"
-
-#include "base/strings/utf_string_conversions.h"
-#include "ui/accessibility/ax_node_data.h"
-#include "ui/accessibility/ax_view_state.h"
-#include "ui/views/accessibility/ax_aura_obj_cache.h"
-#include "ui/views/view.h"
-#include "ui/views/widget/widget.h"
-
-namespace views {
-
-AXViewObjWrapper::AXViewObjWrapper(View* view) : view_(view) {
- DCHECK(view->GetWidget());
- if (view->GetWidget())
- AXAuraObjCache::GetInstance()->GetOrCreate(view->GetWidget());
-}
-
-AXViewObjWrapper::~AXViewObjWrapper() {}
-
-AXAuraObjWrapper* AXViewObjWrapper::GetParent() {
- AXAuraObjCache* cache = AXAuraObjCache::GetInstance();
- if (view_->parent())
- return cache->GetOrCreate(view_->parent());
-
- return cache->GetOrCreate(view_->GetWidget());
-}
-
-void AXViewObjWrapper::GetChildren(
- std::vector<AXAuraObjWrapper*>* out_children) {
- // TODO(dtseng): Need to handle |Widget| child of |View|.
- for (int i = 0; i < view_->child_count(); ++i) {
- AXAuraObjWrapper* child =
- AXAuraObjCache::GetInstance()->GetOrCreate(view_->child_at(i));
- out_children->push_back(child);
- }
-}
-
-void AXViewObjWrapper::Serialize(ui::AXNodeData* out_node_data) {
- ui::AXViewState view_data;
- view_->GetAccessibleState(&view_data);
- out_node_data->id = GetID();
- out_node_data->role = view_data.role;
- out_node_data->state = view_data.state();
- out_node_data->location = view_->GetBoundsInScreen();
-
- out_node_data->AddStringAttribute(
- ui::AX_ATTR_NAME, base::UTF16ToUTF8(view_data.name));
- out_node_data->AddStringAttribute(
- ui::AX_ATTR_VALUE, base::UTF16ToUTF8(view_data.value));
-
- out_node_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_START,
- view_data.selection_start);
- out_node_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_END,
- view_data.selection_end);
-}
-
-int32 AXViewObjWrapper::GetID() {
- return AXAuraObjCache::GetInstance()->GetID(view_);
-}
-
-} // namespace views
diff --git a/ui/views/accessibility/ax_view_obj_wrapper.h b/ui/views/accessibility/ax_view_obj_wrapper.h
deleted file mode 100644
index 5dd4d2c..0000000
--- a/ui/views/accessibility/ax_view_obj_wrapper.h
+++ /dev/null
@@ -1,34 +0,0 @@
-// 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 UI_VIEWS_ACCESSIBILITY_AX_VIEW_OBJ_WRAPPER_H_
-#define UI_VIEWS_ACCESSIBILITY_AX_VIEW_OBJ_WRAPPER_H_
-
-#include "ui/views/accessibility/ax_aura_obj_wrapper.h"
-
-namespace views {
-class View;
-
-// Describes a |View| for use with other AX classes.
-class AXViewObjWrapper : public AXAuraObjWrapper {
- public:
- explicit AXViewObjWrapper(View* view);
- virtual ~AXViewObjWrapper();
-
- // AXAuraObjWrapper overrides.
- virtual AXAuraObjWrapper* GetParent() OVERRIDE;
- virtual void GetChildren(
- std::vector<AXAuraObjWrapper*>* out_children) OVERRIDE;
- virtual void Serialize(ui::AXNodeData* out_node_data) OVERRIDE;
- virtual int32 GetID() OVERRIDE;
-
- private:
- View* view_;
-
- DISALLOW_COPY_AND_ASSIGN(AXViewObjWrapper);
-};
-
-} // namespace views
-
-#endif // UI_VIEWS_ACCESSIBILITY_AX_VIEW_OBJ_WRAPPER_H_
diff --git a/ui/views/accessibility/ax_widget_obj_wrapper.cc b/ui/views/accessibility/ax_widget_obj_wrapper.cc
deleted file mode 100644
index 36a3143..0000000
--- a/ui/views/accessibility/ax_widget_obj_wrapper.cc
+++ /dev/null
@@ -1,55 +0,0 @@
-// 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 "ui/views/accessibility/ax_widget_obj_wrapper.h"
-
-#include "ui/accessibility/ax_node_data.h"
-#include "ui/views/accessibility/ax_aura_obj_cache.h"
-#include "ui/views/accessibility/ax_aura_obj_wrapper.h"
-#include "ui/views/widget/widget.h"
-
-namespace views {
-
-AXWidgetObjWrapper::AXWidgetObjWrapper(Widget* widget) : widget_(widget) {
- widget->AddObserver(this);
- widget->AddRemovalsObserver(this);
-}
-
-AXWidgetObjWrapper::~AXWidgetObjWrapper() {
- widget_->RemoveObserver(this);
- widget_->RemoveRemovalsObserver(this);
- widget_ = NULL;
-}
-
-AXAuraObjWrapper* AXWidgetObjWrapper::GetParent() {
- return AXAuraObjCache::GetInstance()->GetOrCreate(widget_->GetNativeView());
-}
-
-void AXWidgetObjWrapper::GetChildren(
- std::vector<AXAuraObjWrapper*>* out_children) {
- out_children->push_back(
- AXAuraObjCache::GetInstance()->GetOrCreate(widget_->GetRootView()));
-}
-
-void AXWidgetObjWrapper::Serialize(ui::AXNodeData* out_node_data) {
- out_node_data->id = GetID();
- out_node_data->role = ui::AX_ROLE_CLIENT;
- out_node_data->location = widget_->GetWindowBoundsInScreen();
- // TODO(dtseng): Set better states.
- out_node_data->state = 0;
-}
-
-int32 AXWidgetObjWrapper::GetID() {
- return AXAuraObjCache::GetInstance()->GetID(widget_);
-}
-
-void AXWidgetObjWrapper::OnWidgetDestroying(Widget* widget) {
- AXAuraObjCache::GetInstance()->Remove(widget);
-}
-
-void AXWidgetObjWrapper::OnWillRemoveView(Widget* widget, View* view) {
- AXAuraObjCache::GetInstance()->Remove(view);
-}
-
-} // namespace views
diff --git a/ui/views/accessibility/ax_widget_obj_wrapper.h b/ui/views/accessibility/ax_widget_obj_wrapper.h
deleted file mode 100644
index 61ff1e9..0000000
--- a/ui/views/accessibility/ax_widget_obj_wrapper.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// 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 UI_VIEWS_ACCESSIBILITY_AX_WIDGET_OBJ_WRAPPER_H_
-#define UI_VIEWS_ACCESSIBILITY_AX_WIDGET_OBJ_WRAPPER_H_
-
-#include "ui/views/accessibility/ax_aura_obj_wrapper.h"
-#include "ui/views/widget/widget_observer.h"
-#include "ui/views/widget/widget_removals_observer.h"
-
-namespace views {
-class Widget;
-
-// Describes a |Widget| for use with other AX classes.
-class AXWidgetObjWrapper : public AXAuraObjWrapper,
- public WidgetObserver,
- public WidgetRemovalsObserver {
- public:
- explicit AXWidgetObjWrapper(Widget* widget);
- virtual ~AXWidgetObjWrapper();
-
- // AXAuraObjWrapper overrides.
- virtual AXAuraObjWrapper* GetParent() OVERRIDE;
- virtual void GetChildren(
- std::vector<AXAuraObjWrapper*>* out_children) OVERRIDE;
- virtual void Serialize(ui::AXNodeData* out_node_data) OVERRIDE;
- virtual int32 GetID() OVERRIDE;
-
- // WidgetObserver overrides.
- virtual void OnWidgetDestroying(Widget* widget) OVERRIDE;
-
- // WidgetRemovalsObserver overrides.
- virtual void OnWillRemoveView(Widget* widget, View* view) OVERRIDE;
-
- private:
- Widget* widget_;
-
- DISALLOW_COPY_AND_ASSIGN(AXWidgetObjWrapper);
-};
-
-} // namespace views
-
-#endif // UI_VIEWS_ACCESSIBILITY_AX_WIDGET_OBJ_WRAPPER_H_
diff --git a/ui/views/accessibility/ax_window_obj_wrapper.cc b/ui/views/accessibility/ax_window_obj_wrapper.cc
deleted file mode 100644
index b358de5..0000000
--- a/ui/views/accessibility/ax_window_obj_wrapper.cc
+++ /dev/null
@@ -1,64 +0,0 @@
-// 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 "ui/views/accessibility/ax_window_obj_wrapper.h"
-
-#include "base/strings/utf_string_conversions.h"
-#include "ui/accessibility/ax_node_data.h"
-#include "ui/aura/window.h"
-#include "ui/views/accessibility/ax_aura_obj_cache.h"
-#include "ui/views/widget/widget.h"
-
-namespace views {
-
-AXWindowObjWrapper::AXWindowObjWrapper(
- aura::Window* window) : window_(window) {
- window->AddObserver(this);
-}
-
-AXWindowObjWrapper::~AXWindowObjWrapper() {
- window_->RemoveObserver(this);
- window_ = NULL;
-}
-
-AXAuraObjWrapper* AXWindowObjWrapper::GetParent() {
- if (!window_->parent())
- return NULL;
-
- return AXAuraObjCache::GetInstance()->GetOrCreate(window_->parent());
-}
-
-void AXWindowObjWrapper::GetChildren(
- std::vector<AXAuraObjWrapper*>* out_children) {
- aura::Window::Windows children = window_->children();
- for (size_t i = 0; i < children.size(); ++i) {
- out_children->push_back(
- AXAuraObjCache::GetInstance()->GetOrCreate(children[i]));
- }
-
- // Also consider any associated widgets as children.
- Widget* widget = Widget::GetWidgetForNativeView(window_);
- if (widget)
- out_children->push_back(AXAuraObjCache::GetInstance()->GetOrCreate(widget));
-}
-
-void AXWindowObjWrapper::Serialize(ui::AXNodeData* out_node_data) {
- out_node_data->id = GetID();
- out_node_data->role = ui::AX_ROLE_WINDOW;
- // TODO(dtseng): Set better states.
- out_node_data->state = 0;
- out_node_data->location = window_->bounds();
- out_node_data->AddStringAttribute(
- ui::AX_ATTR_NAME, base::UTF16ToUTF8(window_->title()));
-}
-
-int32 AXWindowObjWrapper::GetID() {
- return AXAuraObjCache::GetInstance()->GetID(window_);
-}
-
-void AXWindowObjWrapper::OnWindowDestroying(aura::Window* window) {
- AXAuraObjCache::GetInstance()->Remove(window);
-}
-
-} // namespace views
diff --git a/ui/views/accessibility/ax_window_obj_wrapper.h b/ui/views/accessibility/ax_window_obj_wrapper.h
deleted file mode 100644
index b3cd235..0000000
--- a/ui/views/accessibility/ax_window_obj_wrapper.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// 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 UI_VIEWS_ACCESSIBILITY_AX_WINDOW_OBJ_WRAPPER_H_
-#define UI_VIEWS_ACCESSIBILITY_AX_WINDOW_OBJ_WRAPPER_H_
-
-#include "ui/aura/window_observer.h"
-#include "ui/views/accessibility/ax_aura_obj_wrapper.h"
-
-namespace aura {
-class Window;
-} // namespace aura
-
-namespace views {
-
-// Describes a |Window| for use with other AX classes.
-class AXWindowObjWrapper : public AXAuraObjWrapper,
- public aura::WindowObserver {
- public:
- explicit AXWindowObjWrapper(aura::Window* window);
- virtual ~AXWindowObjWrapper();
-
- // AXAuraObjWrapper overrides.
- virtual AXAuraObjWrapper* GetParent() OVERRIDE;
- virtual void GetChildren(
- std::vector<AXAuraObjWrapper*>* out_children) OVERRIDE;
- virtual void Serialize(ui::AXNodeData* out_node_data) OVERRIDE;
- virtual int32 GetID() OVERRIDE;
-
- // WindowObserver overrides.
- virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
-
- private:
- aura::Window* window_;
-
- DISALLOW_COPY_AND_ASSIGN(AXWindowObjWrapper);
-};
-
-} // namespace views
-
-#endif // UI_VIEWS_ACCESSIBILITY_AX_WINDOW_OBJ_WRAPPER_H_
diff --git a/ui/views/views.gyp b/ui/views/views.gyp
index 1004ab5..ff3eb32 100644
--- a/ui/views/views.gyp
+++ b/ui/views/views.gyp
@@ -47,15 +47,8 @@
],
'sources': [
# All .cc, .h under views, except unittests
- 'accessibility/ax_aura_obj_cache.cc',
- 'accessibility/ax_aura_obj_cache.h',
- 'accessibility/ax_aura_obj_wrapper.h',
- 'accessibility/ax_view_obj_wrapper.cc',
- 'accessibility/ax_view_obj_wrapper.h',
- 'accessibility/ax_widget_obj_wrapper.cc',
- 'accessibility/ax_widget_obj_wrapper.h',
- 'accessibility/ax_window_obj_wrapper.cc',
- 'accessibility/ax_window_obj_wrapper.h',
+ 'accessibility/ax_tree_source_views.cc',
+ 'accessibility/ax_tree_source_views.h',
'accessibility/native_view_accessibility.cc',
'accessibility/native_view_accessibility.h',
'accessibility/native_view_accessibility_win.cc',
@@ -604,6 +597,7 @@
'..',
],
'sources': [
+ 'accessibility/ax_tree_source_views_unittest.cc',
'accessibility/native_view_accessibility_win_unittest.cc',
'accessible_pane_view_unittest.cc',
'animation/bounds_animator_unittest.cc',