| 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( |
| 28 Delegate* delegate, | 29 Delegate* delegate, |
| 29 chrome::search::SearchModel* search_model) | 30 chrome::search::SearchModel* search_model, |
| 31 const InstantModel* instant_model) |
| 30 : delegate_(delegate), | 32 : delegate_(delegate), |
| 31 infobar_service_(NULL), | 33 infobar_service_(NULL), |
| 32 search_model_(search_model), | 34 search_model_(search_model), |
| 35 instant_model_(instant_model), |
| 33 top_arrow_target_height_(InfoBar::kDefaultArrowTargetHeight) { | 36 top_arrow_target_height_(InfoBar::kDefaultArrowTargetHeight) { |
| 34 if (search_model_) | 37 if (search_model_) |
| 35 search_model_->AddObserver(this); | 38 search_model_->AddObserver(this); |
| 39 if (instant_model_) |
| 40 instant_model_->AddObserver(this); |
| 36 } | 41 } |
| 37 | 42 |
| 38 InfoBarContainer::~InfoBarContainer() { | 43 InfoBarContainer::~InfoBarContainer() { |
| 39 // RemoveAllInfoBarsForDestruction() should have already cleared our infobars. | 44 // RemoveAllInfoBarsForDestruction() should have already cleared our infobars. |
| 40 DCHECK(infobars_.empty()); | 45 DCHECK(infobars_.empty()); |
| 41 if (search_model_) | 46 if (search_model_) |
| 42 search_model_->RemoveObserver(this); | 47 search_model_->RemoveObserver(this); |
| 48 if (instant_model_) |
| 49 instant_model_->RemoveObserver(this); |
| 43 } | 50 } |
| 44 | 51 |
| 45 void InfoBarContainer::ChangeInfoBarService(InfoBarService* infobar_service) { | 52 void InfoBarContainer::ChangeInfoBarService(InfoBarService* infobar_service) { |
| 46 registrar_.RemoveAll(); | 53 registrar_.RemoveAll(); |
| 47 | 54 |
| 48 infobars_shown_time_ = base::TimeTicks(); | 55 infobars_shown_time_ = base::TimeTicks(); |
| 49 HideAllInfoBars(); | 56 HideAllInfoBars(); |
| 50 | 57 |
| 51 infobar_service_ = infobar_service; | 58 infobar_service_ = infobar_service; |
| 52 if (infobar_service_) { | 59 if (infobar_service_) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 default: | 164 default: |
| 158 NOTREACHED(); | 165 NOTREACHED(); |
| 159 break; | 166 break; |
| 160 } | 167 } |
| 161 } | 168 } |
| 162 | 169 |
| 163 void InfoBarContainer::ModeChanged(const chrome::search::Mode& old_mode, | 170 void InfoBarContainer::ModeChanged(const chrome::search::Mode& old_mode, |
| 164 const chrome::search::Mode& new_mode) { | 171 const chrome::search::Mode& new_mode) { |
| 165 // Hide infobars when showing Instant Extended suggestions. | 172 // Hide infobars when showing Instant Extended suggestions. |
| 166 if (new_mode.is_search_suggestions()) { | 173 if (new_mode.is_search_suggestions()) { |
| 174 // If suggestions are being shown on a |DEFAULT| page, delay the hiding |
| 175 // until notification that instant preview is ready is received via |
| 176 // PreviewStateChanged(); this prevents jankiness caused by infobars hiding |
| 177 // followed by suggestions appearing. |
| 178 if (new_mode.is_origin_default()) |
| 179 return; |
| 167 HideAllInfoBars(); | 180 HideAllInfoBars(); |
| 168 OnInfoBarStateChanged(false); | 181 OnInfoBarStateChanged(false); |
| 169 } else { | 182 } else { |
| 170 ChangeInfoBarService(infobar_service_); | 183 ChangeInfoBarService(infobar_service_); |
| 171 infobars_shown_time_ = base::TimeTicks::Now(); | 184 infobars_shown_time_ = base::TimeTicks::Now(); |
| 172 } | 185 } |
| 173 } | 186 } |
| 174 | 187 |
| 188 void InfoBarContainer::PreviewStateChanged(const InstantModel& model) { |
| 189 // If suggestions are being shown on a |DEFAULT| page, hide the infobars now. |
| 190 // See comments for ModeChanged() for explanation. |
| 191 if (model.mode().is_search_suggestions() && |
| 192 model.mode().is_origin_default()) { |
| 193 HideAllInfoBars(); |
| 194 OnInfoBarStateChanged(false); |
| 195 } |
| 196 } |
| 197 |
| 175 size_t InfoBarContainer::HideInfoBar(InfoBarDelegate* delegate, | 198 size_t InfoBarContainer::HideInfoBar(InfoBarDelegate* delegate, |
| 176 bool use_animation) { | 199 bool use_animation) { |
| 177 bool should_animate = use_animation && | 200 bool should_animate = use_animation && |
| 178 ((base::TimeTicks::Now() - infobars_shown_time_) > | 201 ((base::TimeTicks::Now() - infobars_shown_time_) > |
| 179 base::TimeDelta::FromMilliseconds(50)); | 202 base::TimeDelta::FromMilliseconds(50)); |
| 180 | 203 |
| 181 // Search for the infobar associated with |delegate|. We cannot search for | 204 // Search for the infobar associated with |delegate|. We cannot search for |
| 182 // |delegate| in |tab_helper_|, because an InfoBar remains alive until its | 205 // |delegate| in |tab_helper_|, because an InfoBar remains alive until its |
| 183 // close animation completes, while the delegate is removed from the tab | 206 // close animation completes, while the delegate is removed from the tab |
| 184 // immediately. | 207 // immediately. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 return InfoBar::kDefaultArrowTargetHeight; | 263 return InfoBar::kDefaultArrowTargetHeight; |
| 241 // When the first infobar is animating closed, we animate the second infobar's | 264 // 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 | 265 // 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. | 266 // 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>( | 267 return top_arrow_target_height_ + static_cast<int>( |
| 245 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) * | 268 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) * |
| 246 first_infobar_animation.GetCurrentValue()); | 269 first_infobar_animation.GetCurrentValue()); |
| 247 } | 270 } |
| 248 | 271 |
| 249 #endif // TOOLKIT_VIEWS || defined(TOOLKIT_GTK) | 272 #endif // TOOLKIT_VIEWS || defined(TOOLKIT_GTK) |
| OLD | NEW |