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

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: fixed flashing bars for DEFAULT->SUGGESTIONS->SERP 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"
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" 18 #include "chrome/browser/instant/instant_overlay_model.h"
19 #include "chrome/browser/instant/search.h"
19 #include "chrome/browser/ui/search/search_model.h" 20 #include "chrome/browser/ui/search/search_model.h"
20 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
21 #include "content/public/browser/notification_details.h" 22 #include "content/public/browser/notification_details.h"
22 #include "content/public/browser/notification_source.h" 23 #include "content/public/browser/notification_source.h"
23 #include "ui/base/animation/slide_animation.h" 24 #include "ui/base/animation/slide_animation.h"
24 25
25 InfoBarContainer::Delegate::~Delegate() { 26 InfoBarContainer::Delegate::~Delegate() {
26 } 27 }
27 28
28 InfoBarContainer::InfoBarContainer( 29 InfoBarContainer::InfoBarContainer(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 source); 67 source);
67 68
68 for (size_t i = 0; i < infobar_service_->GetInfoBarCount(); ++i) { 69 for (size_t i = 0; i < infobar_service_->GetInfoBarCount(); ++i) {
69 // As when we removed the infobars above, we prevent callbacks to 70 // As when we removed the infobars above, we prevent callbacks to
70 // OnInfoBarAnimated() for each infobar. 71 // OnInfoBarAnimated() for each infobar.
71 AddInfoBar( 72 AddInfoBar(
72 infobar_service_->GetInfoBarDelegateAt(i)->CreateInfoBar( 73 infobar_service_->GetInfoBarDelegateAt(i)->CreateInfoBar(
73 infobar_service_), 74 infobar_service_),
74 i, false, NO_CALLBACK); 75 i, false, NO_CALLBACK);
75 } 76 }
77
78 // Hide infobars if search model requires so.
Peter Kasting 2013/03/15 05:32:01 Don't do this. Instead, make this function begin
kuan 2013/03/15 15:53:49 Done.
kuan 2013/03/15 16:32:17 i moved HideAllInfoBars() to start of function. c
79 if (!search_model_->top_bars_visible())
80 HideAllInfoBars();
76 } 81 }
77 82
78 // Now that everything is up to date, signal the delegate to re-layout. 83 // Now that everything is up to date, signal the delegate to re-layout.
79 OnInfoBarStateChanged(false); 84 OnInfoBarStateChanged(false);
80 } 85 }
81 86
82 int InfoBarContainer::GetVerticalOverlap(int* total_height) { 87 int InfoBarContainer::GetVerticalOverlap(int* total_height) {
83 // Our |total_height| is the sum of the preferred heights of the InfoBars 88 // Our |total_height| is the sum of the preferred heights of the InfoBars
84 // contained within us plus the |vertical_overlap|. 89 // contained within us plus the |vertical_overlap|.
85 int vertical_overlap = 0; 90 int vertical_overlap = 0;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 HideInfoBar(replaced_details->first, false), false, WANT_CALLBACK); 172 HideInfoBar(replaced_details->first, false), false, WANT_CALLBACK);
168 break; 173 break;
169 } 174 }
170 175
171 default: 176 default:
172 NOTREACHED(); 177 NOTREACHED();
173 break; 178 break;
174 } 179 }
175 } 180 }
176 181
177 void InfoBarContainer::ModeChanged(const chrome::search::Mode& old_mode, 182 void InfoBarContainer::ModelChanged(
178 const chrome::search::Mode& new_mode) { 183 const chrome::search::SearchModel::State& old_state,
179 // Hide infobars when showing Instant Extended suggestions. 184 const chrome::search::SearchModel::State& new_state) {
180 if (new_mode.is_search_suggestions()) { 185 if (!chrome::search::SearchModel::ShouldChangeTopBarsVisibility(old_state,
181 // If suggestions are being shown on a |DEFAULT| page, delay the hiding 186 new_state)) {
Peter Kasting 2013/03/15 05:32:01 Nit: No {}
kuan 2013/03/15 15:53:49 Done.
182 // until notification that Instant overlay is ready is received via 187 return;
183 // OverlayStateChanged(); this prevents jankiness caused by infobars hiding 188 }
184 // followed by suggestions appearing. 189
185 if (new_mode.is_origin_default()) 190 if (new_state.top_bars_visible && !infobars_shown_) {
186 return;
187 HideAllInfoBars();
188 OnInfoBarStateChanged(false);
189 } else {
190 ChangeInfoBarService(infobar_service_); 191 ChangeInfoBarService(infobar_service_);
191 infobars_shown_time_ = base::TimeTicks::Now(); 192 infobars_shown_time_ = base::TimeTicks::Now();
192 } 193 } 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(); 194 HideAllInfoBars();
201 OnInfoBarStateChanged(false); 195 OnInfoBarStateChanged(false);
202 } 196 }
203 } 197 }
204 198
205 size_t InfoBarContainer::HideInfoBar(InfoBarDelegate* delegate, 199 size_t InfoBarContainer::HideInfoBar(InfoBarDelegate* delegate,
206 bool use_animation) { 200 bool use_animation) {
207 bool should_animate = use_animation && 201 bool should_animate = use_animation &&
208 ((base::TimeTicks::Now() - infobars_shown_time_) > 202 ((base::TimeTicks::Now() - infobars_shown_time_) >
209 base::TimeDelta::FromMilliseconds(50)); 203 base::TimeDelta::FromMilliseconds(50));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 return InfoBar::kDefaultArrowTargetHeight; 265 return InfoBar::kDefaultArrowTargetHeight;
272 // When the first infobar is animating closed, we animate the second infobar's 266 // 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 267 // 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. 268 // 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>( 269 return top_arrow_target_height_ + static_cast<int>(
276 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) * 270 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) *
277 first_infobar_animation.GetCurrentValue()); 271 first_infobar_animation.GetCurrentValue());
278 } 272 }
279 273
280 #endif // TOOLKIT_VIEWS || defined(TOOLKIT_GTK) 274 #endif // TOOLKIT_VIEWS || defined(TOOLKIT_GTK)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698