blob: 66686d0ca83175036f332b123e17b38ccd6116c9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "athena/screen/background_controller.h"
#include "ui/aura/window.h"
#include "ui/compositor/layer.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
namespace athena {
class BackgroundView : public views::View {
public:
BackgroundView() {}
virtual ~BackgroundView() {}
void SetImage(const gfx::ImageSkia& image) {
image_ = image;
SchedulePaint();
}
// views::View
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
canvas->DrawImageInt(image_,
0,
0,
image_.width(),
image_.height(),
0,
0,
width(),
height(),
true);
}
private:
gfx::ImageSkia image_;
DISALLOW_COPY_AND_ASSIGN(BackgroundView);
};
BackgroundController::BackgroundController(aura::Window* container) {
// TODO(oshima): Using widget to just draw an image is probably
// overkill. Just use WindowDelegate to draw the background and
// remove dependency to ui/views.
views::Widget* background_widget = new views::Widget;
views::Widget::InitParams params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.accept_events = false;
params.parent = container;
background_widget->Init(params);
background_widget->GetNativeWindow()->layer()->SetMasksToBounds(true);
background_view_ = new BackgroundView;
background_widget->SetContentsView(background_view_);
background_widget->GetNativeView()->SetName("BackgroundWidget");
background_widget->Show();
}
BackgroundController::~BackgroundController() {
// background_widget is owned by the container and will be deleted
// when the container is deleted.
}
void BackgroundController::SetImage(const gfx::ImageSkia& image) {
// TODO(oshima): implement cross fede animation.
background_view_->SetImage(image);
}
} // namespace athena
|