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