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" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 } | 38 } |
| 39 | 39 |
| 40 InfoBarContainer::~InfoBarContainer() { | 40 InfoBarContainer::~InfoBarContainer() { |
| 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 HideAllInfoBars(); |
|
Peter Kasting
2013/03/16 00:40:59
We don't need to do this here. If the search mode
kuan
2013/03/18 15:37:29
switching between tabs doesn't work correctly if i
| |
| 49 | |
| 50 infobar_service_ = infobar_service; | |
| 51 | |
| 52 if (search_model_ && !search_model_->top_bars_visible()) | |
| 53 return; | |
| 49 | 54 |
| 50 // Note that HideAllInfoBars() sets |infobars_shown_| to false, because that's | 55 // Note that HideAllInfoBars() sets |infobars_shown_| to false, because that's |
| 51 // what the other, Instant-related callers want; but here we actually | 56 // 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 | 57 // explicitly want to reset this variable to true. So do that after calling |
| 53 // the function. | 58 // the function. |
| 54 HideAllInfoBars(); | |
| 55 infobars_shown_ = true; | 59 infobars_shown_ = true; |
| 56 infobars_shown_time_ = base::TimeTicks(); | 60 infobars_shown_time_ = base::TimeTicks(); |
| 57 | 61 |
| 58 infobar_service_ = infobar_service; | |
| 59 if (infobar_service_) { | 62 if (infobar_service_) { |
| 60 content::Source<InfoBarService> source(infobar_service_); | 63 content::Source<InfoBarService> source(infobar_service_); |
| 61 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | 64 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
| 62 source); | 65 source); |
| 63 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 66 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| 64 source); | 67 source); |
| 65 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED, | 68 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED, |
| 66 source); | 69 source); |
| 67 | 70 |
| 68 for (size_t i = 0; i < infobar_service_->GetInfoBarCount(); ++i) { | 71 for (size_t i = 0; i < infobar_service_->GetInfoBarCount(); ++i) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 | 134 |
| 132 for (size_t i = infobars_.size(); i > 0; --i) | 135 for (size_t i = infobars_.size(); i > 0; --i) |
| 133 infobars_[i - 1]->CloseSoon(); | 136 infobars_[i - 1]->CloseSoon(); |
| 134 | 137 |
| 135 ChangeInfoBarService(NULL); | 138 ChangeInfoBarService(NULL); |
| 136 } | 139 } |
| 137 | 140 |
| 138 void InfoBarContainer::Observe(int type, | 141 void InfoBarContainer::Observe(int type, |
| 139 const content::NotificationSource& source, | 142 const content::NotificationSource& source, |
| 140 const content::NotificationDetails& details) { | 143 const content::NotificationDetails& details) { |
| 141 // When infobars are supposed to be hidden, we shouldn't try to hide or show | 144 // When infobars are hidden, we shouldn't be listening for notifications. |
| 142 // anything in response to any notifications. Once infobars get un-hidden | 145 DCHECK(infobars_shown_); |
| 143 // via ChangeInfoBarService(), we'll get the updated set of visible infobars | |
| 144 // from the InfoBarService. | |
| 145 if (!infobars_shown_) | |
| 146 return; | |
| 147 | 146 |
| 148 switch (type) { | 147 switch (type) { |
| 149 case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED: | 148 case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED: |
| 150 AddInfoBar( | 149 AddInfoBar( |
| 151 content::Details<InfoBarAddedDetails>(details)->CreateInfoBar( | 150 content::Details<InfoBarAddedDetails>(details)->CreateInfoBar( |
| 152 infobar_service_), | 151 infobar_service_), |
| 153 infobars_.size(), true, WANT_CALLBACK); | 152 infobars_.size(), true, WANT_CALLBACK); |
| 154 break; | 153 break; |
| 155 | 154 |
| 156 case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED: { | 155 case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED: { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 167 HideInfoBar(replaced_details->first, false), false, WANT_CALLBACK); | 166 HideInfoBar(replaced_details->first, false), false, WANT_CALLBACK); |
| 168 break; | 167 break; |
| 169 } | 168 } |
| 170 | 169 |
| 171 default: | 170 default: |
| 172 NOTREACHED(); | 171 NOTREACHED(); |
| 173 break; | 172 break; |
| 174 } | 173 } |
| 175 } | 174 } |
| 176 | 175 |
| 177 void InfoBarContainer::ModeChanged(const chrome::search::Mode& old_mode, | 176 void InfoBarContainer::ModelChanged( |
| 178 const chrome::search::Mode& new_mode) { | 177 const chrome::search::SearchModel::State& old_state, |
| 179 // Hide infobars when showing Instant Extended suggestions. | 178 const chrome::search::SearchModel::State& new_state) { |
| 180 if (new_mode.is_search_suggestions()) { | 179 if (!chrome::search::SearchModel::ShouldChangeTopBarsVisibility(old_state, |
| 181 // If suggestions are being shown on a |DEFAULT| page, delay the hiding | 180 new_state)) |
| 182 // until notification that Instant overlay is ready is received via | 181 return; |
| 183 // OverlayStateChanged(); this prevents jankiness caused by infobars hiding | 182 |
| 184 // followed by suggestions appearing. | 183 if (new_state.top_bars_visible && !infobars_shown_) { |
| 185 if (new_mode.is_origin_default()) | |
| 186 return; | |
| 187 HideAllInfoBars(); | |
| 188 OnInfoBarStateChanged(false); | |
| 189 } else { | |
| 190 ChangeInfoBarService(infobar_service_); | 184 ChangeInfoBarService(infobar_service_); |
| 191 infobars_shown_time_ = base::TimeTicks::Now(); | 185 infobars_shown_time_ = base::TimeTicks::Now(); |
| 192 } | 186 } else if (!new_state.top_bars_visible && infobars_shown_) { |
| 193 } | |
| 194 | |
| 195 void InfoBarContainer::OverlayStateChanged(const InstantOverlayModel& model) { | |
| 196 // If suggestions are being shown on a |DEFAULT| page, hide the infobars now. | |
| 197 // See comments for ModeChanged() for explanation. | |
| 198 if (model.mode().is_search_suggestions() && | |
| 199 model.mode().is_origin_default()) { | |
| 200 HideAllInfoBars(); | 187 HideAllInfoBars(); |
| 201 OnInfoBarStateChanged(false); | 188 OnInfoBarStateChanged(false); |
| 202 } | 189 } |
| 203 } | 190 } |
| 204 | 191 |
| 205 size_t InfoBarContainer::HideInfoBar(InfoBarDelegate* delegate, | 192 size_t InfoBarContainer::HideInfoBar(InfoBarDelegate* delegate, |
| 206 bool use_animation) { | 193 bool use_animation) { |
| 207 bool should_animate = use_animation && | 194 bool should_animate = use_animation && |
| 208 ((base::TimeTicks::Now() - infobars_shown_time_) > | 195 ((base::TimeTicks::Now() - infobars_shown_time_) > |
| 209 base::TimeDelta::FromMilliseconds(50)); | 196 base::TimeDelta::FromMilliseconds(50)); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 222 infobar->CloseSoon(); | 209 infobar->CloseSoon(); |
| 223 UpdateInfoBarArrowTargetHeights(); | 210 UpdateInfoBarArrowTargetHeights(); |
| 224 return position; | 211 return position; |
| 225 } | 212 } |
| 226 } | 213 } |
| 227 NOTREACHED(); | 214 NOTREACHED(); |
| 228 return infobars_.size(); | 215 return infobars_.size(); |
| 229 } | 216 } |
| 230 | 217 |
| 231 void InfoBarContainer::HideAllInfoBars() { | 218 void InfoBarContainer::HideAllInfoBars() { |
| 219 registrar_.RemoveAll(); | |
| 220 | |
| 232 infobars_shown_ = false; | 221 infobars_shown_ = false; |
| 233 while (!infobars_.empty()) { | 222 while (!infobars_.empty()) { |
| 234 InfoBar* infobar = infobars_.front(); | 223 InfoBar* infobar = infobars_.front(); |
| 235 // Inform the infobar that it's hidden. If it was already closing, this | 224 // Inform the infobar that it's hidden. If it was already closing, this |
| 236 // closes its delegate. | 225 // closes its delegate. |
| 237 infobar->Hide(false); | 226 infobar->Hide(false); |
| 238 } | 227 } |
| 239 } | 228 } |
| 240 | 229 |
| 241 void InfoBarContainer::AddInfoBar(InfoBar* infobar, | 230 void InfoBarContainer::AddInfoBar(InfoBar* infobar, |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 271 return InfoBar::kDefaultArrowTargetHeight; | 260 return InfoBar::kDefaultArrowTargetHeight; |
| 272 // When the first infobar is animating closed, we animate the second infobar's | 261 // 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 | 262 // 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. | 263 // 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>( | 264 return top_arrow_target_height_ + static_cast<int>( |
| 276 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) * | 265 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) * |
| 277 first_infobar_animation.GetCurrentValue()); | 266 first_infobar_animation.GetCurrentValue()); |
| 278 } | 267 } |
| 279 | 268 |
| 280 #endif // TOOLKIT_VIEWS || defined(TOOLKIT_GTK) | 269 #endif // TOOLKIT_VIEWS || defined(TOOLKIT_GTK) |
| OLD | NEW |