| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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_overlay_model.h" | |
| 19 #include "chrome/browser/ui/search/search_model.h" | 18 #include "chrome/browser/ui/search/search_model.h" |
| 20 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "content/public/browser/notification_details.h" | 20 #include "content/public/browser/notification_details.h" |
| 22 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_source.h" |
| 23 #include "ui/base/animation/slide_animation.h" | 22 #include "ui/base/animation/slide_animation.h" |
| 24 | 23 |
| 25 InfoBarContainer::Delegate::~Delegate() { | 24 InfoBarContainer::Delegate::~Delegate() { |
| 26 } | 25 } |
| 27 | 26 |
| 28 InfoBarContainer::InfoBarContainer( | 27 InfoBarContainer::InfoBarContainer( |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } | 113 } |
| 115 | 114 |
| 116 void InfoBarContainer::RemoveInfoBar(InfoBar* infobar) { | 115 void InfoBarContainer::RemoveInfoBar(InfoBar* infobar) { |
| 117 infobar->set_container(NULL); | 116 infobar->set_container(NULL); |
| 118 InfoBars::iterator i(std::find(infobars_.begin(), infobars_.end(), infobar)); | 117 InfoBars::iterator i(std::find(infobars_.begin(), infobars_.end(), infobar)); |
| 119 DCHECK(i != infobars_.end()); | 118 DCHECK(i != infobars_.end()); |
| 120 PlatformSpecificRemoveInfoBar(infobar); | 119 PlatformSpecificRemoveInfoBar(infobar); |
| 121 infobars_.erase(i); | 120 infobars_.erase(i); |
| 122 } | 121 } |
| 123 | 122 |
| 123 void InfoBarContainer::InstantOverlayShown() { |
| 124 // Suggestions are being shown on a |DEFAULT| page. Hide the infobars now. |
| 125 // See comments for ModeChanged() for explanation. |
| 126 HideAllInfoBars(); |
| 127 OnInfoBarStateChanged(false); |
| 128 } |
| 129 |
| 124 void InfoBarContainer::RemoveAllInfoBarsForDestruction() { | 130 void InfoBarContainer::RemoveAllInfoBarsForDestruction() { |
| 125 // Before we remove any children, we reset |delegate_|, so that no removals | 131 // Before we remove any children, we reset |delegate_|, so that no removals |
| 126 // will result in us trying to call | 132 // will result in us trying to call |
| 127 // delegate_->InfoBarContainerStateChanged(). This is important because at | 133 // delegate_->InfoBarContainerStateChanged(). This is important because at |
| 128 // this point |delegate_| may be shutting down, and it's at best unimportant | 134 // this point |delegate_| may be shutting down, and it's at best unimportant |
| 129 // and at worst disastrous to call that. | 135 // and at worst disastrous to call that. |
| 130 delegate_ = NULL; | 136 delegate_ = NULL; |
| 131 | 137 |
| 132 for (size_t i = infobars_.size(); i > 0; --i) | 138 for (size_t i = infobars_.size(); i > 0; --i) |
| 133 infobars_[i - 1]->CloseSoon(); | 139 infobars_[i - 1]->CloseSoon(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 NOTREACHED(); | 178 NOTREACHED(); |
| 173 break; | 179 break; |
| 174 } | 180 } |
| 175 } | 181 } |
| 176 | 182 |
| 177 void InfoBarContainer::ModeChanged(const chrome::search::Mode& old_mode, | 183 void InfoBarContainer::ModeChanged(const chrome::search::Mode& old_mode, |
| 178 const chrome::search::Mode& new_mode) { | 184 const chrome::search::Mode& new_mode) { |
| 179 // Hide infobars when showing Instant Extended suggestions. | 185 // Hide infobars when showing Instant Extended suggestions. |
| 180 if (new_mode.is_search_suggestions()) { | 186 if (new_mode.is_search_suggestions()) { |
| 181 // If suggestions are being shown on a |DEFAULT| page, delay the hiding | 187 // If suggestions are being shown on a |DEFAULT| page, delay the hiding |
| 182 // until notification that Instant overlay is ready is received via | 188 // until a notification that the Instant overlay is ready is received via |
| 183 // OverlayStateChanged(); this prevents jankiness caused by infobars hiding | 189 // InstantOverlayShown(); this prevents jankiness caused by infobars hiding |
| 184 // followed by suggestions appearing. | 190 // followed by suggestions appearing. |
| 185 if (new_mode.is_origin_default()) | 191 if (new_mode.is_origin_default()) |
| 186 return; | 192 return; |
| 187 HideAllInfoBars(); | 193 HideAllInfoBars(); |
| 188 OnInfoBarStateChanged(false); | 194 OnInfoBarStateChanged(false); |
| 189 } else { | 195 } else { |
| 190 ChangeInfoBarService(infobar_service_); | 196 ChangeInfoBarService(infobar_service_); |
| 191 infobars_shown_time_ = base::TimeTicks::Now(); | 197 infobars_shown_time_ = base::TimeTicks::Now(); |
| 192 } | 198 } |
| 193 } | 199 } |
| 194 | 200 |
| 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(); | |
| 201 OnInfoBarStateChanged(false); | |
| 202 } | |
| 203 } | |
| 204 | |
| 205 size_t InfoBarContainer::HideInfoBar(InfoBarDelegate* delegate, | 201 size_t InfoBarContainer::HideInfoBar(InfoBarDelegate* delegate, |
| 206 bool use_animation) { | 202 bool use_animation) { |
| 207 bool should_animate = use_animation && | 203 bool should_animate = use_animation && |
| 208 ((base::TimeTicks::Now() - infobars_shown_time_) > | 204 ((base::TimeTicks::Now() - infobars_shown_time_) > |
| 209 base::TimeDelta::FromMilliseconds(50)); | 205 base::TimeDelta::FromMilliseconds(50)); |
| 210 | 206 |
| 211 // Search for the infobar associated with |delegate|. We cannot search for | 207 // Search for the infobar associated with |delegate|. We cannot search for |
| 212 // |delegate| in |tab_helper_|, because an InfoBar remains alive until its | 208 // |delegate| in |tab_helper_|, because an InfoBar remains alive until its |
| 213 // close animation completes, while the delegate is removed from the tab | 209 // close animation completes, while the delegate is removed from the tab |
| 214 // immediately. | 210 // immediately. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 return InfoBar::kDefaultArrowTargetHeight; | 267 return InfoBar::kDefaultArrowTargetHeight; |
| 272 // When the first infobar is animating closed, we animate the second infobar's | 268 // 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 | 269 // 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. | 270 // 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>( | 271 return top_arrow_target_height_ + static_cast<int>( |
| 276 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) * | 272 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) * |
| 277 first_infobar_animation.GetCurrentValue()); | 273 first_infobar_animation.GetCurrentValue()); |
| 278 } | 274 } |
| 279 | 275 |
| 280 #endif // TOOLKIT_VIEWS || defined(TOOLKIT_GTK) | 276 #endif // TOOLKIT_VIEWS || defined(TOOLKIT_GTK) |
| OLD | NEW |