OLD | NEW |
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 #include "chrome/browser/ui/search/toolbar_search_animator.h" | 5 #include "chrome/browser/ui/search/toolbar_search_animator.h" |
6 | 6 |
7 #include "chrome/browser/ui/search/search_model.h" | 7 #include "chrome/browser/ui/search/search_model.h" |
8 #include "chrome/browser/ui/search/search_types.h" | 8 #include "chrome/browser/ui/search/search_types.h" |
9 #include "chrome/browser/ui/search/toolbar_search_animator_observer.h" | 9 #include "chrome/browser/ui/search/toolbar_search_animator_observer.h" |
10 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 10 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 11 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
11 #include "chrome/browser/ui/webui/instant_ui.h" | 12 #include "chrome/browser/ui/webui/instant_ui.h" |
12 #include "ui/base/animation/multi_animation.h" | 13 #include "ui/base/animation/multi_animation.h" |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 const int kBackgroundChangeDelayMs = 100; | 17 const int kBackgroundChangeDelayMs = 100; |
17 const int kBackgroundChangeDurationMs = 200; | 18 const int kBackgroundChangeDurationMs = 200; |
18 | 19 |
19 const double kMinOpacity = 0.0f; | 20 const double kMinOpacity = 0.0f; |
20 const double kMaxOpacity = 1.0f; | 21 const double kMaxOpacity = 1.0f; |
21 | 22 |
22 } // namespace | 23 } // namespace |
23 | 24 |
24 namespace chrome { | 25 namespace chrome { |
25 namespace search { | 26 namespace search { |
26 | 27 |
27 ToolbarSearchAnimator::ToolbarSearchAnimator(SearchModel* search_model) | 28 ToolbarSearchAnimator::ToolbarSearchAnimator(SearchModel* search_model, |
| 29 ToolbarModel* toolbar_model) |
28 : search_model_(search_model), | 30 : search_model_(search_model), |
| 31 toolbar_model_(toolbar_model), |
29 background_change_delay_ms_(kBackgroundChangeDelayMs), | 32 background_change_delay_ms_(kBackgroundChangeDelayMs), |
30 background_change_duration_ms_(kBackgroundChangeDurationMs), | 33 background_change_duration_ms_(kBackgroundChangeDurationMs), |
31 is_omnibox_popup_open_(false) { | 34 is_omnibox_popup_open_(false) { |
32 search_model_->AddObserver(this); | 35 search_model_->AddObserver(this); |
33 } | 36 } |
34 | 37 |
35 ToolbarSearchAnimator::~ToolbarSearchAnimator() { | 38 ToolbarSearchAnimator::~ToolbarSearchAnimator() { |
36 if (background_animation_.get()) | 39 if (background_animation_.get()) |
37 background_animation_->Stop(); | 40 background_animation_->Stop(); |
38 search_model_->RemoveObserver(this); | 41 search_model_->RemoveObserver(this); |
39 } | 42 } |
40 | 43 |
41 double ToolbarSearchAnimator::GetGradientOpacity() const { | 44 double ToolbarSearchAnimator::GetGradientOpacity() const { |
42 if (background_animation_.get() && background_animation_->is_animating()) | 45 if (background_animation_.get() && background_animation_->is_animating()) |
43 return background_animation_->CurrentValueBetween(kMinOpacity, kMaxOpacity); | 46 return background_animation_->CurrentValueBetween(kMinOpacity, kMaxOpacity); |
44 return search_model_->mode().is_ntp() ? kMinOpacity : kMaxOpacity; | 47 return search_model_->mode().is_ntp() ? kMinOpacity : kMaxOpacity; |
45 } | 48 } |
46 | 49 |
47 bool ToolbarSearchAnimator::IsToolbarSeparatorVisible() const { | 50 bool ToolbarSearchAnimator::IsToolbarSeparatorVisible() const { |
48 // The toolbar separator is only visible in 2 scenarios: | 51 // The toolbar separator is only visible in 2 scenarios: |
49 // 1) when mode is |SEARCH_SUGGESTIONS| and the omnibox popup has finished | 52 // 1) when mode is |SEARCH_SUGGESTIONS|, user input is not in progress, and |
50 // retracting before the navigation URL was committed, i.e. before the | 53 // the omnibox popup has finished retracting before the navigation URL was |
51 // mode was changed to |DEFAULT|. | 54 // committed, i.e. before the mode was changed to |DEFAULT|. |
52 // 2) when mode is |DEFAULT| and the omnibox popup has finished retracting. | 55 // 2) when mode is |DEFAULT| and the omnibox popup has finished retracting. |
53 return !is_omnibox_popup_open_ && | 56 return !is_omnibox_popup_open_ && |
54 (search_model_->mode().mode == Mode::MODE_SEARCH_SUGGESTIONS || | 57 ((search_model_->mode().mode == Mode::MODE_SEARCH_SUGGESTIONS && |
| 58 !toolbar_model_->input_in_progress()) || |
55 search_model_->mode().is_default()); | 59 search_model_->mode().is_default()); |
56 } | 60 } |
57 | 61 |
58 void ToolbarSearchAnimator::OnOmniboxPopupClosed() { | 62 void ToolbarSearchAnimator::OnOmniboxPopupClosed() { |
59 is_omnibox_popup_open_ = false; | 63 is_omnibox_popup_open_ = false; |
60 FOR_EACH_OBSERVER(ToolbarSearchAnimatorObserver, observers_, | 64 FOR_EACH_OBSERVER(ToolbarSearchAnimatorObserver, observers_, |
61 OnToolbarSeparatorChanged()); | 65 OnToolbarSeparatorChanged()); |
62 } | 66 } |
63 | 67 |
64 void ToolbarSearchAnimator::FinishAnimation(TabContents* tab_contents) { | 68 void ToolbarSearchAnimator::FinishAnimation(TabContents* tab_contents) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 154 |
151 // Notify observers of animation cancelation. | 155 // Notify observers of animation cancelation. |
152 if (notify_background_observers) { | 156 if (notify_background_observers) { |
153 FOR_EACH_OBSERVER(ToolbarSearchAnimatorObserver, observers_, | 157 FOR_EACH_OBSERVER(ToolbarSearchAnimatorObserver, observers_, |
154 OnToolbarBackgroundAnimatorCanceled(tab_contents)); | 158 OnToolbarBackgroundAnimatorCanceled(tab_contents)); |
155 } | 159 } |
156 } | 160 } |
157 | 161 |
158 } // namespace search | 162 } // namespace search |
159 } // namespace chrome | 163 } // namespace chrome |
OLD | NEW |