2011-07-01 Dirk Schulze <krit@webkit.org>
authorkrit@webkit.org <krit@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Jul 2011 08:51:28 +0000 (08:51 +0000)
committerkrit@webkit.org <krit@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Jul 2011 08:51:28 +0000 (08:51 +0000)
        Reviewed by Nikolas Zimmermann.

        SVGAnimatedLengthListAnimator does not take additive="sum" into accout
        https://bugs.webkit.org/show_bug.cgi?id=63705

        Added support for additive animations to SVGAnimatedLengthListAnimator. Don't clear the animatedList if not
        necessary.

        SVGLength unit gets animated as well now. We used to take the unit of 'from' all the time.

        Tests: svg/animations/svglength-animation-unitType.html
               svg/animations/svglengthlist-animation-5.html

        * svg/SVGAnimatedLength.cpp:
        (WebCore::SVGAnimatedLengthAnimator::calculateAnimatedValue): Code clean-up and support for unit animation.
        * svg/SVGAnimatedLengthList.cpp: Add support for additive animations.
        (WebCore::SVGAnimatedLengthListAnimator::calculateAnimatedValue):
        * svg/SVGLength.cpp:
        (WebCore::SVGLength::SVGLength):
        (WebCore::SVGLength::setValue): New setValue that gets the LengthType and UnitType as argument for supporting animations of units as well.
        * svg/SVGLength.h:
2011-07-01  Dirk Schulze  <krit@webkit.org>

        Reviewed by Nikolas Zimmermann.

        SVGAnimatedLengthListAnimator does not take additive="sum" into accout
        https://bugs.webkit.org/show_bug.cgi?id=63705

        Tests additive animations for SVGLengthLists as well as unit animations on SVGLength.

        * svg/animations/script-tests/svglength-animation-unitType.js: Added.
        (sample1):
        (sample2):
        (sample3):
        (executeTest):
        * svg/animations/script-tests/svglengthlist-animation-5.js: Added.
        (sample1):
        (sample2):
        (sample3):
        (executeTest):
        * svg/animations/svglength-animation-unitType-expected.txt: Added.
        * svg/animations/svglength-animation-unitType.html: Added.
        * svg/animations/svglengthlist-animation-5-expected.txt: Added.
        * svg/animations/svglengthlist-animation-5.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@90219 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/wk2/Skipped
LayoutTests/svg/animations/script-tests/svglength-animation-unitType.js [new file with mode: 0644]
LayoutTests/svg/animations/script-tests/svglengthlist-animation-5.js [new file with mode: 0644]
LayoutTests/svg/animations/svglength-animation-unitType-expected.txt [new file with mode: 0644]
LayoutTests/svg/animations/svglength-animation-unitType.html [new file with mode: 0644]
LayoutTests/svg/animations/svglengthlist-animation-5-expected.txt [new file with mode: 0644]
LayoutTests/svg/animations/svglengthlist-animation-5.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/svg/SVGAnimatedLength.cpp
Source/WebCore/svg/SVGAnimatedLengthList.cpp
Source/WebCore/svg/SVGLength.cpp
Source/WebCore/svg/SVGLength.h

index f0b8c9c..690b31e 100644 (file)
@@ -2,6 +2,30 @@
 
         Reviewed by Nikolas Zimmermann.
 
+        SVGAnimatedLengthListAnimator does not take additive="sum" into accout
+        https://bugs.webkit.org/show_bug.cgi?id=63705
+
+        Tests additive animations for SVGLengthLists as well as unit animations on SVGLength.
+
+        * svg/animations/script-tests/svglength-animation-unitType.js: Added.
+        (sample1):
+        (sample2):
+        (sample3):
+        (executeTest):
+        * svg/animations/script-tests/svglengthlist-animation-5.js: Added.
+        (sample1):
+        (sample2):
+        (sample3):
+        (executeTest):
+        * svg/animations/svglength-animation-unitType-expected.txt: Added.
+        * svg/animations/svglength-animation-unitType.html: Added.
+        * svg/animations/svglengthlist-animation-5-expected.txt: Added.
+        * svg/animations/svglengthlist-animation-5.html: Added.
+
+2011-07-01  Dirk Schulze  <krit@webkit.org>
+
+        Reviewed by Nikolas Zimmermann.
+
         SVGAnimatedType should support SVGAnimatedInteger animation
         https://bugs.webkit.org/show_bug.cgi?id=63789
         
index d6d6a22..06cb462 100644 (file)
@@ -472,11 +472,13 @@ svg/animations/svglength-animation-px-to-pc.html
 svg/animations/svglength-animation-px-to-percentage.html
 svg/animations/svglength-animation-px-to-pt.html
 svg/animations/svglength-animation-px-to-px.html
+svg/animations/svglength-animation-unitType.html
 svg/animations/svglength-animation-values.html
 svg/animations/svglengthlist-animation-1.html
 svg/animations/svglengthlist-animation-2.html
 svg/animations/svglengthlist-animation-3.html
 svg/animations/svglengthlist-animation-4.html
+svg/animations/svglengthlist-animation-5.html
 svg/animations/svgnumber-animation-1.html
 svg/animations/svgnumber-animation-2.html
 svg/animations/svgnumber-animation-3.html
diff --git a/LayoutTests/svg/animations/script-tests/svglength-animation-unitType.js b/LayoutTests/svg/animations/script-tests/svglength-animation-unitType.js
new file mode 100644 (file)
index 0000000..eda4442
--- /dev/null
@@ -0,0 +1,51 @@
+description("Test change of unit type for SVGLength animation.");
+createSVGTestCase();
+
+// Setup test document
+var rect = createSVGElement("rect");
+rect.setAttribute("id", "rect");
+rect.setAttribute("x", "0");
+rect.setAttribute("width", "100");
+rect.setAttribute("height", "100");
+rect.setAttribute("fill", "green");
+rect.setAttribute("onclick", "executeTest()");
+
+var animate = createSVGElement("animate");
+animate.setAttribute("id", "animation");
+animate.setAttribute("attributeName", "width");
+animate.setAttribute("begin", "click");
+animate.setAttribute("dur", "4s");
+animate.setAttribute("from", "100");
+animate.setAttribute("to", "200px");
+rect.appendChild(animate);
+rootSVGElement.appendChild(rect);
+
+// Setup animation test
+function sample1() {
+    // Check initial/end conditions
+    shouldBe("rect.width.animVal.unitType", "SVGLength.SVG_LENGTHTYPE_NUMBER");
+}
+
+function sample2() {
+    shouldBe("rect.width.animVal.unitType", "SVGLength.SVG_LENGTHTYPE_NUMBER");
+}
+
+function sample3() {
+    shouldBe("rect.width.animVal.unitType", "SVGLength.SVG_LENGTHTYPE_PX");
+}
+
+function executeTest() {
+    const expectedValues = [
+        // [animationId, time, elementId, sampleCallback]
+        ["animation", 0.0,    "rect", sample1],
+        ["animation", 1.5,    "rect", sample2],
+        ["animation", 2.5,    "rect", sample3],
+        ["animation", 4.0 ,   "rect", sample1]
+    ];
+
+    runAnimationTest(expectedValues);
+}
+
+// Begin test async
+window.setTimeout("triggerUpdate(50, 30)", 0);
+var successfullyParsed = true;
diff --git a/LayoutTests/svg/animations/script-tests/svglengthlist-animation-5.js b/LayoutTests/svg/animations/script-tests/svglengthlist-animation-5.js
new file mode 100644 (file)
index 0000000..fb616ac
--- /dev/null
@@ -0,0 +1,59 @@
+description("Test additive='sum' animation of SVGLengthList.");
+createSVGTestCase();
+
+// Setup test document
+var text = createSVGElement("text");
+text.setAttribute("id", "text");
+text.textContent = "ABCD";
+text.setAttribute("x", "50 60 70 80");
+text.setAttribute("y", "50");
+text.setAttribute("onclick", "executeTest()");
+rootSVGElement.appendChild(text);
+
+var animate = createSVGElement("animate");
+animate.setAttribute("id", "animation");
+animate.setAttribute("attributeName", "x");
+animate.setAttribute("begin", "click");
+animate.setAttribute("dur", "4s");
+animate.setAttribute("additive", "sum");
+animate.setAttribute("from", "0 0 0 0");
+animate.setAttribute("to", "20 20 20 20");
+text.appendChild(animate);
+
+// Setup animation test
+function sample1() {
+       shouldBe("text.x.animVal.getItem(0).value", "50");
+       shouldBe("text.x.animVal.getItem(1).value", "60");
+       shouldBe("text.x.animVal.getItem(2).value", "70");
+       shouldBe("text.x.animVal.getItem(3).value", "80");
+}
+
+function sample2() {
+       shouldBe("text.x.animVal.getItem(0).value", "60");
+       shouldBe("text.x.animVal.getItem(1).value", "70");
+       shouldBe("text.x.animVal.getItem(2).value", "80");
+       shouldBe("text.x.animVal.getItem(3).value", "90");
+}
+
+function sample3() {
+       shouldBeCloseEnough("text.x.animVal.getItem(0).value", "70", 0.01);
+       shouldBeCloseEnough("text.x.animVal.getItem(1).value", "80", 0.01);
+       shouldBeCloseEnough("text.x.animVal.getItem(2).value", "90", 0.01);
+       shouldBeCloseEnough("text.x.animVal.getItem(3).value", "100", 0.01);
+}
+
+function executeTest() {
+    const expectedValues = [
+        // [animationId, time, elementId, sampleCallback]
+        ["animation", 0.0,    "text", sample1],
+        ["animation", 2.0,    "text", sample2],
+        ["animation", 3.9999, "text", sample3],
+        ["animation", 4.0 ,   "text", sample1]
+    ];
+
+    runAnimationTest(expectedValues);
+}
+
+// Begin test async
+window.setTimeout("triggerUpdate(51, 49)", 0);
+var successfullyParsed = true;
diff --git a/LayoutTests/svg/animations/svglength-animation-unitType-expected.txt b/LayoutTests/svg/animations/svglength-animation-unitType-expected.txt
new file mode 100644 (file)
index 0000000..6c2ea1f
--- /dev/null
@@ -0,0 +1,15 @@
+SVG 1.1 dynamic animation tests
+
+Test change of unit type for SVGLength animation.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS rect.width.animVal.unitType is SVGLength.SVG_LENGTHTYPE_NUMBER
+PASS rect.width.animVal.unitType is SVGLength.SVG_LENGTHTYPE_NUMBER
+PASS rect.width.animVal.unitType is SVGLength.SVG_LENGTHTYPE_PX
+PASS rect.width.animVal.unitType is SVGLength.SVG_LENGTHTYPE_NUMBER
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/svg/animations/svglength-animation-unitType.html b/LayoutTests/svg/animations/svglength-animation-unitType.html
new file mode 100644 (file)
index 0000000..603f356
--- /dev/null
@@ -0,0 +1,15 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+<script src="../dynamic-updates/resources/SVGTestCase.js"></script>
+<script src="resources/SVGAnimationTestCase.js"></script>
+</head>
+<body>
+<h1>SVG 1.1 dynamic animation tests</h1>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/svglength-animation-unitType.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/svg/animations/svglengthlist-animation-5-expected.txt b/LayoutTests/svg/animations/svglengthlist-animation-5-expected.txt
new file mode 100644 (file)
index 0000000..43278b7
--- /dev/null
@@ -0,0 +1,28 @@
+SVG 1.1 dynamic animation tests
+
+ABCD
+Test additive='sum' animation of SVGLengthList.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS text.x.animVal.getItem(0).value is 50
+PASS text.x.animVal.getItem(1).value is 60
+PASS text.x.animVal.getItem(2).value is 70
+PASS text.x.animVal.getItem(3).value is 80
+PASS text.x.animVal.getItem(0).value is 60
+PASS text.x.animVal.getItem(1).value is 70
+PASS text.x.animVal.getItem(2).value is 80
+PASS text.x.animVal.getItem(3).value is 90
+PASS text.x.animVal.getItem(0).value is 70
+PASS text.x.animVal.getItem(1).value is 80
+PASS text.x.animVal.getItem(2).value is 90
+PASS text.x.animVal.getItem(3).value is 100
+PASS text.x.animVal.getItem(0).value is 50
+PASS text.x.animVal.getItem(1).value is 60
+PASS text.x.animVal.getItem(2).value is 70
+PASS text.x.animVal.getItem(3).value is 80
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/svg/animations/svglengthlist-animation-5.html b/LayoutTests/svg/animations/svglengthlist-animation-5.html
new file mode 100644 (file)
index 0000000..f0dacb1
--- /dev/null
@@ -0,0 +1,15 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+<script src="../dynamic-updates/resources/SVGTestCase.js"></script>
+<script src="resources/SVGAnimationTestCase.js"></script>
+</head>
+<body>
+<h1>SVG 1.1 dynamic animation tests</h1>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/svglengthlist-animation-5.js"></script>
+</body>
+</html>
index a7a66ab..193df0d 100644 (file)
@@ -2,6 +2,30 @@
 
         Reviewed by Nikolas Zimmermann.
 
+        SVGAnimatedLengthListAnimator does not take additive="sum" into accout
+        https://bugs.webkit.org/show_bug.cgi?id=63705
+
+        Added support for additive animations to SVGAnimatedLengthListAnimator. Don't clear the animatedList if not
+        necessary.
+
+        SVGLength unit gets animated as well now. We used to take the unit of 'from' all the time.
+
+        Tests: svg/animations/svglength-animation-unitType.html
+               svg/animations/svglengthlist-animation-5.html
+
+        * svg/SVGAnimatedLength.cpp:
+        (WebCore::SVGAnimatedLengthAnimator::calculateAnimatedValue): Code clean-up and support for unit animation.
+        * svg/SVGAnimatedLengthList.cpp: Add support for additive animations.
+        (WebCore::SVGAnimatedLengthListAnimator::calculateAnimatedValue):
+        * svg/SVGLength.cpp:
+        (WebCore::SVGLength::SVGLength):
+        (WebCore::SVGLength::setValue): New setValue that gets the LengthType and UnitType as argument for supporting animations of units as well.
+        * svg/SVGLength.h:
+
+2011-07-01  Dirk Schulze  <krit@webkit.org>
+
+        Reviewed by Nikolas Zimmermann.
+
         SVGAnimatedType should support SVGAnimatedInteger animation
         https://bugs.webkit.org/show_bug.cgi?id=63789
         
index c2f0d68..3048abf 100644 (file)
@@ -23,6 +23,7 @@
 #include "SVGAnimatedLength.h"
 
 #include "SVGAnimateElement.h"
+#include "SVGAnimatedNumber.h"
 
 namespace WebCore {
 
@@ -79,46 +80,35 @@ void SVGAnimatedLengthAnimator::calculateAnimatedValue(float percentage, unsigne
 {
     ASSERT(m_animationElement);
     ASSERT(m_contextElement);
+
     SVGAnimateElement* animationElement = static_cast<SVGAnimateElement*>(m_animationElement);
-    
     AnimationMode animationMode = animationElement->animationMode();
+
     // To animation uses contributions from the lower priority animations as the base value.
-    // FIXME: Avoid string parsing.
+    SVGLength& animatedSVGLength = animated->length();
+    SVGLength& fromSVGLength = from->length();
     if (animationMode == ToAnimation)
-        from = constructFromString(animated->length().valueAsString());
+        fromSVGLength = animatedSVGLength;
     
     // Replace 'inherit' by their computed property values.
-    float number;
-    float fromLength = from->length().value(m_contextElement);
-    float toLength = to->length().value(m_contextElement);
-    
+    SVGLength& toSVGLength = to->length();
     if (animationElement->fromPropertyValueType() == InheritValue) {
         String fromLengthString;
         animationElement->adjustForInheritance(m_contextElement, animationElement->attributeName(), fromLengthString);
-        fromLength = sharedSVGLength(m_lengthMode, fromLengthString).value(m_contextElement);
+        fromSVGLength = sharedSVGLength(m_lengthMode, fromLengthString);
     }
     if (animationElement->toPropertyValueType() == InheritValue) {
         String toLengthString;
         animationElement->adjustForInheritance(m_contextElement, animationElement->attributeName(), toLengthString);
-        toLength = sharedSVGLength(m_lengthMode, toLengthString).value(m_contextElement); 
+        toSVGLength = sharedSVGLength(m_lengthMode, toLengthString); 
     }
     
-    if (animationElement->calcMode() == CalcModeDiscrete)
-        number = percentage < 0.5f ? fromLength : toLength;
-    else
-        number = (toLength - fromLength) * percentage + fromLength;
-    
-    // FIXME: This is not correct for values animation.
-    if (animationElement->isAccumulated() && repeatCount)
-        number += toLength * repeatCount;
+    float result = animatedSVGLength.value(m_contextElement);
+    SVGLengthType unitType = percentage < 0.5 ? fromSVGLength.unitType() : toSVGLength.unitType();
+    SVGAnimatedNumberAnimator::calculateAnimatedNumber(animationElement, percentage, repeatCount, result, fromSVGLength.value(m_contextElement), toSVGLength.value(m_contextElement));
+
     ExceptionCode ec = 0;
-    SVGLength& animatedSVGLength = animated->length();
-    if (animationElement->isAdditive() && animationMode != ToAnimation) {
-        float animatedSVGLengthValue = animatedSVGLength.value(m_contextElement);
-        animatedSVGLengthValue += number;
-        animatedSVGLength.setValue(animatedSVGLengthValue, m_contextElement, ec);
-    } else
-        animatedSVGLength.setValue(number, m_contextElement, ec);
+    animatedSVGLength.setValue(m_contextElement, result, m_lengthMode, unitType, ec);
     ASSERT(!ec);
 }
 
index 7c1de89..8dae3ff 100644 (file)
@@ -111,12 +111,20 @@ void SVGAnimatedLengthListAnimator::calculateAnimatedValue(float percentage, uns
         return;
     }
     
-    animatedLengthList.clear();
+    bool animatedListSizeEqual = itemsCount == animatedLengthList.size();
+    if (!animatedListSizeEqual)
+        animatedLengthList.clear();
+    ExceptionCode ec = 0;
     for (unsigned i = 0; i < itemsCount; ++i) {
-        float result = 0;
+        float result = animatedListSizeEqual ? animatedLengthList[i].value(m_contextElement) : 0;
         SVGLengthType unitType = percentage < 0.5 ? fromLengthList[i].unitType() : toLengthList[i].unitType();
         SVGAnimatedNumberAnimator::calculateAnimatedNumber(animationElement, percentage, repeatCount, result, fromLengthList[i].value(m_contextElement), toLengthList[i].value(m_contextElement));
-        animatedLengthList.append(SVGLength(m_contextElement, result, m_lengthMode, unitType));
+        if (!animatedListSizeEqual)
+            animatedLengthList.append(SVGLength(m_contextElement, result, m_lengthMode, unitType));
+        else {
+            animatedLengthList[i].setValue(m_contextElement, result, m_lengthMode, unitType, ec);
+            ASSERT(!ec);
+        }
     }
 }
 
index 1baa386..9dbe997 100644 (file)
@@ -141,6 +141,12 @@ SVGLength::SVGLength(const SVGElement* context, float value, SVGLengthMode mode,
     ASSERT(!ec);
 }
 
+SVGLength::SVGLength(const SVGLength& other)
+    : m_valueInSpecifiedUnits(other.m_valueInSpecifiedUnits)
+    , m_unit(other.m_unit)
+{
+}
+
 void SVGLength::setValueAsString(const String& valueAsString, SVGLengthMode mode, ExceptionCode& ec)
 {
     m_valueInSpecifiedUnits = 0;
@@ -148,12 +154,6 @@ void SVGLength::setValueAsString(const String& valueAsString, SVGLengthMode mode
     setValueAsString(valueAsString, ec);
 }
 
-SVGLength::SVGLength(const SVGLength& other)
-    : m_valueInSpecifiedUnits(other.m_valueInSpecifiedUnits)
-    , m_unit(other.m_unit)
-{
-}
-
 bool SVGLength::operator==(const SVGLength& other) const
 {
     return m_unit == other.m_unit
@@ -208,6 +208,12 @@ float SVGLength::value(const SVGElement* context, ExceptionCode& ec) const
     return 0;
 }
 
+void SVGLength::setValue(const SVGElement* context, float value, SVGLengthMode mode, SVGLengthType unitType, ExceptionCode& ec)
+{
+    m_unit = storeUnit(mode, unitType);
+    setValue(value, context, ec);
+}
+
 void SVGLength::setValue(float value, const SVGElement* context, ExceptionCode& ec)
 {
     switch (extractType(m_unit)) {
index 8838254..cbefaa0 100644 (file)
@@ -81,6 +81,7 @@ public:
     float value(const SVGElement* context) const;
     float value(const SVGElement* context, ExceptionCode&) const;
     void setValue(float, const SVGElement* context, ExceptionCode&);
+    void setValue(const SVGElement* context, float, SVGLengthMode, SVGLengthType, ExceptionCode&);
 
     float valueInSpecifiedUnits() const { return m_valueInSpecifiedUnits; }
     void setValueInSpecifiedUnits(float value) { m_valueInSpecifiedUnits = value; }