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/system/background_controller.h" | 5 #include "athena/system/background_controller.h" |
6 | 6 |
7 #include "athena/system/public/system_ui.h" | 7 #include "athena/system/public/system_ui.h" |
8 #include "ui/aura/window.h" | 8 #include "ui/aura/window.h" |
9 #include "ui/compositor/layer.h" | 9 #include "ui/compositor/layer.h" |
10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
11 #include "ui/gfx/image/image_skia.h" | 11 #include "ui/gfx/image/image_skia.h" |
12 #include "ui/views/view.h" | 12 #include "ui/views/view.h" |
13 #include "ui/views/widget/widget.h" | 13 #include "ui/views/widget/widget.h" |
14 | 14 |
15 namespace athena { | 15 namespace athena { |
16 | 16 |
17 class BackgroundView : public views::View { | 17 class BackgroundView : public views::View { |
18 public: | 18 public: |
19 BackgroundView() | 19 BackgroundView() : system_info_view_(NULL) { |
20 : time_view_(SystemUI::Get()->CreateTimeView()), | 20 system_info_view_ = |
21 status_icon_view_(SystemUI::Get()->CreateStatusIconView()) { | 21 SystemUI::Get()->CreateSystemInfoView(SystemUI::COLOR_SCHEME_LIGHT); |
22 AddChildView(time_view_); | 22 AddChildView(system_info_view_); |
23 AddChildView(status_icon_view_); | |
24 } | 23 } |
25 virtual ~BackgroundView() {} | 24 virtual ~BackgroundView() {} |
26 | 25 |
27 void SetImage(const gfx::ImageSkia& image) { | 26 void SetImage(const gfx::ImageSkia& image) { |
28 image_ = image; | 27 image_ = image; |
29 SchedulePaint(); | 28 SchedulePaint(); |
30 } | 29 } |
31 | 30 |
32 // views::View: | 31 // views::View: |
33 virtual void Layout() OVERRIDE { | 32 virtual void Layout() OVERRIDE { |
34 time_view_->SetBoundsRect(gfx::Rect(time_view_->GetPreferredSize())); | 33 system_info_view_->SetBounds( |
35 gfx::Size status_icon_preferred_size = | 34 0, 0, width(), system_info_view_->GetPreferredSize().height()); |
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 } | 35 } |
47 | 36 |
48 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | 37 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
49 canvas->DrawImageInt(image_, | 38 canvas->DrawImageInt(image_, |
50 0, | 39 0, |
51 0, | 40 0, |
52 image_.width(), | 41 image_.width(), |
53 image_.height(), | 42 image_.height(), |
54 0, | 43 0, |
55 0, | 44 0, |
56 width(), | 45 width(), |
57 height(), | 46 height(), |
58 true); | 47 true); |
59 } | 48 } |
60 | 49 |
61 private: | 50 private: |
62 gfx::ImageSkia image_; | 51 gfx::ImageSkia image_; |
63 views::View* time_view_; | 52 views::View* system_info_view_; |
64 views::View* status_icon_view_; | |
65 | 53 |
66 DISALLOW_COPY_AND_ASSIGN(BackgroundView); | 54 DISALLOW_COPY_AND_ASSIGN(BackgroundView); |
67 }; | 55 }; |
68 | 56 |
69 BackgroundController::BackgroundController(aura::Window* background_container) { | 57 BackgroundController::BackgroundController(aura::Window* background_container) { |
70 views::Widget* background_widget = new views::Widget; | 58 views::Widget* background_widget = new views::Widget; |
71 views::Widget::InitParams params( | 59 views::Widget::InitParams params( |
72 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 60 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
73 params.parent = background_container; | 61 params.parent = background_container; |
74 background_widget->Init(params); | 62 background_widget->Init(params); |
75 background_widget->GetNativeWindow()->layer()->SetMasksToBounds(true); | 63 background_widget->GetNativeWindow()->layer()->SetMasksToBounds(true); |
76 background_view_ = new BackgroundView; | 64 background_view_ = new BackgroundView; |
77 background_widget->SetContentsView(background_view_); | 65 background_widget->SetContentsView(background_view_); |
78 background_widget->GetNativeView()->SetName("BackgroundWidget"); | 66 background_widget->GetNativeView()->SetName("BackgroundWidget"); |
79 background_widget->Show(); | 67 background_widget->Show(); |
80 } | 68 } |
81 | 69 |
82 BackgroundController::~BackgroundController() { | 70 BackgroundController::~BackgroundController() { |
83 // background_widget is owned by the container and will be deleted | 71 // background_widget is owned by the container and will be deleted |
84 // when the container is deleted. | 72 // when the container is deleted. |
85 } | 73 } |
86 | 74 |
87 void BackgroundController::SetImage(const gfx::ImageSkia& image) { | 75 void BackgroundController::SetImage(const gfx::ImageSkia& image) { |
88 // TODO(oshima): implement cross fede animation. | 76 // TODO(oshima): implement cross fede animation. |
89 background_view_->SetImage(image); | 77 background_view_->SetImage(image); |
90 } | 78 } |
91 | 79 |
92 } // namespace athena | 80 } // namespace athena |
OLD | NEW |