OLD | NEW |
(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 // |search_background_opacity| contains a valid opacity value only if |
| 53 // background for |MODE_SEARCH| 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* search_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 // If we're waiting to animate or animating, i.e. |animate_state| is not |
| 90 // ANIMATE_STAET_NONE, wwe'll notify observers via |
| 91 // ToolbarSearchAnimatorObserver::BackgroundChangeCanceled. |
| 92 // Pass in |tab_contents| if animation is canceled because of deactivating or |
| 93 // detaching or closing a tab. |
| 94 void Reset(TabContents* tab_contents); |
| 95 |
| 96 // Weak. Owned by Browser. Non-NULL. |
| 97 SearchModel* search_model_; |
| 98 |
| 99 // State of animation. |
| 100 AnimateState animate_state_; |
| 101 |
| 102 // The background fade animation. |
| 103 scoped_ptr<ui::SlideAnimation> background_animation_; |
| 104 |
| 105 // The timer to delay start of animation after mode changes from |MODE_NTP| to |
| 106 // |MODE_SEARCH|. |
| 107 base::OneShotTimer<ToolbarSearchAnimator> background_change_timer_; |
| 108 |
| 109 // Observers. |
| 110 ObserverList<ToolbarSearchAnimatorObserver> observers_; |
| 111 |
| 112 DISALLOW_COPY_AND_ASSIGN(ToolbarSearchAnimator); |
| 113 }; |
| 114 |
| 115 } // namespace chrome |
| 116 } // namespace search |
| 117 |
| 118 #endif // CHROME_BROWSER_UI_SEARCH_TOOLBAR_SEARCH_ANIMATOR_H_ |
OLD | NEW |