| 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/node.h" | 5 #include "mojo/services/public/cpp/view_manager/node.h" |
| 6 | 6 |
| 7 #include "mojo/services/public/cpp/view_manager/lib/node_private.h" | 7 #include "mojo/services/public/cpp/view_manager/lib/node_private.h" |
| 8 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h" | 8 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.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/node_observer.h" | 10 #include "mojo/services/public/cpp/view_manager/node_observer.h" |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 } | 187 } |
| 188 | 188 |
| 189 private: | 189 private: |
| 190 Node* node_; | 190 Node* node_; |
| 191 const gfx::Rect old_bounds_; | 191 const gfx::Rect old_bounds_; |
| 192 const gfx::Rect new_bounds_; | 192 const gfx::Rect new_bounds_; |
| 193 | 193 |
| 194 DISALLOW_COPY_AND_ASSIGN(ScopedSetBoundsNotifier); | 194 DISALLOW_COPY_AND_ASSIGN(ScopedSetBoundsNotifier); |
| 195 }; | 195 }; |
| 196 | 196 |
| 197 class ScopedDestructionNotifier { | |
| 198 public: | |
| 199 explicit ScopedDestructionNotifier(Node* node) | |
| 200 : node_(node) { | |
| 201 FOR_EACH_OBSERVER(NodeObserver, | |
| 202 *NodePrivate(node_).observers(), | |
| 203 OnNodeDestroying(node_)); | |
| 204 } | |
| 205 ~ScopedDestructionNotifier() { | |
| 206 FOR_EACH_OBSERVER(NodeObserver, | |
| 207 *NodePrivate(node_).observers(), | |
| 208 OnNodeDestroyed(node_)); | |
| 209 } | |
| 210 | |
| 211 private: | |
| 212 Node* node_; | |
| 213 | |
| 214 DISALLOW_COPY_AND_ASSIGN(ScopedDestructionNotifier); | |
| 215 }; | |
| 216 | |
| 217 // Some operations are only permitted in the connection that created the node. | 197 // Some operations are only permitted in the connection that created the node. |
| 218 bool OwnsNode(ViewManager* manager, Node* node) { | 198 bool OwnsNode(ViewManager* manager, Node* node) { |
| 219 return !manager || | 199 return !manager || |
| 220 static_cast<ViewManagerClientImpl*>(manager)->OwnsNode(node->id()); | 200 static_cast<ViewManagerClientImpl*>(manager)->OwnsNode(node->id()); |
| 221 } | 201 } |
| 222 | 202 |
| 223 } // namespace | 203 } // namespace |
| 224 | 204 |
| 225 //////////////////////////////////////////////////////////////////////////////// | 205 //////////////////////////////////////////////////////////////////////////////// |
| 226 // Node, public: | 206 // Node, public: |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 //////////////////////////////////////////////////////////////////////////////// | 332 //////////////////////////////////////////////////////////////////////////////// |
| 353 // Node, protected: | 333 // Node, protected: |
| 354 | 334 |
| 355 Node::Node() | 335 Node::Node() |
| 356 : manager_(NULL), | 336 : manager_(NULL), |
| 357 id_(static_cast<Id>(-1)), | 337 id_(static_cast<Id>(-1)), |
| 358 parent_(NULL), | 338 parent_(NULL), |
| 359 active_view_(NULL) {} | 339 active_view_(NULL) {} |
| 360 | 340 |
| 361 Node::~Node() { | 341 Node::~Node() { |
| 362 ScopedDestructionNotifier notifier(this); | 342 FOR_EACH_OBSERVER(NodeObserver, observers_, OnNodeDestroying(this)); |
| 363 if (parent_) | 343 if (parent_) |
| 364 parent_->LocalRemoveChild(this); | 344 parent_->LocalRemoveChild(this); |
| 365 // TODO(beng): It'd be better to do this via a destruction observer in the | 345 // TODO(beng): It'd be better to do this via a destruction observer in the |
| 366 // ViewManagerClientImpl. | 346 // ViewManagerClientImpl. |
| 367 if (manager_) | 347 if (manager_) |
| 368 static_cast<ViewManagerClientImpl*>(manager_)->RemoveNode(id_); | 348 static_cast<ViewManagerClientImpl*>(manager_)->RemoveNode(id_); |
| 349 FOR_EACH_OBSERVER(NodeObserver, observers_, OnNodeDestroyed(this)); |
| 369 } | 350 } |
| 370 | 351 |
| 371 //////////////////////////////////////////////////////////////////////////////// | 352 //////////////////////////////////////////////////////////////////////////////// |
| 372 // Node, private: | 353 // Node, private: |
| 373 | 354 |
| 374 Node::Node(ViewManager* manager) | 355 Node::Node(ViewManager* manager) |
| 375 : manager_(manager), | 356 : manager_(manager), |
| 376 id_(static_cast<ViewManagerClientImpl*>(manager_)->CreateNode()), | 357 id_(static_cast<ViewManagerClientImpl*>(manager_)->CreateNode()), |
| 377 parent_(NULL), | 358 parent_(NULL), |
| 378 active_view_(NULL) {} | 359 active_view_(NULL) {} |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 | 391 |
| 411 void Node::LocalSetBounds(const gfx::Rect& old_bounds, | 392 void Node::LocalSetBounds(const gfx::Rect& old_bounds, |
| 412 const gfx::Rect& new_bounds) { | 393 const gfx::Rect& new_bounds) { |
| 413 DCHECK(old_bounds == bounds_); | 394 DCHECK(old_bounds == bounds_); |
| 414 ScopedSetBoundsNotifier notifier(this, old_bounds, new_bounds); | 395 ScopedSetBoundsNotifier notifier(this, old_bounds, new_bounds); |
| 415 bounds_ = new_bounds; | 396 bounds_ = new_bounds; |
| 416 } | 397 } |
| 417 | 398 |
| 418 } // namespace view_manager | 399 } // namespace view_manager |
| 419 } // namespace mojo | 400 } // namespace mojo |
| OLD | NEW |