Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Side by Side Diff: chrome/browser/ui/search/toolbar_search_animator.h

Issue 10816027: alternate ntp: toolbar background and separator animation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix android build break Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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();
67
68 // Helper function to start animation for gradient background change.
85 void StartBackgroundChange(); 69 void StartBackgroundChange();
86 70
87 // Reset state of animator: reset animate_state_, stop timer or animation, 71 // Reset animations by stopping them.
88 // If we're waiting to animate or animating, i.e. |animate_state| is not 72 // If we're animating background or separator, we'll notify observers via
89 // ANIMATE_STAET_NONE, wwe'll notify observers via 73 // ToolbarSearchAnimatorObserver::OnToolbarBackgroundAnimatorCanceled or
90 // ToolbarSearchAnimatorObserver::BackgroundChangeCanceled. 74 // ToolbarSearchAnimatorObserver::OnToolbarSeparatorAnimatorCanceled
75 // respectively.
91 // Pass in |tab_contents| if animation is canceled because of deactivating or 76 // Pass in |tab_contents| if animation is canceled because of deactivating or
92 // detaching or closing a tab. 77 // detaching or closing a tab.
93 void Reset(TabContents* tab_contents); 78 void Reset(TabContents* tab_contents);
94 79
95 // Weak. Owned by Browser. Non-NULL. 80 // Weak. Owned by Browser. Non-NULL.
96 SearchModel* search_model_; 81 SearchModel* search_model_;
97 82
98 // State of animation. 83 // The background change animation.
99 AnimateState animate_state_; 84 scoped_ptr<ui::MultiAnimation> background_animation_;
100 85
101 // The background fade animation. 86 // Time (in ms) of background animation delay and duration.
102 scoped_ptr<ui::SlideAnimation> background_animation_; 87 int background_change_delay_ms_;
103 88 int background_change_duration_ms_;
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 89
108 // Observers. 90 // Observers.
109 ObserverList<ToolbarSearchAnimatorObserver> observers_; 91 ObserverList<ToolbarSearchAnimatorObserver> observers_;
110 92
111 DISALLOW_COPY_AND_ASSIGN(ToolbarSearchAnimator); 93 DISALLOW_COPY_AND_ASSIGN(ToolbarSearchAnimator);
112 }; 94 };
113 95
114 } // namespace chrome 96 } // namespace chrome
115 } // namespace search 97 } // namespace search
116 98
117 #endif // CHROME_BROWSER_UI_SEARCH_TOOLBAR_SEARCH_ANIMATOR_H_ 99 #endif // CHROME_BROWSER_UI_SEARCH_TOOLBAR_SEARCH_ANIMATOR_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_tab_helper.cc ('k') | chrome/browser/ui/search/toolbar_search_animator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698