Chromium Code Reviews| Index: ash/common/shelf/shelf_background_animator.h |
| diff --git a/ash/common/shelf/shelf_background_animator.h b/ash/common/shelf/shelf_background_animator.h |
| index fcc95dd26a905dff656bd445075d59acc3d42215..1611d951299faeaabd47309cd2ec4bc1b4d8d916 100644 |
| --- a/ash/common/shelf/shelf_background_animator.h |
| +++ b/ash/common/shelf/shelf_background_animator.h |
| @@ -10,10 +10,16 @@ |
| #include "ash/ash_export.h" |
| #include "ash/common/shelf/wm_shelf_observer.h" |
| -#include "ash/common/wm/background_animator.h" |
| #include "ash/public/cpp/shelf_types.h" |
| #include "base/macros.h" |
| #include "base/observer_list.h" |
| +#include "ui/gfx/animation/animation_delegate.h" |
| +#include "ui/gfx/animation/tween.h" |
|
James Cook
2017/02/10 21:17:34
needed?
bruthig
2017/02/10 22:45:36
Nope, removed.
|
| + |
| +namespace gfx { |
| +class SlideAnimation; |
| +enum class AnimationChangeType; |
| +} // namespace gfx |
| namespace ash { |
| @@ -30,10 +36,10 @@ class WmShelf; |
| // |
| // Material Design: |
| // 1. Shelf button backgrounds |
| -// 2. Opaque overlay for the SHELF_BACKGROUND_OVERLAP and |
| -// SHELF_BACKGROUND_MAXIMIZED states. |
| +// 2. Overlay for the SHELF_BACKGROUND_OVERLAP and SHELF_BACKGROUND_MAXIMIZED |
| +// states. |
| class ASH_EXPORT ShelfBackgroundAnimator : public WmShelfObserver, |
| - public BackgroundAnimatorDelegate { |
| + public gfx::AnimationDelegate { |
| public: |
| // Initializes this with the given |background_type|. This will observe the |
| // |wm_shelf| for background type changes if |wm_shelf| is not null. |
| @@ -50,7 +56,7 @@ class ASH_EXPORT ShelfBackgroundAnimator : public WmShelfObserver, |
| void RemoveObserver(ShelfBackgroundAnimatorObserver* observer); |
| // Updates |observer| with current values. |
| - void Initialize(ShelfBackgroundAnimatorObserver* observer) const; |
| + void NotifyObserver(ShelfBackgroundAnimatorObserver* observer); |
| // Conditionally animates the background to the specified |background_type| |
| // and notifies observers of the new background parameters (e.g. alpha). |
| @@ -63,36 +69,81 @@ class ASH_EXPORT ShelfBackgroundAnimator : public WmShelfObserver, |
| // BACKGROUND_CHANGE_ANIMATE change type is received it will be ignored and |
| // observers will NOT be notified. |
| void PaintBackground(ShelfBackgroundType background_type, |
| - BackgroundAnimatorChangeType change_type); |
| + gfx::AnimationChangeType change_type); |
| + |
| + // gfx::AnimationDelegate: |
| + void AnimationProgressed(const gfx::Animation* animation) override; |
| + void AnimationEnded(const gfx::Animation* animation) override; |
| + void AnimationCanceled(const gfx::Animation* animation) override; |
| protected: |
| // WmShelfObserver: |
| - void OnBackgroundTypeChanged( |
| - ShelfBackgroundType background_type, |
| - BackgroundAnimatorChangeType change_type) override; |
| - |
| - // BackgroundAnimatorDelegate: |
| - void UpdateBackground(BackgroundAnimator* animator, int alpha) override; |
| - void BackgroundAnimationEnded(BackgroundAnimator* animator) override; |
| + void OnBackgroundTypeChanged(ShelfBackgroundType background_type, |
| + gfx::AnimationChangeType change_type) override; |
| private: |
| friend class ShelfBackgroundAnimatorTestApi; |
| + // Track the values related to a single animation (e.g. Shelf background, |
| + // shelf item background) |
| + class AnimationValues { |
|
James Cook
2017/02/10 21:17:34
nit: I would provide empty constructor and destruc
bruthig
2017/02/10 22:45:36
Done.
|
| + public: |
| + int current_alpha() const { return current_alpha_; } |
| + |
| + // Updates the current values based on |t| value between 0 and 1. |
| + void UpdateCurrentValues(double t); |
| + |
| + // Set the target values and assign the current values to the initial |
| + // values. |
| + void SetTargetValues(int target_alpha); |
| + |
| + // Returns true if the initial values of |this| equal the target values of |
| + // |other|. |
| + bool InitialValuesEqualTargetValuesOf(const AnimationValues& other) const; |
| + |
| + private: |
| + int initial_alpha_ = 0; |
| + int current_alpha_ = 0; |
| + int target_alpha_ = 0; |
| + }; |
| + |
| + // The maximum alpha value that can be used. |
| + static const int kMaxAlpha = 255; |
| + |
| // Helper function used by PaintBackground() to animate the background. |
| void AnimateBackground(ShelfBackgroundType background_type, |
| - BackgroundAnimatorChangeType change_type); |
| + gfx::AnimationChangeType change_type); |
| + |
| + // Returns true if the current |animator_| should be re-used to animate to the |
| + // given |background_type|. This allows for pre-empted animations to take the |
| + // same amount of time to reverse to the |previous_background_type_|. |
| + bool CanReuseAnimator(ShelfBackgroundType background_type) const; |
| + |
| + // Creates a new |animator_| configured with the correct duration. If the |
| + // |animator_| is currently animating it will be stopped. |
| + void CreateAnimator(ShelfBackgroundType background_type); |
| - // Creates new BackgroundAnimators configured with the correct durations and |
| - // initial/target alpha values. If any BackgroundAnimators are currently |
| - // animating they will be stopped. |
| - void CreateAnimators(ShelfBackgroundType background_type, |
| - BackgroundAnimatorChangeType change_type); |
| + // Stops the animator owned by this. |
| + void StopAnimator(); |
| - // Stops all existing animators owned by this. |
| - void StopAnimators(); |
| + // Updates the |shelf_background_values_| and |shelf_item_background_values_|. |
| + void SetTargetValues(ShelfBackgroundType background_type); |
| - // Called when an alpha value changes and observers need to be notified. |
| - void OnAlphaChanged(BackgroundAnimator* animator, int alpha); |
| + // Sets the target values for |shelf_background_values| and |
| + // |item_background_values| according to |background_type|. |
| + void GetTargetValues(ShelfBackgroundType background_type, |
| + AnimationValues* shelf_background_values, |
| + AnimationValues* item_background_values) const; |
| + |
| + // Updates the animation values corresponding to the |t| value between 0 and |
| + // 1. |
| + void SetAnimationValues(double t); |
| + |
| + // Called when observers need to be notified. |
| + void NotifyObservers(); |
| + |
| + // The shelf to observe for changes to the shelf background type, can be null. |
| + WmShelf* wm_shelf_; |
| // The background type that this is animating towards or has reached. |
| ShelfBackgroundType target_background_type_ = SHELF_BACKGROUND_DEFAULT; |
| @@ -100,27 +151,16 @@ class ASH_EXPORT ShelfBackgroundAnimator : public WmShelfObserver, |
| // The last background type this is animating away from. |
| ShelfBackgroundType previous_background_type_ = SHELF_BACKGROUND_MAXIMIZED; |
| - // Animates the solid color background of the Shelf. |
| - // TODO(bruthig): Replace all BackgroundAnimators with a single |
| - // gfx::SlideAnimation. |
| - std::unique_ptr<BackgroundAnimator> opaque_background_animator_; |
| + // Drives the animtion. |
| + std::unique_ptr<gfx::SlideAnimation> animator_; |
| - // Animates the backgrounds of Shelf child Views. |
| - std::unique_ptr<BackgroundAnimator> item_background_animator_; |
| + // Tracks the shelf background animation values. |
| + AnimationValues shelf_background_values_; |
| - base::ObserverList<ShelfBackgroundAnimatorObserver> observers_; |
| + // Tracks the item background animation values. |
| + AnimationValues item_background_values_; |
| - // True if the existing BackgroundAnimators can be re-used to animate to the |
| - // |previous_background_type_|. This allows for pre-empted animations to take |
| - // the same amount of time to reverse to the |previous_background_type_|. |
| - bool can_reuse_animators_ = false; |
| - |
| - // Tracks how many animators completed successfully since the last |
| - // CreateAnimators() call. Used to properly set |can_reuse_animators_|. |
| - int successful_animator_count_ = 0; |
| - |
| - // The shelf to observe for changes to the shelf background type, can be null. |
| - WmShelf* wm_shelf_; |
| + base::ObserverList<ShelfBackgroundAnimatorObserver> observers_; |
| DISALLOW_COPY_AND_ASSIGN(ShelfBackgroundAnimator); |
| }; |