Add an iterator to KeyframeList
https://bugs.webkit.org/show_bug.cgi?id=235652

Reviewed by Darin Adler.

Add an iterator for KeyframeList and remove the keyframes() method which serves no purpose now.

* animation/KeyframeEffect.cpp:
(WebCore::KeyframeEffect::getKeyframes):
(WebCore::KeyframeEffect::computeCSSAnimationBlendingKeyframes):
(WebCore::KeyframeEffect::computedNeedsForcedLayout):
(WebCore::KeyframeEffect::computeSomeKeyframesUseStepsTimingFunction):
(WebCore::KeyframeEffect::setAnimatedPropertiesInStyle):
(WebCore::KeyframeEffect::computeExtentOfTransformAnimation const):
* rendering/RenderLayerBacking.cpp:
(WebCore::RenderLayerBacking::startAnimation):
* rendering/style/KeyframeList.cpp:
(WebCore::KeyframeList::copyKeyframes):
* rendering/style/KeyframeList.h:
(WebCore::KeyframeList::operator[] const):
(WebCore::KeyframeList::begin const):
(WebCore::KeyframeList::end const):
(WebCore::KeyframeList::keyframes const): Deleted.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@288641 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 4203d04..d2d19e0 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,29 @@
+2022-01-26  Antoine Quint  <graouts@webkit.org>
+
+        Add an iterator to KeyframeList
+        https://bugs.webkit.org/show_bug.cgi?id=235652
+
+        Reviewed by Darin Adler.
+
+        Add an iterator for KeyframeList and remove the keyframes() method which serves no purpose now.
+
+        * animation/KeyframeEffect.cpp:
+        (WebCore::KeyframeEffect::getKeyframes):
+        (WebCore::KeyframeEffect::computeCSSAnimationBlendingKeyframes):
+        (WebCore::KeyframeEffect::computedNeedsForcedLayout):
+        (WebCore::KeyframeEffect::computeSomeKeyframesUseStepsTimingFunction):
+        (WebCore::KeyframeEffect::setAnimatedPropertiesInStyle):
+        (WebCore::KeyframeEffect::computeExtentOfTransformAnimation const):
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::RenderLayerBacking::startAnimation):
+        * rendering/style/KeyframeList.cpp:
+        (WebCore::KeyframeList::copyKeyframes):
+        * rendering/style/KeyframeList.h:
+        (WebCore::KeyframeList::operator[] const):
+        (WebCore::KeyframeList::begin const):
+        (WebCore::KeyframeList::end const):
+        (WebCore::KeyframeList::keyframes const): Deleted.
+
 2022-01-26  Alexey Shvayka  <ashvayka@apple.com>
 
         globalThis.queueMicrotask() should report thrown exceptions
diff --git a/Source/WebCore/animation/KeyframeEffect.cpp b/Source/WebCore/animation/KeyframeEffect.cpp
index ee9b7a0..0eb1724 100644
--- a/Source/WebCore/animation/KeyframeEffect.cpp
+++ b/Source/WebCore/animation/KeyframeEffect.cpp
@@ -647,7 +647,7 @@
     auto oneKeyframeProperties = computedKeyframeList.properties();
     zeroKeyframeProperties.remove(CSSPropertyCustom);
     oneKeyframeProperties.remove(CSSPropertyCustom);
-    for (auto& keyframe : computedKeyframeList.keyframes()) {
+    for (auto& keyframe : computedKeyframeList) {
         if (!keyframe.key()) {
             for (auto cssPropertyId : keyframe.properties())
                 zeroKeyframeProperties.remove(cssPropertyId);
@@ -657,7 +657,7 @@
         }
     }
 
-    for (auto& keyframe : computedKeyframeList.keyframes()) {
+    for (auto& keyframe : computedKeyframeList) {
         auto& style = *keyframe.style();
         auto* keyframeRule = keyframeRuleForKey(keyframe.key());
 
@@ -1050,7 +1050,7 @@
         styleScope->resolver().keyframeStylesForAnimation(*m_target, &unanimatedStyle, resolutionContext, keyframeList);
 
     // Ensure resource loads for all the frames.
-    for (auto& keyframe : keyframeList.keyframes()) {
+    for (auto& keyframe : keyframeList) {
         if (auto* style = const_cast<RenderStyle*>(keyframe.style()))
             Style::loadPendingResources(*style, *document(), m_target.get());
     }
@@ -1094,9 +1094,8 @@
     if (is<CSSTransition>(animation()) || !m_blendingKeyframes.containsProperty(CSSPropertyTransform))
         return;
 
-    size_t numberOfKeyframes = m_blendingKeyframes.size();
-    for (size_t i = 0; i < numberOfKeyframes; i++) {
-        auto* keyframeStyle = m_blendingKeyframes[i].style();
+    for (auto& keyframe : m_blendingKeyframes) {
+        auto* keyframeStyle = keyframe.style();
         if (!keyframeStyle) {
             ASSERT_NOT_REACHED();
             continue;
@@ -1349,14 +1348,12 @@
 {
     m_someKeyframesUseStepsTimingFunction = false;
 
-    size_t numberOfKeyframes = m_blendingKeyframes.size();
-
     // If we're dealing with a CSS Animation and it specifies a default steps() timing function,
     // we need to check that any of the specified keyframes either does not have an explicit timing
     // function or specifies an explicit steps() timing function.
     if (is<CSSAnimation>(animation()) && is<StepsTimingFunction>(downcast<DeclarativeAnimation>(*animation()).backingAnimation().timingFunction())) {
-        for (size_t i = 0; i < numberOfKeyframes; i++) {
-            auto* timingFunction = m_blendingKeyframes[i].timingFunction();
+        for (auto& keyframe : m_blendingKeyframes) {
+            auto* timingFunction = keyframe.timingFunction();
             if (!timingFunction || is<StepsTimingFunction>(timingFunction)) {
                 m_someKeyframesUseStepsTimingFunction = true;
                 return;
@@ -1367,8 +1364,8 @@
 
     // For any other type of animation, we just need to check whether any of the keyframes specify
     // an explicit steps() timing function.
-    for (size_t i = 0; i < numberOfKeyframes; i++) {
-        if (is<StepsTimingFunction>(m_blendingKeyframes[i].timingFunction())) {
+    for (auto& keyframe : m_blendingKeyframes) {
+        if (is<StepsTimingFunction>(keyframe.timingFunction())) {
             m_someKeyframesUseStepsTimingFunction = true;
             return;
         }
@@ -1450,8 +1447,7 @@
         unsigned numberOfKeyframesWithZeroOffset = 0;
         unsigned numberOfKeyframesWithOneOffset = 0;
         Vector<const KeyframeValue*> propertySpecificKeyframes;
-        for (size_t i = 0; i < m_blendingKeyframes.size(); ++i) {
-            auto& keyframe = m_blendingKeyframes[i];
+        for (auto& keyframe : m_blendingKeyframes) {
             auto offset = keyframe.key();
             if (!keyframe.containsProperty(cssPropertyId)) {
                 // If we're dealing with a CSS animation, we consider the first and last keyframes to always have the property listed
@@ -1948,7 +1944,7 @@
         return true;
     };
 
-    for (const auto& keyframe : m_blendingKeyframes.keyframes()) {
+    for (const auto& keyframe : m_blendingKeyframes) {
         const auto* keyframeStyle = keyframe.style();
 
         // FIXME: maybe for declarative animations we always say it's true for the first and last keyframe.
diff --git a/Source/WebCore/rendering/RenderLayerBacking.cpp b/Source/WebCore/rendering/RenderLayerBacking.cpp
index 6879ca5..cfb4206 100644
--- a/Source/WebCore/rendering/RenderLayerBacking.cpp
+++ b/Source/WebCore/rendering/RenderLayerBacking.cpp
@@ -3683,9 +3683,7 @@
     KeyframeValueList backdropFilterVector(AnimatedPropertyWebkitBackdropFilter);
 #endif
 
-    size_t numKeyframes = keyframes.size();
-    for (size_t i = 0; i < numKeyframes; ++i) {
-        const KeyframeValue& currentKeyframe = keyframes[i];
+    for (auto& currentKeyframe : keyframes) {
         const RenderStyle* keyframeStyle = currentKeyframe.style();
         double key = currentKeyframe.key();
 
diff --git a/Source/WebCore/rendering/style/KeyframeList.cpp b/Source/WebCore/rendering/style/KeyframeList.cpp
index 48ce4b1..4532e04 100644
--- a/Source/WebCore/rendering/style/KeyframeList.cpp
+++ b/Source/WebCore/rendering/style/KeyframeList.cpp
@@ -84,7 +84,7 @@
 
 void KeyframeList::copyKeyframes(KeyframeList& other)
 {
-    for (auto& keyframe : other.keyframes()) {
+    for (auto& keyframe : other) {
         KeyframeValue keyframeValue(keyframe.key(), RenderStyle::clonePtr(*keyframe.style()));
         for (auto propertyId : keyframe.properties())
             keyframeValue.addProperty(propertyId);
diff --git a/Source/WebCore/rendering/style/KeyframeList.h b/Source/WebCore/rendering/style/KeyframeList.h
index 1f30878..ae4a07e 100644
--- a/Source/WebCore/rendering/style/KeyframeList.h
+++ b/Source/WebCore/rendering/style/KeyframeList.h
@@ -97,12 +97,14 @@
     bool isEmpty() const { return m_keyframes.isEmpty(); }
     size_t size() const { return m_keyframes.size(); }
     const KeyframeValue& operator[](size_t index) const { return m_keyframes[index]; }
-    const Vector<KeyframeValue>& keyframes() const { return m_keyframes; }
 
     void copyKeyframes(KeyframeList&);
     bool hasImplicitKeyframes() const;
     void fillImplicitKeyframes(const Element&, Style::Resolver&, const RenderStyle* elementStyle, const RenderStyle* parentElementStyle);
 
+    auto begin() const { return m_keyframes.begin(); }
+    auto end() const { return m_keyframes.end(); }
+
 private:
     AtomString m_animationName;
     Vector<KeyframeValue> m_keyframes; // Kept sorted by key.