| 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.h" | 5 #include "ui/accessibility/ax_tree.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 update_state->new_nodes.insert(node); | 236 update_state->new_nodes.insert(node); |
| 237 node->SetData(src); | 237 node->SetData(src); |
| 238 } | 238 } |
| 239 | 239 |
| 240 if (delegate_) | 240 if (delegate_) |
| 241 delegate_->OnNodeChanged(this, node); | 241 delegate_->OnNodeChanged(this, node); |
| 242 | 242 |
| 243 // First, delete nodes that used to be children of this node but aren't | 243 // First, delete nodes that used to be children of this node but aren't |
| 244 // anymore. | 244 // anymore. |
| 245 if (!DeleteOldChildren(node, src.child_ids, update_state)) { | 245 if (!DeleteOldChildren(node, src.child_ids, update_state)) { |
| 246 if (update_state->new_root) | 246 if (update_state->new_root) { |
| 247 DestroySubtree(update_state->new_root, update_state); | 247 AXNode* old_root = root_; |
| 248 root_ = nullptr; |
| 249 |
| 250 DestroySubtree(old_root, update_state); |
| 251 if (node != old_root && |
| 252 update_state->new_nodes.find(node) != update_state->new_nodes.end()) { |
| 253 DestroySubtree(node, update_state); |
| 254 } |
| 255 } |
| 248 return false; | 256 return false; |
| 249 } | 257 } |
| 250 | 258 |
| 251 // Now build a new children vector, reusing nodes when possible, | 259 // Now build a new children vector, reusing nodes when possible, |
| 252 // and swap it in. | 260 // and swap it in. |
| 253 std::vector<AXNode*> new_children; | 261 std::vector<AXNode*> new_children; |
| 254 bool success = CreateNewChildVector( | 262 bool success = CreateNewChildVector( |
| 255 node, src.child_ids, &new_children, update_state); | 263 node, src.child_ids, &new_children, update_state); |
| 256 node->SwapChildren(new_children); | 264 node->SwapChildren(new_children); |
| 257 | 265 |
| 258 // Update the root of the tree if needed. | 266 // Update the root of the tree if needed. |
| 259 if (is_new_root) { | 267 if (is_new_root) { |
| 260 // Make sure root_ always points to something valid or null_, even inside | 268 // Make sure root_ always points to something valid or null_, even inside |
| 261 // DestroySubtree. | 269 // DestroySubtree. |
| 262 AXNode* old_root = root_; | 270 AXNode* old_root = root_; |
| 263 root_ = node; | 271 root_ = node; |
| 264 if (old_root) | 272 if (old_root && old_root != node) |
| 265 DestroySubtree(old_root, update_state); | 273 DestroySubtree(old_root, update_state); |
| 266 } | 274 } |
| 267 | 275 |
| 268 return success; | 276 return success; |
| 269 } | 277 } |
| 270 | 278 |
| 271 void AXTree::DestroySubtree(AXNode* node, | 279 void AXTree::DestroySubtree(AXNode* node, |
| 272 AXTreeUpdateState* update_state) { | 280 AXTreeUpdateState* update_state) { |
| 273 DCHECK(update_state); | 281 DCHECK(update_state); |
| 274 if (delegate_) { | 282 if (delegate_) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 update_state->pending_nodes.insert(child); | 360 update_state->pending_nodes.insert(child); |
| 353 update_state->new_nodes.insert(child); | 361 update_state->new_nodes.insert(child); |
| 354 } | 362 } |
| 355 new_children->push_back(child); | 363 new_children->push_back(child); |
| 356 } | 364 } |
| 357 | 365 |
| 358 return success; | 366 return success; |
| 359 } | 367 } |
| 360 | 368 |
| 361 } // namespace ui | 369 } // namespace ui |
| OLD | NEW |