| 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 CHROME_BROWSER_UI_SEARCH_TOOLBAR_SEARCH_ANIMATOR_H_ | 5 #ifndef CHROME_BROWSER_UI_SEARCH_TOOLBAR_SEARCH_ANIMATOR_H_ |
| 6 #define CHROME_BROWSER_UI_SEARCH_TOOLBAR_SEARCH_ANIMATOR_H_ | 6 #define CHROME_BROWSER_UI_SEARCH_TOOLBAR_SEARCH_ANIMATOR_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
| 10 #include "base/timer.h" | |
| 11 #include "chrome/browser/ui/search/search_model_observer.h" | 10 #include "chrome/browser/ui/search/search_model_observer.h" |
| 11 #include "chrome/browser/ui/search/search_types.h" |
| 12 #include "ui/base/animation/animation_delegate.h" | 12 #include "ui/base/animation/animation_delegate.h" |
| 13 | 13 |
| 14 class TabContents; | 14 class TabContents; |
| 15 | 15 |
| 16 namespace ui { | 16 namespace ui { |
| 17 class SlideAnimation; | 17 class MultiAnimation; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace chrome { | 20 namespace chrome { |
| 21 namespace search { | 21 namespace search { |
| 22 | 22 |
| 23 class SearchModel; | 23 class SearchModel; |
| 24 class ToolbarSearchAnimatorObserver; | 24 class ToolbarSearchAnimatorObserver; |
| 25 | 25 |
| 26 // ToolbarSearchAnimator is used to track the background state of the toolbar | 26 // ToolbarSearchAnimator is used to track the gradient background state of the |
| 27 // and related classes. To use ToolbarSearchAnimator, add a | 27 // toolbar and related classes. To use ToolbarSearchAnimator, add a |
| 28 // ToolbarSearchAnimatorObserver. The ToolbarSearchAnimatorObserver is then | 28 // ToolbarSearchAnimatorObserver. The ToolbarSearchAnimatorObserver is then |
| 29 // notified appropriately. | 29 // notified appropriately. |
| 30 class ToolbarSearchAnimator : public SearchModelObserver, | 30 class ToolbarSearchAnimator : public SearchModelObserver, |
| 31 public ui::AnimationDelegate { | 31 public ui::AnimationDelegate { |
| 32 public: | 32 public: |
| 33 // State of background to paint by observers, only applicable for | |
| 34 // |MODE_SEARCH|. | |
| 35 enum BackgroundState { | |
| 36 // Background state is not applicable. | |
| 37 BACKGROUND_STATE_DEFAULT = 0, | |
| 38 // Show background for |MODE_NTP|. | |
| 39 BACKGROUND_STATE_NTP = 0x01, | |
| 40 // Show background for |MODE_SEARCH|. | |
| 41 BACKGROUND_STATE_SEARCH = 0x02, | |
| 42 // Show backgrounds for both |MODE_NTP| and |MODE_SEARCH|. | |
| 43 BACKGROUND_STATE_NTP_SEARCH = BACKGROUND_STATE_NTP | | |
| 44 BACKGROUND_STATE_SEARCH, | |
| 45 }; | |
| 46 | |
| 47 explicit ToolbarSearchAnimator(SearchModel* search_model); | 33 explicit ToolbarSearchAnimator(SearchModel* search_model); |
| 48 virtual ~ToolbarSearchAnimator(); | 34 virtual ~ToolbarSearchAnimator(); |
| 49 | 35 |
| 50 // Get the current background state to paint. | 36 // Get the gradient background opacity to paint for toolbar and active tab, a |
| 51 // |search_background_opacity| contains a valid opacity value only if | 37 // value between 0f and 1f inclusive: |
| 52 // background for |MODE_SEARCH| needs to be shown i.e. |background_state| is | 38 // - 0f: only paint flat background |
| 53 // BACKGROUND_STATE_SEARCH or BACKGROUND_STATE_NTP_SEARCH. | 39 // - < 1f: paint flat background at full opacity and gradient background at |
| 54 // Only call this for |MODE_SEARCH|. | 40 // specified opacity |
| 55 void GetCurrentBackgroundState(BackgroundState* background_state, | 41 // - 1f: only paint gradient background at full opacity |
| 56 double* search_background_opacity) const; | 42 double GetGradientOpacity() const; |
| 57 | 43 |
| 58 // Called from SearchDelegate::StopObservingTab() when a tab is deactivated or | 44 // Called from SearchDelegate::StopObservingTab() when a tab is deactivated or |
| 59 // closing or detached, to jump to the end state of the animation. | 45 // closing or detached, to jump to the end state of the animation. |
| 60 // This allows a reactivated tab to show the end state of the animation, | 46 // This allows a reactivated tab to show the end state of the animation, |
| 61 // rather than the transient state. | 47 // rather than the transient state. |
| 62 void FinishAnimation(TabContents* tab_contents); | 48 void FinishAnimation(TabContents* tab_contents); |
| 63 | 49 |
| 64 // Add and remove observers. | 50 // Add and remove observers. |
| 65 void AddObserver(ToolbarSearchAnimatorObserver* observer); | 51 void AddObserver(ToolbarSearchAnimatorObserver* observer); |
| 66 void RemoveObserver(ToolbarSearchAnimatorObserver* observer); | 52 void RemoveObserver(ToolbarSearchAnimatorObserver* observer); |
| 67 | 53 |
| 68 // Overridden from SearchModelObserver: | 54 // Overridden from SearchModelObserver: |
| 69 virtual void ModeChanged(const Mode& mode) OVERRIDE; | 55 virtual void ModeChanged(const Mode& old_mode, const Mode& new_mode) OVERRIDE; |
| 70 | 56 |
| 71 // Overridden from ui::AnimationDelegate: | 57 // Overridden from ui::AnimationDelegate: |
| 72 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; | 58 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; |
| 73 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; | 59 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; |
| 74 | 60 |
| 75 private: | 61 private: |
| 76 // State of animation. | 62 friend class ToolbarSearchAnimatorTest; |
| 77 enum AnimateState { | 63 friend class ToolbarSearchAnimatorTestObserver; |
| 78 ANIMATE_STATE_NONE, // Doing nothing. | |
| 79 ANIMATE_STATE_WAITING, // Waiting to run background animation. | |
| 80 ANIMATE_STATE_RUNNING, // Running background animation. | |
| 81 }; | |
| 82 | 64 |
| 83 // Callback for |background_change_timer_| to actually start the background | 65 // Helper function to initialize background animation with its parts. |
| 84 // change animation. | 66 void InitBackgroundAnimation(int background_change_delay_ms, |
| 67 int background_change_duration_ms); |
| 68 |
| 69 // Helper function to start animation for gradient background change. |
| 85 void StartBackgroundChange(); | 70 void StartBackgroundChange(); |
| 86 | 71 |
| 87 // Reset state of animator: reset animate_state_, stop timer or animation, | 72 // Reset animations by stopping them. |
| 88 // If we're waiting to animate or animating, i.e. |animate_state| is not | 73 // If we're animating background or separator, we'll notify observers via |
| 89 // ANIMATE_STAET_NONE, wwe'll notify observers via | 74 // ToolbarSearchAnimatorObserver::OnToolbarBackgroundAnimatorCanceled or |
| 90 // ToolbarSearchAnimatorObserver::BackgroundChangeCanceled. | 75 // ToolbarSearchAnimatorObserver::OnToolbarSeparatorAnimatorCanceled |
| 76 // respectively. |
| 91 // Pass in |tab_contents| if animation is canceled because of deactivating or | 77 // Pass in |tab_contents| if animation is canceled because of deactivating or |
| 92 // detaching or closing a tab. | 78 // detaching or closing a tab. |
| 93 void Reset(TabContents* tab_contents); | 79 void Reset(TabContents* tab_contents); |
| 94 | 80 |
| 95 // Weak. Owned by Browser. Non-NULL. | 81 // Weak. Owned by Browser. Non-NULL. |
| 96 SearchModel* search_model_; | 82 SearchModel* search_model_; |
| 97 | 83 |
| 98 // State of animation. | 84 // The background change animation. |
| 99 AnimateState animate_state_; | 85 scoped_ptr<ui::MultiAnimation> background_animation_; |
| 100 | |
| 101 // The background fade animation. | |
| 102 scoped_ptr<ui::SlideAnimation> background_animation_; | |
| 103 | |
| 104 // The timer to delay start of animation after mode changes from |MODE_NTP| to | |
| 105 // |MODE_SEARCH|. | |
| 106 base::OneShotTimer<ToolbarSearchAnimator> background_change_timer_; | |
| 107 | 86 |
| 108 // Observers. | 87 // Observers. |
| 109 ObserverList<ToolbarSearchAnimatorObserver> observers_; | 88 ObserverList<ToolbarSearchAnimatorObserver> observers_; |
| 110 | 89 |
| 111 DISALLOW_COPY_AND_ASSIGN(ToolbarSearchAnimator); | 90 DISALLOW_COPY_AND_ASSIGN(ToolbarSearchAnimator); |
| 112 }; | 91 }; |
| 113 | 92 |
| 114 } // namespace chrome | 93 } // namespace chrome |
| 115 } // namespace search | 94 } // namespace search |
| 116 | 95 |
| 117 #endif // CHROME_BROWSER_UI_SEARCH_TOOLBAR_SEARCH_ANIMATOR_H_ | 96 #endif // CHROME_BROWSER_UI_SEARCH_TOOLBAR_SEARCH_ANIMATOR_H_ |
| OLD | NEW |