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

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

Issue 10662032: alternate ntp (cros/partial-win): add tab-related stuff and toolbar/tab background change (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed scott's comments, fixed bookmark background and moved frame code, fixed unittests build b… Created 8 years, 5 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_UI_SEARCH_TOOLBAR_SEARCH_ANIMATOR_H_
6 #define CHROME_BROWSER_UI_SEARCH_TOOLBAR_SEARCH_ANIMATOR_H_
7 #pragma once
8
9 #include "base/memory/scoped_ptr.h"
10 #include "base/observer_list.h"
11 #include "base/timer.h"
12 #include "chrome/browser/ui/search/search_model_observer.h"
13 #include "ui/base/animation/animation_delegate.h"
14
15 class TabContents;
16
17 namespace ui {
18 class SlideAnimation;
19 }
20
21 namespace chrome {
22 namespace search {
23
24 class SearchModel;
25 class ToolbarSearchAnimatorObserver;
26
27 // ToolbarSearchAnimator is used to track the background state of the toolbar
28 // and related classes. To use ToolbarSearchAnimator, add a
29 // ToolbarSearchAnimatorObserver. The ToolbarSearchAnimatorObserver is then
30 // notified appropriately.
31 class ToolbarSearchAnimator : public SearchModelObserver,
32 public ui::AnimationDelegate {
33 public:
34 // State of background to paint by observers, only applicable for
35 // |MODE_SEARCH|.
36 enum BackgroundState {
37 // Background state is not applicable.
38 BACKGROUND_STATE_DEFAULT = 0,
39 // Show background for |MODE_NTP|.
40 BACKGROUND_STATE_NTP = 0x01,
41 // Show background for |MODE_SEARCH|.
42 BACKGROUND_STATE_SEARCH = 0x02,
43 // Show backgrounds for both |MODE_NTP| and |MODE_SEARCH|.
44 BACKGROUND_STATE_NTP_SEARCH = BACKGROUND_STATE_NTP |
45 BACKGROUND_STATE_SEARCH,
46 };
47
48 explicit ToolbarSearchAnimator(SearchModel* search_model);
49 virtual ~ToolbarSearchAnimator();
50
51 // Get the current background state to paint.
52 // |new_background_opacity| contains a valid opacity value only if new
53 // background needs to be shown i.e. |background_state| is
54 // BACKGROUND_STATE_SEARCH or BACKGROUND_STATE_NTP_SEARCH.
55 // Only call this for |MODE_SEARCH|.
56 void GetCurrentBackgroundState(BackgroundState* background_state,
57 double* new_background_opacity) const;
58
59 // Called from SearchDelegate::StopObservingTab() when a tab is deactivated or
60 // closing or detached, to jump to the end state of the animation.
61 // This allows a reactivated tab to show the end state of the animation,
62 // rather than the transient state.
63 void FinishAnimation(TabContents* tab_contents);
64
65 // Add and remove observers.
66 void AddObserver(ToolbarSearchAnimatorObserver* observer);
67 void RemoveObserver(ToolbarSearchAnimatorObserver* observer);
68
69 // Overridden from SearchModelObserver:
70 virtual void ModeChanged(const Mode& mode) OVERRIDE;
71
72 // Overridden from ui::AnimationDelegate:
73 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
74 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE;
75
76 private:
77 // State of animation.
78 enum AnimateState {
79 ANIMATE_STATE_NONE, // Doing nothing.
80 ANIMATE_STATE_WAITING, // Waiting to run background animation.
81 ANIMATE_STATE_RUNNING, // Running background animation.
82 };
83
84 // Callback for |background_change_timer_| to actually start the background
85 // change animation.
86 void StartBackgroundChange();
87
88 // Reset state of animator: reset animate_state_, stop timer or animation,
89 // Set |notify_observers| to true to notify observers via
90 // ToolbarSearchAnimatorObserver::BackgroundChangeCanceled.
91 // Pass in |tab_contents| if animation is canceled because of deactivating or
92 // detaching or closing a tab.
93 void Reset(bool notify_observers, TabContents* tab_contents);
94
95 // Weak. Owned by Browser. Non-NULL.
96 SearchModel* search_model_;
97
98 // State of animation.
99 AnimateState animate_state_;
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
108 // Observers.
109 ObserverList<ToolbarSearchAnimatorObserver> observers_;
110
111 DISALLOW_COPY_AND_ASSIGN(ToolbarSearchAnimator);
112 };
113
114 } // namespace chrome
115 } // namespace search
116
117 #endif // CHROME_BROWSER_UI_SEARCH_TOOLBAR_SEARCH_ANIMATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698