Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: ui/accessibility/ax_tree.cc

Issue 940753002: accessibility: Simpler AXTree root accessor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix win Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/accessibility/ax_tree.h ('k') | ui/accessibility/ax_tree_serializer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/accessibility/ax_tree.h" 5 #include "ui/accessibility/ax_tree.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "ui/accessibility/ax_node.h" 11 #include "ui/accessibility/ax_node.h"
12 12
13 namespace ui { 13 namespace ui {
14 14
15 namespace { 15 namespace {
16 16
17 std::string TreeToStringHelper(AXNode* node, int indent) { 17 std::string TreeToStringHelper(AXNode* node, int indent) {
18 std::string result = std::string(2 * indent, ' '); 18 std::string result = std::string(2 * indent, ' ');
19 result += node->data().ToString() + "\n"; 19 result += node->data().ToString() + "\n";
20 for (int i = 0; i < node->child_count(); ++i) 20 for (int i = 0; i < node->child_count(); ++i)
21 result += TreeToStringHelper(node->ChildAtIndex(i), indent + 1); 21 result += TreeToStringHelper(node->ChildAtIndex(i), indent + 1);
22 return result; 22 return result;
23 } 23 }
24 24
25 } // anonymous namespace 25 } // namespace
26 26
27 // Intermediate state to keep track of during a tree update. 27 // Intermediate state to keep track of during a tree update.
28 struct AXTreeUpdateState { 28 struct AXTreeUpdateState {
29 // During an update, this keeps track of all nodes that have been 29 // During an update, this keeps track of all nodes that have been
30 // implicitly referenced as part of this update, but haven't been 30 // implicitly referenced as part of this update, but haven't been
31 // updated yet. It's an error if there are any pending nodes at the 31 // updated yet. It's an error if there are any pending nodes at the
32 // end of Unserialize. 32 // end of Unserialize.
33 std::set<AXNode*> pending_nodes; 33 std::set<AXNode*> pending_nodes;
34 34
35 // Keeps track of new nodes created during this update. 35 // Keeps track of new nodes created during this update.
(...skipping 24 matching lines...) Expand all
60 60
61 AXTree::~AXTree() { 61 AXTree::~AXTree() {
62 if (root_) 62 if (root_)
63 DestroyNodeAndSubtree(root_); 63 DestroyNodeAndSubtree(root_);
64 } 64 }
65 65
66 void AXTree::SetDelegate(AXTreeDelegate* delegate) { 66 void AXTree::SetDelegate(AXTreeDelegate* delegate) {
67 delegate_ = delegate; 67 delegate_ = delegate;
68 } 68 }
69 69
70 AXNode* AXTree::GetRoot() const {
71 return root_;
72 }
73
74 AXNode* AXTree::GetFromId(int32 id) const { 70 AXNode* AXTree::GetFromId(int32 id) const {
75 base::hash_map<int32, AXNode*>::const_iterator iter = id_map_.find(id); 71 base::hash_map<int32, AXNode*>::const_iterator iter = id_map_.find(id);
76 return iter != id_map_.end() ? iter->second : NULL; 72 return iter != id_map_.end() ? iter->second : NULL;
77 } 73 }
78 74
79 bool AXTree::Unserialize(const AXTreeUpdate& update) { 75 bool AXTree::Unserialize(const AXTreeUpdate& update) {
80 AXTreeUpdateState update_state; 76 AXTreeUpdateState update_state;
81 int32 old_root_id = root_ ? root_->id() : 0; 77 int32 old_root_id = root_ ? root_->id() : 0;
82 78
83 if (update.node_id_to_clear != 0) { 79 if (update.node_id_to_clear != 0) {
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 update_state->pending_nodes.insert(child); 269 update_state->pending_nodes.insert(child);
274 update_state->new_nodes.insert(child); 270 update_state->new_nodes.insert(child);
275 } 271 }
276 new_children->push_back(child); 272 new_children->push_back(child);
277 } 273 }
278 274
279 return success; 275 return success;
280 } 276 }
281 277
282 } // namespace ui 278 } // namespace ui
OLDNEW
« no previous file with comments | « ui/accessibility/ax_tree.h ('k') | ui/accessibility/ax_tree_serializer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698