OLD | NEW |
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 { |
| 16 |
| 17 std::string TreeToStringHelper(AXNode* node, int indent) { |
| 18 std::string result; |
| 19 for (int i = 0; i < indent; i++) |
| 20 result += " "; |
| 21 result += node->data().ToString() + "\n"; |
| 22 for (int i = 0; i < node->child_count(); ++i) |
| 23 result += TreeToStringHelper(node->ChildAtIndex(i), indent + 1); |
| 24 return result; |
| 25 } |
| 26 |
| 27 } // anonymous namespace |
| 28 |
15 AXTree::AXTree() | 29 AXTree::AXTree() |
16 : root_(NULL) { | 30 : root_(NULL) { |
17 AXNodeData root; | 31 AXNodeData root; |
18 root.id = 0; | 32 root.id = 0; |
19 root.role = AX_ROLE_ROOT_WEB_AREA; | 33 root.role = AX_ROLE_ROOT_WEB_AREA; |
20 | 34 |
21 AXTreeUpdate initial_state; | 35 AXTreeUpdate initial_state; |
22 initial_state.nodes.push_back(root); | 36 initial_state.nodes.push_back(root); |
23 CHECK(Unserialize(initial_state)) << error(); | 37 CHECK(Unserialize(initial_state)) << error(); |
24 } | 38 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 for (std::set<AXNode*>::iterator iter = pending_nodes.begin(); | 88 for (std::set<AXNode*>::iterator iter = pending_nodes.begin(); |
75 iter != pending_nodes.end(); ++iter) { | 89 iter != pending_nodes.end(); ++iter) { |
76 error_ += base::StringPrintf(" %d", (*iter)->id()); | 90 error_ += base::StringPrintf(" %d", (*iter)->id()); |
77 } | 91 } |
78 return false; | 92 return false; |
79 } | 93 } |
80 | 94 |
81 return true; | 95 return true; |
82 } | 96 } |
83 | 97 |
| 98 std::string AXTree::ToString() const { |
| 99 return TreeToStringHelper(root_, 0); |
| 100 } |
| 101 |
84 AXNode* AXTree::CreateNode(AXNode* parent, int32 id, int32 index_in_parent) { | 102 AXNode* AXTree::CreateNode(AXNode* parent, int32 id, int32 index_in_parent) { |
85 return new AXNode(parent, id, index_in_parent); | 103 return new AXNode(parent, id, index_in_parent); |
86 } | 104 } |
87 | 105 |
88 bool AXTree::UpdateNode( | 106 bool AXTree::UpdateNode( |
89 const AXNodeData& src, std::set<AXNode*>* pending_nodes) { | 107 const AXNodeData& src, std::set<AXNode*>* pending_nodes) { |
90 // This method updates one node in the tree based on serialized data | 108 // This method updates one node in the tree based on serialized data |
91 // received in an AXTreeUpdate. See AXTreeUpdate for pre and post | 109 // received in an AXTreeUpdate. See AXTreeUpdate for pre and post |
92 // conditions. | 110 // conditions. |
93 | 111 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 child = CreateAndInitializeNode(node, child_id, index_in_parent); | 220 child = CreateAndInitializeNode(node, child_id, index_in_parent); |
203 pending_nodes->insert(child); | 221 pending_nodes->insert(child); |
204 } | 222 } |
205 new_children->push_back(child); | 223 new_children->push_back(child); |
206 } | 224 } |
207 | 225 |
208 return success; | 226 return success; |
209 } | 227 } |
210 | 228 |
211 } // namespace ui | 229 } // namespace ui |
OLD | NEW |