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/screen/background_controller.h" |
| 6 |
| 7 #include "ui/aura/window.h" |
| 8 #include "ui/compositor/layer.h" |
| 9 #include "ui/gfx/canvas.h" |
| 10 #include "ui/gfx/image/image_skia.h" |
| 11 #include "ui/views/view.h" |
| 12 #include "ui/views/widget/widget.h" |
| 13 |
| 14 namespace athena { |
| 15 |
| 16 class BackgroundView : public views::View { |
| 17 public: |
| 18 BackgroundView() {} |
| 19 virtual ~BackgroundView() {} |
| 20 |
| 21 void SetImage(const gfx::ImageSkia& image) { image_ = image; } |
| 22 |
| 23 // views::View |
| 24 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
| 25 canvas->DrawImageInt(image_, |
| 26 0, |
| 27 0, |
| 28 image_.width(), |
| 29 image_.height(), |
| 30 0, |
| 31 0, |
| 32 width(), |
| 33 height(), |
| 34 true); |
| 35 } |
| 36 |
| 37 private: |
| 38 gfx::ImageSkia image_; |
| 39 |
| 40 DISALLOW_COPY_AND_ASSIGN(BackgroundView); |
| 41 }; |
| 42 |
| 43 BackgroundController::BackgroundController(aura::Window* container) { |
| 44 views::Widget* desktop_widget = new views::Widget; |
| 45 views::Widget::InitParams params( |
| 46 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 47 params.parent = container; |
| 48 desktop_widget->Init(params); |
| 49 desktop_widget->GetNativeWindow()->layer()->SetMasksToBounds(true); |
| 50 background_view_ = new BackgroundView; |
| 51 desktop_widget->SetContentsView(background_view_); |
| 52 desktop_widget->Show(); |
| 53 } |
| 54 |
| 55 void BackgroundController::SetImage(const gfx::ImageSkia& image) { |
| 56 background_view_->SetImage(image); |
| 57 } |
| 58 |
| 59 } // namespace athena |
OLD | NEW |