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

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 build break 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
« no previous file with comments | « chrome/browser/infobars/infobar_container.h ('k') | chrome/browser/ui/browser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 27 matching lines...) Expand all
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 // We have to call HideAllInfoBars() here and not after the early exit below,
49 // to handle the case we're switching from a tab with visible infobars to one
50 // where the SearchModel directs us to hide infobars.
51 HideAllInfoBars();
52
53 infobar_service_ = infobar_service;
54
55 if (search_model_ && !search_model_->top_bars_visible())
56 return;
49 57
50 // Note that HideAllInfoBars() sets |infobars_shown_| to false, because that's 58 // Note that HideAllInfoBars() sets |infobars_shown_| to false, because that's
51 // what the other, Instant-related callers want; but here we actually 59 // 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 60 // explicitly want to reset this variable to true. So do that after calling
53 // the function. 61 // the function.
54 HideAllInfoBars();
55 infobars_shown_ = true; 62 infobars_shown_ = true;
56 infobars_shown_time_ = base::TimeTicks(); 63 infobars_shown_time_ = base::TimeTicks();
57 64
58 infobar_service_ = infobar_service;
59 if (infobar_service_) { 65 if (infobar_service_) {
60 content::Source<InfoBarService> source(infobar_service_); 66 content::Source<InfoBarService> source(infobar_service_);
61 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, 67 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
62 source); 68 source);
63 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, 69 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
64 source); 70 source);
65 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED, 71 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED,
66 source); 72 source);
67 73
68 for (size_t i = 0; i < infobar_service_->GetInfoBarCount(); ++i) { 74 for (size_t i = 0; i < infobar_service_->GetInfoBarCount(); ++i) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
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();
134 140
135 ChangeInfoBarService(NULL); 141 ChangeInfoBarService(NULL);
136 } 142 }
137 143
138 void InfoBarContainer::Observe(int type, 144 void InfoBarContainer::Observe(int type,
139 const content::NotificationSource& source, 145 const content::NotificationSource& source,
140 const content::NotificationDetails& details) { 146 const content::NotificationDetails& details) {
141 // When infobars are supposed to be hidden, we shouldn't try to hide or show 147 // When infobars are hidden, we shouldn't be listening for notifications.
142 // anything in response to any notifications. Once infobars get un-hidden 148 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 149
148 switch (type) { 150 switch (type) {
149 case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED: 151 case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED:
150 AddInfoBar( 152 AddInfoBar(
151 content::Details<InfoBarAddedDetails>(details)->CreateInfoBar( 153 content::Details<InfoBarAddedDetails>(details)->CreateInfoBar(
152 infobar_service_), 154 infobar_service_),
153 infobars_.size(), true, WANT_CALLBACK); 155 infobars_.size(), true, WANT_CALLBACK);
154 break; 156 break;
155 157
156 case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED: { 158 case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED: {
(...skipping 10 matching lines...) Expand all
167 HideInfoBar(replaced_details->first, false), false, WANT_CALLBACK); 169 HideInfoBar(replaced_details->first, false), false, WANT_CALLBACK);
168 break; 170 break;
169 } 171 }
170 172
171 default: 173 default:
172 NOTREACHED(); 174 NOTREACHED();
173 break; 175 break;
174 } 176 }
175 } 177 }
176 178
177 void InfoBarContainer::ModeChanged(const chrome::search::Mode& old_mode, 179 void InfoBarContainer::ModelChanged(
178 const chrome::search::Mode& new_mode) { 180 const chrome::search::SearchModel::State& old_state,
179 // Hide infobars when showing Instant Extended suggestions. 181 const chrome::search::SearchModel::State& new_state) {
180 if (new_mode.is_search_suggestions()) { 182 if (!chrome::search::SearchModel::ShouldChangeTopBarsVisibility(old_state,
181 // If suggestions are being shown on a |DEFAULT| page, delay the hiding 183 new_state))
182 // until notification that Instant overlay is ready is received via 184 return;
183 // OverlayStateChanged(); this prevents jankiness caused by infobars hiding 185
184 // followed by suggestions appearing. 186 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_); 187 ChangeInfoBarService(infobar_service_);
191 infobars_shown_time_ = base::TimeTicks::Now(); 188 infobars_shown_time_ = base::TimeTicks::Now();
192 } 189 } 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(); 190 HideAllInfoBars();
201 OnInfoBarStateChanged(false); 191 OnInfoBarStateChanged(false);
202 } 192 }
203 } 193 }
204 194
205 size_t InfoBarContainer::HideInfoBar(InfoBarDelegate* delegate, 195 size_t InfoBarContainer::HideInfoBar(InfoBarDelegate* delegate,
206 bool use_animation) { 196 bool use_animation) {
207 bool should_animate = use_animation && 197 bool should_animate = use_animation &&
208 ((base::TimeTicks::Now() - infobars_shown_time_) > 198 ((base::TimeTicks::Now() - infobars_shown_time_) >
209 base::TimeDelta::FromMilliseconds(50)); 199 base::TimeDelta::FromMilliseconds(50));
(...skipping 12 matching lines...) Expand all
222 infobar->CloseSoon(); 212 infobar->CloseSoon();
223 UpdateInfoBarArrowTargetHeights(); 213 UpdateInfoBarArrowTargetHeights();
224 return position; 214 return position;
225 } 215 }
226 } 216 }
227 NOTREACHED(); 217 NOTREACHED();
228 return infobars_.size(); 218 return infobars_.size();
229 } 219 }
230 220
231 void InfoBarContainer::HideAllInfoBars() { 221 void InfoBarContainer::HideAllInfoBars() {
222 registrar_.RemoveAll();
223
232 infobars_shown_ = false; 224 infobars_shown_ = false;
233 while (!infobars_.empty()) { 225 while (!infobars_.empty()) {
234 InfoBar* infobar = infobars_.front(); 226 InfoBar* infobar = infobars_.front();
235 // Inform the infobar that it's hidden. If it was already closing, this 227 // Inform the infobar that it's hidden. If it was already closing, this
236 // closes its delegate. 228 // closes its delegate.
237 infobar->Hide(false); 229 infobar->Hide(false);
238 } 230 }
239 } 231 }
240 232
241 void InfoBarContainer::AddInfoBar(InfoBar* infobar, 233 void InfoBarContainer::AddInfoBar(InfoBar* infobar,
(...skipping 29 matching lines...) Expand all
271 return InfoBar::kDefaultArrowTargetHeight; 263 return InfoBar::kDefaultArrowTargetHeight;
272 // When the first infobar is animating closed, we animate the second infobar's 264 // 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 265 // 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. 266 // 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>( 267 return top_arrow_target_height_ + static_cast<int>(
276 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) * 268 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) *
277 first_infobar_animation.GetCurrentValue()); 269 first_infobar_animation.GetCurrentValue());
278 } 270 }
279 271
280 #endif // TOOLKIT_VIEWS || defined(TOOLKIT_GTK) 272 #endif // TOOLKIT_VIEWS || defined(TOOLKIT_GTK)
OLDNEW
« no previous file with comments | « chrome/browser/infobars/infobar_container.h ('k') | chrome/browser/ui/browser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698