aboutsummaryrefslogtreecommitdiff
path: root/AppKit
diff options
context:
space:
mode:
authorGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-11-10 15:30:27 +0000
committerGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-11-10 15:30:27 +0000
commite2e723bf10e3ec694df5a44d99f405aff8417489 (patch)
tree141cee434f6e35f0b23a57e1507cda9c2cb3e501 /AppKit
parent7faafe50af3d0d3b3c1eeb40af77d57328fcc0cb (diff)
[Author: dmaclach]
Turns out I needed to expose a bit more API to make it work with all of the animations in Chrome nicely. R=thomasvl DELTA=42 (30 added, 8 deleted, 4 changed)
Diffstat (limited to 'AppKit')
-rw-r--r--AppKit/GTMNSAnimation+Duration.h28
-rw-r--r--AppKit/GTMNSAnimation+Duration.m18
2 files changed, 34 insertions, 12 deletions
diff --git a/AppKit/GTMNSAnimation+Duration.h b/AppKit/GTMNSAnimation+Duration.h
index fa1d86f..ee4be84 100644
--- a/AppKit/GTMNSAnimation+Duration.h
+++ b/AppKit/GTMNSAnimation+Duration.h
@@ -16,27 +16,47 @@
// the License.
//
-// Categories for changing the duration of an animation based on the current
-// event. Right now they track the state of the shift and control keys to slow
-// down animations similar to how minimize window animations occur.
#import <AppKit/AppKit.h>
#import "GTMDefines.h"
+// Given a "normal" duration for an animation, return what it should be based
+// on the current system state. For example, holding down the shift and/or
+// control keys modifies the normal duration for an animation making it slower.
+NSTimeInterval GTMModifyDurationBasedOnCurrentState(NSTimeInterval duration);
+
+// Categories for changing the duration of an animation based on the current
+// event. Right now they track the state of the shift and control keys to slow
+// down animations similar to how minimize window animations occur.
@interface NSAnimation (GTMNSAnimationDurationAdditions)
+
+// Note that using this initializer will set the duration of the animation
+// based on the current event when the animation is created. If the animation
+// is to be reused, the duration for the event should be reset with
+// gtm_setDuration each time the animation is started.
+- (id)gtm_initWithDuration:(NSTimeInterval)duration
+ animationCurve:(NSAnimationCurve)animationCurve;
+
+// Sets the duration by taking the duration passed in and calling
+// GTMModifyDurationBasedOnCurrentState to calculate the real duration.
- (void)gtm_setDuration:(NSTimeInterval)duration;
@end
-
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
#import <QuartzCore/QuartzCore.h>
@interface NSAnimationContext (GTMNSAnimationDurationAdditions)
+
+// Sets the duration by taking the duration passed in and calling
+// GTMModifyDurationBasedOnCurrentState to calculate the real duration.
- (void)gtm_setDuration:(NSTimeInterval)duration;
@end
@interface CAAnimation (GTMCAAnimationDurationAdditions)
+
+// Sets the duration by taking the duration passed in and calling
+// GTMModifyDurationBasedOnCurrentState to calculate the real duration.
- (void)gtm_setDuration:(CFTimeInterval)duration;
@end
diff --git a/AppKit/GTMNSAnimation+Duration.m b/AppKit/GTMNSAnimation+Duration.m
index 89e3f3e..327a349 100644
--- a/AppKit/GTMNSAnimation+Duration.m
+++ b/AppKit/GTMNSAnimation+Duration.m
@@ -18,10 +18,9 @@
#import "GTMNSAnimation+Duration.h"
-static NSTimeInterval GTMCurrentDurationMultiplier(void) {
+NSTimeInterval GTMModifyDurationBasedOnCurrentState(NSTimeInterval duration) {
NSEvent *event = [NSApp currentEvent];
NSUInteger modifiers = [event modifierFlags];
- NSTimeInterval duration = 1.0;
if (modifiers & NSShiftKeyMask) {
duration *= 5.0;
}
@@ -34,9 +33,14 @@ static NSTimeInterval GTMCurrentDurationMultiplier(void) {
@implementation NSAnimation (GTMNSAnimationDurationAdditions)
+- (id)gtm_initWithDuration:(NSTimeInterval)duration
+ animationCurve:(NSAnimationCurve)animationCurve {
+ return [self initWithDuration:GTMModifyDurationBasedOnCurrentState(duration)
+ animationCurve:animationCurve];
+}
+
- (void)gtm_setDuration:(NSTimeInterval)duration {
- duration = duration * GTMCurrentDurationMultiplier();
- [self setDuration:duration];
+ [self setDuration:GTMModifyDurationBasedOnCurrentState(duration)];
}
@end
@@ -46,8 +50,7 @@ static NSTimeInterval GTMCurrentDurationMultiplier(void) {
@implementation NSAnimationContext (GTMNSAnimationDurationAdditions)
- (void)gtm_setDuration:(NSTimeInterval)duration {
- duration = duration * GTMCurrentDurationMultiplier();
- [self setDuration:duration];
+ [self setDuration:GTMModifyDurationBasedOnCurrentState(duration)];
}
@end
@@ -55,8 +58,7 @@ static NSTimeInterval GTMCurrentDurationMultiplier(void) {
@implementation CAAnimation (GTMCAAnimationDurationAdditions)
- (void)gtm_setDuration:(CFTimeInterval)duration {
- duration = duration * GTMCurrentDurationMultiplier();
- [self setDuration:duration];
+ [self setDuration:GTMModifyDurationBasedOnCurrentState(duration)];
}
@end