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 #ifndef UI_ACCESSIBILITY_AX_TREE_SERIALIZER_H_ | 5 #ifndef UI_ACCESSIBILITY_AX_TREE_SERIALIZER_H_ |
6 #define UI_ACCESSIBILITY_AX_TREE_SERIALIZER_H_ | 6 #define UI_ACCESSIBILITY_AX_TREE_SERIALIZER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 ClientTreeNode* ClientTreeNodeById(int32 id); | 130 ClientTreeNode* ClientTreeNodeById(int32 id); |
131 | 131 |
132 // Delete the given client tree node and recursively delete all of its | 132 // Delete the given client tree node and recursively delete all of its |
133 // descendants. | 133 // descendants. |
134 void DeleteClientSubtree(ClientTreeNode* client_node); | 134 void DeleteClientSubtree(ClientTreeNode* client_node); |
135 | 135 |
136 // Helper function, called recursively with each new node to serialize. | 136 // Helper function, called recursively with each new node to serialize. |
137 void SerializeChangedNodes(AXSourceNode node, | 137 void SerializeChangedNodes(AXSourceNode node, |
138 AXTreeUpdate* out_update); | 138 AXTreeUpdate* out_update); |
139 | 139 |
| 140 // Visit all of the descendants of |node| once. |
| 141 void WalkAllDescendants(AXSourceNode node); |
| 142 |
140 // The tree source. | 143 // The tree source. |
141 AXTreeSource<AXSourceNode>* tree_; | 144 AXTreeSource<AXSourceNode>* tree_; |
142 | 145 |
143 // Our representation of the client tree. | 146 // Our representation of the client tree. |
144 ClientTreeNode* client_root_; | 147 ClientTreeNode* client_root_; |
145 | 148 |
146 // A map from IDs to nodes in the client tree. | 149 // A map from IDs to nodes in the client tree. |
147 base::hash_map<int32, ClientTreeNode*> client_id_map_; | 150 base::hash_map<int32, ClientTreeNode*> client_id_map_; |
148 }; | 151 }; |
149 | 152 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 ClientTreeNode* client_lca = ClientTreeNodeById(tree_->GetId(lca)); | 325 ClientTreeNode* client_lca = ClientTreeNodeById(tree_->GetId(lca)); |
323 CHECK(client_lca); | 326 CHECK(client_lca); |
324 DeleteClientSubtree(client_lca); | 327 DeleteClientSubtree(client_lca); |
325 } | 328 } |
326 } | 329 } |
327 } while (need_delete); | 330 } while (need_delete); |
328 | 331 |
329 // Serialize from the LCA, or from the root if there isn't one. | 332 // Serialize from the LCA, or from the root if there isn't one. |
330 if (!tree_->IsValid(lca)) | 333 if (!tree_->IsValid(lca)) |
331 lca = tree_->GetRoot(); | 334 lca = tree_->GetRoot(); |
| 335 |
| 336 // Work around flaky source trees where nodes don't figure out their |
| 337 // correct parent/child relationships until you walk the whole tree once. |
| 338 // Covered by this test in the content_browsertests suite: |
| 339 // DumpAccessibilityTreeTest.AccessibilityAriaOwns. |
| 340 WalkAllDescendants(lca); |
| 341 |
332 SerializeChangedNodes(lca, out_update); | 342 SerializeChangedNodes(lca, out_update); |
333 } | 343 } |
334 | 344 |
335 template<typename AXSourceNode> | 345 template<typename AXSourceNode> |
336 void AXTreeSerializer<AXSourceNode>::DeleteClientSubtree(AXSourceNode node) { | 346 void AXTreeSerializer<AXSourceNode>::DeleteClientSubtree(AXSourceNode node) { |
337 ClientTreeNode* client_node = ClientTreeNodeById(tree_->GetId(node)); | 347 ClientTreeNode* client_node = ClientTreeNodeById(tree_->GetId(node)); |
338 if (client_node) | 348 if (client_node) |
339 DeleteClientSubtree(client_node); | 349 DeleteClientSubtree(client_node); |
340 } | 350 } |
341 | 351 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 SerializeChangedNodes(child, out_update); | 475 SerializeChangedNodes(child, out_update); |
466 } | 476 } |
467 } | 477 } |
468 | 478 |
469 // Finally, update the child ids of this node to reflect the actual child | 479 // Finally, update the child ids of this node to reflect the actual child |
470 // ids that were valid during serialization. | 480 // ids that were valid during serialization. |
471 out_update->nodes[serialized_node_index].child_ids.swap( | 481 out_update->nodes[serialized_node_index].child_ids.swap( |
472 actual_serialized_node_child_ids); | 482 actual_serialized_node_child_ids); |
473 } | 483 } |
474 | 484 |
| 485 template<typename AXSourceNode> |
| 486 void AXTreeSerializer<AXSourceNode>::WalkAllDescendants( |
| 487 AXSourceNode node) { |
| 488 std::vector<AXSourceNode> children; |
| 489 tree_->GetChildren(node, &children); |
| 490 for (size_t i = 0; i < children.size(); ++i) |
| 491 WalkAllDescendants(children[i]); |
| 492 } |
| 493 |
475 } // namespace ui | 494 } // namespace ui |
476 | 495 |
477 #endif // UI_ACCESSIBILITY_AX_TREE_SERIALIZER_H_ | 496 #endif // UI_ACCESSIBILITY_AX_TREE_SERIALIZER_H_ |
OLD | NEW |