summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-19 20:47:26 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-19 20:47:26 +0000
commitfa47f1d6f6b26628080b5277f40dbcfafa571db1 (patch)
tree025a33078e287bc4b77dc7243ec24e2aa870bb88 /chrome
parent300cc58db6bc8d78e279dc07c46f15d9702148c6 (diff)
downloadchromium_src-fa47f1d6f6b26628080b5277f40dbcfafa571db1.zip
chromium_src-fa47f1d6f6b26628080b5277f40dbcfafa571db1.tar.gz
chromium_src-fa47f1d6f6b26628080b5277f40dbcfafa571db1.tar.bz2
Add progress disks to os x download items. Some more spacing tweaks. Still not done.
BUG=18902 TEST=download something, note that a green disk appears, and disappears after some flashing after the download is done. Review URL: http://codereview.chromium.org/174048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23740 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/app/nibs/DownloadItem.xib4
-rw-r--r--chrome/app/nibs/DownloadShelf.xib2
-rw-r--r--chrome/browser/cocoa/download_item_cell.h2
-rw-r--r--chrome/browser/cocoa/download_item_cell.mm124
4 files changed, 106 insertions, 26 deletions
diff --git a/chrome/app/nibs/DownloadItem.xib b/chrome/app/nibs/DownloadItem.xib
index 11abe7a..79b056e 100644
--- a/chrome/app/nibs/DownloadItem.xib
+++ b/chrome/app/nibs/DownloadItem.xib
@@ -9,7 +9,7 @@
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="17"/>
- <integer value="66"/>
+ <integer value="1"/>
<integer value="24"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
@@ -200,7 +200,7 @@
<object class="NSButton" id="575090266">
<reference key="NSNextResponder" ref="1005"/>
<int key="NSvFlags">292</int>
- <string key="NSFrameSize">{200, 34}</string>
+ <string key="NSFrameSize">{207, 34}</string>
<reference key="NSSuperview" ref="1005"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="966513665">
diff --git a/chrome/app/nibs/DownloadShelf.xib b/chrome/app/nibs/DownloadShelf.xib
index 9ea3dc12..fd17c97f 100644
--- a/chrome/app/nibs/DownloadShelf.xib
+++ b/chrome/app/nibs/DownloadShelf.xib
@@ -327,7 +327,7 @@
<object class="NSCustomView" id="931787328">
<reference key="NSNextResponder" ref="1005"/>
<int key="NSvFlags">258</int>
- <string key="NSFrame">{{3, 5}, {240, 34}}</string>
+ <string key="NSFrame">{{3, 6}, {240, 34}}</string>
<reference key="NSSuperview" ref="1005"/>
<string key="NSClassName">NSView</string>
</object>
diff --git a/chrome/browser/cocoa/download_item_cell.h b/chrome/browser/cocoa/download_item_cell.h
index e2c5162..b23f8b5 100644
--- a/chrome/browser/cocoa/download_item_cell.h
+++ b/chrome/browser/cocoa/download_item_cell.h
@@ -34,6 +34,8 @@ enum DownloadItemMousePosition {
FilePath downloadPath_; // stored unelided
NSString* secondaryTitle_;
NSFont* secondaryFont_;
+ int percentDone_;
+ scoped_nsobject<NSAnimation> completionAnimation_;
BOOL isStatusTextVisible_;
CGFloat titleY_;
diff --git a/chrome/browser/cocoa/download_item_cell.mm b/chrome/browser/cocoa/download_item_cell.mm
index 795cc99..81e25d1 100644
--- a/chrome/browser/cocoa/download_item_cell.mm
+++ b/chrome/browser/cocoa/download_item_cell.mm
@@ -4,6 +4,7 @@
#import "chrome/browser/cocoa/download_item_cell.h"
+#include "app/gfx/canvas_paint.h"
#include "app/gfx/text_elider.h"
#include "app/l10n_util.h"
#include "base/mac_util.h"
@@ -11,15 +12,16 @@
#import "chrome/browser/cocoa/download_item_cell.h"
#include "chrome/browser/download/download_item_model.h"
#include "chrome/browser/download/download_manager.h"
+#include "chrome/browser/download/download_util.h"
#import "third_party/GTM/AppKit/GTMTheme.h"
namespace {
// Distance from top border to icon
-const CGFloat kImagePaddingTop = 8;
+const CGFloat kImagePaddingTop = 7;
// Distance from left border to icon
-const CGFloat kImagePaddingLeft = 5;
+const CGFloat kImagePaddingLeft = 8;
// Width of icon
const CGFloat kImageWidth = 16;
@@ -28,7 +30,8 @@ const CGFloat kImageWidth = 16;
const CGFloat kImageHeight = 16;
// x coordinate of download name string, in view coords
-const CGFloat kTextPosLeft = kImagePaddingLeft + kImageWidth + 4 + 1;
+const CGFloat kTextPosLeft = kImagePaddingLeft +
+ kImageWidth + download_util::kSmallProgressIconOffset;
// Distance from end of download name string to dropdown area
const CGFloat kTextPaddingRight = 3;
@@ -57,19 +60,25 @@ const CGFloat kDropdownArrowHeight = 3;
// Duration of the two-lines-to-one-line animation, in seconds
NSTimeInterval kHideStatusDuration = 0.3;
+// Duration of the 'download complete' animation, in seconds
+const int kCompleteAnimationDuration = 2.5;
+
}
// This is a helper class to animate the fading out of the status text.
-@interface HideSecondaryTitleAnimation : NSAnimation {
+@interface DownloadItemCellAnimation : NSAnimation {
DownloadItemCell* cell_;
}
-- (id)initWithDownloadItemCell:(DownloadItemCell*)cell;
+- (id)initWithDownloadItemCell:(DownloadItemCell*)cell
+ duration:(NSTimeInterval)duration
+ animationCurve:(NSAnimationCurve)animationCurve;
@end
@interface DownloadItemCell(Private)
- (void)updateTrackingAreas:(id)sender;
- (void)hideSecondaryTitle;
-- (void)animationProgressed:(NSAnimationProgress)progress;
+- (void)animation:(NSAnimation*)animation
+ progressed:(NSAnimationProgress)progress;
@end
@implementation DownloadItemCell
@@ -134,6 +143,27 @@ NSTimeInterval kHideStatusDuration = 0.3;
isStatusTextVisible_ = YES;
}
+ switch (downloadModel->download()->state()) {
+ case DownloadItem::COMPLETE:
+ completionAnimation_.reset([[DownloadItemCellAnimation alloc]
+ initWithDownloadItemCell:self
+ duration:kCompleteAnimationDuration
+ animationCurve:NSAnimationLinear]);
+ [completionAnimation_.get() setDelegate:self];
+ [completionAnimation_.get() startAnimation];
+ percentDone_ = -1;
+ break;
+ case DownloadItem::CANCELLED:
+ percentDone_ = -1;
+ break;
+ case DownloadItem::IN_PROGRESS:
+ percentDone_ = downloadModel->download()->is_paused() ?
+ -1 : downloadModel->download()->PercentComplete();
+ break;
+ default:
+ NOTREACHED();
+ }
+
[[self controlView] setNeedsDisplay:YES];
}
@@ -263,8 +293,8 @@ NSTimeInterval kHideStatusDuration = 0.3;
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
// Constants from Cole. Will kConstant them once the feedback loop
// is complete.
- NSRect drawFrame = NSInsetRect(cellFrame, 0.5, 0.5);
- NSRect innerFrame = NSInsetRect(cellFrame, 1, 1);
+ NSRect drawFrame = NSInsetRect(cellFrame, 1.5, 1.5);
+ NSRect innerFrame = NSInsetRect(cellFrame, 2, 2);
const float radius = 5;
NSWindow* window = [controlView window];
@@ -346,6 +376,39 @@ NSTimeInterval kHideStatusDuration = 0.3;
withAttributes:secondaryTextAttributes];
}
+ // Draw progress disk
+ {
+ // CanvasPaint draws its content to the current NSGraphicsContext in its
+ // destructor, which needs to be invoked before the icon is drawn below -
+ // hence this nested block.
+
+ // Always repaint the whole disk.
+ NSPoint imagePosition = [self imageRectForBounds:cellFrame].origin;
+ int x = imagePosition.x - download_util::kSmallProgressIconOffset;
+ int y = imagePosition.y - download_util::kSmallProgressIconOffset;
+ NSRect dirtyRect = NSMakeRect(
+ x, y,
+ download_util::kSmallProgressIconSize,
+ download_util::kSmallProgressIconSize);
+
+ gfx::CanvasPaint canvas(dirtyRect, false);
+ canvas.set_composite_alpha(true);
+ if (completionAnimation_.get()) {
+ if ([completionAnimation_ isAnimating]) {
+ download_util::PaintDownloadComplete(&canvas,
+ x, y,
+ [completionAnimation_ currentValue],
+ download_util::SMALL);
+ }
+ } else if (percentDone_ >= 0) {
+ download_util::PaintDownloadProgress(&canvas,
+ x, y,
+ download_util::kStartAngleDegrees, // TODO(thakis): Animate
+ percentDone_,
+ download_util::SMALL);
+ }
+ }
+
// Draw icon
NSRect imageRect = NSZeroRect;
imageRect.size = [[self image] size];
@@ -377,41 +440,56 @@ NSTimeInterval kHideStatusDuration = 0.3;
}
- (NSRect)imageRectForBounds:(NSRect)cellFrame {
- return NSMakeRect(
- kImagePaddingLeft, kImagePaddingTop, kImageWidth, kImageHeight);
+ return NSMakeRect(cellFrame.origin.x + kImagePaddingLeft,
+ cellFrame.origin.y + kImagePaddingTop,
+ kImageWidth,
+ kImageHeight);
}
- (void)hideSecondaryTitle {
if (isStatusTextVisible_) {
// No core animation -- text in CA layers is not subpixel antialiased :-/
- hideStatusAnimation_.reset([[HideSecondaryTitleAnimation alloc]
- initWithDownloadItemCell:self]);
+ hideStatusAnimation_.reset([[DownloadItemCellAnimation alloc]
+ initWithDownloadItemCell:self
+ duration:kHideStatusDuration
+ animationCurve:NSAnimationEaseIn]);
[hideStatusAnimation_.get() setDelegate:self];
[hideStatusAnimation_.get() startAnimation];
} else {
// If the download is done so quickly that the status line is never visible,
// don't show an animation
- [self animationProgressed:1.0];
+ [self animation:nil progressed:1.0];
}
}
-- (void)animationProgressed:(NSAnimationProgress)progress {
- titleY_ = progress*kPrimaryTextOnlyPosTop + (1 - progress)*kPrimaryTextPosTop;
- statusAlpha_ = 1 - progress;
- [[self controlView] setNeedsDisplay:YES];
+- (void)animation:(NSAnimation*)animation
+ progressed:(NSAnimationProgress)progress {
+ if (animation == hideStatusAnimation_ || animation == nil) {
+ titleY_ = progress*kPrimaryTextOnlyPosTop +
+ (1 - progress)*kPrimaryTextPosTop;
+ statusAlpha_ = 1 - progress;
+ [[self controlView] setNeedsDisplay:YES];
+ } else if (animation == completionAnimation_) {
+ [[self controlView] setNeedsDisplay:YES];
+ }
}
- (void)animationDidEnd:(NSAnimation *)animation {
- hideStatusAnimation_.reset();
+ if (animation == hideStatusAnimation_)
+ hideStatusAnimation_.reset();
+ else if (animation == completionAnimation_)
+ completionAnimation_.reset();
}
@end
-@implementation HideSecondaryTitleAnimation
+@implementation DownloadItemCellAnimation
-- (id)initWithDownloadItemCell:(DownloadItemCell*)cell {
- if ((self = [super initWithDuration:kHideStatusDuration
- animationCurve:NSAnimationEaseIn])) {
+- (id)initWithDownloadItemCell:(DownloadItemCell*)cell
+ duration:(NSTimeInterval)duration
+ animationCurve:(NSAnimationCurve)animationCurve {
+ if ((self = [super initWithDuration:duration
+ animationCurve:animationCurve])) {
cell_ = cell;
[self setAnimationBlockingMode:NSAnimationNonblocking];
}
@@ -420,7 +498,7 @@ NSTimeInterval kHideStatusDuration = 0.3;
- (void)setCurrentProgress:(NSAnimationProgress)progress {
[super setCurrentProgress:progress];
- [cell_ animationProgressed:progress];
+ [cell_ animation:self progressed:progress];
}
@end