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/screen/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 explicit BackgroundView(aura::Window* popup_container) |
53 AddChildView(new VersionView); | 20 : time_view_(SystemUI::Get()->CreateTimeView()), |
| 21 status_icon_view_(SystemUI::Get()->CreateStatusIconView( |
| 22 popup_container)) { |
| 23 AddChildView(time_view_); |
| 24 AddChildView(status_icon_view_); |
54 } | 25 } |
55 virtual ~BackgroundView() {} | 26 virtual ~BackgroundView() {} |
56 | 27 |
57 void SetImage(const gfx::ImageSkia& image) { | 28 void SetImage(const gfx::ImageSkia& image) { |
58 image_ = image; | 29 image_ = image; |
59 SchedulePaint(); | 30 SchedulePaint(); |
60 } | 31 } |
61 | 32 |
62 // views::View | 33 // views::View: |
| 34 virtual void Layout() OVERRIDE { |
| 35 time_view_->SetBoundsRect(gfx::Rect(time_view_->GetPreferredSize())); |
| 36 gfx::Size status_icon_preferred_size = |
| 37 status_icon_view_->GetPreferredSize(); |
| 38 status_icon_view_->SetBounds(width() - status_icon_preferred_size.width(), |
| 39 0, |
| 40 status_icon_preferred_size.width(), |
| 41 status_icon_preferred_size.height()); |
| 42 } |
| 43 |
| 44 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE { |
| 45 // Relayout when |status_icon_view_| changes its preferred size. |
| 46 Layout(); |
| 47 } |
| 48 |
63 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | 49 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
64 canvas->DrawImageInt(image_, | 50 canvas->DrawImageInt(image_, |
65 0, | 51 0, |
66 0, | 52 0, |
67 image_.width(), | 53 image_.width(), |
68 image_.height(), | 54 image_.height(), |
69 0, | 55 0, |
70 0, | 56 0, |
71 width(), | 57 width(), |
72 height(), | 58 height(), |
73 true); | 59 true); |
74 } | 60 } |
75 | 61 |
76 private: | 62 private: |
77 gfx::ImageSkia image_; | 63 gfx::ImageSkia image_; |
| 64 views::View* time_view_; |
| 65 views::View* status_icon_view_; |
78 | 66 |
79 DISALLOW_COPY_AND_ASSIGN(BackgroundView); | 67 DISALLOW_COPY_AND_ASSIGN(BackgroundView); |
80 }; | 68 }; |
81 | 69 |
82 BackgroundController::BackgroundController(aura::Window* container) { | 70 BackgroundController::BackgroundController(aura::Window* background_container, |
83 // TODO(oshima): Using widget to just draw an image is probably | 71 aura::Window* popup_container) { |
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; | 72 views::Widget* background_widget = new views::Widget; |
88 views::Widget::InitParams params( | 73 views::Widget::InitParams params( |
89 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 74 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
90 params.accept_events = false; | 75 params.parent = background_container; |
91 params.parent = container; | |
92 background_widget->Init(params); | 76 background_widget->Init(params); |
93 background_widget->GetNativeWindow()->layer()->SetMasksToBounds(true); | 77 background_widget->GetNativeWindow()->layer()->SetMasksToBounds(true); |
94 background_view_ = new BackgroundView; | 78 background_view_ = new BackgroundView(popup_container); |
95 background_widget->SetContentsView(background_view_); | 79 background_widget->SetContentsView(background_view_); |
96 background_widget->GetNativeView()->SetName("BackgroundWidget"); | 80 background_widget->GetNativeView()->SetName("BackgroundWidget"); |
97 background_widget->Show(); | 81 background_widget->Show(); |
98 } | 82 } |
99 | 83 |
100 BackgroundController::~BackgroundController() { | 84 BackgroundController::~BackgroundController() { |
101 // background_widget is owned by the container and will be deleted | 85 // background_widget is owned by the container and will be deleted |
102 // when the container is deleted. | 86 // when the container is deleted. |
103 } | 87 } |
104 | 88 |
105 void BackgroundController::SetImage(const gfx::ImageSkia& image) { | 89 void BackgroundController::SetImage(const gfx::ImageSkia& image) { |
106 // TODO(oshima): implement cross fede animation. | 90 // TODO(oshima): implement cross fede animation. |
107 background_view_->SetImage(image); | 91 background_view_->SetImage(image); |
108 } | 92 } |
109 | 93 |
110 } // namespace athena | 94 } // namespace athena |
OLD | NEW |