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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 update_state->new_nodes.insert(node); | 213 update_state->new_nodes.insert(node); |
214 node->SetData(src); | 214 node->SetData(src); |
215 } | 215 } |
216 | 216 |
217 if (delegate_) | 217 if (delegate_) |
218 delegate_->OnNodeChanged(this, node); | 218 delegate_->OnNodeChanged(this, node); |
219 | 219 |
220 // First, delete nodes that used to be children of this node but aren't | 220 // First, delete nodes that used to be children of this node but aren't |
221 // anymore. | 221 // anymore. |
222 if (!DeleteOldChildren(node, src.child_ids, update_state)) { | 222 if (!DeleteOldChildren(node, src.child_ids, update_state)) { |
223 if (update_state->new_root) | 223 if (update_state->new_root) { |
224 DestroySubtree(update_state->new_root, update_state); | 224 DestroySubtree(root_, update_state); |
| 225 root_ = nullptr; |
| 226 } |
225 return false; | 227 return false; |
226 } | 228 } |
227 | 229 |
228 // Now build a new children vector, reusing nodes when possible, | 230 // Now build a new children vector, reusing nodes when possible, |
229 // and swap it in. | 231 // and swap it in. |
230 std::vector<AXNode*> new_children; | 232 std::vector<AXNode*> new_children; |
231 bool success = CreateNewChildVector( | 233 bool success = CreateNewChildVector( |
232 node, src.child_ids, &new_children, update_state); | 234 node, src.child_ids, &new_children, update_state); |
233 node->SwapChildren(new_children); | 235 node->SwapChildren(new_children); |
234 | 236 |
235 // Update the root of the tree if needed. | 237 // Update the root of the tree if needed. |
236 if (is_new_root) { | 238 if (is_new_root) { |
237 // Make sure root_ always points to something valid or null_, even inside | 239 // Make sure root_ always points to something valid or null_, even inside |
238 // DestroySubtree. | 240 // DestroySubtree. |
239 AXNode* old_root = root_; | 241 AXNode* old_root = root_; |
240 root_ = node; | 242 root_ = node; |
241 if (old_root) | 243 if (old_root && old_root != node) |
242 DestroySubtree(old_root, update_state); | 244 DestroySubtree(old_root, update_state); |
243 } | 245 } |
244 | 246 |
245 return success; | 247 return success; |
246 } | 248 } |
247 | 249 |
248 void AXTree::DestroySubtree(AXNode* node, | 250 void AXTree::DestroySubtree(AXNode* node, |
249 AXTreeUpdateState* update_state) { | 251 AXTreeUpdateState* update_state) { |
250 if (delegate_) | 252 if (delegate_) |
251 delegate_->OnSubtreeWillBeDeleted(this, node); | 253 delegate_->OnSubtreeWillBeDeleted(this, node); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 update_state->pending_nodes.insert(child); | 322 update_state->pending_nodes.insert(child); |
321 update_state->new_nodes.insert(child); | 323 update_state->new_nodes.insert(child); |
322 } | 324 } |
323 new_children->push_back(child); | 325 new_children->push_back(child); |
324 } | 326 } |
325 | 327 |
326 return success; | 328 return success; |
327 } | 329 } |
328 | 330 |
329 } // namespace ui | 331 } // namespace ui |
OLD | NEW |