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_private.h" | 9 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" |
10 #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h" | 10 #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 } | 117 } |
118 | 118 |
119 private: | 119 private: |
120 ViewTreeNode* node_; | 120 ViewTreeNode* node_; |
121 View* old_view_; | 121 View* old_view_; |
122 View* new_view_; | 122 View* new_view_; |
123 | 123 |
124 DISALLOW_COPY_AND_ASSIGN(ScopedSetActiveViewNotifier); | 124 DISALLOW_COPY_AND_ASSIGN(ScopedSetActiveViewNotifier); |
125 }; | 125 }; |
126 | 126 |
| 127 class ScopedSetBoundsNotifier { |
| 128 public: |
| 129 ScopedSetBoundsNotifier(ViewTreeNode* node, |
| 130 const gfx::Rect& old_bounds, |
| 131 const gfx::Rect& new_bounds) |
| 132 : node_(node), |
| 133 old_bounds_(old_bounds), |
| 134 new_bounds_(new_bounds) { |
| 135 FOR_EACH_OBSERVER( |
| 136 ViewTreeNodeObserver, |
| 137 *ViewTreeNodePrivate(node_).observers(), |
| 138 OnNodeBoundsChange(node_, |
| 139 old_bounds_, |
| 140 new_bounds_, |
| 141 ViewTreeNodeObserver::DISPOSITION_CHANGING)); |
| 142 } |
| 143 ~ScopedSetBoundsNotifier() { |
| 144 FOR_EACH_OBSERVER( |
| 145 ViewTreeNodeObserver, |
| 146 *ViewTreeNodePrivate(node_).observers(), |
| 147 OnNodeBoundsChange(node_, |
| 148 old_bounds_, |
| 149 new_bounds_, |
| 150 ViewTreeNodeObserver::DISPOSITION_CHANGED)); |
| 151 } |
| 152 |
| 153 private: |
| 154 ViewTreeNode* node_; |
| 155 const gfx::Rect old_bounds_; |
| 156 const gfx::Rect new_bounds_; |
| 157 |
| 158 DISALLOW_COPY_AND_ASSIGN(ScopedSetBoundsNotifier); |
| 159 }; |
| 160 |
127 class ScopedDestructionNotifier { | 161 class ScopedDestructionNotifier { |
128 public: | 162 public: |
129 explicit ScopedDestructionNotifier(ViewTreeNode* node) | 163 explicit ScopedDestructionNotifier(ViewTreeNode* node) |
130 : node_(node) { | 164 : node_(node) { |
131 FOR_EACH_OBSERVER( | 165 FOR_EACH_OBSERVER( |
132 ViewTreeNodeObserver, | 166 ViewTreeNodeObserver, |
133 *ViewTreeNodePrivate(node_).observers(), | 167 *ViewTreeNodePrivate(node_).observers(), |
134 OnNodeDestroy(node_, ViewTreeNodeObserver::DISPOSITION_CHANGING)); | 168 OnNodeDestroy(node_, ViewTreeNodeObserver::DISPOSITION_CHANGING)); |
135 } | 169 } |
136 ~ScopedDestructionNotifier() { | 170 ~ScopedDestructionNotifier() { |
(...skipping 15 matching lines...) Expand all Loading... |
152 // ViewTreeNode, public: | 186 // ViewTreeNode, public: |
153 | 187 |
154 // static | 188 // static |
155 ViewTreeNode* ViewTreeNode::Create(ViewManager* view_manager) { | 189 ViewTreeNode* ViewTreeNode::Create(ViewManager* view_manager) { |
156 ViewTreeNode* node = new ViewTreeNode(view_manager); | 190 ViewTreeNode* node = new ViewTreeNode(view_manager); |
157 ViewManagerPrivate(view_manager).AddNode(node->id(), node); | 191 ViewManagerPrivate(view_manager).AddNode(node->id(), node); |
158 return node; | 192 return node; |
159 } | 193 } |
160 | 194 |
161 void ViewTreeNode::Destroy() { | 195 void ViewTreeNode::Destroy() { |
| 196 // TODO(beng): only proceed if |manager_| OwnsNode(this). |
162 if (manager_) | 197 if (manager_) |
163 ViewManagerPrivate(manager_).synchronizer()->DestroyViewTreeNode(id_); | 198 ViewManagerPrivate(manager_).synchronizer()->DestroyViewTreeNode(id_); |
164 while (!children_.empty()) | 199 while (!children_.empty()) |
165 children_.front()->Destroy(); | 200 children_.front()->Destroy(); |
166 LocalDestroy(); | 201 LocalDestroy(); |
167 } | 202 } |
168 | 203 |
| 204 void ViewTreeNode::SetBounds(const gfx::Rect& bounds) { |
| 205 // TODO(beng): only proceed if |manager_| OwnsNode(this). |
| 206 if (manager_) |
| 207 ViewManagerPrivate(manager_).synchronizer()->SetBounds(id_, bounds); |
| 208 LocalSetBounds(bounds_, bounds); |
| 209 } |
| 210 |
169 void ViewTreeNode::AddObserver(ViewTreeNodeObserver* observer) { | 211 void ViewTreeNode::AddObserver(ViewTreeNodeObserver* observer) { |
170 observers_.AddObserver(observer); | 212 observers_.AddObserver(observer); |
171 } | 213 } |
172 | 214 |
173 void ViewTreeNode::RemoveObserver(ViewTreeNodeObserver* observer) { | 215 void ViewTreeNode::RemoveObserver(ViewTreeNodeObserver* observer) { |
174 observers_.RemoveObserver(observer); | 216 observers_.RemoveObserver(observer); |
175 } | 217 } |
176 | 218 |
177 void ViewTreeNode::AddChild(ViewTreeNode* child) { | 219 void ViewTreeNode::AddChild(ViewTreeNode* child) { |
178 if (manager_) | 220 if (manager_) |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 | 311 |
270 void ViewTreeNode::LocalSetActiveView(View* view) { | 312 void ViewTreeNode::LocalSetActiveView(View* view) { |
271 ScopedSetActiveViewNotifier notifier(this, active_view_, view); | 313 ScopedSetActiveViewNotifier notifier(this, active_view_, view); |
272 if (active_view_) | 314 if (active_view_) |
273 ViewPrivate(active_view_).set_node(NULL); | 315 ViewPrivate(active_view_).set_node(NULL); |
274 active_view_ = view; | 316 active_view_ = view; |
275 if (active_view_) | 317 if (active_view_) |
276 ViewPrivate(active_view_).set_node(this); | 318 ViewPrivate(active_view_).set_node(this); |
277 } | 319 } |
278 | 320 |
| 321 void ViewTreeNode::LocalSetBounds(const gfx::Rect& old_bounds, |
| 322 const gfx::Rect& new_bounds) { |
| 323 DCHECK(old_bounds == bounds_); |
| 324 ScopedSetBoundsNotifier notifier(this, old_bounds, new_bounds); |
| 325 bounds_ = new_bounds; |
| 326 } |
| 327 |
279 } // namespace view_manager | 328 } // namespace view_manager |
280 } // namespace mojo | 329 } // namespace mojo |
281 | 330 |
OLD | NEW |