Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/panels/panel_window_controller_cocoa.h" | 5 #include "chrome/browser/ui/panels/panel_window_controller_cocoa.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 421 [[[[self window] contentView] superview] | 421 [[[[self window] contentView] superview] |
| 422 addTrackingArea:windowTrackingArea_.get()]; | 422 addTrackingArea:windowTrackingArea_.get()]; |
| 423 | 423 |
| 424 if (!animateOnBoundsChange_) { | 424 if (!animateOnBoundsChange_) { |
| 425 [[self window] setFrame:frame display:YES animate:NO]; | 425 [[self window] setFrame:frame display:YES animate:NO]; |
| 426 return; | 426 return; |
| 427 } | 427 } |
| 428 // Will be enabled back in animationDidEnd callback. | 428 // Will be enabled back in animationDidEnd callback. |
| 429 [self disableTabContentsViewAutosizing]; | 429 [self disableTabContentsViewAutosizing]; |
| 430 | 430 |
| 431 // Terminate previous animation, if it is still playing. | |
| 432 [self terminateBoundsAnimation]; | |
| 433 | |
| 431 NSDictionary *windowResize = [NSDictionary dictionaryWithObjectsAndKeys: | 434 NSDictionary *windowResize = [NSDictionary dictionaryWithObjectsAndKeys: |
| 432 [self window], NSViewAnimationTargetKey, | 435 [self window], NSViewAnimationTargetKey, |
| 433 [NSValue valueWithRect:frame], NSViewAnimationEndFrameKey, nil]; | 436 [NSValue valueWithRect:frame], NSViewAnimationEndFrameKey, nil]; |
| 434 | 437 |
| 435 NSArray *animations = [NSArray arrayWithObjects:windowResize, nil]; | 438 NSArray *animations = [NSArray arrayWithObjects:windowResize, nil]; |
| 436 | 439 |
| 437 // Terminate previous animation, if it is still playing. | |
| 438 [self terminateBoundsAnimation]; | |
| 439 boundsAnimation_ = | 440 boundsAnimation_ = |
| 440 [[NSViewAnimation alloc] initWithViewAnimations:animations]; | 441 [[NSViewAnimation alloc] initWithViewAnimations:animations]; |
| 441 [boundsAnimation_ setDelegate:self]; | 442 [boundsAnimation_ setDelegate:self]; |
| 442 | 443 |
| 443 [boundsAnimation_ setAnimationBlockingMode: NSAnimationNonblocking]; | |
| 444 | |
| 445 NSRect currentFrame = [[self window] frame]; | 444 NSRect currentFrame = [[self window] frame]; |
| 446 // Compute duration. We use constant speed of animation, however if the change | 445 // Compute duration. We use constant speed of animation, however if the change |
| 447 // is too large, we clip the duration (effectively increasing speed) to | 446 // is too large, we clip the duration (effectively increasing speed) to |
| 448 // limit total duration of animation. This makes 'small' transitions fast. | 447 // limit total duration of animation. This makes 'small' transitions fast. |
| 449 // 'distance' is the max travel between 4 potentially traveling corners. | 448 // 'distance' is the max travel between 4 potentially traveling corners. |
| 450 double distanceX = std::max(abs(NSMinX(currentFrame) - NSMinX(frame)), | 449 double distanceX = std::max(abs(NSMinX(currentFrame) - NSMinX(frame)), |
| 451 abs(NSMaxX(currentFrame) - NSMaxX(frame))); | 450 abs(NSMaxX(currentFrame) - NSMaxX(frame))); |
| 452 double distanceY = std::max(abs(NSMinY(currentFrame) - NSMinY(frame)), | 451 double distanceY = std::max(abs(NSMinY(currentFrame) - NSMinY(frame)), |
| 453 abs(NSMaxY(currentFrame) - NSMaxY(frame))); | 452 abs(NSMaxY(currentFrame) - NSMaxY(frame))); |
| 454 double distance = std::max(distanceX, distanceY); | 453 double distance = std::max(distanceX, distanceY); |
| 455 double duration = std::min(distance / kBoundsAnimationSpeedPixelsPerSecond, | 454 double duration = std::min(distance / kBoundsAnimationSpeedPixelsPerSecond, |
| 456 kBoundsAnimationMaxDurationSeconds); | 455 kBoundsAnimationMaxDurationSeconds); |
| 456 // Detect animation that happens when expansion state is set to MINIMIZED | |
| 457 // and there is relatively big portion of the panel to hide from view. | |
| 458 // Initialize animation differently in this case, using fast-pause-slow | |
| 459 // method, see below for more details. | |
| 460 if (windowShim_->panel()->expansion_state() == Panel::MINIMIZED) { | |
| 461 float titlebarToFrameProportion = | |
| 462 (windowShim_->TitleOnlyHeight() - NSHeight(frame)) / distanceY; | |
|
jianli
2011/12/02 06:18:32
Is NSHeight(frame) for the height of the expanded
Dmitry Titov
2011/12/02 06:47:10
The |frame| here is a new frame, since we are mini
| |
| 463 if (titlebarToFrameProportion < 0.3) { // Relatively big movement. | |
| 464 playingMinimizeAnimation_ = YES; | |
| 465 animationSpeedThreshold_ = 1.0 - titlebarToFrameProportion; | |
| 466 duration = 1.5; | |
| 467 } | |
| 468 } | |
| 457 [boundsAnimation_ setDuration: duration]; | 469 [boundsAnimation_ setDuration: duration]; |
| 470 [boundsAnimation_ setFrameRate:0.0]; | |
| 471 [boundsAnimation_ setAnimationBlockingMode: NSAnimationNonblocking]; | |
| 458 [boundsAnimation_ startAnimation]; | 472 [boundsAnimation_ startAnimation]; |
| 459 } | 473 } |
| 460 | 474 |
| 475 - (float)animation:(NSAnimation*)animation | |
| 476 valueForProgress:(NSAnimationProgress)progress { | |
| 477 if (!playingMinimizeAnimation_) { | |
| 478 // Cubic easing out. | |
| 479 float value = 1.0 - progress; | |
| 480 return 1.0 - value * value * value; | |
| 481 } | |
| 482 | |
| 483 // Minimize animation: | |
| 484 // 1. Quickly (0 -> 0.15) make only titlebar visible. | |
| 485 // 2. Stay a little bit (0.15->0.6) in place, just showing titlebar. | |
| 486 // 3. Slowly minimize to thin strip (0.6->1.0) | |
| 487 const float kAnimationStopAfterQuickDecrease = 0.15; | |
| 488 const float kAnimationStopAfterShowingTitlebar = 0.6; | |
| 489 float value; | |
| 490 if (progress <= kAnimationStopAfterQuickDecrease) | |
|
jianli
2011/12/02 06:18:32
nit: better to add brackets.
Dmitry Titov
2011/12/02 06:47:10
Done.
| |
| 491 value = | |
| 492 progress * animationSpeedThreshold_ / kAnimationStopAfterQuickDecrease; | |
| 493 else if (progress <= kAnimationStopAfterShowingTitlebar) | |
| 494 value = animationSpeedThreshold_; | |
| 495 else | |
| 496 value = animationSpeedThreshold_ + | |
| 497 (progress - kAnimationStopAfterShowingTitlebar) * | |
| 498 (1.0 - animationSpeedThreshold_) / | |
| 499 (1.0 - kAnimationStopAfterShowingTitlebar); | |
| 500 return value; | |
| 501 } | |
| 502 | |
| 461 - (void)animationDidEnd:(NSAnimation*)animation { | 503 - (void)animationDidEnd:(NSAnimation*)animation { |
| 504 playingMinimizeAnimation_ = NO; | |
| 462 if (windowShim_->panel()->expansion_state() == Panel::EXPANDED) | 505 if (windowShim_->panel()->expansion_state() == Panel::EXPANDED) |
| 463 [self enableTabContentsViewAutosizing]; | 506 [self enableTabContentsViewAutosizing]; |
| 464 | 507 |
| 465 content::NotificationService::current()->Notify( | 508 content::NotificationService::current()->Notify( |
| 466 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, | 509 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, |
| 467 content::Source<Panel>(windowShim_->panel()), | 510 content::Source<Panel>(windowShim_->panel()), |
| 468 content::NotificationService::NoDetails()); | 511 content::NotificationService::NoDetails()); |
| 469 } | 512 } |
| 470 | 513 |
| 471 - (void)terminateBoundsAnimation { | 514 - (void)terminateBoundsAnimation { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 - (BOOL)canBecomeKeyWindow { | 612 - (BOOL)canBecomeKeyWindow { |
| 570 // Panel can only gain focus if it is expanded. Minimized panels do not | 613 // Panel can only gain focus if it is expanded. Minimized panels do not |
| 571 // participate in Cmd-~ rotation. | 614 // participate in Cmd-~ rotation. |
| 572 // TODO(dimich): If it will be ever desired to expand/focus the Panel on | 615 // TODO(dimich): If it will be ever desired to expand/focus the Panel on |
| 573 // keyboard navigation or via main menu, the care should be taken to avoid | 616 // keyboard navigation or via main menu, the care should be taken to avoid |
| 574 // cases when minimized Panel is getting keyboard input, invisibly. | 617 // cases when minimized Panel is getting keyboard input, invisibly. |
| 575 return windowShim_->panel()->expansion_state() == Panel::EXPANDED; | 618 return windowShim_->panel()->expansion_state() == Panel::EXPANDED; |
| 576 } | 619 } |
| 577 | 620 |
| 578 @end | 621 @end |
| OLD | NEW |