| 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" |
| 8 #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h" |
| 7 #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" |
| 8 #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" |
| 9 | 11 |
| 10 namespace mojo { | 12 namespace mojo { |
| 11 namespace services { | 13 namespace services { |
| 12 namespace view_manager { | 14 namespace view_manager { |
| 13 | 15 |
| 14 void NotifyViewTreeChangeAtReceiver( | 16 void NotifyViewTreeChangeAtReceiver( |
| 15 ViewTreeNode* receiver, | 17 ViewTreeNode* receiver, |
| 16 const ViewTreeNodeObserver::TreeChangeParams& params) { | 18 const ViewTreeNodeObserver::TreeChangeParams& params) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 std::find(children->begin(), children->end(), child); | 83 std::find(children->begin(), children->end(), child); |
| 82 if (it != children->end()) { | 84 if (it != children->end()) { |
| 83 children->erase(it); | 85 children->erase(it); |
| 84 ViewTreeNodePrivate(child).ClearParent(); | 86 ViewTreeNodePrivate(child).ClearParent(); |
| 85 } | 87 } |
| 86 } | 88 } |
| 87 | 89 |
| 88 //////////////////////////////////////////////////////////////////////////////// | 90 //////////////////////////////////////////////////////////////////////////////// |
| 89 // ViewTreeNode, public: | 91 // ViewTreeNode, public: |
| 90 | 92 |
| 91 ViewTreeNode::ViewTreeNode() : owned_by_parent_(true), parent_(NULL) {} | 93 ViewTreeNode::ViewTreeNode() |
| 94 : manager_(NULL), |
| 95 id_(-1), |
| 96 owned_by_parent_(true), |
| 97 parent_(NULL) {} |
| 98 |
| 99 ViewTreeNode::ViewTreeNode(ViewManager* manager) |
| 100 : manager_(manager), |
| 101 id_(ViewManagerPrivate(manager).synchronizer()->CreateViewTreeNode()), |
| 102 owned_by_parent_(true), |
| 103 parent_(NULL) {} |
| 92 | 104 |
| 93 ViewTreeNode::~ViewTreeNode() { | 105 ViewTreeNode::~ViewTreeNode() { |
| 94 while (!children_.empty()) { | 106 while (!children_.empty()) { |
| 95 ViewTreeNode* child = children_.front(); | 107 ViewTreeNode* child = children_.front(); |
| 96 if (child->owned_by_parent_) { | 108 if (child->owned_by_parent_) { |
| 97 delete child; | 109 delete child; |
| 98 // Deleting the child also removes it from our child list. | 110 // Deleting the child also removes it from our child list. |
| 99 DCHECK(std::find(children_.begin(), children_.end(), child) == | 111 DCHECK(std::find(children_.begin(), children_.end(), child) == |
| 100 children_.end()); | 112 children_.end()); |
| 101 } else { | 113 } else { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 115 void ViewTreeNode::RemoveObserver(ViewTreeNodeObserver* observer) { | 127 void ViewTreeNode::RemoveObserver(ViewTreeNodeObserver* observer) { |
| 116 observers_.RemoveObserver(observer); | 128 observers_.RemoveObserver(observer); |
| 117 } | 129 } |
| 118 | 130 |
| 119 void ViewTreeNode::AddChild(ViewTreeNode* child) { | 131 void ViewTreeNode::AddChild(ViewTreeNode* child) { |
| 120 ScopedTreeNotifier notifier(child, child->parent(), this); | 132 ScopedTreeNotifier notifier(child, child->parent(), this); |
| 121 if (child->parent()) | 133 if (child->parent()) |
| 122 RemoveChildImpl(child, &child->parent_->children_); | 134 RemoveChildImpl(child, &child->parent_->children_); |
| 123 children_.push_back(child); | 135 children_.push_back(child); |
| 124 child->parent_ = this; | 136 child->parent_ = this; |
| 137 ViewManagerPrivate(manager_).synchronizer()->AddChild(child->id(), id_); |
| 125 } | 138 } |
| 126 | 139 |
| 127 void ViewTreeNode::RemoveChild(ViewTreeNode* child) { | 140 void ViewTreeNode::RemoveChild(ViewTreeNode* child) { |
| 128 DCHECK_EQ(this, child->parent()); | 141 DCHECK_EQ(this, child->parent()); |
| 129 ScopedTreeNotifier(child, this, NULL); | 142 ScopedTreeNotifier(child, this, NULL); |
| 130 RemoveChildImpl(child, &children_); | 143 RemoveChildImpl(child, &children_); |
| 144 ViewManagerPrivate(manager_).synchronizer()->RemoveChild(child->id(), id_); |
| 131 } | 145 } |
| 132 | 146 |
| 133 bool ViewTreeNode::Contains(ViewTreeNode* child) const { | 147 bool ViewTreeNode::Contains(ViewTreeNode* child) const { |
| 134 for (ViewTreeNode* p = child->parent(); p; p = p->parent()) { | 148 for (ViewTreeNode* p = child->parent(); p; p = p->parent()) { |
| 135 if (p == this) | 149 if (p == this) |
| 136 return true; | 150 return true; |
| 137 } | 151 } |
| 138 return false; | 152 return false; |
| 139 } | 153 } |
| 140 | 154 |
| 141 } // namespace view_manager | 155 } // namespace view_manager |
| 142 } // namespace services | 156 } // namespace services |
| 143 } // namespace mojo | 157 } // namespace mojo |
| 144 | 158 |
| OLD | NEW |