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/screen/background_controller.h"
7 #include "base/strings/stringprintf.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"
12 #include "ui/compositor/layer.h"
13 #include "ui/gfx/canvas.h"
14 #include "ui/gfx/image/image_skia.h"
15 #include "ui/views/controls/label.h"
16 #include "ui/views/view.h"
17 #include "ui/views/widget/widget.h"
23 const SkColor kVersionColor
= SK_ColorWHITE
;
24 const SkColor kVersionBackground
= SK_ColorTRANSPARENT
;
25 const SkColor kVersionShadow
= 0xB0000000;
26 const int kVersionShadowBlur
= 10;
28 class VersionView
: public views::Label
{
31 SetEnabledColor(kVersionColor
);
32 SetBackgroundColor(kVersionBackground
);
33 SetShadows(gfx::ShadowValues(1, gfx::ShadowValue(gfx::Point(0, 1),
36 SetText(base::UTF8ToUTF16(base::StringPrintf("%s (Build %s)",
39 SetBoundsRect(gfx::Rect(gfx::Point(), GetPreferredSize()));
41 virtual ~VersionView() {
45 DISALLOW_COPY_AND_ASSIGN(VersionView
);
50 class BackgroundView
: public views::View
{
53 AddChildView(new VersionView
);
55 virtual ~BackgroundView() {}
57 void SetImage(const gfx::ImageSkia
& image
) {
63 virtual void OnPaint(gfx::Canvas
* canvas
) OVERRIDE
{
64 canvas
->DrawImageInt(image_
,
77 gfx::ImageSkia image_
;
79 DISALLOW_COPY_AND_ASSIGN(BackgroundView
);
82 BackgroundController::BackgroundController(aura::Window
* container
) {
83 // TODO(oshima): Using widget to just draw an image is probably
84 // overkill. Just use WindowDelegate to draw the background and
85 // remove dependency to ui/views.
87 views::Widget
* background_widget
= new views::Widget
;
88 views::Widget::InitParams
params(
89 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS
);
90 params
.accept_events
= false;
91 params
.parent
= container
;
92 background_widget
->Init(params
);
93 background_widget
->GetNativeWindow()->layer()->SetMasksToBounds(true);
94 background_view_
= new BackgroundView
;
95 background_widget
->SetContentsView(background_view_
);
96 background_widget
->GetNativeView()->SetName("BackgroundWidget");
97 background_widget
->Show();
100 BackgroundController::~BackgroundController() {
101 // background_widget is owned by the container and will be deleted
102 // when the container is deleted.
105 void BackgroundController::SetImage(const gfx::ImageSkia
& image
) {
106 // TODO(oshima): implement cross fede animation.
107 background_view_
->SetImage(image
);
110 } // namespace athena