Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: chrome/browser/infobars/infobar_container.cc

Issue 12631008: alternate ntp: implement Show/HideBars API to reduce jank when showing/hiding bars (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 break; 168 break;
169 } 169 }
170 170
171 default: 171 default:
172 NOTREACHED(); 172 NOTREACHED();
173 break; 173 break;
174 } 174 }
175 } 175 }
176 176
177 void InfoBarContainer::ModeChanged(const chrome::search::Mode& old_mode, 177 void InfoBarContainer::ModeChanged(const chrome::search::Mode& old_mode,
178 const chrome::search::Mode& new_mode) { 178 const chrome::search::Mode& new_mode) {
Peter Kasting 2013/03/08 00:51:36 I'm not terribly thrilled by having three differen
dhollowa 2013/03/08 01:14:19 +1 Kuan, I think we may be able to collapse these
kuan 2013/03/12 18:00:38 i've consolidated all 3 notifications into 1: Mode
kuan 2013/03/12 18:00:38 i've consolidated all 3 different functions into j
179 // Hide infobars when showing Instant Extended suggestions. 179 // If new mode is |SEARCH_SUGGESTIONS| or |SEARCH_RESULTS|, don't update
180 if (new_mode.is_search_suggestions()) { 180 // infobars' states now:
181 // If suggestions are being shown on a |DEFAULT| page, delay the hiding 181 // - for |DEFAULT| page, wait for instant overlay to show or hide, via
182 // until notification that Instant overlay is ready is received via 182 // OverlayStateChanged().
183 // OverlayStateChanged(); this prevents jankiness caused by infobars hiding 183 // - for |NTP| and |SERP| pages, wait for SearchBox API callback via
184 // followed by suggestions appearing. 184 // TopBarsVisibilityChanged().
185 if (new_mode.is_origin_default()) 185 // For other mode transitions, show infobars now.
186 return; 186 if (new_mode.is_search())
187 HideAllInfoBars(); 187 return;
188 OnInfoBarStateChanged(false); 188 if (!infobars_shown_) {
189 } else {
190 ChangeInfoBarService(infobar_service_); 189 ChangeInfoBarService(infobar_service_);
191 infobars_shown_time_ = base::TimeTicks::Now(); 190 infobars_shown_time_ = base::TimeTicks::Now();
192 } 191 }
193 } 192 }
194 193
195 void InfoBarContainer::OverlayStateChanged(const InstantOverlayModel& model) { 194 void InfoBarContainer::TopBarsVisibilityChanged(
196 // If suggestions are being shown on a |DEFAULT| page, hide the infobars now. 195 const chrome::search::Mode& mode,
197 // See comments for ModeChanged() for explanation. 196 bool visible) {
198 if (model.mode().is_search_suggestions() && 197 // Only handle non-|DEFAULT| pages in |SEARCH_SUGGESTIONS| or |SEARCH_RESULTS|
199 model.mode().is_origin_default()) { 198 // modes for this callback.
199 if (!mode.is_search() || mode.is_origin_default())
200 return;
201 if (visible && !infobars_shown_) {
202 ChangeInfoBarService(infobar_service_);
203 infobars_shown_time_ = base::TimeTicks::Now();
204 } else if (!visible && infobars_shown_) {
200 HideAllInfoBars(); 205 HideAllInfoBars();
201 OnInfoBarStateChanged(false); 206 OnInfoBarStateChanged(false);
202 } 207 }
203 } 208 }
204 209
210 void InfoBarContainer::OverlayStateChanged(const InstantOverlayModel& model) {
211 // This is invoked by a platform-specific implementation of
212 // |InstantOverlayController| to update infobars' states according to instant
213 // overlay state. Only handle |DEFAULT| pages for this callback.
214 if (!model.mode().is_origin_default())
215 return;
216 if (model.mode().is_search_suggestions()) {
217 // Hide infobars if they're shown.
218 if (infobars_shown_) {
219 HideAllInfoBars();
220 OnInfoBarStateChanged(false);
221 }
222 } else if (!infobars_shown_) {
223 // Show hidden infobars.
224 ChangeInfoBarService(infobar_service_);
225 infobars_shown_time_ = base::TimeTicks::Now();
226 }
227 }
228
205 size_t InfoBarContainer::HideInfoBar(InfoBarDelegate* delegate, 229 size_t InfoBarContainer::HideInfoBar(InfoBarDelegate* delegate,
206 bool use_animation) { 230 bool use_animation) {
207 bool should_animate = use_animation && 231 bool should_animate = use_animation &&
208 ((base::TimeTicks::Now() - infobars_shown_time_) > 232 ((base::TimeTicks::Now() - infobars_shown_time_) >
209 base::TimeDelta::FromMilliseconds(50)); 233 base::TimeDelta::FromMilliseconds(50));
210 234
211 // Search for the infobar associated with |delegate|. We cannot search for 235 // Search for the infobar associated with |delegate|. We cannot search for
212 // |delegate| in |tab_helper_|, because an InfoBar remains alive until its 236 // |delegate| in |tab_helper_|, because an InfoBar remains alive until its
213 // close animation completes, while the delegate is removed from the tab 237 // close animation completes, while the delegate is removed from the tab
214 // immediately. 238 // immediately.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 return InfoBar::kDefaultArrowTargetHeight; 295 return InfoBar::kDefaultArrowTargetHeight;
272 // When the first infobar is animating closed, we animate the second infobar's 296 // 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 297 // 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. 298 // 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>( 299 return top_arrow_target_height_ + static_cast<int>(
276 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) * 300 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) *
277 first_infobar_animation.GetCurrentValue()); 301 first_infobar_animation.GetCurrentValue());
278 } 302 }
279 303
280 #endif // TOOLKIT_VIEWS || defined(TOOLKIT_GTK) 304 #endif // TOOLKIT_VIEWS || defined(TOOLKIT_GTK)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698