aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2010-03-10 18:33:34 +0000
committerGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2010-03-10 18:33:34 +0000
commit332accd330b679f8ccb0ed0c8916439a39347711 (patch)
treeb2995f4995097fe875d6ac644782767eeeecc765
parent13b87870c8cf9d5445a1da6d20d142d43ac9c2e8 (diff)
[Author: dmaclach]
Change over animation so it will work with other event types than just mouse downs. R=thomasvl DELTA=33 (16 added, 1 deleted, 16 changed)
-rw-r--r--AppKit/GTMNSAnimation+Duration.h38
-rw-r--r--AppKit/GTMNSAnimation+Duration.m39
2 files changed, 53 insertions, 24 deletions
diff --git a/AppKit/GTMNSAnimation+Duration.h b/AppKit/GTMNSAnimation+Duration.h
index 4ed7ef9..5d45378 100644
--- a/AppKit/GTMNSAnimation+Duration.h
+++ b/AppKit/GTMNSAnimation+Duration.h
@@ -6,9 +6,9 @@
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy
// of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -23,25 +23,37 @@
// 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.
-// Currently only modifies the duration if the current event is of type
-// NSLeftMouseUp and only the control and/or shift modifiers are down.
-NSTimeInterval GTMModifyDurationBasedOnCurrentState(NSTimeInterval duration);
+// Currently only modifies the duration if the current event is masked by
+// eventMask and only the control and/or shift modifiers are down.
+NSTimeInterval GTMModifyDurationBasedOnCurrentState(NSTimeInterval duration,
+ NSUInteger eventMask);
+
+// The standard eventmask that you want for the methods in this file. Some apps
+// (eg Chrome) may not want to have animations fire on key strokes, so will use
+// just NSLeftMouseDownMask instead.
+extern const NSUInteger kGTMLeftMouseDownAndKeyDownMask;
// 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
+// 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
+// Currently only modifies the duration if the current event is masked by
+// eventMask and only the control and/or shift modifiers are down.
+- (id)gtm_initWithDuration:(NSTimeInterval)duration
+ eventMask:(NSUInteger)eventMask
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;
+// Currently only modifies the duration if the current event is masked by
+// eventMask and only the control and/or shift modifiers are down.
+- (void)gtm_setDuration:(NSTimeInterval)duration
+ eventMask:(NSUInteger)eventMask;
@end
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
@@ -52,14 +64,20 @@ NSTimeInterval GTMModifyDurationBasedOnCurrentState(NSTimeInterval duration);
// Sets the duration by taking the duration passed in and calling
// GTMModifyDurationBasedOnCurrentState to calculate the real duration.
-- (void)gtm_setDuration:(NSTimeInterval)duration;
+// Currently only modifies the duration if the current event is masked by
+// eventMask and only the control and/or shift modifiers are down.
+- (void)gtm_setDuration:(NSTimeInterval)duration
+ eventMask:(NSUInteger)eventMask;
@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;
+// Currently only modifies the duration if the current event is masked by
+// eventMask and only the control and/or shift modifiers are down.
+- (void)gtm_setDuration:(CFTimeInterval)duration
+ eventMask:(NSUInteger)events;
@end
#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
diff --git a/AppKit/GTMNSAnimation+Duration.m b/AppKit/GTMNSAnimation+Duration.m
index 884cd32..c47772b 100644
--- a/AppKit/GTMNSAnimation+Duration.m
+++ b/AppKit/GTMNSAnimation+Duration.m
@@ -6,9 +6,9 @@
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy
// of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -18,13 +18,16 @@
#import "GTMNSAnimation+Duration.h"
-NSTimeInterval GTMModifyDurationBasedOnCurrentState(NSTimeInterval duration) {
+const NSUInteger kGTMLeftMouseDownAndKeyDownMask
+ = NSLeftMouseDownMask | NSKeyDownMask;
+
+NSTimeInterval GTMModifyDurationBasedOnCurrentState(NSTimeInterval duration,
+ NSUInteger eventMask) {
NSEvent *event = [NSApp currentEvent];
- if ([event type] == NSLeftMouseUp) {
+ if (eventMask & NSEventMaskFromType([event type])) {
NSUInteger modifiers = [event modifierFlags];
if (!(modifiers & (NSAlternateKeyMask |
- NSCommandKeyMask |
- NSFunctionKeyMask))) {
+ NSCommandKeyMask))) {
if (modifiers & NSShiftKeyMask) {
duration *= 5.0;
}
@@ -39,14 +42,18 @@ NSTimeInterval GTMModifyDurationBasedOnCurrentState(NSTimeInterval duration) {
@implementation NSAnimation (GTMNSAnimationDurationAdditions)
-- (id)gtm_initWithDuration:(NSTimeInterval)duration
+- (id)gtm_initWithDuration:(NSTimeInterval)duration
+ eventMask:(NSUInteger)eventMask
animationCurve:(NSAnimationCurve)animationCurve {
- return [self initWithDuration:GTMModifyDurationBasedOnCurrentState(duration)
+ return [self initWithDuration:GTMModifyDurationBasedOnCurrentState(duration,
+ eventMask)
animationCurve:animationCurve];
}
-- (void)gtm_setDuration:(NSTimeInterval)duration {
- [self setDuration:GTMModifyDurationBasedOnCurrentState(duration)];
+- (void)gtm_setDuration:(NSTimeInterval)duration
+ eventMask:(NSUInteger)eventMask {
+ [self setDuration:GTMModifyDurationBasedOnCurrentState(duration,
+ eventMask)];
}
@end
@@ -55,16 +62,20 @@ NSTimeInterval GTMModifyDurationBasedOnCurrentState(NSTimeInterval duration) {
@implementation NSAnimationContext (GTMNSAnimationDurationAdditions)
-- (void)gtm_setDuration:(NSTimeInterval)duration {
- [self setDuration:GTMModifyDurationBasedOnCurrentState(duration)];
+- (void)gtm_setDuration:(NSTimeInterval)duration
+ eventMask:(NSUInteger)eventMask {
+ [self setDuration:GTMModifyDurationBasedOnCurrentState(duration,
+ eventMask)];
}
@end
@implementation CAAnimation (GTMCAAnimationDurationAdditions)
-- (void)gtm_setDuration:(CFTimeInterval)duration {
- [self setDuration:GTMModifyDurationBasedOnCurrentState(duration)];
+- (void)gtm_setDuration:(CFTimeInterval)duration
+ eventMask:(NSUInteger)eventMask {
+ [self setDuration:GTMModifyDurationBasedOnCurrentState(duration,
+ eventMask)];
}
@end