| 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 "ui/wm/core/window_animations.h" | 5 #include "ui/wm/core/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 <memory> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" |
| 16 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 17 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 19 #include "ui/aura/client/aura_constants.h" | 20 #include "ui/aura/client/aura_constants.h" |
| 20 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 21 #include "ui/aura/window_delegate.h" | 22 #include "ui/aura/window_delegate.h" |
| 22 #include "ui/aura/window_observer.h" | 23 #include "ui/aura/window_observer.h" |
| 23 #include "ui/aura/window_property.h" | 24 #include "ui/aura/window_property.h" |
| 24 #include "ui/compositor/compositor_observer.h" | 25 #include "ui/compositor/compositor_observer.h" |
| 25 #include "ui/compositor/layer.h" | 26 #include "ui/compositor/layer.h" |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 | 345 |
| 345 // Show/Hide windows using a fade. | 346 // Show/Hide windows using a fade. |
| 346 void AnimateShowWindow_Fade(aura::Window* window) { | 347 void AnimateShowWindow_Fade(aura::Window* window) { |
| 347 AnimateShowWindowCommon(window, gfx::Transform(), gfx::Transform()); | 348 AnimateShowWindowCommon(window, gfx::Transform(), gfx::Transform()); |
| 348 } | 349 } |
| 349 | 350 |
| 350 void AnimateHideWindow_Fade(aura::Window* window) { | 351 void AnimateHideWindow_Fade(aura::Window* window) { |
| 351 AnimateHideWindowCommon(window, gfx::Transform()); | 352 AnimateHideWindowCommon(window, gfx::Transform()); |
| 352 } | 353 } |
| 353 | 354 |
| 354 ui::LayerAnimationElement* CreateGrowShrinkElement( | 355 std::unique_ptr<ui::LayerAnimationElement> CreateGrowShrinkElement( |
| 355 aura::Window* window, bool grow) { | 356 aura::Window* window, |
| 356 std::unique_ptr<ui::InterpolatedTransform> scale( | 357 bool grow) { |
| 357 new ui::InterpolatedScale(gfx::Point3F(kWindowAnimation_Bounce_Scale, | 358 std::unique_ptr<ui::InterpolatedTransform> scale = |
| 358 kWindowAnimation_Bounce_Scale, 1), | 359 base::MakeUnique<ui::InterpolatedScale>( |
| 359 gfx::Point3F(1, 1, 1))); | 360 gfx::Point3F(kWindowAnimation_Bounce_Scale, |
| 360 std::unique_ptr<ui::InterpolatedTransform> scale_about_pivot( | 361 kWindowAnimation_Bounce_Scale, 1), |
| 361 new ui::InterpolatedTransformAboutPivot( | 362 gfx::Point3F(1, 1, 1)); |
| 363 std::unique_ptr<ui::InterpolatedTransform> scale_about_pivot = |
| 364 base::MakeUnique<ui::InterpolatedTransformAboutPivot>( |
| 362 gfx::Point(window->bounds().width() * 0.5, | 365 gfx::Point(window->bounds().width() * 0.5, |
| 363 window->bounds().height() * 0.5), | 366 window->bounds().height() * 0.5), |
| 364 scale.release())); | 367 std::move(scale)); |
| 365 scale_about_pivot->SetReversed(grow); | 368 scale_about_pivot->SetReversed(grow); |
| 366 std::unique_ptr<ui::LayerAnimationElement> transition( | 369 std::unique_ptr<ui::LayerAnimationElement> transition = |
| 367 ui::LayerAnimationElement::CreateInterpolatedTransformElement( | 370 ui::LayerAnimationElement::CreateInterpolatedTransformElement( |
| 368 scale_about_pivot.release(), | 371 std::move(scale_about_pivot), |
| 369 base::TimeDelta::FromMilliseconds( | 372 base::TimeDelta::FromMilliseconds( |
| 370 kWindowAnimation_Bounce_DurationMS * | 373 kWindowAnimation_Bounce_DurationMS * |
| 371 kWindowAnimation_Bounce_GrowShrinkDurationPercent / 100))); | 374 kWindowAnimation_Bounce_GrowShrinkDurationPercent / 100)); |
| 372 transition->set_tween_type(grow ? gfx::Tween::EASE_OUT : gfx::Tween::EASE_IN); | 375 transition->set_tween_type(grow ? gfx::Tween::EASE_OUT : gfx::Tween::EASE_IN); |
| 373 return transition.release(); | 376 return transition; |
| 374 } | 377 } |
| 375 | 378 |
| 376 void AnimateBounce(aura::Window* window) { | 379 void AnimateBounce(aura::Window* window) { |
| 377 ui::ScopedLayerAnimationSettings scoped_settings( | 380 ui::ScopedLayerAnimationSettings scoped_settings( |
| 378 window->layer()->GetAnimator()); | 381 window->layer()->GetAnimator()); |
| 379 scoped_settings.SetPreemptionStrategy( | 382 scoped_settings.SetPreemptionStrategy( |
| 380 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | 383 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
| 381 std::unique_ptr<ui::LayerAnimationSequence> sequence( | 384 std::unique_ptr<ui::LayerAnimationSequence> sequence = |
| 382 new ui::LayerAnimationSequence); | 385 base::MakeUnique<ui::LayerAnimationSequence>(); |
| 383 sequence->AddElement(CreateGrowShrinkElement(window, true)); | 386 sequence->AddElement(CreateGrowShrinkElement(window, true)); |
| 384 sequence->AddElement(ui::LayerAnimationElement::CreatePauseElement( | 387 sequence->AddElement(ui::LayerAnimationElement::CreatePauseElement( |
| 385 ui::LayerAnimationElement::BOUNDS, | 388 ui::LayerAnimationElement::BOUNDS, |
| 386 base::TimeDelta::FromMilliseconds( | 389 base::TimeDelta::FromMilliseconds( |
| 387 kWindowAnimation_Bounce_DurationMS * | 390 kWindowAnimation_Bounce_DurationMS * |
| 388 (100 - 2 * kWindowAnimation_Bounce_GrowShrinkDurationPercent) / | 391 (100 - 2 * kWindowAnimation_Bounce_GrowShrinkDurationPercent) / |
| 389 100))); | 392 100))); |
| 390 sequence->AddElement(CreateGrowShrinkElement(window, false)); | 393 sequence->AddElement(CreateGrowShrinkElement(window, false)); |
| 391 window->layer()->GetAnimator()->StartAnimation(sequence.release()); | 394 window->layer()->GetAnimator()->StartAnimation(sequence.release()); |
| 392 } | 395 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 kWindowAnimation_Rotate_DurationMS); | 432 kWindowAnimation_Rotate_DurationMS); |
| 430 | 433 |
| 431 RotateHidingWindowAnimationObserver* observer = NULL; | 434 RotateHidingWindowAnimationObserver* observer = NULL; |
| 432 | 435 |
| 433 if (!show) { | 436 if (!show) { |
| 434 observer = new RotateHidingWindowAnimationObserver(window); | 437 observer = new RotateHidingWindowAnimationObserver(window); |
| 435 window->layer()->GetAnimator()->SchedulePauseForProperties( | 438 window->layer()->GetAnimator()->SchedulePauseForProperties( |
| 436 duration * (100 - kWindowAnimation_Rotate_OpacityDurationPercent) / 100, | 439 duration * (100 - kWindowAnimation_Rotate_OpacityDurationPercent) / 100, |
| 437 ui::LayerAnimationElement::OPACITY); | 440 ui::LayerAnimationElement::OPACITY); |
| 438 } | 441 } |
| 439 std::unique_ptr<ui::LayerAnimationElement> opacity( | 442 std::unique_ptr<ui::LayerAnimationElement> opacity = |
| 440 ui::LayerAnimationElement::CreateOpacityElement( | 443 ui::LayerAnimationElement::CreateOpacityElement( |
| 441 show ? kWindowAnimation_ShowOpacity : kWindowAnimation_HideOpacity, | 444 show ? kWindowAnimation_ShowOpacity : kWindowAnimation_HideOpacity, |
| 442 duration * kWindowAnimation_Rotate_OpacityDurationPercent / 100)); | 445 duration * kWindowAnimation_Rotate_OpacityDurationPercent / 100); |
| 443 opacity->set_tween_type(gfx::Tween::EASE_IN_OUT); | 446 opacity->set_tween_type(gfx::Tween::EASE_IN_OUT); |
| 444 window->layer()->GetAnimator()->ScheduleAnimation( | 447 window->layer()->GetAnimator()->ScheduleAnimation( |
| 445 new ui::LayerAnimationSequence(opacity.release())); | 448 new ui::LayerAnimationSequence(std::move(opacity))); |
| 446 | 449 |
| 447 float xcenter = window->bounds().width() * 0.5; | 450 float xcenter = window->bounds().width() * 0.5; |
| 448 | 451 |
| 449 gfx::Transform transform; | 452 gfx::Transform transform; |
| 450 transform.Translate(xcenter, 0); | 453 transform.Translate(xcenter, 0); |
| 451 transform.ApplyPerspectiveDepth(kWindowAnimation_Rotate_PerspectiveDepth); | 454 transform.ApplyPerspectiveDepth(kWindowAnimation_Rotate_PerspectiveDepth); |
| 452 transform.Translate(-xcenter, 0); | 455 transform.Translate(-xcenter, 0); |
| 453 std::unique_ptr<ui::InterpolatedTransform> perspective( | 456 std::unique_ptr<ui::InterpolatedTransform> perspective = |
| 454 new ui::InterpolatedConstantTransform(transform)); | 457 base::MakeUnique<ui::InterpolatedConstantTransform>(transform); |
| 455 | 458 |
| 456 std::unique_ptr<ui::InterpolatedTransform> scale( | 459 std::unique_ptr<ui::InterpolatedTransform> scale = |
| 457 new ui::InterpolatedScale(1, kWindowAnimation_Rotate_ScaleFactor)); | 460 base::MakeUnique<ui::InterpolatedScale>( |
| 458 std::unique_ptr<ui::InterpolatedTransform> scale_about_pivot( | 461 1, kWindowAnimation_Rotate_ScaleFactor); |
| 459 new ui::InterpolatedTransformAboutPivot( | 462 std::unique_ptr<ui::InterpolatedTransform> scale_about_pivot = |
| 463 base::MakeUnique<ui::InterpolatedTransformAboutPivot>( |
| 460 gfx::Point(xcenter, kWindowAnimation_Rotate_TranslateY), | 464 gfx::Point(xcenter, kWindowAnimation_Rotate_TranslateY), |
| 461 scale.release())); | 465 std::move(scale)); |
| 462 | 466 |
| 463 std::unique_ptr<ui::InterpolatedTransform> translation( | 467 std::unique_ptr<ui::InterpolatedTransform> translation = |
| 464 new ui::InterpolatedTranslation( | 468 base::MakeUnique<ui::InterpolatedTranslation>( |
| 465 gfx::PointF(), gfx::PointF(0, kWindowAnimation_Rotate_TranslateY))); | 469 gfx::PointF(), gfx::PointF(0, kWindowAnimation_Rotate_TranslateY)); |
| 466 | 470 |
| 467 std::unique_ptr<ui::InterpolatedTransform> rotation( | 471 std::unique_ptr<ui::InterpolatedTransform> rotation = |
| 468 new ui::InterpolatedAxisAngleRotation(gfx::Vector3dF(1, 0, 0), 0, | 472 base::MakeUnique<ui::InterpolatedAxisAngleRotation>( |
| 469 kWindowAnimation_Rotate_DegreesX)); | 473 gfx::Vector3dF(1, 0, 0), 0, kWindowAnimation_Rotate_DegreesX); |
| 470 | 474 |
| 471 scale_about_pivot->SetChild(perspective.release()); | 475 scale_about_pivot->SetChild(std::move(perspective)); |
| 472 translation->SetChild(scale_about_pivot.release()); | 476 translation->SetChild(std::move(scale_about_pivot)); |
| 473 rotation->SetChild(translation.release()); | 477 rotation->SetChild(std::move(translation)); |
| 474 rotation->SetReversed(show); | 478 rotation->SetReversed(show); |
| 475 | 479 |
| 476 std::unique_ptr<ui::LayerAnimationElement> transition( | 480 std::unique_ptr<ui::LayerAnimationElement> transition = |
| 477 ui::LayerAnimationElement::CreateInterpolatedTransformElement( | 481 ui::LayerAnimationElement::CreateInterpolatedTransformElement( |
| 478 rotation.release(), duration)); | 482 std::move(rotation), duration); |
| 479 ui::LayerAnimationSequence* last_sequence = | 483 ui::LayerAnimationSequence* last_sequence = |
| 480 new ui::LayerAnimationSequence(transition.release()); | 484 new ui::LayerAnimationSequence(std::move(transition)); |
| 481 window->layer()->GetAnimator()->ScheduleAnimation(last_sequence); | 485 window->layer()->GetAnimator()->ScheduleAnimation(last_sequence); |
| 482 | 486 |
| 483 if (observer) { | 487 if (observer) { |
| 484 observer->SetLastSequence(last_sequence); | 488 observer->SetLastSequence(last_sequence); |
| 485 observer->DetachAndRecreateLayers(); | 489 observer->DetachAndRecreateLayers(); |
| 486 } | 490 } |
| 487 } | 491 } |
| 488 | 492 |
| 489 void AnimateShowWindow_Rotate(aura::Window* window) { | 493 void AnimateShowWindow_Rotate(aura::Window* window) { |
| 490 AddLayerAnimationsForRotate(window, true); | 494 AddLayerAnimationsForRotate(window, true); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 // being accessed via Remote Desktop. | 664 // being accessed via Remote Desktop. |
| 661 if (ui::ScopedAnimationDurationScaleMode::duration_scale_mode() == | 665 if (ui::ScopedAnimationDurationScaleMode::duration_scale_mode() == |
| 662 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION) | 666 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION) |
| 663 return false; | 667 return false; |
| 664 | 668 |
| 665 // Let the user decide whether or not to play the animation. | 669 // Let the user decide whether or not to play the animation. |
| 666 return !gfx::Animation::ShouldRenderRichAnimation(); | 670 return !gfx::Animation::ShouldRenderRichAnimation(); |
| 667 } | 671 } |
| 668 | 672 |
| 669 } // namespace wm | 673 } // namespace wm |
| OLD | NEW |