mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-12-03 19:44:22 +00:00
AppKit: Animate toolbar visibility changes started by the user
Showing or hiding the toolbar via -toggleToolbarShown: changed the window frame and content layout immediately rather than animating the transition as AppKit does for user-initiated changes. Mark the change as user-initiated and animate it over -animationResizeTime: in -[CPWindow _noteToolbarChanged]. Hiding collapses the toolbar toward its top edge while fading its items out; showing reverses the transition. A standalone window resizes with its top edge fixed and keeps its content size; a bridge window keeps its frame while its content view grows or shrinks. Toggling again mid-animation reverses from the current position, and the size change is reported once at completion. Apply the change immediately when reduced motion is enabled, when the window is off-screen, when -[CPToolbar setVisible:] is called directly, or when the window view cannot animate (such as HUD windows and sheets; only _CPStandardWindowView outside a sheet and _CPBorderlessBridgeWindowView animate). Remove commented-out animation code in -_noteToolbarChanged and _CPWindowView.
This commit is contained in:
1 parent
ab7aff5e72
commit
684ab6e926
5 files changed
+530
-35
No files matched your search
+199
-7
@@ -37,6 +37,7 @@
|
||||
@import "CPText.j"
|
||||
@import "CPTrackingArea.j"
|
||||
@import "CPView.j"
|
||||
@import "CPWorkspace.j"
|
||||
@import "CPWindow_Constants.j"
|
||||
@import "_CPBorderlessBridgeWindowView.j"
|
||||
@import "_CPBorderlessWindowView.j"
|
||||
@@ -55,6 +56,7 @@
|
||||
@class CPWindowController
|
||||
@class _CPWindowFrameAnimation
|
||||
@class _CPWindowFrameAnimationDelegate
|
||||
@class _CPWindowToolbarAnimation
|
||||
|
||||
@global CPApp
|
||||
@global _CPPlatformWindowWillCloseNotification
|
||||
@@ -281,6 +283,8 @@ var CPWindowActionMessageKeys = [
|
||||
CPAppearance _appliedAppearance;
|
||||
_CPWindowFrameAnimation _frameAnimation;
|
||||
_CPWindowFrameAnimationDelegate _frameAnimationDelegate;
|
||||
_CPWindowToolbarAnimation _toolbarAnimation;
|
||||
BOOL _isUserToolbarToggle;
|
||||
|
||||
BOOL _inhibitUpdateTrackingAreas; // Used by the CPView when updating tracking areas
|
||||
}
|
||||
@@ -3120,7 +3124,16 @@ CPTexturedBackgroundWindowMask
|
||||
{
|
||||
var toolbar = [self toolbar];
|
||||
|
||||
[toolbar setVisible:![toolbar isVisible]];
|
||||
_isUserToolbarToggle = YES;
|
||||
|
||||
try
|
||||
{
|
||||
[toolbar setVisible:![toolbar isVisible]];
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isUserToolbarToggle = NO;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -3227,7 +3240,33 @@ CPTexturedBackgroundWindowMask
|
||||
return NO;
|
||||
}
|
||||
|
||||
/*
|
||||
A change of the toolbar's visibility that the user starts, with -toggleToolbarShown:,
|
||||
animates. The toolbar collapses toward its top edge as it hides, and its items fade out;
|
||||
showing reverses it. The content's top edge follows the toolbar's bottom edge. A window
|
||||
with a frame of its own grows or shrinks by as much, so the content keeps its size; a full
|
||||
platform window keeps its frame, and the content grows or shrinks. A direct -setVisible:
|
||||
and every other toolbar change take effect at once, as every framework operation that the
|
||||
developer starts does. Under reduced motion nothing animates.
|
||||
|
||||
2026-12-01: the window frame changed at once, with no animation, for every toolbar change.
|
||||
The animation was left commented out here, and depended on an animatingToolbar property of
|
||||
the window view that was commented out too.
|
||||
*/
|
||||
- (void)_noteToolbarChanged
|
||||
{
|
||||
var duration = [self _toolbarVisibilityAnimationDuration],
|
||||
revealHeight = [_windowView _visibleToolbarHeight];
|
||||
|
||||
[self _stopToolbarAnimation];
|
||||
|
||||
if (duration > 0.0)
|
||||
[self _animateToolbarChangeFromRevealHeight:revealHeight duration:duration];
|
||||
else
|
||||
[self _applyToolbarChange];
|
||||
}
|
||||
|
||||
- (void)_applyToolbarChange
|
||||
{
|
||||
var frame = CGRectMakeCopy([self frame]),
|
||||
newFrame;
|
||||
@@ -3252,13 +3291,126 @@ CPTexturedBackgroundWindowMask
|
||||
*/
|
||||
if ([self attachedSheet])
|
||||
[self _setAttachedSheetFrameOrigin];
|
||||
}
|
||||
|
||||
/*
|
||||
[_windowView setAnimatingToolbar:YES];
|
||||
[self setFrame:frame];
|
||||
[self setFrame:newFrame display:YES animate:YES];
|
||||
[_windowView setAnimatingToolbar:NO];
|
||||
*/
|
||||
/*
|
||||
Returns the duration of the animation of a toolbar change that is starting, or 0 when it
|
||||
does not animate.
|
||||
*/
|
||||
- (CPTimeInterval)_toolbarVisibilityAnimationDuration
|
||||
{
|
||||
if (!_isUserToolbarToggle || !_isVisible || ![_windowView _animatesToolbarVisibility])
|
||||
return 0.0;
|
||||
|
||||
if ([[CPWorkspace sharedWorkspace] accessibilityDisplayShouldReduceMotion])
|
||||
return 0.0;
|
||||
|
||||
return [self animationResizeTime:_frame];
|
||||
}
|
||||
|
||||
/*
|
||||
Starts the animation from the toolbar height the window view shows now, which is the
|
||||
revealed height when an earlier animation was stopped part way. The window's top edge stays
|
||||
in place.
|
||||
*/
|
||||
- (void)_animateToolbarChangeFromRevealHeight:(float)aHeight duration:(CPTimeInterval)aDuration
|
||||
{
|
||||
var startFrame = CGRectMakeCopy(_frame),
|
||||
toolbar = [self toolbar],
|
||||
targetRevealHeight = [toolbar isVisible] ? CGRectGetHeight([[toolbar _toolbarView] frame]) : 0.0,
|
||||
targetFrame;
|
||||
|
||||
[_windowView _setToolbarRevealHeight:aHeight];
|
||||
[_windowView _attachToolbarView];
|
||||
|
||||
if (_isFullPlatformWindow)
|
||||
targetFrame = CGRectMakeCopy(startFrame);
|
||||
else
|
||||
{
|
||||
targetFrame = [_windowView _frameRectForCurrentContentRect];
|
||||
targetFrame.origin = CGPointMakeCopy(startFrame.origin);
|
||||
targetFrame = [self _constrainFrame:targetFrame toUsableScreenWidth:NO andHeight:YES];
|
||||
}
|
||||
|
||||
_toolbarAnimation = [[_CPWindowToolbarAnimation alloc] initWithWindow:self startFrame:startFrame targetFrame:targetFrame revealHeight:aHeight targetRevealHeight:targetRevealHeight duration:aDuration];
|
||||
|
||||
[self _setAnimating:YES];
|
||||
[_toolbarAnimation startAnimation];
|
||||
}
|
||||
|
||||
/*
|
||||
Lays the window out for anAnimation at aValue. When the frame height changes, the revealed
|
||||
toolbar height follows it, so the content view keeps its size. A full platform window keeps
|
||||
its frame, and the revealed height follows aValue.
|
||||
*/
|
||||
- (void)_toolbarAnimation:(_CPWindowToolbarAnimation)anAnimation didReachValue:(float)aValue
|
||||
{
|
||||
if (anAnimation !== _toolbarAnimation)
|
||||
return;
|
||||
|
||||
var startFrame = [anAnimation startFrame],
|
||||
targetFrame = [anAnimation targetFrame],
|
||||
frame = CGRectMake(
|
||||
interpolate(CGRectGetMinX(startFrame), CGRectGetMinX(targetFrame), aValue),
|
||||
interpolate(CGRectGetMinY(startFrame), CGRectGetMinY(targetFrame), aValue),
|
||||
interpolate(CGRectGetWidth(startFrame), CGRectGetWidth(targetFrame), aValue),
|
||||
interpolate(CGRectGetHeight(startFrame), CGRectGetHeight(targetFrame), aValue)),
|
||||
fromHeight = [anAnimation revealHeight],
|
||||
toHeight = [anAnimation targetRevealHeight],
|
||||
heightChange = CGRectGetHeight(targetFrame) - CGRectGetHeight(startFrame),
|
||||
revealHeight;
|
||||
|
||||
[_windowView setAutoresizesSubviews:NO];
|
||||
|
||||
if (!_isFullPlatformWindow)
|
||||
[self _setFrame:frame display:YES animate:NO constrainWidth:NO constrainHeight:NO];
|
||||
|
||||
if (heightChange && !_isFullPlatformWindow)
|
||||
revealHeight = fromHeight + (toHeight - fromHeight) * (CGRectGetHeight(_frame) - CGRectGetHeight(startFrame)) / heightChange;
|
||||
else
|
||||
revealHeight = ROUND(interpolate(fromHeight, toHeight, aValue));
|
||||
|
||||
[_windowView _setToolbarRevealHeight:revealHeight];
|
||||
[_windowView tile];
|
||||
[_windowView setAutoresizesSubviews:YES];
|
||||
|
||||
if ([self attachedSheet])
|
||||
[self _setAttachedSheetFrameOrigin];
|
||||
|
||||
if (aValue === 1.0)
|
||||
[self _finishToolbarAnimation];
|
||||
}
|
||||
|
||||
/*
|
||||
Ends the animation in the toolbar's end state. The size changes reported while it ran were
|
||||
held back, so the change is reported once.
|
||||
*/
|
||||
- (void)_finishToolbarAnimation
|
||||
{
|
||||
var startSize = [_toolbarAnimation startFrame].size;
|
||||
|
||||
[self _stopToolbarAnimation];
|
||||
[self _applyToolbarChange];
|
||||
|
||||
if (!CGSizeEqualToSize(startSize, _frame.size))
|
||||
[[CPNotificationCenter defaultCenter] postNotificationName:CPWindowDidResizeNotification object:self];
|
||||
}
|
||||
|
||||
/*
|
||||
Stops a running toolbar animation where it is. The window view keeps the laid out state
|
||||
until the next layout.
|
||||
*/
|
||||
- (void)_stopToolbarAnimation
|
||||
{
|
||||
if (!_toolbarAnimation)
|
||||
return;
|
||||
|
||||
var animation = _toolbarAnimation;
|
||||
|
||||
_toolbarAnimation = nil;
|
||||
[animation stopAnimation];
|
||||
[_windowView _setToolbarRevealHeight:nil];
|
||||
[self _setAnimating:NO];
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -4574,6 +4726,46 @@ var interpolate = function(fromValue, toValue, progress)
|
||||
|
||||
@end
|
||||
|
||||
/*
|
||||
The animation of a change of the toolbar's visibility. The window lays itself out at each
|
||||
value.
|
||||
@ignore
|
||||
*/
|
||||
@implementation _CPWindowToolbarAnimation : CPAnimation
|
||||
{
|
||||
CPWindow _window;
|
||||
|
||||
CGRect _startFrame @accessors(readonly, property=startFrame);
|
||||
CGRect _targetFrame @accessors(readonly, property=targetFrame);
|
||||
float _revealHeight @accessors(readonly, property=revealHeight);
|
||||
float _targetRevealHeight @accessors(readonly, property=targetRevealHeight);
|
||||
}
|
||||
|
||||
- (id)initWithWindow:(CPWindow)aWindow startFrame:(CGRect)aStartFrame targetFrame:(CGRect)aTargetFrame revealHeight:(float)aHeight targetRevealHeight:(float)aTargetHeight duration:(CPTimeInterval)aDuration
|
||||
{
|
||||
self = [super initWithDuration:aDuration animationCurve:CPAnimationEaseInOut];
|
||||
|
||||
if (self)
|
||||
{
|
||||
_window = aWindow;
|
||||
_startFrame = CGRectMakeCopy(aStartFrame);
|
||||
_targetFrame = CGRectMakeCopy(aTargetFrame);
|
||||
_revealHeight = aHeight;
|
||||
_targetRevealHeight = aTargetHeight;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setCurrentProgress:(float)aProgress
|
||||
{
|
||||
[super setCurrentProgress:aProgress];
|
||||
|
||||
[_window _toolbarAnimation:self didReachValue:aProgress === 1.0 ? 1.0 : [self currentValue]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPWindow (CPDraggingAdditions)
|
||||
|
||||
/* @ignore */
|
||||
|
||||
@@ -117,7 +117,13 @@
|
||||
|
||||
[[theWindow contentView] setFrame:CGRectMake(0.0, [self toolbarMaxY], CGRectGetWidth(bounds), CGRectGetHeight(bounds) - [self toolbarMaxY])];
|
||||
|
||||
if (![[theWindow toolbar] isVisible])
|
||||
/*
|
||||
While a change of the toolbar's visibility animates, the toolbar background takes the
|
||||
revealed height, so it collapses with the toolbar.
|
||||
*/
|
||||
var visibleToolbarHeight = [self _visibleToolbarHeight];
|
||||
|
||||
if (![[theWindow toolbar] isVisible] && _toolbarRevealHeight == nil)
|
||||
{
|
||||
[_toolbarBackgroundView removeFromSuperview];
|
||||
|
||||
@@ -140,11 +146,20 @@
|
||||
toolbarOffset = [self toolbarOffset];
|
||||
|
||||
frame.origin = CGPointMake(toolbarOffset.width, toolbarOffset.height);
|
||||
frame.size = [_toolbarView frame].size;
|
||||
frame.size = CGSizeMake(CGRectGetWidth([_toolbarView frame]), visibleToolbarHeight);
|
||||
|
||||
[_toolbarBackgroundView setFrame:frame];
|
||||
}
|
||||
|
||||
/*
|
||||
The receiver lays the content view out from -toolbarMaxY and its frame does not change, so
|
||||
the content follows the toolbar's collapsing edge.
|
||||
*/
|
||||
- (BOOL)_animatesToolbarVisibility
|
||||
{
|
||||
return [self showsToolbar];
|
||||
}
|
||||
|
||||
- (void)setFrameSize:(CGSize)aFrameSize
|
||||
{
|
||||
[super setFrameSize:aFrameSize];
|
||||
|
||||
@@ -289,6 +289,15 @@ var _CPStandardWindowViewDividerViewHeight = 1.0;
|
||||
return CGSizeMake(0.0, _titleBarHeight);
|
||||
}
|
||||
|
||||
/*
|
||||
A sheet places its toolbar at its top edge and does not lay it out from -toolbarMaxY. A
|
||||
window that does not show its toolbar has no change to animate.
|
||||
*/
|
||||
- (BOOL)_animatesToolbarVisibility
|
||||
{
|
||||
return !_isSheet && [self showsToolbar];
|
||||
}
|
||||
|
||||
- (void)tile
|
||||
{
|
||||
[super tile];
|
||||
|
||||
@@ -244,7 +244,7 @@ function _CPWindowViewSetCornerRadii(aDOMElement, someRadii)
|
||||
|
||||
CPView _toolbarView;
|
||||
CGSize _toolbarOffset;
|
||||
// BOOL _isAnimatingToolbar;
|
||||
float _toolbarRevealHeight;
|
||||
|
||||
CGRect _cachedFrame;
|
||||
int _resizeRegion;
|
||||
@@ -381,6 +381,7 @@ function _CPWindowViewSetCornerRadii(aDOMElement, someRadii)
|
||||
_styleMask = aStyleMask;
|
||||
_resizeIndicatorOffset = CGSizeMakeZero();
|
||||
_toolbarOffset = CGSizeMakeZero();
|
||||
_toolbarRevealHeight = nil;
|
||||
_isTracking = NO;
|
||||
}
|
||||
|
||||
@@ -1065,6 +1066,9 @@ function _CPWindowViewSetCornerRadii(aDOMElement, someRadii)
|
||||
|
||||
- (float)toolbarMaxY
|
||||
{
|
||||
if (_toolbarRevealHeight != nil)
|
||||
return [self toolbarOffset].height + _toolbarRevealHeight;
|
||||
|
||||
if (!_toolbarView || [_toolbarView isHidden])
|
||||
return [self toolbarOffset].height;
|
||||
|
||||
@@ -1101,8 +1105,27 @@ function _CPWindowViewSetCornerRadii(aDOMElement, someRadii)
|
||||
|
||||
- (void)noteToolbarChanged
|
||||
{
|
||||
var theWindow = [self window],
|
||||
toolbar = [theWindow toolbar],
|
||||
var theWindow = [self window];
|
||||
|
||||
[self _attachToolbarView];
|
||||
|
||||
if (theWindow)
|
||||
{
|
||||
[self setAutoresizesSubviews:NO];
|
||||
[theWindow setFrame:[self _frameRectForCurrentContentRect]];
|
||||
[self setAutoresizesSubviews:YES];
|
||||
}
|
||||
|
||||
[self tile];
|
||||
}
|
||||
|
||||
/*
|
||||
Makes the window's toolbar view a subview of the receiver, and shows it when the toolbar is
|
||||
visible or while a change of visibility animates.
|
||||
*/
|
||||
- (void)_attachToolbarView
|
||||
{
|
||||
var toolbar = [[self window] toolbar],
|
||||
toolbarView = [toolbar _toolbarView];
|
||||
|
||||
if (_toolbarView !== toolbarView)
|
||||
@@ -1112,27 +1135,68 @@ function _CPWindowViewSetCornerRadii(aDOMElement, someRadii)
|
||||
if (toolbarView)
|
||||
{
|
||||
[toolbarView removeFromSuperview];
|
||||
|
||||
[self addSubview:toolbarView];
|
||||
}
|
||||
|
||||
_toolbarView = toolbarView;
|
||||
}
|
||||
|
||||
[toolbarView setHidden:![self showsToolbar] || ![toolbar isVisible]];
|
||||
[toolbarView setHidden:(![self showsToolbar] || ![toolbar isVisible]) && _toolbarRevealHeight == nil];
|
||||
}
|
||||
|
||||
if (theWindow)
|
||||
{
|
||||
var contentRect = [self convertRect:[[theWindow contentView] frame] toView:nil];
|
||||
/*
|
||||
Returns the window frame that keeps the content view's current rect, for the toolbar's
|
||||
current visibility.
|
||||
*/
|
||||
- (CGRect)_frameRectForCurrentContentRect
|
||||
{
|
||||
var theWindow = [self window],
|
||||
contentRect = [self convertRect:[[theWindow contentView] frame] toView:nil];
|
||||
|
||||
contentRect.origin = [theWindow convertBaseToGlobal:contentRect.origin];
|
||||
contentRect.origin = [theWindow convertBaseToGlobal:contentRect.origin];
|
||||
|
||||
[self setAutoresizesSubviews:NO];
|
||||
[theWindow setFrame:[theWindow frameRectForContentRect:contentRect]];
|
||||
[self setAutoresizesSubviews:YES];
|
||||
}
|
||||
return [theWindow frameRectForContentRect:contentRect];
|
||||
}
|
||||
|
||||
[self tile];
|
||||
/*
|
||||
Returns YES when the receiver can animate a change of the toolbar's visibility: it lays out
|
||||
its head and content from -toolbarMaxY, so a partly revealed toolbar moves the content.
|
||||
*/
|
||||
- (BOOL)_animatesToolbarVisibility
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the height of the toolbar that the receiver shows: the height revealed while a
|
||||
change of visibility animates, else the toolbar view's height or 0.
|
||||
*/
|
||||
- (float)_visibleToolbarHeight
|
||||
{
|
||||
return [self toolbarMaxY] - [self toolbarOffset].height;
|
||||
}
|
||||
|
||||
/*
|
||||
Sets the height of the toolbar that the receiver shows while a change of visibility
|
||||
animates. The toolbar collapses toward its top edge: the receiver cuts it off below the
|
||||
revealed height, and its items fade in proportion. nil ends the animation, and the
|
||||
toolbar's visibility governs the layout again.
|
||||
*/
|
||||
- (void)_setToolbarRevealHeight:(float)aHeight
|
||||
{
|
||||
_toolbarRevealHeight = aHeight;
|
||||
|
||||
if (!_toolbarView)
|
||||
return;
|
||||
|
||||
var height = CGRectGetHeight([_toolbarView frame]),
|
||||
isRevealing = _toolbarRevealHeight != nil && height > 0.0,
|
||||
revealHeight = isRevealing ? MIN(height, MAX(0.0, _toolbarRevealHeight)) : height;
|
||||
|
||||
[_toolbarView setAlphaValue:isRevealing ? revealHeight / height : 1.0];
|
||||
|
||||
if (CPDOMAvailable && _toolbarView._DOMElement)
|
||||
_toolbarView._DOMElement.style.clipPath = isRevealing ? "inset(0px 0px " + (height - revealHeight) + "px 0px)" : "";
|
||||
}
|
||||
|
||||
- (void)noteKeyWindowStateChanged
|
||||
@@ -1151,18 +1215,6 @@ function _CPWindowViewSetCornerRadii(aDOMElement, someRadii)
|
||||
[self unsetThemeState:CPThemeStateMainWindow];
|
||||
}
|
||||
|
||||
/*
|
||||
- (void)setAnimatingToolbar:(BOOL)isAnimatingToolbar
|
||||
{
|
||||
_isAnimatingToolbar = isAnimatingToolbar;
|
||||
}
|
||||
|
||||
- (BOOL)isAnimatingToolbar
|
||||
{
|
||||
return _isAnimatingToolbar;
|
||||
}
|
||||
*/
|
||||
|
||||
- (void)didAddSubview:(CPView)aView
|
||||
{
|
||||
if (aView === [[self window] contentView])
|
||||
|
||||
@@ -561,6 +561,233 @@
|
||||
message:@"content view size " + CPStringFromSize([[window contentView] frameSize]) + " should be {480, 270}"];
|
||||
}
|
||||
|
||||
/*
|
||||
A change of the toolbar's visibility that the user starts, with -toggleToolbarShown:,
|
||||
animates: the toolbar collapses toward its top edge and its items fade, the window frame
|
||||
follows, and the content view keeps its size throughout. A direct
|
||||
-setVisible:, a window that is not on screen and reduced motion make the change at once.
|
||||
The tests drive the animation by setting its progress. A twin window whose toolbar is
|
||||
hidden with -setVisible: gives the end state.
|
||||
*/
|
||||
- (CPWindow)visibleWindowWithToolbar
|
||||
{
|
||||
var window = [[CPWindow alloc] initWithContentRect:CGRectMake(196.0, 540.0, 480.0, 270.0)
|
||||
styleMask:CPTitledWindowMask | CPClosableWindowMask];
|
||||
|
||||
[window setToolbar:[[CPToolbar alloc] initWithIdentifier:@"CPWindowTestToolbar"]];
|
||||
|
||||
/*
|
||||
The window is marked visible, as the minimize tests do. It is not kept inside the usable
|
||||
screen, whose size the test environment does not give.
|
||||
*/
|
||||
window._isVisible = YES;
|
||||
window._constrainsToUsableScreen = NO;
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
- (void)assertFrame:(CGRect)aFrame equals:(CGRect)anExpectedFrame message:(CPString)aMessage
|
||||
{
|
||||
[self assertTrue:CGRectEqualToRect(aFrame, anExpectedFrame)
|
||||
message:aMessage + ": " + CPStringFromRect(aFrame) + " should be " + CPStringFromRect(anExpectedFrame)];
|
||||
}
|
||||
|
||||
- (void)testTogglingTheToolbarAnimatesTheWindowFrame
|
||||
{
|
||||
[[CPWorkspace sharedWorkspace] _setSystemReduceMotionOverride:NO];
|
||||
|
||||
try
|
||||
{
|
||||
var window = [self visibleWindowWithToolbar],
|
||||
twin = [self visibleWindowWithToolbar],
|
||||
startFrame = CGRectMakeCopy([window frame]),
|
||||
contentSize = CGSizeMakeCopy([[window contentView] frameSize]),
|
||||
toolbarView = [[window toolbar] _toolbarView];
|
||||
|
||||
[[twin toolbar] setVisible:NO];
|
||||
[window toggleToolbarShown:nil];
|
||||
|
||||
[self assertFalse:[[window toolbar] isVisible] message:@"the toolbar is hidden at once"];
|
||||
[self assertTrue:[window._toolbarAnimation isAnimating] message:@"an animation runs"];
|
||||
[self assertFrame:[window frame] equals:startFrame message:@"before the first step, the window frame"];
|
||||
|
||||
[window._toolbarAnimation setCurrentProgress:0.5];
|
||||
|
||||
var height = CGRectGetHeight([window frame]);
|
||||
|
||||
[self assertTrue:height < CGRectGetHeight(startFrame) && height > CGRectGetHeight([twin frame])
|
||||
message:@"half way, the window height " + height + " lies between " + CGRectGetHeight([twin frame]) + " and " + CGRectGetHeight(startFrame)];
|
||||
[self assertTrue:CGSizeEqualToSize([[window contentView] frameSize], contentSize)
|
||||
message:@"half way, the content view size " + CPStringFromSize([[window contentView] frameSize]) + " should be " + CPStringFromSize(contentSize)];
|
||||
[self assertFalse:[toolbarView isHidden] message:@"half way, the toolbar view shows"];
|
||||
|
||||
[window._toolbarAnimation setCurrentProgress:1.0];
|
||||
|
||||
[self assertFrame:[window frame] equals:[twin frame] message:@"at the end, the window frame"];
|
||||
[self assertFrame:[[window contentView] frame] equals:[[twin contentView] frame] message:@"at the end, the content view frame"];
|
||||
[self assertTrue:[toolbarView isHidden] message:@"at the end, the toolbar view is hidden"];
|
||||
[self assertFalse:!!window._toolbarAnimation message:@"at the end, no animation remains"];
|
||||
}
|
||||
finally
|
||||
{
|
||||
[[CPWorkspace sharedWorkspace] _setSystemReduceMotionOverride:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testShowingTheToolbarAnimatesBackToTheFrameItHadWithTheToolbar
|
||||
{
|
||||
[[CPWorkspace sharedWorkspace] _setSystemReduceMotionOverride:NO];
|
||||
|
||||
try
|
||||
{
|
||||
var window = [self visibleWindowWithToolbar],
|
||||
frameWithToolbar = CGRectMakeCopy([window frame]),
|
||||
contentFrame = CGRectMakeCopy([[window contentView] frame]);
|
||||
|
||||
[[window toolbar] setVisible:NO];
|
||||
[window toggleToolbarShown:nil];
|
||||
|
||||
[self assertTrue:[[window toolbar] isVisible] message:@"the toolbar is visible at once"];
|
||||
|
||||
[window._toolbarAnimation setCurrentProgress:1.0];
|
||||
|
||||
[self assertFrame:[window frame] equals:frameWithToolbar message:@"the window frame"];
|
||||
[self assertFrame:[[window contentView] frame] equals:contentFrame message:@"the content view frame"];
|
||||
[self assertFalse:[[[window toolbar] _toolbarView] isHidden] message:@"the toolbar view shows"];
|
||||
}
|
||||
finally
|
||||
{
|
||||
[[CPWorkspace sharedWorkspace] _setSystemReduceMotionOverride:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testTogglingTheToolbarAgainDuringTheAnimationReversesItFromWhereItIs
|
||||
{
|
||||
[[CPWorkspace sharedWorkspace] _setSystemReduceMotionOverride:NO];
|
||||
|
||||
try
|
||||
{
|
||||
var window = [self visibleWindowWithToolbar],
|
||||
startFrame = CGRectMakeCopy([window frame]),
|
||||
contentSize = CGSizeMakeCopy([[window contentView] frameSize]);
|
||||
|
||||
[window toggleToolbarShown:nil];
|
||||
[window._toolbarAnimation setCurrentProgress:0.5];
|
||||
|
||||
var midFrame = CGRectMakeCopy([window frame]);
|
||||
|
||||
[window toggleToolbarShown:nil];
|
||||
|
||||
[self assertFrame:[window frame] equals:midFrame message:@"after the second toggle, the window frame"];
|
||||
[self assertFrame:[window._toolbarAnimation startFrame] equals:midFrame message:@"the second animation starts from"];
|
||||
|
||||
[window._toolbarAnimation setCurrentProgress:1.0];
|
||||
|
||||
[self assertFrame:[window frame] equals:startFrame message:@"at the end, the window frame"];
|
||||
[self assertTrue:CGSizeEqualToSize([[window contentView] frameSize], contentSize)
|
||||
message:@"at the end, the content view size " + CPStringFromSize([[window contentView] frameSize]) + " should be " + CPStringFromSize(contentSize)];
|
||||
}
|
||||
finally
|
||||
{
|
||||
[[CPWorkspace sharedWorkspace] _setSystemReduceMotionOverride:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)assertToolbarChangeIsImmediateInWindow:(CPWindow)aWindow afterToggle:(Function)aToggle message:(CPString)aMessage
|
||||
{
|
||||
var startHeight = CGRectGetHeight([aWindow frame]);
|
||||
|
||||
aToggle();
|
||||
|
||||
[self assertFalse:!!aWindow._toolbarAnimation message:aMessage + ": no animation runs"];
|
||||
[self assertTrue:CGRectGetHeight([aWindow frame]) < startHeight message:aMessage + ": the window is shorter at once"];
|
||||
[self assertTrue:[[[aWindow toolbar] _toolbarView] isHidden] message:aMessage + ": the toolbar view is hidden at once"];
|
||||
}
|
||||
|
||||
- (void)testSettingTheToolbarVisibilityDirectlyDoesNotAnimate
|
||||
{
|
||||
[[CPWorkspace sharedWorkspace] _setSystemReduceMotionOverride:NO];
|
||||
|
||||
try
|
||||
{
|
||||
var window = [self visibleWindowWithToolbar];
|
||||
|
||||
[self assertToolbarChangeIsImmediateInWindow:window afterToggle:function() { [[window toolbar] setVisible:NO]; } message:@"-setVisible:"];
|
||||
}
|
||||
finally
|
||||
{
|
||||
[[CPWorkspace sharedWorkspace] _setSystemReduceMotionOverride:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testTogglingTheToolbarOfAWindowThatIsNotOnScreenDoesNotAnimate
|
||||
{
|
||||
[[CPWorkspace sharedWorkspace] _setSystemReduceMotionOverride:NO];
|
||||
|
||||
try
|
||||
{
|
||||
var window = [self visibleWindowWithToolbar];
|
||||
|
||||
window._isVisible = NO;
|
||||
|
||||
[self assertToolbarChangeIsImmediateInWindow:window afterToggle:function() { [window toggleToolbarShown:nil]; } message:@"a window not on screen"];
|
||||
}
|
||||
finally
|
||||
{
|
||||
[[CPWorkspace sharedWorkspace] _setSystemReduceMotionOverride:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testUnderReducedMotionTogglingTheToolbarDoesNotAnimate
|
||||
{
|
||||
[[CPWorkspace sharedWorkspace] _setSystemReduceMotionOverride:YES];
|
||||
|
||||
try
|
||||
{
|
||||
var window = [self visibleWindowWithToolbar];
|
||||
|
||||
[self assertToolbarChangeIsImmediateInWindow:window afterToggle:function() { [window toggleToolbarShown:nil]; } message:@"reduced motion"];
|
||||
}
|
||||
finally
|
||||
{
|
||||
[[CPWorkspace sharedWorkspace] _setSystemReduceMotionOverride:nil];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
The toolbar collapses toward its top edge as it hides, and its items fade out in proportion
|
||||
to the height it still shows. At the end it is opaque again, and hidden.
|
||||
*/
|
||||
- (void)testTheToolbarItemsFadeAsTheToolbarCollapses
|
||||
{
|
||||
[[CPWorkspace sharedWorkspace] _setSystemReduceMotionOverride:NO];
|
||||
|
||||
try
|
||||
{
|
||||
var window = [self visibleWindowWithToolbar],
|
||||
windowView = [window _windowView],
|
||||
toolbarView = [[window toolbar] _toolbarView],
|
||||
toolbarHeight = CGRectGetHeight([toolbarView frame]);
|
||||
|
||||
[window toggleToolbarShown:nil];
|
||||
[window._toolbarAnimation setCurrentProgress:0.5];
|
||||
|
||||
var shownHeight = [windowView _visibleToolbarHeight];
|
||||
|
||||
[self assertTrue:shownHeight > 0.0 && shownHeight < toolbarHeight
|
||||
message:@"half way, the shown toolbar height " + shownHeight + " lies between 0 and " + toolbarHeight];
|
||||
[self assert:shownHeight / toolbarHeight equals:[toolbarView alphaValue] message:@"half way, the toolbar view's alpha"];
|
||||
|
||||
[window._toolbarAnimation setCurrentProgress:1.0];
|
||||
|
||||
[self assert:1.0 equals:[toolbarView alphaValue] message:@"at the end, the toolbar view's alpha"];
|
||||
}
|
||||
finally
|
||||
{
|
||||
[[CPWorkspace sharedWorkspace] _setSystemReduceMotionOverride:nil];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
The content view lies inside the frame border that the theme draws, below the title bar
|
||||
and the 1-point divider. Under a theme with Aristo3's window values (a 31-point title bar
|
||||
|
||||
Reference in new issue
Block a user