| 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 <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 // Now build a new children vector, reusing nodes when possible, | 197 // Now build a new children vector, reusing nodes when possible, |
| 198 // and swap it in. | 198 // and swap it in. |
| 199 std::vector<AXNode*> new_children; | 199 std::vector<AXNode*> new_children; |
| 200 bool success = CreateNewChildVector( | 200 bool success = CreateNewChildVector( |
| 201 node, src.child_ids, &new_children, update_state); | 201 node, src.child_ids, &new_children, update_state); |
| 202 node->SwapChildren(new_children); | 202 node->SwapChildren(new_children); |
| 203 | 203 |
| 204 // Update the root of the tree if needed. | 204 // Update the root of the tree if needed. |
| 205 if ((src.role == AX_ROLE_ROOT_WEB_AREA || src.role == AX_ROLE_DESKTOP) && | 205 if ((src.role == AX_ROLE_ROOT_WEB_AREA || src.role == AX_ROLE_DESKTOP) && |
| 206 (!root_ || root_->id() != src.id)) { | 206 (!root_ || root_->id() != src.id)) { |
| 207 if (root_) | 207 // Make sure root_ always points to something valid, even inside |
| 208 DestroySubtree(root_, update_state); | 208 // DestroySubtree. |
| 209 AXNode* old_root = root_; |
| 209 root_ = node; | 210 root_ = node; |
| 211 if (old_root) |
| 212 DestroySubtree(old_root, update_state); |
| 210 } | 213 } |
| 211 | 214 |
| 212 return success; | 215 return success; |
| 213 } | 216 } |
| 214 | 217 |
| 215 void AXTree::DestroySubtree(AXNode* node, | 218 void AXTree::DestroySubtree(AXNode* node, |
| 216 AXTreeUpdateState* update_state) { | 219 AXTreeUpdateState* update_state) { |
| 217 if (delegate_) | 220 if (delegate_) |
| 218 delegate_->OnSubtreeWillBeDeleted(this, node); | 221 delegate_->OnSubtreeWillBeDeleted(this, node); |
| 219 DestroyNodeAndSubtree(node, update_state); | 222 DestroyNodeAndSubtree(node, update_state); |
| 220 } | 223 } |
| 221 | 224 |
| 222 void AXTree::DestroyNodeAndSubtree(AXNode* node, | 225 void AXTree::DestroyNodeAndSubtree(AXNode* node, |
| 223 AXTreeUpdateState* update_state) { | 226 AXTreeUpdateState* update_state) { |
| 227 if (delegate_) |
| 228 delegate_->OnNodeWillBeDeleted(this, node); |
| 224 id_map_.erase(node->id()); | 229 id_map_.erase(node->id()); |
| 225 for (int i = 0; i < node->child_count(); ++i) | 230 for (int i = 0; i < node->child_count(); ++i) |
| 226 DestroyNodeAndSubtree(node->ChildAtIndex(i), update_state); | 231 DestroyNodeAndSubtree(node->ChildAtIndex(i), update_state); |
| 227 if (delegate_) | |
| 228 delegate_->OnNodeWillBeDeleted(this, node); | |
| 229 if (update_state) { | 232 if (update_state) { |
| 230 update_state->pending_nodes.erase(node); | 233 update_state->pending_nodes.erase(node); |
| 231 } | 234 } |
| 232 node->Destroy(); | 235 node->Destroy(); |
| 233 } | 236 } |
| 234 | 237 |
| 235 bool AXTree::DeleteOldChildren(AXNode* node, | 238 bool AXTree::DeleteOldChildren(AXNode* node, |
| 236 const std::vector<int32>& new_child_ids, | 239 const std::vector<int32>& new_child_ids, |
| 237 AXTreeUpdateState* update_state) { | 240 AXTreeUpdateState* update_state) { |
| 238 // Create a set of child ids in |src| for fast lookup, and return false | 241 // Create a set of child ids in |src| for fast lookup, and return false |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 update_state->pending_nodes.insert(child); | 289 update_state->pending_nodes.insert(child); |
| 287 update_state->new_nodes.insert(child); | 290 update_state->new_nodes.insert(child); |
| 288 } | 291 } |
| 289 new_children->push_back(child); | 292 new_children->push_back(child); |
| 290 } | 293 } |
| 291 | 294 |
| 292 return success; | 295 return success; |
| 293 } | 296 } |
| 294 | 297 |
| 295 } // namespace ui | 298 } // namespace ui |
| OLD | NEW |