Home | History | Annotate | Download | only in screen
      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) {
     22     image_ = image;
     23     SchedulePaint();
     24   }
     25 
     26   // views::View
     27   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
     28     canvas->DrawImageInt(image_,
     29                          0,
     30                          0,
     31                          image_.width(),
     32                          image_.height(),
     33                          0,
     34                          0,
     35                          width(),
     36                          height(),
     37                          true);
     38   }
     39 
     40  private:
     41   gfx::ImageSkia image_;
     42 
     43   DISALLOW_COPY_AND_ASSIGN(BackgroundView);
     44 };
     45 
     46 BackgroundController::BackgroundController(aura::Window* container) {
     47   // TODO(oshima): Using widget to just draw an image is probably
     48   // overkill. Just use WindowDelegate to draw the background and
     49   // remove dependency to ui/views.
     50 
     51   views::Widget* background_widget = new views::Widget;
     52   views::Widget::InitParams params(
     53       views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
     54   params.accept_events = false;
     55   params.parent = container;
     56   background_widget->Init(params);
     57   background_widget->GetNativeWindow()->layer()->SetMasksToBounds(true);
     58   background_view_ = new BackgroundView;
     59   background_widget->SetContentsView(background_view_);
     60   background_widget->GetNativeView()->SetName("BackgroundWidget");
     61   background_widget->Show();
     62 }
     63 
     64 BackgroundController::~BackgroundController() {
     65   // background_widget is owned by the container and will be deleted
     66   // when the container is deleted.
     67 }
     68 
     69 void BackgroundController::SetImage(const gfx::ImageSkia& image) {
     70   // TODO(oshima): implement cross fede animation.
     71   background_view_->SetImage(image);
     72 }
     73 
     74 }  // namespace athena
     75