Home | History | Annotate | Download | only in shelf
      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_SHELF_BACKGROUND_ANIMATOR_H_
      6 #define ASH_SHELF_BACKGROUND_ANIMATOR_H_
      7 
      8 #include "ash/ash_export.h"
      9 #include "base/basictypes.h"
     10 #include "ui/gfx/animation/animation_delegate.h"
     11 #include "ui/gfx/animation/slide_animation.h"
     12 
     13 namespace ash {
     14 
     15 // How the background can be changed.
     16 enum BackgroundAnimatorChangeType {
     17   BACKGROUND_CHANGE_ANIMATE,
     18   BACKGROUND_CHANGE_IMMEDIATE
     19 };
     20 
     21 namespace internal {
     22 
     23 // Delegate is notified any time the background changes.
     24 class ASH_EXPORT BackgroundAnimatorDelegate {
     25  public:
     26   virtual void UpdateBackground(int alpha) = 0;
     27 
     28  protected:
     29   virtual ~BackgroundAnimatorDelegate() {}
     30 };
     31 
     32 // BackgroundAnimator is used by the shelf to animate the background (alpha).
     33 class ASH_EXPORT BackgroundAnimator : public gfx::AnimationDelegate {
     34  public:
     35   BackgroundAnimator(BackgroundAnimatorDelegate* delegate,
     36                      int min_alpha,
     37                      int max_alpha);
     38   virtual ~BackgroundAnimator();
     39 
     40   // Sets the transition time in ms.
     41   void SetDuration(int time_in_ms);
     42 
     43   // Sets whether a background is rendered. Initial value is false. If |type|
     44   // is |CHANGE_IMMEDIATE| and an animation is not in progress this notifies
     45   // the delegate immediately (synchronously from this method).
     46   void SetPaintsBackground(bool value, BackgroundAnimatorChangeType type);
     47   bool paints_background() const { return paints_background_; }
     48 
     49   // Current alpha.
     50   int alpha() const { return alpha_; }
     51 
     52   // gfx::AnimationDelegate overrides:
     53   virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
     54 
     55  private:
     56   BackgroundAnimatorDelegate* delegate_;
     57 
     58   const int min_alpha_;
     59   const int max_alpha_;
     60 
     61   gfx::SlideAnimation animation_;
     62 
     63   // Whether the background is painted.
     64   bool paints_background_;
     65 
     66   // Current alpha value of the background.
     67   int alpha_;
     68 
     69   DISALLOW_COPY_AND_ASSIGN(BackgroundAnimator);
     70 };
     71 
     72 }  // namespace internal
     73 }  // namespace ash
     74 
     75 #endif  // ASH_SHELF_BACKGROUND_ANIMATOR_H_
     76