Home | History | Annotate | Download | only in desktop_background
      1 // Copyright (c) 2012 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 #ifndef ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_WIDGET_CONTROLLER_H_
      6 #define ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_WIDGET_CONTROLLER_H_
      7 
      8 #include "ash/ash_export.h"
      9 #include "base/memory/scoped_ptr.h"
     10 #include "ui/aura/window.h"
     11 #include "ui/compositor/layer.h"
     12 #include "ui/views/widget/widget.h"
     13 #include "ui/views/widget/widget_observer.h"
     14 
     15 namespace ash {
     16 namespace internal {
     17 class RootWindowController;
     18 
     19 // This class implements a widget-based wallpaper.
     20 // DesktopBackgroundWidgetController is owned by RootWindowController.
     21 // When the animation completes the old DesktopBackgroundWidgetController is
     22 // destroyed. Exported for tests.
     23 class ASH_EXPORT DesktopBackgroundWidgetController
     24     : public views::WidgetObserver {
     25  public:
     26   // Create
     27   explicit DesktopBackgroundWidgetController(views::Widget* widget);
     28 
     29   virtual ~DesktopBackgroundWidgetController();
     30 
     31   // Overridden from views::WidgetObserver.
     32   virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
     33 
     34   // Set bounds of component that draws background.
     35   void SetBounds(gfx::Rect bounds);
     36 
     37   // Move component from |src_container| in |root_window| to |dest_container|.
     38   // It is required for lock screen, when we need to move background so that
     39   // it hides user's windows. Returns true if there was something to reparent.
     40   bool Reparent(aura::Window* root_window,
     41                 int src_container,
     42                 int dest_container);
     43 
     44   // Starts wallpaper fade in animation. |root_window_controller| is
     45   // the root window where the animation will happen. (This is
     46   // necessary this as |layer_| doesn't have access to the root window).
     47   void StartAnimating(RootWindowController* root_window_controller);
     48 
     49   views::Widget* widget() { return widget_; }
     50 
     51  private:
     52   views::Widget* widget_;
     53 
     54   DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundWidgetController);
     55 };
     56 
     57 // This class wraps a DesktopBackgroundWidgetController pointer. It is owned
     58 // by RootWindowController. The instance of DesktopBackgroundWidgetController is
     59 // moved to this RootWindowController when the animation completes.
     60 // Exported for tests.
     61 class ASH_EXPORT AnimatingDesktopController {
     62  public:
     63   explicit AnimatingDesktopController(
     64       DesktopBackgroundWidgetController* component);
     65   ~AnimatingDesktopController();
     66 
     67   // Stops animation and makes sure OnImplicitAnimationsCompleted() is called if
     68   // current animation is not finished yet.
     69   // Note we have to make sure this function is called before we set
     70   // kAnimatingDesktopController to a new controller. If it is not called, the
     71   // animating widget/layer is closed immediately and the new one is animating
     72   // from the widget/layer before animation. For instance, if a user quickly
     73   // switches between red, green and blue wallpapers. The green wallpaper will
     74   // first fade in from red wallpaper. And in the middle of the animation, blue
     75   // wallpaper also wants to fade in. If the green wallpaper animation does not
     76   // finish immediately, the green wallpaper widget will be removed and the red
     77   // widget will show again. As a result, the blue wallpaper fades in from red
     78   // wallpaper. This is a bad user experience. See bug http://crbug.com/156542
     79   // for more details.
     80   void StopAnimating();
     81 
     82   // Gets the wrapped DesktopBackgroundWidgetController pointer. Caller should
     83   // take ownership of the pointer if |pass_ownership| is true.
     84   DesktopBackgroundWidgetController* GetController(bool pass_ownership);
     85 
     86  private:
     87   scoped_ptr<DesktopBackgroundWidgetController> controller_;
     88 
     89   DISALLOW_COPY_AND_ASSIGN(AnimatingDesktopController);
     90 };
     91 
     92 }  // namespace internal
     93 }  // namespace ash
     94 
     95 #endif  // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_WIDGET_CONTROLLER_H_
     96