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_update.h" | 5 #include "ui/accessibility/ax_tree_update.h" |
6 | 6 |
| 7 #include "base/containers/hash_tables.h" |
| 8 #include "base/strings/string_number_conversions.h" |
| 9 |
7 namespace ui { | 10 namespace ui { |
8 | 11 |
9 AXTreeUpdate::AXTreeUpdate() : node_id_to_clear(0) { | 12 AXTreeUpdate::AXTreeUpdate() : node_id_to_clear(0) { |
10 } | 13 } |
11 | 14 |
12 AXTreeUpdate::~AXTreeUpdate() { | 15 AXTreeUpdate::~AXTreeUpdate() { |
13 } | 16 } |
14 | 17 |
| 18 std::string AXTreeUpdate::ToString() const { |
| 19 std::string result; |
| 20 if (node_id_to_clear != 0) { |
| 21 result += "AXTreeUpdate: clear node " + |
| 22 base::IntToString(node_id_to_clear) + "\n"; |
| 23 } |
| 24 |
| 25 // The challenge here is that we want to indent the nodes being updated |
| 26 // so that parent/child relationships are clear, but we don't have access |
| 27 // to the rest of the tree for context, so we have to try to show the |
| 28 // relative indentation of child nodes in this update relative to their |
| 29 // parents. |
| 30 base::hash_map<int32, int> id_to_indentation; |
| 31 for (size_t i = 0; i < nodes.size(); ++i) { |
| 32 int indent = id_to_indentation[nodes[i].id]; |
| 33 result += std::string(2 * indent, ' '); |
| 34 result += nodes[i].ToString() + "\n"; |
| 35 for (size_t j = 0; j < nodes[i].child_ids.size(); ++j) |
| 36 id_to_indentation[nodes[i].child_ids[j]] = indent + 1; |
| 37 } |
| 38 |
| 39 return result; |
| 40 } |
| 41 |
15 } // namespace ui | 42 } // namespace ui |
OLD | NEW |