aboutsummaryrefslogtreecommitdiff
path: root/AppKit
diff options
context:
space:
mode:
authorGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-04-22 16:15:17 +0000
committerGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-04-22 16:15:17 +0000
commitb4d9a4e890c31751a6b3b8dea090912ccd16a79d (patch)
treedeafec907e4455595e85885abd06c0a9a6ee98bf /AppKit
parent4b39e586b5c5625b275a78f0efbc0a50e27e6a61 (diff)
[Author: dmaclach]
Adds duration support to GTMLargeTypeWindow to speed up the unittest cycle. DELTA=30 (25 added, 0 deleted, 5 changed) R=thomasvl
Diffstat (limited to 'AppKit')
-rw-r--r--AppKit/GTMLargeTypeWindow.h16
-rw-r--r--AppKit/GTMLargeTypeWindow.m35
-rw-r--r--AppKit/GTMLargeTypeWindowTest.m18
3 files changed, 55 insertions, 14 deletions
diff --git a/AppKit/GTMLargeTypeWindow.h b/AppKit/GTMLargeTypeWindow.h
index 0a7759f..2b66a93 100644
--- a/AppKit/GTMLargeTypeWindow.h
+++ b/AppKit/GTMLargeTypeWindow.h
@@ -37,10 +37,18 @@
// at this time on our test machines.
// Dual-Core Intel Xeon with ATI Radeon X1300
-// Amount of time to fade the window in or out
-const NSTimeInterval kGTMLargeTypeWindowFadeTime;
-
@interface GTMLargeTypeWindow : NSPanel
+
+// Setter and getter for the copy animation duration. Default value is .5s.
+// Note that this affects all windows.
++ (NSTimeInterval)copyAnimationDuration;
++ (void)setCopyAnimationDuration:(NSTimeInterval)duration;
+
+// Setter and getter for the fade animation duration. Default value is .3s.
+// Note that this affects all windows.
++ (NSTimeInterval)fadeAnimationDuration;
++ (void)setFadeAnimationDuration:(NSTimeInterval)duration;
+
// Creates a display window with |string| displayed.
// Formats |string| as best as possible to fill the screen.
- (id)initWithString:(NSString *)string;
@@ -57,4 +65,6 @@ const NSTimeInterval kGTMLargeTypeWindowFadeTime;
// as part of the responder chain so that the user can copy the displayed text
// using cmd-c.
- (void)copy:(id)sender;
+
+
@end
diff --git a/AppKit/GTMLargeTypeWindow.m b/AppKit/GTMLargeTypeWindow.m
index 97847aa..5b070cf 100644
--- a/AppKit/GTMLargeTypeWindow.m
+++ b/AppKit/GTMLargeTypeWindow.m
@@ -23,8 +23,6 @@
#import "GTMNSBezierPath+RoundRect.h"
#import "GTMMethodCheck.h"
-// Amount of time to fade the window in or out
-const NSTimeInterval kGTMLargeTypeWindowFadeTime = 0.333;
// How far to inset the text from the edge of the window
static const CGFloat kEdgeInset = 16.0;
@@ -32,6 +30,12 @@ static const CGFloat kEdgeInset = 16.0;
// Give us an alpha value for our backing window
static const CGFloat kTwoThirdsAlpha = 0.66;
+// Amount of time to do copy animations
+static NSTimeInterval gGTMLargeTypeWindowCopyAnimationDuration = 0.5;
+
+// Amount of time to do fade animations
+static NSTimeInterval gGTMLargeTypeWindowFadeAnimationDuration = 0.333;
+
@interface GTMLargeTypeCopyAnimation : NSAnimation
@end
@@ -39,7 +43,7 @@ static const CGFloat kTwoThirdsAlpha = 0.66;
CIFilter *transition_;
GTMLargeTypeCopyAnimation *animation_;
}
-- (void)animateCopy;
+- (void)animateCopyWithDuration:(NSTimeInterval)duration;
@end
@interface GTMLargeTypeWindow (GTMLargeTypeWindowPrivate)
@@ -193,6 +197,22 @@ static const CGFloat kTwoThirdsAlpha = 0.66;
return self;
}
++ (NSTimeInterval)copyAnimationDuration {
+ return gGTMLargeTypeWindowCopyAnimationDuration;
+}
+
++ (void)setCopyAnimationDuration:(NSTimeInterval)duration {
+ gGTMLargeTypeWindowCopyAnimationDuration = duration;
+}
+
++ (NSTimeInterval)fadeAnimationDuration {
+ return gGTMLargeTypeWindowFadeAnimationDuration;
+}
+
++ (void)setFadeAnimationDuration:(NSTimeInterval)duration {
+ gGTMLargeTypeWindowFadeAnimationDuration = duration;
+}
+
- (void)copy:(id)sender {
id firstResponder = [self initialFirstResponder];
if ([firstResponder respondsToSelector:@selector(textStorage)]) {
@@ -203,7 +223,8 @@ static const CGFloat kTwoThirdsAlpha = 0.66;
}
// Give the user some feedback that a copy has occurred
- [(GTMLargeTypeBackgroundView*)[self contentView] animateCopy];
+ NSTimeInterval dur = [[self class] copyAnimationDuration];
+ [(GTMLargeTypeBackgroundView*)[self contentView] animateCopyWithDuration:dur];
}
- (BOOL)canBecomeKeyWindow {
@@ -262,7 +283,7 @@ static const CGFloat kTwoThirdsAlpha = 0.66;
NSArray *animation = [NSArray arrayWithObject:fadeIn];
NSViewAnimation *viewAnim
= [[[NSViewAnimation alloc] initWithViewAnimations:animation] autorelease];
- [viewAnim setDuration:kGTMLargeTypeWindowFadeTime];
+ [viewAnim setDuration:[[self class] fadeAnimationDuration]];
[viewAnim setAnimationBlockingMode:NSAnimationBlocking];
[viewAnim startAnimation];
}
@@ -306,7 +327,7 @@ GTM_METHOD_CHECK(NSBezierPath, gtm_appendBezierPathWithRoundRect:cornerRadius:);
}
}
-- (void)animateCopy {
+- (void)animateCopyWithDuration:(NSTimeInterval)duration {
// This does a photocopy swipe to show folks that their copy has succceeded
// Store off a copy of our background
NSRect bounds = [self bounds];
@@ -333,7 +354,7 @@ GTM_METHOD_CHECK(NSBezierPath, gtm_appendBezierPathWithRoundRect:cornerRadius:);
[transition valueForKey:@"outputImage"];
[image release];
transition_ = [transition retain];
- animation_ = [[GTMLargeTypeCopyAnimation alloc] initWithDuration:0.5
+ animation_ = [[GTMLargeTypeCopyAnimation alloc] initWithDuration:duration
animationCurve:NSAnimationLinear];
[animation_ setFrameRate:0.0f];
[animation_ setDelegate:self];
diff --git a/AppKit/GTMLargeTypeWindowTest.m b/AppKit/GTMLargeTypeWindowTest.m
index 65ea101..442fbac 100644
--- a/AppKit/GTMLargeTypeWindowTest.m
+++ b/AppKit/GTMLargeTypeWindowTest.m
@@ -75,6 +75,16 @@ NSString *const kShortTextBlock = @"Short";
}
}
+- (void)setUp {
+ [GTMLargeTypeWindow setCopyAnimationDuration:0];
+ [GTMLargeTypeWindow setFadeAnimationDuration:0];
+}
+
+- (void)tearDown {
+ [GTMLargeTypeWindow setCopyAnimationDuration:0.5];
+ [GTMLargeTypeWindow setFadeAnimationDuration:0.333];
+}
+
- (void)testLargeTypeWindowIllegalInits {
[GTMUnitTestDevLog expectString:@"GTMLargeTypeWindow got an empty string"];
GTMLargeTypeWindow *window = [[[GTMLargeTypeWindow alloc]
@@ -113,7 +123,7 @@ NSString *const kShortTextBlock = @"Short";
STAssertTrue([window canBecomeKeyWindow], nil);
[window makeKeyAndOrderFront:nil];
NSDate *endDate
- = [NSDate dateWithTimeIntervalSinceNow:kGTMLargeTypeWindowFadeTime];
+ = [NSDate dateWithTimeIntervalSinceNow:.1];
[[NSRunLoop currentRunLoop] runUntilDate:endDate];
GTMAssertObjectStateEqualToStateNamed(window,
@"GTMLargeTypeWindowMediumTextTest",
@@ -134,7 +144,7 @@ NSString *const kShortTextBlock = @"Short";
STAssertTrue([window canBecomeKeyWindow], nil);
[window makeKeyAndOrderFront:nil];
NSDate *endDate
- = [NSDate dateWithTimeIntervalSinceNow:kGTMLargeTypeWindowFadeTime];
+ = [NSDate dateWithTimeIntervalSinceNow:.1];
[[NSRunLoop currentRunLoop] runUntilDate:endDate];
GTMAssertObjectStateEqualToStateNamed(window,
@"GTMLargeTypeWindowShortTextTest",
@@ -154,7 +164,7 @@ NSString *const kShortTextBlock = @"Short";
STAssertNotNil(window, nil);
[window orderFront:nil];
NSDate *endDate
- = [NSDate dateWithTimeIntervalSinceNow:kGTMLargeTypeWindowFadeTime];
+ = [NSDate dateWithTimeIntervalSinceNow:.1];
[[NSRunLoop currentRunLoop] runUntilDate:endDate];
// Can't do state for long text as it will wrap differently on different
// sized screens.
@@ -177,7 +187,7 @@ NSString *const kShortTextBlock = @"Short";
STAssertNotNil(window, nil);
[window makeKeyAndOrderFront:nil];
NSDate *endDate
- = [NSDate dateWithTimeIntervalSinceNow:kGTMLargeTypeWindowFadeTime];
+ = [NSDate dateWithTimeIntervalSinceNow:.1];
[[NSRunLoop currentRunLoop] runUntilDate:endDate];
GTMAssertObjectStateEqualToStateNamed(window,
@"GTMLargeTypeWindowImageTest",