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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 // TODO(pkasting): Port Mac to use this. | 7 // TODO(pkasting): Port Mac to use this. |
8 #if defined(TOOLKIT_VIEWS) || defined(TOOLKIT_GTK) | 8 #if defined(TOOLKIT_VIEWS) || defined(TOOLKIT_GTK) |
9 | 9 |
10 #include "chrome/browser/infobars/infobar_container.h" | 10 #include "chrome/browser/infobars/infobar_container.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 // RemoveAllInfoBarsForDestruction() should have already cleared our infobars. | 41 // RemoveAllInfoBarsForDestruction() should have already cleared our infobars. |
42 DCHECK(infobars_.empty()); | 42 DCHECK(infobars_.empty()); |
43 if (search_model_) | 43 if (search_model_) |
44 search_model_->RemoveObserver(this); | 44 search_model_->RemoveObserver(this); |
45 } | 45 } |
46 | 46 |
47 void InfoBarContainer::ChangeInfoBarService(InfoBarService* infobar_service) { | 47 void InfoBarContainer::ChangeInfoBarService(InfoBarService* infobar_service) { |
48 registrar_.RemoveAll(); | 48 registrar_.RemoveAll(); |
49 | 49 |
50 // Note that HideAllInfoBars() sets |infobars_shown_| to false, because that's | 50 // Note that HideAllInfoBars() sets |infobars_shown_| to false, because that's |
51 // what the other, instant-related callers want; but here we actually | 51 // what the other, Instant-related callers want; but here we actually |
52 // explicitly want to reset this variable to true. So do that after calling | 52 // explicitly want to reset this variable to true. So do that after calling |
53 // the function. | 53 // the function. |
54 HideAllInfoBars(); | 54 HideAllInfoBars(); |
55 infobars_shown_ = true; | 55 infobars_shown_ = true; |
56 infobars_shown_time_ = base::TimeTicks(); | 56 infobars_shown_time_ = base::TimeTicks(); |
57 | 57 |
58 infobar_service_ = infobar_service; | 58 infobar_service_ = infobar_service; |
59 if (infobar_service_) { | 59 if (infobar_service_) { |
60 content::Source<InfoBarService> source(infobar_service_); | 60 content::Source<InfoBarService> source(infobar_service_); |
61 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | 61 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 NOTREACHED(); | 172 NOTREACHED(); |
173 break; | 173 break; |
174 } | 174 } |
175 } | 175 } |
176 | 176 |
177 void InfoBarContainer::ModeChanged(const chrome::search::Mode& old_mode, | 177 void InfoBarContainer::ModeChanged(const chrome::search::Mode& old_mode, |
178 const chrome::search::Mode& new_mode) { | 178 const chrome::search::Mode& new_mode) { |
179 // Hide infobars when showing Instant Extended suggestions. | 179 // Hide infobars when showing Instant Extended suggestions. |
180 if (new_mode.is_search_suggestions()) { | 180 if (new_mode.is_search_suggestions()) { |
181 // If suggestions are being shown on a |DEFAULT| page, delay the hiding | 181 // If suggestions are being shown on a |DEFAULT| page, delay the hiding |
182 // until notification that instant preview is ready is received via | 182 // until notification that Instant overlay is ready is received via |
183 // PreviewStateChanged(); this prevents jankiness caused by infobars hiding | 183 // OverlayStateChanged(); this prevents jankiness caused by infobars hiding |
184 // followed by suggestions appearing. | 184 // followed by suggestions appearing. |
185 if (new_mode.is_origin_default()) | 185 if (new_mode.is_origin_default()) |
186 return; | 186 return; |
187 HideAllInfoBars(); | 187 HideAllInfoBars(); |
188 OnInfoBarStateChanged(false); | 188 OnInfoBarStateChanged(false); |
189 } else { | 189 } else { |
190 ChangeInfoBarService(infobar_service_); | 190 ChangeInfoBarService(infobar_service_); |
191 infobars_shown_time_ = base::TimeTicks::Now(); | 191 infobars_shown_time_ = base::TimeTicks::Now(); |
192 } | 192 } |
193 } | 193 } |
194 | 194 |
195 void InfoBarContainer::PreviewStateChanged(const InstantModel& model) { | 195 void InfoBarContainer::OverlayStateChanged(const InstantModel& model) { |
196 // If suggestions are being shown on a |DEFAULT| page, hide the infobars now. | 196 // Suggestions are being shown on a |DEFAULT| page. Hide the infobars now. |
197 // See comments for ModeChanged() for explanation. | 197 // See comments for ModeChanged() for explanation. |
198 if (model.mode().is_search_suggestions() && | 198 if (model.overlay()) { |
199 model.mode().is_origin_default()) { | |
200 HideAllInfoBars(); | 199 HideAllInfoBars(); |
201 OnInfoBarStateChanged(false); | 200 OnInfoBarStateChanged(false); |
202 } | 201 } |
203 } | 202 } |
204 | 203 |
205 size_t InfoBarContainer::HideInfoBar(InfoBarDelegate* delegate, | 204 size_t InfoBarContainer::HideInfoBar(InfoBarDelegate* delegate, |
206 bool use_animation) { | 205 bool use_animation) { |
207 bool should_animate = use_animation && | 206 bool should_animate = use_animation && |
208 ((base::TimeTicks::Now() - infobars_shown_time_) > | 207 ((base::TimeTicks::Now() - infobars_shown_time_) > |
209 base::TimeDelta::FromMilliseconds(50)); | 208 base::TimeDelta::FromMilliseconds(50)); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 return InfoBar::kDefaultArrowTargetHeight; | 270 return InfoBar::kDefaultArrowTargetHeight; |
272 // When the first infobar is animating closed, we animate the second infobar's | 271 // When the first infobar is animating closed, we animate the second infobar's |
273 // arrow target height from the default to the top target height. Note that | 272 // arrow target height from the default to the top target height. Note that |
274 // the animation values here are going from 1.0 -> 0.0 as the top bar closes. | 273 // the animation values here are going from 1.0 -> 0.0 as the top bar closes. |
275 return top_arrow_target_height_ + static_cast<int>( | 274 return top_arrow_target_height_ + static_cast<int>( |
276 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) * | 275 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) * |
277 first_infobar_animation.GetCurrentValue()); | 276 first_infobar_animation.GetCurrentValue()); |
278 } | 277 } |
279 | 278 |
280 #endif // TOOLKIT_VIEWS || defined(TOOLKIT_GTK) | 279 #endif // TOOLKIT_VIEWS || defined(TOOLKIT_GTK) |
OLD | NEW |