| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ASH_COMMON_WM_BACKGROUND_ANIMATOR_H_ | 5 #ifndef ASH_COMMON_WM_BACKGROUND_ANIMATOR_H_ |
| 6 #define ASH_COMMON_WM_BACKGROUND_ANIMATOR_H_ | 6 #define ASH_COMMON_WM_BACKGROUND_ANIMATOR_H_ |
| 7 | 7 |
| 8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "ui/gfx/animation/animation_delegate.h" | 10 #include "ui/gfx/animation/animation_delegate.h" |
| 11 #include "ui/gfx/animation/slide_animation.h" | 11 #include "ui/gfx/animation/slide_animation.h" |
| 12 | 12 |
| 13 namespace ash { | 13 namespace ash { |
| 14 | 14 |
| 15 // How the background can be changed. | 15 // How the background can be changed. |
| 16 enum BackgroundAnimatorChangeType { | 16 enum BackgroundAnimatorChangeType { |
| 17 BACKGROUND_CHANGE_ANIMATE, | 17 BACKGROUND_CHANGE_ANIMATE, |
| 18 BACKGROUND_CHANGE_IMMEDIATE | 18 BACKGROUND_CHANGE_IMMEDIATE |
| 19 }; | 19 }; |
| 20 | 20 |
| 21 class BackgroundAnimator; | |
| 22 | |
| 23 // Delegate is notified any time the background changes. | 21 // Delegate is notified any time the background changes. |
| 24 class ASH_EXPORT BackgroundAnimatorDelegate { | 22 class ASH_EXPORT BackgroundAnimatorDelegate { |
| 25 public: | 23 public: |
| 26 virtual void UpdateBackground(BackgroundAnimator* animator, int alpha) = 0; | 24 virtual void UpdateBackground(int alpha) = 0; |
| 27 | |
| 28 virtual void BackgroundAnimationEnded(BackgroundAnimator* animator) = 0; | |
| 29 | 25 |
| 30 protected: | 26 protected: |
| 31 virtual ~BackgroundAnimatorDelegate() {} | 27 virtual ~BackgroundAnimatorDelegate() {} |
| 32 }; | 28 }; |
| 33 | 29 |
| 34 // BackgroundAnimator is used by the shelf to animate the background (alpha). | 30 // BackgroundAnimator is used by the shelf to animate the background (alpha). |
| 35 class ASH_EXPORT BackgroundAnimator : public gfx::AnimationDelegate { | 31 class ASH_EXPORT BackgroundAnimator : public gfx::AnimationDelegate { |
| 36 public: | 32 public: |
| 37 BackgroundAnimator(BackgroundAnimatorDelegate* delegate, | 33 BackgroundAnimator(BackgroundAnimatorDelegate* delegate, |
| 38 int min_alpha, | 34 int min_alpha, |
| 39 int max_alpha); | 35 int max_alpha); |
| 40 ~BackgroundAnimator() override; | 36 ~BackgroundAnimator() override; |
| 41 | 37 |
| 42 // Sets the transition time in ms. | 38 // Sets the transition time in ms. |
| 43 void SetDuration(int time_in_ms); | 39 void SetDuration(int time_in_ms); |
| 44 | 40 |
| 45 // Stops the animation. Does nothing if the animation is not running. | |
| 46 void Stop(); | |
| 47 | |
| 48 // Sets whether a background is rendered. Initial value is false. If |type| | 41 // Sets whether a background is rendered. Initial value is false. If |type| |
| 49 // is |CHANGE_IMMEDIATE| and an animation is not in progress this notifies | 42 // is |CHANGE_IMMEDIATE| and an animation is not in progress this notifies |
| 50 // the delegate immediately (synchronously from this method). | 43 // the delegate immediately (synchronously from this method). |
| 51 void SetPaintsBackground(bool value, BackgroundAnimatorChangeType type); | 44 void SetPaintsBackground(bool value, BackgroundAnimatorChangeType type); |
| 52 bool paints_background() const { return paints_background_; } | 45 bool paints_background() const { return paints_background_; } |
| 53 | 46 |
| 54 // Current alpha. | 47 // Current alpha. |
| 55 int alpha() const { return alpha_; } | 48 int alpha() const { return alpha_; } |
| 56 | 49 |
| 57 // gfx::AnimationDelegate overrides: | 50 // gfx::AnimationDelegate overrides: |
| 58 void AnimationProgressed(const gfx::Animation* animation) override; | 51 void AnimationProgressed(const gfx::Animation* animation) override; |
| 59 void AnimationEnded(const gfx::Animation* animation) override; | |
| 60 | 52 |
| 61 private: | 53 private: |
| 62 BackgroundAnimatorDelegate* delegate_; | 54 BackgroundAnimatorDelegate* delegate_; |
| 63 | 55 |
| 64 const int min_alpha_; | 56 const int min_alpha_; |
| 65 const int max_alpha_; | 57 const int max_alpha_; |
| 66 | 58 |
| 67 gfx::SlideAnimation animation_; | 59 gfx::SlideAnimation animation_; |
| 68 | 60 |
| 69 // Whether the background is painted. | 61 // Whether the background is painted. |
| 70 bool paints_background_; | 62 bool paints_background_; |
| 71 | 63 |
| 72 // Current alpha value of the background. | 64 // Current alpha value of the background. |
| 73 int alpha_; | 65 int alpha_; |
| 74 | 66 |
| 75 DISALLOW_COPY_AND_ASSIGN(BackgroundAnimator); | 67 DISALLOW_COPY_AND_ASSIGN(BackgroundAnimator); |
| 76 }; | 68 }; |
| 77 | 69 |
| 78 } // namespace ash | 70 } // namespace ash |
| 79 | 71 |
| 80 #endif // ASH_COMMON_WM_BACKGROUND_ANIMATOR_H_ | 72 #endif // ASH_COMMON_WM_BACKGROUND_ANIMATOR_H_ |
| OLD | NEW |