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 "athena/screen/background_controller.h" | 5 #include "athena/system/background_controller.h" |
6 | 6 |
7 #include "base/strings/stringprintf.h" | 7 #include "athena/system/public/system_ui.h" |
8 #include "base/strings/utf_string_conversions.h" | |
9 #include "extensions/shell/common/version.h" | |
10 #include "third_party/skia/include/core/SkColor.h" | |
11 #include "ui/aura/window.h" | 8 #include "ui/aura/window.h" |
12 #include "ui/compositor/layer.h" | 9 #include "ui/compositor/layer.h" |
13 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
14 #include "ui/gfx/image/image_skia.h" | 11 #include "ui/gfx/image/image_skia.h" |
15 #include "ui/views/controls/label.h" | |
16 #include "ui/views/view.h" | 12 #include "ui/views/view.h" |
17 #include "ui/views/widget/widget.h" | 13 #include "ui/views/widget/widget.h" |
18 | 14 |
19 namespace athena { | 15 namespace athena { |
20 | 16 |
21 namespace { | |
22 | |
23 const SkColor kVersionColor = SK_ColorWHITE; | |
24 const SkColor kVersionBackground = SK_ColorTRANSPARENT; | |
25 const SkColor kVersionShadow = 0xB0000000; | |
26 const int kVersionShadowBlur = 10; | |
27 | |
28 class VersionView : public views::Label { | |
29 public: | |
30 VersionView() { | |
31 SetEnabledColor(kVersionColor); | |
32 SetBackgroundColor(kVersionBackground); | |
33 SetShadows(gfx::ShadowValues(1, gfx::ShadowValue(gfx::Point(0, 1), | |
34 kVersionShadowBlur, | |
35 kVersionShadow))); | |
36 SetText(base::UTF8ToUTF16(base::StringPrintf("%s (Build %s)", | |
37 PRODUCT_VERSION, | |
38 LAST_CHANGE))); | |
39 SetBoundsRect(gfx::Rect(gfx::Point(), GetPreferredSize())); | |
40 } | |
41 virtual ~VersionView() { | |
42 } | |
43 | |
44 private: | |
45 DISALLOW_COPY_AND_ASSIGN(VersionView); | |
46 }; | |
47 | |
48 } // namespace | |
49 | |
50 class BackgroundView : public views::View { | 17 class BackgroundView : public views::View { |
51 public: | 18 public: |
52 BackgroundView() { | 19 BackgroundView() |
53 AddChildView(new VersionView); | 20 : time_view_(SystemUI::Get()->CreateTimeView()), |
oshima
2014/08/22 14:12:09
Since you're in the same module, you can just crea
pkotwicz
2014/08/22 14:18:06
SystemUI::CreateTimeView() and SystemUI::CreateSta
oshima
2014/08/22 16:33:55
So we're going to have the same UI on background a
| |
21 status_icon_view_(SystemUI::Get()->CreateStatusIconView()) { | |
22 AddChildView(time_view_); | |
23 AddChildView(status_icon_view_); | |
54 } | 24 } |
55 virtual ~BackgroundView() {} | 25 virtual ~BackgroundView() {} |
56 | 26 |
57 void SetImage(const gfx::ImageSkia& image) { | 27 void SetImage(const gfx::ImageSkia& image) { |
58 image_ = image; | 28 image_ = image; |
59 SchedulePaint(); | 29 SchedulePaint(); |
60 } | 30 } |
61 | 31 |
62 // views::View | 32 // views::View: |
33 virtual void Layout() OVERRIDE { | |
34 time_view_->SetBoundsRect(gfx::Rect(time_view_->GetPreferredSize())); | |
35 gfx::Size status_icon_preferred_size = | |
36 status_icon_view_->GetPreferredSize(); | |
37 status_icon_view_->SetBounds(width() - status_icon_preferred_size.width(), | |
38 0, | |
39 status_icon_preferred_size.width(), | |
40 status_icon_preferred_size.height()); | |
41 } | |
42 | |
43 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE { | |
44 // Relayout when |status_icon_view_| changes its preferred size. | |
45 Layout(); | |
46 } | |
47 | |
63 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | 48 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
64 canvas->DrawImageInt(image_, | 49 canvas->DrawImageInt(image_, |
65 0, | 50 0, |
66 0, | 51 0, |
67 image_.width(), | 52 image_.width(), |
68 image_.height(), | 53 image_.height(), |
69 0, | 54 0, |
70 0, | 55 0, |
71 width(), | 56 width(), |
72 height(), | 57 height(), |
73 true); | 58 true); |
74 } | 59 } |
75 | 60 |
76 private: | 61 private: |
77 gfx::ImageSkia image_; | 62 gfx::ImageSkia image_; |
63 views::View* time_view_; | |
64 views::View* status_icon_view_; | |
78 | 65 |
79 DISALLOW_COPY_AND_ASSIGN(BackgroundView); | 66 DISALLOW_COPY_AND_ASSIGN(BackgroundView); |
80 }; | 67 }; |
81 | 68 |
82 BackgroundController::BackgroundController(aura::Window* container) { | 69 BackgroundController::BackgroundController(aura::Window* background_container) { |
83 // TODO(oshima): Using widget to just draw an image is probably | |
84 // overkill. Just use WindowDelegate to draw the background and | |
85 // remove dependency to ui/views. | |
86 | |
87 views::Widget* background_widget = new views::Widget; | 70 views::Widget* background_widget = new views::Widget; |
88 views::Widget::InitParams params( | 71 views::Widget::InitParams params( |
89 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 72 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
90 params.accept_events = false; | 73 params.parent = background_container; |
91 params.parent = container; | |
92 background_widget->Init(params); | 74 background_widget->Init(params); |
93 background_widget->GetNativeWindow()->layer()->SetMasksToBounds(true); | 75 background_widget->GetNativeWindow()->layer()->SetMasksToBounds(true); |
94 background_view_ = new BackgroundView; | 76 background_view_ = new BackgroundView; |
95 background_widget->SetContentsView(background_view_); | 77 background_widget->SetContentsView(background_view_); |
96 background_widget->GetNativeView()->SetName("BackgroundWidget"); | 78 background_widget->GetNativeView()->SetName("BackgroundWidget"); |
97 background_widget->Show(); | 79 background_widget->Show(); |
98 } | 80 } |
99 | 81 |
100 BackgroundController::~BackgroundController() { | 82 BackgroundController::~BackgroundController() { |
101 // background_widget is owned by the container and will be deleted | 83 // background_widget is owned by the container and will be deleted |
102 // when the container is deleted. | 84 // when the container is deleted. |
103 } | 85 } |
104 | 86 |
105 void BackgroundController::SetImage(const gfx::ImageSkia& image) { | 87 void BackgroundController::SetImage(const gfx::ImageSkia& image) { |
106 // TODO(oshima): implement cross fede animation. | 88 // TODO(oshima): implement cross fede animation. |
107 background_view_->SetImage(image); | 89 background_view_->SetImage(image); |
108 } | 90 } |
109 | 91 |
110 } // namespace athena | 92 } // namespace athena |
OLD | NEW |