/
KeyframeEffect.cpp
2487 lines (2103 loc) · 111 KB
/
KeyframeEffect.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2017-2019 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "KeyframeEffect.h"
#include "Animation.h"
#include "CSSAnimation.h"
#include "CSSKeyframeRule.h"
#include "CSSPropertyAnimation.h"
#include "CSSPropertyNames.h"
#include "CSSPropertyParser.h"
#include "CSSSelector.h"
#include "CSSStyleDeclaration.h"
#include "CSSTimingFunctionValue.h"
#include "CSSTransition.h"
#include "CSSValue.h"
#include "CSSValueKeywords.h"
#include "ComputedStyleExtractor.h"
#include "Element.h"
#include "FontCascade.h"
#include "FrameView.h"
#include "GeometryUtilities.h"
#include "InspectorInstrumentation.h"
#include "JSCompositeOperation.h"
#include "JSCompositeOperationOrAuto.h"
#include "JSDOMConvert.h"
#include "JSKeyframeEffect.h"
#include "KeyframeEffectStack.h"
#include "Logging.h"
#include "MutableStyleProperties.h"
#include "PropertyAllowlist.h"
#include "RenderBox.h"
#include "RenderBoxModelObject.h"
#include "RenderElement.h"
#include "RenderStyle.h"
#include "Settings.h"
#include "StyleAdjuster.h"
#include "StylePendingResources.h"
#include "StyleProperties.h"
#include "StyleResolver.h"
#include "StyleScope.h"
#include "StyledElement.h"
#include "TimingFunction.h"
#include "TranslateTransformOperation.h"
#include "WillChangeData.h"
#include <JavaScriptCore/Exception.h>
#include <wtf/UUID.h>
#include <wtf/text/TextStream.h>
namespace WebCore {
using namespace JSC;
KeyframeEffect::ParsedKeyframe::ParsedKeyframe()
: style(MutableStyleProperties::create())
{
}
KeyframeEffect::ParsedKeyframe::~ParsedKeyframe() = default;
static inline void invalidateElement(const std::optional<const Styleable>& styleable)
{
if (styleable)
styleable->element.invalidateStyleInternal();
}
String KeyframeEffect::CSSPropertyIDToIDLAttributeName(CSSPropertyID property)
{
// https://drafts.csswg.org/web-animations-1/#animation-property-name-to-idl-attribute-name
// 1. If property follows the <custom-property-name> production, return property.
// 2. If property refers to the CSS float property, return the string "cssFloat".
if (property == CSSPropertyFloat)
return "cssFloat"_s;
// 3. If property refers to the CSS offset property, return the string "cssOffset".
if (property == CSSPropertyOffset)
return "cssOffset"_s;
// 4. Otherwise, return the result of applying the CSS property to IDL attribute algorithm [CSSOM] to property.
return nameForIDL(property);
}
static inline CSSPropertyID IDLAttributeNameToAnimationPropertyName(const AtomString& idlAttributeName)
{
// https://drafts.csswg.org/web-animations-1/#idl-attribute-name-to-animation-property-name
// 1. If attribute conforms to the <custom-property-name> production, return attribute.
// 2. If attribute is the string "cssFloat", then return an animation property representing the CSS float property.
if (idlAttributeName == "cssFloat"_s)
return CSSPropertyFloat;
// 3. If attribute is the string "cssOffset", then return an animation property representing the CSS offset property.
if (idlAttributeName == "cssOffset"_s)
return CSSPropertyOffset;
// 4. Otherwise, return the result of applying the IDL attribute to CSS property algorithm [CSSOM] to attribute.
auto cssPropertyId = CSSStyleDeclaration::getCSSPropertyIDFromJavaScriptPropertyName(idlAttributeName);
if (cssPropertyId == CSSPropertyInvalid && isCustomPropertyName(idlAttributeName))
return CSSPropertyCustom;
// We need to check that converting the property back to IDL form yields the same result such that a property passed
// in non-IDL form is rejected, for instance "font-size".
if (idlAttributeName != KeyframeEffect::CSSPropertyIDToIDLAttributeName(cssPropertyId))
return CSSPropertyInvalid;
return cssPropertyId;
}
static inline void computeMissingKeyframeOffsets(Vector<KeyframeEffect::ParsedKeyframe>& keyframes)
{
// https://drafts.csswg.org/web-animations-1/#compute-missing-keyframe-offsets
if (keyframes.isEmpty())
return;
// 1. For each keyframe, in keyframes, let the computed keyframe offset of the keyframe be equal to its keyframe offset value.
// In our implementation, we only set non-null values to avoid making computedOffset std::optional<double>. Instead, we'll know
// that a keyframe hasn't had a computed offset by checking if it has a null offset and a 0 computedOffset, since the first
// keyframe will already have a 0 computedOffset.
for (auto& keyframe : keyframes) {
auto computedOffset = keyframe.offset;
keyframe.computedOffset = computedOffset ? *computedOffset : 0;
}
// 2. If keyframes contains more than one keyframe and the computed keyframe offset of the first keyframe in keyframes is null,
// set the computed keyframe offset of the first keyframe to 0.
if (keyframes.size() > 1 && !keyframes[0].offset)
keyframes[0].computedOffset = 0;
// 3. If the computed keyframe offset of the last keyframe in keyframes is null, set its computed keyframe offset to 1.
if (!keyframes.last().offset)
keyframes.last().computedOffset = 1;
// 4. For each pair of keyframes A and B where:
// - A appears before B in keyframes, and
// - A and B have a computed keyframe offset that is not null, and
// - all keyframes between A and B have a null computed keyframe offset,
// calculate the computed keyframe offset of each keyframe between A and B as follows:
// 1. Let offsetk be the computed keyframe offset of a keyframe k.
// 2. Let n be the number of keyframes between and including A and B minus 1.
// 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.
// 4. Set the computed keyframe offset of keyframe to offsetA + (offsetB − offsetA) × index / n.
size_t indexOfLastKeyframeWithNonNullOffset = 0;
for (size_t i = 1; i < keyframes.size(); ++i) {
auto& keyframe = keyframes[i];
// Keyframes with a null offset that don't yet have a non-zero computed offset are keyframes
// with an offset that needs to be computed.
if (!keyframe.offset && !keyframe.computedOffset)
continue;
if (indexOfLastKeyframeWithNonNullOffset != i - 1) {
double lastNonNullOffset = keyframes[indexOfLastKeyframeWithNonNullOffset].computedOffset;
double offsetDelta = keyframe.computedOffset - lastNonNullOffset;
double offsetIncrement = offsetDelta / (i - indexOfLastKeyframeWithNonNullOffset);
size_t indexOfFirstKeyframeWithNullOffset = indexOfLastKeyframeWithNonNullOffset + 1;
for (size_t j = indexOfFirstKeyframeWithNullOffset; j < i; ++j)
keyframes[j].computedOffset = lastNonNullOffset + (j - indexOfLastKeyframeWithNonNullOffset) * offsetIncrement;
}
indexOfLastKeyframeWithNonNullOffset = i;
}
}
static inline ExceptionOr<KeyframeEffect::KeyframeLikeObject> processKeyframeLikeObject(JSGlobalObject& lexicalGlobalObject, Document& document, Strong<JSObject>&& keyframesInput, bool allowLists)
{
// https://drafts.csswg.org/web-animations-1/#process-a-keyframe-like-object
VM& vm = lexicalGlobalObject.vm();
auto scope = DECLARE_THROW_SCOPE(vm);
// 1. Run the procedure to convert an ECMAScript value to a dictionary type [WEBIDL] with keyframe input as the ECMAScript value as follows:
//
// If allow lists is true, use the following dictionary type:
//
// dictionary BasePropertyIndexedKeyframe {
// (double? or sequence<double?>) offset = [];
// (DOMString or sequence<DOMString>) easing = [];
// (CompositeOperationOrAuto or sequence<CompositeOperationOrAuto>) composite = [];
// };
//
// Otherwise, use the following dictionary type:
//
// dictionary BaseKeyframe {
// double? offset = null;
// DOMString easing = "linear";
// CompositeOperationOrAuto composite = "auto";
// };
//
// Store the result of this procedure as keyframe output.
KeyframeEffect::BasePropertyIndexedKeyframe baseProperties;
if (allowLists)
baseProperties = convert<IDLDictionary<KeyframeEffect::BasePropertyIndexedKeyframe>>(lexicalGlobalObject, keyframesInput.get());
else {
auto baseKeyframe = convert<IDLDictionary<KeyframeEffect::BaseKeyframe>>(lexicalGlobalObject, keyframesInput.get());
if (baseKeyframe.offset)
baseProperties.offset = baseKeyframe.offset.value();
else
baseProperties.offset = nullptr;
baseProperties.easing = baseKeyframe.easing;
if (document.settings().webAnimationsCompositeOperationsEnabled())
baseProperties.composite = baseKeyframe.composite;
}
RETURN_IF_EXCEPTION(scope, Exception { TypeError });
KeyframeEffect::KeyframeLikeObject keyframeOuput;
keyframeOuput.baseProperties = baseProperties;
// 2. Build up a list of animatable properties as follows:
//
// 1. Let animatable properties be a list of property names (including shorthand properties that have longhand sub-properties
// that are animatable) that can be animated by the implementation.
// 2. Convert each property name in animatable properties to the equivalent IDL attribute by applying the animation property
// name to IDL attribute name algorithm.
// 3. Let input properties be the result of calling the EnumerableOwnNames operation with keyframe input as the object.
PropertyNameArray inputProperties(vm, PropertyNameMode::Strings, PrivateSymbolMode::Exclude);
JSObject::getOwnPropertyNames(keyframesInput.get(), &lexicalGlobalObject, inputProperties, DontEnumPropertiesMode::Exclude);
// 4. Make up a new list animation properties that consists of all of the properties that are in both input properties and animatable
// properties, or which are in input properties and conform to the <custom-property-name> production.
Vector<JSC::Identifier> animationProperties;
for (auto& inputProperty : inputProperties) {
auto cssProperty = IDLAttributeNameToAnimationPropertyName(inputProperty.string());
if (!isExposed(cssProperty, &document.settings()))
cssProperty = CSSPropertyInvalid;
auto resolvedCSSProperty = CSSProperty::resolveDirectionAwareProperty(cssProperty, RenderStyle::initialDirection(), RenderStyle::initialWritingMode());
if (CSSPropertyAnimation::isPropertyAnimatable(resolvedCSSProperty))
animationProperties.append(inputProperty);
}
// 5. Sort animation properties in ascending order by the Unicode codepoints that define each property name.
std::sort(animationProperties.begin(), animationProperties.end(), [](auto& lhs, auto& rhs) {
return codePointCompareLessThan(lhs.string().string(), rhs.string().string());
});
// 6. For each property name in animation properties,
size_t numberOfAnimationProperties = animationProperties.size();
for (size_t i = 0; i < numberOfAnimationProperties; ++i) {
// 1. Let raw value be the result of calling the [[Get]] internal method on keyframe input, with property name as the property
// key and keyframe input as the receiver.
auto rawValue = keyframesInput->get(&lexicalGlobalObject, animationProperties[i]);
// 2. Check the completion record of raw value.
RETURN_IF_EXCEPTION(scope, Exception { TypeError });
// 3. Convert raw value to a DOMString or sequence of DOMStrings property values as follows:
Vector<String> propertyValues;
if (allowLists) {
// If allow lists is true,
// Let property values be the result of converting raw value to IDL type (DOMString or sequence<DOMString>)
// using the procedures defined for converting an ECMAScript value to an IDL value [WEBIDL].
// If property values is a single DOMString, replace property values with a sequence of DOMStrings with the original value of property
// Values as the only element.
if (rawValue.isObject())
propertyValues = convert<IDLSequence<IDLDOMString>>(lexicalGlobalObject, rawValue);
else
propertyValues = { rawValue.toWTFString(&lexicalGlobalObject) };
} else {
// Otherwise,
// Let property values be the result of converting raw value to a DOMString using the procedure for converting an ECMAScript value to a DOMString.
propertyValues = { convert<IDLDOMString>(lexicalGlobalObject, rawValue) };
}
RETURN_IF_EXCEPTION(scope, Exception { TypeError });
// 4. Calculate the normalized property name as the result of applying the IDL attribute name to animation property name algorithm to property name.
auto propertyName = animationProperties[i].string();
auto cssPropertyID = IDLAttributeNameToAnimationPropertyName(propertyName);
ASSERT(isExposed(cssPropertyID, &document.settings()));
// 5. Add a property to to keyframe output with normalized property name as the property name, and property values as the property value.
if (cssPropertyID == CSSPropertyCustom)
keyframeOuput.propertiesAndValues.append({ cssPropertyID, propertyName, propertyValues });
else
keyframeOuput.propertiesAndValues.append({ cssPropertyID, emptyAtom(), propertyValues });
}
// 7. Return keyframe output.
return { WTFMove(keyframeOuput) };
}
static inline ExceptionOr<void> processIterableKeyframes(JSGlobalObject& lexicalGlobalObject, Document& document, Strong<JSObject>&& keyframesInput, JSValue method, Vector<KeyframeEffect::ParsedKeyframe>& parsedKeyframes)
{
CSSParserContext parserContext(document);
// 1. Let iter be GetIterator(object, method).
forEachInIterable(lexicalGlobalObject, keyframesInput.get(), method, [&parsedKeyframes, &document, &parserContext](VM& vm, JSGlobalObject& lexicalGlobalObject, JSValue nextValue) -> ExceptionOr<void> {
// Steps 2 through 5 are already implemented by forEachInIterable().
auto scope = DECLARE_THROW_SCOPE(vm);
// 6. If Type(nextItem) is not Undefined, Null or Object, then throw a TypeError and abort these steps.
if (!nextValue.isUndefinedOrNull() && !nextValue.isObject()) {
throwException(&lexicalGlobalObject, scope, JSC::Exception::create(vm, createTypeError(&lexicalGlobalObject)));
return { };
}
if (!nextValue.isObject()) {
parsedKeyframes.append({ });
return { };
}
// 7. Append to processed keyframes the result of running the procedure to process a keyframe-like object passing nextItem
// as the keyframe input and with the allow lists flag set to false.
auto processKeyframeLikeObjectResult = processKeyframeLikeObject(lexicalGlobalObject, document, Strong<JSObject>(vm, nextValue.toObject(&lexicalGlobalObject)), false);
if (processKeyframeLikeObjectResult.hasException())
return processKeyframeLikeObjectResult.releaseException();
auto keyframeLikeObject = processKeyframeLikeObjectResult.returnValue();
KeyframeEffect::ParsedKeyframe keyframeOutput;
// When calling processKeyframeLikeObject() with the "allow lists" flag set to false, the only offset
// alternatives we should expect are double and nullptr.
if (std::holds_alternative<double>(keyframeLikeObject.baseProperties.offset))
keyframeOutput.offset = std::get<double>(keyframeLikeObject.baseProperties.offset);
else
ASSERT(std::holds_alternative<std::nullptr_t>(keyframeLikeObject.baseProperties.offset));
// When calling processKeyframeLikeObject() with the "allow lists" flag set to false, the only easing
// alternative we should expect is String.
ASSERT(std::holds_alternative<String>(keyframeLikeObject.baseProperties.easing));
keyframeOutput.easing = std::get<String>(keyframeLikeObject.baseProperties.easing);
// When calling processKeyframeLikeObject() with the "allow lists" flag set to false, the only composite
// alternatives we should expect is CompositeOperationAuto.
if (document.settings().webAnimationsCompositeOperationsEnabled()) {
ASSERT(std::holds_alternative<CompositeOperationOrAuto>(keyframeLikeObject.baseProperties.composite));
keyframeOutput.composite = std::get<CompositeOperationOrAuto>(keyframeLikeObject.baseProperties.composite);
}
for (auto& propertyAndValue : keyframeLikeObject.propertiesAndValues) {
auto cssPropertyId = propertyAndValue.property;
// When calling processKeyframeLikeObject() with the "allow lists" flag set to false,
// there should only ever be a single value for a given property.
ASSERT(propertyAndValue.values.size() == 1);
auto stringValue = propertyAndValue.values[0];
if (cssPropertyId == CSSPropertyCustom) {
auto customProperty = propertyAndValue.customProperty;
if (keyframeOutput.style->setCustomProperty(customProperty, stringValue, false, parserContext))
keyframeOutput.customStyleStrings.set(customProperty, stringValue);
} else if (keyframeOutput.style->setProperty(cssPropertyId, stringValue, false, parserContext))
keyframeOutput.styleStrings.set(cssPropertyId, stringValue);
}
parsedKeyframes.append(WTFMove(keyframeOutput));
return { };
});
return { };
}
static inline ExceptionOr<void> processPropertyIndexedKeyframes(JSGlobalObject& lexicalGlobalObject, Document& document, Strong<JSObject>&& keyframesInput, Vector<KeyframeEffect::ParsedKeyframe>& parsedKeyframes, Vector<String>& unusedEasings)
{
// 1. Let property-indexed keyframe be the result of running the procedure to process a keyframe-like object passing object as the keyframe input.
auto processKeyframeLikeObjectResult = processKeyframeLikeObject(lexicalGlobalObject, document, WTFMove(keyframesInput), true);
if (processKeyframeLikeObjectResult.hasException())
return processKeyframeLikeObjectResult.releaseException();
auto propertyIndexedKeyframe = processKeyframeLikeObjectResult.returnValue();
CSSParserContext parserContext(document);
// 2. For each member, m, in property-indexed keyframe, perform the following steps:
for (auto& m : propertyIndexedKeyframe.propertiesAndValues) {
// 1. Let property name be the key for m.
auto propertyName = m.property;
// 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
// keyframe after m.
// We skip this test since we split those properties and the actual CSS properties that we're currently iterating over.
// 3. Let property values be the value for m.
auto propertyValues = m.values;
// 4. Let property keyframes be an empty sequence of keyframes.
Vector<KeyframeEffect::ParsedKeyframe> propertyKeyframes;
// 5. For each value, v, in property values perform the following steps:
for (auto& v : propertyValues) {
// 1. Let k be a new keyframe with a null keyframe offset.
KeyframeEffect::ParsedKeyframe k;
// 2. Add the property-value pair, property name → v, to k.
if (propertyName == CSSPropertyCustom) {
auto customProperty = m.customProperty;
if (k.style->setCustomProperty(customProperty, v, false, parserContext))
k.customStyleStrings.set(customProperty, v);
} else if (k.style->setProperty(propertyName, v, false, parserContext))
k.styleStrings.set(propertyName, v);
// 3. Append k to property keyframes.
propertyKeyframes.append(WTFMove(k));
}
// 6. Apply the procedure to compute missing keyframe offsets to property keyframes.
computeMissingKeyframeOffsets(propertyKeyframes);
// 7. Add keyframes in property keyframes to processed keyframes.
parsedKeyframes.appendVector(propertyKeyframes);
}
// 3. Sort processed keyframes by the computed keyframe offset of each keyframe in increasing order.
std::sort(parsedKeyframes.begin(), parsedKeyframes.end(), [](auto& lhs, auto& rhs) {
return lhs.computedOffset < rhs.computedOffset;
});
// 4. Merge adjacent keyframes in processed keyframes when they have equal computed keyframe offsets.
size_t i = 1;
while (i < parsedKeyframes.size()) {
auto& keyframe = parsedKeyframes[i];
auto& previousKeyframe = parsedKeyframes[i - 1];
// If the offsets of this keyframe and the previous keyframe are different,
// this means that the two keyframes should not be merged and we can move
// on to the next keyframe.
if (keyframe.computedOffset != previousKeyframe.computedOffset) {
i++;
continue;
}
// Otherwise, both this keyframe and the previous keyframe should be merged.
// Unprocessed keyframes in parsedKeyframes at this stage have at most a single
// property in cssPropertiesAndValues, so just set this on the previous keyframe.
// In case an invalid or null value was originally provided, then the property
// was not set and the property count is 0, in which case there is nothing to merge.
if (keyframe.styleStrings.size()) {
previousKeyframe.style->mergeAndOverrideOnConflict(keyframe.style);
for (auto& [property, value] : keyframe.styleStrings)
previousKeyframe.styleStrings.set(property, value);
}
if (keyframe.customStyleStrings.size()) {
previousKeyframe.style->mergeAndOverrideOnConflict(keyframe.style);
for (auto& [customProperty, value] : keyframe.customStyleStrings)
previousKeyframe.customStyleStrings.set(customProperty, value);
}
// Since we've processed this keyframe, we can remove it and keep i the same
// so that we process the next keyframe in the next loop iteration.
parsedKeyframes.remove(i);
}
// 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:
// - sequence<double?>, the value of “offset” as-is.
// - double?, a sequence of length one with the value of “offset” as its single item, i.e. « offset »,
Vector<std::optional<double>> offsets;
if (std::holds_alternative<Vector<std::optional<double>>>(propertyIndexedKeyframe.baseProperties.offset))
offsets = std::get<Vector<std::optional<double>>>(propertyIndexedKeyframe.baseProperties.offset);
else if (std::holds_alternative<double>(propertyIndexedKeyframe.baseProperties.offset))
offsets.append(std::get<double>(propertyIndexedKeyframe.baseProperties.offset));
else if (std::holds_alternative<std::nullptr_t>(propertyIndexedKeyframe.baseProperties.offset))
offsets.append(std::nullopt);
// 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.
for (size_t i = 0; i < offsets.size() && i < parsedKeyframes.size(); ++i)
parsedKeyframes[i].offset = offsets[i];
// 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:
// - sequence<DOMString>, the value of “easing” as-is.
// - DOMString, a sequence of length one with the value of “easing” as its single item, i.e. « easing »,
Vector<String> easings;
if (std::holds_alternative<Vector<String>>(propertyIndexedKeyframe.baseProperties.easing))
easings = std::get<Vector<String>>(propertyIndexedKeyframe.baseProperties.easing);
else if (std::holds_alternative<String>(propertyIndexedKeyframe.baseProperties.easing))
easings.append(std::get<String>(propertyIndexedKeyframe.baseProperties.easing));
// 8. If easings is an empty sequence, let it be a sequence of length one containing the single value “linear”, i.e. « "linear" ».
if (easings.isEmpty())
easings.append("linear"_s);
// 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
// items as property keyframes.
if (easings.size() < parsedKeyframes.size()) {
size_t initialNumberOfEasings = easings.size();
for (i = initialNumberOfEasings; i < parsedKeyframes.size(); ++i)
easings.append(easings[i % initialNumberOfEasings]);
}
// 10. If easings has more items than property keyframes, store the excess items as unused easings.
while (easings.size() > parsedKeyframes.size())
unusedEasings.append(easings.takeLast());
// 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
// is reached.
for (size_t i = 0; i < parsedKeyframes.size(); ++i)
parsedKeyframes[i].easing = easings[i];
// 12. If the “composite” member of the property-indexed keyframe is not an empty sequence:
if (document.settings().webAnimationsCompositeOperationsEnabled()) {
Vector<CompositeOperationOrAuto> compositeModes;
if (std::holds_alternative<Vector<CompositeOperationOrAuto>>(propertyIndexedKeyframe.baseProperties.composite))
compositeModes = std::get<Vector<CompositeOperationOrAuto>>(propertyIndexedKeyframe.baseProperties.composite);
else if (std::holds_alternative<CompositeOperationOrAuto>(propertyIndexedKeyframe.baseProperties.composite))
compositeModes.append(std::get<CompositeOperationOrAuto>(propertyIndexedKeyframe.baseProperties.composite));
if (!compositeModes.isEmpty()) {
// 1. Let composite modes be a sequence of CompositeOperationOrAuto values assigned from the “composite” member of property-indexed keyframe. If that member is a single
// CompositeOperationOrAuto value operation, let composite modes be a sequence of length one, with the value of the “composite” as its single item.
// 2. As with easings, if composite modes has fewer items than processed keyframes, repeat the elements in composite modes successively starting from the beginning of
// the list until composite modes has as many items as processed keyframes.
if (compositeModes.size() < parsedKeyframes.size()) {
size_t initialNumberOfCompositeModes = compositeModes.size();
for (i = initialNumberOfCompositeModes; i < parsedKeyframes.size(); ++i)
compositeModes.append(compositeModes[i % initialNumberOfCompositeModes]);
}
// 3. Assign each value in composite modes that is not auto to the keyframe-specific composite operation on the keyframe with the corresponding position in processed
// keyframes until the end of processed keyframes is reached.
for (size_t i = 0; i < compositeModes.size() && i < parsedKeyframes.size(); ++i) {
if (compositeModes[i] != CompositeOperationOrAuto::Auto)
parsedKeyframes[i].composite = compositeModes[i];
}
}
}
return { };
}
ExceptionOr<Ref<KeyframeEffect>> KeyframeEffect::create(JSGlobalObject& lexicalGlobalObject, Document& document, Element* target, Strong<JSObject>&& keyframes, std::optional<std::variant<double, KeyframeEffectOptions>>&& options)
{
auto keyframeEffect = adoptRef(*new KeyframeEffect(target, PseudoId::None));
if (options) {
OptionalEffectTiming timing;
auto optionsValue = options.value();
if (std::holds_alternative<double>(optionsValue)) {
std::variant<double, String> duration = std::get<double>(optionsValue);
timing.duration = duration;
} else {
auto keyframeEffectOptions = std::get<KeyframeEffectOptions>(optionsValue);
auto setPseudoElementResult = keyframeEffect->setPseudoElement(keyframeEffectOptions.pseudoElement);
if (setPseudoElementResult.hasException())
return setPseudoElementResult.releaseException();
timing = {
keyframeEffectOptions.duration,
keyframeEffectOptions.iterations,
keyframeEffectOptions.delay,
keyframeEffectOptions.endDelay,
keyframeEffectOptions.iterationStart,
keyframeEffectOptions.easing,
keyframeEffectOptions.fill,
keyframeEffectOptions.direction
};
if (document.settings().webAnimationsCompositeOperationsEnabled())
keyframeEffect->setComposite(keyframeEffectOptions.composite);
if (document.settings().webAnimationsIterationCompositeEnabled())
keyframeEffect->setIterationComposite(keyframeEffectOptions.iterationComposite);
}
auto updateTimingResult = keyframeEffect->updateTiming(timing);
if (updateTimingResult.hasException())
return updateTimingResult.releaseException();
}
auto processKeyframesResult = keyframeEffect->processKeyframes(lexicalGlobalObject, document, WTFMove(keyframes));
if (processKeyframesResult.hasException())
return processKeyframesResult.releaseException();
return keyframeEffect;
}
Ref<KeyframeEffect> KeyframeEffect::create(Ref<KeyframeEffect>&& source)
{
auto keyframeEffect = adoptRef(*new KeyframeEffect(nullptr, PseudoId::None));
keyframeEffect->copyPropertiesFromSource(WTFMove(source));
return keyframeEffect;
}
Ref<KeyframeEffect> KeyframeEffect::create(const Element& target, PseudoId pseudoId)
{
return adoptRef(*new KeyframeEffect(const_cast<Element*>(&target), pseudoId));
}
KeyframeEffect::KeyframeEffect(Element* target, PseudoId pseudoId)
: m_keyframesName(makeAtomString("keyframe-effect-"_s, UUID::createVersion4Weak()))
, m_target(target)
, m_pseudoId(pseudoId)
{
}
void KeyframeEffect::copyPropertiesFromSource(Ref<KeyframeEffect>&& source)
{
m_target = source->m_target;
m_pseudoId = source->m_pseudoId;
m_compositeOperation = source->m_compositeOperation;
m_iterationCompositeOperation = source->m_iterationCompositeOperation;
Vector<ParsedKeyframe> parsedKeyframes;
for (auto& sourceParsedKeyframe : source->m_parsedKeyframes) {
ParsedKeyframe parsedKeyframe;
parsedKeyframe.easing = sourceParsedKeyframe.easing;
parsedKeyframe.offset = sourceParsedKeyframe.offset;
parsedKeyframe.composite = sourceParsedKeyframe.composite;
parsedKeyframe.styleStrings = sourceParsedKeyframe.styleStrings;
parsedKeyframe.customStyleStrings = sourceParsedKeyframe.customStyleStrings;
parsedKeyframe.computedOffset = sourceParsedKeyframe.computedOffset;
parsedKeyframe.timingFunction = sourceParsedKeyframe.timingFunction;
parsedKeyframe.style = sourceParsedKeyframe.style->mutableCopy();
parsedKeyframes.append(WTFMove(parsedKeyframe));
}
m_parsedKeyframes = WTFMove(parsedKeyframes);
setFill(source->fill());
setDelay(source->delay());
setEndDelay(source->endDelay());
setDirection(source->direction());
setIterations(source->iterations());
setTimingFunction(source->timingFunction());
setIterationStart(source->iterationStart());
setIterationDuration(source->iterationDuration());
updateStaticTimingProperties();
KeyframeList keyframeList(m_keyframesName);
keyframeList.copyKeyframes(source->m_blendingKeyframes);
setBlendingKeyframes(WTFMove(keyframeList));
}
auto KeyframeEffect::getKeyframes(Document& document) -> Vector<ComputedKeyframe>
{
// https://drafts.csswg.org/web-animations-1/#dom-keyframeeffectreadonly-getkeyframes
if (auto* declarativeAnimation = dynamicDowncast<DeclarativeAnimation>(animation()))
declarativeAnimation->flushPendingStyleChanges();
Vector<ComputedKeyframe> computedKeyframes;
if (!m_parsedKeyframes.isEmpty() || m_blendingKeyframesSource == BlendingKeyframesSource::WebAnimation || !m_blendingKeyframes.containsAnimatableProperty()) {
for (size_t i = 0; i < m_parsedKeyframes.size(); ++i) {
auto& parsedKeyframe = m_parsedKeyframes[i];
ComputedKeyframe computedKeyframe { parsedKeyframe };
for (auto& [cssPropertyId, stringValue] : computedKeyframe.styleStrings) {
if (cssPropertyId == CSSPropertyCustom)
continue;
if (auto cssValue = parsedKeyframe.style->getPropertyCSSValue(cssPropertyId))
stringValue = cssValue->cssText();
}
computedKeyframe.easing = timingFunctionForKeyframeAtIndex(i)->cssText();
computedKeyframes.append(WTFMove(computedKeyframe));
}
return computedKeyframes;
}
auto* target = m_target.get();
auto* lastStyleChangeEventStyle = targetStyleable()->lastStyleChangeEventStyle();
auto& elementStyle = lastStyleChangeEventStyle ? *lastStyleChangeEventStyle : currentStyle();
ComputedStyleExtractor computedStyleExtractor { target, false, m_pseudoId };
KeyframeList computedKeyframeList(m_blendingKeyframes.animationName());
computedKeyframeList.copyKeyframes(m_blendingKeyframes);
computedKeyframeList.fillImplicitKeyframes(*this, elementStyle);
auto keyframeRules = [&]() -> const Vector<Ref<StyleRuleKeyframe>> {
if (!is<CSSAnimation>(animation()))
return { };
if (!m_target || !m_target->isConnected())
return { };
auto& backingAnimation = downcast<CSSAnimation>(*animation()).backingAnimation();
auto* styleScope = Style::Scope::forOrdinal(*m_target, backingAnimation.nameStyleScopeOrdinal());
if (!styleScope)
return { };
return styleScope->resolver().keyframeRulesForName(computedKeyframeList.animationName());
}();
auto keyframeRuleForKey = [&](double key) -> StyleRuleKeyframe* {
for (auto& keyframeRule : keyframeRules) {
for (auto keyframeRuleKey : keyframeRule->keys()) {
if (keyframeRuleKey == key)
return keyframeRule.ptr();
}
}
return nullptr;
};
auto styleProperties = MutableStyleProperties::create();
if (m_blendingKeyframesSource == BlendingKeyframesSource::CSSAnimation) {
auto matchingRules = m_target->styleResolver().pseudoStyleRulesForElement(target, m_pseudoId, Style::Resolver::AllCSSRules);
for (auto& matchedRule : matchingRules)
styleProperties->mergeAndOverrideOnConflict(matchedRule->properties());
if (is<StyledElement>(m_target) && m_pseudoId == PseudoId::None) {
if (auto* inlineProperties = downcast<StyledElement>(*m_target).inlineStyle())
styleProperties->mergeAndOverrideOnConflict(*inlineProperties);
}
}
for (auto& keyframe : computedKeyframeList) {
auto& style = *keyframe.style();
auto* keyframeRule = keyframeRuleForKey(keyframe.key());
ComputedKeyframe computedKeyframe;
computedKeyframe.offset = keyframe.key();
computedKeyframe.computedOffset = keyframe.key();
// For CSS transitions, all keyframes should return "linear" since the effect's global timing function applies.
computedKeyframe.easing = is<CSSTransition>(animation()) ? "linear"_s : timingFunctionForBlendingKeyframe(keyframe)->cssText();
if (document.settings().webAnimationsCompositeOperationsEnabled()) {
if (auto compositeOperation = keyframe.compositeOperation())
computedKeyframe.composite = toCompositeOperationOrAuto(*compositeOperation);
}
auto addPropertyToKeyframe = [&](CSSPropertyID cssPropertyId) {
String styleString = emptyString();
if (keyframeRule) {
if (auto cssValue = keyframeRule->properties().getPropertyCSSValue(cssPropertyId)) {
if (!cssValue->hasVariableReferences())
styleString = keyframeRule->properties().getPropertyValue(cssPropertyId);
}
}
if (styleString.isEmpty()) {
if (auto cssValue = styleProperties->getPropertyCSSValue(cssPropertyId)) {
if (!cssValue->hasVariableReferences())
styleString = styleProperties->getPropertyValue(cssPropertyId);
}
}
if (styleString.isEmpty()) {
if (auto cssValue = computedStyleExtractor.valueForPropertyInStyle(style, cssPropertyId, nullptr, ComputedStyleExtractor::PropertyValueType::Computed))
styleString = cssValue->cssText();
}
computedKeyframe.styleStrings.set(cssPropertyId, styleString);
};
auto addCustomPropertyToKeyframe = [&](const AtomString& customProperty) {
String styleString = emptyString();
if (keyframeRule) {
if (auto cssValue = keyframeRule->properties().getCustomPropertyCSSValue(customProperty)) {
if (!cssValue->hasVariableReferences())
styleString = keyframeRule->properties().getCustomPropertyValue(customProperty);
}
}
if (styleString.isEmpty()) {
if (auto cssValue = styleProperties->getCustomPropertyCSSValue(customProperty)) {
if (!cssValue->hasVariableReferences())
styleString = styleProperties->getCustomPropertyValue(customProperty);
}
}
if (styleString.isEmpty()) {
if (auto cssValue = computedStyleExtractor.customPropertyValue(customProperty))
styleString = cssValue->cssText();
}
computedKeyframe.customStyleStrings.set(customProperty, styleString);
};
for (auto property : keyframe.properties()) {
WTF::switchOn(property,
[&] (CSSPropertyID cssProperty) {
addPropertyToKeyframe(cssProperty);
},
[&] (const AtomString& customProperty) {
if (m_blendingKeyframesSource != BlendingKeyframesSource::CSSAnimation)
addCustomPropertyToKeyframe(customProperty);
}
);
}
computedKeyframes.append(WTFMove(computedKeyframe));
}
return computedKeyframes;
}
ExceptionOr<void> KeyframeEffect::setBindingsKeyframes(JSGlobalObject& lexicalGlobalObject, Document& document, Strong<JSObject>&& keyframesInput)
{
auto retVal = setKeyframes(lexicalGlobalObject, document, WTFMove(keyframesInput));
if (!retVal.hasException() && is<CSSAnimation>(animation()))
downcast<CSSAnimation>(*animation()).effectKeyframesWereSetUsingBindings();
return retVal;
}
ExceptionOr<void> KeyframeEffect::setKeyframes(JSGlobalObject& lexicalGlobalObject, Document& document, Strong<JSObject>&& keyframesInput)
{
auto processKeyframesResult = processKeyframes(lexicalGlobalObject, document, WTFMove(keyframesInput));
if (!processKeyframesResult.hasException() && animation())
animation()->effectTimingDidChange();
return processKeyframesResult;
}
void KeyframeEffect::keyframesRuleDidChange()
{
ASSERT(is<CSSAnimation>(animation()));
clearBlendingKeyframes();
invalidate();
}
void KeyframeEffect::customPropertyRegistrationDidChange(const AtomString& customProperty)
{
// If the registration of a custom property is changed, we should recompute keyframes
// at the next opportunity as the initial value, inherited value, etc. could have changed.
if (!m_blendingKeyframes.properties().contains(customProperty))
return;
clearBlendingKeyframes();
invalidate();
}
ExceptionOr<void> KeyframeEffect::processKeyframes(JSGlobalObject& lexicalGlobalObject, Document& document, Strong<JSObject>&& keyframesInput)
{
Ref protectedDocument { document };
// 1. If object is null, return an empty sequence of keyframes.
if (!keyframesInput.get())
return { };
VM& vm = lexicalGlobalObject.vm();
auto scope = DECLARE_THROW_SCOPE(vm);
// 2. Let processed keyframes be an empty sequence of keyframes.
Vector<ParsedKeyframe> parsedKeyframes;
// 3. Let method be the result of GetMethod(object, @@iterator).
auto method = keyframesInput.get()->get(&lexicalGlobalObject, vm.propertyNames->iteratorSymbol);
// 4. Check the completion record of method.
RETURN_IF_EXCEPTION(scope, Exception { TypeError });
// 5. Perform the steps corresponding to the first matching condition from below,
Vector<String> unusedEasings;
if (!method.isUndefined()) {
auto retVal = processIterableKeyframes(lexicalGlobalObject, document, WTFMove(keyframesInput), WTFMove(method), parsedKeyframes);
if (retVal.hasException())
return retVal.releaseException();
} else {
auto retVal = processPropertyIndexedKeyframes(lexicalGlobalObject, document, WTFMove(keyframesInput), parsedKeyframes, unusedEasings);
if (retVal.hasException())
return retVal.releaseException();
}
// 6. If processed keyframes is not loosely sorted by offset, throw a TypeError and abort these steps.
// 7. If there exist any keyframe in processed keyframes whose keyframe offset is non-null and less than
// zero or greater than one, throw a TypeError and abort these steps.
double lastNonNullOffset = -1;
for (auto& keyframe : parsedKeyframes) {
if (!keyframe.offset)
continue;
auto offset = keyframe.offset.value();
if (offset < lastNonNullOffset || offset < 0 || offset > 1)
return Exception { TypeError };
lastNonNullOffset = offset;
}
// We take a slight detour from the spec text and compute the missing keyframe offsets right away
// since they can be computed up-front.
computeMissingKeyframeOffsets(parsedKeyframes);
// 8. For each frame in processed keyframes, perform the following steps:
for (auto& keyframe : parsedKeyframes) {
// Let the timing function of frame be the result of parsing the “easing” property on frame using the CSS syntax
// defined for the easing property of the AnimationEffectTiming interface.
// If parsing the “easing” property fails, throw a TypeError and abort this procedure.
auto timingFunctionResult = TimingFunction::createFromCSSText(keyframe.easing);
if (timingFunctionResult.hasException())
return timingFunctionResult.releaseException();
keyframe.timingFunction = timingFunctionResult.returnValue();
}
// 9. Parse each of the values in unused easings using the CSS syntax defined for easing property of the
// AnimationEffectTiming interface, and if any of the values fail to parse, throw a TypeError
// and abort this procedure.
for (auto& easing : unusedEasings) {
auto timingFunctionResult = TimingFunction::createFromCSSText(easing);
if (timingFunctionResult.hasException())
return timingFunctionResult.releaseException();
}
m_parsedKeyframes = WTFMove(parsedKeyframes);
clearBlendingKeyframes();
invalidate();
return { };
}
void KeyframeEffect::updateBlendingKeyframes(RenderStyle& elementStyle, const Style::ResolutionContext& resolutionContext)
{
if (!m_blendingKeyframes.isEmpty() || !m_target)
return;
KeyframeList keyframeList(m_keyframesName);
auto& styleResolver = m_target->styleResolver();
for (auto& keyframe : m_parsedKeyframes) {
KeyframeValue keyframeValue(keyframe.computedOffset, nullptr);
keyframeValue.setTimingFunction(keyframe.timingFunction->clone());
switch (keyframe.composite) {
case CompositeOperationOrAuto::Replace:
keyframeValue.setCompositeOperation(CompositeOperation::Replace);
break;
case CompositeOperationOrAuto::Add:
keyframeValue.setCompositeOperation(CompositeOperation::Add);
break;
case CompositeOperationOrAuto::Accumulate:
keyframeValue.setCompositeOperation(CompositeOperation::Accumulate);
break;
case CompositeOperationOrAuto::Auto:
break;
}
auto keyframeRule = StyleRuleKeyframe::create(keyframe.style->immutableCopyIfNeeded());
keyframeValue.setStyle(styleResolver.styleForKeyframe(*m_target, elementStyle, resolutionContext, keyframeRule.get(), keyframeValue));
keyframeList.insert(WTFMove(keyframeValue));
keyframeList.updatePropertiesMetadata(keyframeRule->properties());
}
setBlendingKeyframes(WTFMove(keyframeList));
}
const HashSet<AnimatableProperty>& KeyframeEffect::animatedProperties()
{
if (!m_blendingKeyframes.isEmpty())
return m_blendingKeyframes.properties();
if (m_animatedProperties.isEmpty()) {
for (auto& keyframe : m_parsedKeyframes) {
for (auto keyframeCustomProperty : keyframe.customStyleStrings.keys())
m_animatedProperties.add(keyframeCustomProperty);
for (auto keyframeProperty : keyframe.styleStrings.keys())
m_animatedProperties.add(keyframeProperty);
}
}
return m_animatedProperties;
}
bool KeyframeEffect::animatesProperty(AnimatableProperty property) const
{
if (!m_blendingKeyframes.isEmpty())
return m_blendingKeyframes.containsProperty(property);
return m_parsedKeyframes.findIf([&](const auto& keyframe) {
return WTF::switchOn(property,
[&](CSSPropertyID cssProperty) {
for (auto keyframeProperty : keyframe.styleStrings.keys()) {
if (keyframeProperty == cssProperty)
return true;
}
return false;
},
[&](const AtomString& customProperty) {
for (auto keyframeProperty : keyframe.customStyleStrings.keys()) {
if (keyframeProperty == customProperty)
return true;
}
return false;
}
);
}) != notFound;
}
bool KeyframeEffect::forceLayoutIfNeeded()
{
if (!m_needsForcedLayout || !m_target)
return false;
auto* renderer = this->renderer();
if (!renderer || !renderer->parent())
return false;
ASSERT(document());
auto* frameView = document()->view();
if (!frameView)
return false;
frameView->forceLayout();
return true;
}
void KeyframeEffect::clearBlendingKeyframes()
{
m_blendingKeyframesSource = BlendingKeyframesSource::WebAnimation;
m_blendingKeyframes.clear();
}
void KeyframeEffect::setBlendingKeyframes(KeyframeList&& blendingKeyframes)
{
CanBeAcceleratedMutationScope mutationScope(this);
m_blendingKeyframes = WTFMove(blendingKeyframes);
m_animatedProperties.clear();
computedNeedsForcedLayout();
computeStackingContextImpact();
computeAcceleratedPropertiesState();
computeSomeKeyframesUseStepsTimingFunction();
computeHasImplicitKeyframeForAcceleratedProperty();