| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/animation/keyframed_animation_curve.h" | 5 #include "cc/animation/keyframed_animation_curve.h" |
| 6 | 6 |
| 7 #include "cc/animation/transform_operations.h" | 7 #include "cc/animation/transform_operations.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/gfx/animation/tween.h" | 10 #include "ui/gfx/animation/tween.h" |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 KeyframedTransformAnimationCurve::Create()); | 541 KeyframedTransformAnimationCurve::Create()); |
| 542 | 542 |
| 543 TransformOperations operations1; | 543 TransformOperations operations1; |
| 544 curve->AddKeyframe( | 544 curve->AddKeyframe( |
| 545 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 545 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
| 546 operations1.AppendTranslate(2.0, 3.0, -1.0); | 546 operations1.AppendTranslate(2.0, 3.0, -1.0); |
| 547 curve->AddKeyframe(TransformKeyframe::Create( | 547 curve->AddKeyframe(TransformKeyframe::Create( |
| 548 base::TimeDelta::FromSecondsD(0.5f), operations1, nullptr)); | 548 base::TimeDelta::FromSecondsD(0.5f), operations1, nullptr)); |
| 549 TransformOperations operations2; | 549 TransformOperations operations2; |
| 550 operations2.AppendTranslate(4.0, 1.0, 2.0); | 550 operations2.AppendTranslate(4.0, 1.0, 2.0); |
| 551 curve->AddKeyframe( | 551 curve->AddKeyframe(TransformKeyframe::Create( |
| 552 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), operations2, | 552 base::TimeDelta::FromSecondsD(1.f), operations2, |
| 553 EaseTimingFunction::Create())); | 553 CubicBezierTimingFunction::CreatePreset( |
| 554 CubicBezierTimingFunction::EaseType::EASE))); |
| 554 | 555 |
| 555 gfx::BoxF box(2.f, 3.f, 4.f, 1.f, 3.f, 2.f); | 556 gfx::BoxF box(2.f, 3.f, 4.f, 1.f, 3.f, 2.f); |
| 556 gfx::BoxF bounds; | 557 gfx::BoxF bounds; |
| 557 | 558 |
| 558 EXPECT_TRUE(curve->AnimatedBoundsForBox(box, &bounds)); | 559 EXPECT_TRUE(curve->AnimatedBoundsForBox(box, &bounds)); |
| 559 EXPECT_EQ(gfx::BoxF(2.f, 3.f, 3.f, 5.f, 6.f, 5.f).ToString(), | 560 EXPECT_EQ(gfx::BoxF(2.f, 3.f, 3.f, 5.f, 6.f, 5.f).ToString(), |
| 560 bounds.ToString()); | 561 bounds.ToString()); |
| 561 } | 562 } |
| 562 | 563 |
| 563 // Tests that animations that affect scale are correctly identified. | 564 // Tests that animations that affect scale are correctly identified. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 | 625 |
| 625 // Tests that maximum target scale is computed as expected. | 626 // Tests that maximum target scale is computed as expected. |
| 626 TEST(KeyframedAnimationCurveTest, MaximumTargetScale) { | 627 TEST(KeyframedAnimationCurveTest, MaximumTargetScale) { |
| 627 std::unique_ptr<KeyframedTransformAnimationCurve> curve( | 628 std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
| 628 KeyframedTransformAnimationCurve::Create()); | 629 KeyframedTransformAnimationCurve::Create()); |
| 629 | 630 |
| 630 TransformOperations operations1; | 631 TransformOperations operations1; |
| 631 curve->AddKeyframe( | 632 curve->AddKeyframe( |
| 632 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 633 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
| 633 operations1.AppendScale(2.f, -3.f, 1.f); | 634 operations1.AppendScale(2.f, -3.f, 1.f); |
| 634 curve->AddKeyframe( | 635 curve->AddKeyframe(TransformKeyframe::Create( |
| 635 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), operations1, | 636 base::TimeDelta::FromSecondsD(1.f), operations1, |
| 636 EaseTimingFunction::Create())); | 637 CubicBezierTimingFunction::CreatePreset( |
| 638 CubicBezierTimingFunction::EaseType::EASE))); |
| 637 | 639 |
| 638 float maximum_scale = 0.f; | 640 float maximum_scale = 0.f; |
| 639 EXPECT_TRUE(curve->MaximumTargetScale(true, &maximum_scale)); | 641 EXPECT_TRUE(curve->MaximumTargetScale(true, &maximum_scale)); |
| 640 EXPECT_EQ(3.f, maximum_scale); | 642 EXPECT_EQ(3.f, maximum_scale); |
| 641 | 643 |
| 642 TransformOperations operations2; | 644 TransformOperations operations2; |
| 643 operations2.AppendScale(6.f, 3.f, 2.f); | 645 operations2.AppendScale(6.f, 3.f, 2.f); |
| 644 curve->AddKeyframe( | 646 curve->AddKeyframe(TransformKeyframe::Create( |
| 645 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(2.f), operations2, | 647 base::TimeDelta::FromSecondsD(2.f), operations2, |
| 646 EaseTimingFunction::Create())); | 648 CubicBezierTimingFunction::CreatePreset( |
| 649 CubicBezierTimingFunction::EaseType::EASE))); |
| 647 | 650 |
| 648 EXPECT_TRUE(curve->MaximumTargetScale(true, &maximum_scale)); | 651 EXPECT_TRUE(curve->MaximumTargetScale(true, &maximum_scale)); |
| 649 EXPECT_EQ(6.f, maximum_scale); | 652 EXPECT_EQ(6.f, maximum_scale); |
| 650 | 653 |
| 651 TransformOperations operations3; | 654 TransformOperations operations3; |
| 652 operations3.AppendRotate(1.f, 0.f, 0.f, 90.f); | 655 operations3.AppendRotate(1.f, 0.f, 0.f, 90.f); |
| 653 curve->AddKeyframe( | 656 curve->AddKeyframe(TransformKeyframe::Create( |
| 654 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(3.f), operations3, | 657 base::TimeDelta::FromSecondsD(3.f), operations3, |
| 655 EaseTimingFunction::Create())); | 658 CubicBezierTimingFunction::CreatePreset( |
| 659 CubicBezierTimingFunction::EaseType::EASE))); |
| 656 | 660 |
| 657 EXPECT_FALSE(curve->MaximumTargetScale(true, &maximum_scale)); | 661 EXPECT_FALSE(curve->MaximumTargetScale(true, &maximum_scale)); |
| 658 | 662 |
| 659 // The original scale is not used in computing the max. | 663 // The original scale is not used in computing the max. |
| 660 std::unique_ptr<KeyframedTransformAnimationCurve> curve2( | 664 std::unique_ptr<KeyframedTransformAnimationCurve> curve2( |
| 661 KeyframedTransformAnimationCurve::Create()); | 665 KeyframedTransformAnimationCurve::Create()); |
| 662 | 666 |
| 663 TransformOperations operations4; | 667 TransformOperations operations4; |
| 664 operations4.AppendScale(0.4f, 0.2f, 0.6f); | 668 operations4.AppendScale(0.4f, 0.2f, 0.6f); |
| 665 curve2->AddKeyframe(TransformKeyframe::Create(base::TimeDelta(), operations4, | 669 curve2->AddKeyframe(TransformKeyframe::Create( |
| 666 EaseTimingFunction::Create())); | 670 base::TimeDelta(), operations4, |
| 671 CubicBezierTimingFunction::CreatePreset( |
| 672 CubicBezierTimingFunction::EaseType::EASE))); |
| 667 TransformOperations operations5; | 673 TransformOperations operations5; |
| 668 operations5.AppendScale(0.5f, 0.3f, -0.8f); | 674 operations5.AppendScale(0.5f, 0.3f, -0.8f); |
| 669 curve2->AddKeyframe( | 675 curve2->AddKeyframe(TransformKeyframe::Create( |
| 670 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), operations5, | 676 base::TimeDelta::FromSecondsD(1.f), operations5, |
| 671 EaseTimingFunction::Create())); | 677 CubicBezierTimingFunction::CreatePreset( |
| 678 CubicBezierTimingFunction::EaseType::EASE))); |
| 672 | 679 |
| 673 EXPECT_TRUE(curve2->MaximumTargetScale(true, &maximum_scale)); | 680 EXPECT_TRUE(curve2->MaximumTargetScale(true, &maximum_scale)); |
| 674 EXPECT_EQ(0.8f, maximum_scale); | 681 EXPECT_EQ(0.8f, maximum_scale); |
| 675 | 682 |
| 676 EXPECT_TRUE(curve2->MaximumTargetScale(false, &maximum_scale)); | 683 EXPECT_TRUE(curve2->MaximumTargetScale(false, &maximum_scale)); |
| 677 EXPECT_EQ(0.6f, maximum_scale); | 684 EXPECT_EQ(0.6f, maximum_scale); |
| 678 } | 685 } |
| 679 | 686 |
| 680 // Tests that starting animation scale is computed as expected. | 687 // Tests that starting animation scale is computed as expected. |
| 681 TEST(KeyframedAnimationCurveTest, AnimationStartScale) { | 688 TEST(KeyframedAnimationCurveTest, AnimationStartScale) { |
| 682 std::unique_ptr<KeyframedTransformAnimationCurve> curve( | 689 std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
| 683 KeyframedTransformAnimationCurve::Create()); | 690 KeyframedTransformAnimationCurve::Create()); |
| 684 | 691 |
| 685 TransformOperations operations1; | 692 TransformOperations operations1; |
| 686 curve->AddKeyframe( | 693 curve->AddKeyframe( |
| 687 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 694 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
| 688 operations1.AppendScale(2.f, -3.f, 1.f); | 695 operations1.AppendScale(2.f, -3.f, 1.f); |
| 689 curve->AddKeyframe( | 696 curve->AddKeyframe(TransformKeyframe::Create( |
| 690 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), operations1, | 697 base::TimeDelta::FromSecondsD(1.f), operations1, |
| 691 EaseTimingFunction::Create())); | 698 CubicBezierTimingFunction::CreatePreset( |
| 699 CubicBezierTimingFunction::EaseType::EASE))); |
| 692 | 700 |
| 693 float start_scale = 0.f; | 701 float start_scale = 0.f; |
| 694 | 702 |
| 695 // Forward direction | 703 // Forward direction |
| 696 EXPECT_TRUE(curve->AnimationStartScale(true, &start_scale)); | 704 EXPECT_TRUE(curve->AnimationStartScale(true, &start_scale)); |
| 697 EXPECT_EQ(1.f, start_scale); | 705 EXPECT_EQ(1.f, start_scale); |
| 698 | 706 |
| 699 // Backward direction | 707 // Backward direction |
| 700 EXPECT_TRUE(curve->AnimationStartScale(false, &start_scale)); | 708 EXPECT_TRUE(curve->AnimationStartScale(false, &start_scale)); |
| 701 EXPECT_EQ(3.f, start_scale); | 709 EXPECT_EQ(3.f, start_scale); |
| 702 | 710 |
| 703 TransformOperations operations2; | 711 TransformOperations operations2; |
| 704 operations2.AppendScale(6.f, 3.f, 2.f); | 712 operations2.AppendScale(6.f, 3.f, 2.f); |
| 705 curve->AddKeyframe( | 713 curve->AddKeyframe(TransformKeyframe::Create( |
| 706 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(2.f), operations2, | 714 base::TimeDelta::FromSecondsD(2.f), operations2, |
| 707 EaseTimingFunction::Create())); | 715 CubicBezierTimingFunction::CreatePreset( |
| 716 CubicBezierTimingFunction::EaseType::EASE))); |
| 708 | 717 |
| 709 // Backward direction | 718 // Backward direction |
| 710 EXPECT_TRUE(curve->AnimationStartScale(true, &start_scale)); | 719 EXPECT_TRUE(curve->AnimationStartScale(true, &start_scale)); |
| 711 EXPECT_EQ(1.f, start_scale); | 720 EXPECT_EQ(1.f, start_scale); |
| 712 | 721 |
| 713 // Backward direction | 722 // Backward direction |
| 714 EXPECT_TRUE(curve->AnimationStartScale(false, &start_scale)); | 723 EXPECT_TRUE(curve->AnimationStartScale(false, &start_scale)); |
| 715 EXPECT_EQ(6.f, start_scale); | 724 EXPECT_EQ(6.f, start_scale); |
| 716 | 725 |
| 717 TransformOperations operations3; | 726 TransformOperations operations3; |
| 718 operations3.AppendRotate(1.f, 0.f, 0.f, 90.f); | 727 operations3.AppendRotate(1.f, 0.f, 0.f, 90.f); |
| 719 curve->AddKeyframe( | 728 curve->AddKeyframe(TransformKeyframe::Create( |
| 720 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(3.f), operations3, | 729 base::TimeDelta::FromSecondsD(3.f), operations3, |
| 721 EaseTimingFunction::Create())); | 730 CubicBezierTimingFunction::CreatePreset( |
| 731 CubicBezierTimingFunction::EaseType::EASE))); |
| 722 | 732 |
| 723 EXPECT_FALSE(curve->AnimationStartScale(false, &start_scale)); | 733 EXPECT_FALSE(curve->AnimationStartScale(false, &start_scale)); |
| 724 EXPECT_EQ(0.f, start_scale); | 734 EXPECT_EQ(0.f, start_scale); |
| 725 } | 735 } |
| 726 | 736 |
| 727 // Tests that an animation with a curve timing function works as expected. | 737 // Tests that an animation with a curve timing function works as expected. |
| 728 TEST(KeyframedAnimationCurveTest, CurveTiming) { | 738 TEST(KeyframedAnimationCurveTest, CurveTiming) { |
| 729 std::unique_ptr<KeyframedFloatAnimationCurve> curve( | 739 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
| 730 KeyframedFloatAnimationCurve::Create()); | 740 KeyframedFloatAnimationCurve::Create()); |
| 731 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr)); | 741 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr)); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 curve->SetTimingFunction( | 893 curve->SetTimingFunction( |
| 884 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f)); | 894 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f)); |
| 885 EXPECT_LE(curve->GetValue(base::TimeDelta::FromSecondsD(1.f)), | 895 EXPECT_LE(curve->GetValue(base::TimeDelta::FromSecondsD(1.f)), |
| 886 0.f); // c(.25) < 0 | 896 0.f); // c(.25) < 0 |
| 887 EXPECT_GE(curve->GetValue(base::TimeDelta::FromSecondsD(3.f)), | 897 EXPECT_GE(curve->GetValue(base::TimeDelta::FromSecondsD(3.f)), |
| 888 9.f); // c(.75) > 1 | 898 9.f); // c(.75) > 1 |
| 889 } | 899 } |
| 890 | 900 |
| 891 } // namespace | 901 } // namespace |
| 892 } // namespace cc | 902 } // namespace cc |
| OLD | NEW |