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