| 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.h" | 5 #include "mojo/services/public/cpp/view_manager/view.h" |
| 6 | 6 |
| 7 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h" | 7 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h" |
| 8 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" | 8 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" |
| 9 #include "mojo/services/public/cpp/view_manager/node.h" | 9 #include "mojo/services/public/cpp/view_manager/node.h" |
| 10 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 10 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
| 11 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
| 12 | 12 |
| 13 namespace mojo { | 13 namespace mojo { |
| 14 namespace view_manager { | 14 namespace view_manager { |
| 15 | 15 |
| 16 namespace { | |
| 17 class ScopedDestructionNotifier { | |
| 18 public: | |
| 19 explicit ScopedDestructionNotifier(View* view) | |
| 20 : view_(view) { | |
| 21 FOR_EACH_OBSERVER(ViewObserver, | |
| 22 *ViewPrivate(view_).observers(), | |
| 23 OnViewDestroying(view_)); | |
| 24 } | |
| 25 ~ScopedDestructionNotifier() { | |
| 26 FOR_EACH_OBSERVER(ViewObserver, | |
| 27 *ViewPrivate(view_).observers(), | |
| 28 OnViewDestroyed(view_)); | |
| 29 } | |
| 30 | |
| 31 private: | |
| 32 View* view_; | |
| 33 | |
| 34 DISALLOW_COPY_AND_ASSIGN(ScopedDestructionNotifier); | |
| 35 }; | |
| 36 } // namespace | |
| 37 | |
| 38 // static | 16 // static |
| 39 View* View::Create(ViewManager* manager) { | 17 View* View::Create(ViewManager* manager) { |
| 40 View* view = new View(manager); | 18 View* view = new View(manager); |
| 41 static_cast<ViewManagerClientImpl*>(manager)->AddView(view); | 19 static_cast<ViewManagerClientImpl*>(manager)->AddView(view); |
| 42 return view; | 20 return view; |
| 43 } | 21 } |
| 44 | 22 |
| 45 void View::Destroy() { | 23 void View::Destroy() { |
| 46 if (manager_) | 24 if (manager_) |
| 47 static_cast<ViewManagerClientImpl*>(manager_)->DestroyView(id_); | 25 static_cast<ViewManagerClientImpl*>(manager_)->DestroyView(id_); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 73 : id_(static_cast<ViewManagerClientImpl*>(manager)->CreateView()), | 51 : id_(static_cast<ViewManagerClientImpl*>(manager)->CreateView()), |
| 74 node_(NULL), | 52 node_(NULL), |
| 75 manager_(manager) {} | 53 manager_(manager) {} |
| 76 | 54 |
| 77 View::View() | 55 View::View() |
| 78 : id_(static_cast<Id>(-1)), | 56 : id_(static_cast<Id>(-1)), |
| 79 node_(NULL), | 57 node_(NULL), |
| 80 manager_(NULL) {} | 58 manager_(NULL) {} |
| 81 | 59 |
| 82 View::~View() { | 60 View::~View() { |
| 83 ScopedDestructionNotifier notifier(this); | 61 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDestroying(this)); |
| 84 // TODO(beng): It'd be better to do this via a destruction observer in the | 62 // TODO(beng): It'd be better to do this via a destruction observer in the |
| 85 // ViewManagerClientImpl. | 63 // ViewManagerClientImpl. |
| 86 if (manager_) | 64 if (manager_) |
| 87 static_cast<ViewManagerClientImpl*>(manager_)->RemoveView(id_); | 65 static_cast<ViewManagerClientImpl*>(manager_)->RemoveView(id_); |
| 66 |
| 67 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDestroyed(this)); |
| 88 } | 68 } |
| 89 | 69 |
| 90 void View::LocalDestroy() { | 70 void View::LocalDestroy() { |
| 91 delete this; | 71 delete this; |
| 92 } | 72 } |
| 93 | 73 |
| 94 } // namespace view_manager | 74 } // namespace view_manager |
| 95 } // namespace mojo | 75 } // namespace mojo |
| OLD | NEW |