OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/wm/window_animations.h" | 5 #include "ash/wm/window_animations.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 DEFINE_WINDOW_PROPERTY_KEY(WindowVisibilityAnimationTransition, | 58 DEFINE_WINDOW_PROPERTY_KEY(WindowVisibilityAnimationTransition, |
59 kWindowVisibilityAnimationTransitionKey, | 59 kWindowVisibilityAnimationTransitionKey, |
60 ANIMATE_BOTH); | 60 ANIMATE_BOTH); |
61 DEFINE_WINDOW_PROPERTY_KEY(float, | 61 DEFINE_WINDOW_PROPERTY_KEY(float, |
62 kWindowVisibilityAnimationVerticalPositionKey, | 62 kWindowVisibilityAnimationVerticalPositionKey, |
63 kWindowAnimation_Vertical_TranslateY); | 63 kWindowAnimation_Vertical_TranslateY); |
64 | 64 |
65 namespace { | 65 namespace { |
66 | 66 |
67 const int kDefaultAnimationDurationForMenuMS = 150; | 67 const int kDefaultAnimationDurationForMenuMS = 150; |
| 68 const int kLayerAnimationsForMinimizeDurationMS = 350; |
68 | 69 |
69 // Durations for the cross-fade animation, in milliseconds. | 70 // Durations for the cross-fade animation, in milliseconds. |
70 const float kCrossFadeDurationMinMs = 100.f; | 71 const float kCrossFadeDurationMinMs = 100.f; |
71 const float kCrossFadeDurationMaxMs = 400.f; | 72 const float kCrossFadeDurationMaxMs = 400.f; |
72 | 73 |
73 // Durations for the brightness/grayscale fade animation, in milliseconds. | 74 // Durations for the brightness/grayscale fade animation, in milliseconds. |
74 const int kBrightnessGrayscaleFadeDurationMs = 1000; | 75 const int kBrightnessGrayscaleFadeDurationMs = 1000; |
75 | 76 |
76 // Brightness/grayscale values for hide/show window animations. | 77 // Brightness/grayscale values for hide/show window animations. |
77 const float kWindowAnimation_HideBrightnessGrayscale = 1.f; | 78 const float kWindowAnimation_HideBrightnessGrayscale = 1.f; |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 scoped_ptr<ui::InterpolatedTransform> rotation_about_pivot( | 429 scoped_ptr<ui::InterpolatedTransform> rotation_about_pivot( |
429 new ui::InterpolatedTransformAboutPivot( | 430 new ui::InterpolatedTransformAboutPivot( |
430 gfx::Point(bounds.width() * 0.5, bounds.height() * 0.5), | 431 gfx::Point(bounds.width() * 0.5, bounds.height() * 0.5), |
431 rotation.release())); | 432 rotation.release())); |
432 | 433 |
433 scale->SetChild(translation.release()); | 434 scale->SetChild(translation.release()); |
434 rotation_about_pivot->SetChild(scale.release()); | 435 rotation_about_pivot->SetChild(scale.release()); |
435 | 436 |
436 rotation_about_pivot->SetReversed(show); | 437 rotation_about_pivot->SetReversed(show); |
437 | 438 |
438 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(350); | 439 base::TimeDelta duration = base::TimeDelta::FromMilliseconds( |
| 440 kLayerAnimationsForMinimizeDurationMS); |
439 | 441 |
440 scoped_ptr<ui::LayerAnimationElement> transition( | 442 scoped_ptr<ui::LayerAnimationElement> transition( |
441 ui::LayerAnimationElement::CreateInterpolatedTransformElement( | 443 ui::LayerAnimationElement::CreateInterpolatedTransformElement( |
442 rotation_about_pivot.release(), duration)); | 444 rotation_about_pivot.release(), duration)); |
443 | 445 |
444 transition->set_tween_type( | 446 transition->set_tween_type( |
445 show ? ui::Tween::EASE_IN : ui::Tween::EASE_IN_OUT); | 447 show ? ui::Tween::EASE_IN : ui::Tween::EASE_IN_OUT); |
446 | 448 |
447 window->layer()->GetAnimator()->ScheduleAnimation( | 449 window->layer()->GetAnimator()->ScheduleAnimation( |
448 new ui::LayerAnimationSequence(transition.release())); | 450 new ui::LayerAnimationSequence(transition.release())); |
449 | 451 |
| 452 // When hiding a window, turn off blending until the animation is |
| 453 // 3 / 4 done to save bandwidth and reduce jank |
| 454 if (!show) { |
| 455 ui::LayerAnimationElement::AnimatableProperties propertiesToPause; |
| 456 propertiesToPause.insert(ui::LayerAnimationElement::OPACITY); |
| 457 window->layer()->GetAnimator()->ScheduleAnimation( |
| 458 new ui::LayerAnimationSequence( |
| 459 ui::LayerAnimationElement::CreatePauseElement( |
| 460 propertiesToPause, (duration * 3 ) / 4))); |
| 461 } |
| 462 |
| 463 // Fade in and out quickly when the window is small to reduce jank |
450 float opacity = show ? 1.0f : 0.0f; | 464 float opacity = show ? 1.0f : 0.0f; |
451 window->layer()->GetAnimator()->ScheduleAnimation( | 465 window->layer()->GetAnimator()->ScheduleAnimation( |
452 new ui::LayerAnimationSequence( | 466 new ui::LayerAnimationSequence( |
453 ui::LayerAnimationElement::CreateOpacityElement(opacity, duration))); | 467 ui::LayerAnimationElement::CreateOpacityElement( |
| 468 opacity, duration / 4))); |
454 } | 469 } |
455 | 470 |
456 void AnimateShowWindow_Minimize(aura::Window* window) { | 471 void AnimateShowWindow_Minimize(aura::Window* window) { |
457 window->layer()->set_delegate(window); | 472 window->layer()->set_delegate(window); |
458 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); | 473 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); |
459 AddLayerAnimationsForMinimize(window, true); | 474 AddLayerAnimationsForMinimize(window, true); |
460 | 475 |
461 // Now that the window has been restored, we need to clear its animation style | 476 // Now that the window has been restored, we need to clear its animation style |
462 // to default so that normal animation applies. | 477 // to default so that normal animation applies. |
463 SetWindowVisibilityAnimationType( | 478 SetWindowVisibilityAnimationType( |
464 window, WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT); | 479 window, WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT); |
465 } | 480 } |
466 | 481 |
467 void AnimateHideWindow_Minimize(aura::Window* window) { | 482 void AnimateHideWindow_Minimize(aura::Window* window) { |
468 window->layer()->set_delegate(NULL); | 483 window->layer()->set_delegate(NULL); |
469 | 484 |
470 // Property sets within this scope will be implicitly animated. | 485 // Property sets within this scope will be implicitly animated. |
471 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 486 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
| 487 base::TimeDelta duration = base::TimeDelta::FromMilliseconds( |
| 488 kLayerAnimationsForMinimizeDurationMS); |
| 489 settings.SetTransitionDuration(duration); |
472 settings.AddObserver(new HidingWindowAnimationObserver(window)); | 490 settings.AddObserver(new HidingWindowAnimationObserver(window)); |
473 window->layer()->SetVisible(false); | 491 window->layer()->SetVisible(false); |
474 | 492 |
475 AddLayerAnimationsForMinimize(window, false); | 493 AddLayerAnimationsForMinimize(window, false); |
476 } | 494 } |
477 | 495 |
478 void AnimateShowHideWindowCommon_BrightnessGrayscale(aura::Window* window, | 496 void AnimateShowHideWindowCommon_BrightnessGrayscale(aura::Window* window, |
479 bool show) { | 497 bool show) { |
480 window->layer()->set_delegate(window); | 498 window->layer()->set_delegate(window); |
481 | 499 |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 AnimateHideWindow(window); | 877 AnimateHideWindow(window); |
860 } | 878 } |
861 } | 879 } |
862 | 880 |
863 void SetDelayedOldLayerDeletionInCrossFadeForTest(bool value) { | 881 void SetDelayedOldLayerDeletionInCrossFadeForTest(bool value) { |
864 delayed_old_layer_deletion_in_cross_fade_for_test_ = value; | 882 delayed_old_layer_deletion_in_cross_fade_for_test_ = value; |
865 } | 883 } |
866 | 884 |
867 } // namespace internal | 885 } // namespace internal |
868 } // namespace ash | 886 } // namespace ash |
OLD | NEW |