| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/services/public/cpp/view_manager/view_tree_node.h" | 5 #include "mojo/services/public/cpp/view_manager/view_tree_node.h" |
| 6 | 6 |
| 7 #include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h" | 7 #include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h" |
| 8 #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h" | 8 #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h" |
| 9 #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h" | 9 #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h" |
| 10 #include "mojo/services/public/cpp/view_manager/view_tree_node_observer.h" | 10 #include "mojo/services/public/cpp/view_manager/view_tree_node_observer.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 DCHECK(std::find(children_.begin(), children_.end(), child) == | 111 DCHECK(std::find(children_.begin(), children_.end(), child) == |
| 112 children_.end()); | 112 children_.end()); |
| 113 } else { | 113 } else { |
| 114 RemoveChild(child); | 114 RemoveChild(child); |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 | 117 |
| 118 if (parent_) | 118 if (parent_) |
| 119 parent_->RemoveChild(this); | 119 parent_->RemoveChild(this); |
| 120 | 120 |
| 121 if (manager_) |
| 122 ViewManagerPrivate(manager_).synchronizer()->DestroyViewTreeNode(id_); |
| 121 } | 123 } |
| 122 | 124 |
| 123 void ViewTreeNode::AddObserver(ViewTreeNodeObserver* observer) { | 125 void ViewTreeNode::AddObserver(ViewTreeNodeObserver* observer) { |
| 124 observers_.AddObserver(observer); | 126 observers_.AddObserver(observer); |
| 125 } | 127 } |
| 126 | 128 |
| 127 void ViewTreeNode::RemoveObserver(ViewTreeNodeObserver* observer) { | 129 void ViewTreeNode::RemoveObserver(ViewTreeNodeObserver* observer) { |
| 128 observers_.RemoveObserver(observer); | 130 observers_.RemoveObserver(observer); |
| 129 } | 131 } |
| 130 | 132 |
| 131 void ViewTreeNode::AddChild(ViewTreeNode* child) { | 133 void ViewTreeNode::AddChild(ViewTreeNode* child) { |
| 132 ScopedTreeNotifier notifier(child, child->parent(), this); | 134 LocalAddChild(child); |
| 133 if (child->parent()) | 135 if (manager_) |
| 134 RemoveChildImpl(child, &child->parent_->children_); | 136 ViewManagerPrivate(manager_).synchronizer()->AddChild(child->id(), id_); |
| 135 children_.push_back(child); | |
| 136 child->parent_ = this; | |
| 137 ViewManagerPrivate(manager_).synchronizer()->AddChild(child->id(), id_); | |
| 138 } | 137 } |
| 139 | 138 |
| 140 void ViewTreeNode::RemoveChild(ViewTreeNode* child) { | 139 void ViewTreeNode::RemoveChild(ViewTreeNode* child) { |
| 141 DCHECK_EQ(this, child->parent()); | 140 LocalRemoveChild(child); |
| 142 ScopedTreeNotifier(child, this, NULL); | 141 if (manager_) |
| 143 RemoveChildImpl(child, &children_); | 142 ViewManagerPrivate(manager_).synchronizer()->RemoveChild(child->id(), id_); |
| 144 ViewManagerPrivate(manager_).synchronizer()->RemoveChild(child->id(), id_); | |
| 145 } | 143 } |
| 146 | 144 |
| 147 bool ViewTreeNode::Contains(ViewTreeNode* child) const { | 145 bool ViewTreeNode::Contains(ViewTreeNode* child) const { |
| 148 for (ViewTreeNode* p = child->parent(); p; p = p->parent()) { | 146 for (ViewTreeNode* p = child->parent(); p; p = p->parent()) { |
| 149 if (p == this) | 147 if (p == this) |
| 150 return true; | 148 return true; |
| 151 } | 149 } |
| 152 return false; | 150 return false; |
| 153 } | 151 } |
| 154 | 152 |
| 153 //////////////////////////////////////////////////////////////////////////////// |
| 154 // ViewTreeNode, private: |
| 155 |
| 156 void ViewTreeNode::LocalAddChild(ViewTreeNode* child) { |
| 157 ScopedTreeNotifier notifier(child, child->parent(), this); |
| 158 if (child->parent()) |
| 159 RemoveChildImpl(child, &child->parent_->children_); |
| 160 children_.push_back(child); |
| 161 child->parent_ = this; |
| 162 } |
| 163 |
| 164 void ViewTreeNode::LocalRemoveChild(ViewTreeNode* child) { |
| 165 DCHECK_EQ(this, child->parent()); |
| 166 ScopedTreeNotifier(child, this, NULL); |
| 167 RemoveChildImpl(child, &children_); |
| 168 } |
| 169 |
| 155 } // namespace view_manager | 170 } // namespace view_manager |
| 156 } // namespace services | 171 } // namespace services |
| 157 } // namespace mojo | 172 } // namespace mojo |
| 158 | 173 |
| OLD | NEW |