2011-06-19 Dirk Schulze <krit@webkit.org>
authorkrit@webkit.org <krit@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 19 Jun 2011 20:11:24 +0000 (20:11 +0000)
committerkrit@webkit.org <krit@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 19 Jun 2011 20:11:24 +0000 (20:11 +0000)
        Reviewed by Nikolas Zimmermann.

        SVGAnimatorFactory does not support SVGNumber
        https://bugs.webkit.org/show_bug.cgi?id=62938

        Follow up of "SVGAnimation should use direct unit animation for SVGLength": https://bugs.webkit.org/show_bug.cgi?id=61368
        This patch continues the conversion to the new concept of SVGAnimatorFactory with SVGNumber. With the new animator for the
        With the new animator for SVGNumber we also support the scientific notation, and everything else that's supported by
        the SVGNumber parsing, removing the SVGAnimate* specific number parsing functionality.

        Moving the content of SVGAnimatedType header into its own cpp.

        Changed behavior of parseNumberFromString(). It checks if the String simply consits of a number now. parseNumberFromString()
        is using genericParseNumber() for parsing numbers. But this method just stops at the first char that does not belong to a number and
        returns true. I added a check if the current char pointer is at the last char of the String and return false if not.

        Tests: svg/animations/svgnumber-animation-1.html
               svg/animations/svgnumber-animation-2.html
               svg/animations/svgnumber-animation-3.html

        * CMakeLists.txt: Added new files to build system.
        * GNUmakefile.list.am: Ditto.
        * WebCore.gypi: Ditto.
        * WebCore.pro: Ditto.
        * WebCore.xcodeproj/project.pbxproj: Ditto.
        * svg/SVGAllInOne.cpp: Ditto.
        * svg/SVGAnimateElement.cpp: Use SVGAnimatedNumberAnimator for animations of SVGNumbers.
        (WebCore::SVGAnimateElement::SVGAnimateElement):
        (WebCore::SVGAnimateElement::calculateAnimatedValue):
        (WebCore::SVGAnimateElement::calculateFromAndToValues):
        (WebCore::SVGAnimateElement::calculateFromAndByValues):
        (WebCore::SVGAnimateElement::resetToBaseValue):
        (WebCore::SVGAnimateElement::applyResultsToTarget):
        (WebCore::SVGAnimateElement::calculateDistance):
        * svg/SVGAnimateElement.h: Remove floats for value storage. This is done by SVGAnimatedTypes now.
        * svg/SVGAnimatedNumber.cpp: Added. Animator for SVGNumbers.
        (WebCore::SVGAnimatedNumberAnimator::SVGAnimatedNumberAnimator):
        (WebCore::SVGAnimatedNumberAnimator::constructFromString):
        (WebCore::SVGAnimatedNumberAnimator::calculateFromAndToValues):
        (WebCore::SVGAnimatedNumberAnimator::calculateFromAndByValues):
        (WebCore::SVGAnimatedNumberAnimator::calculateAnimatedValue):
        (WebCore::SVGAnimatedNumberAnimator::calculateDistance):
        * svg/SVGAnimatedNumber.h:
        (WebCore::SVGAnimatedNumberAnimator::~SVGAnimatedNumberAnimator):
        * svg/SVGAnimatedType.cpp: Added. Moved content from header to cpp.
        (WebCore::SVGAnimatedType::SVGAnimatedType):
        (WebCore::SVGAnimatedType::~SVGAnimatedType):
        (WebCore::SVGAnimatedType::createAngle):
        (WebCore::SVGAnimatedType::createLength):
        (WebCore::SVGAnimatedType::createNumber):
        (WebCore::SVGAnimatedType::angle):
        (WebCore::SVGAnimatedType::length):
        (WebCore::SVGAnimatedType::number):
        (WebCore::SVGAnimatedType::valueAsString):
        (WebCore::SVGAnimatedType::setValueAsString):
        * svg/SVGAnimatedType.h: Removed method create(). Allways call type specific create funtcions.
        * svg/SVGAnimatorFactory.h:
        (WebCore::SVGAnimatorFactory::create):
        * svg/SVGParserUtilities.cpp:
        (WebCore::parseNumberFromString): Check if String simply consits of a number. Return false otherwise.
2011-06-19  Dirk Schulze  <krit@webkit.org>

        Reviewed by Nikolas Zimmermann.

        SVGAnimatorFactory does not support SVGNumber
        https://bugs.webkit.org/show_bug.cgi?id=62938

        Added new tests to check behavior on SVGNumber animation.

        * svg/animations/script-tests/svgnumber-animation-1.js: Added.
        (sample1):
        (sample2):
        (sample3):
        (executeTest):
        * svg/animations/script-tests/svgnumber-animation-2.js: Added.
        (sample1):
        (sample2):
        (sample3):
        (executeTest):
        * svg/animations/script-tests/svgnumber-animation-3.js: Added.
        (sample1):
        (sample2):
        (sample3):
        (executeTest):
        * svg/animations/svgnumber-animation-1-expected.txt: Added.
        * svg/animations/svgnumber-animation-1.html: Added.
        * svg/animations/svgnumber-animation-2-expected.txt: Added.
        * svg/animations/svgnumber-animation-2.html: Added.
        * svg/animations/svgnumber-animation-3-expected.txt: Added.
        * svg/animations/svgnumber-animation-3.html: Added.

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

25 files changed:
LayoutTests/ChangeLog
LayoutTests/svg/animations/script-tests/svgnumber-animation-1.js [new file with mode: 0644]
LayoutTests/svg/animations/script-tests/svgnumber-animation-2.js [new file with mode: 0644]
LayoutTests/svg/animations/script-tests/svgnumber-animation-3.js [new file with mode: 0644]
LayoutTests/svg/animations/svgnumber-animation-1-expected.txt [new file with mode: 0644]
LayoutTests/svg/animations/svgnumber-animation-1.html [new file with mode: 0644]
LayoutTests/svg/animations/svgnumber-animation-2-expected.txt [new file with mode: 0644]
LayoutTests/svg/animations/svgnumber-animation-2.html [new file with mode: 0644]
LayoutTests/svg/animations/svgnumber-animation-3-expected.txt [new file with mode: 0644]
LayoutTests/svg/animations/svgnumber-animation-3.html [new file with mode: 0644]
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.pro
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/svg/SVGAllInOne.cpp
Source/WebCore/svg/SVGAnimateElement.cpp
Source/WebCore/svg/SVGAnimateElement.h
Source/WebCore/svg/SVGAnimatedNumber.cpp [new file with mode: 0644]
Source/WebCore/svg/SVGAnimatedNumber.h
Source/WebCore/svg/SVGAnimatedType.cpp [new file with mode: 0644]
Source/WebCore/svg/SVGAnimatedType.h
Source/WebCore/svg/SVGAnimatorFactory.h
Source/WebCore/svg/SVGParserUtilities.cpp

index dbc55aa..0a63516 100644 (file)
@@ -1,3 +1,34 @@
+2011-06-19  Dirk Schulze  <krit@webkit.org>
+
+        Reviewed by Nikolas Zimmermann.
+
+        SVGAnimatorFactory does not support SVGNumber
+        https://bugs.webkit.org/show_bug.cgi?id=62938
+        
+        Added new tests to check behavior on SVGNumber animation.
+
+        * svg/animations/script-tests/svgnumber-animation-1.js: Added.
+        (sample1):
+        (sample2):
+        (sample3):
+        (executeTest):
+        * svg/animations/script-tests/svgnumber-animation-2.js: Added.
+        (sample1):
+        (sample2):
+        (sample3):
+        (executeTest):
+        * svg/animations/script-tests/svgnumber-animation-3.js: Added.
+        (sample1):
+        (sample2):
+        (sample3):
+        (executeTest):
+        * svg/animations/svgnumber-animation-1-expected.txt: Added.
+        * svg/animations/svgnumber-animation-1.html: Added.
+        * svg/animations/svgnumber-animation-2-expected.txt: Added.
+        * svg/animations/svgnumber-animation-2.html: Added.
+        * svg/animations/svgnumber-animation-3-expected.txt: Added.
+        * svg/animations/svgnumber-animation-3.html: Added.
+
 2011-06-19  Stephen White  <senorblanco@chromium.org>
 
         Unreviewed.
diff --git a/LayoutTests/svg/animations/script-tests/svgnumber-animation-1.js b/LayoutTests/svg/animations/script-tests/svgnumber-animation-1.js
new file mode 100644 (file)
index 0000000..ecc69e8
--- /dev/null
@@ -0,0 +1,54 @@
+description("Test for SVGNumber 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("opacity", "0");
+rect.setAttribute("onclick", "executeTest()");
+
+var animate = createSVGElement("animate");
+animate.setAttribute("id", "animation");
+animate.setAttribute("attributeName", "opacity");
+animate.setAttribute("begin", "click");
+animate.setAttribute("dur", "4s");
+animate.setAttribute("from", "0");
+animate.setAttribute("to", "1");
+rect.appendChild(animate);
+rootSVGElement.appendChild(rect);
+
+var computedStyle = rect.ownerDocument.defaultView.getComputedStyle(rect);
+
+// Setup animation test
+function sample1() {
+    // Check initial/end conditions
+    shouldBe("computedStyle.getPropertyCSSValue('opacity').getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "0");
+}
+
+function sample2() {
+    shouldBe("computedStyle.getPropertyCSSValue('opacity').getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "0.5");
+}
+
+function sample3() {
+    shouldBeCloseEnough("computedStyle.getPropertyCSSValue('opacity').getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "1", 0.01);
+}
+
+function executeTest() {
+    const expectedValues = [
+        // [animationId, time, elementId, sampleCallback]
+        ["animation", 0,      "rect", sample1],
+        ["animation", 2.0,    "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/script-tests/svgnumber-animation-2.js b/LayoutTests/svg/animations/script-tests/svgnumber-animation-2.js
new file mode 100644 (file)
index 0000000..67d9788
--- /dev/null
@@ -0,0 +1,54 @@
+description("Test for SVGNumber animation with different exponents.");
+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("opacity", "0");
+rect.setAttribute("onclick", "executeTest()");
+
+var animate = createSVGElement("animate");
+animate.setAttribute("id", "animation");
+animate.setAttribute("attributeName", "opacity");
+animate.setAttribute("begin", "click");
+animate.setAttribute("dur", "4s");
+animate.setAttribute("from", "0e10");
+animate.setAttribute("to", ".1e1");
+rect.appendChild(animate);
+rootSVGElement.appendChild(rect);
+
+var computedStyle = rect.ownerDocument.defaultView.getComputedStyle(rect);
+
+// Setup animation test
+function sample1() {
+    // Check initial/end conditions
+    shouldBe("computedStyle.getPropertyCSSValue('opacity').getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "0");
+}
+
+function sample2() {
+    shouldBe("computedStyle.getPropertyCSSValue('opacity').getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "0.5");
+}
+
+function sample3() {
+    shouldBeCloseEnough("computedStyle.getPropertyCSSValue('opacity').getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "1", 0.01);
+}
+
+function executeTest() {
+    const expectedValues = [
+        // [animationId, time, elementId, sampleCallback]
+        ["animation", 0,      "rect", sample1],
+        ["animation", 2.0,    "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/script-tests/svgnumber-animation-3.js b/LayoutTests/svg/animations/script-tests/svgnumber-animation-3.js
new file mode 100644 (file)
index 0000000..a55b1be
--- /dev/null
@@ -0,0 +1,54 @@
+description("Test for SVGNumber animation with invalid units.");
+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("opacity", "0");
+rect.setAttribute("onclick", "executeTest()");
+
+var animate = createSVGElement("animate");
+animate.setAttribute("id", "animation");
+animate.setAttribute("attributeName", "opacity");
+animate.setAttribute("begin", "click");
+animate.setAttribute("dur", "4s");
+animate.setAttribute("from", "0px");
+animate.setAttribute("to", "1px");
+rect.appendChild(animate);
+rootSVGElement.appendChild(rect);
+
+var computedStyle = rect.ownerDocument.defaultView.getComputedStyle(rect);
+
+// Setup animation test
+function sample1() {
+    // Check initial/end conditions
+    shouldBe("computedStyle.getPropertyCSSValue('opacity').getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "0");
+}
+
+function sample2() {
+    shouldBe("computedStyle.getPropertyCSSValue('opacity').getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "0");
+}
+
+function sample3() {
+    shouldBe("computedStyle.getPropertyCSSValue('opacity').getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "0");
+}
+
+function executeTest() {
+    const expectedValues = [
+        // [animationId, time, elementId, sampleCallback]
+        ["animation", 0,      "rect", sample1],
+        ["animation", 2.0,    "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/svgnumber-animation-1-expected.txt b/LayoutTests/svg/animations/svgnumber-animation-1-expected.txt
new file mode 100644 (file)
index 0000000..07f2e4d
--- /dev/null
@@ -0,0 +1,15 @@
+SVG 1.1 dynamic animation tests
+
+Test for SVGNumber animation.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS computedStyle.getPropertyCSSValue('opacity').getFloatValue(CSSPrimitiveValue.CSS_NUMBER) is 0
+PASS computedStyle.getPropertyCSSValue('opacity').getFloatValue(CSSPrimitiveValue.CSS_NUMBER) is 0.5
+PASS computedStyle.getPropertyCSSValue('opacity').getFloatValue(CSSPrimitiveValue.CSS_NUMBER) is 1
+PASS computedStyle.getPropertyCSSValue('opacity').getFloatValue(CSSPrimitiveValue.CSS_NUMBER) is 0
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/svg/animations/svgnumber-animation-1.html b/LayoutTests/svg/animations/svgnumber-animation-1.html
new file mode 100644 (file)
index 0000000..47e9516
--- /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/svgnumber-animation-1.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/svg/animations/svgnumber-animation-2-expected.txt b/LayoutTests/svg/animations/svgnumber-animation-2-expected.txt
new file mode 100644 (file)
index 0000000..59a279f
--- /dev/null
@@ -0,0 +1,15 @@
+SVG 1.1 dynamic animation tests
+
+Test for SVGNumber animation with different exponents.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS computedStyle.getPropertyCSSValue('opacity').getFloatValue(CSSPrimitiveValue.CSS_NUMBER) is 0
+PASS computedStyle.getPropertyCSSValue('opacity').getFloatValue(CSSPrimitiveValue.CSS_NUMBER) is 0.5
+PASS computedStyle.getPropertyCSSValue('opacity').getFloatValue(CSSPrimitiveValue.CSS_NUMBER) is 1
+PASS computedStyle.getPropertyCSSValue('opacity').getFloatValue(CSSPrimitiveValue.CSS_NUMBER) is 0
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/svg/animations/svgnumber-animation-2.html b/LayoutTests/svg/animations/svgnumber-animation-2.html
new file mode 100644 (file)
index 0000000..0737f74
--- /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/svgnumber-animation-2.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/svg/animations/svgnumber-animation-3-expected.txt b/LayoutTests/svg/animations/svgnumber-animation-3-expected.txt
new file mode 100644 (file)
index 0000000..0f19e0d
--- /dev/null
@@ -0,0 +1,15 @@
+SVG 1.1 dynamic animation tests
+
+Test for SVGNumber animation with invalid units.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS computedStyle.getPropertyCSSValue('opacity').getFloatValue(CSSPrimitiveValue.CSS_NUMBER) is 0
+PASS computedStyle.getPropertyCSSValue('opacity').getFloatValue(CSSPrimitiveValue.CSS_NUMBER) is 0
+PASS computedStyle.getPropertyCSSValue('opacity').getFloatValue(CSSPrimitiveValue.CSS_NUMBER) is 0
+PASS computedStyle.getPropertyCSSValue('opacity').getFloatValue(CSSPrimitiveValue.CSS_NUMBER) is 0
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/svg/animations/svgnumber-animation-3.html b/LayoutTests/svg/animations/svgnumber-animation-3.html
new file mode 100644 (file)
index 0000000..092759d
--- /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/svgnumber-animation-3.js"></script>
+</body>
+</html>
index 6806854..8f9f76e 100644 (file)
@@ -1655,6 +1655,8 @@ IF (ENABLE_SVG)
         svg/SVGAnimateColorElement.cpp
         svg/SVGAnimatedAngle.cpp
         svg/SVGAnimatedLength.cpp
+        svg/SVGAnimatedNumber.cpp
+        svg/SVGAnimatedType.cpp
         svg/SVGAnimateElement.cpp
         svg/SVGAnimateMotionElement.cpp
         svg/SVGAnimateTransformElement.cpp
index b1cd35a..ed4db2c 100644 (file)
@@ -1,3 +1,66 @@
+2011-06-19  Dirk Schulze  <krit@webkit.org>
+
+        Reviewed by Nikolas Zimmermann.
+
+        SVGAnimatorFactory does not support SVGNumber
+        https://bugs.webkit.org/show_bug.cgi?id=62938
+
+        Follow up of "SVGAnimation should use direct unit animation for SVGLength": https://bugs.webkit.org/show_bug.cgi?id=61368
+        This patch continues the conversion to the new concept of SVGAnimatorFactory with SVGNumber. With the new animator for the
+        With the new animator for SVGNumber we also support the scientific notation, and everything else that's supported by
+        the SVGNumber parsing, removing the SVGAnimate* specific number parsing functionality.
+
+        Moving the content of SVGAnimatedType header into its own cpp.
+        
+        Changed behavior of parseNumberFromString(). It checks if the String simply consits of a number now. parseNumberFromString()
+        is using genericParseNumber() for parsing numbers. But this method just stops at the first char that does not belong to a number and
+        returns true. I added a check if the current char pointer is at the last char of the String and return false if not.
+
+        Tests: svg/animations/svgnumber-animation-1.html
+               svg/animations/svgnumber-animation-2.html
+               svg/animations/svgnumber-animation-3.html
+
+        * CMakeLists.txt: Added new files to build system.
+        * GNUmakefile.list.am: Ditto.
+        * WebCore.gypi: Ditto.
+        * WebCore.pro: Ditto.
+        * WebCore.xcodeproj/project.pbxproj: Ditto.
+        * svg/SVGAllInOne.cpp: Ditto.
+        * svg/SVGAnimateElement.cpp: Use SVGAnimatedNumberAnimator for animations of SVGNumbers.
+        (WebCore::SVGAnimateElement::SVGAnimateElement):
+        (WebCore::SVGAnimateElement::calculateAnimatedValue):
+        (WebCore::SVGAnimateElement::calculateFromAndToValues):
+        (WebCore::SVGAnimateElement::calculateFromAndByValues):
+        (WebCore::SVGAnimateElement::resetToBaseValue):
+        (WebCore::SVGAnimateElement::applyResultsToTarget):
+        (WebCore::SVGAnimateElement::calculateDistance):
+        * svg/SVGAnimateElement.h: Remove floats for value storage. This is done by SVGAnimatedTypes now.
+        * svg/SVGAnimatedNumber.cpp: Added. Animator for SVGNumbers.
+        (WebCore::SVGAnimatedNumberAnimator::SVGAnimatedNumberAnimator):
+        (WebCore::SVGAnimatedNumberAnimator::constructFromString):
+        (WebCore::SVGAnimatedNumberAnimator::calculateFromAndToValues):
+        (WebCore::SVGAnimatedNumberAnimator::calculateFromAndByValues):
+        (WebCore::SVGAnimatedNumberAnimator::calculateAnimatedValue):
+        (WebCore::SVGAnimatedNumberAnimator::calculateDistance):
+        * svg/SVGAnimatedNumber.h:
+        (WebCore::SVGAnimatedNumberAnimator::~SVGAnimatedNumberAnimator):
+        * svg/SVGAnimatedType.cpp: Added. Moved content from header to cpp.
+        (WebCore::SVGAnimatedType::SVGAnimatedType):
+        (WebCore::SVGAnimatedType::~SVGAnimatedType):
+        (WebCore::SVGAnimatedType::createAngle):
+        (WebCore::SVGAnimatedType::createLength):
+        (WebCore::SVGAnimatedType::createNumber):
+        (WebCore::SVGAnimatedType::angle):
+        (WebCore::SVGAnimatedType::length):
+        (WebCore::SVGAnimatedType::number):
+        (WebCore::SVGAnimatedType::valueAsString):
+        (WebCore::SVGAnimatedType::setValueAsString):
+        * svg/SVGAnimatedType.h: Removed method create(). Allways call type specific create funtcions.
+        * svg/SVGAnimatorFactory.h:
+        (WebCore::SVGAnimatorFactory::create):
+        * svg/SVGParserUtilities.cpp:
+        (WebCore::parseNumberFromString): Check if String simply consits of a number. Return false otherwise.
+
 2011-06-18  Dimitri Glazkov  <dglazkov@chromium.org>
 
         Reviewed by Darin Adler.
index b8a6757..304c3bc 100644 (file)
@@ -3345,12 +3345,14 @@ webcore_sources += \
        Source/WebCore/svg/SVGAnimatedLength.cpp \
        Source/WebCore/svg/SVGAnimatedLength.h \
        Source/WebCore/svg/SVGAnimatedLengthList.h \
+       Source/WebCore/svg/SVGAnimatedNumber.cpp \
        Source/WebCore/svg/SVGAnimatedNumber.h \
        Source/WebCore/svg/SVGAnimatedNumberList.h \
        Source/WebCore/svg/SVGAnimatedPreserveAspectRatio.h \
        Source/WebCore/svg/SVGAnimatedRect.h \
        Source/WebCore/svg/SVGAnimatedString.h \
        Source/WebCore/svg/SVGAnimatedTransformList.h \
+       Source/WebCore/svg/SVGAnimatedType.cpp \
        Source/WebCore/svg/SVGAnimatedType.h \
        Source/WebCore/svg/SVGAnimatedTypeAnimator.h \
        Source/WebCore/svg/SVGAnimateElement.cpp \
index 15dd72f..a11744f 100644 (file)
             'svg/SVGAnimateColorElement.h',
             'svg/SVGAnimatedAngle.cpp',
             'svg/SVGAnimatedLength.cpp',
+            'svg/SVGAnimatedNumber.cpp',
+            'svg/SVGAnimatedType.cpp',
             'svg/SVGAnimateElement.cpp',
             'svg/SVGAnimateElement.h',
             'svg/SVGAnimateMotionElement.cpp',
index 8b12c92..acb6f46 100644 (file)
@@ -3295,6 +3295,8 @@ contains(DEFINES, ENABLE_SVG=1) {
               svg/SVGAnimateColorElement.cpp \
               svg/SVGAnimatedAngle.cpp \
               svg/SVGAnimatedLength.cpp \
+              svg/SVGAnimatedNumber.cpp \
+              svg/SVGAnimatedType.cpp \
               svg/SVGAnimateElement.cpp \
               svg/SVGAnimateMotionElement.cpp \
               svg/SVGAnimateTransformElement.cpp \
index 049c5a4..76ff1d3 100644 (file)
                439D334313A6911C00C20F4F /* SVGAnimatedType.h in Headers */ = {isa = PBXBuildFile; fileRef = 439D334013A6911C00C20F4F /* SVGAnimatedType.h */; };
                439D334413A6911C00C20F4F /* SVGAnimatedTypeAnimator.h in Headers */ = {isa = PBXBuildFile; fileRef = 439D334113A6911C00C20F4F /* SVGAnimatedTypeAnimator.h */; };
                439D334513A6911C00C20F4F /* SVGAnimatorFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = 439D334213A6911C00C20F4F /* SVGAnimatorFactory.h */; };
+               43A0F0B113AC7D6D00A5F0A7 /* SVGAnimatedNumber.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 43A0F0B013AC7D6D00A5F0A7 /* SVGAnimatedNumber.cpp */; };
+               43A0F0B613ACCCFF00A5F0A7 /* SVGAnimatedType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 43A0F0B513ACCCFF00A5F0A7 /* SVGAnimatedType.cpp */; };
                43C092BC12D9E4EE00A989C3 /* RenderSVGForeignObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 43C092BA12D9E4EE00A989C3 /* RenderSVGForeignObject.h */; };
                4415292E0E1AE8A000C4A2D0 /* HTMLPlugInImageElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 4415292C0E1AE8A000C4A2D0 /* HTMLPlugInImageElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
                4415292F0E1AE8A000C4A2D0 /* HTMLPlugInImageElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4415292D0E1AE8A000C4A2D0 /* HTMLPlugInImageElement.cpp */; };
                439D334013A6911C00C20F4F /* SVGAnimatedType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGAnimatedType.h; sourceTree = "<group>"; };
                439D334113A6911C00C20F4F /* SVGAnimatedTypeAnimator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGAnimatedTypeAnimator.h; sourceTree = "<group>"; };
                439D334213A6911C00C20F4F /* SVGAnimatorFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGAnimatorFactory.h; sourceTree = "<group>"; };
+               43A0F0B013AC7D6D00A5F0A7 /* SVGAnimatedNumber.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGAnimatedNumber.cpp; sourceTree = "<group>"; };
+               43A0F0B513ACCCFF00A5F0A7 /* SVGAnimatedType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGAnimatedType.cpp; sourceTree = "<group>"; };
                43C092B912D9E4EE00A989C3 /* RenderSVGForeignObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGForeignObject.cpp; sourceTree = "<group>"; };
                43C092BA12D9E4EE00A989C3 /* RenderSVGForeignObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGForeignObject.h; sourceTree = "<group>"; };
                4415292C0E1AE8A000C4A2D0 /* HTMLPlugInImageElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLPlugInImageElement.h; sourceTree = "<group>"; };
                                B22277EA0D00BF1F0071B782 /* SVGAnimatedLength.idl */,
                                089021AC126EF5E90092D5EA /* SVGAnimatedLengthList.h */,
                                B22277EB0D00BF1F0071B782 /* SVGAnimatedLengthList.idl */,
+                               43A0F0B013AC7D6D00A5F0A7 /* SVGAnimatedNumber.cpp */,
                                08B35B12127B6A7C005314DD /* SVGAnimatedNumber.h */,
                                B22277EC0D00BF1F0071B782 /* SVGAnimatedNumber.idl */,
                                08B35B16127B6A88005314DD /* SVGAnimatedNumberList.h */,
                                B22277F60D00BF1F0071B782 /* SVGAnimatedString.idl */,
                                08250938128BD4D800E2ED8E /* SVGAnimatedTransformList.h */,
                                B22277F80D00BF1F0071B782 /* SVGAnimatedTransformList.idl */,
+                               43A0F0B513ACCCFF00A5F0A7 /* SVGAnimatedType.cpp */,
                                439D334013A6911C00C20F4F /* SVGAnimatedType.h */,
                                439D334113A6911C00C20F4F /* SVGAnimatedTypeAnimator.h */,
                                B22277F90D00BF1F0071B782 /* SVGAnimateElement.cpp */,
                                B1AD4E7313A12A4600846B27 /* CueLoader.cpp in Sources */,
                                B1AD4E7B13A12A7200846B27 /* CueParser.cpp in Sources */,
                                4362C7B913AC6F1A00344BEB /* SVGAnimatedAngle.cpp in Sources */,
+                               43A0F0B113AC7D6D00A5F0A7 /* SVGAnimatedNumber.cpp in Sources */,
+                               43A0F0B613ACCCFF00A5F0A7 /* SVGAnimatedType.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 48a0048..fa31e6d 100644 (file)
@@ -32,6 +32,8 @@
 #include "SVGAnimateColorElement.cpp"
 #include "SVGAnimatedAngle.cpp"
 #include "SVGAnimatedLength.cpp"
+#include "SVGAnimatedNumber.cpp"
+#include "SVGAnimatedType.cpp"
 #include "SVGAnimateElement.cpp"
 #include "SVGAnimateMotionElement.cpp"
 #include "SVGAnimateTransformElement.cpp"
index 534235c..468f67d 100644 (file)
@@ -29,7 +29,6 @@
 #include "CSSParser.h"
 #include "CSSPropertyNames.h"
 #include "ColorDistance.h"
-#include "FloatConversion.h"
 #include "QualifiedName.h"
 #include "RenderObject.h"
 #include "SVGAnimatorFactory.h"
@@ -48,9 +47,6 @@ namespace WebCore {
 SVGAnimateElement::SVGAnimateElement(const QualifiedName& tagName, Document* document)
     : SVGAnimationElement(tagName, document)
     , m_animatedAttributeType(AnimatedString)
-    , m_fromNumber(0)
-    , m_toNumber(0)
-    , m_animatedNumber(numeric_limits<float>::infinity())
     , m_animatedPathPointer(0)
 {
     ASSERT(hasTagName(SVGNames::animateTag) || hasTagName(SVGNames::setTag) || hasTagName(SVGNames::animateColorTag));
@@ -169,40 +165,6 @@ void SVGAnimateElement::calculateAnimatedValue(float percentage, unsigned repeat
     if (results->m_animatedAttributeType == AnimatedString && m_animatedAttributeType != AnimatedString)
         return;
     switch (m_animatedAttributeType) {
-    case AnimatedNumber: {
-        // To animation uses contributions from the lower priority animations as the base value.
-        if (animationMode == ToAnimation)
-            m_fromNumber = results->m_animatedNumber;
-        
-        // Replace 'currentColor' / 'inherit' by their computed property values.
-        if (m_fromPropertyValueType == InheritValue) {
-            String fromNumberString;
-            adjustForInheritance(targetElement, attributeName(), fromNumberString);
-            if (!parseNumberFromString(fromNumberString, m_fromNumber, false))
-                return;
-        }
-        if (m_toPropertyValueType == InheritValue) {
-            String toNumberString;
-            adjustForInheritance(targetElement, attributeName(), toNumberString);
-            if (!parseNumberFromString(toNumberString, m_toNumber, false))
-                return;
-        }
-
-        float number;
-        if (calcMode() == CalcModeDiscrete)
-            number = isInFirstHalfOfAnimation ? m_fromNumber : m_toNumber;
-        else
-            number = (m_toNumber - m_fromNumber) * percentage + m_fromNumber;
-
-        // FIXME: This is not correct for values animation.
-        if (isAccumulated() && repeat)
-            number += m_toNumber * repeat;
-        if (isAdditive() && animationMode != ToAnimation)
-            results->m_animatedNumber += number;
-        else 
-            results->m_animatedNumber = number;
-        return;
-    } 
     case AnimatedColor: {
         if (animationMode == ToAnimation)
             m_fromColor = results->m_animatedColor;
@@ -287,7 +249,8 @@ void SVGAnimateElement::calculateAnimatedValue(float percentage, unsigned repeat
         return;
     }
     case AnimatedAngle:
-    case AnimatedLength: {
+    case AnimatedLength:
+    case AnimatedNumber: {
         ASSERT(m_animator);
         ASSERT(results->m_animatedType);
         // Target element might have changed.
@@ -357,14 +320,6 @@ bool SVGAnimateElement::calculateFromAndToValues(const String& fromString, const
             return true;
         break;
     }
-    case AnimatedNumber: {
-        if (parseNumberFromString(toString, m_toNumber, false)) {
-            // For to-animations the from number is calculated later
-            if (animationMode() == ToAnimation || parseNumberFromString(fromString, m_fromNumber, false))
-                return true;
-        }
-        break;
-    }
     case AnimatedPath: {
         SVGPathParserFactory* factory = SVGPathParserFactory::self();
         if (factory->buildSVGPathByteStreamFromString(toString, m_toPath, UnalteredParsing)) {
@@ -387,6 +342,7 @@ bool SVGAnimateElement::calculateFromAndToValues(const String& fromString, const
     }
     case AnimatedAngle:
     case AnimatedLength:
+    case AnimatedNumber:
         ensureAnimator()->calculateFromAndToValues(m_fromType, m_toType, fromString, toString);
         return true;
     default:
@@ -428,15 +384,11 @@ bool SVGAnimateElement::calculateFromAndByValues(const String& fromString, const
     }
     case AnimatedAngle:
     case AnimatedLength:
+    case AnimatedNumber:
         ensureAnimator()->calculateFromAndByValues(m_fromType, m_toType, fromString, byString);
         return true;
     default:
-        m_fromNumber = 0;
-        if (!fromString.isEmpty() && !parseNumberFromString(fromString, m_fromNumber, false))
-            return false;
-        if (!parseNumberFromString(byString, m_toNumber, false))
-            return false;
-        m_toNumber += m_fromNumber;
+        break;
     }
     return true;
 }
@@ -456,14 +408,6 @@ void SVGAnimateElement::resetToBaseValue(const String& baseString)
             return;
         }
         break;
-    case AnimatedNumber:
-        if (baseString.isEmpty()) {
-            m_animatedNumber = 0;
-            return;
-        }
-        if (parseNumberFromString(baseString, m_animatedNumber, false))
-            return;
-        break;
     case AnimatedPath: {
         m_animatedPath.clear();
         SVGPathParserFactory* factory = SVGPathParserFactory::self();
@@ -475,7 +419,8 @@ void SVGAnimateElement::resetToBaseValue(const String& baseString)
         m_animatedPoints.clear();
         return;
     case AnimatedAngle:
-    case AnimatedLength: {
+    case AnimatedLength:
+    case AnimatedNumber: {
         if (!m_animatedType)
             m_animatedType = ensureAnimator()->constructFromString(baseString);
         else
@@ -495,9 +440,6 @@ void SVGAnimateElement::applyResultsToTarget()
     case AnimatedColor:
         valueToApply = m_animatedColor.serialized();
         break;
-    case AnimatedNumber:
-        valueToApply = String::number(m_animatedNumber);
-        break;
     case AnimatedPath: {
         if (!m_animatedPathPointer || m_animatedPathPointer->isEmpty())
             valueToApply = m_animatedString;
@@ -516,6 +458,7 @@ void SVGAnimateElement::applyResultsToTarget()
         break;
     case AnimatedAngle:
     case AnimatedLength:
+    case AnimatedNumber:
         valueToApply = m_animatedType->valueAsString();
         break;
     default:
@@ -526,20 +469,13 @@ void SVGAnimateElement::applyResultsToTarget()
     
 float SVGAnimateElement::calculateDistance(const String& fromString, const String& toString)
 {
+    // FIXME: A return value of float is not enough to support paced animations on lists.
     SVGElement* targetElement = this->targetElement();
     if (!targetElement)
         return -1;
     m_animatedAttributeType = determineAnimatedAttributeType(targetElement);
-    if (m_animatedAttributeType == AnimatedNumber) {
-        float from;
-        float to;
-        if (!parseNumberFromString(fromString, from, false))
-            return -1;
-        if (!parseNumberFromString(toString, to, false))
-            return -1;
-        return fabs(to - from);
-    }
-    if (m_animatedAttributeType == AnimatedColor) {
+    switch (m_animatedAttributeType) {
+    case AnimatedColor: {
         Color from = SVGColor::colorFromRGBColorString(fromString);
         if (!from.isValid())
             return -1;
@@ -548,8 +484,13 @@ float SVGAnimateElement::calculateDistance(const String& fromString, const Strin
             return -1;
         return ColorDistance(from, to).distance();
     }
-    if (m_animatedAttributeType == AnimatedAngle || m_animatedAttributeType == AnimatedLength)
+    case AnimatedAngle:
+    case AnimatedLength:
+    case AnimatedNumber:
         return ensureAnimator()->calculateDistance(this, fromString, toString);
+    default:
+        break;
+    }
     return -1;
 }
 
index dc02974..02afff9 100644 (file)
@@ -72,9 +72,6 @@ private:
 
     AnimatedPropertyValueType m_fromPropertyValueType;
     AnimatedPropertyValueType m_toPropertyValueType;
-    float m_fromNumber;
-    float m_toNumber;
-    float m_animatedNumber;
     Color m_fromColor;
     Color m_toColor;
     Color m_animatedColor;
diff --git a/Source/WebCore/svg/SVGAnimatedNumber.cpp b/Source/WebCore/svg/SVGAnimatedNumber.cpp
new file mode 100644 (file)
index 0000000..6fb1911
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) Research In Motion Limited 2011. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#if ENABLE(SVG) && ENABLE(SVG_ANIMATION)
+#include "SVGAnimatedNumber.h"
+
+#include "SVGParserUtilities.h"
+
+using namespace std;
+
+namespace WebCore {
+
+SVGAnimatedNumberAnimator::SVGAnimatedNumberAnimator(SVGElement* contextElement, const QualifiedName&)
+    : SVGAnimatedTypeAnimator(AnimatedNumber, contextElement)
+{
+}
+
+PassOwnPtr<SVGAnimatedType> SVGAnimatedNumberAnimator::constructFromString(const String& string)
+{
+    OwnPtr<SVGAnimatedType> animtedType = SVGAnimatedType::createNumber(new float);
+    float& animatedNumber = animtedType->number();
+    if (!parseNumberFromString(string, animatedNumber))
+        animatedNumber = 0;
+    return animtedType.release();
+}
+
+void SVGAnimatedNumberAnimator::calculateFromAndToValues(OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, const String& fromString, const String& toString)
+{
+    from = constructFromString(fromString);
+    to = constructFromString(toString);
+}
+
+void SVGAnimatedNumberAnimator::calculateFromAndByValues(OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, const String& fromString, const String& byString)
+{
+    ASSERT(m_contextElement);
+    
+    from = constructFromString(fromString);
+    to = constructFromString(byString);
+
+    to->number() += from->number();
+}
+
+void SVGAnimatedNumberAnimator::calculateAnimatedValue(SVGSMILElement* smilElement, float percentage, unsigned repeatCount,
+                                                       OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, OwnPtr<SVGAnimatedType>& animated,
+                                                       bool fromPropertyInherits, bool toPropertyInherits)
+{
+    ASSERT(smilElement);
+    ASSERT(m_contextElement);
+    SVGAnimateElement* animationElement = static_cast<SVGAnimateElement*>(smilElement);
+    
+    AnimationMode animationMode = animationElement->animationMode();
+    // To animation uses contributions from the lower priority animations as the base value.
+    float& animatedNumber = animated->number();
+    if (animationMode == ToAnimation)
+        from->number() = animatedNumber;
+    
+    // Replace 'inherit' by their computed property values.
+    float& fromNumber = from->number();
+    float& toNumber = to->number();
+    if (fromPropertyInherits) {
+        String fromNumberString;
+        animationElement->adjustForInheritance(m_contextElement, animationElement->attributeName(), fromNumberString);
+        parseNumberFromString(fromNumberString, fromNumber); 
+    }
+    if (toPropertyInherits) {
+        String toNumberString;
+        animationElement->adjustForInheritance(m_contextElement, animationElement->attributeName(), toNumberString);
+        parseNumberFromString(toNumberString, toNumber); 
+    }
+
+    float number;
+    if (animationElement->calcMode() == CalcModeDiscrete)
+        number = percentage < 0.5f ? fromNumber : toNumber;
+    else
+        number = (toNumber - fromNumber) * percentage + fromNumber;
+    
+    // FIXME: This is not correct for values animation. Right now we transform values-animation to multiple from-to-animations and
+    // accumulate every single value to the previous one. But accumulation should just take into account after a complete cycle
+    // of values-animaiton. See example at: http://www.w3.org/TR/2001/REC-smil-animation-20010904/#RepeatingAnim
+    if (animationElement->isAccumulated() && repeatCount)
+        number += toNumber * repeatCount;
+    if (animationElement->isAdditive() && animationMode != ToAnimation)
+        animatedNumber += number;
+    else
+        animatedNumber = number;
+}
+
+float SVGAnimatedNumberAnimator::calculateDistance(SVGSMILElement*, const String& fromString, const String& toString)
+{
+    ASSERT(m_contextElement);
+    float from = 0;
+    float to = 0;
+    parseNumberFromString(fromString, from);
+    parseNumberFromString(toString, to);
+    return fabsf(to - from);
+}
+
+}
+
+#endif // ENABLE(SVG) && ENABLE(SVG_ANIMATION)
index b59deac..798f968 100644 (file)
@@ -21,6 +21,7 @@
 #define SVGAnimatedNumber_h
 
 #if ENABLE(SVG)
+#include "SVGAnimateElement.h"
 #include "SVGAnimatedPropertyMacros.h"
 #include "SVGAnimatedStaticPropertyTearOff.h"
 
@@ -38,7 +39,24 @@ DEFINE_ANIMATED_PROPERTY(OwnerType, DOMAttribute, DOMAttribute.localName(), SVGA
 #define DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, UpperProperty, LowerProperty) \
 DEFINE_ANIMATED_PROPERTY(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, SVGAnimatedNumber, float, UpperProperty, LowerProperty)
 
+#if ENABLE(SVG_ANIMATION)
+class SVGAnimatedNumberAnimator : public SVGAnimatedTypeAnimator {
+    
+public:
+    SVGAnimatedNumberAnimator(SVGElement*, const QualifiedName&);
+    virtual ~SVGAnimatedNumberAnimator() { }
+    
+    virtual PassOwnPtr<SVGAnimatedType> constructFromString(const String&);
+    
+    virtual void calculateFromAndToValues(OwnPtr<SVGAnimatedType>& fromValue, OwnPtr<SVGAnimatedType>& toValue, const String& fromString, const String& toString);
+    virtual void calculateFromAndByValues(OwnPtr<SVGAnimatedType>& fromValue, OwnPtr<SVGAnimatedType>& toValue, const String& fromString, const String& byString);
+    virtual void calculateAnimatedValue(SVGSMILElement*, float percentage, unsigned repeatCount,
+                                        OwnPtr<SVGAnimatedType>& fromValue, OwnPtr<SVGAnimatedType>& toValue, OwnPtr<SVGAnimatedType>& animatedValue,
+                                        bool fromPropertyInherits, bool toPropertyInherits);
+    virtual float calculateDistance(SVGSMILElement*, const String& fromString, const String& toString);
+};
 } // namespace WebCore
 
+#endif // ENABLE(SVG_ANIMATION)
 #endif // ENABLE(SVG)
 #endif
diff --git a/Source/WebCore/svg/SVGAnimatedType.cpp b/Source/WebCore/svg/SVGAnimatedType.cpp
new file mode 100644 (file)
index 0000000..e2fd825
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) Research In Motion Limited 2011. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#if ENABLE(SVG) && ENABLE(SVG_ANIMATION)
+#include "SVGAnimatedType.h"
+
+#include "SVGAngle.h"
+#include "SVGLength.h"
+#include "SVGParserUtilities.h"
+
+namespace WebCore {
+
+SVGAnimatedType::SVGAnimatedType(AnimatedAttributeType type)
+    : m_type(type)
+{
+}
+
+SVGAnimatedType::~SVGAnimatedType()
+{
+    switch (m_type) {
+    case AnimatedAngle:
+        delete m_data.angle;
+        break;
+    case AnimatedLength:
+        delete m_data.length;
+        break;
+    case AnimatedNumber:
+        delete m_data.number;
+        break;
+    default:
+        ASSERT_NOT_REACHED();
+        break;
+    }
+}
+
+PassOwnPtr<SVGAnimatedType> SVGAnimatedType::createAngle(SVGAngle* angle)
+{
+    ASSERT(angle);
+    OwnPtr<SVGAnimatedType> animatedType = adoptPtr(new SVGAnimatedType(AnimatedAngle));
+    animatedType->m_data.angle = angle;
+    return animatedType.release();
+}
+
+PassOwnPtr<SVGAnimatedType> SVGAnimatedType::createLength(SVGLength* length)
+{
+    ASSERT(length);
+    OwnPtr<SVGAnimatedType> animatedType = adoptPtr(new SVGAnimatedType(AnimatedLength));
+    animatedType->m_data.length = length;
+    return animatedType.release();
+}
+
+PassOwnPtr<SVGAnimatedType> SVGAnimatedType::createNumber(float* number)
+{
+    ASSERT(number);
+    OwnPtr<SVGAnimatedType> animatedType = adoptPtr(new SVGAnimatedType(AnimatedNumber));
+    animatedType->m_data.number = number;
+    return animatedType.release();
+}
+
+SVGAngle& SVGAnimatedType::angle()
+{
+    ASSERT(m_type == AnimatedAngle);
+    return *m_data.angle;
+}
+
+SVGLength& SVGAnimatedType::length()
+{
+    ASSERT(m_type == AnimatedLength);
+    return *m_data.length;
+}
+
+float& SVGAnimatedType::number()
+{
+    ASSERT(m_type == AnimatedNumber);
+    return *m_data.number;
+}
+
+String SVGAnimatedType::valueAsString()
+{
+    switch (m_type) {
+    case AnimatedAngle:
+        ASSERT(m_data.angle);
+        return m_data.angle->valueAsString();
+    case AnimatedLength:
+        ASSERT(m_data.length);
+        return m_data.length->valueAsString();
+    case AnimatedNumber:
+        ASSERT(m_data.number);
+        return String::number(*m_data.number);
+    default:
+        break;
+    }
+    ASSERT_NOT_REACHED();
+    return String();
+}
+
+bool SVGAnimatedType::setValueAsString(const QualifiedName& attrName, const String& value)
+{
+    ExceptionCode ec = 0;
+    switch (m_type) {
+    case AnimatedAngle:
+        ASSERT(m_data.angle);
+        m_data.angle->setValueAsString(value, ec);
+        break;
+    case AnimatedLength:
+        ASSERT(m_data.length);
+        m_data.length->setValueAsString(value, SVGLength::lengthModeForAnimatedLengthAttribute(attrName), ec);
+        break;
+    case AnimatedNumber:
+        ASSERT(m_data.number);
+        parseNumberFromString(value, *m_data.number);
+        break;
+    default:
+        ASSERT_NOT_REACHED();
+        break;
+    }
+    return !ec;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SVG) && ENABLE(SVG_ANIMATION)
index 1cd70a4..7ef93d1 100644 (file)
 #define SVGAnimatedType_h
 
 #if ENABLE(SVG) && ENABLE(SVG_ANIMATION)
-#include "SVGAngle.h"
 #include "SVGElement.h"
-#include "SVGLength.h"
 
 namespace WebCore {
 
+class SVGAngle;
+class SVGLength;
+
 class SVGAnimatedType {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    static PassOwnPtr<SVGAnimatedType> create(AnimatedAttributeType type)
-    {
-        return adoptPtr(new SVGAnimatedType(type));
-    }
-
-    static PassOwnPtr<SVGAnimatedType> createAngle(SVGAngle* angle)
-    {
-        ASSERT(angle);
-        OwnPtr<SVGAnimatedType> animatedType = create(AnimatedAngle);
-        animatedType->m_data.angle = angle;
-        return animatedType.release();
-    }
+    virtual ~SVGAnimatedType();
 
-    static PassOwnPtr<SVGAnimatedType> createLength(SVGLength* length)
-    {
-        ASSERT(length);
-        OwnPtr<SVGAnimatedType> animatedType = create(AnimatedLength);
-        animatedType->m_data.length = length;
-        return animatedType.release();
-    }
-
-    virtual ~SVGAnimatedType()
-    {
-        switch (m_type) {
-        case AnimatedAngle:
-            delete m_data.angle;
-            break;
-        case AnimatedLength:
-            delete m_data.length;
-            break;
-        default:
-            ASSERT_NOT_REACHED();
-            break;
-        }
-    }
+    static PassOwnPtr<SVGAnimatedType> createAngle(SVGAngle*);
+    static PassOwnPtr<SVGAnimatedType> createLength(SVGLength*);
+    static PassOwnPtr<SVGAnimatedType> createNumber(float*);
     
     AnimatedAttributeType type() const { return m_type; }
 
-    SVGAngle& angle()
-    {
-        ASSERT(m_type == AnimatedAngle);
-        return *m_data.angle;
-    }
+    SVGAngle& angle();
+    SVGLength& length();
+    float& number();
 
-    SVGLength& length()
-    {
-        ASSERT(m_type == AnimatedLength);
-        return *m_data.length;
-    }
-    
-    String valueAsString()
-    {
-        switch (m_type) {
-        case AnimatedAngle:
-            ASSERT(m_data.angle);
-            return m_data.angle->valueAsString();
-        case AnimatedLength:
-            ASSERT(m_data.length);
-            return m_data.length->valueAsString();
-        default:
-            break;
-        }
-        ASSERT_NOT_REACHED();
-        return String();
-    }
-    
-    bool setValueAsString(const QualifiedName& attrName, const String& value)
-    {
-        ExceptionCode ec = 0;
-        switch (m_type) {
-        case AnimatedAngle:
-            ASSERT(m_data.angle);
-            m_data.angle->setValueAsString(value, ec);
-            break;
-        case AnimatedLength:
-            ASSERT(m_data.length);
-            m_data.length->setValueAsString(value, SVGLength::lengthModeForAnimatedLengthAttribute(attrName), ec);
-            break;
-        default:
-            ASSERT_NOT_REACHED();
-            break;
-        }
-        return !ec;
-    }
+    String valueAsString();
+    bool setValueAsString(const QualifiedName&, const String&);
     
 private:
-    SVGAnimatedType(AnimatedAttributeType type)
-        : m_type(type)
-    {
-    }
+    SVGAnimatedType(AnimatedAttributeType);
     
     AnimatedAttributeType m_type;
     
@@ -132,6 +60,7 @@ private:
         // FIXME: More SVG primitive types need to be added step by step.
         SVGAngle* angle;
         SVGLength* length;
+        float* number;
     } m_data;
 };
     
index 1ecb0f4..f880717 100644 (file)
@@ -23,6 +23,7 @@
 #if ENABLE(SVG) && ENABLE(SVG_ANIMATION)
 #include "SVGAnimatedAngle.h"
 #include "SVGAnimatedLength.h"
+#include "SVGAnimatedNumber.h"
 
 namespace WebCore {
     
@@ -36,6 +37,8 @@ public:
             return adoptPtr(new SVGAnimatedAngleAnimator(contextElement, attributeName));
         case AnimatedLength:
             return adoptPtr(new SVGAnimatedLengthAnimator(contextElement, attributeName));
+        case AnimatedNumber:
+            return adoptPtr(new SVGAnimatedNumberAnimator(contextElement, attributeName));
         default:
             ASSERT_NOT_REACHED();
             return adoptPtr(new SVGAnimatedLengthAnimator(contextElement, attributeName));
index c117c7a..c09f8fe 100644 (file)
@@ -151,7 +151,7 @@ bool parseNumberFromString(const String& string, float& number, bool skip)
 {
     const UChar* ptr = string.characters();
     const UChar* end = ptr + string.length();
-    return genericParseNumber(ptr, end, number, skip);
+    return genericParseNumber(ptr, end, number, skip) && ptr == end;
 }
 
 // only used to parse largeArcFlag and sweepFlag which must be a "0" or "1"