Commit 270e8dc3 authored by dimich@chromium.org's avatar dimich@chromium.org

Implement 3-stage minimize animation for Panels on OSX.

Fast close to titlebar only -> pause on titlebar-only -> slow minimize.

Also, moved close button 1 px lower so it doesn't show up when panel is minimized.

BUG=104645

Review URL: http://codereview.chromium.org/8773030

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112746 0039d316-1c4b-4281-b951-d872f2087c98
parent a15905af
......@@ -212,7 +212,6 @@ static NSEvent* MakeMouseEvent(NSEventType type,
[[settingsButton_ cell] setHighlightsBy:NSNoCellMask];
[self checkMouseAndUpdateSettingsButtonVisibility];
// Update layout of controls in the titlebar.
[self updateCloseButtonLayout];
// Set autoresizing behavior: glued to edges on left, top and right.
......@@ -264,19 +263,20 @@ static NSEvent* MakeMouseEvent(NSEventType type,
NSRect bounds = [self bounds];
buttonFrame.origin.x = kButtonPadding;
buttonFrame.origin.y = (NSHeight(bounds) - NSHeight(buttonFrame)) / 2;
// Lower Close Button's frame 1 px to avoid it 'peeking' in MINIMIZED mode.
buttonFrame.origin.y = (NSHeight(bounds) - NSHeight(buttonFrame)) / 2 - 1;
[closeButton_ setFrame:buttonFrame];
DCHECK(!closeButtonTrackingArea_.get());
if (!closeButtonTrackingArea_.get()) {
closeButtonTrackingArea_.reset(
[[CrTrackingArea alloc] initWithRect:buttonFrame
[[CrTrackingArea alloc] initWithRect:[closeButton_ bounds]
options:(NSTrackingMouseEnteredAndExited |
NSTrackingActiveAlways)
proxiedOwner:self
userInfo:nil]);
NSWindow* panelWindow = [self window];
[closeButtonTrackingArea_.get() clearOwnerWhenWindowWillClose:panelWindow];
[self addTrackingArea:closeButtonTrackingArea_.get()];
[closeButton_ addTrackingArea:closeButtonTrackingArea_.get()];
}
}
- (void)updateIconAndTitleLayout {
......
......@@ -52,6 +52,8 @@ class PanelBrowserWindowCocoa;
BOOL animateOnBoundsChange_;
ScopedCrTrackingArea windowTrackingArea_;
BOOL throbberShouldSpin_;
BOOL playingMinimizeAnimation_;
float animationStopToShowTitlebarOnly_;
}
// Load the browser window nib and do any Cocoa-specific initialization.
......
......@@ -429,20 +429,19 @@ enum {
// Will be enabled back in animationDidEnd callback.
[self disableTabContentsViewAutosizing];
// Terminate previous animation, if it is still playing.
[self terminateBoundsAnimation];
NSDictionary *windowResize = [NSDictionary dictionaryWithObjectsAndKeys:
[self window], NSViewAnimationTargetKey,
[NSValue valueWithRect:frame], NSViewAnimationEndFrameKey, nil];
NSArray *animations = [NSArray arrayWithObjects:windowResize, nil];
// Terminate previous animation, if it is still playing.
[self terminateBoundsAnimation];
boundsAnimation_ =
[[NSViewAnimation alloc] initWithViewAnimations:animations];
[boundsAnimation_ setDelegate:self];
[boundsAnimation_ setAnimationBlockingMode: NSAnimationNonblocking];
NSRect currentFrame = [[self window] frame];
// Compute duration. We use constant speed of animation, however if the change
// is too large, we clip the duration (effectively increasing speed) to
......@@ -455,11 +454,55 @@ enum {
double distance = std::max(distanceX, distanceY);
double duration = std::min(distance / kBoundsAnimationSpeedPixelsPerSecond,
kBoundsAnimationMaxDurationSeconds);
// Detect animation that happens when expansion state is set to MINIMIZED
// and there is relatively big portion of the panel to hide from view.
// Initialize animation differently in this case, using fast-pause-slow
// method, see below for more details.
if (windowShim_->panel()->expansion_state() == Panel::MINIMIZED) {
animationStopToShowTitlebarOnly_ =
1.0 - (windowShim_->TitleOnlyHeight() - NSHeight(frame)) / distanceY;
if (animationStopToShowTitlebarOnly_ > 0.7) { // Relatively big movement.
playingMinimizeAnimation_ = YES;
duration = 1.5;
}
}
[boundsAnimation_ setDuration: duration];
[boundsAnimation_ setFrameRate:0.0];
[boundsAnimation_ setAnimationBlockingMode: NSAnimationNonblocking];
[boundsAnimation_ startAnimation];
}
- (float)animation:(NSAnimation*)animation
valueForProgress:(NSAnimationProgress)progress {
if (!playingMinimizeAnimation_) {
// Cubic easing out.
float value = 1.0 - progress;
return 1.0 - value * value * value;
}
// Minimize animation:
// 1. Quickly (0 -> 0.15) make only titlebar visible.
// 2. Stay a little bit (0.15->0.6) in place, just showing titlebar.
// 3. Slowly minimize to thin strip (0.6->1.0)
const float kAnimationStopAfterQuickDecrease = 0.15;
const float kAnimationStopAfterShowingTitlebar = 0.6;
float value;
if (progress <= kAnimationStopAfterQuickDecrease) {
value = progress * animationStopToShowTitlebarOnly_ /
kAnimationStopAfterQuickDecrease;
} else if (progress <= kAnimationStopAfterShowingTitlebar) {
value = animationStopToShowTitlebarOnly_;
} else {
value = animationStopToShowTitlebarOnly_ +
(progress - kAnimationStopAfterShowingTitlebar) *
(1.0 - animationStopToShowTitlebarOnly_) /
(1.0 - kAnimationStopAfterShowingTitlebar);
}
return value;
}
- (void)animationDidEnd:(NSAnimation*)animation {
playingMinimizeAnimation_ = NO;
if (windowShim_->panel()->expansion_state() == Panel::EXPANDED)
[self enableTabContentsViewAutosizing];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment