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

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: removed images from cl 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 } // namespace ui
dhollowa 2012/06/26 18:16:27 nit: Typically the trailing "// namespace ui" is o
kuan 2012/06/26 23:25:49 Done.
20
21 namespace chrome {
22 namespace search {
23
24 class SearchModel;
25 class ToolbarSearchAnimatorObserver;
26
27 // Animate fade in of new background.
sky 2012/06/26 17:11:27 Remove this sentence. Also, how about a descriptio
kuan 2012/06/26 23:25:49 Done.
28 // This class is used in Search Integration, where backgrounds of toolbar and
29 // tab change 100ms after search model mode changes from NTP to SEARCH.
30 // This class runs the animation sequence and fires notification to
31 // |ToolbarSearchAnimatorObserver|s on every tick as the animation progresses.
32 class ToolbarSearchAnimator : public SearchModelObserver,
33 public ui::AnimationDelegate {
34 public:
35 // State of background to paint by observers, only applicable when mode is
36 // SEARCH.
37 enum BackgroundState {
38 // Background state is not applicable.
39 BACKGROUND_STATE_SHOW_NON_APPLICABLE = 0,
sky 2012/06/26 17:11:27 Should this be BACKGROUND_STATE_SHOW_DEFAULT? Also
kuan 2012/06/26 23:25:49 Done.
40 // Show background for NTP mode.
41 BACKGROUND_STATE_SHOW_NTP = 0x01,
42 // Show background for SEARCH mode.
43 BACKGROUND_STATE_SHOW_SEARCH = 0x02,
44 // Show backgrounds for both NTP and SEARCH modes.
45 BACKGROUND_STATE_SHOW_NTP_SEARCH = BACKGROUND_STATE_SHOW_NTP |
46 BACKGROUND_STATE_SHOW_SEARCH,
47 };
48
49 explicit ToolbarSearchAnimator(SearchModel* search_model);
50 virtual ~ToolbarSearchAnimator();
51
52 // Get the current background state to paint.
53 // |new_background_opacity| contains a valid opacity value only if new
sky 2012/06/26 17:11:27 Should the opacity always be 1 when not default?
kuan 2012/06/26 23:25:49 the opacity is for the new background, so it shoul
54 // background needs to be shown i.e. |background_state| is
55 // BACKGROUND_STATE_SHOW_NEW or BACKGROUND_STATE_SHOW_BOTH.
sky 2012/06/26 17:11:27 This comment isn't right, it can also by NON_APPLI
kuan 2012/06/26 23:25:49 Done. i assume u mean the names of the states are
56 // Note "background animation not running" doesn't mean we're not waiting to
57 // run the background animation. Because background animation runs after a
58 // delay of 100ms, IsWaitingToAnimate provides state about "waiting to run"
59 // and hence should be called before this method - DCHECK happens if this
60 // method is called when waiting to run background animation.
61 void GetCurrentBackgroundState(BackgroundState* background_state,
62 int* new_background_opacity) const;
sky 2012/06/26 17:11:27 I think it makes more sense to have opacity from 0
kuan 2012/06/26 23:25:49 Done.
63
64 // Called from SearchDelegate::StopObservingTab when a tab is deactivated or
sky 2012/06/26 17:11:27 nit: use () after method in comments.
kuan 2012/06/26 23:25:49 Done.
65 // closing or detached, to jump to the end state of the animation.
66 // This allows a reactivated tab to show the end state of the animation,
67 // rather than the transient state.
68 void FinishAnimation(TabContents* tab_contents);
69
70 // Add and remove observers.
71 void AddObserver(ToolbarSearchAnimatorObserver* observer);
72 void RemoveObserver(ToolbarSearchAnimatorObserver* observer);
73
74 // Overridden from SearchModelObserver:
75 virtual void ModeChanged(const Mode& mode) OVERRIDE;
76
77 // Overridden from ui::AnimationDelegate:
78 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
79 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE;
80
81 private:
82 // State of animation.
83 enum AnimateState {
84 ANIMATE_STATE_NONE, // Doing nothing.
85 ANIMATE_STATE_WAITING, // Waiting to run background animation.
86 ANIMATE_STATE_RUNNING, // Running background animation.
87 };
88
89 // Callback for |background_change_timer_| to actually start the background
90 // change animation.
91 void StartBackgroundChange();
92
93 // Reset state of animator: reset animate_state_, stop timer or animation,
94 // Set |notify_observers| to true to notify observers via
95 // ToolbarSearchAnimatorObserver::BackgroundChangeCanceled.
96 // Pass in |tab_contents| if animation is canceled because of deactivating or
97 // detaching or closing a tab.
98 void Reset(bool notify_observers, TabContents* tab_contents);
99
100 // Caches the search model from browser.
dhollowa 2012/06/26 18:16:27 // Weak. Owned by Browser. Non-null.
kuan 2012/06/26 23:25:49 Done.
101 SearchModel* search_model_;
102
103 // State of animation.
104 AnimateState animate_state_;
105
106 // The background fade animation.
107 scoped_ptr<ui::SlideAnimation> background_animation_;
108
109 // The timer to delay start of animation after mode changes from NTP to
dhollowa 2012/06/26 18:16:27 ...from |MODE_NTP| to |MODE_SEARCH|.
kuan 2012/06/26 23:25:49 Done. also changed for all comments in this file.
110 // SEARCH.
111 base::OneShotTimer<ToolbarSearchAnimator> background_change_timer_;
112
113 // Observers.
114 ObserverList<ToolbarSearchAnimatorObserver> observers_;
115
116 DISALLOW_COPY_AND_ASSIGN(ToolbarSearchAnimator);
117 };
118
119 } // namespace chrome
120 } // namespace search
121
122 #endif // CHROME_BROWSER_UI_SEARCH_TOOLBAR_SEARCH_ANIMATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698