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