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

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

Issue 1236463002: Vectorize download shelf progress indicators (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 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
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 #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/bind.h" 7 #include "base/bind.h"
8 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.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_shelf.h" 10 #include "chrome/browser/download/download_shelf.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 NSTimeInterval kHideStatusDuration = 0.3; 69 NSTimeInterval kHideStatusDuration = 0.3;
70 70
71 // Duration of the 'download complete' animation, in seconds. 71 // Duration of the 'download complete' animation, in seconds.
72 const CGFloat kCompleteAnimationDuration = 2.5; 72 const CGFloat kCompleteAnimationDuration = 2.5;
73 73
74 // Duration of the 'download interrupted' animation, in seconds. 74 // Duration of the 'download interrupted' animation, in seconds.
75 const CGFloat kInterruptedAnimationDuration = 2.5; 75 const CGFloat kInterruptedAnimationDuration = 2.5;
76 76
77 using content::DownloadItem; 77 using content::DownloadItem;
78 78
79 namespace {
80
81 // Passed as a callback to DownloadShelf paint functions. On toolkit-views
82 // platforms it will mirror the position of the download progress, but that's
83 // not done on Mac.
84 void DummyRTLMirror(gfx::Rect* bounds) {
85 }
86
87 } // namespace
88
89 // This is a helper class to animate the fading out of the status text. 79 // This is a helper class to animate the fading out of the status text.
90 @interface DownloadItemCellAnimation : NSAnimation { 80 @interface DownloadItemCellAnimation : NSAnimation {
91 @private 81 @private
92 DownloadItemCell* cell_; 82 DownloadItemCell* cell_;
93 } 83 }
94 - (id)initWithDownloadItemCell:(DownloadItemCell*)cell 84 - (id)initWithDownloadItemCell:(DownloadItemCell*)cell
95 duration:(NSTimeInterval)duration 85 duration:(NSTimeInterval)duration
96 animationCurve:(NSAnimationCurve)animationCurve; 86 animationCurve:(NSAnimationCurve)animationCurve;
97 87
98 @end 88 @end
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 123
134 @implementation DownloadItemCell 124 @implementation DownloadItemCell
135 125
136 @synthesize secondaryTitle = secondaryTitle_; 126 @synthesize secondaryTitle = secondaryTitle_;
137 @synthesize secondaryFont = secondaryFont_; 127 @synthesize secondaryFont = secondaryFont_;
138 128
139 - (void)setInitialState { 129 - (void)setInitialState {
140 isStatusTextVisible_ = NO; 130 isStatusTextVisible_ = NO;
141 titleY_ = kPrimaryTextOnlyPosTop; 131 titleY_ = kPrimaryTextOnlyPosTop;
142 statusAlpha_ = 0.0; 132 statusAlpha_ = 0.0;
143 indeterminateProgressAngle_ = DownloadShelf::kStartAngleDegrees;
144 133
145 [self setFont:[NSFont systemFontOfSize: 134 [self setFont:[NSFont systemFontOfSize:
146 [NSFont systemFontSizeForControlSize:NSSmallControlSize]]]; 135 [NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
147 [self setSecondaryFont:[NSFont systemFontOfSize: 136 [self setSecondaryFont:[NSFont systemFontOfSize:
148 [NSFont systemFontSizeForControlSize:NSSmallControlSize]]]; 137 [NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
149 138
150 [self updateTrackingAreas:self]; 139 [self updateTrackingAreas:self];
151 [[NSNotificationCenter defaultCenter] 140 [[NSNotificationCenter defaultCenter]
152 addObserver:self 141 addObserver:self
153 selector:@selector(updateTrackingAreas:) 142 selector:@selector(updateTrackingAreas:)
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 break; 234 break;
246 case DownloadItem::IN_PROGRESS: 235 case DownloadItem::IN_PROGRESS:
247 if (downloadModel->download()->IsPaused()) { 236 if (downloadModel->download()->IsPaused()) {
248 percentDone_ = -1; 237 percentDone_ = -1;
249 [self stopIndeterminateAnimation]; 238 [self stopIndeterminateAnimation];
250 } else if (downloadModel->PercentComplete() == -1) { 239 } else if (downloadModel->PercentComplete() == -1) {
251 percentDone_ = -1; 240 percentDone_ = -1;
252 if (!indeterminateProgressTimer_) { 241 if (!indeterminateProgressTimer_) {
253 indeterminateProgressTimer_.reset([[IndeterminateProgressTimer alloc] 242 indeterminateProgressTimer_.reset([[IndeterminateProgressTimer alloc]
254 initWithDownloadItemCell:self]); 243 initWithDownloadItemCell:self]);
244 progressStartTime_ = base::TimeTicks::Now();
255 } 245 }
256 } else { 246 } else {
257 percentDone_ = downloadModel->PercentComplete(); 247 percentDone_ = downloadModel->PercentComplete();
258 [self stopIndeterminateAnimation]; 248 [self stopIndeterminateAnimation];
259 } 249 }
260 break; 250 break;
261 default: 251 default:
262 NOTREACHED(); 252 NOTREACHED();
263 } 253 }
264 254
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 NSPoint imagePosition = [self imageRectForBounds:cellFrame].origin; 545 NSPoint imagePosition = [self imageRectForBounds:cellFrame].origin;
556 int x = imagePosition.x - DownloadShelf::kSmallProgressIconOffset; 546 int x = imagePosition.x - DownloadShelf::kSmallProgressIconOffset;
557 int y = imagePosition.y - DownloadShelf::kSmallProgressIconOffset; 547 int y = imagePosition.y - DownloadShelf::kSmallProgressIconOffset;
558 NSRect dirtyRect = NSMakeRect( 548 NSRect dirtyRect = NSMakeRect(
559 x, y, 549 x, y,
560 DownloadShelf::kSmallProgressIconSize, 550 DownloadShelf::kSmallProgressIconSize,
561 DownloadShelf::kSmallProgressIconSize); 551 DownloadShelf::kSmallProgressIconSize);
562 552
563 gfx::CanvasSkiaPaint canvas(dirtyRect, false); 553 gfx::CanvasSkiaPaint canvas(dirtyRect, false);
564 canvas.set_composite_alpha(true); 554 canvas.set_composite_alpha(true);
555 canvas.Translate(gfx::Vector2d(x, y));
556
565 if (completionAnimation_.get()) { 557 if (completionAnimation_.get()) {
566 if ([completionAnimation_ isAnimating]) { 558 if ([completionAnimation_ isAnimating]) {
567 if (percentDone_ == -1) { 559 if (percentDone_ == -1) {
568 DownloadShelf::PaintDownloadComplete( 560 DownloadShelf::PaintDownloadComplete(
569 &canvas, base::Bind(&DummyRTLMirror), x, y, 561 &canvas, [completionAnimation_ currentValue]);
570 [completionAnimation_ currentValue]);
571 } else { 562 } else {
572 DownloadShelf::PaintDownloadInterrupted( 563 DownloadShelf::PaintDownloadInterrupted(
573 &canvas, base::Bind(&DummyRTLMirror), x, y, 564 &canvas, [completionAnimation_ currentValue]);
574 [completionAnimation_ currentValue]);
575 } 565 }
576 } 566 }
577 } else if (percentDone_ >= 0 || indeterminateProgressTimer_) { 567 } else if (percentDone_ >= 0 || indeterminateProgressTimer_) {
578 DownloadShelf::PaintDownloadProgress(&canvas, base::Bind(&DummyRTLMirror), 568 DownloadShelf::PaintDownloadProgress(&canvas, progressStartTime_,
579 x, y, indeterminateProgressAngle_,
580 percentDone_); 569 percentDone_);
581 } 570 }
582 } 571 }
583 572
584 // Draw icon 573 // Draw icon
585 [[self image] drawInRect:[self imageRectForBounds:cellFrame] 574 [[self image] drawInRect:[self imageRectForBounds:cellFrame]
586 fromRect:NSZeroRect 575 fromRect:NSZeroRect
587 operation:NSCompositeSourceOver 576 operation:NSCompositeSourceOver
588 fraction:[self isEnabled] ? 1.0 : 0.5 577 fraction:[self isEnabled] ? 1.0 : 0.5
589 respectFlipped:YES 578 respectFlipped:YES
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 (1 - progress)*kPrimaryTextPosTop; 671 (1 - progress)*kPrimaryTextPosTop;
683 statusAlpha_ = 1 - progress; 672 statusAlpha_ = 1 - progress;
684 } 673 }
685 [[self controlView] setNeedsDisplay:YES]; 674 [[self controlView] setNeedsDisplay:YES];
686 } else if (animation == completionAnimation_) { 675 } else if (animation == completionAnimation_) {
687 [[self controlView] setNeedsDisplay:YES]; 676 [[self controlView] setNeedsDisplay:YES];
688 } 677 }
689 } 678 }
690 679
691 - (void)updateIndeterminateDownload { 680 - (void)updateIndeterminateDownload {
692 indeterminateProgressAngle_ =
693 (indeterminateProgressAngle_ + DownloadShelf::kUnknownIncrementDegrees) %
694 DownloadShelf::kMaxDegrees;
695 [[self controlView] setNeedsDisplay:YES]; 681 [[self controlView] setNeedsDisplay:YES];
696 } 682 }
697 683
698 - (void)stopIndeterminateAnimation { 684 - (void)stopIndeterminateAnimation {
699 [indeterminateProgressTimer_ invalidate]; 685 [indeterminateProgressTimer_ invalidate];
700 indeterminateProgressTimer_.reset(); 686 indeterminateProgressTimer_.reset();
701 } 687 }
702 688
703 - (void)animationDidEnd:(NSAnimation *)animation { 689 - (void)animationDidEnd:(NSAnimation *)animation {
704 if (animation == toggleStatusVisibilityAnimation_) 690 if (animation == toggleStatusVisibilityAnimation_)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 749
764 - (void)invalidate { 750 - (void)invalidate {
765 [timer_ invalidate]; 751 [timer_ invalidate];
766 } 752 }
767 753
768 - (void)onTimer:(NSTimer*)timer { 754 - (void)onTimer:(NSTimer*)timer {
769 [cell_ updateIndeterminateDownload]; 755 [cell_ updateIndeterminateDownload];
770 } 756 }
771 757
772 @end 758 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698