diff options
author | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-05 23:24:23 +0000 |
---|---|---|
committer | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-05 23:24:23 +0000 |
commit | 8c8d9a30879460088e60797c98537fd90a23d998 (patch) | |
tree | 20d2ed1168c2d72302d4c531568bafb9d501b82b /chrome/browser | |
parent | 0ac5ce097edbbc2f7f0f362c30f51e79c513f493 (diff) | |
download | chromium_src-8c8d9a30879460088e60797c98537fd90a23d998.zip chromium_src-8c8d9a30879460088e60797c98537fd90a23d998.tar.gz chromium_src-8c8d9a30879460088e60797c98537fd90a23d998.tar.bz2 |
[Mac] Adds animations for the download shelf.
Nib file changes:
- Connected DownloadShelfView's delegate_ to DownloadShelfController.
BUG=http://crbug.com/25602
TEST=Download shelf should animate open/closed.
Review URL: http://codereview.chromium.org/342083
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31156 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
4 files changed, 37 insertions, 7 deletions
diff --git a/chrome/browser/cocoa/download_shelf_controller.h b/chrome/browser/cocoa/download_shelf_controller.h index d310f7f..cc6413c 100644 --- a/chrome/browser/cocoa/download_shelf_controller.h +++ b/chrome/browser/cocoa/download_shelf_controller.h @@ -9,6 +9,7 @@ #include "base/scoped_ptr.h" #import "chrome/browser/cocoa/view_resizer.h" +@class AnimatableView; class BaseDownloadItemModel; class Browser; @class BrowserWindowController; @@ -58,6 +59,9 @@ class DownloadShelf; - (id)initWithBrowser:(Browser*)browser resizeDelegate:(id<ViewResizer>)resizeDelegate; +// Returns our view cast as an AnimatableView. +- (AnimatableView*)animatableView; + - (DownloadShelf*)bridge; - (BOOL)isVisible; diff --git a/chrome/browser/cocoa/download_shelf_controller.mm b/chrome/browser/cocoa/download_shelf_controller.mm index 122a132..81af11e 100644 --- a/chrome/browser/cocoa/download_shelf_controller.mm +++ b/chrome/browser/cocoa/download_shelf_controller.mm @@ -9,6 +9,7 @@ #include "base/mac_util.h" #include "base/sys_string_conversions.h" #include "chrome/browser/browser.h" +#import "chrome/browser/cocoa/animatable_view.h" #import "chrome/browser/cocoa/browser_window_controller.h" #include "chrome/browser/cocoa/browser_window_cocoa.h" #include "chrome/browser/cocoa/download_item_controller.h" @@ -30,6 +31,9 @@ const int kDownloadItemPadding = 0; // Duration for the open-new-leftmost-item animation, in seconds. const NSTimeInterval kDownloadItemOpenDuration = 0.8; +// Duration for download shelf closing animation, in seconds. +const NSTimeInterval kDownloadShelfCloseDuration = 0.12; + } // namespace @interface DownloadShelfController(Private) @@ -67,6 +71,8 @@ const NSTimeInterval kDownloadItemOpenDuration = 0.8; } - (void)awakeFromNib { + [[self animatableView] setResizeDelegate:resizeDelegate_]; + // Initialize "Show all downloads" link. scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( @@ -103,6 +109,10 @@ const NSTimeInterval kDownloadItemOpenDuration = 0.8; [super dealloc]; } +- (AnimatableView*)animatableView { + return static_cast<AnimatableView*>([self view]); +} + - (void)resizeDownloadLinkToFit { // Get width required by localized download link text. // http://developer.apple.com/documentation/Cocoa/Conceptual/TextLayout/Tasks/StringHeight.html @@ -163,6 +173,7 @@ const NSTimeInterval kDownloadItemOpenDuration = 0.8; // We need to explicitly release our download controllers here since they need // to remove themselves as observers before the remaining shutdown happens. - (void)exiting { + [[self animatableView] stopAnimation]; downloadItemControllers_.reset(); } @@ -172,8 +183,17 @@ const NSTimeInterval kDownloadItemOpenDuration = 0.8; if ([self isVisible] == enable) return; - [resizeDelegate_ resizeView:[self view] - newHeight:(enable ? shelfHeight_ : 0)]; + // Animate the shelf out, but not in. + // TODO(rohitrao): We do not animate on the way in because Cocoa is already + // doing a lot of work to set up the download arrow animation. I've chosen to + // do no animation over janky animation. Find a way to make animating in + // smoother. + AnimatableView* view = [self animatableView]; + if (enable) + [view setHeight:shelfHeight_]; + else + [view animateToNewHeight:0 duration:kDownloadShelfCloseDuration]; + barIsVisible_ = enable; } @@ -197,10 +217,11 @@ const NSTimeInterval kDownloadItemOpenDuration = 0.8; bridge_->Close(); else [self showDownloadShelf:NO]; +} - // TODO(port): When closing the shelf is animated, call this only after the - // animation has ended: - [self closed]; +- (void)animationDidEnd:(NSAnimation*)animation { + if (![self isVisible]) + [self closed]; } - (float)height { diff --git a/chrome/browser/cocoa/download_shelf_view.h b/chrome/browser/cocoa/download_shelf_view.h index d69b139..5b05dd6 100644 --- a/chrome/browser/cocoa/download_shelf_view.h +++ b/chrome/browser/cocoa/download_shelf_view.h @@ -7,10 +7,12 @@ #import <Cocoa/Cocoa.h> +#import "chrome/browser/cocoa/animatable_view.h" + // A view that handles any special rendering for the download shelf, painting // a gradient and managing a set of DownloadItemViews. -@interface DownloadShelfView : NSView { +@interface DownloadShelfView : AnimatableView { } @end diff --git a/chrome/browser/cocoa/download_started_animation_mac.mm b/chrome/browser/cocoa/download_started_animation_mac.mm index c2536f0..dde9101 100644 --- a/chrome/browser/cocoa/download_started_animation_mac.mm +++ b/chrome/browser/cocoa/download_started_animation_mac.mm @@ -145,8 +145,11 @@ private: NSPoint stop = NSMakePoint(0, 0); // Bottom of the tab. // Set for the duration of the animation, or we won't see our layer. We reset - // this in the completion callback. + // this in the completion callback. Layers by default scale their content to + // fit, but we need them to clip their content instead, or else renderer + // resizes will look janky. [view_ setWantsLayer:YES]; + [[view_ layer] setContentsGravity:kCAGravityTopLeft]; // CALayer initalization. layer_.reset([[CALayer layer] retain]); |