OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 | 48 |
49 PassRefPtr<Animation> Animation::create(PassRefPtr<Element> target, PassRefPtrWi llBeRawPtr<AnimationEffect> effect, const Timing& timing, Priority priority, Pas sOwnPtr<EventDelegate> eventDelegate) | 49 PassRefPtr<Animation> Animation::create(PassRefPtr<Element> target, PassRefPtrWi llBeRawPtr<AnimationEffect> effect, const Timing& timing, Priority priority, Pas sOwnPtr<EventDelegate> eventDelegate) |
50 { | 50 { |
51 return adoptRef(new Animation(target, effect, timing, priority, eventDelegat e)); | 51 return adoptRef(new Animation(target, effect, timing, priority, eventDelegat e)); |
52 } | 52 } |
53 | 53 |
54 static bool checkDocumentAndRenderer(Element* element) | 54 static bool checkDocumentAndRenderer(Element* element) |
55 { | 55 { |
56 if (!element->inActiveDocument()) | 56 if (!element->inActiveDocument()) |
57 return false; | 57 return false; |
58 element->document().updateStyleIfNeeded(); | 58 element->document().updateStyleIfNeeded(); |
esprehn
2014/02/28 00:57:16
Animation::create is called from CSSAnimations::ma
alancutter (OOO until 2018)
2014/03/03 05:09:45
This particular check only occurs when an Animatio
| |
59 if (!element->renderer()) | 59 return element->renderer(); |
60 return false; | |
61 return true; | |
62 } | 60 } |
63 | 61 |
64 PassRefPtr<Animation> Animation::create(Element* element, Vector<Dictionary> key frameDictionaryVector, Dictionary timingInput) | 62 PassRefPtrWillBeRawPtr<AnimationEffect> Animation::convertEffectInput(Element* e lement, Vector<Dictionary> keyframeDictionaryVector, bool unsafe) |
65 { | 63 { |
66 ASSERT(RuntimeEnabledFeatures::webAnimationsAPIEnabled()); | |
67 | |
68 // FIXME: This test will not be neccessary once resolution of keyframe value s occurs at | 64 // FIXME: This test will not be neccessary once resolution of keyframe value s occurs at |
69 // animation application time. | 65 // animation application time. |
70 if (!checkDocumentAndRenderer(element)) | 66 if (!unsafe && !checkDocumentAndRenderer(element)) |
71 return nullptr; | 67 return nullptr; |
72 | 68 |
73 return createUnsafe(element, keyframeDictionaryVector, timingInput); | 69 // FIXME: Move this code into KeyframeEffectModel, it will be used by the ID L constructor for that class. |
74 } | |
75 | |
76 PassRefPtr<Animation> Animation::create(Element* element, Vector<Dictionary> key frameDictionaryVector, double timingInput) | |
77 { | |
78 ASSERT(RuntimeEnabledFeatures::webAnimationsAPIEnabled()); | |
79 | |
80 // FIXME: This test will not be neccessary once resolution of keyframe value s occurs at | |
81 // animation application time. | |
82 if (!checkDocumentAndRenderer(element)) | |
83 return nullptr; | |
84 | |
85 return createUnsafe(element, keyframeDictionaryVector, timingInput); | |
86 } | |
87 | |
88 PassRefPtr<Animation> Animation::create(Element* element, Vector<Dictionary> key frameDictionaryVector) | |
89 { | |
90 ASSERT(RuntimeEnabledFeatures::webAnimationsAPIEnabled()); | |
91 | |
92 // FIXME: This test will not be neccessary once resolution of keyframe value s occurs at | |
93 // animation application time. | |
94 if (!checkDocumentAndRenderer(element)) | |
95 return nullptr; | |
96 | |
97 return createUnsafe(element, keyframeDictionaryVector); | |
98 } | |
99 | |
100 void Animation::setStartDelay(Timing& timing, double startDelay) | |
101 { | |
102 if (std::isfinite(startDelay)) | |
103 timing.startDelay = startDelay; | |
104 else | |
105 timing.startDelay = 0; | |
106 } | |
107 | |
108 void Animation::setEndDelay(Timing& timing, double endDelay) | |
109 { | |
110 if (std::isfinite(endDelay)) | |
111 timing.endDelay = endDelay; | |
112 else | |
113 timing.endDelay = 0; | |
114 } | |
115 | |
116 void Animation::setFillMode(Timing& timing, String fillMode) | |
117 { | |
118 if (fillMode == "none") { | |
119 timing.fillMode = Timing::FillModeNone; | |
120 } else if (fillMode == "backwards") { | |
121 timing.fillMode = Timing::FillModeBackwards; | |
122 } else if (fillMode == "both") { | |
123 timing.fillMode = Timing::FillModeBoth; | |
124 } else if (fillMode == "forwards") { | |
125 timing.fillMode = Timing::FillModeForwards; | |
126 } else { | |
127 timing.fillMode = Timing::FillModeAuto; | |
128 } | |
129 } | |
130 | |
131 void Animation::setIterationStart(Timing& timing, double iterationStart) | |
132 { | |
133 if (!std::isnan(iterationStart) && !std::isinf(iterationStart)) | |
134 timing.iterationStart = std::max<double>(iterationStart, 0); | |
135 else | |
136 timing.iterationStart = 0; | |
137 } | |
138 | |
139 void Animation::setIterationCount(Timing& timing, double iterationCount) | |
140 { | |
141 if (!std::isnan(iterationCount)) | |
142 timing.iterationCount = std::max<double>(iterationCount, 0); | |
143 else | |
144 timing.iterationCount = 1; | |
145 } | |
146 | |
147 void Animation::setIterationDuration(Timing& timing, double iterationDuration) | |
148 { | |
149 if (!std::isnan(iterationDuration) && iterationDuration >= 0) | |
150 timing.iterationDuration = iterationDuration; | |
151 else | |
152 timing.iterationDuration = std::numeric_limits<double>::quiet_NaN(); | |
153 } | |
154 | |
155 void Animation::setPlaybackRate(Timing& timing, double playbackRate) | |
156 { | |
157 if (!std::isnan(playbackRate) && !std::isinf(playbackRate)) | |
158 timing.playbackRate = playbackRate; | |
159 else | |
160 timing.playbackRate = 1; | |
161 } | |
162 | |
163 void Animation::setPlaybackDirection(Timing& timing, String direction) | |
164 { | |
165 if (direction == "reverse") { | |
166 timing.direction = Timing::PlaybackDirectionReverse; | |
167 } else if (direction == "alternate") { | |
168 timing.direction = Timing::PlaybackDirectionAlternate; | |
169 } else if (direction == "alternate-reverse") { | |
170 timing.direction = Timing::PlaybackDirectionAlternateReverse; | |
171 } else { | |
172 timing.direction = Timing::PlaybackDirectionNormal; | |
173 } | |
174 } | |
175 | |
176 void Animation::setTimingFunction(Timing& timing, String timingFunctionString) | |
177 { | |
178 RefPtrWillBeRawPtr<CSSValue> timingFunctionValue = BisonCSSParser::parseAnim ationTimingFunctionValue(timingFunctionString); | |
179 if (timingFunctionValue) { | |
180 RefPtr<TimingFunction> timingFunction = CSSToStyleMap::animationTimingFu nction(timingFunctionValue.get(), false); | |
181 if (timingFunction) { | |
182 timing.timingFunction = timingFunction; | |
183 return; | |
184 } | |
185 } | |
186 timing.timingFunction = LinearTimingFunction::create(); | |
187 } | |
188 | |
189 void Animation::populateTiming(Timing& timing, Dictionary timingInputDictionary) | |
190 { | |
191 // FIXME: This method needs to be refactored to handle invalid | |
192 // null, NaN, Infinity values better. | |
193 // See: http://www.w3.org/TR/WebIDL/#es-double | |
194 double startDelay = 0; | |
195 timingInputDictionary.get("delay", startDelay); | |
196 setStartDelay(timing, startDelay); | |
197 | |
198 double endDelay = 0; | |
199 timingInputDictionary.get("endDelay", endDelay); | |
200 setEndDelay(timing, endDelay); | |
201 | |
202 String fillMode; | |
203 timingInputDictionary.get("fill", fillMode); | |
204 setFillMode(timing, fillMode); | |
205 | |
206 double iterationStart = 0; | |
207 timingInputDictionary.get("iterationStart", iterationStart); | |
208 setIterationStart(timing, iterationStart); | |
209 | |
210 double iterationCount = 1; | |
211 timingInputDictionary.get("iterations", iterationCount); | |
212 setIterationCount(timing, iterationCount); | |
213 | |
214 v8::Local<v8::Value> iterationDurationValue; | |
215 if (timingInputDictionary.get("duration", iterationDurationValue)) { | |
216 double iterationDuration = iterationDurationValue->NumberValue(); | |
217 setIterationDuration(timing, iterationDuration); | |
218 } | |
219 | |
220 double playbackRate = 1; | |
221 timingInputDictionary.get("playbackRate", playbackRate); | |
222 setPlaybackRate(timing, playbackRate); | |
223 | |
224 String direction; | |
225 timingInputDictionary.get("direction", direction); | |
226 setPlaybackDirection(timing, direction); | |
227 | |
228 String timingFunctionString; | |
229 timingInputDictionary.get("easing", timingFunctionString); | |
230 setTimingFunction(timing, timingFunctionString); | |
231 | |
232 timing.assertValid(); | |
233 } | |
234 | |
235 static PassRefPtrWillBeRawPtr<KeyframeEffectModel> createKeyframeEffectModel(Ele ment* element, Vector<Dictionary> keyframeDictionaryVector) | |
236 { | |
237 KeyframeEffectModel::KeyframeVector keyframes; | 70 KeyframeEffectModel::KeyframeVector keyframes; |
238 Vector<RefPtr<MutableStylePropertySet> > propertySetVector; | 71 Vector<RefPtr<MutableStylePropertySet> > propertySetVector; |
239 | 72 |
240 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) { | 73 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) { |
241 RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::c reate(); | 74 RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::c reate(); |
242 propertySetVector.append(propertySet); | 75 propertySetVector.append(propertySet); |
243 | 76 |
244 RefPtrWillBeRawPtr<Keyframe> keyframe = Keyframe::create(); | 77 RefPtrWillBeRawPtr<Keyframe> keyframe = Keyframe::create(); |
245 keyframes.append(keyframe); | 78 keyframes.append(keyframe); |
246 | 79 |
(...skipping 30 matching lines...) Expand all Loading... | |
277 if (id == CSSPropertyInvalid || !CSSAnimations::isAnimatableProperty (id)) | 110 if (id == CSSPropertyInvalid || !CSSAnimations::isAnimatableProperty (id)) |
278 continue; | 111 continue; |
279 | 112 |
280 String value; | 113 String value; |
281 keyframeDictionaryVector[i].get(property, value); | 114 keyframeDictionaryVector[i].get(property, value); |
282 propertySet->setProperty(id, value); | 115 propertySet->setProperty(id, value); |
283 } | 116 } |
284 } | 117 } |
285 | 118 |
286 // FIXME: Replace this with code that just parses, when that code is availab le. | 119 // FIXME: Replace this with code that just parses, when that code is availab le. |
287 RefPtrWillBeRawPtr<KeyframeEffectModel> effect = StyleResolver::createKeyfra meEffectModel(*element, propertySetVector, keyframes); | 120 return StyleResolver::createKeyframeEffectModel(*element, propertySetVector, keyframes); |
288 return effect; | |
289 } | |
290 | |
291 PassRefPtr<Animation> Animation::createUnsafe(Element* element, Vector<Dictionar y> keyframeDictionaryVector, Dictionary timingInput) | |
292 { | |
293 RefPtrWillBeRawPtr<KeyframeEffectModel> effect = createKeyframeEffectModel(e lement, keyframeDictionaryVector); | |
294 | |
295 Timing timing; | |
296 populateTiming(timing, timingInput); | |
297 | |
298 return create(element, effect, timing); | |
299 } | |
300 | |
301 PassRefPtr<Animation> Animation::createUnsafe(Element* element, Vector<Dictionar y> keyframeDictionaryVector, double timingInput) | |
302 { | |
303 RefPtrWillBeRawPtr<KeyframeEffectModel> effect = createKeyframeEffectModel(e lement, keyframeDictionaryVector); | |
304 | |
305 Timing timing; | |
306 if (!std::isnan(timingInput)) | |
307 timing.iterationDuration = std::max<double>(timingInput, 0); | |
308 | |
309 return create(element, effect, timing); | |
310 } | |
311 | |
312 PassRefPtr<Animation> Animation::createUnsafe(Element* element, Vector<Dictionar y> keyframeDictionaryVector) | |
313 { | |
314 RefPtrWillBeRawPtr<KeyframeEffectModel> effect = createKeyframeEffectModel(e lement, keyframeDictionaryVector); | |
315 Timing timing; | |
316 | |
317 return create(element, effect, timing); | |
318 } | 121 } |
319 | 122 |
320 Animation::Animation(PassRefPtr<Element> target, PassRefPtrWillBeRawPtr<Animatio nEffect> effect, const Timing& timing, Priority priority, PassOwnPtr<EventDelega te> eventDelegate) | 123 Animation::Animation(PassRefPtr<Element> target, PassRefPtrWillBeRawPtr<Animatio nEffect> effect, const Timing& timing, Priority priority, PassOwnPtr<EventDelega te> eventDelegate) |
321 : TimedItem(timing, eventDelegate) | 124 : TimedItem(timing, eventDelegate) |
322 , m_target(target) | 125 , m_target(target) |
323 , m_effect(effect) | 126 , m_effect(effect) |
324 , m_activeInAnimationStack(false) | 127 , m_activeInAnimationStack(false) |
325 , m_priority(priority) | 128 , m_priority(priority) |
326 { | 129 { |
327 } | 130 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
478 void Animation::pauseAnimationForTestingOnCompositor(double pauseTime) | 281 void Animation::pauseAnimationForTestingOnCompositor(double pauseTime) |
479 { | 282 { |
480 ASSERT(hasActiveAnimationsOnCompositor()); | 283 ASSERT(hasActiveAnimationsOnCompositor()); |
481 if (!m_target || !m_target->renderer()) | 284 if (!m_target || !m_target->renderer()) |
482 return; | 285 return; |
483 for (size_t i = 0; i < m_compositorAnimationIds.size(); ++i) | 286 for (size_t i = 0; i < m_compositorAnimationIds.size(); ++i) |
484 CompositorAnimations::instance()->pauseAnimationForTestingOnCompositor(* m_target.get(), m_compositorAnimationIds[i], pauseTime); | 287 CompositorAnimations::instance()->pauseAnimationForTestingOnCompositor(* m_target.get(), m_compositorAnimationIds[i], pauseTime); |
485 } | 288 } |
486 | 289 |
487 } // namespace WebCore | 290 } // namespace WebCore |
OLD | NEW |