| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/animation/AnimationStack.h" | 6 #include "core/animation/AnimationStack.h" |
| 7 | 7 |
| 8 #include "core/animation/AnimationClock.h" | 8 #include "core/animation/AnimationClock.h" |
| 9 #include "core/animation/AnimationTimeline.h" | 9 #include "core/animation/AnimationTimeline.h" |
| 10 #include "core/animation/ElementAnimations.h" | 10 #include "core/animation/ElementAnimations.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 animation->update(TimingUpdateOnDemand); | 32 animation->update(TimingUpdateOnDemand); |
| 33 return animation; | 33 return animation; |
| 34 } | 34 } |
| 35 | 35 |
| 36 void updateTimeline(double time) | 36 void updateTimeline(double time) |
| 37 { | 37 { |
| 38 document->animationClock().updateTime(time); | 38 document->animationClock().updateTime(time); |
| 39 timeline->serviceAnimations(TimingUpdateForAnimationFrame); | 39 timeline->serviceAnimations(TimingUpdateForAnimationFrame); |
| 40 } | 40 } |
| 41 | 41 |
| 42 const WillBeHeapVector<OwnPtrWillBeMember<SampledEffect>>& effects() | 42 const HeapVector<Member<SampledEffect>>& effects() |
| 43 { | 43 { |
| 44 return element->ensureElementAnimations().defaultStack().m_effects; | 44 return element->ensureElementAnimations().defaultStack().m_effects; |
| 45 } | 45 } |
| 46 | 46 |
| 47 PassRefPtrWillBeRawPtr<EffectModel> makeEffectModel(CSSPropertyID id, PassRe
fPtrWillBeRawPtr<AnimatableValue> value) | 47 EffectModel* makeEffectModel(CSSPropertyID id, PassRefPtrWillBeRawPtr<Animat
ableValue> value) |
| 48 { | 48 { |
| 49 AnimatableValueKeyframeVector keyframes(2); | 49 AnimatableValueKeyframeVector keyframes(2); |
| 50 keyframes[0] = AnimatableValueKeyframe::create(); | 50 keyframes[0] = AnimatableValueKeyframe::create(); |
| 51 keyframes[0]->setOffset(0.0); | 51 keyframes[0]->setOffset(0.0); |
| 52 keyframes[0]->setPropertyValue(id, value.get()); | 52 keyframes[0]->setPropertyValue(id, value.get()); |
| 53 keyframes[1] = AnimatableValueKeyframe::create(); | 53 keyframes[1] = AnimatableValueKeyframe::create(); |
| 54 keyframes[1]->setOffset(1.0); | 54 keyframes[1]->setOffset(1.0); |
| 55 keyframes[1]->setPropertyValue(id, value.get()); | 55 keyframes[1]->setPropertyValue(id, value.get()); |
| 56 return AnimatableValueKeyframeEffectModel::create(keyframes); | 56 return AnimatableValueKeyframeEffectModel::create(keyframes); |
| 57 } | 57 } |
| 58 | 58 |
| 59 PassRefPtrWillBeRawPtr<InertEffect> makeInertEffect(PassRefPtrWillBeRawPtr<E
ffectModel> effect) | 59 InertEffect* makeInertEffect(EffectModel* effect) |
| 60 { | 60 { |
| 61 Timing timing; | 61 Timing timing; |
| 62 timing.fillMode = Timing::FillModeBoth; | 62 timing.fillMode = Timing::FillModeBoth; |
| 63 return InertEffect::create(effect, timing, false, 0); | 63 return InertEffect::create(effect, timing, false, 0); |
| 64 } | 64 } |
| 65 | 65 |
| 66 PassRefPtrWillBeRawPtr<KeyframeEffect> makeKeyframeEffect(PassRefPtrWillBeRa
wPtr<EffectModel> effect, double duration = 10) | 66 KeyframeEffect* makeKeyframeEffect(EffectModel* effect, double duration = 10
) |
| 67 { | 67 { |
| 68 Timing timing; | 68 Timing timing; |
| 69 timing.fillMode = Timing::FillModeBoth; | 69 timing.fillMode = Timing::FillModeBoth; |
| 70 timing.iterationDuration = duration; | 70 timing.iterationDuration = duration; |
| 71 return KeyframeEffect::create(element.get(), effect, timing); | 71 return KeyframeEffect::create(element.get(), effect, timing); |
| 72 } | 72 } |
| 73 | 73 |
| 74 AnimatableValue* interpolationValue(const ActiveInterpolationMap& activeInte
rpolations, CSSPropertyID id) | 74 AnimatableValue* interpolationValue(const ActiveInterpolationMap& activeInte
rpolations, CSSPropertyID id) |
| 75 { | 75 { |
| 76 Interpolation& interpolation = *activeInterpolations.get(PropertyHandle(
id)); | 76 Interpolation& interpolation = *activeInterpolations.get(PropertyHandle(
id)); |
| 77 return toLegacyStyleInterpolation(interpolation).currentValue().get(); | 77 return toLegacyStyleInterpolation(interpolation).currentValue().get(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 RefPtrWillBePersistent<Document> document; | 80 RefPtrWillBePersistent<Document> document; |
| 81 RefPtrWillBePersistent<AnimationTimeline> timeline; | 81 Persistent<AnimationTimeline> timeline; |
| 82 RefPtrWillBePersistent<Element> element; | 82 RefPtrWillBePersistent<Element> element; |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 TEST_F(AnimationAnimationStackTest, ElementAnimationsSorted) | 85 TEST_F(AnimationAnimationStackTest, ElementAnimationsSorted) |
| 86 { | 86 { |
| 87 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(1))).get(), 10); | 87 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(1))), 10); |
| 88 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(2))).get(), 15); | 88 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(2))), 15); |
| 89 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(3))).get(), 5); | 89 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(3))), 5); |
| 90 ActiveInterpolationMap result = AnimationStack::activeInterpolations(&elemen
t->elementAnimations()->defaultStack(), 0, 0, KeyframeEffect::DefaultPriority, 0
); | 90 ActiveInterpolationMap result = AnimationStack::activeInterpolations(&elemen
t->elementAnimations()->defaultStack(), 0, 0, KeyframeEffect::DefaultPriority, 0
); |
| 91 EXPECT_EQ(1u, result.size()); | 91 EXPECT_EQ(1u, result.size()); |
| 92 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)->equals(Animatab
leDouble::create(3).get())); | 92 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)->equals(Animatab
leDouble::create(3).get())); |
| 93 } | 93 } |
| 94 | 94 |
| 95 TEST_F(AnimationAnimationStackTest, NewAnimations) | 95 TEST_F(AnimationAnimationStackTest, NewAnimations) |
| 96 { | 96 { |
| 97 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(1))).get(), 15); | 97 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(1))), 15); |
| 98 play(makeKeyframeEffect(makeEffectModel(CSSPropertyZIndex, AnimatableDouble:
:create(2))).get(), 10); | 98 play(makeKeyframeEffect(makeEffectModel(CSSPropertyZIndex, AnimatableDouble:
:create(2))), 10); |
| 99 WillBeHeapVector<RawPtrWillBeMember<InertEffect>> newAnimations; | 99 HeapVector<Member<InertEffect>> newAnimations; |
| 100 RefPtrWillBeRawPtr<InertEffect> inert1 = makeInertEffect(makeEffectModel(CSS
PropertyFontSize, AnimatableDouble::create(3))); | 100 InertEffect* inert1 = makeInertEffect(makeEffectModel(CSSPropertyFontSize, A
nimatableDouble::create(3))); |
| 101 RefPtrWillBeRawPtr<InertEffect> inert2 = makeInertEffect(makeEffectModel(CSS
PropertyZIndex, AnimatableDouble::create(4))); | 101 InertEffect* inert2 = makeInertEffect(makeEffectModel(CSSPropertyZIndex, Ani
matableDouble::create(4))); |
| 102 newAnimations.append(inert1.get()); | 102 newAnimations.append(inert1); |
| 103 newAnimations.append(inert2.get()); | 103 newAnimations.append(inert2); |
| 104 ActiveInterpolationMap result = AnimationStack::activeInterpolations(&elemen
t->elementAnimations()->defaultStack(), &newAnimations, 0, KeyframeEffect::Defau
ltPriority, 10); | 104 ActiveInterpolationMap result = AnimationStack::activeInterpolations(&elemen
t->elementAnimations()->defaultStack(), &newAnimations, 0, KeyframeEffect::Defau
ltPriority, 10); |
| 105 EXPECT_EQ(2u, result.size()); | 105 EXPECT_EQ(2u, result.size()); |
| 106 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)->equals(Animatab
leDouble::create(3).get())); | 106 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)->equals(Animatab
leDouble::create(3).get())); |
| 107 EXPECT_TRUE(interpolationValue(result, CSSPropertyZIndex)->equals(Animatable
Double::create(4).get())); | 107 EXPECT_TRUE(interpolationValue(result, CSSPropertyZIndex)->equals(Animatable
Double::create(4).get())); |
| 108 } | 108 } |
| 109 | 109 |
| 110 TEST_F(AnimationAnimationStackTest, CancelledAnimations) | 110 TEST_F(AnimationAnimationStackTest, CancelledAnimations) |
| 111 { | 111 { |
| 112 WillBeHeapHashSet<RawPtrWillBeMember<const Animation>> cancelledAnimations; | 112 HeapHashSet<Member<const Animation>> cancelledAnimations; |
| 113 RefPtrWillBeRawPtr<Animation> animation = play(makeKeyframeEffect(makeEffect
Model(CSSPropertyFontSize, AnimatableDouble::create(1))).get(), 0); | 113 Animation* animation = play(makeKeyframeEffect(makeEffectModel(CSSPropertyFo
ntSize, AnimatableDouble::create(1))), 0); |
| 114 cancelledAnimations.add(animation.get()); | 114 cancelledAnimations.add(animation); |
| 115 play(makeKeyframeEffect(makeEffectModel(CSSPropertyZIndex, AnimatableDouble:
:create(2))).get(), 0); | 115 play(makeKeyframeEffect(makeEffectModel(CSSPropertyZIndex, AnimatableDouble:
:create(2))), 0); |
| 116 ActiveInterpolationMap result = AnimationStack::activeInterpolations(&elemen
t->elementAnimations()->defaultStack(), 0, &cancelledAnimations, KeyframeEffect:
:DefaultPriority, 0); | 116 ActiveInterpolationMap result = AnimationStack::activeInterpolations(&elemen
t->elementAnimations()->defaultStack(), 0, &cancelledAnimations, KeyframeEffect:
:DefaultPriority, 0); |
| 117 EXPECT_EQ(1u, result.size()); | 117 EXPECT_EQ(1u, result.size()); |
| 118 EXPECT_TRUE(interpolationValue(result, CSSPropertyZIndex)->equals(Animatable
Double::create(2).get())); | 118 EXPECT_TRUE(interpolationValue(result, CSSPropertyZIndex)->equals(Animatable
Double::create(2).get())); |
| 119 } | 119 } |
| 120 | 120 |
| 121 TEST_F(AnimationAnimationStackTest, ClearedEffectsRemoved) | 121 TEST_F(AnimationAnimationStackTest, ClearedEffectsRemoved) |
| 122 { | 122 { |
| 123 RefPtrWillBeRawPtr<Animation> animation = play(makeKeyframeEffect(makeEffect
Model(CSSPropertyFontSize, AnimatableDouble::create(1))).get(), 10); | 123 Animation* animation = play(makeKeyframeEffect(makeEffectModel(CSSPropertyFo
ntSize, AnimatableDouble::create(1))), 10); |
| 124 ActiveInterpolationMap result = AnimationStack::activeInterpolations(&elemen
t->elementAnimations()->defaultStack(), 0, 0, KeyframeEffect::DefaultPriority, 0
); | 124 ActiveInterpolationMap result = AnimationStack::activeInterpolations(&elemen
t->elementAnimations()->defaultStack(), 0, 0, KeyframeEffect::DefaultPriority, 0
); |
| 125 EXPECT_EQ(1u, result.size()); | 125 EXPECT_EQ(1u, result.size()); |
| 126 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)->equals(Animatab
leDouble::create(1).get())); | 126 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)->equals(Animatab
leDouble::create(1).get())); |
| 127 | 127 |
| 128 animation->setEffect(0); | 128 animation->setEffect(0); |
| 129 result = AnimationStack::activeInterpolations(&element->elementAnimations()-
>defaultStack(), 0, 0, KeyframeEffect::DefaultPriority, 0); | 129 result = AnimationStack::activeInterpolations(&element->elementAnimations()-
>defaultStack(), 0, 0, KeyframeEffect::DefaultPriority, 0); |
| 130 EXPECT_EQ(0u, result.size()); | 130 EXPECT_EQ(0u, result.size()); |
| 131 } | 131 } |
| 132 | 132 |
| 133 } | 133 } |
| OLD | NEW |