| 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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 } | 285 } |
| 286 | 286 |
| 287 template<typename AXSourceNode> | 287 template<typename AXSourceNode> |
| 288 void AXTreeSerializer<AXSourceNode>::SerializeChanges( | 288 void AXTreeSerializer<AXSourceNode>::SerializeChanges( |
| 289 AXSourceNode node, | 289 AXSourceNode node, |
| 290 AXTreeUpdate* out_update) { | 290 AXTreeUpdate* out_update) { |
| 291 // If the node isn't in the client tree, we need to serialize starting | 291 // If the node isn't in the client tree, we need to serialize starting |
| 292 // with the LCA. | 292 // with the LCA. |
| 293 AXSourceNode lca = LeastCommonAncestor(node); | 293 AXSourceNode lca = LeastCommonAncestor(node); |
| 294 | 294 |
| 295 if (client_root_) { | 295 // This loop computes the least common ancestor that includes the old |
| 296 bool need_delete = false; | 296 // and new parents of any nodes that have been reparented, and clears the |
| 297 if (tree_->IsValid(lca)) { | 297 // whole client subtree of that LCA if necessary. If we do end up clearing |
| 298 // Check for any reparenting within this subtree - if there is | 298 // any client nodes, keep looping because we have to search for more |
| 299 // any, we need to delete and reserialize the whole subtree | 299 // nodes that may have been reparented from this new LCA. |
| 300 // that contains the old and new parents of the reparented node. | 300 bool need_delete; |
| 301 if (AnyDescendantWasReparented(lca, &lca)) | 301 do { |
| 302 need_delete = true; | 302 need_delete = false; |
| 303 if (client_root_) { |
| 304 if (tree_->IsValid(lca)) { |
| 305 // Check for any reparenting within this subtree - if there is |
| 306 // any, we need to delete and reserialize the whole subtree |
| 307 // that contains the old and new parents of the reparented node. |
| 308 if (AnyDescendantWasReparented(lca, &lca)) |
| 309 need_delete = true; |
| 310 } |
| 311 |
| 312 if (!tree_->IsValid(lca)) { |
| 313 // If there's no LCA, just tell the client to destroy the whole |
| 314 // tree and then we'll serialize everything from the new root. |
| 315 out_update->node_id_to_clear = client_root_->id; |
| 316 Reset(); |
| 317 } else if (need_delete) { |
| 318 // Otherwise, if we need to reserialize a subtree, first we need |
| 319 // to delete those nodes in our client tree so that |
| 320 // SerializeChangedNodes() will be sure to send them again. |
| 321 out_update->node_id_to_clear = tree_->GetId(lca); |
| 322 ClientTreeNode* client_lca = ClientTreeNodeById(tree_->GetId(lca)); |
| 323 CHECK(client_lca); |
| 324 DeleteClientSubtree(client_lca); |
| 325 } |
| 303 } | 326 } |
| 304 | 327 } while (need_delete); |
| 305 if (!tree_->IsValid(lca)) { | |
| 306 // If there's no LCA, just tell the client to destroy the whole | |
| 307 // tree and then we'll serialize everything from the new root. | |
| 308 out_update->node_id_to_clear = client_root_->id; | |
| 309 Reset(); | |
| 310 } else if (need_delete) { | |
| 311 // Otherwise, if we need to reserialize a subtree, first we need | |
| 312 // to delete those nodes in our client tree so that | |
| 313 // SerializeChangedNodes() will be sure to send them again. | |
| 314 out_update->node_id_to_clear = tree_->GetId(lca); | |
| 315 ClientTreeNode* client_lca = ClientTreeNodeById(tree_->GetId(lca)); | |
| 316 CHECK(client_lca); | |
| 317 for (size_t i = 0; i < client_lca->children.size(); ++i) { | |
| 318 client_id_map_.erase(client_lca->children[i]->id); | |
| 319 DeleteClientSubtree(client_lca->children[i]); | |
| 320 delete client_lca->children[i]; | |
| 321 } | |
| 322 client_lca->children.clear(); | |
| 323 } | |
| 324 } | |
| 325 | 328 |
| 326 // Serialize from the LCA, or from the root if there isn't one. | 329 // Serialize from the LCA, or from the root if there isn't one. |
| 327 if (!tree_->IsValid(lca)) | 330 if (!tree_->IsValid(lca)) |
| 328 lca = tree_->GetRoot(); | 331 lca = tree_->GetRoot(); |
| 329 SerializeChangedNodes(lca, out_update); | 332 SerializeChangedNodes(lca, out_update); |
| 330 } | 333 } |
| 331 | 334 |
| 332 template<typename AXSourceNode> | 335 template<typename AXSourceNode> |
| 333 void AXTreeSerializer<AXSourceNode>::DeleteClientSubtree(AXSourceNode node) { | 336 void AXTreeSerializer<AXSourceNode>::DeleteClientSubtree(AXSourceNode node) { |
| 334 ClientTreeNode* client_node = ClientTreeNodeById(tree_->GetId(node)); | 337 ClientTreeNode* client_node = ClientTreeNodeById(tree_->GetId(node)); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 } | 459 } |
| 457 | 460 |
| 458 // Serialize all of the new children, recursively. | 461 // Serialize all of the new children, recursively. |
| 459 for (size_t i = 0; i < children_to_serialize.size(); ++i) | 462 for (size_t i = 0; i < children_to_serialize.size(); ++i) |
| 460 SerializeChangedNodes(children_to_serialize[i], out_update); | 463 SerializeChangedNodes(children_to_serialize[i], out_update); |
| 461 } | 464 } |
| 462 | 465 |
| 463 } // namespace ui | 466 } // namespace ui |
| 464 | 467 |
| 465 #endif // UI_ACCESSIBILITY_AX_TREE_SERIALIZER_H_ | 468 #endif // UI_ACCESSIBILITY_AX_TREE_SERIALIZER_H_ |
| OLD | NEW |