| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "mojo/services/public/cpp/view_manager/view.h" | |
| 6 | |
| 7 #include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h" | |
| 8 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" | |
| 9 #include "mojo/services/public/cpp/view_manager/view_observer.h" | |
| 10 | |
| 11 namespace mojo { | |
| 12 namespace services { | |
| 13 namespace view_manager { | |
| 14 | |
| 15 namespace { | |
| 16 class ScopedDestructionNotifier { | |
| 17 public: | |
| 18 explicit ScopedDestructionNotifier(View* view) | |
| 19 : view_(view) { | |
| 20 FOR_EACH_OBSERVER( | |
| 21 ViewObserver, | |
| 22 *ViewPrivate(view_).observers(), | |
| 23 OnViewDestroy(view_, ViewObserver::DISPOSITION_CHANGING)); | |
| 24 } | |
| 25 ~ScopedDestructionNotifier() { | |
| 26 FOR_EACH_OBSERVER( | |
| 27 ViewObserver, | |
| 28 *ViewPrivate(view_).observers(), | |
| 29 OnViewDestroy(view_, ViewObserver::DISPOSITION_CHANGED)); | |
| 30 } | |
| 31 | |
| 32 private: | |
| 33 View* view_; | |
| 34 | |
| 35 DISALLOW_COPY_AND_ASSIGN(ScopedDestructionNotifier); | |
| 36 }; | |
| 37 } // namespace | |
| 38 | |
| 39 // static | |
| 40 View* View::Create(ViewManager* manager) { | |
| 41 View* view = new View(manager); | |
| 42 ViewManagerPrivate(manager).AddView(view->id(), view); | |
| 43 return view; | |
| 44 } | |
| 45 | |
| 46 void View::Destroy() { | |
| 47 if (manager_) | |
| 48 ViewManagerPrivate(manager_).synchronizer()->DestroyView(id_); | |
| 49 LocalDestroy(); | |
| 50 } | |
| 51 | |
| 52 void View::AddObserver(ViewObserver* observer) { | |
| 53 observers_.AddObserver(observer); | |
| 54 } | |
| 55 | |
| 56 void View::RemoveObserver(ViewObserver* observer) { | |
| 57 observers_.RemoveObserver(observer); | |
| 58 } | |
| 59 | |
| 60 View::View(ViewManager* manager) | |
| 61 : id_(ViewManagerPrivate(manager).synchronizer()->CreateView()), | |
| 62 node_(NULL), | |
| 63 manager_(manager) {} | |
| 64 | |
| 65 View::View() | |
| 66 : id_(-1), | |
| 67 node_(NULL), | |
| 68 manager_(NULL) {} | |
| 69 | |
| 70 View::~View() { | |
| 71 ScopedDestructionNotifier notifier(this); | |
| 72 if (manager_) | |
| 73 ViewManagerPrivate(manager_).RemoveView(id_); | |
| 74 } | |
| 75 | |
| 76 void View::LocalDestroy() { | |
| 77 delete this; | |
| 78 } | |
| 79 | |
| 80 } // namespace view_manager | |
| 81 } // namespace services | |
| 82 } // namespace mojo | |
| OLD | NEW |