Title: [287762] trunk/Source/WebCore
Revision
287762
Author
grao...@webkit.org
Date
2022-01-07 10:48:40 -0800 (Fri, 07 Jan 2022)

Log Message

Expose iterators on AnimationList
https://bugs.webkit.org/show_bug.cgi?id=234957

Reviewed by Antti Koivisto.

* animation/WebAnimationUtilities.cpp:
(WebCore::compareCSSAnimations):
* css/CSSComputedStyleDeclaration.cpp:
(WebCore::valueListForAnimationOrTransitionProperty):
(WebCore::animationShorthandValue):
* css/makeprop.pl:
(generateAnimationPropertyInitialValueSetter):
* platform/animation/AnimationList.h:
(WebCore::AnimationList::begin const):
(WebCore::AnimationList::end const):
(WebCore::AnimationList::rbegin const):
(WebCore::AnimationList::rend const):
* style/Styleable.cpp:
(WebCore::Styleable::updateCSSAnimations const):
(WebCore::compileTransitionPropertiesInStyle):
(WebCore::updateCSSTransitionsForStyleableAndProperty):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (287761 => 287762)


--- trunk/Source/WebCore/ChangeLog	2022-01-07 18:46:00 UTC (rev 287761)
+++ trunk/Source/WebCore/ChangeLog	2022-01-07 18:48:40 UTC (rev 287762)
@@ -1,5 +1,29 @@
 2022-01-07  Antoine Quint  <grao...@webkit.org>
 
+        Expose iterators on AnimationList
+        https://bugs.webkit.org/show_bug.cgi?id=234957
+
+        Reviewed by Antti Koivisto.
+
+        * animation/WebAnimationUtilities.cpp:
+        (WebCore::compareCSSAnimations):
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::valueListForAnimationOrTransitionProperty):
+        (WebCore::animationShorthandValue):
+        * css/makeprop.pl:
+        (generateAnimationPropertyInitialValueSetter):
+        * platform/animation/AnimationList.h:
+        (WebCore::AnimationList::begin const):
+        (WebCore::AnimationList::end const):
+        (WebCore::AnimationList::rbegin const):
+        (WebCore::AnimationList::rend const):
+        * style/Styleable.cpp:
+        (WebCore::Styleable::updateCSSAnimations const):
+        (WebCore::compileTransitionPropertiesInStyle):
+        (WebCore::updateCSSTransitionsForStyleableAndProperty):
+
+2022-01-07  Antoine Quint  <grao...@webkit.org>
+
         Values in WebAnimation::instances should not be null-checked
         https://bugs.webkit.org/show_bug.cgi?id=234948
 

Modified: trunk/Source/WebCore/animation/WebAnimationUtilities.cpp (287761 => 287762)


--- trunk/Source/WebCore/animation/WebAnimationUtilities.cpp	2022-01-07 18:46:00 UTC (rev 287761)
+++ trunk/Source/WebCore/animation/WebAnimationUtilities.cpp	2022-01-07 18:48:40 UTC (rev 287762)
@@ -132,11 +132,10 @@
 
     auto& aBackingAnimation = a.backingAnimation();
     auto& bBackingAnimation = b.backingAnimation();
-    for (size_t i = 0; i < cssAnimationList->size(); ++i) {
-        auto& animation = cssAnimationList->animation(i);
-        if (&animation == &aBackingAnimation)
+    for (auto& animation : *cssAnimationList) {
+        if (animation.ptr() == &aBackingAnimation)
             return true;
-        if (&animation == &bBackingAnimation)
+        if (animation.ptr() == &bBackingAnimation)
             return false;
     }
 

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (287761 => 287762)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2022-01-07 18:46:00 UTC (rev 287761)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2022-01-07 18:48:40 UTC (rev 287762)
@@ -1474,8 +1474,8 @@
 {
     auto list = CSSValueList::createCommaSeparated();
     if (animationList) {
-        for (size_t i = 0; i < animationList->size(); ++i)
-            ComputedStyleExtractor::addValueForAnimationPropertyToList(list.get(), property, &animationList->animation(i));
+        for (const auto& animation : *animationList)
+            ComputedStyleExtractor::addValueForAnimationPropertyToList(list.get(), property, animation.ptr());
     } else
         ComputedStyleExtractor::addValueForAnimationPropertyToList(list.get(), property, nullptr);
     return list;
@@ -1485,11 +1485,10 @@
 {
     auto parentList = CSSValueList::createCommaSeparated();
     if (animationList) {
-        for (size_t i = 0; i < animationList->size(); ++i) {
-            const auto& animation = animationList->animation(i);
+        for (const auto& animation : *animationList) {
             auto childList = CSSValueList::createSpaceSeparated();
             for (auto longhand : shorthandForProperty(property))
-                ComputedStyleExtractor::addValueForAnimationPropertyToList(childList.get(), longhand, &animation);
+                ComputedStyleExtractor::addValueForAnimationPropertyToList(childList.get(), longhand, animation.ptr());
             parentList->append(childList);
         }
     }

Modified: trunk/Source/WebCore/css/makeprop.pl (287761 => 287762)


--- trunk/Source/WebCore/css/makeprop.pl	2022-01-07 18:46:00 UTC (rev 287761)
+++ trunk/Source/WebCore/css/makeprop.pl	2022-01-07 18:48:40 UTC (rev 287762)
@@ -1067,8 +1067,8 @@
   my $setter = $propertiesWithStyleBuilderOptions{$name}{"setter"};
   my $initial = $propertiesWithStyleBuilderOptions{$name}{"initial"};
   $setterContent .= $indent . "list.animation(0)." . $setter . "(Animation::" . $initial . "());\n";
-  $setterContent .= $indent . "for (size_t i = 1; i < list.size(); ++i)\n";
-  $setterContent .= $indent . "    list.animation(i)." . getClearFunction($name) . "();\n";
+  $setterContent .= $indent . "for (auto& animation : list)\n";
+  $setterContent .= $indent . "    animation->" . getClearFunction($name) . "();\n";
 
   return $setterContent;
 }

Modified: trunk/Source/WebCore/platform/animation/AnimationList.h (287761 => 287762)


--- trunk/Source/WebCore/platform/animation/AnimationList.h	2022-01-07 18:46:00 UTC (rev 287761)
+++ trunk/Source/WebCore/platform/animation/AnimationList.h	2022-01-07 18:48:40 UTC (rev 287762)
@@ -54,7 +54,14 @@
 
     Animation& animation(size_t i) { return m_animations[i].get(); }
     const Animation& animation(size_t i) const { return m_animations[i].get(); }
-    
+
+    auto begin() const { return m_animations.begin(); }
+    auto end() const { return m_animations.end(); }
+
+    using const_reverse_iterator = Vector<Ref<Animation>>::const_reverse_iterator;
+    const_reverse_iterator rbegin() const { return m_animations.rbegin(); }
+    const_reverse_iterator rend() const { return m_animations.rend(); }
+
 private:
     AnimationList();
 

Modified: trunk/Source/WebCore/style/Styleable.cpp (287761 => 287762)


--- trunk/Source/WebCore/style/Styleable.cpp	2022-01-07 18:46:00 UTC (rev 287761)
+++ trunk/Source/WebCore/style/Styleable.cpp	2022-01-07 18:48:40 UTC (rev 287762)
@@ -246,17 +246,16 @@
     // cause the existing animation for ‘a’ to become the second animation in the list and a new animation will be created for the
     // first item in the list.
     if (currentAnimationList) {
-        for (size_t i = currentAnimationList->size(); i > 0; --i) {
-            auto& currentAnimation = currentAnimationList->animation(i - 1);
-            if (!shouldConsiderAnimation(this->element, currentAnimation))
+        for (auto& currentAnimation : makeReversedRange(*currentAnimationList)) {
+            if (!shouldConsiderAnimation(this->element, currentAnimation.get()))
                 continue;
 
             bool foundMatchingAnimation = false;
             for (auto& previousAnimation : previousAnimations) {
-                if (previousAnimation->animationName() == currentAnimation.name().string) {
+                if (previousAnimation->animationName() == currentAnimation->name().string) {
                     // Timing properties or play state may have changed so we need to update the backing animation with
                     // the Animation found in the current style.
-                    previousAnimation->setBackingAnimation(currentAnimation);
+                    previousAnimation->setBackingAnimation(currentAnimation.get());
                     // Keyframes may have been cleared if the @keyframes rules was changed since
                     // the last style update, so we must ensure keyframes are picked up.
                     previousAnimation->updateKeyframesIfNeeded(currentStyle, newStyle, resolutionContext);
@@ -269,7 +268,7 @@
             }
 
             if (!foundMatchingAnimation)
-                newAnimations.add(CSSAnimation::create(*this, currentAnimation, currentStyle, newStyle, resolutionContext));
+                newAnimations.add(CSSAnimation::create(*this, currentAnimation.get(), currentStyle, newStyle, resolutionContext));
         }
     }
 
@@ -342,11 +341,10 @@
     if (!transitions)
         return;
 
-    for (size_t i = 0; i < transitions->size(); ++i) {
-        const auto& animation = transitions->animation(i);
-        auto mode = animation.property().mode;
+    for (const auto& animation : *transitions) {
+        auto mode = animation->property().mode;
         if (mode == Animation::TransitionMode::SingleProperty) {
-            auto property = animation.property().id;
+            auto property = animation->property().id;
             if (isShorthandCSSProperty(property)) {
                 for (auto longhand : shorthandForProperty(property))
                     transitionProperties.add(longhand);
@@ -375,10 +373,9 @@
 
     const Animation* matchingBackingAnimation = nullptr;
     if (auto* transitions = newStyle.transitions()) {
-        for (size_t i = 0; i < transitions->size(); ++i) {
-            auto& backingAnimation = transitions->animation(i);
-            if (transitionMatchesProperty(backingAnimation, property))
-                matchingBackingAnimation = &backingAnimation;
+        for (auto& backingAnimation : *transitions) {
+            if (transitionMatchesProperty(backingAnimation.get(), property))
+                matchingBackingAnimation = backingAnimation.ptr();
         }
     }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to