Chromium Code Reviews| Index: chrome/browser/ui/search/toolbar_search_animator.h |
| diff --git a/chrome/browser/ui/search/toolbar_search_animator.h b/chrome/browser/ui/search/toolbar_search_animator.h |
| index 6041cf89da3004acf61c28562284ff9fc6a5aced..27fdde9ce00104b7426717bb9af85a4b118e1274 100644 |
| --- a/chrome/browser/ui/search/toolbar_search_animator.h |
| +++ b/chrome/browser/ui/search/toolbar_search_animator.h |
| @@ -7,14 +7,14 @@ |
| #include "base/memory/scoped_ptr.h" |
| #include "base/observer_list.h" |
| -#include "base/timer.h" |
| #include "chrome/browser/ui/search/search_model_observer.h" |
| +#include "chrome/browser/ui/search/search_types.h" |
| #include "ui/base/animation/animation_delegate.h" |
| class TabContents; |
| namespace ui { |
| -class SlideAnimation; |
| +class MultiAnimation; |
| } |
| namespace chrome { |
| @@ -23,37 +23,23 @@ namespace search { |
| class SearchModel; |
| class ToolbarSearchAnimatorObserver; |
| -// ToolbarSearchAnimator is used to track the background state of the toolbar |
| -// and related classes. To use ToolbarSearchAnimator, add a |
| -// ToolbarSearchAnimatorObserver. The ToolbarSearchAnimatorObserver is then |
| -// notified appropriately. |
| +// ToolbarSearchAnimator is used to track the gradient background and separator |
|
dhollowa
2012/08/02 22:35:38
delete "and separator states".
kuan
2012/08/03 04:55:58
Done.
|
| +// states of the toolbar and related classes. To use ToolbarSearchAnimator, |
| +// add a ToolbarSearchAnimatorObserver. The ToolbarSearchAnimatorObserver is |
| +// then notified appropriately. |
| class ToolbarSearchAnimator : public SearchModelObserver, |
| public ui::AnimationDelegate { |
| public: |
| - // State of background to paint by observers, only applicable for |
| - // |MODE_SEARCH|. |
| - enum BackgroundState { |
| - // Background state is not applicable. |
| - BACKGROUND_STATE_DEFAULT = 0, |
| - // Show background for |MODE_NTP|. |
| - BACKGROUND_STATE_NTP = 0x01, |
| - // Show background for |MODE_SEARCH|. |
| - BACKGROUND_STATE_SEARCH = 0x02, |
| - // Show backgrounds for both |MODE_NTP| and |MODE_SEARCH|. |
| - BACKGROUND_STATE_NTP_SEARCH = BACKGROUND_STATE_NTP | |
| - BACKGROUND_STATE_SEARCH, |
| - }; |
| - |
| explicit ToolbarSearchAnimator(SearchModel* search_model); |
| virtual ~ToolbarSearchAnimator(); |
| - // Get the current background state to paint. |
| - // |search_background_opacity| contains a valid opacity value only if |
| - // background for |MODE_SEARCH| needs to be shown i.e. |background_state| is |
| - // BACKGROUND_STATE_SEARCH or BACKGROUND_STATE_NTP_SEARCH. |
| - // Only call this for |MODE_SEARCH|. |
| - void GetCurrentBackgroundState(BackgroundState* background_state, |
| - double* search_background_opacity) const; |
| + // Get the gradient background opacity to paint for toolbar and active tab, a |
| + // value between 0f and 1f inclusive: |
| + // - 0f: only paint flat background |
| + // - < 1f: paint flat background at full opacity and gradient background at |
| + // specified opacity |
| + // - 1f: only paint gradient background at full opacity |
| + double GetGradientOpacity() const; |
| // Called from SearchDelegate::StopObservingTab() when a tab is deactivated or |
| // closing or detached, to jump to the end state of the animation. |
| @@ -66,28 +52,28 @@ class ToolbarSearchAnimator : public SearchModelObserver, |
| void RemoveObserver(ToolbarSearchAnimatorObserver* observer); |
| // Overridden from SearchModelObserver: |
| - virtual void ModeChanged(const Mode& mode) OVERRIDE; |
| + virtual void ModeChanged(const Mode& old_mode, const Mode& new_mode) OVERRIDE; |
| // Overridden from ui::AnimationDelegate: |
| virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; |
| virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; |
| private: |
| - // State of animation. |
| - enum AnimateState { |
| - ANIMATE_STATE_NONE, // Doing nothing. |
| - ANIMATE_STATE_WAITING, // Waiting to run background animation. |
| - ANIMATE_STATE_RUNNING, // Running background animation. |
| - }; |
| - |
| - // Callback for |background_change_timer_| to actually start the background |
| - // change animation. |
| + friend class ToolbarSearchAnimatorTest; |
| + friend class ToolbarSearchAnimatorTestObserver; |
| + |
| + // Helper function to initialize background animation with its parts. |
| + void InitBackgroundAnimation(int background_change_delay_ms, |
| + int background_change_duration_ms); |
| + |
| + // Helper function to start animation for gradient background change. |
| void StartBackgroundChange(); |
| - // Reset state of animator: reset animate_state_, stop timer or animation, |
| - // If we're waiting to animate or animating, i.e. |animate_state| is not |
| - // ANIMATE_STAET_NONE, wwe'll notify observers via |
| - // ToolbarSearchAnimatorObserver::BackgroundChangeCanceled. |
| + // Reset animations by stopping them. |
| + // If we're animating background or separator, we'll notify observers via |
| + // ToolbarSearchAnimatorObserver::OnToolbarBackgroundAnimatorCanceled or |
| + // ToolbarSearchAnimatorObserver::OnToolbarSeparatorAnimatorCanceled |
| + // respectively. |
| // Pass in |tab_contents| if animation is canceled because of deactivating or |
| // detaching or closing a tab. |
| void Reset(TabContents* tab_contents); |
| @@ -95,15 +81,8 @@ class ToolbarSearchAnimator : public SearchModelObserver, |
| // Weak. Owned by Browser. Non-NULL. |
| SearchModel* search_model_; |
| - // State of animation. |
| - AnimateState animate_state_; |
| - |
| - // The background fade animation. |
| - scoped_ptr<ui::SlideAnimation> background_animation_; |
| - |
| - // The timer to delay start of animation after mode changes from |MODE_NTP| to |
| - // |MODE_SEARCH|. |
| - base::OneShotTimer<ToolbarSearchAnimator> background_change_timer_; |
| + // The background change animation. |
| + scoped_ptr<ui::MultiAnimation> background_animation_; |
| // Observers. |
| ObserverList<ToolbarSearchAnimatorObserver> observers_; |