Chromium Code Reviews| 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 bool need_delete; |
| 296 bool need_delete = false; | 296 do { |
| 297 if (tree_->IsValid(lca)) { | 297 need_delete = false; |
| 298 // Check for any reparenting within this subtree - if there is | 298 if (client_root_) { |
| 299 // any, we need to delete and reserialize the whole subtree | 299 if (tree_->IsValid(lca)) { |
| 300 // that contains the old and new parents of the reparented node. | 300 // Check for any reparenting within this subtree - if there is |
| 301 if (AnyDescendantWasReparented(lca, &lca)) | 301 // any, we need to delete and reserialize the whole subtree |
| 302 need_delete = true; | 302 // that contains the old and new parents of the reparented node. |
| 303 if (AnyDescendantWasReparented(lca, &lca)) | |
| 304 need_delete = true; | |
| 305 } | |
| 306 | |
| 307 if (!tree_->IsValid(lca)) { | |
| 308 // If there's no LCA, just tell the client to destroy the whole | |
| 309 // tree and then we'll serialize everything from the new root. | |
| 310 out_update->node_id_to_clear = client_root_->id; | |
| 311 Reset(); | |
| 312 } else if (need_delete) { | |
| 313 // Otherwise, if we need to reserialize a subtree, first we need | |
| 314 // to delete those nodes in our client tree so that | |
| 315 // SerializeChangedNodes() will be sure to send them again. | |
| 316 out_update->node_id_to_clear = tree_->GetId(lca); | |
| 317 ClientTreeNode* client_lca = ClientTreeNodeById(tree_->GetId(lca)); | |
| 318 CHECK(client_lca); | |
| 319 | |
| 320 for (size_t i = 0; i < client_lca->children.size(); ++i) { | |
| 321 client_id_map_.erase(client_lca->children[i]->id); | |
| 322 DeleteClientSubtree(client_lca->children[i]); | |
| 323 delete client_lca->children[i]; | |
| 324 } | |
| 325 client_lca->children.clear(); | |
| 326 } | |
| 303 } | 327 } |
| 304 | 328 |
| 305 if (!tree_->IsValid(lca)) { | 329 // If we deleted a client subtree, we have to call |
| 306 // If there's no LCA, just tell the client to destroy the whole | 330 // AnyDescendantWasReparented again because the computed LCA may be |
| 307 // tree and then we'll serialize everything from the new root. | 331 // different now. |
|
David Tseng
2015/03/11 21:19:27
Please rebase.
dmazzoni
2015/03/17 17:47:32
Done.
| |
| 308 out_update->node_id_to_clear = client_root_->id; | 332 } while (need_delete); |
| 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 | 333 |
| 326 // Serialize from the LCA, or from the root if there isn't one. | 334 // Serialize from the LCA, or from the root if there isn't one. |
| 327 if (!tree_->IsValid(lca)) | 335 if (!tree_->IsValid(lca)) |
| 328 lca = tree_->GetRoot(); | 336 lca = tree_->GetRoot(); |
| 329 SerializeChangedNodes(lca, out_update); | 337 SerializeChangedNodes(lca, out_update); |
| 330 } | 338 } |
| 331 | 339 |
| 332 template<typename AXSourceNode> | 340 template<typename AXSourceNode> |
| 333 void AXTreeSerializer<AXSourceNode>::DeleteClientSubtree(AXSourceNode node) { | 341 void AXTreeSerializer<AXSourceNode>::DeleteClientSubtree(AXSourceNode node) { |
| 334 ClientTreeNode* client_node = ClientTreeNodeById(tree_->GetId(node)); | 342 ClientTreeNode* client_node = ClientTreeNodeById(tree_->GetId(node)); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 } | 464 } |
| 457 | 465 |
| 458 // Serialize all of the new children, recursively. | 466 // Serialize all of the new children, recursively. |
| 459 for (size_t i = 0; i < children_to_serialize.size(); ++i) | 467 for (size_t i = 0; i < children_to_serialize.size(); ++i) |
| 460 SerializeChangedNodes(children_to_serialize[i], out_update); | 468 SerializeChangedNodes(children_to_serialize[i], out_update); |
| 461 } | 469 } |
| 462 | 470 |
| 463 } // namespace ui | 471 } // namespace ui |
| 464 | 472 |
| 465 #endif // UI_ACCESSIBILITY_AX_TREE_SERIALIZER_H_ | 473 #endif // UI_ACCESSIBILITY_AX_TREE_SERIALIZER_H_ |
| OLD | NEW |