Commit 6b1c1e08 authored by tfarina's avatar tfarina Committed by Commit bot

accessibility: Simpler AXTree root accessor.

- It does not need to be virtual.
- Since it is a simple getter accessor it can be inlined in the header
file and thus renamed to just root().

BUG=None
R=dmazzoni@chromium.org,avi@chromium.org
TBR=dtseng@chromium.org

Review URL: https://codereview.chromium.org/940753002

Cr-Commit-Position: refs/heads/master@{#317444}
parent a43a4b01
...@@ -237,10 +237,10 @@ class TreeSerializationState { ...@@ -237,10 +237,10 @@ class TreeSerializationState {
int routing_id, int routing_id,
BrowserContext* browser_context) { BrowserContext* browser_context) {
ui::AXTreeUpdate update; ui::AXTreeUpdate update;
serializer->SerializeChanges(tree->GetRoot(), &update); serializer->SerializeChanges(tree->root(), &update);
SendUpdate(update, SendUpdate(update,
ui::AX_EVENT_LAYOUT_COMPLETE, ui::AX_EVENT_LAYOUT_COMPLETE,
tree->GetRoot()->id(), tree->root()->id(),
routing_id, routing_id,
browser_context); browser_context);
} }
...@@ -398,14 +398,14 @@ void TransformTree(TreeSerializer* source_serializer, ...@@ -398,14 +398,14 @@ void TransformTree(TreeSerializer* source_serializer,
ui::AXEvent event = ui::AXEvent event =
is_last_update ? AX_EVENT_ASSERT_EQUAL : AX_EVENT_IGNORE; is_last_update ? AX_EVENT_ASSERT_EQUAL : AX_EVENT_IGNORE;
state.SendUpdate( state.SendUpdate(
update, event, target_tree->GetRoot()->id(), kTab0Rid, browser_context); update, event, target_tree->root()->id(), kTab0Rid, browser_context);
} }
} }
// Helper method to send a no-op tree update to tab 0 with the given event. // Helper method to send a no-op tree update to tab 0 with the given event.
void SendEvent(ui::AXEvent event, content::BrowserContext* browser_context) { void SendEvent(ui::AXEvent event, content::BrowserContext* browser_context) {
ui::AXTreeUpdate update; ui::AXTreeUpdate update;
ui::AXNode* root = state.tree0->GetRoot(); ui::AXNode* root = state.tree0->root();
state.serializer0->SerializeChanges(root, &update); state.serializer0->SerializeChanges(root, &update);
state.SendUpdate(update, event, root->id(), kTab0Rid, browser_context); state.SendUpdate(update, event, root->id(), kTab0Rid, browser_context);
} }
......
...@@ -107,7 +107,7 @@ IN_PROC_BROWSER_TEST_F(AccessibilityIpcErrorBrowserTest, ...@@ -107,7 +107,7 @@ IN_PROC_BROWSER_TEST_F(AccessibilityIpcErrorBrowserTest,
// Get the accessibility tree, ensure it reflects the final state of the // Get the accessibility tree, ensure it reflects the final state of the
// document. // document.
const ui::AXNode* root = tree->GetRoot(); const ui::AXNode* root = tree->root();
// Use this for debugging if the test fails. // Use this for debugging if the test fails.
VLOG(1) << tree->ToString(); VLOG(1) << tree->ToString();
......
...@@ -114,7 +114,7 @@ void BrowserAccessibilityManager::Initialize( ...@@ -114,7 +114,7 @@ void BrowserAccessibilityManager::Initialize(
} }
if (!focus_) if (!focus_)
SetFocus(tree_->GetRoot(), false); SetFocus(tree_->root(), false);
} }
// static // static
...@@ -128,7 +128,7 @@ ui::AXTreeUpdate BrowserAccessibilityManager::GetEmptyDocument() { ...@@ -128,7 +128,7 @@ ui::AXTreeUpdate BrowserAccessibilityManager::GetEmptyDocument() {
} }
BrowserAccessibility* BrowserAccessibilityManager::GetRoot() { BrowserAccessibility* BrowserAccessibilityManager::GetRoot() {
return GetFromAXNode(tree_->GetRoot()); return GetFromAXNode(tree_->root());
} }
BrowserAccessibility* BrowserAccessibilityManager::GetFromAXNode( BrowserAccessibility* BrowserAccessibilityManager::GetFromAXNode(
...@@ -198,7 +198,7 @@ void BrowserAccessibilityManager::OnAccessibilityEvents( ...@@ -198,7 +198,7 @@ void BrowserAccessibilityManager::OnAccessibilityEvents(
// Set focus to the root if it's not anywhere else. // Set focus to the root if it's not anywhere else.
if (!focus_) { if (!focus_) {
SetFocus(tree_->GetRoot(), false); SetFocus(tree_->root(), false);
should_send_initial_focus = true; should_send_initial_focus = true;
} }
} }
...@@ -420,8 +420,8 @@ BrowserAccessibility* BrowserAccessibilityManager::PreviousInTreeOrder( ...@@ -420,8 +420,8 @@ BrowserAccessibility* BrowserAccessibilityManager::PreviousInTreeOrder(
void BrowserAccessibilityManager::OnNodeWillBeDeleted(ui::AXNode* node) { void BrowserAccessibilityManager::OnNodeWillBeDeleted(ui::AXNode* node) {
if (node == focus_ && tree_) { if (node == focus_ && tree_) {
if (node != tree_->GetRoot()) if (node != tree_->root())
SetFocus(tree_->GetRoot(), false); SetFocus(tree_->root(), false);
else else
focus_ = NULL; focus_ = NULL;
} }
...@@ -471,7 +471,7 @@ ui::AXTreeUpdate BrowserAccessibilityManager::SnapshotAXTreeForTesting() { ...@@ -471,7 +471,7 @@ ui::AXTreeUpdate BrowserAccessibilityManager::SnapshotAXTreeForTesting() {
tree_->CreateTreeSource()); tree_->CreateTreeSource());
ui::AXTreeSerializer<const ui::AXNode*> serializer(tree_source.get()); ui::AXTreeSerializer<const ui::AXNode*> serializer(tree_source.get());
ui::AXTreeUpdate update; ui::AXTreeUpdate update;
serializer.SerializeChanges(tree_->GetRoot(), &update); serializer.SerializeChanges(tree_->root(), &update);
return update; return update;
} }
......
...@@ -176,7 +176,7 @@ void BrowserAccessibilityManagerWin::OnWindowFocused() { ...@@ -176,7 +176,7 @@ void BrowserAccessibilityManagerWin::OnWindowFocused() {
// Try to fire a focus event on the root first and then the focused node. // Try to fire a focus event on the root first and then the focused node.
// This will clear focus_event_on_root_needed_ if successful. // This will clear focus_event_on_root_needed_ if successful.
if (focus_ != tree_->GetRoot()) if (focus_ != tree_->root())
NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, GetRoot()); NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, GetRoot());
BrowserAccessibilityManager::OnWindowFocused(); BrowserAccessibilityManager::OnWindowFocused();
} }
......
...@@ -142,7 +142,7 @@ IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest, ...@@ -142,7 +142,7 @@ IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
GURL url(url_str); GURL url(url_str);
NavigateToURL(shell(), url); NavigateToURL(shell(), url);
const ui::AXTree& tree = GetAXTree(); const ui::AXTree& tree = GetAXTree();
const ui::AXNode* root = tree.GetRoot(); const ui::AXNode* root = tree.root();
// Check properties of the root element of the tree. // Check properties of the root element of the tree.
EXPECT_STREQ(url_str, EXPECT_STREQ(url_str,
...@@ -213,7 +213,7 @@ IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest, ...@@ -213,7 +213,7 @@ IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
NavigateToURL(shell(), url); NavigateToURL(shell(), url);
const ui::AXTree& tree = GetAXTree(); const ui::AXTree& tree = GetAXTree();
const ui::AXNode* root = tree.GetRoot(); const ui::AXNode* root = tree.root();
ASSERT_EQ(1, root->child_count()); ASSERT_EQ(1, root->child_count());
const ui::AXNode* body = root->ChildAtIndex(0); const ui::AXNode* body = root->ChildAtIndex(0);
ASSERT_EQ(1, body->child_count()); ASSERT_EQ(1, body->child_count());
...@@ -245,7 +245,7 @@ IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest, ...@@ -245,7 +245,7 @@ IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
NavigateToURL(shell(), url); NavigateToURL(shell(), url);
const ui::AXTree& tree = GetAXTree(); const ui::AXTree& tree = GetAXTree();
const ui::AXNode* root = tree.GetRoot(); const ui::AXNode* root = tree.root();
ASSERT_EQ(1, root->child_count()); ASSERT_EQ(1, root->child_count());
const ui::AXNode* body = root->ChildAtIndex(0); const ui::AXNode* body = root->ChildAtIndex(0);
ASSERT_EQ(1, body->child_count()); ASSERT_EQ(1, body->child_count());
...@@ -275,7 +275,7 @@ IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest, ...@@ -275,7 +275,7 @@ IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
NavigateToURL(shell(), url); NavigateToURL(shell(), url);
const ui::AXTree& tree = GetAXTree(); const ui::AXTree& tree = GetAXTree();
const ui::AXNode* root = tree.GetRoot(); const ui::AXNode* root = tree.root();
ASSERT_EQ(1, root->child_count()); ASSERT_EQ(1, root->child_count());
const ui::AXNode* table = root->ChildAtIndex(0); const ui::AXNode* table = root->ChildAtIndex(0);
EXPECT_EQ(ui::AX_ROLE_TABLE, table->data().role); EXPECT_EQ(ui::AX_ROLE_TABLE, table->data().role);
...@@ -324,7 +324,7 @@ IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest, ...@@ -324,7 +324,7 @@ IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
NavigateToURL(shell(), url); NavigateToURL(shell(), url);
const ui::AXTree& tree = GetAXTree(); const ui::AXTree& tree = GetAXTree();
const ui::AXNode* root = tree.GetRoot(); const ui::AXNode* root = tree.root();
base::hash_set<int> ids; base::hash_set<int> ids;
RecursiveAssertUniqueIds(root, &ids); RecursiveAssertUniqueIds(root, &ids);
} }
...@@ -346,7 +346,7 @@ IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest, ...@@ -346,7 +346,7 @@ IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
NavigateToURL(shell(), url); NavigateToURL(shell(), url);
const ui::AXTree& tree = GetAXTree(); const ui::AXTree& tree = GetAXTree();
const ui::AXNode* root = tree.GetRoot(); const ui::AXNode* root = tree.root();
ASSERT_EQ(1, root->child_count()); ASSERT_EQ(1, root->child_count());
const ui::AXNode* body = root->ChildAtIndex(0); const ui::AXNode* body = root->ChildAtIndex(0);
ASSERT_EQ(3, body->child_count()); ASSERT_EQ(3, body->child_count());
...@@ -397,7 +397,7 @@ IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest, ...@@ -397,7 +397,7 @@ IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
NavigateToURL(shell(), url); NavigateToURL(shell(), url);
const ui::AXTree& tree = GetAXTree(); const ui::AXTree& tree = GetAXTree();
const ui::AXNode* root = tree.GetRoot(); const ui::AXNode* root = tree.root();
base::hash_set<int> ids; base::hash_set<int> ids;
RecursiveAssertUniqueIds(root, &ids); RecursiveAssertUniqueIds(root, &ids);
} }
...@@ -425,7 +425,7 @@ IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest, ...@@ -425,7 +425,7 @@ IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
NavigateToURL(shell(), url); NavigateToURL(shell(), url);
const ui::AXTree& tree = GetAXTree(); const ui::AXTree& tree = GetAXTree();
const ui::AXNode* root = tree.GetRoot(); const ui::AXNode* root = tree.root();
const ui::AXNode* table = root->ChildAtIndex(0); const ui::AXNode* table = root->ChildAtIndex(0);
EXPECT_EQ(ui::AX_ROLE_TABLE, table->data().role); EXPECT_EQ(ui::AX_ROLE_TABLE, table->data().role);
ASSERT_GE(table->child_count(), 5); ASSERT_GE(table->child_count(), 5);
...@@ -488,7 +488,7 @@ IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest, ...@@ -488,7 +488,7 @@ IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
GURL url(url_str); GURL url(url_str);
NavigateToURL(shell(), url); NavigateToURL(shell(), url);
const ui::AXTree& tree = GetAXTree(); const ui::AXTree& tree = GetAXTree();
const ui::AXNode* root = tree.GetRoot(); const ui::AXNode* root = tree.root();
ASSERT_EQ(1, root->child_count()); ASSERT_EQ(1, root->child_count());
const ui::AXNode* textbox = root->ChildAtIndex(0); const ui::AXNode* textbox = root->ChildAtIndex(0);
EXPECT_EQ(true, GetBoolAttr(textbox, ui::AX_ATTR_CAN_SET_VALUE)); EXPECT_EQ(true, GetBoolAttr(textbox, ui::AX_ATTR_CAN_SET_VALUE));
......
...@@ -92,7 +92,7 @@ bool AccessibilityNotificationWaiter::IsAboutBlank() { ...@@ -92,7 +92,7 @@ bool AccessibilityNotificationWaiter::IsAboutBlank() {
// Skip any accessibility notifications related to "about:blank", // Skip any accessibility notifications related to "about:blank",
// to avoid a possible race condition between the test beginning // to avoid a possible race condition between the test beginning
// listening for accessibility events and "about:blank" loading. // listening for accessibility events and "about:blank" loading.
const ui::AXNodeData& root = GetAXTree().GetRoot()->data(); const ui::AXNodeData& root = GetAXTree().root()->data();
for (size_t i = 0; i < root.string_attributes.size(); ++i) { for (size_t i = 0; i < root.string_attributes.size(); ++i) {
if (root.string_attributes[i].first != ui::AX_ATTR_DOC_URL) if (root.string_attributes[i].first != ui::AX_ATTR_DOC_URL)
continue; continue;
......
...@@ -41,7 +41,7 @@ void TreeToStringHelper(const AXNode* node, std::string* out_result) { ...@@ -41,7 +41,7 @@ void TreeToStringHelper(const AXNode* node, std::string* out_result) {
std::string TreeToString(const AXTree& tree) { std::string TreeToString(const AXTree& tree) {
std::string result; std::string result;
TreeToStringHelper(tree.GetRoot(), &result); TreeToStringHelper(tree.root(), &result);
return "(" + result + ")"; return "(" + result + ")";
} }
...@@ -125,7 +125,7 @@ TEST(AXGeneratedTreeTest, SerializeGeneratedTrees) { ...@@ -125,7 +125,7 @@ TEST(AXGeneratedTreeTest, SerializeGeneratedTrees) {
tree0.CreateTreeSource()); tree0.CreateTreeSource());
AXTreeSerializer<const AXNode*> serializer(tree0_source.get()); AXTreeSerializer<const AXNode*> serializer(tree0_source.get());
AXTreeUpdate update0; AXTreeUpdate update0;
serializer.SerializeChanges(tree0.GetRoot(), &update0); serializer.SerializeChanges(tree0.root(), &update0);
AXTree dst_tree; AXTree dst_tree;
ASSERT_TRUE(dst_tree.Unserialize(update0)); ASSERT_TRUE(dst_tree.Unserialize(update0));
......
...@@ -20,7 +20,7 @@ class AX_EXPORT AXTreeSourceAdapter : public AXTreeSource<const AXNode*> { ...@@ -20,7 +20,7 @@ class AX_EXPORT AXTreeSourceAdapter : public AXTreeSource<const AXNode*> {
~AXTreeSourceAdapter() override {} ~AXTreeSourceAdapter() override {}
// AXTreeSource implementation. // AXTreeSource implementation.
AXNode* GetRoot() const override { return tree_->GetRoot(); } AXNode* GetRoot() const override { return tree_->root(); }
AXNode* GetFromId(int32 id) const override { return tree_->GetFromId(id); } AXNode* GetFromId(int32 id) const override { return tree_->GetFromId(id); }
......
...@@ -22,7 +22,7 @@ std::string TreeToStringHelper(AXNode* node, int indent) { ...@@ -22,7 +22,7 @@ std::string TreeToStringHelper(AXNode* node, int indent) {
return result; return result;
} }
} // anonymous namespace } // namespace
// Intermediate state to keep track of during a tree update. // Intermediate state to keep track of during a tree update.
struct AXTreeUpdateState { struct AXTreeUpdateState {
...@@ -67,10 +67,6 @@ void AXTree::SetDelegate(AXTreeDelegate* delegate) { ...@@ -67,10 +67,6 @@ void AXTree::SetDelegate(AXTreeDelegate* delegate) {
delegate_ = delegate; delegate_ = delegate;
} }
AXNode* AXTree::GetRoot() const {
return root_;
}
AXNode* AXTree::GetFromId(int32 id) const { AXNode* AXTree::GetFromId(int32 id) const {
base::hash_map<int32, AXNode*>::const_iterator iter = id_map_.find(id); base::hash_map<int32, AXNode*>::const_iterator iter = id_map_.find(id);
return iter != id_map_.end() ? iter->second : NULL; return iter != id_map_.end() ? iter->second : NULL;
......
...@@ -91,8 +91,10 @@ class AX_EXPORT AXTree { ...@@ -91,8 +91,10 @@ class AX_EXPORT AXTree {
virtual void SetDelegate(AXTreeDelegate* delegate); virtual void SetDelegate(AXTreeDelegate* delegate);
virtual AXNode* GetRoot() const; AXNode* root() const { return root_; }
virtual AXNode* GetFromId(int32 id) const;
// Returns the AXNode with the given |id| if it is part of this AXTree.
AXNode* GetFromId(int32 id) const;
// Returns true on success. If it returns false, it's a fatal error // Returns true on success. If it returns false, it's a fatal error
// and this tree should be destroyed, and the source of the tree update // and this tree should be destroyed, and the source of the tree update
......
...@@ -50,7 +50,7 @@ void AXTreeSerializerTest::CreateTreeSerializer() { ...@@ -50,7 +50,7 @@ void AXTreeSerializerTest::CreateTreeSerializer() {
tree0_source_.reset(tree0_->CreateTreeSource()); tree0_source_.reset(tree0_->CreateTreeSource());
serializer_.reset(new AXTreeSerializer<const AXNode*>(tree0_source_.get())); serializer_.reset(new AXTreeSerializer<const AXNode*>(tree0_source_.get()));
AXTreeUpdate unused_update; AXTreeUpdate unused_update;
serializer_->SerializeChanges(tree0_->GetRoot(), &unused_update); serializer_->SerializeChanges(tree0_->root(), &unused_update);
// Pretend that tree0_ turned into tree1_. The next call to // Pretend that tree0_ turned into tree1_. The next call to
// AXTreeSerializer will force it to consider these changes to // AXTreeSerializer will force it to consider these changes to
......
...@@ -114,12 +114,12 @@ TEST(AXTreeTest, SerializeSimpleAXTree) { ...@@ -114,12 +114,12 @@ TEST(AXTreeTest, SerializeSimpleAXTree) {
src_tree.CreateTreeSource()); src_tree.CreateTreeSource());
AXTreeSerializer<const AXNode*> serializer(tree_source.get()); AXTreeSerializer<const AXNode*> serializer(tree_source.get());
AXTreeUpdate update; AXTreeUpdate update;
serializer.SerializeChanges(src_tree.GetRoot(), &update); serializer.SerializeChanges(src_tree.root(), &update);
AXTree dst_tree; AXTree dst_tree;
ASSERT_TRUE(dst_tree.Unserialize(update)); ASSERT_TRUE(dst_tree.Unserialize(update));
const AXNode* root_node = dst_tree.GetRoot(); const AXNode* root_node = dst_tree.root();
ASSERT_TRUE(root_node != NULL); ASSERT_TRUE(root_node != NULL);
EXPECT_EQ(root.id, root_node->id()); EXPECT_EQ(root.id, root_node->id());
EXPECT_EQ(root.role, root_node->data().role); EXPECT_EQ(root.role, root_node->data().role);
......
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