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

Unified Diff: chrome/browser/cocoa/animatable_view.mm

Issue 350002: [Mac] Adds a new view that will allow us to animate the height property of vi... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/cocoa/animatable_view.h ('k') | chrome/browser/cocoa/animatable_view_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/cocoa/animatable_view.mm
===================================================================
--- chrome/browser/cocoa/animatable_view.mm (revision 0)
+++ chrome/browser/cocoa/animatable_view.mm (revision 0)
@@ -0,0 +1,100 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import <Cocoa/Cocoa.h>
+#import <QuartzCore/QuartzCore.h>
+
+#import "chrome/browser/cocoa/animatable_view.h"
+
+// NSAnimation subclass that animates the height of an AnimatableView. Allows
+// the caller to start and cancel the animation as desired.
+@interface NSHeightAnimation : NSAnimation {
+ @private
+ AnimatableView* view_; // weak, owns us.
+ CGFloat startHeight_;
+ CGFloat endHeight_;
+}
+
+// Initialize a new height animation for the given view. The animation will not
+// start until startAnimation: is called.
+- (id)initWithView:(AnimatableView*)view
+ finalHeight:(CGFloat)height
+ duration:(NSTimeInterval)duration;
+@end
+
+@implementation NSHeightAnimation
+- (id)initWithView:(AnimatableView*)view
+ finalHeight:(CGFloat)height
+ duration:(NSTimeInterval)duration {
+ if ((self = [super initWithDuration:duration
+ animationCurve:NSAnimationEaseIn])) {
+ view_ = view;
+ startHeight_ = [view_ height];
+ endHeight_ = height;
+ [self setAnimationBlockingMode:NSAnimationNonblocking];
+ [self setDelegate:view_];
+ }
+ return self;
+}
+
+// Overridden to call setHeight for each progress tick.
+- (void)setCurrentProgress:(NSAnimationProgress)progress {
+ [super setCurrentProgress:progress];
+ [view_ setHeight:((progress * (endHeight_ - startHeight_)) + startHeight_)];
+}
+@end
+
+
+@implementation AnimatableView
+@synthesize delegate = delegate_;
+
+- (void)dealloc {
+ // Stop the animation if it is running, since it holds a pointer to this view.
+ [self stopAnimation];
+ [super dealloc];
+}
+
+- (CGFloat)height {
+ return [self frame].size.height;
+}
+
+- (void)setHeight:(CGFloat)newHeight {
+ // Force the height to be an integer because some animations look terrible
+ // with non-integer intermediate heights. We only ever set integer heights
+ // for our views, so this shouldn't be a limitation in practice.
+ int height = floor(newHeight);
+ [resizeDelegate_ resizeView:self newHeight:height];
+}
+
+- (void)animateToNewHeight:(CGFloat)newHeight
+ duration:(NSTimeInterval)duration {
+ [currentAnimation_ stopAnimation];
+
+ currentAnimation_.reset([[NSHeightAnimation alloc] initWithView:self
+ finalHeight:newHeight
+ duration:duration]);
+ [currentAnimation_ startAnimation];
+}
+
+- (void)stopAnimation {
+ [currentAnimation_ stopAnimation];
+}
+
+- (void)setResizeDelegate:(id<ViewResizer>)resizeDelegate {
+ resizeDelegate_ = resizeDelegate;
+}
+
+- (void)animationDidStop:(NSAnimation*)animation {
+ if ([delegate_ respondsToSelector:@selector(animationDidStop:)])
+ [delegate_ animationDidStop:animation];
+ currentAnimation_.reset(nil);
+}
+
+- (void)animationDidEnd:(NSAnimation*)animation {
+ if ([delegate_ respondsToSelector:@selector(animationDidEnd:)])
+ [delegate_ animationDidEnd:animation];
+ currentAnimation_.reset(nil);
+}
+
+@end
Property changes on: chrome/browser/cocoa/animatable_view.mm
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « chrome/browser/cocoa/animatable_view.h ('k') | chrome/browser/cocoa/animatable_view_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698