| OLD | NEW |
| 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" |
| 11 #import "chrome/browser/themes/theme_properties.h" | 11 #import "chrome/browser/themes/theme_properties.h" |
| 12 #import "chrome/browser/ui/cocoa/download/background_theme.h" | 12 #import "chrome/browser/ui/cocoa/download/background_theme.h" |
| 13 #import "chrome/browser/ui/cocoa/themed_window.h" | 13 #import "chrome/browser/ui/cocoa/themed_window.h" |
| 14 #include "content/public/browser/download_item.h" | 14 #include "content/public/browser/download_item.h" |
| 15 #include "content/public/browser/download_manager.h" | 15 #include "content/public/browser/download_manager.h" |
| 16 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 17 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h
" | 17 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h
" |
| 18 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSColor+Luminance.h" | 18 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSColor+Luminance.h" |
| 19 #include "ui/gfx/canvas_skia_paint.h" | 19 #include "ui/gfx/canvas_skia_paint.h" |
| 20 #include "ui/gfx/font_list.h" | 20 #include "ui/gfx/font_list.h" |
| 21 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 21 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 22 #include "ui/gfx/text_elider.h" | 22 #include "ui/gfx/text_elider.h" |
| 23 #include "ui/native_theme/native_theme.h" |
| 23 | 24 |
| 24 // Distance from top border to icon. | 25 // Distance from top border to icon. |
| 25 const CGFloat kImagePaddingTop = 7; | 26 const CGFloat kImagePaddingTop = 7; |
| 26 | 27 |
| 27 // Distance from left border to icon. | 28 // Distance from left border to icon. |
| 28 const CGFloat kImagePaddingLeft = 9; | 29 const CGFloat kImagePaddingLeft = 9; |
| 29 | 30 |
| 30 // Width of icon. | 31 // Width of icon. |
| 31 const CGFloat kImageWidth = 16; | 32 const CGFloat kImageWidth = 16; |
| 32 | 33 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 NSTimeInterval kHideStatusDuration = 0.3; | 70 NSTimeInterval kHideStatusDuration = 0.3; |
| 70 | 71 |
| 71 // Duration of the 'download complete' animation, in seconds. | 72 // Duration of the 'download complete' animation, in seconds. |
| 72 const CGFloat kCompleteAnimationDuration = 2.5; | 73 const CGFloat kCompleteAnimationDuration = 2.5; |
| 73 | 74 |
| 74 // Duration of the 'download interrupted' animation, in seconds. | 75 // Duration of the 'download interrupted' animation, in seconds. |
| 75 const CGFloat kInterruptedAnimationDuration = 2.5; | 76 const CGFloat kInterruptedAnimationDuration = 2.5; |
| 76 | 77 |
| 77 using content::DownloadItem; | 78 using content::DownloadItem; |
| 78 | 79 |
| 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. | 80 // This is a helper class to animate the fading out of the status text. |
| 90 @interface DownloadItemCellAnimation : NSAnimation { | 81 @interface DownloadItemCellAnimation : NSAnimation { |
| 91 @private | 82 @private |
| 92 DownloadItemCell* cell_; | 83 DownloadItemCell* cell_; |
| 93 } | 84 } |
| 94 - (id)initWithDownloadItemCell:(DownloadItemCell*)cell | 85 - (id)initWithDownloadItemCell:(DownloadItemCell*)cell |
| 95 duration:(NSTimeInterval)duration | 86 duration:(NSTimeInterval)duration |
| 96 animationCurve:(NSAnimationCurve)animationCurve; | 87 animationCurve:(NSAnimationCurve)animationCurve; |
| 97 | 88 |
| 98 @end | 89 @end |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 124 |
| 134 @implementation DownloadItemCell | 125 @implementation DownloadItemCell |
| 135 | 126 |
| 136 @synthesize secondaryTitle = secondaryTitle_; | 127 @synthesize secondaryTitle = secondaryTitle_; |
| 137 @synthesize secondaryFont = secondaryFont_; | 128 @synthesize secondaryFont = secondaryFont_; |
| 138 | 129 |
| 139 - (void)setInitialState { | 130 - (void)setInitialState { |
| 140 isStatusTextVisible_ = NO; | 131 isStatusTextVisible_ = NO; |
| 141 titleY_ = kPrimaryTextOnlyPosTop; | 132 titleY_ = kPrimaryTextOnlyPosTop; |
| 142 statusAlpha_ = 0.0; | 133 statusAlpha_ = 0.0; |
| 143 indeterminateProgressAngle_ = DownloadShelf::kStartAngleDegrees; | |
| 144 | 134 |
| 145 [self setFont:[NSFont systemFontOfSize: | 135 [self setFont:[NSFont systemFontOfSize: |
| 146 [NSFont systemFontSizeForControlSize:NSSmallControlSize]]]; | 136 [NSFont systemFontSizeForControlSize:NSSmallControlSize]]]; |
| 147 [self setSecondaryFont:[NSFont systemFontOfSize: | 137 [self setSecondaryFont:[NSFont systemFontOfSize: |
| 148 [NSFont systemFontSizeForControlSize:NSSmallControlSize]]]; | 138 [NSFont systemFontSizeForControlSize:NSSmallControlSize]]]; |
| 149 | 139 |
| 150 [self updateTrackingAreas:self]; | 140 [self updateTrackingAreas:self]; |
| 151 [[NSNotificationCenter defaultCenter] | 141 [[NSNotificationCenter defaultCenter] |
| 152 addObserver:self | 142 addObserver:self |
| 153 selector:@selector(updateTrackingAreas:) | 143 selector:@selector(updateTrackingAreas:) |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 break; | 235 break; |
| 246 case DownloadItem::IN_PROGRESS: | 236 case DownloadItem::IN_PROGRESS: |
| 247 if (downloadModel->download()->IsPaused()) { | 237 if (downloadModel->download()->IsPaused()) { |
| 248 percentDone_ = -1; | 238 percentDone_ = -1; |
| 249 [self stopIndeterminateAnimation]; | 239 [self stopIndeterminateAnimation]; |
| 250 } else if (downloadModel->PercentComplete() == -1) { | 240 } else if (downloadModel->PercentComplete() == -1) { |
| 251 percentDone_ = -1; | 241 percentDone_ = -1; |
| 252 if (!indeterminateProgressTimer_) { | 242 if (!indeterminateProgressTimer_) { |
| 253 indeterminateProgressTimer_.reset([[IndeterminateProgressTimer alloc] | 243 indeterminateProgressTimer_.reset([[IndeterminateProgressTimer alloc] |
| 254 initWithDownloadItemCell:self]); | 244 initWithDownloadItemCell:self]); |
| 245 progressStartTime_ = base::TimeTicks::Now(); |
| 255 } | 246 } |
| 256 } else { | 247 } else { |
| 257 percentDone_ = downloadModel->PercentComplete(); | 248 percentDone_ = downloadModel->PercentComplete(); |
| 258 [self stopIndeterminateAnimation]; | 249 [self stopIndeterminateAnimation]; |
| 259 } | 250 } |
| 260 break; | 251 break; |
| 261 default: | 252 default: |
| 262 NOTREACHED(); | 253 NOTREACHED(); |
| 263 } | 254 } |
| 264 | 255 |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 NSPoint imagePosition = [self imageRectForBounds:cellFrame].origin; | 546 NSPoint imagePosition = [self imageRectForBounds:cellFrame].origin; |
| 556 int x = imagePosition.x - DownloadShelf::kSmallProgressIconOffset; | 547 int x = imagePosition.x - DownloadShelf::kSmallProgressIconOffset; |
| 557 int y = imagePosition.y - DownloadShelf::kSmallProgressIconOffset; | 548 int y = imagePosition.y - DownloadShelf::kSmallProgressIconOffset; |
| 558 NSRect dirtyRect = NSMakeRect( | 549 NSRect dirtyRect = NSMakeRect( |
| 559 x, y, | 550 x, y, |
| 560 DownloadShelf::kSmallProgressIconSize, | 551 DownloadShelf::kSmallProgressIconSize, |
| 561 DownloadShelf::kSmallProgressIconSize); | 552 DownloadShelf::kSmallProgressIconSize); |
| 562 | 553 |
| 563 gfx::CanvasSkiaPaint canvas(dirtyRect, false); | 554 gfx::CanvasSkiaPaint canvas(dirtyRect, false); |
| 564 canvas.set_composite_alpha(true); | 555 canvas.set_composite_alpha(true); |
| 556 canvas.Translate(gfx::Vector2d(x, y)); |
| 557 |
| 565 if (completionAnimation_.get()) { | 558 if (completionAnimation_.get()) { |
| 566 if ([completionAnimation_ isAnimating]) { | 559 if ([completionAnimation_ isAnimating]) { |
| 567 if (percentDone_ == -1) { | 560 if (percentDone_ == -1) { |
| 568 DownloadShelf::PaintDownloadComplete( | 561 DownloadShelf::PaintDownloadComplete( |
| 569 &canvas, base::Bind(&DummyRTLMirror), x, y, | 562 &canvas, *[[self window] themeProvider], |
| 570 [completionAnimation_ currentValue]); | 563 [completionAnimation_ currentValue]); |
| 571 } else { | 564 } else { |
| 572 DownloadShelf::PaintDownloadInterrupted( | 565 DownloadShelf::PaintDownloadInterrupted( |
| 573 &canvas, base::Bind(&DummyRTLMirror), x, y, | 566 &canvas, *[[self window] themeProvider], |
| 574 [completionAnimation_ currentValue]); | 567 [completionAnimation_ currentValue]); |
| 575 } | 568 } |
| 576 } | 569 } |
| 577 } else if (percentDone_ >= 0 || indeterminateProgressTimer_) { | 570 } else if (percentDone_ >= 0 || indeterminateProgressTimer_) { |
| 578 DownloadShelf::PaintDownloadProgress(&canvas, base::Bind(&DummyRTLMirror), | 571 DownloadShelf::PaintDownloadProgress(&canvas, |
| 579 x, y, indeterminateProgressAngle_, | 572 *[[self window] themeProvider], |
| 580 percentDone_); | 573 progressStartTime_, percentDone_); |
| 581 } | 574 } |
| 582 } | 575 } |
| 583 | 576 |
| 584 // Draw icon | 577 // Draw icon |
| 585 [[self image] drawInRect:[self imageRectForBounds:cellFrame] | 578 [[self image] drawInRect:[self imageRectForBounds:cellFrame] |
| 586 fromRect:NSZeroRect | 579 fromRect:NSZeroRect |
| 587 operation:NSCompositeSourceOver | 580 operation:NSCompositeSourceOver |
| 588 fraction:[self isEnabled] ? 1.0 : 0.5 | 581 fraction:[self isEnabled] ? 1.0 : 0.5 |
| 589 respectFlipped:YES | 582 respectFlipped:YES |
| 590 hints:nil]; | 583 hints:nil]; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 (1 - progress)*kPrimaryTextPosTop; | 675 (1 - progress)*kPrimaryTextPosTop; |
| 683 statusAlpha_ = 1 - progress; | 676 statusAlpha_ = 1 - progress; |
| 684 } | 677 } |
| 685 [[self controlView] setNeedsDisplay:YES]; | 678 [[self controlView] setNeedsDisplay:YES]; |
| 686 } else if (animation == completionAnimation_) { | 679 } else if (animation == completionAnimation_) { |
| 687 [[self controlView] setNeedsDisplay:YES]; | 680 [[self controlView] setNeedsDisplay:YES]; |
| 688 } | 681 } |
| 689 } | 682 } |
| 690 | 683 |
| 691 - (void)updateIndeterminateDownload { | 684 - (void)updateIndeterminateDownload { |
| 692 indeterminateProgressAngle_ = | |
| 693 (indeterminateProgressAngle_ + DownloadShelf::kUnknownIncrementDegrees) % | |
| 694 DownloadShelf::kMaxDegrees; | |
| 695 [[self controlView] setNeedsDisplay:YES]; | 685 [[self controlView] setNeedsDisplay:YES]; |
| 696 } | 686 } |
| 697 | 687 |
| 698 - (void)stopIndeterminateAnimation { | 688 - (void)stopIndeterminateAnimation { |
| 699 [indeterminateProgressTimer_ invalidate]; | 689 [indeterminateProgressTimer_ invalidate]; |
| 700 indeterminateProgressTimer_.reset(); | 690 indeterminateProgressTimer_.reset(); |
| 701 } | 691 } |
| 702 | 692 |
| 703 - (void)animationDidEnd:(NSAnimation *)animation { | 693 - (void)animationDidEnd:(NSAnimation *)animation { |
| 704 if (animation == toggleStatusVisibilityAnimation_) | 694 if (animation == toggleStatusVisibilityAnimation_) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 | 753 |
| 764 - (void)invalidate { | 754 - (void)invalidate { |
| 765 [timer_ invalidate]; | 755 [timer_ invalidate]; |
| 766 } | 756 } |
| 767 | 757 |
| 768 - (void)onTimer:(NSTimer*)timer { | 758 - (void)onTimer:(NSTimer*)timer { |
| 769 [cell_ updateIndeterminateDownload]; | 759 [cell_ updateIndeterminateDownload]; |
| 770 } | 760 } |
| 771 | 761 |
| 772 @end | 762 @end |
| OLD | NEW |