| 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_synchronizer.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/view_observer.h" | 10 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
| 10 #include "mojo/services/public/cpp/view_manager/view_tree_node.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 { | 16 namespace { |
| 17 class ScopedDestructionNotifier { | 17 class ScopedDestructionNotifier { |
| 18 public: | 18 public: |
| 19 explicit ScopedDestructionNotifier(View* view) | 19 explicit ScopedDestructionNotifier(View* view) |
| 20 : view_(view) { | 20 : view_(view) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 33 private: | 33 private: |
| 34 View* view_; | 34 View* view_; |
| 35 | 35 |
| 36 DISALLOW_COPY_AND_ASSIGN(ScopedDestructionNotifier); | 36 DISALLOW_COPY_AND_ASSIGN(ScopedDestructionNotifier); |
| 37 }; | 37 }; |
| 38 } // namespace | 38 } // namespace |
| 39 | 39 |
| 40 // static | 40 // static |
| 41 View* View::Create(ViewManager* manager) { | 41 View* View::Create(ViewManager* manager) { |
| 42 View* view = new View(manager); | 42 View* view = new View(manager); |
| 43 static_cast<ViewManagerSynchronizer*>(manager)->AddView(view); | 43 static_cast<ViewManagerClientImpl*>(manager)->AddView(view); |
| 44 return view; | 44 return view; |
| 45 } | 45 } |
| 46 | 46 |
| 47 void View::Destroy() { | 47 void View::Destroy() { |
| 48 if (manager_) | 48 if (manager_) |
| 49 static_cast<ViewManagerSynchronizer*>(manager_)->DestroyView(id_); | 49 static_cast<ViewManagerClientImpl*>(manager_)->DestroyView(id_); |
| 50 LocalDestroy(); | 50 LocalDestroy(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void View::AddObserver(ViewObserver* observer) { | 53 void View::AddObserver(ViewObserver* observer) { |
| 54 observers_.AddObserver(observer); | 54 observers_.AddObserver(observer); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void View::RemoveObserver(ViewObserver* observer) { | 57 void View::RemoveObserver(ViewObserver* observer) { |
| 58 observers_.RemoveObserver(observer); | 58 observers_.RemoveObserver(observer); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void View::SetContents(const SkBitmap& contents) { | 61 void View::SetContents(const SkBitmap& contents) { |
| 62 if (manager_) { | 62 if (manager_) { |
| 63 static_cast<ViewManagerSynchronizer*>(manager_)->SetViewContents(id_, | 63 static_cast<ViewManagerClientImpl*>(manager_)->SetViewContents(id_, |
| 64 contents); | 64 contents); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 void View::SetColor(SkColor color) { | 68 void View::SetColor(SkColor color) { |
| 69 gfx::Canvas canvas(node_->bounds().size(), 1.0f, true); | 69 gfx::Canvas canvas(node_->bounds().size(), 1.0f, true); |
| 70 canvas.DrawColor(color); | 70 canvas.DrawColor(color); |
| 71 SetContents(skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(true)); | 71 SetContents(skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(true)); |
| 72 } | 72 } |
| 73 | 73 |
| 74 View::View(ViewManager* manager) | 74 View::View(ViewManager* manager) |
| 75 : id_(static_cast<ViewManagerSynchronizer*>(manager)->CreateView()), | 75 : id_(static_cast<ViewManagerClientImpl*>(manager)->CreateView()), |
| 76 node_(NULL), | 76 node_(NULL), |
| 77 manager_(manager) {} | 77 manager_(manager) {} |
| 78 | 78 |
| 79 View::View() | 79 View::View() |
| 80 : id_(-1), | 80 : id_(-1), |
| 81 node_(NULL), | 81 node_(NULL), |
| 82 manager_(NULL) {} | 82 manager_(NULL) {} |
| 83 | 83 |
| 84 View::~View() { | 84 View::~View() { |
| 85 ScopedDestructionNotifier notifier(this); | 85 ScopedDestructionNotifier notifier(this); |
| 86 // TODO(beng): It'd be better to do this via a destruction observer in the | 86 // TODO(beng): It'd be better to do this via a destruction observer in the |
| 87 // synchronizer. | 87 // ViewManagerClientImpl. |
| 88 if (manager_) | 88 if (manager_) |
| 89 static_cast<ViewManagerSynchronizer*>(manager_)->RemoveView(id_); | 89 static_cast<ViewManagerClientImpl*>(manager_)->RemoveView(id_); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void View::LocalDestroy() { | 92 void View::LocalDestroy() { |
| 93 delete this; | 93 delete this; |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // namespace view_manager | 96 } // namespace view_manager |
| 97 } // namespace mojo | 97 } // namespace mojo |
| OLD | NEW |