fcba25cbec5f01e5d7c4c0bdcd527de92a6469ad
[WebKit-https.git] / Source / WebCore / animation / AnimationTimeline.cpp
1 /*
2  * Copyright (C) Canon Inc. 2016
3  * Copyright (C) 2017 Apple Inc. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #include "config.h"
28 #include "AnimationTimeline.h"
29
30 #include "Animation.h"
31 #include "AnimationEffect.h"
32 #include "AnimationList.h"
33 #include "CSSAnimation.h"
34 #include "CSSPropertyAnimation.h"
35 #include "CSSTransition.h"
36 #include "DocumentTimeline.h"
37 #include "Element.h"
38 #include "KeyframeEffect.h"
39 #include "RenderStyle.h"
40 #include "RenderView.h"
41 #include "StylePropertyShorthand.h"
42 #include "StyleResolver.h"
43 #include "WebAnimationUtilities.h"
44 #include <wtf/text/TextStream.h>
45 #include <wtf/text/WTFString.h>
46
47 namespace WebCore {
48
49 AnimationTimeline::AnimationTimeline(ClassType classType)
50     : m_classType(classType)
51 {
52 }
53
54 AnimationTimeline::~AnimationTimeline()
55 {
56 }
57
58 void AnimationTimeline::forgetAnimation(WebAnimation* animation)
59 {
60     m_allAnimations.remove(animation);
61 }
62
63 void AnimationTimeline::animationTimingDidChange(WebAnimation& animation)
64 {
65     if (m_animations.add(&animation)) {
66         m_allAnimations.add(&animation);
67         auto* timeline = animation.timeline();
68         if (timeline && timeline != this)
69             timeline->removeAnimation(animation);
70     }
71 }
72
73 void AnimationTimeline::removeAnimation(WebAnimation& animation)
74 {
75     ASSERT(!animation.timeline() || animation.timeline() == this);
76     m_animations.remove(&animation);
77     if (is<KeyframeEffect>(animation.effect())) {
78         if (auto* target = downcast<KeyframeEffect>(animation.effect())->target())
79             animationWasRemovedFromElement(animation, *target);
80     }
81 }
82
83 Optional<double> AnimationTimeline::bindingsCurrentTime()
84 {
85     auto time = currentTime();
86     if (!time)
87         return WTF::nullopt;
88     return secondsToWebAnimationsAPITime(*time);
89 }
90
91 void AnimationTimeline::animationWasAddedToElement(WebAnimation& animation, Element& element)
92 {
93     [&] () -> ElementToAnimationsMap& {
94         if (is<CSSTransition>(animation) && downcast<CSSTransition>(animation).owningElement())
95             return m_elementToCSSTransitionsMap;
96         if (is<CSSAnimation>(animation) && downcast<CSSAnimation>(animation).owningElement())
97             return m_elementToCSSAnimationsMap;
98         return m_elementToAnimationsMap;
99     }().ensure(&element, [] {
100         return ListHashSet<RefPtr<WebAnimation>> { };
101     }).iterator->value.add(&animation);
102 }
103
104 static inline bool removeCSSTransitionFromMap(CSSTransition& transition, Element& element, HashMap<Element*, AnimationTimeline::PropertyToTransitionMap>& map)
105 {
106     auto iterator = map.find(&element);
107     if (iterator == map.end())
108         return false;
109
110     auto& cssTransitionsByProperty = iterator->value;
111
112     auto transitionIterator = cssTransitionsByProperty.find(transition.property());
113     if (transitionIterator == cssTransitionsByProperty.end() || transitionIterator->value != &transition)
114         return false;
115
116     cssTransitionsByProperty.remove(transitionIterator);
117
118     if (cssTransitionsByProperty.isEmpty())
119         map.remove(&element);
120     return true;
121 }
122
123 static inline void removeAnimationFromMapForElement(WebAnimation& animation, AnimationTimeline::ElementToAnimationsMap& map, Element& element)
124 {
125     auto iterator = map.find(&element);
126     if (iterator == map.end())
127         return;
128
129     auto& animations = iterator->value;
130     animations.remove(&animation);
131     if (!animations.size())
132         map.remove(iterator);
133 }
134
135 void AnimationTimeline::animationWasRemovedFromElement(WebAnimation& animation, Element& element)
136 {
137     removeAnimationFromMapForElement(animation, m_elementToCSSTransitionsMap, element);
138     removeAnimationFromMapForElement(animation, m_elementToCSSAnimationsMap, element);
139     removeAnimationFromMapForElement(animation, m_elementToAnimationsMap, element);
140
141     // Now, if we're dealing with a declarative animation, we remove it from either the m_elementToCSSAnimationByName
142     // or the m_elementToRunningCSSTransitionByCSSPropertyID map, whichever is relevant to this type of animation.
143     if (is<DeclarativeAnimation>(animation))
144         removeDeclarativeAnimationFromListsForOwningElement(animation, element);
145 }
146
147 void AnimationTimeline::removeDeclarativeAnimationFromListsForOwningElement(WebAnimation& animation, Element& element)
148 {
149     ASSERT(is<DeclarativeAnimation>(animation));
150
151     if (is<CSSAnimation>(animation)) {
152         auto iterator = m_elementToCSSAnimationByName.find(&element);
153         if (iterator != m_elementToCSSAnimationByName.end()) {
154             auto& cssAnimationsByName = iterator->value;
155             auto& name = downcast<CSSAnimation>(animation).animationName();
156             cssAnimationsByName.remove(name);
157             if (cssAnimationsByName.isEmpty())
158                 m_elementToCSSAnimationByName.remove(&element);
159         }
160     } else if (is<CSSTransition>(animation)) {
161         auto& transition = downcast<CSSTransition>(animation);
162         if (!removeCSSTransitionFromMap(transition, element, m_elementToRunningCSSTransitionByCSSPropertyID))
163             removeCSSTransitionFromMap(transition, element, m_elementToCompletedCSSTransitionByCSSPropertyID);
164     }
165 }
166
167 Vector<RefPtr<WebAnimation>> AnimationTimeline::animationsForElement(Element& element, Ordering ordering) const
168 {
169     Vector<RefPtr<WebAnimation>> animations;
170     if (m_elementToCSSTransitionsMap.contains(&element)) {
171         const auto& cssTransitions = m_elementToCSSTransitionsMap.get(&element);
172         if (ordering == Ordering::Sorted) {
173             Vector<RefPtr<WebAnimation>> sortedCSSTransitions;
174             sortedCSSTransitions.appendRange(cssTransitions.begin(), cssTransitions.end());
175             std::sort(sortedCSSTransitions.begin(), sortedCSSTransitions.end(), [](auto& lhs, auto& rhs) {
176                 // Sort transitions first by their generation time, and then by transition-property.
177                 // https://drafts.csswg.org/css-transitions-2/#animation-composite-order
178                 auto* lhsTransition = downcast<CSSTransition>(lhs.get());
179                 auto* rhsTransition = downcast<CSSTransition>(rhs.get());
180                 if (lhsTransition->generationTime() != rhsTransition->generationTime())
181                     return lhsTransition->generationTime() < rhsTransition->generationTime();
182                 return lhsTransition->transitionProperty().utf8() < rhsTransition->transitionProperty().utf8();
183             });
184             animations.appendVector(sortedCSSTransitions);
185         } else
186             animations.appendRange(cssTransitions.begin(), cssTransitions.end());
187     }
188     if (m_elementToCSSAnimationsMap.contains(&element)) {
189         const auto& cssAnimations = m_elementToCSSAnimationsMap.get(&element);
190         animations.appendRange(cssAnimations.begin(), cssAnimations.end());
191     }
192     if (m_elementToAnimationsMap.contains(&element)) {
193         const auto& webAnimations = m_elementToAnimationsMap.get(&element);
194         animations.appendRange(webAnimations.begin(), webAnimations.end());
195     }
196     return animations;
197 }
198
199 void AnimationTimeline::elementWasRemoved(Element& element)
200 {
201     for (auto& animation : animationsForElement(element))
202         animation->cancel(WebAnimation::Silently::Yes);
203 }
204
205 void AnimationTimeline::removeAnimationsForElement(Element& element)
206 {
207     for (auto& animation : animationsForElement(element))
208         animation->remove();
209 }
210
211 void AnimationTimeline::cancelDeclarativeAnimationsForElement(Element& element)
212 {
213     for (auto& cssTransition : m_elementToCSSTransitionsMap.get(&element))
214         cssTransition->cancel();
215     for (auto& cssAnimation : m_elementToCSSAnimationsMap.get(&element))
216         cssAnimation->cancel();
217 }
218
219 static bool shouldConsiderAnimation(Element& element, const Animation& animation)
220 {
221     if (!animation.isValidAnimation())
222         return false;
223
224     static NeverDestroyed<const String> animationNameNone(MAKE_STATIC_STRING_IMPL("none"));
225
226     auto& name = animation.name();
227     if (name == animationNameNone || name.isEmpty())
228         return false;
229
230     if (auto* styleScope = Style::Scope::forOrdinal(element, animation.nameStyleScopeOrdinal()))
231         return styleScope->resolver().isAnimationNameValid(name);
232
233     return false;
234 }
235
236 void AnimationTimeline::updateCSSAnimationsForElement(Element& element, const RenderStyle* currentStyle, const RenderStyle& afterChangeStyle)
237 {
238     // In case this element is newly getting a "display: none" we need to cancel all of its animations and disregard new ones.
239     if (currentStyle && currentStyle->hasAnimations() && currentStyle->display() != DisplayType::None && afterChangeStyle.display() == DisplayType::None) {
240         if (m_elementToCSSAnimationByName.contains(&element)) {
241             for (const auto& cssAnimationsByNameMapItem : m_elementToCSSAnimationByName.take(&element))
242                 cancelDeclarativeAnimation(*cssAnimationsByNameMapItem.value);
243         }
244         return;
245     }
246
247     if (currentStyle && currentStyle->hasAnimations() && afterChangeStyle.hasAnimations() && *(currentStyle->animations()) == *(afterChangeStyle.animations()))
248         return;
249
250     // First, compile the list of animation names that were applied to this element up to this point.
251     HashSet<String> namesOfPreviousAnimations;
252     if (currentStyle && currentStyle->hasAnimations()) {
253         auto* previousAnimations = currentStyle->animations();
254         for (size_t i = 0; i < previousAnimations->size(); ++i) {
255             auto& previousAnimation = previousAnimations->animation(i);
256             if (shouldConsiderAnimation(element, previousAnimation))
257                 namesOfPreviousAnimations.add(previousAnimation.name());
258         }
259     }
260
261     // Create or get the CSSAnimations by animation name map for this element.
262     auto& cssAnimationsByName = m_elementToCSSAnimationByName.ensure(&element, [] {
263         return HashMap<String, RefPtr<CSSAnimation>> { };
264     }).iterator->value;
265
266     if (auto* currentAnimations = afterChangeStyle.animations()) {
267         for (size_t i = 0; i < currentAnimations->size(); ++i) {
268             auto& currentAnimation = currentAnimations->animation(i);
269             auto& name = currentAnimation.name();
270             if (namesOfPreviousAnimations.contains(name)) {
271                 // We've found the name of this animation in our list of previous animations, this means we've already
272                 // created a CSSAnimation object for it and need to ensure that this CSSAnimation is backed by the current
273                 // animation object for this animation name.
274                 if (auto cssAnimation = cssAnimationsByName.get(name))
275                     cssAnimation->setBackingAnimation(currentAnimation);
276             } else if (shouldConsiderAnimation(element, currentAnimation)) {
277                 // Otherwise we are dealing with a new animation name and must create a CSSAnimation for it.
278                 cssAnimationsByName.set(name, CSSAnimation::create(element, currentAnimation, currentStyle, afterChangeStyle));
279             }
280             // Remove the name of this animation from our list since it's now known to be current.
281             namesOfPreviousAnimations.remove(name);
282         }
283     }
284
285     // The animations names left in namesOfPreviousAnimations are now known to no longer apply so we need to
286     // remove the CSSAnimation object created for them.
287     for (const auto& nameOfAnimationToRemove : namesOfPreviousAnimations) {
288         if (auto animation = cssAnimationsByName.take(nameOfAnimationToRemove))
289             cancelDeclarativeAnimation(*animation);
290     }
291 }
292
293 RefPtr<WebAnimation> AnimationTimeline::cssAnimationForElementAndProperty(Element& element, CSSPropertyID property)
294 {
295     RefPtr<WebAnimation> matchingAnimation;
296     for (const auto& animation : m_elementToCSSAnimationsMap.get(&element)) {
297         auto* effect = animation->effect();
298         if (is<KeyframeEffect>(effect) && downcast<KeyframeEffect>(effect)->animatedProperties().contains(property))
299             matchingAnimation = animation;
300     }
301     return matchingAnimation;
302 }
303
304 static bool propertyInStyleMatchesValueForTransitionInMap(CSSPropertyID property, const RenderStyle& style, AnimationTimeline::PropertyToTransitionMap& transitions)
305 {
306     if (auto* transition = transitions.get(property)) {
307         if (CSSPropertyAnimation::propertiesEqual(property, &style, &transition->targetStyle()))
308             return true;
309     }
310     return false;
311 }
312
313 static double transitionCombinedDuration(const Animation* transition)
314 {
315     return std::max(0.0, transition->duration()) + transition->delay();
316 }
317
318 static bool transitionMatchesProperty(const Animation& transition, CSSPropertyID property)
319 {
320     auto mode = transition.animationMode();
321     if (mode == Animation::AnimateNone || mode == Animation::AnimateUnknownProperty)
322         return false;
323     if (mode == Animation::AnimateSingleProperty) {
324         auto transitionProperty = transition.property();
325         if (transitionProperty != property) {
326             auto shorthand = shorthandForProperty(transitionProperty);
327             for (size_t i = 0; i < shorthand.length(); ++i) {
328                 if (shorthand.properties()[i] == property)
329                     return true;
330             }
331             return false;
332         }
333     }
334     return true;
335 }
336
337 AnimationTimeline::PropertyToTransitionMap& AnimationTimeline::ensureRunningTransitionsByProperty(Element& element)
338 {
339     return m_elementToRunningCSSTransitionByCSSPropertyID.ensure(&element, [] {
340         return PropertyToTransitionMap { };
341     }).iterator->value;
342 }
343
344 void AnimationTimeline::updateCSSTransitionsForElement(Element& element, const RenderStyle& currentStyle, const RenderStyle& afterChangeStyle)
345 {
346     // In case this element is newly getting a "display: none" we need to cancel all of its transitions and disregard new ones.
347     if (currentStyle.hasTransitions() && currentStyle.display() != DisplayType::None && afterChangeStyle.display() == DisplayType::None) {
348         if (m_elementToRunningCSSTransitionByCSSPropertyID.contains(&element)) {
349             for (const auto& cssTransitionsByCSSPropertyIDMapItem : m_elementToRunningCSSTransitionByCSSPropertyID.take(&element))
350                 cancelDeclarativeAnimation(*cssTransitionsByCSSPropertyIDMapItem.value);
351         }
352         return;
353     }
354
355     // Section 3 "Starting of transitions" from the CSS Transitions Level 1 specification.
356     // https://drafts.csswg.org/css-transitions-1/#starting
357
358     auto& runningTransitionsByProperty = ensureRunningTransitionsByProperty(element);
359
360     auto& completedTransitionsByProperty = m_elementToCompletedCSSTransitionByCSSPropertyID.ensure(&element, [] {
361         return PropertyToTransitionMap { };
362     }).iterator->value;
363
364     auto generationTime = MonotonicTime::now();
365
366     auto numberOfProperties = CSSPropertyAnimation::getNumProperties();
367     for (int propertyIndex = 0; propertyIndex < numberOfProperties; ++propertyIndex) {
368         Optional<bool> isShorthand;
369         auto property = CSSPropertyAnimation::getPropertyAtIndex(propertyIndex, isShorthand);
370         if (isShorthand && *isShorthand)
371             continue;
372
373         const Animation* matchingBackingAnimation = nullptr;
374         if (auto* transitions = afterChangeStyle.transitions()) {
375             for (size_t i = 0; i < transitions->size(); ++i) {
376                 auto& backingAnimation = transitions->animation(i);
377                 if (transitionMatchesProperty(backingAnimation, property))
378                     matchingBackingAnimation = &backingAnimation;
379             }
380         }
381
382         // https://drafts.csswg.org/css-transitions-1/#before-change-style
383         // Define the before-change style as the computed values of all properties on the element as of the previous style change event, except with
384         // any styles derived from declarative animations such as CSS Transitions, CSS Animations, and SMIL Animations updated to the current time.
385         auto existingAnimation = cssAnimationForElementAndProperty(element, property);
386         const auto& beforeChangeStyle = existingAnimation ? downcast<CSSAnimation>(existingAnimation.get())->unanimatedStyle() : currentStyle;
387
388         if (!runningTransitionsByProperty.contains(property)
389             && !CSSPropertyAnimation::propertiesEqual(property, &beforeChangeStyle, &afterChangeStyle)
390             && CSSPropertyAnimation::canPropertyBeInterpolated(property, &beforeChangeStyle, &afterChangeStyle)
391             && !propertyInStyleMatchesValueForTransitionInMap(property, afterChangeStyle, completedTransitionsByProperty)
392             && matchingBackingAnimation && transitionCombinedDuration(matchingBackingAnimation) > 0) {
393             // 1. If all of the following are true:
394             //   - the element does not have a running transition for the property,
395             //   - the before-change style is different from and can be interpolated with the after-change style for that property,
396             //   - the element does not have a completed transition for the property or the end value of the completed transition is different from the after-change style for the property,
397             //   - there is a matching transition-property value, and
398             //   - the combined duration is greater than 0s,
399
400             // then implementations must remove the completed transition (if present) from the set of completed transitions
401             completedTransitionsByProperty.remove(property);
402
403             // and start a transition whose:
404             //   - start time is the time of the style change event plus the matching transition delay,
405             //   - end time is the start time plus the matching transition duration,
406             //   - start value is the value of the transitioning property in the before-change style,
407             //   - end value is the value of the transitioning property in the after-change style,
408             //   - reversing-adjusted start value is the same as the start value, and
409             //   - reversing shortening factor is 1.
410             auto delay = Seconds(matchingBackingAnimation->delay());
411             auto duration = Seconds(matchingBackingAnimation->duration());
412             auto& reversingAdjustedStartStyle = beforeChangeStyle;
413             auto reversingShorteningFactor = 1;
414             runningTransitionsByProperty.set(property, CSSTransition::create(element, property, generationTime, *matchingBackingAnimation, &beforeChangeStyle, afterChangeStyle, delay, duration, reversingAdjustedStartStyle, reversingShorteningFactor));
415         } else if (completedTransitionsByProperty.contains(property) && !propertyInStyleMatchesValueForTransitionInMap(property, afterChangeStyle, completedTransitionsByProperty)) {
416             // 2. Otherwise, if the element has a completed transition for the property and the end value of the completed transition is different from
417             //    the after-change style for the property, then implementations must remove the completed transition from the set of completed transitions.
418             completedTransitionsByProperty.remove(property);
419         }
420
421         bool hasRunningTransition = runningTransitionsByProperty.contains(property);
422         if ((hasRunningTransition || completedTransitionsByProperty.contains(property)) && !matchingBackingAnimation) {
423             // 3. If the element has a running transition or completed transition for the property, and there is not a matching transition-property
424             //    value, then implementations must cancel the running transition or remove the completed transition from the set of completed transitions.
425             if (hasRunningTransition)
426                 runningTransitionsByProperty.take(property)->cancel();
427             else
428                 completedTransitionsByProperty.remove(property);
429         }
430
431         if (matchingBackingAnimation && runningTransitionsByProperty.contains(property) && !propertyInStyleMatchesValueForTransitionInMap(property, afterChangeStyle, runningTransitionsByProperty)) {
432             auto previouslyRunningTransition = runningTransitionsByProperty.take(property);
433             auto& previouslyRunningTransitionCurrentStyle = previouslyRunningTransition->currentStyle();
434             // 4. If the element has a running transition for the property, there is a matching transition-property value, and the end value of the running
435             //    transition is not equal to the value of the property in the after-change style, then:
436             if (CSSPropertyAnimation::propertiesEqual(property, &previouslyRunningTransitionCurrentStyle, &afterChangeStyle) || !CSSPropertyAnimation::canPropertyBeInterpolated(property, &currentStyle, &afterChangeStyle)) {
437                 // 1. If the current value of the property in the running transition is equal to the value of the property in the after-change style,
438                 //    or if these two values cannot be interpolated, then implementations must cancel the running transition.
439                 cancelDeclarativeAnimation(*previouslyRunningTransition);
440             } else if (transitionCombinedDuration(matchingBackingAnimation) <= 0.0 || !CSSPropertyAnimation::canPropertyBeInterpolated(property, &previouslyRunningTransitionCurrentStyle, &afterChangeStyle)) {
441                 // 2. Otherwise, if the combined duration is less than or equal to 0s, or if the current value of the property in the running transition
442                 //    cannot be interpolated with the value of the property in the after-change style, then implementations must cancel the running transition.
443                 cancelDeclarativeAnimation(*previouslyRunningTransition);
444             } else if (CSSPropertyAnimation::propertiesEqual(property, &previouslyRunningTransition->reversingAdjustedStartStyle(), &afterChangeStyle)) {
445                 // 3. Otherwise, if the reversing-adjusted start value of the running transition is the same as the value of the property in the after-change
446                 //    style (see the section on reversing of transitions for why these case exists), implementations must cancel the running transition
447                 cancelDeclarativeAnimation(*previouslyRunningTransition);
448
449                 // and start a new transition whose:
450                 //   - reversing-adjusted start value is the end value of the running transition,
451                 //   - reversing shortening factor is the absolute value, clamped to the range [0, 1], of the sum of:
452                 //       1. the output of the timing function of the old transition at the time of the style change event, times the reversing shortening factor of the old transition
453                 //       2. 1 minus the reversing shortening factor of the old transition.
454                 //   - start time is the time of the style change event plus:
455                 //       1. if the matching transition delay is nonnegative, the matching transition delay, or
456                 //       2. if the matching transition delay is negative, the product of the new transition’s reversing shortening factor and the matching transition delay,
457                 //   - end time is the start time plus the product of the matching transition duration and the new transition’s reversing shortening factor,
458                 //   - start value is the current value of the property in the running transition,
459                 //   - end value is the value of the property in the after-change style
460                 auto& reversingAdjustedStartStyle = previouslyRunningTransition->targetStyle();
461                 double transformedProgress = 1;
462                 if (auto* effect = previouslyRunningTransition->effect())
463                     transformedProgress = effect->iterationProgress().value_or(transformedProgress);
464                 auto reversingShorteningFactor = std::max(std::min(((transformedProgress * previouslyRunningTransition->reversingShorteningFactor()) + (1 - previouslyRunningTransition->reversingShorteningFactor())), 1.0), 0.0);
465                 auto delay = matchingBackingAnimation->delay() < 0 ? Seconds(matchingBackingAnimation->delay()) * reversingShorteningFactor : Seconds(matchingBackingAnimation->delay());
466                 auto duration = Seconds(matchingBackingAnimation->duration()) * reversingShorteningFactor;
467
468                 ensureRunningTransitionsByProperty(element).set(property, CSSTransition::create(element, property, generationTime, *matchingBackingAnimation, &previouslyRunningTransitionCurrentStyle, afterChangeStyle, delay, duration, reversingAdjustedStartStyle, reversingShorteningFactor));
469             } else {
470                 // 4. Otherwise, implementations must cancel the running transition
471                 cancelDeclarativeAnimation(*previouslyRunningTransition);
472
473                 // and start a new transition whose:
474                 //   - start time is the time of the style change event plus the matching transition delay,
475                 //   - end time is the start time plus the matching transition duration,
476                 //   - start value is the current value of the property in the running transition,
477                 //   - end value is the value of the property in the after-change style,
478                 //   - reversing-adjusted start value is the same as the start value, and
479                 //   - reversing shortening factor is 1.
480                 auto delay = Seconds(matchingBackingAnimation->delay());
481                 auto duration = Seconds(matchingBackingAnimation->duration());
482                 auto& reversingAdjustedStartStyle = currentStyle;
483                 auto reversingShorteningFactor = 1;
484                 ensureRunningTransitionsByProperty(element).set(property, CSSTransition::create(element, property, generationTime, *matchingBackingAnimation, &previouslyRunningTransitionCurrentStyle, afterChangeStyle, delay, duration, reversingAdjustedStartStyle, reversingShorteningFactor));
485             }
486         }
487     }
488 }
489
490 void AnimationTimeline::cancelDeclarativeAnimation(DeclarativeAnimation& animation)
491 {
492     animation.cancelFromStyle();
493     removeAnimation(animation);
494     m_allAnimations.remove(&animation);
495 }
496
497 } // namespace WebCore