| 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_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_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" | 9 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
| 10 #include "ui/gfx/canvas.h" |
| 10 | 11 |
| 11 namespace mojo { | 12 namespace mojo { |
| 12 namespace view_manager { | 13 namespace view_manager { |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 class ScopedDestructionNotifier { | 16 class ScopedDestructionNotifier { |
| 16 public: | 17 public: |
| 17 explicit ScopedDestructionNotifier(View* view) | 18 explicit ScopedDestructionNotifier(View* view) |
| 18 : view_(view) { | 19 : view_(view) { |
| 19 FOR_EACH_OBSERVER( | 20 FOR_EACH_OBSERVER( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 55 |
| 55 void View::RemoveObserver(ViewObserver* observer) { | 56 void View::RemoveObserver(ViewObserver* observer) { |
| 56 observers_.RemoveObserver(observer); | 57 observers_.RemoveObserver(observer); |
| 57 } | 58 } |
| 58 | 59 |
| 59 void View::SetContents(const SkBitmap& contents) { | 60 void View::SetContents(const SkBitmap& contents) { |
| 60 if (manager_) | 61 if (manager_) |
| 61 ViewManagerPrivate(manager_).synchronizer()->SetViewContents(id_, contents); | 62 ViewManagerPrivate(manager_).synchronizer()->SetViewContents(id_, contents); |
| 62 } | 63 } |
| 63 | 64 |
| 65 void View::SetColor(SkColor color) { |
| 66 gfx::Canvas canvas(node_->bounds().size(), 1.0f, true); |
| 67 canvas.DrawColor(color); |
| 68 SetContents(skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(true)); |
| 69 } |
| 70 |
| 64 View::View(ViewManager* manager) | 71 View::View(ViewManager* manager) |
| 65 : id_(ViewManagerPrivate(manager).synchronizer()->CreateView()), | 72 : id_(ViewManagerPrivate(manager).synchronizer()->CreateView()), |
| 66 node_(NULL), | 73 node_(NULL), |
| 67 manager_(manager) {} | 74 manager_(manager) {} |
| 68 | 75 |
| 69 View::View() | 76 View::View() |
| 70 : id_(-1), | 77 : id_(-1), |
| 71 node_(NULL), | 78 node_(NULL), |
| 72 manager_(NULL) {} | 79 manager_(NULL) {} |
| 73 | 80 |
| 74 View::~View() { | 81 View::~View() { |
| 75 ScopedDestructionNotifier notifier(this); | 82 ScopedDestructionNotifier notifier(this); |
| 76 if (manager_) | 83 if (manager_) |
| 77 ViewManagerPrivate(manager_).RemoveView(id_); | 84 ViewManagerPrivate(manager_).RemoveView(id_); |
| 78 } | 85 } |
| 79 | 86 |
| 80 void View::LocalDestroy() { | 87 void View::LocalDestroy() { |
| 81 delete this; | 88 delete this; |
| 82 } | 89 } |
| 83 | 90 |
| 84 } // namespace view_manager | 91 } // namespace view_manager |
| 85 } // namespace mojo | 92 } // namespace mojo |
| OLD | NEW |