Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #import "chrome/browser/ui/cocoa/download/download_item_cell.h" | 5 #import "chrome/browser/ui/cocoa/download/download_item_cell.h" |
| 6 | 6 |
| 7 #include "base/sys_string_conversions.h" | 7 #include "base/sys_string_conversions.h" |
| 8 #include "chrome/browser/download/download_item.h" | 8 #include "chrome/browser/download/download_item.h" |
| 9 #include "chrome/browser/download/download_item_model.h" | 9 #include "chrome/browser/download/download_item_model.h" |
| 10 #include "chrome/browser/download/download_manager.h" | 10 #include "chrome/browser/download/download_manager.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 @end | 102 @end |
| 103 | 103 |
| 104 @implementation DownloadItemCell | 104 @implementation DownloadItemCell |
| 105 | 105 |
| 106 @synthesize secondaryTitle = secondaryTitle_; | 106 @synthesize secondaryTitle = secondaryTitle_; |
| 107 @synthesize secondaryFont = secondaryFont_; | 107 @synthesize secondaryFont = secondaryFont_; |
| 108 | 108 |
| 109 - (void)setInitialState { | 109 - (void)setInitialState { |
| 110 isStatusTextVisible_ = NO; | 110 isStatusTextVisible_ = NO; |
| 111 titleY_ = kPrimaryTextPosTop; | 111 titleY_ = kPrimaryTextPosTop; |
| 112 statusAlpha_ = 1.0; | 112 statusAlpha_ = 0.0; |
| 113 | 113 |
| 114 [self setFont:[NSFont systemFontOfSize: | 114 [self setFont:[NSFont systemFontOfSize: |
| 115 [NSFont systemFontSizeForControlSize:NSSmallControlSize]]]; | 115 [NSFont systemFontSizeForControlSize:NSSmallControlSize]]]; |
| 116 [self setSecondaryFont:[NSFont systemFontOfSize: | 116 [self setSecondaryFont:[NSFont systemFontOfSize: |
| 117 [NSFont systemFontSizeForControlSize:NSSmallControlSize]]]; | 117 [NSFont systemFontSizeForControlSize:NSSmallControlSize]]]; |
| 118 | 118 |
| 119 [self updateTrackingAreas:self]; | 119 [self updateTrackingAreas:self]; |
| 120 [[NSNotificationCenter defaultCenter] | 120 [[NSNotificationCenter defaultCenter] |
| 121 addObserver:self | 121 addObserver:self |
| 122 selector:@selector(updateTrackingAreas:) | 122 selector:@selector(updateTrackingAreas:) |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 137 if ((self = [super initTextCell:string])) { | 137 if ((self = [super initTextCell:string])) { |
| 138 [self setInitialState]; | 138 [self setInitialState]; |
| 139 } | 139 } |
| 140 return self; | 140 return self; |
| 141 } | 141 } |
| 142 | 142 |
| 143 - (void)dealloc { | 143 - (void)dealloc { |
| 144 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 144 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 145 if ([completionAnimation_ isAnimating]) | 145 if ([completionAnimation_ isAnimating]) |
| 146 [completionAnimation_ stopAnimation]; | 146 [completionAnimation_ stopAnimation]; |
| 147 if ([showStatusAnimation_ isAnimating]) | 147 if ([toggleStatusVisibilityAnimation_ isAnimating]) |
| 148 [showStatusAnimation_ stopAnimation]; | 148 [toggleStatusVisibilityAnimation_ stopAnimation]; |
| 149 if ([hideStatusAnimation_ isAnimating]) | |
| 150 [hideStatusAnimation_ stopAnimation]; | |
| 151 if (trackingAreaButton_) { | 149 if (trackingAreaButton_) { |
| 152 [[self controlView] removeTrackingArea:trackingAreaButton_]; | 150 [[self controlView] removeTrackingArea:trackingAreaButton_]; |
| 153 trackingAreaButton_.reset(); | 151 trackingAreaButton_.reset(); |
| 154 } | 152 } |
| 155 if (trackingAreaDropdown_) { | 153 if (trackingAreaDropdown_) { |
| 156 [[self controlView] removeTrackingArea:trackingAreaDropdown_]; | 154 [[self controlView] removeTrackingArea:trackingAreaDropdown_]; |
| 157 trackingAreaDropdown_.reset(); | 155 trackingAreaDropdown_.reset(); |
| 158 } | 156 } |
| 159 [secondaryTitle_ release]; | 157 [secondaryTitle_ release]; |
| 160 [secondaryFont_ release]; | 158 [secondaryFont_ release]; |
| 161 [super dealloc]; | 159 [super dealloc]; |
| 162 } | 160 } |
| 163 | 161 |
| 164 - (void)setStateFromDownload:(BaseDownloadItemModel*)downloadModel { | 162 - (void)setStateFromDownload:(BaseDownloadItemModel*)downloadModel { |
| 165 // Set the name of the download. | 163 // Set the name of the download. |
| 166 downloadPath_ = downloadModel->download()->GetFileNameToReportUser(); | 164 downloadPath_ = downloadModel->download()->GetFileNameToReportUser(); |
| 167 | 165 |
| 168 string16 statusText = downloadModel->GetStatusText(); | 166 string16 statusText = downloadModel->GetStatusText(); |
| 169 if (statusText.empty()) { | 167 if (statusText.empty()) { |
| 170 // Remove the status text label. | 168 // Remove the status text label. |
| 171 [self hideSecondaryTitle]; | 169 [self hideSecondaryTitle]; |
| 172 isStatusTextVisible_ = NO; | |
| 173 } else { | 170 } else { |
| 174 // Set status text. | 171 // Set status text. |
| 175 NSString* statusString = base::SysUTF16ToNSString(statusText); | 172 NSString* statusString = base::SysUTF16ToNSString(statusText); |
| 176 [self setSecondaryTitle:statusString]; | 173 [self setSecondaryTitle:statusString]; |
| 177 [self showSecondaryTitle]; | 174 [self showSecondaryTitle]; |
| 178 isStatusTextVisible_ = YES; | |
| 179 } | 175 } |
| 180 | 176 |
| 181 switch (downloadModel->download()->state()) { | 177 switch (downloadModel->download()->state()) { |
| 182 case DownloadItem::COMPLETE: | 178 case DownloadItem::COMPLETE: |
| 183 // Small downloads may start in a complete state due to asynchronous | 179 // Small downloads may start in a complete state due to asynchronous |
| 184 // notifications. In this case, we'll get a second complete notification | 180 // notifications. In this case, we'll get a second complete notification |
| 185 // via the observers, so we ignore it and avoid creating a second complete | 181 // via the observers, so we ignore it and avoid creating a second complete |
| 186 // animation. | 182 // animation. |
| 187 if (completionAnimation_.get()) | 183 if (completionAnimation_.get()) |
| 188 break; | 184 break; |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 592 } | 588 } |
| 593 | 589 |
| 594 - (NSRect)imageRectForBounds:(NSRect)cellFrame { | 590 - (NSRect)imageRectForBounds:(NSRect)cellFrame { |
| 595 return NSMakeRect(cellFrame.origin.x + kImagePaddingLeft, | 591 return NSMakeRect(cellFrame.origin.x + kImagePaddingLeft, |
| 596 cellFrame.origin.y + kImagePaddingTop, | 592 cellFrame.origin.y + kImagePaddingTop, |
| 597 kImageWidth, | 593 kImageWidth, |
| 598 kImageHeight); | 594 kImageHeight); |
| 599 } | 595 } |
| 600 | 596 |
| 601 - (void)showSecondaryTitle { | 597 - (void)showSecondaryTitle { |
| 602 if (!isStatusTextVisible_) { | 598 if (isStatusTextVisible_) |
| 599 return; | |
| 600 isStatusTextVisible_ = YES; | |
| 601 if (toggleStatusVisibilityAnimation_ && | |
| 602 [toggleStatusVisibilityAnimation_ isAnimating]) { | |
| 603 // If the animation is hiding the status text, cancel the animation and | |
| 604 // show the status text immediately. | |
| 605 [toggleStatusVisibilityAnimation_ stopAnimation]; | |
| 606 [self animation:toggleStatusVisibilityAnimation_ progressed:1.0]; | |
| 607 toggleStatusVisibilityAnimation_.reset(); | |
| 608 } else { | |
| 603 // No core animation -- text in CA layers is not subpixel antialiased :-/ | 609 // No core animation -- text in CA layers is not subpixel antialiased :-/ |
|
Nico
2011/07/04 16:39:02
Can you s/No/Don't use/?
| |
| 604 showStatusAnimation_.reset([[DownloadItemCellAnimation alloc] | 610 toggleStatusVisibilityAnimation_.reset([[DownloadItemCellAnimation alloc] |
| 605 initWithDownloadItemCell:self | 611 initWithDownloadItemCell:self |
| 606 duration:kShowStatusDuration | 612 duration:kShowStatusDuration |
| 607 animationCurve:NSAnimationEaseIn]); | 613 animationCurve:NSAnimationEaseIn]); |
|
Nico
2011/07/04 16:39:02
ObjC style is to align the colons (:) vertically –
| |
| 608 [showStatusAnimation_.get() setDelegate:self]; | 614 [toggleStatusVisibilityAnimation_.get() setDelegate:self]; |
| 609 [showStatusAnimation_.get() startAnimation]; | 615 [toggleStatusVisibilityAnimation_.get() startAnimation]; |
| 610 } else { | 616 NSLog(@"start"); |
|
Nico
2011/07/04 16:39:02
Remove
| |
| 611 // If the status line continues to be visible, don't show an animation | |
| 612 [self animation:nil progressed:0.0]; | |
| 613 } | 617 } |
| 614 } | 618 } |
| 615 | 619 |
| 616 - (void)hideSecondaryTitle { | 620 - (void)hideSecondaryTitle { |
|
Nico
2011/07/04 16:39:02
From what I can tell, this function is identical t
| |
| 617 if (isStatusTextVisible_) { | 621 if (!isStatusTextVisible_) |
| 618 // No core animation -- text in CA layers is not subpixel antialiased :-/ | 622 return; |
| 619 hideStatusAnimation_.reset([[DownloadItemCellAnimation alloc] | 623 isStatusTextVisible_ = NO; |
| 620 initWithDownloadItemCell:self | 624 if (toggleStatusVisibilityAnimation_ && |
| 621 duration:kHideStatusDuration | 625 [toggleStatusVisibilityAnimation_ isAnimating]) { |
| 622 animationCurve:NSAnimationEaseIn]); | |
| 623 [hideStatusAnimation_.get() setDelegate:self]; | |
| 624 [hideStatusAnimation_.get() startAnimation]; | |
| 625 } else { | |
| 626 // If the download is done so quickly that the status line is never visible, | 626 // If the download is done so quickly that the status line is never visible, |
| 627 // don't show an animation | 627 // don't show an animation |
| 628 [self animation:nil progressed:1.0]; | 628 [toggleStatusVisibilityAnimation_ stopAnimation]; |
| 629 [self animation:toggleStatusVisibilityAnimation_ progressed:1.0]; | |
| 630 toggleStatusVisibilityAnimation_.reset(); | |
| 631 } else { | |
| 632 // No core animation -- text in CA layers is not subpixel antialiased :-/ | |
|
Nico
2011/07/04 16:39:02
here too
| |
| 633 toggleStatusVisibilityAnimation_.reset([[DownloadItemCellAnimation alloc] | |
| 634 initWithDownloadItemCell:self | |
| 635 duration:kHideStatusDuration | |
| 636 animationCurve:NSAnimationEaseIn]); | |
|
Nico
2011/07/04 16:39:02
align : too
| |
| 637 [toggleStatusVisibilityAnimation_.get() setDelegate:self]; | |
| 638 [toggleStatusVisibilityAnimation_.get() startAnimation]; | |
| 629 } | 639 } |
| 630 } | 640 } |
| 631 | 641 |
| 632 - (void)animation:(NSAnimation*)animation | 642 - (void)animation:(NSAnimation*)animation |
| 633 progressed:(NSAnimationProgress)progress { | 643 progressed:(NSAnimationProgress)progress { |
| 634 if (animation == showStatusAnimation_) { | 644 NSLog(@"progress"); |
|
Nico
2011/07/04 16:39:02
remove
| |
| 635 titleY_ = (1 - progress)*kPrimaryTextOnlyPosTop + | 645 if (animation == toggleStatusVisibilityAnimation_) { |
| 636 kPrimaryTextPosTop; | 646 if (isStatusTextVisible_) { |
| 637 statusAlpha_ = progress; | 647 titleY_ = (1 - progress)*kPrimaryTextOnlyPosTop + kPrimaryTextPosTop; |
| 638 [[self controlView] setNeedsDisplay:YES]; | 648 statusAlpha_ = progress; |
| 639 } else if (animation == hideStatusAnimation_ || animation == nil) { | 649 } else { |
| 640 titleY_ = progress*kPrimaryTextOnlyPosTop + | 650 titleY_ = progress*kPrimaryTextOnlyPosTop + |
| 641 (1 - progress)*kPrimaryTextPosTop; | 651 (1 - progress)*kPrimaryTextPosTop; |
| 642 statusAlpha_ = 1 - progress; | 652 statusAlpha_ = 1 - progress; |
| 653 } | |
| 643 [[self controlView] setNeedsDisplay:YES]; | 654 [[self controlView] setNeedsDisplay:YES]; |
| 644 } else if (animation == completionAnimation_) { | 655 } else if (animation == completionAnimation_) { |
| 645 [[self controlView] setNeedsDisplay:YES]; | 656 [[self controlView] setNeedsDisplay:YES]; |
| 646 } | 657 } |
| 647 } | 658 } |
| 648 | 659 |
| 649 - (void)animationDidEnd:(NSAnimation *)animation { | 660 - (void)animationDidEnd:(NSAnimation *)animation { |
| 650 if (animation == showStatusAnimation_) | 661 if (animation == toggleStatusVisibilityAnimation_) |
| 651 showStatusAnimation_.reset(); | 662 toggleStatusVisibilityAnimation_.reset(); |
| 652 else if (animation == hideStatusAnimation_) | |
| 653 hideStatusAnimation_.reset(); | |
| 654 else if (animation == completionAnimation_) | 663 else if (animation == completionAnimation_) |
| 655 completionAnimation_.reset(); | 664 completionAnimation_.reset(); |
| 656 } | 665 } |
| 657 | 666 |
| 667 - (BOOL)isStatusTextVisible { | |
| 668 return isStatusTextVisible_; | |
| 669 } | |
| 670 | |
| 671 - (CGFloat)statusTextAlpha { | |
| 672 return statusAlpha_; | |
| 673 } | |
| 674 | |
| 675 - (void)skipVisibilityAnimation { | |
| 676 [toggleStatusVisibilityAnimation_ setCurrentProgress:1.0]; | |
| 677 } | |
| 678 | |
| 658 @end | 679 @end |
| 659 | 680 |
| 660 @implementation DownloadItemCellAnimation | 681 @implementation DownloadItemCellAnimation |
| 661 | 682 |
| 662 - (id)initWithDownloadItemCell:(DownloadItemCell*)cell | 683 - (id)initWithDownloadItemCell:(DownloadItemCell*)cell |
| 663 duration:(NSTimeInterval)duration | 684 duration:(NSTimeInterval)duration |
| 664 animationCurve:(NSAnimationCurve)animationCurve { | 685 animationCurve:(NSAnimationCurve)animationCurve { |
| 665 if ((self = [super gtm_initWithDuration:duration | 686 if ((self = [super gtm_initWithDuration:duration |
| 666 eventMask:NSLeftMouseDownMask | 687 eventMask:NSLeftMouseDownMask |
| 667 animationCurve:animationCurve])) { | 688 animationCurve:animationCurve])) { |
| 668 cell_ = cell; | 689 cell_ = cell; |
| 669 [self setAnimationBlockingMode:NSAnimationNonblocking]; | 690 [self setAnimationBlockingMode:NSAnimationNonblocking]; |
| 670 } | 691 } |
| 671 return self; | 692 return self; |
| 672 } | 693 } |
| 673 | 694 |
| 674 - (void)setCurrentProgress:(NSAnimationProgress)progress { | 695 - (void)setCurrentProgress:(NSAnimationProgress)progress { |
| 675 [super setCurrentProgress:progress]; | 696 [super setCurrentProgress:progress]; |
| 676 [cell_ animation:self progressed:progress]; | 697 [cell_ animation:self progressed:progress]; |
| 677 } | 698 } |
| 678 | 699 |
| 679 @end | 700 @end |
| OLD | NEW |