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