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 #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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 int32 old_root_id = root_ ? root_->id() : 0; | 82 int32 old_root_id = root_ ? root_->id() : 0; |
| 83 | 83 |
| 84 if (update.node_id_to_clear != 0) { | 84 if (update.node_id_to_clear != 0) { |
| 85 AXNode* node = GetFromId(update.node_id_to_clear); | 85 AXNode* node = GetFromId(update.node_id_to_clear); |
| 86 if (!node) { | 86 if (!node) { |
| 87 error_ = base::StringPrintf("Bad node_id_to_clear: %d", | 87 error_ = base::StringPrintf("Bad node_id_to_clear: %d", |
| 88 update.node_id_to_clear); | 88 update.node_id_to_clear); |
| 89 return false; | 89 return false; |
| 90 } | 90 } |
| 91 if (node == root_) { | 91 if (node == root_) { |
| 92 DestroySubtree(root_, &update_state); | 92 // Make sure root_ always points to something valid or nullptr, |
|
David Tseng
2015/07/27 18:46:38
nit: Confusing comment; root_ is always nullptr in
dmazzoni
2015/07/27 21:40:31
Done.
| |
| 93 root_ = NULL; | 93 // even inside DestroySubtree. |
| 94 AXNode* old_root = root_; | |
| 95 root_ = nullptr; | |
| 96 DestroySubtree(old_root, &update_state); | |
| 94 } else { | 97 } else { |
| 95 for (int i = 0; i < node->child_count(); ++i) | 98 for (int i = 0; i < node->child_count(); ++i) |
| 96 DestroySubtree(node->ChildAtIndex(i), &update_state); | 99 DestroySubtree(node->ChildAtIndex(i), &update_state); |
| 97 std::vector<AXNode*> children; | 100 std::vector<AXNode*> children; |
| 98 node->SwapChildren(children); | 101 node->SwapChildren(children); |
| 99 update_state.pending_nodes.insert(node); | 102 update_state.pending_nodes.insert(node); |
| 100 } | 103 } |
| 101 } | 104 } |
| 102 | 105 |
| 103 for (size_t i = 0; i < update.nodes.size(); ++i) { | 106 for (size_t i = 0; i < update.nodes.size(); ++i) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 // Now build a new children vector, reusing nodes when possible, | 200 // Now build a new children vector, reusing nodes when possible, |
| 198 // and swap it in. | 201 // and swap it in. |
| 199 std::vector<AXNode*> new_children; | 202 std::vector<AXNode*> new_children; |
| 200 bool success = CreateNewChildVector( | 203 bool success = CreateNewChildVector( |
| 201 node, src.child_ids, &new_children, update_state); | 204 node, src.child_ids, &new_children, update_state); |
| 202 node->SwapChildren(new_children); | 205 node->SwapChildren(new_children); |
| 203 | 206 |
| 204 // Update the root of the tree if needed. | 207 // Update the root of the tree if needed. |
| 205 if ((src.role == AX_ROLE_ROOT_WEB_AREA || src.role == AX_ROLE_DESKTOP) && | 208 if ((src.role == AX_ROLE_ROOT_WEB_AREA || src.role == AX_ROLE_DESKTOP) && |
| 206 (!root_ || root_->id() != src.id)) { | 209 (!root_ || root_->id() != src.id)) { |
| 207 if (root_) | 210 // Make sure root_ always points to something valid or null_, even inside |
| 208 DestroySubtree(root_, update_state); | 211 // DestroySubtree. |
| 212 AXNode* old_root = root_; | |
| 209 root_ = node; | 213 root_ = node; |
| 214 if (old_root) | |
| 215 DestroySubtree(old_root, update_state); | |
| 210 } | 216 } |
| 211 | 217 |
| 212 return success; | 218 return success; |
| 213 } | 219 } |
| 214 | 220 |
| 215 void AXTree::DestroySubtree(AXNode* node, | 221 void AXTree::DestroySubtree(AXNode* node, |
| 216 AXTreeUpdateState* update_state) { | 222 AXTreeUpdateState* update_state) { |
| 217 if (delegate_) | 223 if (delegate_) |
| 218 delegate_->OnSubtreeWillBeDeleted(this, node); | 224 delegate_->OnSubtreeWillBeDeleted(this, node); |
| 219 DestroyNodeAndSubtree(node, update_state); | 225 DestroyNodeAndSubtree(node, update_state); |
| 220 } | 226 } |
| 221 | 227 |
| 222 void AXTree::DestroyNodeAndSubtree(AXNode* node, | 228 void AXTree::DestroyNodeAndSubtree(AXNode* node, |
| 223 AXTreeUpdateState* update_state) { | 229 AXTreeUpdateState* update_state) { |
| 230 if (delegate_) | |
| 231 delegate_->OnNodeWillBeDeleted(this, node); | |
| 224 id_map_.erase(node->id()); | 232 id_map_.erase(node->id()); |
| 225 for (int i = 0; i < node->child_count(); ++i) | 233 for (int i = 0; i < node->child_count(); ++i) |
| 226 DestroyNodeAndSubtree(node->ChildAtIndex(i), update_state); | 234 DestroyNodeAndSubtree(node->ChildAtIndex(i), update_state); |
| 227 if (delegate_) | |
| 228 delegate_->OnNodeWillBeDeleted(this, node); | |
| 229 if (update_state) { | 235 if (update_state) { |
| 230 update_state->pending_nodes.erase(node); | 236 update_state->pending_nodes.erase(node); |
| 231 } | 237 } |
| 232 node->Destroy(); | 238 node->Destroy(); |
| 233 } | 239 } |
| 234 | 240 |
| 235 bool AXTree::DeleteOldChildren(AXNode* node, | 241 bool AXTree::DeleteOldChildren(AXNode* node, |
| 236 const std::vector<int32>& new_child_ids, | 242 const std::vector<int32>& new_child_ids, |
| 237 AXTreeUpdateState* update_state) { | 243 AXTreeUpdateState* update_state) { |
| 238 // Create a set of child ids in |src| for fast lookup, and return false | 244 // 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); | 292 update_state->pending_nodes.insert(child); |
| 287 update_state->new_nodes.insert(child); | 293 update_state->new_nodes.insert(child); |
| 288 } | 294 } |
| 289 new_children->push_back(child); | 295 new_children->push_back(child); |
| 290 } | 296 } |
| 291 | 297 |
| 292 return success; | 298 return success; |
| 293 } | 299 } |
| 294 | 300 |
| 295 } // namespace ui | 301 } // namespace ui |
| OLD | NEW |