SVGAnimation does not support 'values' for from-to animations
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 24 Sep 2011 08:17:38 +0000 (08:17 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 24 Sep 2011 08:17:38 +0000 (08:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=64859

Patch by Young Han Lee <joybro@company100.net> on 2011-09-24
Reviewed by Dirk Schulze.

If from-to animation have discrete calc-mode and have a 'keyTimes' list, values of
the keyTimes indicate the begin and the end of the animation respectively.[1][2]

When keyTimes is given, calculate the progress percentage of the animation with it
even for from-to animation.

[1] http://www.w3.org/TR/SVG/animate.html#ValueAttributes
[2] http://www.w3.org/TR/2001/REC-smil-animation-20010904/#AnimFuncValues

Source/WebCore:

Test: svg/animations/animate-from-to-keyTimes.html

* svg/SVGAnimationElement.cpp:
(WebCore::SVGAnimationElement::calculatePercentForFromTo):
(WebCore::SVGAnimationElement::updateAnimation):
* svg/SVGAnimationElement.h:

LayoutTests:

* svg/animations/animate-from-to-keyTimes-expected.txt: Added.
* svg/animations/animate-from-to-keyTimes.html: Added.
* svg/animations/script-tests/animate-from-to-keyTimes.js: Added.
(sample1):
(sample2):
(executeTest):

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

LayoutTests/ChangeLog
LayoutTests/svg/animations/animate-from-to-keyTimes-expected.txt [new file with mode: 0644]
LayoutTests/svg/animations/animate-from-to-keyTimes.html [new file with mode: 0644]
LayoutTests/svg/animations/script-tests/animate-from-to-keyTimes.js [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/svg/SVGAnimationElement.cpp
Source/WebCore/svg/SVGAnimationElement.h

index 0d24889..c31ec1f 100644 (file)
@@ -1,3 +1,26 @@
+2011-09-24  Young Han Lee  <joybro@company100.net>
+
+        SVGAnimation does not support 'values' for from-to animations
+        https://bugs.webkit.org/show_bug.cgi?id=64859
+
+        Reviewed by Dirk Schulze.
+
+        If from-to animation have discrete calc-mode and have a 'keyTimes' list, values of
+        the keyTimes indicate the begin and the end of the animation respectively.[1][2]
+
+        When keyTimes is given, calculate the progress percentage of the animation with it
+        even for from-to animation.
+
+        [1] http://www.w3.org/TR/SVG/animate.html#ValueAttributes
+        [2] http://www.w3.org/TR/2001/REC-smil-animation-20010904/#AnimFuncValues
+
+        * svg/animations/animate-from-to-keyTimes-expected.txt: Added.
+        * svg/animations/animate-from-to-keyTimes.html: Added.
+        * svg/animations/script-tests/animate-from-to-keyTimes.js: Added.
+        (sample1):
+        (sample2):
+        (executeTest):
+
 2011-09-23  Chris Fleizach  <cfleizach@apple.com>
 
         WebKit does not expose AXPlaceholder value on password fields
diff --git a/LayoutTests/svg/animations/animate-from-to-keyTimes-expected.txt b/LayoutTests/svg/animations/animate-from-to-keyTimes-expected.txt
new file mode 100644 (file)
index 0000000..d0bb399
--- /dev/null
@@ -0,0 +1,9 @@
+SVG 1.1 dynamic animation tests
+
+PASS rect.x.baseVal.value is 100
+PASS rect.x.baseVal.value is 200
+PASS rect.x.baseVal.value is 200
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/svg/animations/animate-from-to-keyTimes.html b/LayoutTests/svg/animations/animate-from-to-keyTimes.html
new file mode 100644 (file)
index 0000000..ac7f552
--- /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/animate-from-to-keyTimes.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/svg/animations/script-tests/animate-from-to-keyTimes.js b/LayoutTests/svg/animations/script-tests/animate-from-to-keyTimes.js
new file mode 100644 (file)
index 0000000..5883314
--- /dev/null
@@ -0,0 +1,45 @@
+createSVGTestCase();
+
+// Setup test document
+var rect = createSVGElement("rect");
+rect.setAttribute("id", "rect");
+rect.setAttribute("x", "100");
+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", "x");
+animate.setAttribute("to", "200");
+animate.setAttribute("dur", "4s");
+animate.setAttribute("keyTimes", "0;0.25");
+animate.setAttribute("calcMode", "discrete");
+animate.setAttribute("fill", "freeze");
+rect.appendChild(animate);
+rootSVGElement.appendChild(rect);
+
+// Setup animation test
+function sample1() {
+    shouldBe("rect.x.baseVal.value", "100");
+}
+
+function sample2() {
+    shouldBe("rect.x.baseVal.value", "200");
+}
+
+function executeTest() {
+    const expectedValues = [
+        // [animationId, time, elementId, sampleCallback]
+        ["animation", 0.5,    "rect", sample1],
+        ["animation", 1.5,    "rect", sample2],
+        ["animation", 2.5,    "rect", sample2]
+    ];
+
+    runAnimationTest(expectedValues);
+}
+
+// Begin test async
+window.setTimeout("triggerUpdate(150, 30)", 0);
+var successfullyParsed = true;
index f5aa8ea..b0dd04b 100644 (file)
@@ -1,3 +1,26 @@
+2011-09-24  Young Han Lee  <joybro@company100.net>
+
+        SVGAnimation does not support 'values' for from-to animations
+        https://bugs.webkit.org/show_bug.cgi?id=64859
+
+        Reviewed by Dirk Schulze.
+
+        If from-to animation have discrete calc-mode and have a 'keyTimes' list, values of
+        the keyTimes indicate the begin and the end of the animation respectively.[1][2]
+
+        When keyTimes is given, calculate the progress percentage of the animation with it
+        even for from-to animation.
+
+        [1] http://www.w3.org/TR/SVG/animate.html#ValueAttributes
+        [2] http://www.w3.org/TR/2001/REC-smil-animation-20010904/#AnimFuncValues
+
+        Test: svg/animations/animate-from-to-keyTimes.html
+
+        * svg/SVGAnimationElement.cpp:
+        (WebCore::SVGAnimationElement::calculatePercentForFromTo):
+        (WebCore::SVGAnimationElement::updateAnimation):
+        * svg/SVGAnimationElement.h:
+
 2011-09-23  Chris Fleizach  <cfleizach@apple.com>
 
         WebKit does not expose AXPlaceholder value on password fields
index 50590af..39808b4 100644 (file)
@@ -461,6 +461,14 @@ float SVGAnimationElement::calculatePercentFromKeyPoints(float percent) const
     }
     return (toKeyPoint - fromKeyPoint) * keyPointPercent + fromKeyPoint;
 }
+
+float SVGAnimationElement::calculatePercentForFromTo(float percent) const
+{
+    if (calcMode() == CalcModeDiscrete && m_keyTimes.size() == 2)
+        return percent > m_keyTimes[1] ? 1 : 0;
+
+    return percent;
+}
     
 void SVGAnimationElement::currentValuesFromKeyPoints(float percent, float& effectivePercent, String& from, String& to) const
 {
@@ -608,6 +616,8 @@ void SVGAnimationElement::updateAnimation(float percent, unsigned repeat, SVGSMI
         effectivePercent = calculatePercentFromKeyPoints(percent);
     else if (m_keyPoints.isEmpty() && mode == CalcModeSpline && m_keyTimes.size() > 1)
         effectivePercent = calculatePercentForSpline(percent, calculateKeyTimesIndex(percent));
+    else if (animationMode() == FromToAnimation || animationMode() == ToAnimation)
+        effectivePercent = calculatePercentForFromTo(percent);
     else
         effectivePercent = percent;
 
index 87af9d0..2e109f0 100644 (file)
@@ -120,6 +120,7 @@ private:
     float calculatePercentFromKeyPoints(float percent) const;
     void currentValuesFromKeyPoints(float percent, float& effectivePercent, String& from, String& to) const;
     float calculatePercentForSpline(float percent, unsigned splineIndex) const;
+    float calculatePercentForFromTo(float percent) const;
     unsigned calculateKeyTimesIndex(float percent) const;
 
     BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGAnimationElement)