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" |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 | 13 |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "chrome/browser/api/infobars/infobar_delegate.h" | 15 #include "chrome/browser/api/infobars/infobar_delegate.h" |
16 #include "chrome/browser/api/infobars/infobar_service.h" | 16 #include "chrome/browser/api/infobars/infobar_service.h" |
17 #include "chrome/browser/infobars/infobar.h" | 17 #include "chrome/browser/infobars/infobar.h" |
| 18 #include "chrome/browser/instant/instant_model.h" |
18 #include "chrome/browser/ui/search/search_model.h" | 19 #include "chrome/browser/ui/search/search_model.h" |
19 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
20 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
21 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
22 #include "ui/base/animation/slide_animation.h" | 23 #include "ui/base/animation/slide_animation.h" |
23 | 24 |
24 InfoBarContainer::Delegate::~Delegate() { | 25 InfoBarContainer::Delegate::~Delegate() { |
25 } | 26 } |
26 | 27 |
27 InfoBarContainer::InfoBarContainer( | 28 InfoBarContainer::InfoBarContainer( |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 default: | 158 default: |
158 NOTREACHED(); | 159 NOTREACHED(); |
159 break; | 160 break; |
160 } | 161 } |
161 } | 162 } |
162 | 163 |
163 void InfoBarContainer::ModeChanged(const chrome::search::Mode& old_mode, | 164 void InfoBarContainer::ModeChanged(const chrome::search::Mode& old_mode, |
164 const chrome::search::Mode& new_mode) { | 165 const chrome::search::Mode& new_mode) { |
165 // Hide infobars when showing Instant Extended suggestions. | 166 // Hide infobars when showing Instant Extended suggestions. |
166 if (new_mode.is_search_suggestions()) { | 167 if (new_mode.is_search_suggestions()) { |
| 168 // If suggestions are being shown on a |DEFAULT| page, delay the hiding |
| 169 // until notification that instant preview is ready is received via |
| 170 // PreviewStateChanged(); this prevents jankiness caused by infobars hiding |
| 171 // followed by suggestions appearing. |
| 172 if (new_mode.is_origin_default()) |
| 173 return; |
167 HideAllInfoBars(); | 174 HideAllInfoBars(); |
168 OnInfoBarStateChanged(false); | 175 OnInfoBarStateChanged(false); |
169 } else { | 176 } else { |
170 ChangeInfoBarService(infobar_service_); | 177 ChangeInfoBarService(infobar_service_); |
171 infobars_shown_time_ = base::TimeTicks::Now(); | 178 infobars_shown_time_ = base::TimeTicks::Now(); |
172 } | 179 } |
173 } | 180 } |
174 | 181 |
| 182 void InfoBarContainer::PreviewStateChanged(const InstantModel& model) { |
| 183 // If suggestions are being shown on a |DEFAULT| page, hide the infobars now. |
| 184 // See comments for ModeChanged() for explanation. |
| 185 if (model.mode().is_search_suggestions() && |
| 186 model.mode().is_origin_default()) { |
| 187 HideAllInfoBars(); |
| 188 OnInfoBarStateChanged(false); |
| 189 } |
| 190 } |
| 191 |
175 size_t InfoBarContainer::HideInfoBar(InfoBarDelegate* delegate, | 192 size_t InfoBarContainer::HideInfoBar(InfoBarDelegate* delegate, |
176 bool use_animation) { | 193 bool use_animation) { |
177 bool should_animate = use_animation && | 194 bool should_animate = use_animation && |
178 ((base::TimeTicks::Now() - infobars_shown_time_) > | 195 ((base::TimeTicks::Now() - infobars_shown_time_) > |
179 base::TimeDelta::FromMilliseconds(50)); | 196 base::TimeDelta::FromMilliseconds(50)); |
180 | 197 |
181 // Search for the infobar associated with |delegate|. We cannot search for | 198 // Search for the infobar associated with |delegate|. We cannot search for |
182 // |delegate| in |tab_helper_|, because an InfoBar remains alive until its | 199 // |delegate| in |tab_helper_|, because an InfoBar remains alive until its |
183 // close animation completes, while the delegate is removed from the tab | 200 // close animation completes, while the delegate is removed from the tab |
184 // immediately. | 201 // immediately. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 return InfoBar::kDefaultArrowTargetHeight; | 257 return InfoBar::kDefaultArrowTargetHeight; |
241 // When the first infobar is animating closed, we animate the second infobar's | 258 // When the first infobar is animating closed, we animate the second infobar's |
242 // arrow target height from the default to the top target height. Note that | 259 // arrow target height from the default to the top target height. Note that |
243 // the animation values here are going from 1.0 -> 0.0 as the top bar closes. | 260 // the animation values here are going from 1.0 -> 0.0 as the top bar closes. |
244 return top_arrow_target_height_ + static_cast<int>( | 261 return top_arrow_target_height_ + static_cast<int>( |
245 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) * | 262 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) * |
246 first_infobar_animation.GetCurrentValue()); | 263 first_infobar_animation.GetCurrentValue()); |
247 } | 264 } |
248 | 265 |
249 #endif // TOOLKIT_VIEWS || defined(TOOLKIT_GTK) | 266 #endif // TOOLKIT_VIEWS || defined(TOOLKIT_GTK) |
OLD | NEW |