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 | |
David Tseng
2015/06/22 20:58:29
Is there a specific source tree with this issue? P
dmazzoni
2015/06/22 21:11:26
The test I added exposes this bug. I added a speci
| |
337 // correct parent/child relationships until you walk the whole tree once. | |
338 WalkAllDescendants(lca); | |
339 | |
332 SerializeChangedNodes(lca, out_update); | 340 SerializeChangedNodes(lca, out_update); |
333 } | 341 } |
334 | 342 |
335 template<typename AXSourceNode> | 343 template<typename AXSourceNode> |
336 void AXTreeSerializer<AXSourceNode>::DeleteClientSubtree(AXSourceNode node) { | 344 void AXTreeSerializer<AXSourceNode>::DeleteClientSubtree(AXSourceNode node) { |
337 ClientTreeNode* client_node = ClientTreeNodeById(tree_->GetId(node)); | 345 ClientTreeNode* client_node = ClientTreeNodeById(tree_->GetId(node)); |
338 if (client_node) | 346 if (client_node) |
339 DeleteClientSubtree(client_node); | 347 DeleteClientSubtree(client_node); |
340 } | 348 } |
341 | 349 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
465 SerializeChangedNodes(child, out_update); | 473 SerializeChangedNodes(child, out_update); |
466 } | 474 } |
467 } | 475 } |
468 | 476 |
469 // Finally, update the child ids of this node to reflect the actual child | 477 // Finally, update the child ids of this node to reflect the actual child |
470 // ids that were valid during serialization. | 478 // ids that were valid during serialization. |
471 out_update->nodes[serialized_node_index].child_ids.swap( | 479 out_update->nodes[serialized_node_index].child_ids.swap( |
472 actual_serialized_node_child_ids); | 480 actual_serialized_node_child_ids); |
473 } | 481 } |
474 | 482 |
483 template<typename AXSourceNode> | |
484 void AXTreeSerializer<AXSourceNode>::WalkAllDescendants( | |
485 AXSourceNode node) { | |
486 std::vector<AXSourceNode> children; | |
487 tree_->GetChildren(node, &children); | |
488 for (size_t i = 0; i < children.size(); ++i) | |
489 WalkAllDescendants(children[i]); | |
490 } | |
491 | |
475 } // namespace ui | 492 } // namespace ui |
476 | 493 |
477 #endif // UI_ACCESSIBILITY_AX_TREE_SERIALIZER_H_ | 494 #endif // UI_ACCESSIBILITY_AX_TREE_SERIALIZER_H_ |
OLD | NEW |