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

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

Powered by Google App Engine
This is Rietveld 408576698