Chromium Code Reviews| Index: chrome/browser/ui/search/toolbar_search_animator.h |
| diff --git a/chrome/browser/ui/search/toolbar_search_animator.h b/chrome/browser/ui/search/toolbar_search_animator.h |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..8fc7558de104fcf3be865b6d79a7dde01352eb9c |
| --- /dev/null |
| +++ b/chrome/browser/ui/search/toolbar_search_animator.h |
| @@ -0,0 +1,122 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_UI_SEARCH_TOOLBAR_SEARCH_ANIMATOR_H_ |
| +#define CHROME_BROWSER_UI_SEARCH_TOOLBAR_SEARCH_ANIMATOR_H_ |
| +#pragma once |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/observer_list.h" |
| +#include "base/timer.h" |
| +#include "chrome/browser/ui/search/search_model_observer.h" |
| +#include "ui/base/animation/animation_delegate.h" |
| + |
| +class TabContents; |
| + |
| +namespace ui { |
| +class SlideAnimation; |
| +} // 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.
|
| + |
| +namespace chrome { |
| +namespace search { |
| + |
| +class SearchModel; |
| +class ToolbarSearchAnimatorObserver; |
| + |
| +// 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.
|
| +// This class is used in Search Integration, where backgrounds of toolbar and |
| +// tab change 100ms after search model mode changes from NTP to SEARCH. |
| +// This class runs the animation sequence and fires notification to |
| +// |ToolbarSearchAnimatorObserver|s on every tick as the animation progresses. |
| +class ToolbarSearchAnimator : public SearchModelObserver, |
| + public ui::AnimationDelegate { |
| + public: |
| + // State of background to paint by observers, only applicable when mode is |
| + // SEARCH. |
| + enum BackgroundState { |
| + // Background state is not applicable. |
| + 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.
|
| + // Show background for NTP mode. |
| + BACKGROUND_STATE_SHOW_NTP = 0x01, |
| + // Show background for SEARCH mode. |
| + BACKGROUND_STATE_SHOW_SEARCH = 0x02, |
| + // Show backgrounds for both NTP and SEARCH modes. |
| + BACKGROUND_STATE_SHOW_NTP_SEARCH = BACKGROUND_STATE_SHOW_NTP | |
| + BACKGROUND_STATE_SHOW_SEARCH, |
| + }; |
| + |
| + explicit ToolbarSearchAnimator(SearchModel* search_model); |
| + virtual ~ToolbarSearchAnimator(); |
| + |
| + // Get the current background state to paint. |
| + // |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
|
| + // background needs to be shown i.e. |background_state| is |
| + // 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
|
| + // Note "background animation not running" doesn't mean we're not waiting to |
| + // run the background animation. Because background animation runs after a |
| + // delay of 100ms, IsWaitingToAnimate provides state about "waiting to run" |
| + // and hence should be called before this method - DCHECK happens if this |
| + // method is called when waiting to run background animation. |
| + void GetCurrentBackgroundState(BackgroundState* background_state, |
| + 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.
|
| + |
| + // 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.
|
| + // closing or detached, to jump to the end state of the animation. |
| + // This allows a reactivated tab to show the end state of the animation, |
| + // rather than the transient state. |
| + void FinishAnimation(TabContents* tab_contents); |
| + |
| + // Add and remove observers. |
| + void AddObserver(ToolbarSearchAnimatorObserver* observer); |
| + void RemoveObserver(ToolbarSearchAnimatorObserver* observer); |
| + |
| + // Overridden from SearchModelObserver: |
| + virtual void ModeChanged(const Mode& mode) OVERRIDE; |
| + |
| + // Overridden from ui::AnimationDelegate: |
| + virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; |
| + virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; |
| + |
| + private: |
| + // State of animation. |
| + enum AnimateState { |
| + ANIMATE_STATE_NONE, // Doing nothing. |
| + ANIMATE_STATE_WAITING, // Waiting to run background animation. |
| + ANIMATE_STATE_RUNNING, // Running background animation. |
| + }; |
| + |
| + // Callback for |background_change_timer_| to actually start the background |
| + // change animation. |
| + void StartBackgroundChange(); |
| + |
| + // Reset state of animator: reset animate_state_, stop timer or animation, |
| + // Set |notify_observers| to true to notify observers via |
| + // ToolbarSearchAnimatorObserver::BackgroundChangeCanceled. |
| + // Pass in |tab_contents| if animation is canceled because of deactivating or |
| + // detaching or closing a tab. |
| + void Reset(bool notify_observers, TabContents* tab_contents); |
| + |
| + // 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.
|
| + SearchModel* search_model_; |
| + |
| + // State of animation. |
| + AnimateState animate_state_; |
| + |
| + // The background fade animation. |
| + scoped_ptr<ui::SlideAnimation> background_animation_; |
| + |
| + // 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.
|
| + // SEARCH. |
| + base::OneShotTimer<ToolbarSearchAnimator> background_change_timer_; |
| + |
| + // Observers. |
| + ObserverList<ToolbarSearchAnimatorObserver> observers_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ToolbarSearchAnimator); |
| +}; |
| + |
| +} // namespace chrome |
| +} // namespace search |
| + |
| +#endif // CHROME_BROWSER_UI_SEARCH_TOOLBAR_SEARCH_ANIMATOR_H_ |