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

Side by Side Diff: chrome/browser/cocoa/status_bubble_mac.mm

Issue 385043: "Am I on the right thread?" DCHECKs for StatusBubbleMac.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 1 month 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 | « no previous file | no next file » | 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/cocoa/status_bubble_mac.h" 5 #include "chrome/browser/cocoa/status_bubble_mac.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "app/gfx/text_elider.h" 9 #include "app/gfx/text_elider.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 void StatusBubbleMac::Attach() { 336 void StatusBubbleMac::Attach() {
337 // If the parent window is offscreen when the child is added, the child will 337 // If the parent window is offscreen when the child is added, the child will
338 // never be displayed, even when the parent moves on-screen. This method 338 // never be displayed, even when the parent moves on-screen. This method
339 // may be called several times during the process of creating or showing a 339 // may be called several times during the process of creating or showing a
340 // status bubble to attach the bubble to its parent window. 340 // status bubble to attach the bubble to its parent window.
341 if (![window_ parentWindow] && [parent_ isVisible]) 341 if (![window_ parentWindow] && [parent_ isVisible])
342 [parent_ addChildWindow:window_ ordered:NSWindowAbove]; 342 [parent_ addChildWindow:window_ ordered:NSWindowAbove];
343 } 343 }
344 344
345 void StatusBubbleMac::AnimationDidStop(CAAnimation* animation, bool finished) { 345 void StatusBubbleMac::AnimationDidStop(CAAnimation* animation, bool finished) {
346 DCHECK([NSThread isMainThread]);
346 DCHECK(state_ == kBubbleShowingFadeIn || state_ == kBubbleHidingFadeOut); 347 DCHECK(state_ == kBubbleShowingFadeIn || state_ == kBubbleHidingFadeOut);
347 348
348 if (finished) { 349 if (finished) {
349 // Because of the mechanism used to interrupt animations, this is never 350 // Because of the mechanism used to interrupt animations, this is never
350 // actually called with finished set to false. If animations ever become 351 // actually called with finished set to false. If animations ever become
351 // directly interruptible, the check will ensure that state_ remains 352 // directly interruptible, the check will ensure that state_ remains
352 // properly synchronized. 353 // properly synchronized.
353 if (state_ == kBubbleShowingFadeIn) { 354 if (state_ == kBubbleShowingFadeIn) {
354 DCHECK_EQ([[window_ animator] alphaValue], kBubbleOpacity); 355 DCHECK_EQ([[window_ animator] alphaValue], kBubbleOpacity);
355 state_ = kBubbleShown; 356 SetState(kBubbleShown);
356 } else { 357 } else {
357 DCHECK_EQ([[window_ animator] alphaValue], 0.0); 358 DCHECK_EQ([[window_ animator] alphaValue], 0.0);
358 state_ = kBubbleHidden; 359 SetState(kBubbleHidden);
359 } 360 }
360 } 361 }
361 } 362 }
362 363
363 void StatusBubbleMac::SetState(StatusBubbleState state) { 364 void StatusBubbleMac::SetState(StatusBubbleState state) {
364 if (state == state_) 365 if (state == state_)
365 return; 366 return;
366 367
367 if ([delegate_ respondsToSelector:@selector(statusBubbleWillEnterState:)]) 368 if ([delegate_ respondsToSelector:@selector(statusBubbleWillEnterState:)])
368 [delegate_ statusBubbleWillEnterState:state]; 369 [delegate_ statusBubbleWillEnterState:state];
369 370
370 state_ = state; 371 state_ = state;
371 } 372 }
372 373
373 void StatusBubbleMac::Fade(bool show) { 374 void StatusBubbleMac::Fade(bool show) {
375 DCHECK([NSThread isMainThread]);
376
374 StatusBubbleState fade_state = kBubbleShowingFadeIn; 377 StatusBubbleState fade_state = kBubbleShowingFadeIn;
375 StatusBubbleState target_state = kBubbleShown; 378 StatusBubbleState target_state = kBubbleShown;
376 NSTimeInterval full_duration = kShowFadeInDurationSeconds; 379 NSTimeInterval full_duration = kShowFadeInDurationSeconds;
377 CGFloat opacity = kBubbleOpacity; 380 CGFloat opacity = kBubbleOpacity;
378 381
379 if (!show) { 382 if (!show) {
380 fade_state = kBubbleHidingFadeOut; 383 fade_state = kBubbleHidingFadeOut;
381 target_state = kBubbleHidden; 384 target_state = kBubbleHidden;
382 full_duration = kHideFadeOutDurationSeconds; 385 full_duration = kHideFadeOutDurationSeconds;
383 opacity = 0.0; 386 opacity = 0.0;
(...skipping 23 matching lines...) Expand all
407 duration = kMinimumTimeInterval; 410 duration = kMinimumTimeInterval;
408 411
409 // This will cancel an in-progress transition and replace it with this fade. 412 // This will cancel an in-progress transition and replace it with this fade.
410 [NSAnimationContext beginGrouping]; 413 [NSAnimationContext beginGrouping];
411 [[NSAnimationContext currentContext] gtm_setDuration:duration]; 414 [[NSAnimationContext currentContext] gtm_setDuration:duration];
412 [[window_ animator] setAlphaValue:opacity]; 415 [[window_ animator] setAlphaValue:opacity];
413 [NSAnimationContext endGrouping]; 416 [NSAnimationContext endGrouping];
414 } 417 }
415 418
416 void StatusBubbleMac::StartTimer(int64 delay_ms) { 419 void StatusBubbleMac::StartTimer(int64 delay_ms) {
420 DCHECK([NSThread isMainThread]);
417 DCHECK(state_ == kBubbleShowingTimer || state_ == kBubbleHidingTimer); 421 DCHECK(state_ == kBubbleShowingTimer || state_ == kBubbleHidingTimer);
418 422
419 if (immediate_) { 423 if (immediate_) {
420 TimerFired(); 424 TimerFired();
421 return; 425 return;
422 } 426 }
423 427
424 // There can only be one running timer. 428 // There can only be one running timer.
425 CancelTimer(); 429 CancelTimer();
426 430
427 MessageLoop::current()->PostDelayedTask( 431 MessageLoop::current()->PostDelayedTask(
428 FROM_HERE, 432 FROM_HERE,
429 timer_factory_.NewRunnableMethod(&StatusBubbleMac::TimerFired), 433 timer_factory_.NewRunnableMethod(&StatusBubbleMac::TimerFired),
430 delay_ms); 434 delay_ms);
431 } 435 }
432 436
433 void StatusBubbleMac::CancelTimer() { 437 void StatusBubbleMac::CancelTimer() {
438 DCHECK([NSThread isMainThread]);
439
434 if (!timer_factory_.empty()) 440 if (!timer_factory_.empty())
435 timer_factory_.RevokeAll(); 441 timer_factory_.RevokeAll();
436 } 442 }
437 443
438 void StatusBubbleMac::TimerFired() { 444 void StatusBubbleMac::TimerFired() {
439 DCHECK(state_ == kBubbleShowingTimer || state_ == kBubbleHidingTimer); 445 DCHECK(state_ == kBubbleShowingTimer || state_ == kBubbleHidingTimer);
446 DCHECK([NSThread isMainThread]);
440 447
441 if (state_ == kBubbleShowingTimer) { 448 if (state_ == kBubbleShowingTimer) {
442 SetState(kBubbleShowingFadeIn); 449 SetState(kBubbleShowingFadeIn);
443 Fade(true); 450 Fade(true);
444 } else { 451 } else {
445 SetState(kBubbleHidingFadeOut); 452 SetState(kBubbleHidingFadeOut);
446 Fade(false); 453 Fade(false);
447 } 454 }
448 } 455 }
449 456
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 } 513 }
507 514
508 NSRect StatusBubbleMac::CalculateWindowFrame() { 515 NSRect StatusBubbleMac::CalculateWindowFrame() {
509 DCHECK(parent_); 516 DCHECK(parent_);
510 517
511 NSRect rect = [parent_ frame]; 518 NSRect rect = [parent_ frame];
512 rect.size.height = kWindowHeight; 519 rect.size.height = kWindowHeight;
513 rect.size.width = static_cast<int>(kWindowWidthPercent * rect.size.width); 520 rect.size.width = static_cast<int>(kWindowWidthPercent * rect.size.width);
514 return rect; 521 return rect;
515 } 522 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698