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/ActiveAnimations.h" | 8 #include "core/animation/ActiveAnimations.h" |
9 #include "core/animation/AnimatableDouble.h" | 9 #include "core/animation/AnimatableDouble.h" |
10 #include "core/animation/AnimationClock.h" | 10 #include "core/animation/AnimationClock.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 player->update(TimingUpdateOnDemand); | 32 player->update(TimingUpdateOnDemand); |
33 return player; | 33 return player; |
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 Vector<OwnPtr<SampledEffect> >& effects() | 42 const WillBeHeapVector<OwnPtrWillBeMember<SampledEffect> >& effects() |
43 { | 43 { |
44 return element->ensureActiveAnimations().defaultStack().m_effects; | 44 return element->ensureActiveAnimations().defaultStack().m_effects; |
45 } | 45 } |
46 | 46 |
47 PassRefPtrWillBeRawPtr<AnimationEffect> makeAnimationEffect(CSSPropertyID id
, PassRefPtrWillBeRawPtr<AnimatableValue> value) | 47 PassRefPtrWillBeRawPtr<AnimationEffect> makeAnimationEffect(CSSPropertyID id
, PassRefPtrWillBeRawPtr<AnimatableValue> 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 PassRefPtr<InertAnimation> makeInertAnimation(PassRefPtrWillBeRawPtr<Animati
onEffect> effect) | 59 PassRefPtrWillBeRawPtr<InertAnimation> makeInertAnimation(PassRefPtrWillBeRa
wPtr<AnimationEffect> effect) |
60 { | 60 { |
61 Timing timing; | 61 Timing timing; |
62 timing.fillMode = Timing::FillModeBoth; | 62 timing.fillMode = Timing::FillModeBoth; |
63 return InertAnimation::create(effect, timing, false); | 63 return InertAnimation::create(effect, timing, false); |
64 } | 64 } |
65 | 65 |
66 PassRefPtr<Animation> makeAnimation(PassRefPtrWillBeRawPtr<AnimationEffect>
effect, double duration = 10) | 66 PassRefPtrWillBeRawPtr<Animation> makeAnimation(PassRefPtrWillBeRawPtr<Anima
tionEffect> 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 Animation::create(element.get(), effect, timing); | 71 return Animation::create(element.get(), effect, timing); |
72 } | 72 } |
73 | 73 |
74 AnimatableValue* interpolationValue(Interpolation* interpolation) | 74 AnimatableValue* interpolationValue(Interpolation* interpolation) |
75 { | 75 { |
76 return toLegacyStyleInterpolation(interpolation)->currentValue().get(); | 76 return toLegacyStyleInterpolation(interpolation)->currentValue().get(); |
77 } | 77 } |
78 | 78 |
79 RefPtr<Document> document; | 79 RefPtr<Document> document; |
80 RefPtr<DocumentTimeline> timeline; | 80 RefPtrWillBePersistent<DocumentTimeline> timeline; |
81 RefPtrWillBePersistent<Element> element; | 81 RefPtrWillBePersistent<Element> element; |
82 }; | 82 }; |
83 | 83 |
84 TEST_F(AnimationAnimationStackTest, ActiveAnimationsSorted) | 84 TEST_F(AnimationAnimationStackTest, ActiveAnimationsSorted) |
85 { | 85 { |
86 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble
::create(1))).get(), 10); | 86 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble
::create(1))).get(), 10); |
87 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble
::create(2))).get(), 15); | 87 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble
::create(2))).get(), 15); |
88 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble
::create(3))).get(), 5); | 88 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble
::create(3))).get(), 5); |
89 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> > result
= AnimationStack::activeInterpolations(&element->activeAnimations()->defaultStac
k(), 0, 0, Animation::DefaultPriority, 0); | 89 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> > result
= AnimationStack::activeInterpolations(&element->activeAnimations()->defaultStac
k(), 0, 0, Animation::DefaultPriority, 0); |
90 EXPECT_EQ(1u, result.size()); | 90 EXPECT_EQ(1u, result.size()); |
91 EXPECT_TRUE(interpolationValue(result.get(CSSPropertyFontSize))->equals(Anim
atableDouble::create(2).get())); | 91 EXPECT_TRUE(interpolationValue(result.get(CSSPropertyFontSize))->equals(Anim
atableDouble::create(2).get())); |
92 } | 92 } |
93 | 93 |
94 TEST_F(AnimationAnimationStackTest, NewAnimations) | 94 TEST_F(AnimationAnimationStackTest, NewAnimations) |
95 { | 95 { |
96 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble
::create(1))).get(), 15); | 96 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble
::create(1))).get(), 15); |
97 play(makeAnimation(makeAnimationEffect(CSSPropertyZIndex, AnimatableDouble::
create(2))).get(), 10); | 97 play(makeAnimation(makeAnimationEffect(CSSPropertyZIndex, AnimatableDouble::
create(2))).get(), 10); |
98 Vector<InertAnimation*> newAnimations; | 98 WillBeHeapVector<RawPtrWillBeMember<InertAnimation> > newAnimations; |
99 RefPtr<InertAnimation> inert1 = makeInertAnimation(makeAnimationEffect(CSSPr
opertyFontSize, AnimatableDouble::create(3))); | 99 RefPtrWillBeRawPtr<InertAnimation> inert1 = makeInertAnimation(makeAnimation
Effect(CSSPropertyFontSize, AnimatableDouble::create(3))); |
100 RefPtr<InertAnimation> inert2 = makeInertAnimation(makeAnimationEffect(CSSPr
opertyZIndex, AnimatableDouble::create(4))); | 100 RefPtrWillBeRawPtr<InertAnimation> inert2 = makeInertAnimation(makeAnimation
Effect(CSSPropertyZIndex, AnimatableDouble::create(4))); |
101 newAnimations.append(inert1.get()); | 101 newAnimations.append(inert1.get()); |
102 newAnimations.append(inert2.get()); | 102 newAnimations.append(inert2.get()); |
103 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> > result
= AnimationStack::activeInterpolations(&element->activeAnimations()->defaultStac
k(), &newAnimations, 0, Animation::DefaultPriority, 10); | 103 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> > result
= AnimationStack::activeInterpolations(&element->activeAnimations()->defaultStac
k(), &newAnimations, 0, Animation::DefaultPriority, 10); |
104 EXPECT_EQ(2u, result.size()); | 104 EXPECT_EQ(2u, result.size()); |
105 EXPECT_TRUE(interpolationValue(result.get(CSSPropertyFontSize))->equals(Anim
atableDouble::create(1).get())); | 105 EXPECT_TRUE(interpolationValue(result.get(CSSPropertyFontSize))->equals(Anim
atableDouble::create(1).get())); |
106 EXPECT_TRUE(interpolationValue(result.get(CSSPropertyZIndex))->equals(Animat
ableDouble::create(4).get())); | 106 EXPECT_TRUE(interpolationValue(result.get(CSSPropertyZIndex))->equals(Animat
ableDouble::create(4).get())); |
107 } | 107 } |
108 | 108 |
109 TEST_F(AnimationAnimationStackTest, CancelledAnimationPlayers) | 109 TEST_F(AnimationAnimationStackTest, CancelledAnimationPlayers) |
110 { | 110 { |
111 HashSet<const AnimationPlayer*> cancelledAnimationPlayers; | 111 WillBeHeapHashSet<RawPtrWillBeMember<const AnimationPlayer> > cancelledAnima
tionPlayers; |
112 RefPtr<AnimationPlayer> player = play(makeAnimation(makeAnimationEffect(CSSP
ropertyFontSize, AnimatableDouble::create(1))).get(), 0); | 112 RefPtrWillBeRawPtr<AnimationPlayer> player = play(makeAnimation(makeAnimatio
nEffect(CSSPropertyFontSize, AnimatableDouble::create(1))).get(), 0); |
113 cancelledAnimationPlayers.add(player.get()); | 113 cancelledAnimationPlayers.add(player.get()); |
114 play(makeAnimation(makeAnimationEffect(CSSPropertyZIndex, AnimatableDouble::
create(2))).get(), 0); | 114 play(makeAnimation(makeAnimationEffect(CSSPropertyZIndex, AnimatableDouble::
create(2))).get(), 0); |
115 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> > result
= AnimationStack::activeInterpolations(&element->activeAnimations()->defaultStac
k(), 0, &cancelledAnimationPlayers, Animation::DefaultPriority, 0); | 115 WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> > result
= AnimationStack::activeInterpolations(&element->activeAnimations()->defaultStac
k(), 0, &cancelledAnimationPlayers, Animation::DefaultPriority, 0); |
116 EXPECT_EQ(1u, result.size()); | 116 EXPECT_EQ(1u, result.size()); |
117 EXPECT_TRUE(interpolationValue(result.get(CSSPropertyZIndex))->equals(Animat
ableDouble::create(2).get())); | 117 EXPECT_TRUE(interpolationValue(result.get(CSSPropertyZIndex))->equals(Animat
ableDouble::create(2).get())); |
118 } | 118 } |
119 | 119 |
120 TEST_F(AnimationAnimationStackTest, ForwardsFillDiscarding) | 120 TEST_F(AnimationAnimationStackTest, ForwardsFillDiscarding) |
121 { | 121 { |
122 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble
::create(1))).get(), 2); | 122 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble
::create(1))).get(), 2); |
(...skipping 27 matching lines...) Expand all Loading... |
150 EXPECT_EQ(6, effects()[1]->sortInfo().startTime()); | 150 EXPECT_EQ(6, effects()[1]->sortInfo().startTime()); |
151 | 151 |
152 updateTimeline(17); | 152 updateTimeline(17); |
153 interpolations = AnimationStack::activeInterpolations(&element->activeAnimat
ions()->defaultStack(), 0, 0, Animation::DefaultPriority, 0); | 153 interpolations = AnimationStack::activeInterpolations(&element->activeAnimat
ions()->defaultStack(), 0, 0, Animation::DefaultPriority, 0); |
154 EXPECT_TRUE(interpolationValue(interpolations.get(CSSPropertyFontSize))->equ
als(AnimatableDouble::create(2).get())); | 154 EXPECT_TRUE(interpolationValue(interpolations.get(CSSPropertyFontSize))->equ
als(AnimatableDouble::create(2).get())); |
155 EXPECT_EQ(1u, effects().size()); | 155 EXPECT_EQ(1u, effects().size()); |
156 EXPECT_EQ(6, effects()[0]->sortInfo().startTime()); | 156 EXPECT_EQ(6, effects()[0]->sortInfo().startTime()); |
157 } | 157 } |
158 | 158 |
159 } | 159 } |
OLD | NEW |