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

Side by Side Diff: chrome/browser/ui/cocoa/download/download_item_cell.mm

Issue 7272024: Fix regression: Download status doesn't appear anymore in the download-shelf (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixed Created 9 years, 5 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) 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 @interface DownloadItemCellAnimation : NSAnimation { 81 @interface DownloadItemCellAnimation : NSAnimation {
82 DownloadItemCell* cell_; 82 DownloadItemCell* cell_;
83 } 83 }
84 - (id)initWithDownloadItemCell:(DownloadItemCell*)cell 84 - (id)initWithDownloadItemCell:(DownloadItemCell*)cell
85 duration:(NSTimeInterval)duration 85 duration:(NSTimeInterval)duration
86 animationCurve:(NSAnimationCurve)animationCurve; 86 animationCurve:(NSAnimationCurve)animationCurve;
87 @end 87 @end
88 88
89 @interface DownloadItemCell(Private) 89 @interface DownloadItemCell(Private)
90 - (void)updateTrackingAreas:(id)sender; 90 - (void)updateTrackingAreas:(id)sender;
91 - (void)setupToggleStatusVisibilityAnimation;
91 - (void)showSecondaryTitle; 92 - (void)showSecondaryTitle;
92 - (void)hideSecondaryTitle; 93 - (void)hideSecondaryTitle;
93 - (void)animation:(NSAnimation*)animation 94 - (void)animation:(NSAnimation*)animation
94 progressed:(NSAnimationProgress)progress; 95 progressed:(NSAnimationProgress)progress;
95 - (NSString*)elideTitle:(int)availableWidth; 96 - (NSString*)elideTitle:(int)availableWidth;
96 - (NSString*)elideStatus:(int)availableWidth; 97 - (NSString*)elideStatus:(int)availableWidth;
97 - (ui::ThemeProvider*)backgroundThemeWrappingProvider: 98 - (ui::ThemeProvider*)backgroundThemeWrappingProvider:
98 (ui::ThemeProvider*)provider; 99 (ui::ThemeProvider*)provider;
99 - (BOOL)pressedWithDefaultThemeOnPart:(DownloadItemMousePosition)part; 100 - (BOOL)pressedWithDefaultThemeOnPart:(DownloadItemMousePosition)part;
100 - (NSColor*)titleColorForPart:(DownloadItemMousePosition)part; 101 - (NSColor*)titleColorForPart:(DownloadItemMousePosition)part;
101 - (void)drawSecondaryTitleInRect:(NSRect)innerFrame; 102 - (void)drawSecondaryTitleInRect:(NSRect)innerFrame;
102 @end 103 @end
103 104
104 @implementation DownloadItemCell 105 @implementation DownloadItemCell
105 106
106 @synthesize secondaryTitle = secondaryTitle_; 107 @synthesize secondaryTitle = secondaryTitle_;
107 @synthesize secondaryFont = secondaryFont_; 108 @synthesize secondaryFont = secondaryFont_;
108 109
109 - (void)setInitialState { 110 - (void)setInitialState {
110 isStatusTextVisible_ = NO; 111 isStatusTextVisible_ = NO;
111 titleY_ = kPrimaryTextPosTop; 112 titleY_ = kPrimaryTextPosTop;
112 statusAlpha_ = 1.0; 113 statusAlpha_ = 0.0;
113 114
114 [self setFont:[NSFont systemFontOfSize: 115 [self setFont:[NSFont systemFontOfSize:
115 [NSFont systemFontSizeForControlSize:NSSmallControlSize]]]; 116 [NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
116 [self setSecondaryFont:[NSFont systemFontOfSize: 117 [self setSecondaryFont:[NSFont systemFontOfSize:
117 [NSFont systemFontSizeForControlSize:NSSmallControlSize]]]; 118 [NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
118 119
119 [self updateTrackingAreas:self]; 120 [self updateTrackingAreas:self];
120 [[NSNotificationCenter defaultCenter] 121 [[NSNotificationCenter defaultCenter]
121 addObserver:self 122 addObserver:self
122 selector:@selector(updateTrackingAreas:) 123 selector:@selector(updateTrackingAreas:)
(...skipping 14 matching lines...) Expand all
137 if ((self = [super initTextCell:string])) { 138 if ((self = [super initTextCell:string])) {
138 [self setInitialState]; 139 [self setInitialState];
139 } 140 }
140 return self; 141 return self;
141 } 142 }
142 143
143 - (void)dealloc { 144 - (void)dealloc {
144 [[NSNotificationCenter defaultCenter] removeObserver:self]; 145 [[NSNotificationCenter defaultCenter] removeObserver:self];
145 if ([completionAnimation_ isAnimating]) 146 if ([completionAnimation_ isAnimating])
146 [completionAnimation_ stopAnimation]; 147 [completionAnimation_ stopAnimation];
147 if ([showStatusAnimation_ isAnimating]) 148 if ([toggleStatusVisibilityAnimation_ isAnimating])
148 [showStatusAnimation_ stopAnimation]; 149 [toggleStatusVisibilityAnimation_ stopAnimation];
149 if ([hideStatusAnimation_ isAnimating])
150 [hideStatusAnimation_ stopAnimation];
151 if (trackingAreaButton_) { 150 if (trackingAreaButton_) {
152 [[self controlView] removeTrackingArea:trackingAreaButton_]; 151 [[self controlView] removeTrackingArea:trackingAreaButton_];
153 trackingAreaButton_.reset(); 152 trackingAreaButton_.reset();
154 } 153 }
155 if (trackingAreaDropdown_) { 154 if (trackingAreaDropdown_) {
156 [[self controlView] removeTrackingArea:trackingAreaDropdown_]; 155 [[self controlView] removeTrackingArea:trackingAreaDropdown_];
157 trackingAreaDropdown_.reset(); 156 trackingAreaDropdown_.reset();
158 } 157 }
159 [secondaryTitle_ release]; 158 [secondaryTitle_ release];
160 [secondaryFont_ release]; 159 [secondaryFont_ release];
161 [super dealloc]; 160 [super dealloc];
162 } 161 }
163 162
164 - (void)setStateFromDownload:(BaseDownloadItemModel*)downloadModel { 163 - (void)setStateFromDownload:(BaseDownloadItemModel*)downloadModel {
165 // Set the name of the download. 164 // Set the name of the download.
166 downloadPath_ = downloadModel->download()->GetFileNameToReportUser(); 165 downloadPath_ = downloadModel->download()->GetFileNameToReportUser();
167 166
168 string16 statusText = downloadModel->GetStatusText(); 167 string16 statusText = downloadModel->GetStatusText();
169 if (statusText.empty()) { 168 if (statusText.empty()) {
170 // Remove the status text label. 169 // Remove the status text label.
171 [self hideSecondaryTitle]; 170 [self hideSecondaryTitle];
172 isStatusTextVisible_ = NO;
173 } else { 171 } else {
174 // Set status text. 172 // Set status text.
175 NSString* statusString = base::SysUTF16ToNSString(statusText); 173 NSString* statusString = base::SysUTF16ToNSString(statusText);
176 [self setSecondaryTitle:statusString]; 174 [self setSecondaryTitle:statusString];
177 [self showSecondaryTitle]; 175 [self showSecondaryTitle];
178 isStatusTextVisible_ = YES;
179 } 176 }
180 177
181 switch (downloadModel->download()->state()) { 178 switch (downloadModel->download()->state()) {
182 case DownloadItem::COMPLETE: 179 case DownloadItem::COMPLETE:
183 // Small downloads may start in a complete state due to asynchronous 180 // Small downloads may start in a complete state due to asynchronous
184 // notifications. In this case, we'll get a second complete notification 181 // 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 182 // via the observers, so we ignore it and avoid creating a second complete
186 // animation. 183 // animation.
187 if (completionAnimation_.get()) 184 if (completionAnimation_.get())
188 break; 185 break;
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 [triangle fill]; 588 [triangle fill];
592 } 589 }
593 590
594 - (NSRect)imageRectForBounds:(NSRect)cellFrame { 591 - (NSRect)imageRectForBounds:(NSRect)cellFrame {
595 return NSMakeRect(cellFrame.origin.x + kImagePaddingLeft, 592 return NSMakeRect(cellFrame.origin.x + kImagePaddingLeft,
596 cellFrame.origin.y + kImagePaddingTop, 593 cellFrame.origin.y + kImagePaddingTop,
597 kImageWidth, 594 kImageWidth,
598 kImageHeight); 595 kImageHeight);
599 } 596 }
600 597
601 - (void)showSecondaryTitle { 598 - (void)setupToggleStatusVisibilityAnimation {
602 if (!isStatusTextVisible_) { 599 if (toggleStatusVisibilityAnimation_ &&
603 // No core animation -- text in CA layers is not subpixel antialiased :-/ 600 [toggleStatusVisibilityAnimation_ isAnimating]) {
604 showStatusAnimation_.reset([[DownloadItemCellAnimation alloc] 601 // If the animation is running, cancel the animation and show/hide the
602 // status text immediately.
603 [toggleStatusVisibilityAnimation_ stopAnimation];
604 [self animation:toggleStatusVisibilityAnimation_ progressed:1.0];
605 toggleStatusVisibilityAnimation_.reset();
606 } else {
607 // Don't use core animation -- text in CA layers is not subpixel antialiased
608 toggleStatusVisibilityAnimation_.reset([[DownloadItemCellAnimation alloc]
605 initWithDownloadItemCell:self 609 initWithDownloadItemCell:self
606 duration:kShowStatusDuration 610 duration:kShowStatusDuration
607 animationCurve:NSAnimationEaseIn]); 611 animationCurve:NSAnimationEaseIn]);
608 [showStatusAnimation_.get() setDelegate:self]; 612 [toggleStatusVisibilityAnimation_.get() setDelegate:self];
609 [showStatusAnimation_.get() startAnimation]; 613 [toggleStatusVisibilityAnimation_.get() startAnimation];
610 } else {
611 // If the status line continues to be visible, don't show an animation
612 [self animation:nil progressed:0.0];
613 } 614 }
614 } 615 }
615 616
617 - (void)showSecondaryTitle {
618 if (isStatusTextVisible_)
619 return;
620 isStatusTextVisible_ = YES;
621 [self setupToggleStatusVisibilityAnimation];
622 }
623
616 - (void)hideSecondaryTitle { 624 - (void)hideSecondaryTitle {
617 if (isStatusTextVisible_) { 625 if (!isStatusTextVisible_)
618 // No core animation -- text in CA layers is not subpixel antialiased :-/ 626 return;
619 hideStatusAnimation_.reset([[DownloadItemCellAnimation alloc] 627 isStatusTextVisible_ = NO;
620 initWithDownloadItemCell:self 628 [self setupToggleStatusVisibilityAnimation];
621 duration:kHideStatusDuration
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,
627 // don't show an animation
628 [self animation:nil progressed:1.0];
629 }
630 } 629 }
631 630
632 - (void)animation:(NSAnimation*)animation 631 - (void)animation:(NSAnimation*)animation
633 progressed:(NSAnimationProgress)progress { 632 progressed:(NSAnimationProgress)progress {
634 if (animation == showStatusAnimation_) { 633 if (animation == toggleStatusVisibilityAnimation_) {
635 titleY_ = (1 - progress)*kPrimaryTextOnlyPosTop + 634 if (isStatusTextVisible_) {
636 kPrimaryTextPosTop; 635 titleY_ = (1 - progress)*kPrimaryTextOnlyPosTop + kPrimaryTextPosTop;
637 statusAlpha_ = progress; 636 statusAlpha_ = progress;
638 [[self controlView] setNeedsDisplay:YES]; 637 } else {
639 } else if (animation == hideStatusAnimation_ || animation == nil) { 638 titleY_ = progress*kPrimaryTextOnlyPosTop +
640 titleY_ = progress*kPrimaryTextOnlyPosTop + 639 (1 - progress)*kPrimaryTextPosTop;
641 (1 - progress)*kPrimaryTextPosTop; 640 statusAlpha_ = 1 - progress;
642 statusAlpha_ = 1 - progress; 641 }
643 [[self controlView] setNeedsDisplay:YES]; 642 [[self controlView] setNeedsDisplay:YES];
644 } else if (animation == completionAnimation_) { 643 } else if (animation == completionAnimation_) {
645 [[self controlView] setNeedsDisplay:YES]; 644 [[self controlView] setNeedsDisplay:YES];
646 } 645 }
647 } 646 }
648 647
649 - (void)animationDidEnd:(NSAnimation *)animation { 648 - (void)animationDidEnd:(NSAnimation *)animation {
650 if (animation == showStatusAnimation_) 649 if (animation == toggleStatusVisibilityAnimation_)
651 showStatusAnimation_.reset(); 650 toggleStatusVisibilityAnimation_.reset();
652 else if (animation == hideStatusAnimation_)
653 hideStatusAnimation_.reset();
654 else if (animation == completionAnimation_) 651 else if (animation == completionAnimation_)
655 completionAnimation_.reset(); 652 completionAnimation_.reset();
656 } 653 }
657 654
655 - (BOOL)isStatusTextVisible {
656 return isStatusTextVisible_;
657 }
658
659 - (CGFloat)statusTextAlpha {
660 return statusAlpha_;
661 }
662
663 - (void)skipVisibilityAnimation {
664 [toggleStatusVisibilityAnimation_ setCurrentProgress:1.0];
665 }
666
658 @end 667 @end
659 668
660 @implementation DownloadItemCellAnimation 669 @implementation DownloadItemCellAnimation
661 670
662 - (id)initWithDownloadItemCell:(DownloadItemCell*)cell 671 - (id)initWithDownloadItemCell:(DownloadItemCell*)cell
663 duration:(NSTimeInterval)duration 672 duration:(NSTimeInterval)duration
664 animationCurve:(NSAnimationCurve)animationCurve { 673 animationCurve:(NSAnimationCurve)animationCurve {
665 if ((self = [super gtm_initWithDuration:duration 674 if ((self = [super gtm_initWithDuration:duration
666 eventMask:NSLeftMouseDownMask 675 eventMask:NSLeftMouseDownMask
667 animationCurve:animationCurve])) { 676 animationCurve:animationCurve])) {
668 cell_ = cell; 677 cell_ = cell;
669 [self setAnimationBlockingMode:NSAnimationNonblocking]; 678 [self setAnimationBlockingMode:NSAnimationNonblocking];
670 } 679 }
671 return self; 680 return self;
672 } 681 }
673 682
674 - (void)setCurrentProgress:(NSAnimationProgress)progress { 683 - (void)setCurrentProgress:(NSAnimationProgress)progress {
675 [super setCurrentProgress:progress]; 684 [super setCurrentProgress:progress];
676 [cell_ animation:self progressed:progress]; 685 [cell_ animation:self progressed:progress];
677 } 686 }
678 687
679 @end 688 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/download/download_item_cell.h ('k') | chrome/browser/ui/cocoa/download/download_item_cell_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698