2011-06-21 Dirk Schulze <krit@webkit.org>
authorkrit@webkit.org <krit@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Jun 2011 18:14:12 +0000 (18:14 +0000)
committerkrit@webkit.org <krit@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Jun 2011 18:14:12 +0000 (18:14 +0000)
        Reviewed by Rob Buis.

        SVG no fallback to discrete animation on attribute 'values' for SVGString
        https://bugs.webkit.org/show_bug.cgi?id=57085

        Check for AnimatedString, AnimatedBoolean and AnimatedEnumeration on 'values' calculation.
        If the property type matches one of the above values, fallback to discrete animation.

        The patch also changes behavior for String animation. The animation code doesn't handle inheritance
        for strings anymore. This is done by the CSS parser itself now, we just need to handle inheritance
        on animations that interpolate between two values like for calcMode="linear".

        Test: svg/animations/svgstring-animation-fallback-to-discrete.html

        * svg/SVGAnimateElement.cpp:
        (WebCore::SVGAnimateElement::calculateAnimatedValue):
        * svg/SVGAnimateElement.h:
        * svg/SVGAnimationElement.cpp:
        (WebCore::SVGAnimationElement::currentValuesForValuesAnimation):
2011-06-21  Dirk Schulze  <krit@webkit.org>

        Reviewed by Rob Buis.

        SVG no fallback to discrete animation on attribute 'values' for SVGString
        https://bugs.webkit.org/show_bug.cgi?id=57085

        Added new test to check fallback to discrete animations on string values. One
        test needed rebaseline. Even if we do not pass the test it is still a progression.

        * platform/mac/svg/W3C-SVG-1.1/animate-elem-31-t-expected.png:
        * platform/mac/svg/W3C-SVG-1.1/animate-elem-31-t-expected.txt:
        * svg/animations/script-tests/svgstring-animation-fallback-to-discrete.js: Added.
        (sample1):
        (sample2):
        (sample3):
        (executeTest):
        * svg/animations/svgstring-animation-fallback-to-discrete-expected.txt: Added.
        * svg/animations/svgstring-animation-fallback-to-discrete.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/platform/mac/svg/W3C-SVG-1.1/animate-elem-31-t-expected.png
LayoutTests/platform/mac/svg/W3C-SVG-1.1/animate-elem-31-t-expected.txt
LayoutTests/svg/animations/script-tests/svgstring-animation-fallback-to-discrete.js [new file with mode: 0644]
LayoutTests/svg/animations/svgstring-animation-fallback-to-discrete-expected.txt [new file with mode: 0644]
LayoutTests/svg/animations/svgstring-animation-fallback-to-discrete.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/svg/SVGAnimateElement.cpp
Source/WebCore/svg/SVGAnimateElement.h
Source/WebCore/svg/SVGAnimationElement.cpp

index c0d03a1..ffdbf0c 100644 (file)
@@ -1,3 +1,23 @@
+2011-06-21  Dirk Schulze  <krit@webkit.org>
+
+        Reviewed by Rob Buis.
+
+        SVG no fallback to discrete animation on attribute 'values' for SVGString
+        https://bugs.webkit.org/show_bug.cgi?id=57085
+        
+        Added new test to check fallback to discrete animations on string values. One
+        test needed rebaseline. Even if we do not pass the test it is still a progression. 
+
+        * platform/mac/svg/W3C-SVG-1.1/animate-elem-31-t-expected.png:
+        * platform/mac/svg/W3C-SVG-1.1/animate-elem-31-t-expected.txt:
+        * svg/animations/script-tests/svgstring-animation-fallback-to-discrete.js: Added.
+        (sample1):
+        (sample2):
+        (sample3):
+        (executeTest):
+        * svg/animations/svgstring-animation-fallback-to-discrete-expected.txt: Added.
+        * svg/animations/svgstring-animation-fallback-to-discrete.html: Added.
+
 2011-06-21  Matthew Delaney  <mdelaney@apple.com>
 
         Reviewed by Simon Fraser.
index 0040cba..ab66dd2 100644 (file)
Binary files a/LayoutTests/platform/mac/svg/W3C-SVG-1.1/animate-elem-31-t-expected.png and b/LayoutTests/platform/mac/svg/W3C-SVG-1.1/animate-elem-31-t-expected.png differ
index a913c3e..49e6623 100644 (file)
@@ -19,7 +19,8 @@ layer at (0,0) size 480x360
         RenderSVGHiddenContainer {g} at (0,0) size 0x0
           RenderSVGPath {circle} at (235,10) size 70x70 [stroke={[type=SOLID] [color=#000000] [stroke width=5.00]}] [fill={[type=SOLID] [color=#FFFF00]}] [cx=180.00] [cy=30.00] [r=20.00]
       RenderSVGPath {circle} at (235,115) size 70x70 [stroke={[type=SOLID] [color=#000000] [stroke width=5.00]}] [fill={[type=SOLID] [color=#FFFF00]}] [cx=180.00] [cy=100.00] [r=20.00]
-      RenderSVGContainer {g} at (0,0) size 0x0
+      RenderSVGContainer {g} at (310,10) size 70x70
+        RenderSVGPath {circle} at (310,10) size 70x70 [stroke={[type=SOLID] [color=#000000] [stroke width=5.00]}] [fill={[type=SOLID] [color=#00FFFF]}] [cx=230.00] [cy=30.00] [r=20.00]
       RenderSVGContainer {g} at (310,115) size 70x70
         RenderSVGPath {circle} at (310,115) size 70x70 [stroke={[type=SOLID] [color=#000000] [stroke width=5.00]}] [fill={[type=SOLID] [color=#00FFFF]}] [cx=230.00] [cy=100.00] [r=20.00]
     RenderSVGText {text} at (385,26) size 45x18 contains 1 chunk(s)
diff --git a/LayoutTests/svg/animations/script-tests/svgstring-animation-fallback-to-discrete.js b/LayoutTests/svg/animations/script-tests/svgstring-animation-fallback-to-discrete.js
new file mode 100644 (file)
index 0000000..801ed89
--- /dev/null
@@ -0,0 +1,52 @@
+description("Tests fallback to calcMode='discrete' on animation of SVGString with 'values'.");
+createSVGTestCase();
+
+// Setup test document
+var rect = createSVGElement("rect");
+rect.setAttribute("id", "rect");
+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", "visibility");
+animate.setAttribute("begin", "click");
+animate.setAttribute("dur", "6s");
+animate.setAttribute("calcMode", "linear");
+animate.setAttribute("values", "visible ; hidden ; visible");
+rect.appendChild(animate);
+rootSVGElement.appendChild(rect);
+
+var computedStyle = rect.ownerDocument.defaultView.getComputedStyle(rect);
+
+// Setup animation test
+function sample1() {
+    // Check initial/end conditions
+    shouldBe("rect.style.visibility", "'visible'");
+}
+
+function sample2() {
+    shouldBe("rect.style.visibility", "'hidden'");
+}
+
+function sample3() {
+    shouldBe("rect.style.visibility", "'visible'");
+}
+
+function executeTest() {
+    const expectedValues = [
+        // [animationId, time, elementId, sampleCallback]
+        ["animation", 1.9999, "rect", sample1],
+        ["animation", 2,      "rect", sample2],
+        ["animation", 3.9999, "rect", sample3],
+        ["animation", 4,      "rect", sample1]
+    ];
+
+    runAnimationTest(expectedValues);
+}
+
+// Begin test async
+window.setTimeout("triggerUpdate(50, 30)", 0);
+var successfullyParsed = true;
diff --git a/LayoutTests/svg/animations/svgstring-animation-fallback-to-discrete-expected.txt b/LayoutTests/svg/animations/svgstring-animation-fallback-to-discrete-expected.txt
new file mode 100644 (file)
index 0000000..37943ba
--- /dev/null
@@ -0,0 +1,15 @@
+SVG 1.1 dynamic animation tests
+
+Tests fallback to calcMode='discrete' on animation of SVGString with 'values'.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS rect.style.visibility is 'visible'
+PASS rect.style.visibility is 'hidden'
+FAIL rect.style.visibility should be visible. Was hidden.
+PASS rect.style.visibility is 'visible'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/svg/animations/svgstring-animation-fallback-to-discrete.html b/LayoutTests/svg/animations/svgstring-animation-fallback-to-discrete.html
new file mode 100644 (file)
index 0000000..1759414
--- /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/svgstring-animation-fallback-to-discrete.js"></script>
+</body>
+</html>
index addf8f1..21d4364 100644 (file)
@@ -1,3 +1,25 @@
+2011-06-21  Dirk Schulze  <krit@webkit.org>
+
+        Reviewed by Rob Buis.
+
+        SVG no fallback to discrete animation on attribute 'values' for SVGString
+        https://bugs.webkit.org/show_bug.cgi?id=57085
+
+        Check for AnimatedString, AnimatedBoolean and AnimatedEnumeration on 'values' calculation.
+        If the property type matches one of the above values, fallback to discrete animation.
+
+        The patch also changes behavior for String animation. The animation code doesn't handle inheritance
+        for strings anymore. This is done by the CSS parser itself now, we just need to handle inheritance
+        on animations that interpolate between two values like for calcMode="linear".
+
+        Test: svg/animations/svgstring-animation-fallback-to-discrete.html
+
+        * svg/SVGAnimateElement.cpp:
+        (WebCore::SVGAnimateElement::calculateAnimatedValue):
+        * svg/SVGAnimateElement.h:
+        * svg/SVGAnimationElement.cpp:
+        (WebCore::SVGAnimationElement::currentValuesForValuesAnimation):
+
 2011-06-21  Cary Clark  <caryclark@google.com>
 
         Reviewed by Eric Seidel.
index 468f67d..a033dbe 100644 (file)
@@ -262,12 +262,6 @@ void SVGAnimateElement::calculateAnimatedValue(float percentage, unsigned repeat
         break;
     }
     ASSERT(animationMode == FromToAnimation || animationMode == ToAnimation || animationMode == ValuesAnimation);
-    // Replace 'currentColor' / 'inherit' by their computed property values.
-    if (m_fromPropertyValueType == InheritValue)
-        adjustForInheritance(targetElement, attributeName(), m_fromString);
-    if (m_toPropertyValueType == InheritValue)
-        adjustForInheritance(targetElement, attributeName(), m_toString);
-
     if ((animationMode == FromToAnimation && percentage > 0.5f) || animationMode == ToAnimation || percentage == 1)
         results->m_animatedString = m_toString;
     else
index 02afff9..9f0e80d 100644 (file)
@@ -44,6 +44,8 @@ public:
     
     static void adjustForCurrentColor(SVGElement* targetElement, Color&);
     void adjustForInheritance(SVGElement* targetElement, const QualifiedName&, String& value);
+    
+    AnimatedAttributeType determineAnimatedAttributeType(SVGElement*) const;
 
 protected:
     SVGAnimateElement(const QualifiedName&, Document*);
@@ -57,7 +59,7 @@ protected:
 
 private:
     SVGAnimatedTypeAnimator* ensureAnimator();
-    
+
     // If we have 'currentColor' or 'inherit' as animation value, we need to grab the value during the animation
     // since the value can be animated itself.
     enum AnimatedPropertyValueType {
@@ -67,7 +69,6 @@ private:
     };
     
     virtual bool hasValidAttributeType() const;
-    AnimatedAttributeType determineAnimatedAttributeType(SVGElement*) const;
     AnimatedAttributeType m_animatedAttributeType;
 
     AnimatedPropertyValueType m_fromPropertyValueType;
index 76925c5..ad7a198 100644 (file)
@@ -481,6 +481,16 @@ void SVGAnimationElement::currentValuesForValuesAnimation(float percent, float&
     ASSERT(valuesCount > 1);
     
     CalcMode calcMode = this->calcMode();
+    if (hasTagName(SVGNames::animateTag) || hasTagName(SVGNames::animateColorTag)) {
+        const SVGAnimateElement* animateElement = static_cast<const SVGAnimateElement*>(this);
+        AnimatedAttributeType attributeType = animateElement->determineAnimatedAttributeType(targetElement());
+        // Fall back to discrete animations for Strings.
+        if (attributeType == AnimatedBoolean
+            || attributeType == AnimatedEnumeration
+            || attributeType == AnimatedPreserveAspectRatio
+            || attributeType == AnimatedString)
+            calcMode = CalcModeDiscrete;
+    }
     if (!m_keyPoints.isEmpty() && calcMode != CalcModePaced)
         return currentValuesFromKeyPoints(percent, effectivePercent, from, to);