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

Side by Side Diff: chrome/browser/ui/views/status_bubble_views.cc

Issue 10026013: Update use of TimeDelta in chrome/browser/*, ui/views/*, and other places. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase onto master. Created 8 years, 7 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
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 "chrome/browser/ui/views/status_bubble_views.h" 5 #include "chrome/browser/ui/views/status_bubble_views.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 void Hide(); 131 void Hide();
132 132
133 // Resets any timers we have. Typically called when the user moves a 133 // Resets any timers we have. Typically called when the user moves a
134 // mouse. 134 // mouse.
135 void ResetTimer(); 135 void ResetTimer();
136 136
137 private: 137 private:
138 class InitialTimer; 138 class InitialTimer;
139 139
140 // Manage the timers that control the delay before a fade begins or ends. 140 // Manage the timers that control the delay before a fade begins or ends.
141 void StartTimer(int time); 141 void StartTimer(base::TimeDelta time);
142 void OnTimer(); 142 void OnTimer();
143 void CancelTimer(); 143 void CancelTimer();
144 void RestartTimer(int delay); 144 void RestartTimer(base::TimeDelta delay);
145 145
146 // Manage the fades and starting and stopping the animations correctly. 146 // Manage the fades and starting and stopping the animations correctly.
147 void StartFade(double start, double end, int duration); 147 void StartFade(double start, double end, int duration);
148 void StartHiding(); 148 void StartHiding();
149 void StartShowing(); 149 void StartShowing();
150 150
151 // Animation functions. 151 // Animation functions.
152 double GetCurrentOpacity(); 152 double GetCurrentOpacity();
153 void SetOpacity(double opacity); 153 void SetOpacity(double opacity);
154 void AnimateToState(double state); 154 void AnimateToState(double state);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 205
206 void StatusBubbleViews::StatusView::Hide() { 206 void StatusBubbleViews::StatusView::Hide() {
207 Stop(); 207 Stop();
208 CancelTimer(); 208 CancelTimer();
209 SetOpacity(0.0); 209 SetOpacity(0.0);
210 text_.clear(); 210 text_.clear();
211 popup_->Hide(); 211 popup_->Hide();
212 stage_ = BUBBLE_HIDDEN; 212 stage_ = BUBBLE_HIDDEN;
213 } 213 }
214 214
215 void StatusBubbleViews::StatusView::StartTimer(int time) { 215 void StatusBubbleViews::StatusView::StartTimer(base::TimeDelta time) {
216 if (timer_factory_.HasWeakPtrs()) 216 if (timer_factory_.HasWeakPtrs())
217 timer_factory_.InvalidateWeakPtrs(); 217 timer_factory_.InvalidateWeakPtrs();
218 218
219 MessageLoop::current()->PostDelayedTask( 219 MessageLoop::current()->PostDelayedTask(
220 FROM_HERE, 220 FROM_HERE,
221 base::Bind(&StatusBubbleViews::StatusView::OnTimer, 221 base::Bind(&StatusBubbleViews::StatusView::OnTimer,
222 timer_factory_.GetWeakPtr()), 222 timer_factory_.GetWeakPtr()),
223 time); 223 time);
224 } 224 }
225 225
226 void StatusBubbleViews::StatusView::OnTimer() { 226 void StatusBubbleViews::StatusView::OnTimer() {
227 if (stage_ == BUBBLE_HIDING_TIMER) { 227 if (stage_ == BUBBLE_HIDING_TIMER) {
228 stage_ = BUBBLE_HIDING_FADE; 228 stage_ = BUBBLE_HIDING_FADE;
229 StartFade(1.0, 0.0, kHideFadeDurationMS); 229 StartFade(1.0, 0.0, kHideFadeDurationMS);
230 } else if (stage_ == BUBBLE_SHOWING_TIMER) { 230 } else if (stage_ == BUBBLE_SHOWING_TIMER) {
231 stage_ = BUBBLE_SHOWING_FADE; 231 stage_ = BUBBLE_SHOWING_FADE;
232 StartFade(0.0, 1.0, kShowFadeDurationMS); 232 StartFade(0.0, 1.0, kShowFadeDurationMS);
233 } 233 }
234 } 234 }
235 235
236 void StatusBubbleViews::StatusView::CancelTimer() { 236 void StatusBubbleViews::StatusView::CancelTimer() {
237 if (timer_factory_.HasWeakPtrs()) 237 if (timer_factory_.HasWeakPtrs())
238 timer_factory_.InvalidateWeakPtrs(); 238 timer_factory_.InvalidateWeakPtrs();
239 } 239 }
240 240
241 void StatusBubbleViews::StatusView::RestartTimer(int delay) { 241 void StatusBubbleViews::StatusView::RestartTimer(base::TimeDelta delay) {
242 CancelTimer(); 242 CancelTimer();
243 StartTimer(delay); 243 StartTimer(delay);
244 } 244 }
245 245
246 void StatusBubbleViews::StatusView::ResetTimer() { 246 void StatusBubbleViews::StatusView::ResetTimer() {
247 if (stage_ == BUBBLE_SHOWING_TIMER) { 247 if (stage_ == BUBBLE_SHOWING_TIMER) {
248 // We hadn't yet begun showing anything when we received a new request 248 // We hadn't yet begun showing anything when we received a new request
249 // for something to show, so we start from scratch. 249 // for something to show, so we start from scratch.
250 RestartTimer(kShowDelay); 250 RestartTimer(base::TimeDelta::FromMilliseconds(kShowDelay));
251 } 251 }
252 } 252 }
253 253
254 void StatusBubbleViews::StatusView::StartFade(double start, 254 void StatusBubbleViews::StatusView::StartFade(double start,
255 double end, 255 double end,
256 int duration) { 256 int duration) {
257 opacity_start_ = start; 257 opacity_start_ = start;
258 opacity_end_ = end; 258 opacity_end_ = end;
259 259
260 // This will also reset the currently-occurring animation. 260 // This will also reset the currently-occurring animation.
261 SetDuration(duration); 261 SetDuration(duration);
262 Start(); 262 Start();
263 } 263 }
264 264
265 void StatusBubbleViews::StatusView::StartHiding() { 265 void StatusBubbleViews::StatusView::StartHiding() {
266 if (stage_ == BUBBLE_SHOWN) { 266 if (stage_ == BUBBLE_SHOWN) {
267 stage_ = BUBBLE_HIDING_TIMER; 267 stage_ = BUBBLE_HIDING_TIMER;
268 StartTimer(kHideDelay); 268 StartTimer(base::TimeDelta::FromMilliseconds(kHideDelay));
269 } else if (stage_ == BUBBLE_SHOWING_TIMER) { 269 } else if (stage_ == BUBBLE_SHOWING_TIMER) {
270 stage_ = BUBBLE_HIDDEN; 270 stage_ = BUBBLE_HIDDEN;
271 popup_->Hide(); 271 popup_->Hide();
272 CancelTimer(); 272 CancelTimer();
273 } else if (stage_ == BUBBLE_SHOWING_FADE) { 273 } else if (stage_ == BUBBLE_SHOWING_FADE) {
274 stage_ = BUBBLE_HIDING_FADE; 274 stage_ = BUBBLE_HIDING_FADE;
275 // Figure out where we are in the current fade. 275 // Figure out where we are in the current fade.
276 double current_opacity = GetCurrentOpacity(); 276 double current_opacity = GetCurrentOpacity();
277 277
278 // Start a fade in the opposite direction. 278 // Start a fade in the opposite direction.
279 StartFade(current_opacity, 0.0, 279 StartFade(current_opacity, 0.0,
280 static_cast<int>(kHideFadeDurationMS * current_opacity)); 280 static_cast<int>(kHideFadeDurationMS * current_opacity));
281 } 281 }
282 } 282 }
283 283
284 void StatusBubbleViews::StatusView::StartShowing() { 284 void StatusBubbleViews::StatusView::StartShowing() {
285 if (stage_ == BUBBLE_HIDDEN) { 285 if (stage_ == BUBBLE_HIDDEN) {
286 popup_->Show(); 286 popup_->Show();
287 stage_ = BUBBLE_SHOWING_TIMER; 287 stage_ = BUBBLE_SHOWING_TIMER;
288 StartTimer(kShowDelay); 288 StartTimer(base::TimeDelta::FromMilliseconds(kShowDelay));
289 } else if (stage_ == BUBBLE_HIDING_TIMER) { 289 } else if (stage_ == BUBBLE_HIDING_TIMER) {
290 stage_ = BUBBLE_SHOWN; 290 stage_ = BUBBLE_SHOWN;
291 CancelTimer(); 291 CancelTimer();
292 } else if (stage_ == BUBBLE_HIDING_FADE) { 292 } else if (stage_ == BUBBLE_HIDING_FADE) {
293 // We're partway through a fade. 293 // We're partway through a fade.
294 stage_ = BUBBLE_SHOWING_FADE; 294 stage_ = BUBBLE_SHOWING_FADE;
295 295
296 // Figure out where we are in the current fade. 296 // Figure out where we are in the current fade.
297 double current_opacity = GetCurrentOpacity(); 297 double current_opacity = GetCurrentOpacity();
298 298
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 672
673 // If bubble is already in expanded state, shift to adjust to new text 673 // If bubble is already in expanded state, shift to adjust to new text
674 // size (shrinking or expanding). Otherwise delay. 674 // size (shrinking or expanding). Otherwise delay.
675 if (is_expanded_ && !url.is_empty()) { 675 if (is_expanded_ && !url.is_empty()) {
676 ExpandBubble(); 676 ExpandBubble();
677 } else if (net::FormatUrl(url, languages).length() > url_text_.length()) { 677 } else if (net::FormatUrl(url, languages).length() > url_text_.length()) {
678 MessageLoop::current()->PostDelayedTask( 678 MessageLoop::current()->PostDelayedTask(
679 FROM_HERE, 679 FROM_HERE,
680 base::Bind(&StatusBubbleViews::ExpandBubble, 680 base::Bind(&StatusBubbleViews::ExpandBubble,
681 expand_timer_factory_.GetWeakPtr()), 681 expand_timer_factory_.GetWeakPtr()),
682 kExpandHoverDelay); 682 base::TimeDelta::FromMilliseconds(kExpandHoverDelay));
683 } 683 }
684 } 684 }
685 } 685 }
686 686
687 void StatusBubbleViews::Hide() { 687 void StatusBubbleViews::Hide() {
688 status_text_ = string16(); 688 status_text_ = string16();
689 url_text_ = string16(); 689 url_text_ = string16();
690 if (view_) 690 if (view_)
691 view_->Hide(); 691 view_->Hide();
692 } 692 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 void StatusBubbleViews::SetBubbleWidth(int width) { 838 void StatusBubbleViews::SetBubbleWidth(int width) {
839 size_.set_width(width); 839 size_.set_width(width);
840 SetBounds(original_position_.x(), original_position_.y(), 840 SetBounds(original_position_.x(), original_position_.y(),
841 size_.width(), size_.height()); 841 size_.width(), size_.height());
842 } 842 }
843 843
844 void StatusBubbleViews::CancelExpandTimer() { 844 void StatusBubbleViews::CancelExpandTimer() {
845 if (expand_timer_factory_.HasWeakPtrs()) 845 if (expand_timer_factory_.HasWeakPtrs())
846 expand_timer_factory_.InvalidateWeakPtrs(); 846 expand_timer_factory_.InvalidateWeakPtrs();
847 } 847 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/extensions/extension_installed_bubble.cc ('k') | ui/aura/root_window.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698