| 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" |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 break; | 245 break; |
| 246 case DownloadItem::IN_PROGRESS: | 246 case DownloadItem::IN_PROGRESS: |
| 247 if (downloadModel->download()->IsPaused()) { | 247 if (downloadModel->download()->IsPaused()) { |
| 248 percentDone_ = -1; | 248 percentDone_ = -1; |
| 249 [self stopIndeterminateAnimation]; | 249 [self stopIndeterminateAnimation]; |
| 250 } else if (downloadModel->PercentComplete() == -1) { | 250 } else if (downloadModel->PercentComplete() == -1) { |
| 251 percentDone_ = -1; | 251 percentDone_ = -1; |
| 252 if (!indeterminateProgressTimer_) { | 252 if (!indeterminateProgressTimer_) { |
| 253 indeterminateProgressTimer_.reset([[IndeterminateProgressTimer alloc] | 253 indeterminateProgressTimer_.reset([[IndeterminateProgressTimer alloc] |
| 254 initWithDownloadItemCell:self]); | 254 initWithDownloadItemCell:self]); |
| 255 progressStartTime_ = base::TimeTicks::Now(); |
| 255 } | 256 } |
| 256 } else { | 257 } else { |
| 257 percentDone_ = downloadModel->PercentComplete(); | 258 percentDone_ = downloadModel->PercentComplete(); |
| 258 [self stopIndeterminateAnimation]; | 259 [self stopIndeterminateAnimation]; |
| 259 } | 260 } |
| 260 break; | 261 break; |
| 261 default: | 262 default: |
| 262 NOTREACHED(); | 263 NOTREACHED(); |
| 263 } | 264 } |
| 264 | 265 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 | 554 |
| 554 // Always repaint the whole disk. | 555 // Always repaint the whole disk. |
| 555 NSPoint imagePosition = [self imageRectForBounds:cellFrame].origin; | 556 NSPoint imagePosition = [self imageRectForBounds:cellFrame].origin; |
| 556 int x = imagePosition.x - DownloadShelf::kSmallProgressIconOffset; | 557 int x = imagePosition.x - DownloadShelf::kSmallProgressIconOffset; |
| 557 int y = imagePosition.y - DownloadShelf::kSmallProgressIconOffset; | 558 int y = imagePosition.y - DownloadShelf::kSmallProgressIconOffset; |
| 558 NSRect dirtyRect = NSMakeRect( | 559 NSRect dirtyRect = NSMakeRect( |
| 559 x, y, | 560 x, y, |
| 560 DownloadShelf::kSmallProgressIconSize, | 561 DownloadShelf::kSmallProgressIconSize, |
| 561 DownloadShelf::kSmallProgressIconSize); | 562 DownloadShelf::kSmallProgressIconSize); |
| 562 | 563 |
| 564 canvas.Save(); |
| 565 canvas.Translate(gfx::Vector2d(x, y)); |
| 566 |
| 563 gfx::CanvasSkiaPaint canvas(dirtyRect, false); | 567 gfx::CanvasSkiaPaint canvas(dirtyRect, false); |
| 564 canvas.set_composite_alpha(true); | 568 canvas.set_composite_alpha(true); |
| 565 if (completionAnimation_.get()) { | 569 if (completionAnimation_.get()) { |
| 566 if ([completionAnimation_ isAnimating]) { | 570 if ([completionAnimation_ isAnimating]) { |
| 567 if (percentDone_ == -1) { | 571 if (percentDone_ == -1) { |
| 568 DownloadShelf::PaintDownloadComplete( | 572 DownloadShelf::PaintDownloadComplete( |
| 569 &canvas, base::Bind(&DummyRTLMirror), x, y, | 573 &canvas, [completionAnimation_ currentValue]); |
| 570 [completionAnimation_ currentValue]); | |
| 571 } else { | 574 } else { |
| 572 DownloadShelf::PaintDownloadInterrupted( | 575 DownloadShelf::PaintDownloadInterrupted( |
| 573 &canvas, base::Bind(&DummyRTLMirror), x, y, | 576 &canvas, [completionAnimation_ currentValue]); |
| 574 [completionAnimation_ currentValue]); | |
| 575 } | 577 } |
| 576 } | 578 } |
| 577 } else if (percentDone_ >= 0 || indeterminateProgressTimer_) { | 579 } else if (percentDone_ >= 0 || indeterminateProgressTimer_) { |
| 578 DownloadShelf::PaintDownloadProgress(&canvas, base::Bind(&DummyRTLMirror), | 580 DownloadShelf::PaintDownloadProgress(&canvas, progressStartTime_, |
| 579 x, y, indeterminateProgressAngle_, | |
| 580 percentDone_); | 581 percentDone_); |
| 581 } | 582 } |
| 583 |
| 584 canvas.Restore(); |
| 582 } | 585 } |
| 583 | 586 |
| 584 // Draw icon | 587 // Draw icon |
| 585 [[self image] drawInRect:[self imageRectForBounds:cellFrame] | 588 [[self image] drawInRect:[self imageRectForBounds:cellFrame] |
| 586 fromRect:NSZeroRect | 589 fromRect:NSZeroRect |
| 587 operation:NSCompositeSourceOver | 590 operation:NSCompositeSourceOver |
| 588 fraction:[self isEnabled] ? 1.0 : 0.5 | 591 fraction:[self isEnabled] ? 1.0 : 0.5 |
| 589 respectFlipped:YES | 592 respectFlipped:YES |
| 590 hints:nil]; | 593 hints:nil]; |
| 591 | 594 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 (1 - progress)*kPrimaryTextPosTop; | 685 (1 - progress)*kPrimaryTextPosTop; |
| 683 statusAlpha_ = 1 - progress; | 686 statusAlpha_ = 1 - progress; |
| 684 } | 687 } |
| 685 [[self controlView] setNeedsDisplay:YES]; | 688 [[self controlView] setNeedsDisplay:YES]; |
| 686 } else if (animation == completionAnimation_) { | 689 } else if (animation == completionAnimation_) { |
| 687 [[self controlView] setNeedsDisplay:YES]; | 690 [[self controlView] setNeedsDisplay:YES]; |
| 688 } | 691 } |
| 689 } | 692 } |
| 690 | 693 |
| 691 - (void)updateIndeterminateDownload { | 694 - (void)updateIndeterminateDownload { |
| 692 indeterminateProgressAngle_ = | |
| 693 (indeterminateProgressAngle_ + DownloadShelf::kUnknownIncrementDegrees) % | |
| 694 DownloadShelf::kMaxDegrees; | |
| 695 [[self controlView] setNeedsDisplay:YES]; | 695 [[self controlView] setNeedsDisplay:YES]; |
| 696 } | 696 } |
| 697 | 697 |
| 698 - (void)stopIndeterminateAnimation { | 698 - (void)stopIndeterminateAnimation { |
| 699 [indeterminateProgressTimer_ invalidate]; | 699 [indeterminateProgressTimer_ invalidate]; |
| 700 indeterminateProgressTimer_.reset(); | 700 indeterminateProgressTimer_.reset(); |
| 701 } | 701 } |
| 702 | 702 |
| 703 - (void)animationDidEnd:(NSAnimation *)animation { | 703 - (void)animationDidEnd:(NSAnimation *)animation { |
| 704 if (animation == toggleStatusVisibilityAnimation_) | 704 if (animation == toggleStatusVisibilityAnimation_) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 | 763 |
| 764 - (void)invalidate { | 764 - (void)invalidate { |
| 765 [timer_ invalidate]; | 765 [timer_ invalidate]; |
| 766 } | 766 } |
| 767 | 767 |
| 768 - (void)onTimer:(NSTimer*)timer { | 768 - (void)onTimer:(NSTimer*)timer { |
| 769 [cell_ updateIndeterminateDownload]; | 769 [cell_ updateIndeterminateDownload]; |
| 770 } | 770 } |
| 771 | 771 |
| 772 @end | 772 @end |
| OLD | NEW |