2 * Copyright (C) 2017 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "KeyframeEffectReadOnly.h"
29 #include "Animation.h"
30 #include "AnimationEffectTimingReadOnly.h"
31 #include "CSSAnimation.h"
32 #include "CSSComputedStyleDeclaration.h"
33 #include "CSSPropertyAnimation.h"
34 #include "CSSPropertyNames.h"
35 #include "CSSStyleDeclaration.h"
36 #include "CSSTimingFunctionValue.h"
37 #include "CSSTransition.h"
39 #include "FontCascade.h"
40 #include "JSCompositeOperation.h"
41 #include "JSKeyframeEffectReadOnly.h"
42 #include "RenderBoxModelObject.h"
43 #include "RenderElement.h"
44 #include "RenderStyle.h"
45 #include "StylePendingResources.h"
46 #include "StyleResolver.h"
47 #include "TimingFunction.h"
48 #include "WillChangeData.h"
54 static inline void invalidateElement(Element* element)
57 element->invalidateStyleAndLayerComposition();
60 static inline String CSSPropertyIDToIDLAttributeName(CSSPropertyID cssPropertyId)
62 // https://drafts.csswg.org/web-animations-1/#animation-property-name-to-idl-attribute-name
63 // 1. If property follows the <custom-property-name> production, return property.
64 // FIXME: We don't handle custom properties yet.
66 // 2. If property refers to the CSS float property, return the string "cssFloat".
67 if (cssPropertyId == CSSPropertyFloat)
70 // 3. If property refers to the CSS offset property, return the string "cssOffset".
71 // FIXME: we don't support the CSS "offset" property
73 // 4. Otherwise, return the result of applying the CSS property to IDL attribute algorithm [CSSOM] to property.
74 return getJSPropertyName(cssPropertyId);
77 static inline CSSPropertyID IDLAttributeNameToAnimationPropertyName(const String& idlAttributeName)
79 // https://drafts.csswg.org/web-animations-1/#idl-attribute-name-to-animation-property-name
80 // 1. If attribute conforms to the <custom-property-name> production, return attribute.
81 // FIXME: We don't handle custom properties yet.
83 // 2. If attribute is the string "cssFloat", then return an animation property representing the CSS float property.
84 if (idlAttributeName == "cssFloat")
85 return CSSPropertyFloat;
87 // 3. If attribute is the string "cssOffset", then return an animation property representing the CSS offset property.
88 // FIXME: We don't support the CSS "offset" property.
90 // 4. Otherwise, return the result of applying the IDL attribute to CSS property algorithm [CSSOM] to attribute.
91 auto cssPropertyId = CSSStyleDeclaration::getCSSPropertyIDFromJavaScriptPropertyName(idlAttributeName);
93 // We need to check that converting the property back to IDL form yields the same result such that a property passed
94 // in non-IDL form is rejected, for instance "font-size".
95 if (idlAttributeName != CSSPropertyIDToIDLAttributeName(cssPropertyId))
96 return CSSPropertyInvalid;
101 static inline void computeMissingKeyframeOffsets(Vector<KeyframeEffectReadOnly::ParsedKeyframe>& keyframes)
103 // https://drafts.csswg.org/web-animations-1/#compute-missing-keyframe-offsets
105 if (keyframes.isEmpty())
108 // 1. For each keyframe, in keyframes, let the computed keyframe offset of the keyframe be equal to its keyframe offset value.
109 // In our implementation, we only set non-null values to avoid making computedOffset std::optional<double>. Instead, we'll know
110 // that a keyframe hasn't had a computed offset by checking if it has a null offset and a 0 computedOffset, since the first
111 // keyframe will already have a 0 computedOffset.
112 for (auto& keyframe : keyframes)
113 keyframe.computedOffset = keyframe.offset.value_or(0);
115 // 2. If keyframes contains more than one keyframe and the computed keyframe offset of the first keyframe in keyframes is null,
116 // set the computed keyframe offset of the first keyframe to 0.
117 if (keyframes.size() > 1 && !keyframes[0].offset)
118 keyframes[0].computedOffset = 0;
120 // 3. If the computed keyframe offset of the last keyframe in keyframes is null, set its computed keyframe offset to 1.
121 if (!keyframes.last().offset)
122 keyframes.last().computedOffset = 1;
124 // 4. For each pair of keyframes A and B where:
125 // - A appears before B in keyframes, and
126 // - A and B have a computed keyframe offset that is not null, and
127 // - all keyframes between A and B have a null computed keyframe offset,
128 // calculate the computed keyframe offset of each keyframe between A and B as follows:
129 // 1. Let offsetk be the computed keyframe offset of a keyframe k.
130 // 2. Let n be the number of keyframes between and including A and B minus 1.
131 // 3. Let index refer to the position of keyframe in the sequence of keyframes between A and B such that the first keyframe after A has an index of 1.
132 // 4. Set the computed keyframe offset of keyframe to offsetA + (offsetB − offsetA) × index / n.
133 size_t indexOfLastKeyframeWithNonNullOffset = 0;
134 for (size_t i = 1; i < keyframes.size(); ++i) {
135 auto& keyframe = keyframes[i];
136 if (!keyframe.computedOffset)
138 if (indexOfLastKeyframeWithNonNullOffset == i - 1)
141 double lastNonNullOffset = keyframes[indexOfLastKeyframeWithNonNullOffset].computedOffset;
142 double offsetDelta = keyframe.computedOffset - lastNonNullOffset;
143 double offsetIncrement = offsetDelta / (i - indexOfLastKeyframeWithNonNullOffset);
144 size_t indexOfFirstKeyframeWithNullOffset = indexOfLastKeyframeWithNonNullOffset + 1;
145 for (size_t j = indexOfFirstKeyframeWithNullOffset; j < i; ++j)
146 keyframes[j].computedOffset = lastNonNullOffset + (j - indexOfLastKeyframeWithNonNullOffset) * offsetIncrement;
148 indexOfLastKeyframeWithNonNullOffset = i;
152 static inline ExceptionOr<void> processIterableKeyframes(ExecState& state, Strong<JSObject>&& keyframesInput, JSValue method, Vector<KeyframeEffectReadOnly::ParsedKeyframe>& parsedKeyframes)
155 auto scope = DECLARE_THROW_SCOPE(vm);
157 // 1. Let iter be GetIterator(object, method).
158 forEachInIterable(state, keyframesInput.get(), method, [&parsedKeyframes](VM& vm, ExecState& state, JSValue nextValue) -> ExceptionOr<void> {
159 if (!nextValue || !nextValue.isObject())
160 return Exception { TypeError };
162 auto scope = DECLARE_THROW_SCOPE(vm);
164 JSObject* keyframe = nextValue.toObject(&state);
165 PropertyNameArray ownPropertyNames(&vm, PropertyNameMode::Strings, PrivateSymbolMode::Exclude);
166 JSObject::getOwnPropertyNames(keyframe, &state, ownPropertyNames, EnumerationMode());
167 size_t numberOfProperties = ownPropertyNames.size();
169 KeyframeEffectReadOnly::ParsedKeyframe keyframeOutput;
171 String easing("linear");
172 std::optional<double> offset;
173 std::optional<CompositeOperation> composite;
175 for (size_t j = 0; j < numberOfProperties; ++j) {
176 auto ownPropertyName = ownPropertyNames[j];
177 if (ownPropertyName == "easing")
178 easing = convert<IDLDOMString>(state, keyframe->get(&state, ownPropertyName));
179 else if (ownPropertyName == "offset")
180 offset = convert<IDLNullable<IDLDouble>>(state, keyframe->get(&state, ownPropertyName));
181 else if (ownPropertyName == "composite")
182 composite = convert<IDLNullable<IDLEnumeration<CompositeOperation>>>(state, keyframe->get(&state, ownPropertyName));
184 auto cssPropertyId = IDLAttributeNameToAnimationPropertyName(ownPropertyName.string());
185 if (CSSPropertyAnimation::isPropertyAnimatable(cssPropertyId)) {
186 auto stringValue = convert<IDLDOMString>(state, keyframe->get(&state, ownPropertyName));
187 if (keyframeOutput.style->setProperty(cssPropertyId, stringValue))
188 keyframeOutput.unparsedStyle.set(cssPropertyId, stringValue);
191 RETURN_IF_EXCEPTION(scope, Exception { TypeError });
194 keyframeOutput.easing = easing;
195 keyframeOutput.offset = offset;
196 keyframeOutput.composite = composite;
198 parsedKeyframes.append(WTFMove(keyframeOutput));
202 RETURN_IF_EXCEPTION(scope, Exception { TypeError });
207 static inline ExceptionOr<KeyframeEffectReadOnly::KeyframeLikeObject> processKeyframeLikeObject(ExecState& state, Strong<JSObject>&& keyframesInput)
209 // https://drafts.csswg.org/web-animations-1/#process-a-keyframe-like-object
212 auto scope = DECLARE_THROW_SCOPE(vm);
214 // 1. Run the procedure to convert an ECMAScript value to a dictionary type [WEBIDL] with keyframe input as the ECMAScript value as follows:
216 // dictionary BasePropertyIndexedKeyframe {
217 // (double? or sequence<double?>) offset = [];
218 // (DOMString or sequence<DOMString>) easing = [];
219 // (CompositeOperation? or sequence<CompositeOperation?>) composite = [];
222 // Store the result of this procedure as keyframe output.
223 auto baseProperties = convert<IDLDictionary<KeyframeEffectReadOnly::BasePropertyIndexedKeyframe>>(state, keyframesInput.get());
224 RETURN_IF_EXCEPTION(scope, Exception { TypeError });
226 KeyframeEffectReadOnly::KeyframeLikeObject keyframeOuput;
227 keyframeOuput.baseProperties = baseProperties;
229 // 2. Build up a list of animatable properties as follows:
231 // 1. Let animatable properties be a list of property names (including shorthand properties that have longhand sub-properties
232 // that are animatable) that can be animated by the implementation.
233 // 2. Convert each property name in animatable properties to the equivalent IDL attribute by applying the animation property
234 // name to IDL attribute name algorithm.
236 // 3. Let input properties be the result of calling the EnumerableOwnNames operation with keyframe input as the object.
237 PropertyNameArray inputProperties(&vm, PropertyNameMode::Strings, PrivateSymbolMode::Exclude);
238 JSObject::getOwnPropertyNames(keyframesInput.get(), &state, inputProperties, EnumerationMode());
240 // 4. Make up a new list animation properties that consists of all of the properties that are in both input properties and animatable
241 // properties, or which are in input properties and conform to the <custom-property-name> production.
243 // 5. Sort animation properties in ascending order by the Unicode codepoints that define each property name.
244 // We only actually perform this after step 6.
246 // 6. For each property name in animation properties,
247 size_t numberOfProperties = inputProperties.size();
248 for (size_t i = 0; i < numberOfProperties; ++i) {
249 auto cssPropertyID = IDLAttributeNameToAnimationPropertyName(inputProperties[i].string());
250 if (!CSSPropertyAnimation::isPropertyAnimatable(cssPropertyID))
253 // 1. Let raw value be the result of calling the [[Get]] internal method on keyframe input, with property name as the property
254 // key and keyframe input as the receiver.
255 auto rawValue = keyframesInput->get(&state, inputProperties[i]);
257 // 2. Check the completion record of raw value.
258 RETURN_IF_EXCEPTION(scope, Exception { TypeError });
260 // 3. Convert raw value to a DOMString or sequence of DOMStrings property values as follows:
261 Vector<String> propertyValues;
262 // Let property values be the result of converting raw value to IDL type (DOMString or sequence<DOMString>)
263 // using the procedures defined for converting an ECMAScript value to an IDL value [WEBIDL].
264 // If property values is a single DOMString, replace property values with a sequence of DOMStrings with the original value of property
265 // Values as the only element.
266 if (rawValue.isString())
267 propertyValues = { rawValue.toWTFString(&state) };
269 propertyValues = convert<IDLSequence<IDLDOMString>>(state, rawValue);
270 RETURN_IF_EXCEPTION(scope, Exception { TypeError });
272 // 4. Calculate the normalized property name as the result of applying the IDL attribute name to animation property name algorithm to property name.
273 // 5. Add a property to to keyframe output with normalized property name as the property name, and property values as the property value.
274 keyframeOuput.propertiesAndValues.append({ cssPropertyID, propertyValues });
277 // Now we can perform step 5.
278 std::sort(keyframeOuput.propertiesAndValues.begin(), keyframeOuput.propertiesAndValues.end(), [](auto& lhs, auto& rhs) {
279 return getPropertyNameString(lhs.property).utf8() < getPropertyNameString(rhs.property).utf8();
282 // 7. Return keyframe output.
283 return { WTFMove(keyframeOuput) };
286 static inline ExceptionOr<void> processPropertyIndexedKeyframes(ExecState& state, Strong<JSObject>&& keyframesInput, Vector<KeyframeEffectReadOnly::ParsedKeyframe>& parsedKeyframes, Vector<String>& unusedEasings)
288 // 1. Let property-indexed keyframe be the result of running the procedure to process a keyframe-like object passing object as the keyframe input.
289 auto processKeyframeLikeObjectResult = processKeyframeLikeObject(state, WTFMove(keyframesInput));
290 if (processKeyframeLikeObjectResult.hasException())
291 return processKeyframeLikeObjectResult.releaseException();
292 auto propertyIndexedKeyframe = processKeyframeLikeObjectResult.returnValue();
294 // 2. For each member, m, in property-indexed keyframe, perform the following steps:
295 for (auto& m : propertyIndexedKeyframe.propertiesAndValues) {
296 // 1. Let property name be the key for m.
297 auto propertyName = m.property;
298 // 2. If property name is “composite”, or “easing”, or “offset”, skip the remaining steps in this loop and continue from the next member in property-indexed
300 // We skip this test since we split those properties and the actual CSS properties that we're currently iterating over.
301 // 3. Let property values be the value for m.
302 auto propertyValues = m.values;
303 // 4. Let property keyframes be an empty sequence of keyframes.
304 Vector<KeyframeEffectReadOnly::ParsedKeyframe> propertyKeyframes;
305 // 5. For each value, v, in property values perform the following steps:
306 for (auto& v : propertyValues) {
307 // 1. Let k be a new keyframe with a null keyframe offset.
308 KeyframeEffectReadOnly::ParsedKeyframe k;
309 // 2. Add the property-value pair, property name → v, to k.
310 if (k.style->setProperty(propertyName, v))
311 k.unparsedStyle.set(propertyName, v);
312 // 3. Append k to property keyframes.
313 propertyKeyframes.append(WTFMove(k));
315 // 6. Apply the procedure to compute missing keyframe offsets to property keyframes.
316 computeMissingKeyframeOffsets(propertyKeyframes);
318 // 7. Add keyframes in property keyframes to processed keyframes.
319 for (auto& keyframe : propertyKeyframes)
320 parsedKeyframes.append(WTFMove(keyframe));
323 // 3. Sort processed keyframes by the computed keyframe offset of each keyframe in increasing order.
324 std::sort(parsedKeyframes.begin(), parsedKeyframes.end(), [](auto& lhs, auto& rhs) {
325 return lhs.computedOffset < rhs.computedOffset;
328 // 4. Merge adjacent keyframes in processed keyframes when they have equal computed keyframe offsets.
330 while (i < parsedKeyframes.size()) {
331 auto& keyframe = parsedKeyframes[i];
332 auto& previousKeyframe = parsedKeyframes[i - 1];
333 // If the offsets of this keyframe and the previous keyframe are different,
334 // this means that the two keyframes should not be merged and we can move
335 // on to the next keyframe.
336 if (keyframe.computedOffset != previousKeyframe.computedOffset) {
340 // Otherwise, both this keyframe and the previous keyframe should be merged.
341 // Unprocessed keyframes in parsedKeyframes at this stage have at most a single
342 // property in cssPropertiesAndValues, so just set this on the previous keyframe.
343 // In case an invalid or null value was originally provided, then the property
344 // was not set and the property count is 0, in which case there is nothing to merge.
345 if (keyframe.style->propertyCount()) {
346 auto property = keyframe.style->propertyAt(0);
347 previousKeyframe.style->setProperty(property.id(), property.value());
348 previousKeyframe.unparsedStyle.set(property.id(), keyframe.unparsedStyle.get(property.id()));
350 // Since we've processed this keyframe, we can remove it and keep i the same
351 // so that we process the next keyframe in the next loop iteration.
352 parsedKeyframes.remove(i);
355 // 5. Let offsets be a sequence of nullable double values assigned based on the type of the “offset” member of the property-indexed keyframe as follows:
356 // - sequence<double?>, the value of “offset” as-is.
357 // - double?, a sequence of length one with the value of “offset” as its single item, i.e. « offset »,
358 Vector<std::optional<double>> offsets;
359 if (WTF::holds_alternative<Vector<std::optional<double>>>(propertyIndexedKeyframe.baseProperties.offset))
360 offsets = WTF::get<Vector<std::optional<double>>>(propertyIndexedKeyframe.baseProperties.offset);
361 else if (WTF::holds_alternative<double>(propertyIndexedKeyframe.baseProperties.offset))
362 offsets.append(WTF::get<double>(propertyIndexedKeyframe.baseProperties.offset));
363 else if (WTF::holds_alternative<std::nullptr_t>(propertyIndexedKeyframe.baseProperties.offset))
364 offsets.append(std::nullopt);
366 // 6. Assign each value in offsets to the keyframe offset of the keyframe with corresponding position in property keyframes until the end of either sequence is reached.
367 for (size_t i = 0; i < offsets.size() && i < parsedKeyframes.size(); ++i)
368 parsedKeyframes[i].offset = offsets[i];
370 // 7. Let easings be a sequence of DOMString values assigned based on the type of the “easing” member of the property-indexed keyframe as follows:
371 // - sequence<DOMString>, the value of “easing” as-is.
372 // - DOMString, a sequence of length one with the value of “easing” as its single item, i.e. « easing »,
373 Vector<String> easings;
374 if (WTF::holds_alternative<Vector<String>>(propertyIndexedKeyframe.baseProperties.easing))
375 easings = WTF::get<Vector<String>>(propertyIndexedKeyframe.baseProperties.easing);
376 else if (WTF::holds_alternative<String>(propertyIndexedKeyframe.baseProperties.easing))
377 easings.append(WTF::get<String>(propertyIndexedKeyframe.baseProperties.easing));
379 // 8. If easings is an empty sequence, let it be a sequence of length one containing the single value “linear”, i.e. « "linear" ».
380 if (easings.isEmpty())
381 easings.append("linear");
383 // 9. If easings has fewer items than property keyframes, repeat the elements in easings successively starting from the beginning of the list until easings has as many
384 // items as property keyframes.
385 if (easings.size() < parsedKeyframes.size()) {
386 size_t initialNumberOfEasings = easings.size();
387 for (i = initialNumberOfEasings + 1; i <= parsedKeyframes.size(); ++i)
388 easings.append(easings[i % initialNumberOfEasings]);
391 // 10. If easings has more items than property keyframes, store the excess items as unused easings.
392 while (easings.size() > parsedKeyframes.size())
393 unusedEasings.append(easings.takeLast());
395 // 11. Assign each value in easings to a property named “easing” on the keyframe with the corresponding position in property keyframes until the end of property keyframes
397 for (size_t i = 0; i < parsedKeyframes.size(); ++i)
398 parsedKeyframes[i].easing = easings[i];
400 // 12. If the “composite” member of the property-indexed keyframe is not an empty sequence:
401 Vector<std::optional<CompositeOperation>> compositeModes;
402 if (WTF::holds_alternative<Vector<std::optional<CompositeOperation>>>(propertyIndexedKeyframe.baseProperties.composite))
403 compositeModes = WTF::get<Vector<std::optional<CompositeOperation>>>(propertyIndexedKeyframe.baseProperties.composite);
404 else if (WTF::holds_alternative<CompositeOperation>(propertyIndexedKeyframe.baseProperties.composite))
405 compositeModes.append(WTF::get<CompositeOperation>(propertyIndexedKeyframe.baseProperties.composite));
406 else if (WTF::holds_alternative<std::nullptr_t>(propertyIndexedKeyframe.baseProperties.composite))
407 compositeModes.append(std::nullopt);
408 if (!compositeModes.isEmpty()) {
409 // 1. Let composite modes be a sequence of composite operations assigned from the “composite” member of property-indexed keyframe. If that member is a single composite
410 // operation, let composite modes be a sequence of length one, with the value of the “composite” as its single item.
411 // 2. As with easings, if composite modes has fewer items than property keyframes, repeat the elements in composite modes successively starting from the beginning of
412 // the list until composite modes has as many items as property keyframes.
413 if (compositeModes.size() < parsedKeyframes.size()) {
414 size_t initialNumberOfCompositeModes = compositeModes.size();
415 for (i = initialNumberOfCompositeModes + 1; i <= parsedKeyframes.size(); ++i)
416 compositeModes.append(compositeModes[i % initialNumberOfCompositeModes]);
418 // 3. Assign each value in composite modes to the keyframe-specific composite operation on the keyframe with the corresponding position in property keyframes until
419 // the end of property keyframes is reached.
420 for (size_t i = 0; i < compositeModes.size() && i < parsedKeyframes.size(); ++i)
421 parsedKeyframes[i].composite = compositeModes[i];
427 ExceptionOr<Ref<KeyframeEffectReadOnly>> KeyframeEffectReadOnly::create(ExecState& state, Element* target, Strong<JSObject>&& keyframes, std::optional<Variant<double, KeyframeEffectOptions>>&& options)
429 auto keyframeEffect = adoptRef(*new KeyframeEffectReadOnly(KeyframeEffectReadOnlyClass, AnimationEffectTimingReadOnly::create(), target));
431 auto setPropertiesResult = keyframeEffect->timing()->setProperties(WTFMove(options));
432 if (setPropertiesResult.hasException())
433 return setPropertiesResult.releaseException();
435 auto processKeyframesResult = keyframeEffect->processKeyframes(state, WTFMove(keyframes));
436 if (processKeyframesResult.hasException())
437 return processKeyframesResult.releaseException();
439 return WTFMove(keyframeEffect);
442 ExceptionOr<Ref<KeyframeEffectReadOnly>> KeyframeEffectReadOnly::create(JSC::ExecState&, Ref<KeyframeEffectReadOnly>&& source)
444 auto keyframeEffect = adoptRef(*new KeyframeEffectReadOnly(KeyframeEffectReadOnlyClass, AnimationEffectTimingReadOnly::create(), nullptr));
445 keyframeEffect->copyPropertiesFromSource(WTFMove(source));
446 return WTFMove(keyframeEffect);
449 Ref<KeyframeEffectReadOnly> KeyframeEffectReadOnly::create(const Element& target)
451 return adoptRef(*new KeyframeEffectReadOnly(KeyframeEffectReadOnlyClass, AnimationEffectTimingReadOnly::create(), const_cast<Element*>(&target)));
454 KeyframeEffectReadOnly::KeyframeEffectReadOnly(ClassType classType, Ref<AnimationEffectTimingReadOnly>&& timing, Element* target)
455 : AnimationEffectReadOnly(classType, WTFMove(timing))
457 , m_blendingKeyframes(emptyString())
461 void KeyframeEffectReadOnly::copyPropertiesFromSource(Ref<KeyframeEffectReadOnly>&& source)
463 m_target = source->m_target;
464 m_compositeOperation = source->m_compositeOperation;
465 m_iterationCompositeOperation = source->m_iterationCompositeOperation;
467 Vector<ParsedKeyframe> parsedKeyframes;
468 for (auto& sourceParsedKeyframe : source->m_parsedKeyframes) {
469 ParsedKeyframe parsedKeyframe;
470 parsedKeyframe.easing = sourceParsedKeyframe.easing;
471 parsedKeyframe.offset = sourceParsedKeyframe.offset;
472 parsedKeyframe.composite = sourceParsedKeyframe.composite;
473 parsedKeyframe.unparsedStyle = sourceParsedKeyframe.unparsedStyle;
474 parsedKeyframe.computedOffset = sourceParsedKeyframe.computedOffset;
475 parsedKeyframe.timingFunction = sourceParsedKeyframe.timingFunction;
476 parsedKeyframe.style = sourceParsedKeyframe.style->mutableCopy();
477 parsedKeyframes.append(WTFMove(parsedKeyframe));
479 m_parsedKeyframes = WTFMove(parsedKeyframes);
481 timing()->copyPropertiesFromSource(source->timing());
483 KeyframeList keyframeList("keyframe-effect-" + createCanonicalUUIDString());
484 for (auto& keyframe : source->m_blendingKeyframes.keyframes()) {
485 KeyframeValue keyframeValue(keyframe.key(), RenderStyle::clonePtr(*keyframe.style()));
486 for (auto propertyId : keyframe.properties())
487 keyframeValue.addProperty(propertyId);
488 keyframeList.insert(WTFMove(keyframeValue));
490 m_blendingKeyframes = WTFMove(keyframeList);
493 Vector<Strong<JSObject>> KeyframeEffectReadOnly::getKeyframes(ExecState& state)
495 // https://drafts.csswg.org/web-animations-1/#dom-keyframeeffectreadonly-getkeyframes
497 auto lock = JSLockHolder { &state };
499 // Since keyframes are represented by a partially open-ended dictionary type that is not currently able to be expressed with WebIDL,
500 // the procedure used to prepare the result of this method is defined in prose below:
502 // 1. Let result be an empty sequence of objects.
503 Vector<Strong<JSObject>> result;
505 // 2. Let keyframes be the result of applying the procedure to compute missing keyframe offsets to the keyframes for this keyframe effect.
507 // 3. For each keyframe in keyframes perform the following steps:
508 if (is<DeclarativeAnimation>(animation())) {
509 auto computedStyleExtractor = ComputedStyleExtractor(m_target.get());
510 for (size_t i = 0; i < m_blendingKeyframes.size(); ++i) {
511 // 1. Initialize a dictionary object, output keyframe, using the following definition:
513 // dictionary BaseComputedKeyframe {
514 // double? offset = null;
515 // double computedOffset;
516 // DOMString easing = "linear";
517 // CompositeOperation? composite = null;
520 auto& keyframe = m_blendingKeyframes[i];
522 // 2. Set offset, computedOffset, easing members of output keyframe to the respective values keyframe offset, computed keyframe offset,
523 // and keyframe-specific timing function of keyframe.
524 BaseComputedKeyframe computedKeyframe;
525 computedKeyframe.offset = keyframe.key();
526 computedKeyframe.computedOffset = keyframe.key();
527 // For CSS transitions, there are only two keyframes and the second keyframe should always report "linear". In practice, this value
528 // has no bearing since, as the last keyframe, its value will never be used.
529 computedKeyframe.easing = is<CSSTransition>(animation()) && i == 1 ? "linear" : timingFunctionForKeyframeAtIndex(0)->cssText();
531 auto outputKeyframe = convertDictionaryToJS(state, *jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject()), computedKeyframe);
533 // 3. For each animation property-value pair specified on keyframe, declaration, perform the following steps:
534 auto& style = *keyframe.style();
535 for (auto cssPropertyId : keyframe.properties()) {
536 // 1. Let property name be the result of applying the animation property name to IDL attribute name algorithm to the property name of declaration.
537 auto propertyName = CSSPropertyIDToIDLAttributeName(cssPropertyId);
538 // 2. Let IDL value be the result of serializing the property value of declaration by passing declaration to the algorithm to serialize a CSS value.
539 auto idlValue = computedStyleExtractor.valueForPropertyinStyle(style, cssPropertyId)->cssText();
540 // 3. Let value be the result of converting IDL value to an ECMAScript String value.
541 auto value = toJS<IDLDOMString>(state, idlValue);
542 // 4. Call the [[DefineOwnProperty]] internal method on output keyframe with property name property name,
543 // Property Descriptor { [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true, [[Value]]: value } and Boolean flag false.
544 JSObject::defineOwnProperty(outputKeyframe, &state, AtomicString(propertyName).impl(), PropertyDescriptor(value, 0), false);
547 // 5. Append output keyframe to result.
548 result.append(JSC::Strong<JSC::JSObject> { state.vm(), outputKeyframe });
551 for (size_t i = 0; i < m_parsedKeyframes.size(); ++i) {
552 // 1. Initialize a dictionary object, output keyframe, using the following definition:
554 // dictionary BaseComputedKeyframe {
555 // double? offset = null;
556 // double computedOffset;
557 // DOMString easing = "linear";
558 // CompositeOperation? composite = null;
561 auto& parsedKeyframe = m_parsedKeyframes[i];
563 // 2. Set offset, computedOffset, easing, composite members of output keyframe to the respective values keyframe offset, computed keyframe
564 // offset, keyframe-specific timing function and keyframe-specific composite operation of keyframe.
565 BaseComputedKeyframe computedKeyframe;
566 computedKeyframe.offset = parsedKeyframe.offset;
567 computedKeyframe.computedOffset = parsedKeyframe.computedOffset;
568 computedKeyframe.easing = timingFunctionForKeyframeAtIndex(i)->cssText();
569 computedKeyframe.composite = parsedKeyframe.composite;
571 auto outputKeyframe = convertDictionaryToJS(state, *jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject()), computedKeyframe);
573 // 3. For each animation property-value pair specified on keyframe, declaration, perform the following steps:
574 for (auto it = parsedKeyframe.unparsedStyle.begin(), end = parsedKeyframe.unparsedStyle.end(); it != end; ++it) {
575 // 1. Let property name be the result of applying the animation property name to IDL attribute name algorithm to the property name of declaration.
576 auto propertyName = CSSPropertyIDToIDLAttributeName(it->key);
577 // 2. Let IDL value be the result of serializing the property value of declaration by passing declaration to the algorithm to serialize a CSS value.
578 // 3. Let value be the result of converting IDL value to an ECMAScript String value.
579 auto value = toJS<IDLDOMString>(state, it->value);
580 // 4. Call the [[DefineOwnProperty]] internal method on output keyframe with property name property name,
581 // Property Descriptor { [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true, [[Value]]: value } and Boolean flag false.
582 JSObject::defineOwnProperty(outputKeyframe, &state, AtomicString(propertyName).impl(), PropertyDescriptor(value, 0), false);
585 // 4. Append output keyframe to result.
586 result.append(JSC::Strong<JSC::JSObject> { state.vm(), outputKeyframe });
594 ExceptionOr<void> KeyframeEffectReadOnly::processKeyframes(ExecState& state, Strong<JSObject>&& keyframesInput)
596 // 1. If object is null, return an empty sequence of keyframes.
597 if (!keyframesInput.get())
601 auto scope = DECLARE_THROW_SCOPE(vm);
603 // 2. Let processed keyframes be an empty sequence of keyframes.
604 Vector<ParsedKeyframe> parsedKeyframes;
606 // 3. Let method be the result of GetMethod(object, @@iterator).
607 auto method = keyframesInput.get()->get(&state, vm.propertyNames->iteratorSymbol);
609 // 4. Check the completion record of method.
610 RETURN_IF_EXCEPTION(scope, Exception { TypeError });
612 // 5. Perform the steps corresponding to the first matching condition from below,
613 Vector<String> unusedEasings;
614 if (!method.isUndefined())
615 processIterableKeyframes(state, WTFMove(keyframesInput), WTFMove(method), parsedKeyframes);
617 processPropertyIndexedKeyframes(state, WTFMove(keyframesInput), parsedKeyframes, unusedEasings);
619 // 6. If processed keyframes is not loosely sorted by offset, throw a TypeError and abort these steps.
620 // 7. If there exist any keyframe in processed keyframes whose keyframe offset is non-null and less than
621 // zero or greater than one, throw a TypeError and abort these steps.
622 double lastNonNullOffset = -1;
623 for (auto& keyframe : parsedKeyframes) {
624 if (!keyframe.offset)
626 auto offset = keyframe.offset.value();
627 if (offset <= lastNonNullOffset || offset < 0 || offset > 1)
628 return Exception { TypeError };
629 lastNonNullOffset = offset;
632 // We take a slight detour from the spec text and compute the missing keyframe offsets right away
633 // since they can be computed up-front.
634 computeMissingKeyframeOffsets(parsedKeyframes);
636 // 8. For each frame in processed keyframes, perform the following steps:
637 for (auto& keyframe : parsedKeyframes) {
638 // Let the timing function of frame be the result of parsing the “easing” property on frame using the CSS syntax
639 // defined for the easing property of the AnimationEffectTimingReadOnly interface.
640 // If parsing the “easing” property fails, throw a TypeError and abort this procedure.
641 auto timingFunctionResult = TimingFunction::createFromCSSText(keyframe.easing);
642 if (timingFunctionResult.hasException())
643 return timingFunctionResult.releaseException();
644 keyframe.timingFunction = timingFunctionResult.returnValue();
647 // 9. Parse each of the values in unused easings using the CSS syntax defined for easing property of the
648 // AnimationEffectTimingReadOnly interface, and if any of the values fail to parse, throw a TypeError
649 // and abort this procedure.
650 for (auto& easing : unusedEasings) {
651 auto timingFunctionResult = TimingFunction::createFromCSSText(easing);
652 if (timingFunctionResult.hasException())
653 return timingFunctionResult.releaseException();
656 m_parsedKeyframes = WTFMove(parsedKeyframes);
658 updateBlendingKeyframes();
663 void KeyframeEffectReadOnly::updateBlendingKeyframes()
668 KeyframeList keyframeList("keyframe-effect-" + createCanonicalUUIDString());
669 StyleResolver& styleResolver = m_target->styleResolver();
671 for (auto& keyframe : m_parsedKeyframes) {
672 KeyframeValue keyframeValue(keyframe.computedOffset, nullptr);
673 auto renderStyle = RenderStyle::createPtr();
674 // We need to call update() on the FontCascade or we'll hit an ASSERT when parsing font-related properties.
675 renderStyle->fontCascade().update(nullptr);
677 auto& styleProperties = keyframe.style;
678 for (unsigned i = 0; i < styleProperties->propertyCount(); ++i) {
679 auto cssPropertyId = styleProperties->propertyAt(i).id();
680 keyframeValue.addProperty(cssPropertyId);
681 keyframeList.addProperty(cssPropertyId);
682 styleResolver.applyPropertyToStyle(cssPropertyId, styleProperties->propertyAt(i).value(), WTFMove(renderStyle));
683 renderStyle = styleResolver.state().takeStyle();
686 keyframeValue.setStyle(RenderStyle::clonePtr(*renderStyle));
687 keyframeList.insert(WTFMove(keyframeValue));
690 m_blendingKeyframes = WTFMove(keyframeList);
692 computeStackingContextImpact();
695 void KeyframeEffectReadOnly::computeCSSAnimationBlendingKeyframes()
697 ASSERT(is<CSSAnimation>(animation()));
699 auto& backingAnimation = downcast<CSSAnimation>(animation())->backingAnimation();
700 if (backingAnimation.name().isEmpty())
703 auto renderStyle = RenderStyle::createPtr();
704 // We need to call update() on the FontCascade or we'll hit an ASSERT when parsing font-related properties.
705 renderStyle->fontCascade().update(nullptr);
707 KeyframeList keyframeList(backingAnimation.name());
708 if (auto* styleScope = Style::Scope::forOrdinal(*m_target, backingAnimation.nameStyleScopeOrdinal()))
709 styleScope->resolver().keyframeStylesForAnimation(*m_target, renderStyle.get(), keyframeList);
711 // Ensure resource loads for all the frames.
712 for (auto& keyframe : keyframeList.keyframes()) {
713 if (auto* style = const_cast<RenderStyle*>(keyframe.style()))
714 Style::loadPendingResources(*style, m_target->document(), m_target.get());
717 m_blendingKeyframes = WTFMove(keyframeList);
719 computeStackingContextImpact();
722 void KeyframeEffectReadOnly::computeCSSTransitionBlendingKeyframes(const RenderStyle* oldStyle, const RenderStyle& newStyle)
724 ASSERT(is<CSSTransition>(animation()));
726 if (!oldStyle || m_blendingKeyframes.size())
729 auto property = downcast<CSSTransition>(animation())->property();
731 auto toStyle = RenderStyle::clonePtr(newStyle);
733 Style::loadPendingResources(*toStyle, m_target->document(), m_target.get());
735 KeyframeList keyframeList("keyframe-effect-" + createCanonicalUUIDString());
736 keyframeList.addProperty(property);
738 KeyframeValue fromKeyframeValue(0, RenderStyle::clonePtr(*oldStyle));
739 fromKeyframeValue.addProperty(property);
740 keyframeList.insert(WTFMove(fromKeyframeValue));
742 KeyframeValue toKeyframeValue(1, WTFMove(toStyle));
743 toKeyframeValue.addProperty(property);
744 keyframeList.insert(WTFMove(toKeyframeValue));
746 m_blendingKeyframes = WTFMove(keyframeList);
748 computeStackingContextImpact();
751 bool KeyframeEffectReadOnly::stylesWouldYieldNewCSSTransitionsBlendingKeyframes(const RenderStyle& oldStyle, const RenderStyle& newStyle) const
753 ASSERT(is<CSSTransition>(animation()));
754 auto property = downcast<CSSTransition>(animation())->backingAnimation().property();
756 // There cannot be new keyframes if the start and to values are the same.
757 if (CSSPropertyAnimation::propertiesEqual(property, &oldStyle, &newStyle))
760 // Otherwise, we would create new blending keyframes provided the current end keyframe holds a different
761 // value than the new end style for this property.
762 return !CSSPropertyAnimation::propertiesEqual(property, m_blendingKeyframes[1].style(), &newStyle);
765 void KeyframeEffectReadOnly::computeStackingContextImpact()
767 m_triggersStackingContext = false;
768 for (auto cssPropertyId : m_blendingKeyframes.properties()) {
769 if (WillChangeData::propertyCreatesStackingContext(cssPropertyId)) {
770 m_triggersStackingContext = true;
776 void KeyframeEffectReadOnly::setTarget(RefPtr<Element>&& newTarget)
778 if (m_target == newTarget)
781 auto previousTarget = std::exchange(m_target, WTFMove(newTarget));
783 if (auto* effectAnimation = animation())
784 effectAnimation->effectTargetDidChange(previousTarget.get(), m_target.get());
786 updateBlendingKeyframes();
788 // We need to invalidate the effect now that the target has changed
789 // to ensure the effect's styles are applied to the new target right away.
792 // Likewise, we need to invalidate styles on the previous target so that
793 // any animated styles are removed immediately.
794 invalidateElement(previousTarget.get());
797 void KeyframeEffectReadOnly::apply(RenderStyle& targetStyle)
802 auto progress = iterationProgress();
806 if (m_startedAccelerated && progress.value() >= 1) {
807 m_startedAccelerated = false;
808 animation()->acceleratedRunningStateDidChange();
811 bool needsToStartAccelerated = false;
813 if (!m_started && !m_startedAccelerated) {
814 needsToStartAccelerated = shouldRunAccelerated();
815 m_startedAccelerated = needsToStartAccelerated;
816 if (needsToStartAccelerated)
817 animation()->acceleratedRunningStateDidChange();
821 if (!needsToStartAccelerated && !m_startedAccelerated)
822 setAnimatedPropertiesInStyle(targetStyle, progress.value());
824 // https://w3c.github.io/web-animations/#side-effects-section
825 // For every property targeted by at least one animation effect that is current or in effect, the user agent
826 // must act as if the will-change property ([css-will-change-1]) on the target element includes the property.
827 if (m_triggersStackingContext && targetStyle.hasAutoZIndex())
828 targetStyle.setZIndex(0);
831 void KeyframeEffectReadOnly::invalidate()
833 invalidateElement(m_target.get());
836 bool KeyframeEffectReadOnly::shouldRunAccelerated()
838 for (auto cssPropertyId : m_blendingKeyframes.properties()) {
839 if (!CSSPropertyAnimation::animationOfPropertyIsAccelerated(cssPropertyId))
842 return hasBlendingKeyframes();
845 void KeyframeEffectReadOnly::getAnimatedStyle(std::unique_ptr<RenderStyle>& animatedStyle)
850 if (!m_blendingKeyframes.size())
853 auto progress = iterationProgress();
858 animatedStyle = RenderStyle::clonePtr(renderer()->style());
860 setAnimatedPropertiesInStyle(*animatedStyle.get(), progress.value());
863 void KeyframeEffectReadOnly::setAnimatedPropertiesInStyle(RenderStyle& targetStyle, double iterationProgress)
865 // 4.4.3. The effect value of a keyframe effect
866 // https://drafts.csswg.org/web-animations-1/#the-effect-value-of-a-keyframe-animation-effect
868 // The effect value of a single property referenced by a keyframe effect as one of its target properties,
869 // for a given iteration progress, current iteration and underlying value is calculated as follows.
871 for (auto cssPropertyId : m_blendingKeyframes.properties()) {
872 // 1. If iteration progress is unresolved abort this procedure.
873 // 2. Let target property be the longhand property for which the effect value is to be calculated.
874 // 3. If animation type of the target property is not animatable abort this procedure since the effect cannot be applied.
875 // 4. Define the neutral value for composition as a value which, when combined with an underlying value using the add composite operation,
876 // produces the underlying value.
878 // 5. Let property-specific keyframes be the result of getting the set of computed keyframes for this keyframe effect.
879 // 6. Remove any keyframes from property-specific keyframes that do not have a property value for target property.
880 unsigned numberOfKeyframesWithZeroOffset = 0;
881 unsigned numberOfKeyframesWithOneOffset = 0;
882 Vector<std::optional<size_t>> propertySpecificKeyframes;
883 for (size_t i = 0; i < m_blendingKeyframes.size(); ++i) {
884 auto& keyframe = m_blendingKeyframes[i];
885 if (!keyframe.containsProperty(cssPropertyId))
887 auto offset = keyframe.key();
889 numberOfKeyframesWithZeroOffset++;
891 numberOfKeyframesWithOneOffset++;
892 propertySpecificKeyframes.append(i);
895 // 7. If property-specific keyframes is empty, return underlying value.
896 if (propertySpecificKeyframes.isEmpty())
899 // 8. If there is no keyframe in property-specific keyframes with a computed keyframe offset of 0, create a new keyframe with a computed keyframe
900 // offset of 0, a property value set to the neutral value for composition, and a composite operation of add, and prepend it to the beginning of
901 // property-specific keyframes.
902 if (!numberOfKeyframesWithZeroOffset) {
903 propertySpecificKeyframes.insert(0, std::nullopt);
904 numberOfKeyframesWithZeroOffset = 1;
907 // 9. Similarly, if there is no keyframe in property-specific keyframes with a computed keyframe offset of 1, create a new keyframe with a computed
908 // keyframe offset of 1, a property value set to the neutral value for composition, and a composite operation of add, and append it to the end of
909 // property-specific keyframes.
910 if (!numberOfKeyframesWithOneOffset) {
911 propertySpecificKeyframes.append(std::nullopt);
912 numberOfKeyframesWithOneOffset = 1;
915 // 10. Let interval endpoints be an empty sequence of keyframes.
916 Vector<std::optional<size_t>> intervalEndpoints;
918 // 11. Populate interval endpoints by following the steps from the first matching condition from below:
919 if (iterationProgress < 0 && numberOfKeyframesWithZeroOffset > 1) {
920 // If iteration progress < 0 and there is more than one keyframe in property-specific keyframes with a computed keyframe offset of 0,
921 // Add the first keyframe in property-specific keyframes to interval endpoints.
922 intervalEndpoints.append(propertySpecificKeyframes.first());
923 } else if (iterationProgress >= 1 && numberOfKeyframesWithOneOffset > 1) {
924 // If iteration progress ≥ 1 and there is more than one keyframe in property-specific keyframes with a computed keyframe offset of 1,
925 // Add the last keyframe in property-specific keyframes to interval endpoints.
926 intervalEndpoints.append(propertySpecificKeyframes.last());
929 // 1. Append to interval endpoints the last keyframe in property-specific keyframes whose computed keyframe offset is less than or equal
930 // to iteration progress and less than 1. If there is no such keyframe (because, for example, the iteration progress is negative),
931 // add the last keyframe whose computed keyframe offset is 0.
932 // 2. Append to interval endpoints the next keyframe in property-specific keyframes after the one added in the previous step.
933 size_t indexOfLastKeyframeWithZeroOffset = 0;
934 int indexOfFirstKeyframeToAddToIntervalEndpoints = -1;
935 for (size_t i = 0; i < propertySpecificKeyframes.size(); ++i) {
936 auto keyframeIndex = propertySpecificKeyframes[i];
937 auto offset = [&] () -> double {
940 return m_blendingKeyframes[keyframeIndex.value()].key();
943 indexOfLastKeyframeWithZeroOffset = i;
944 if (offset <= iterationProgress && offset < 1)
945 indexOfFirstKeyframeToAddToIntervalEndpoints = i;
950 if (indexOfFirstKeyframeToAddToIntervalEndpoints >= 0) {
951 intervalEndpoints.append(propertySpecificKeyframes[indexOfFirstKeyframeToAddToIntervalEndpoints]);
952 intervalEndpoints.append(propertySpecificKeyframes[indexOfFirstKeyframeToAddToIntervalEndpoints + 1]);
954 ASSERT(indexOfLastKeyframeWithZeroOffset < propertySpecificKeyframes.size() - 1);
955 intervalEndpoints.append(propertySpecificKeyframes[indexOfLastKeyframeWithZeroOffset]);
956 intervalEndpoints.append(propertySpecificKeyframes[indexOfLastKeyframeWithZeroOffset + 1]);
960 // 12. For each keyframe in interval endpoints…
961 // FIXME: we don't support this step yet since we don't deal with any composite operation other than "replace".
963 // 13. If there is only one keyframe in interval endpoints return the property value of target property on that keyframe.
964 if (intervalEndpoints.size() == 1) {
965 auto keyframeIndex = intervalEndpoints[0];
966 auto keyframeStyle = !keyframeIndex ? &targetStyle : m_blendingKeyframes[keyframeIndex.value()].style();
967 CSSPropertyAnimation::blendProperties(this, cssPropertyId, &targetStyle, keyframeStyle, keyframeStyle, 0);
971 // 14. Let start offset be the computed keyframe offset of the first keyframe in interval endpoints.
972 auto startKeyframeIndex = intervalEndpoints.first();
973 auto startOffset = !startKeyframeIndex ? 0 : m_blendingKeyframes[startKeyframeIndex.value()].key();
975 // 15. Let end offset be the computed keyframe offset of last keyframe in interval endpoints.
976 auto endKeyframeIndex = intervalEndpoints.last();
977 auto endOffset = !endKeyframeIndex ? 1 : m_blendingKeyframes[endKeyframeIndex.value()].key();
979 // 16. Let interval distance be the result of evaluating (iteration progress - start offset) / (end offset - start offset).
980 auto intervalDistance = (iterationProgress - startOffset) / (endOffset - startOffset);
982 // 17. Let transformed distance be the result of evaluating the timing function associated with the first keyframe in interval endpoints
983 // passing interval distance as the input progress.
984 auto transformedDistance = intervalDistance;
985 if (startKeyframeIndex) {
986 if (auto iterationDuration = timing()->iterationDuration()) {
987 auto rangeDuration = (endOffset - startOffset) * iterationDuration.seconds();
988 transformedDistance = timingFunctionForKeyframeAtIndex(startKeyframeIndex.value())->transformTime(intervalDistance, rangeDuration);
992 // 18. Return the result of applying the interpolation procedure defined by the animation type of the target property, to the values of the target
993 // property specified on the two keyframes in interval endpoints taking the first such value as Vstart and the second as Vend and using transformed
994 // distance as the interpolation parameter p.
995 auto startStyle = !startKeyframeIndex ? &targetStyle : m_blendingKeyframes[startKeyframeIndex.value()].style();
996 auto endStyle = !endKeyframeIndex ? &targetStyle : m_blendingKeyframes[endKeyframeIndex.value()].style();
997 CSSPropertyAnimation::blendProperties(this, cssPropertyId, &targetStyle, startStyle, endStyle, transformedDistance);
1001 TimingFunction* KeyframeEffectReadOnly::timingFunctionForKeyframeAtIndex(size_t index)
1003 if (!m_parsedKeyframes.isEmpty())
1004 return m_parsedKeyframes[index].timingFunction.get();
1006 auto effectAnimation = animation();
1008 // If we didn't have parsed keyframes, we must be dealing with a declarative animation.
1009 ASSERT(is<DeclarativeAnimation>(effectAnimation));
1011 // If we're dealing with a CSS Animation, the timing function is specified either on the keyframe itself,
1012 // or failing that on the backing Animation object which defines the default for all keyframes.
1013 if (is<CSSAnimation>(effectAnimation)) {
1014 if (auto* timingFunction = m_blendingKeyframes[index].timingFunction(downcast<CSSAnimation>(effectAnimation)->animationName()))
1015 return timingFunction;
1018 // Failing that, or for a CSS Transition, the timing function is inherited from the backing Animation object.
1019 return downcast<DeclarativeAnimation>(effectAnimation)->backingAnimation().timingFunction();
1022 void KeyframeEffectReadOnly::startOrStopAccelerated()
1024 auto* renderer = this->renderer();
1025 if (!renderer || !renderer->isComposited())
1028 auto* compositedRenderer = downcast<RenderBoxModelObject>(renderer);
1029 if (m_startedAccelerated) {
1030 auto animation = Animation::create();
1031 animation->setDuration(timing()->iterationDuration().seconds());
1032 compositedRenderer->startAnimation(0, animation.ptr(), m_blendingKeyframes);
1034 compositedRenderer->animationFinished(m_blendingKeyframes.animationName());
1035 if (!m_target->document().renderTreeBeingDestroyed())
1036 m_target->invalidateStyleAndLayerComposition();
1040 RenderElement* KeyframeEffectReadOnly::renderer() const
1042 return m_target ? m_target->renderer() : nullptr;
1045 const RenderStyle& KeyframeEffectReadOnly::currentStyle() const
1047 if (auto* renderer = this->renderer())
1048 return renderer->style();
1049 return RenderStyle::defaultStyle();
1052 } // namespace WebCore