Chromium Code Reviews| 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); | |
|
Peter Kasting
2013/01/28 21:51:00
Please pass in a non-const pointer if you're going
kuan
2013/01/29 00:17:08
i was forced to use const InstantModel 'cos Instan
| |
| 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(). | |
|
Peter Kasting
2013/01/28 21:51:00
Nit: Add commentary on why you do this (i.e. what
kuan
2013/01/29 00:17:08
Done.
| |
| 177 if (new_mode.is_origin_default()) | |
| 178 return; | |
| 167 HideAllInfoBars(); | 179 HideAllInfoBars(); |
| 168 OnInfoBarStateChanged(false); | 180 OnInfoBarStateChanged(false); |
| 169 } else { | 181 } else { |
| 170 ChangeInfoBarService(infobar_service_); | 182 ChangeInfoBarService(infobar_service_); |
| 171 infobars_shown_time_ = base::TimeTicks::Now(); | 183 infobars_shown_time_ = base::TimeTicks::Now(); |
| 172 } | 184 } |
| 173 } | 185 } |
| 174 | 186 |
| 187 void InfoBarContainer::PreviewStateChanged(const InstantModel& model) { | |
| 188 // If suggestions are being shown on a |DEFAULT| page, hide the infobars now. | |
| 189 // See comments for ModeChanged() for explanation. | |
| 190 if (model.mode().is_search_suggestions() && | |
| 191 model.mode().is_origin_default()) { | |
| 192 HideAllInfoBars(); | |
| 193 OnInfoBarStateChanged(false); | |
| 194 } | |
| 195 } | |
| 196 | |
| 175 size_t InfoBarContainer::HideInfoBar(InfoBarDelegate* delegate, | 197 size_t InfoBarContainer::HideInfoBar(InfoBarDelegate* delegate, |
| 176 bool use_animation) { | 198 bool use_animation) { |
| 177 bool should_animate = use_animation && | 199 bool should_animate = use_animation && |
| 178 ((base::TimeTicks::Now() - infobars_shown_time_) > | 200 ((base::TimeTicks::Now() - infobars_shown_time_) > |
| 179 base::TimeDelta::FromMilliseconds(50)); | 201 base::TimeDelta::FromMilliseconds(50)); |
| 180 | 202 |
| 181 // Search for the infobar associated with |delegate|. We cannot search for | 203 // Search for the infobar associated with |delegate|. We cannot search for |
| 182 // |delegate| in |tab_helper_|, because an InfoBar remains alive until its | 204 // |delegate| in |tab_helper_|, because an InfoBar remains alive until its |
| 183 // close animation completes, while the delegate is removed from the tab | 205 // close animation completes, while the delegate is removed from the tab |
| 184 // immediately. | 206 // immediately. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 return InfoBar::kDefaultArrowTargetHeight; | 262 return InfoBar::kDefaultArrowTargetHeight; |
| 241 // When the first infobar is animating closed, we animate the second infobar's | 263 // 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 | 264 // 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. | 265 // 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>( | 266 return top_arrow_target_height_ + static_cast<int>( |
| 245 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) * | 267 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) * |
| 246 first_infobar_animation.GetCurrentValue()); | 268 first_infobar_animation.GetCurrentValue()); |
| 247 } | 269 } |
| 248 | 270 |
| 249 #endif // TOOLKIT_VIEWS || defined(TOOLKIT_GTK) | 271 #endif // TOOLKIT_VIEWS || defined(TOOLKIT_GTK) |
| OLD | NEW |