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.
5 #include "athena/system/background_controller.h"
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"
18 class BackgroundView
: public views::View
{
21 ~BackgroundView() override
{}
23 void SetImage(const gfx::ImageSkia
& image
) {
29 virtual void OnPaint(gfx::Canvas
* canvas
) override
{
30 canvas
->DrawImageInt(image_
,
43 gfx::ImageSkia image_
;
45 DISALLOW_COPY_AND_ASSIGN(BackgroundView
);
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();
62 BackgroundController::~BackgroundController() {
63 // background_widget is owned by the container and will be deleted
64 // when the container is deleted.
67 void BackgroundController::SetImage(const gfx::ImageSkia
& image
) {
68 // TODO(oshima): implement cross fede animation.
69 background_view_
->SetImage(image
);