Changeset 71014 in webkit


Ignore:
Timestamp:
Nov 1, 2010 1:57:11 AM (14 years ago)
Author:
Nikolas Zimmermann
Message:

2010-10-31 Nikolas Zimmermann <nzimmermann@rim.com>

Reviewed by Rob Buis.

Enable StrictTypeChecking for all types using SVG(Animated)PropertyTearOff
https://bugs.webkit.org/show_bug.cgi?id=48715

Enable StrictTypeChecking for all readwrite attributes and function calls of all types using the new SVG(Animated)PropertyTearOff concept.
Also enable RequiresAllArguments=Raise for all function calls of these new types. Cover this functionality by tests for each of them.

When testing SVGLength it became obvious that quite a lot of functionality was missing.
Conversion from relative arguments (percentage, ems, exs) to user specified units was missing, added that functionality and tested it.
User units to pt conversion was wrong, fixed that.

Tests: svg/dom/SVGAnimatedAngle.html

svg/dom/SVGAnimatedBoolean.html
svg/dom/SVGAnimatedEnumeration.html
svg/dom/SVGAnimatedInteger.html
svg/dom/SVGAnimatedLength.html
svg/dom/SVGAnimatedLengthList.html
svg/dom/SVGAnimatedRect.html
svg/dom/SVGLength-px-with-context.html
svg/dom/SVGLength-px.html
svg/dom/SVGLength.html

  • bindings/js/JSSVGLengthCustom.cpp: These SVGLength methods now take an ExceptionCode parameter, adapt to that. (WebCore::JSSVGLength::value): (WebCore::JSSVGLength::setValue): (WebCore::JSSVGLength::convertToSpecifiedUnits):
  • bindings/scripts/CodeGeneratorObjC.pm: Remove FIXMEs, pass real context instead off null pointer. DOMSVGLength::value is functional now.
  • bindings/v8/custom/V8SVGLengthCustom.cpp: These SVGLength methods now take an ExceptionCode parameter, adapt to that. (WebCore::V8SVGLength::valueAccessorGetter): (WebCore::V8SVGLength::valueAccessorSetter): (WebCore::V8SVGLength::convertToSpecifiedUnitsCallback):
  • rendering/style/SVGRenderStyle.h: Adapt to SVGLength API changes. (WebCore::SVGRenderStyle::initialBaselineShiftValue): (WebCore::SVGRenderStyle::initialKerning): (WebCore::SVGRenderStyle::initialStrokeDashOffset): (WebCore::SVGRenderStyle::initialStrokeWidth):
  • svg/SVGAngle.idl: Add StrictTypeChecking, RequiresAllArguments=Raise to all methods.
  • svg/SVGAnimatedBoolean.idl: Remove StrictTypeChecking from animVal, it's readonly so this is useless.
  • svg/SVGAnimatedEnumeration.idl: Add StrictTypeChecking to all attributes.
  • svg/SVGAnimatedInteger.idl: Ditto.
  • svg/SVGLength.cpp: Implement all missing features of SVGLength. Conform to our style guide (s/.0f etc) (WebCore::lengthTypeToString): (WebCore::SVGLength::SVGLength): (WebCore::SVGLength::value): Throw NOT_SUPPORTED_ERR when trying to obtain to relative units, when no context is given (SVGLength created by createSVGLength()). (WebCore::SVGLength::setValue): Ditto, for the setter. (WebCore::SVGLength::valueAsPercentage): Use m_valueInSpecifiedUnits instead of valueInSpecifiedUnits(). (WebCore::SVGLength::setValueAsString): Throw SYNTAX_ERR if parsing failed. (WebCore::SVGLength::valueAsString): Use makeString() instead of String and operator+. (WebCore::SVGLength::newValueSpecifiedUnits): Add ExceptionCode parameter, throw NOT_SUPPORTED_ERR, if the given unit type is invalid. (WebCore::SVGLength::convertToSpecifiedUnits): Ditto. (WebCore::SVGLength::determineViewport): Added helper function used by convertValue*Percentage*. (WebCore::SVGLength::convertValueFromUserUnitsToPercentage): Add new helper functions, used by value/setValue. (WebCore::SVGLength::convertValueFromPercentageToUserUnits): Ditto. (WebCore::SVGLength::convertValueFromUserUnitsToEMS): Ditto. (WebCore::SVGLength::convertValueFromEMSToUserUnits): Ditto. (WebCore::SVGLength::convertValueFromUserUnitsToEXS): Ditto. (WebCore::SVGLength::convertValueFromEXSToUserUnits): Ditto. (WebCore::SVGLength::fromCSSPrimitiveValue): Adapt to newValueSpecifiedUnits API change. (WebCore::SVGLength::toCSSPrimitiveValue): Remove default switch case.
  • svg/SVGLength.h: (WebCore::SVGLength::valueInSpecifiedUnits): Inlined. (WebCore::SVGLength::setValueInSpecifiedUnits): Ditto. (WebCore::SVGLength::isRelative):
  • svg/SVGLength.idl: Add StrictTypeChecking for all attributes/functions and RequiresAllArguments=Raise for all functions.
  • svg/SVGLengthList.cpp: Adapt to SVGLength API changes. (WebCore::SVGLengthList::parse):

2010-10-31 Nikolas Zimmermann <nzimmermann@rim.com>

Reviewed by Rob Buis.

Enable StrictTypeChecking for all types using SVG(Animated)PropertyTearOff
https://bugs.webkit.org/show_bug.cgi?id=48715

  • svg/dom/SVGAngle-expected.txt:
  • svg/dom/SVGAnimatedAngle-expected.txt: Added.
  • svg/dom/SVGAnimatedAngle.html: Added.
  • svg/dom/SVGAnimatedBoolean-expected.txt: Copied from LayoutTests/svg/dom/SVGExternalResourcesRequired-expected.txt.
  • svg/dom/SVGAnimatedBoolean.html: Copied from LayoutTests/svg/dom/SVGExternalResourcesRequired.html.
  • svg/dom/SVGAnimatedEnumeration-expected.txt: Added.
  • svg/dom/SVGAnimatedEnumeration.html: Added.
  • svg/dom/SVGAnimatedInteger-expected.txt: Added.
  • svg/dom/SVGAnimatedInteger.html: Added.
  • svg/dom/SVGAnimatedLength-expected.txt: Added.
  • svg/dom/SVGAnimatedLength.html: Added.
  • svg/dom/SVGAnimatedLengthList-expected.txt: Added.
  • svg/dom/SVGAnimatedLengthList.html: Added.
  • svg/dom/SVGAnimatedRect-expected.txt: Added.
  • svg/dom/SVGAnimatedRect.html: Added.
  • svg/dom/SVGExternalResourcesRequired-expected.txt: Removed.
  • svg/dom/SVGExternalResourcesRequired.html: Removed.
  • svg/dom/SVGLength-expected.txt: Added.
  • svg/dom/SVGLength-px-expected.txt: Added.
  • svg/dom/SVGLength-px-with-context-expected.txt: Added.
  • svg/dom/SVGLength-px-with-context.html: Added.
  • svg/dom/SVGLength-px.html: Added.
  • svg/dom/SVGLength.html: Added.
  • svg/dom/script-tests/SVGAngle.js:
  • svg/dom/script-tests/SVGAnimatedAngle.js: Added.
  • svg/dom/script-tests/SVGAnimatedBoolean.js: Copied from LayoutTests/svg/dom/script-tests/SVGExternalResourcesRequired.js.
  • svg/dom/script-tests/SVGAnimatedEnumeration.js: Added.
  • svg/dom/script-tests/SVGAnimatedInteger.js: Added.
  • svg/dom/script-tests/SVGAnimatedLength.js: Added.
  • svg/dom/script-tests/SVGAnimatedLengthList.js: Added.
  • svg/dom/script-tests/SVGAnimatedRect.js: Added.
  • svg/dom/script-tests/SVGExternalResourcesRequired.js: Removed.
  • svg/dom/script-tests/SVGLength-px-with-context.js: Added. Tests various operations on a SVGLength object obtained via rectElement.x.baseVal.
  • svg/dom/script-tests/SVGLength-px.js: Added. Tests various operations on a SVGLength object created via svgElement.createSVGLength().
  • svg/dom/script-tests/SVGLength.js: Added.
  • svg/dom/svg-length-units-expected.txt: Removed.
  • svg/dom/svg-length-units.html: Removed. Test is obsolete now, as SVGLength* covers this in detail.
  • svg/dynamic-updates/script-tests/SVGCircleElement-svgdom-cx-prop.js: (executeTest): Fixed StrictTypeChecking correctness, don't assign strings as SVGLength value.
  • svg/dynamic-updates/script-tests/SVGCircleElement-svgdom-cy-prop.js: (executeTest): Ditto.
  • svg/dynamic-updates/script-tests/SVGCircleElement-svgdom-r-prop.js: (executeTest): Ditto.
  • svg/dynamic-updates/script-tests/SVGEllipseElement-svgdom-cx-prop.js: (executeTest): Ditto.
  • svg/dynamic-updates/script-tests/SVGEllipseElement-svgdom-cy-prop.js: (executeTest): Ditto.
  • svg/dynamic-updates/script-tests/SVGEllipseElement-svgdom-rx-prop.js: (executeTest): Ditto.
  • svg/dynamic-updates/script-tests/SVGEllipseElement-svgdom-ry-prop.js: (executeTest): Ditto.
  • svg/dynamic-updates/script-tests/SVGForeignObjectElement-svgdom-height-prop.js: (executeTest): Ditto.
  • svg/dynamic-updates/script-tests/SVGForeignObjectElement-svgdom-width-prop.js: (executeTest): Ditto.
  • svg/dynamic-updates/script-tests/SVGForeignObjectElement-svgdom-x-prop.js: (executeTest): Ditto.
  • svg/dynamic-updates/script-tests/SVGForeignObjectElement-svgdom-y-prop.js: (executeTest): Ditto.
Location:
trunk
Files:
27 added
2 deleted
18 edited
3 moved

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r71013 r71014  
     12010-11-01  Nikolas Zimmermann  <nzimmermann@rim.com>
     2
     3        Reviewed by Rob Buis.
     4
     5        Enable StrictTypeChecking for all types using SVG(Animated)PropertyTearOff
     6        https://bugs.webkit.org/show_bug.cgi?id=48715
     7
     8        * svg/dom/SVGAngle-expected.txt:
     9        * svg/dom/SVGAnimatedAngle-expected.txt: Added.
     10        * svg/dom/SVGAnimatedAngle.html: Added.
     11        * svg/dom/SVGAnimatedBoolean-expected.txt: Copied from LayoutTests/svg/dom/SVGExternalResourcesRequired-expected.txt.
     12        * svg/dom/SVGAnimatedBoolean.html: Copied from LayoutTests/svg/dom/SVGExternalResourcesRequired.html.
     13        * svg/dom/SVGAnimatedEnumeration-expected.txt: Added.
     14        * svg/dom/SVGAnimatedEnumeration.html: Added.
     15        * svg/dom/SVGAnimatedInteger-expected.txt: Added.
     16        * svg/dom/SVGAnimatedInteger.html: Added.
     17        * svg/dom/SVGAnimatedLength-expected.txt: Added.
     18        * svg/dom/SVGAnimatedLength.html: Added.
     19        * svg/dom/SVGAnimatedLengthList-expected.txt: Added.
     20        * svg/dom/SVGAnimatedLengthList.html: Added.
     21        * svg/dom/SVGAnimatedRect-expected.txt: Added.
     22        * svg/dom/SVGAnimatedRect.html: Added.
     23        * svg/dom/SVGExternalResourcesRequired-expected.txt: Removed.
     24        * svg/dom/SVGExternalResourcesRequired.html: Removed.
     25        * svg/dom/SVGLength-expected.txt: Added.
     26        * svg/dom/SVGLength-px-expected.txt: Added.
     27        * svg/dom/SVGLength-px-with-context-expected.txt: Added.
     28        * svg/dom/SVGLength-px-with-context.html: Added.
     29        * svg/dom/SVGLength-px.html: Added.
     30        * svg/dom/SVGLength.html: Added.
     31        * svg/dom/script-tests/SVGAngle.js:
     32        * svg/dom/script-tests/SVGAnimatedAngle.js: Added.
     33        * svg/dom/script-tests/SVGAnimatedBoolean.js: Copied from LayoutTests/svg/dom/script-tests/SVGExternalResourcesRequired.js.
     34        * svg/dom/script-tests/SVGAnimatedEnumeration.js: Added.
     35        * svg/dom/script-tests/SVGAnimatedInteger.js: Added.
     36        * svg/dom/script-tests/SVGAnimatedLength.js: Added.
     37        * svg/dom/script-tests/SVGAnimatedLengthList.js: Added.
     38        * svg/dom/script-tests/SVGAnimatedRect.js: Added.
     39        * svg/dom/script-tests/SVGExternalResourcesRequired.js: Removed.
     40        * svg/dom/script-tests/SVGLength-px-with-context.js: Added. Tests various operations on a SVGLength object obtained via rectElement.x.baseVal.
     41        * svg/dom/script-tests/SVGLength-px.js: Added. Tests various operations on a SVGLength object created via svgElement.createSVGLength().
     42        * svg/dom/script-tests/SVGLength.js: Added.
     43        * svg/dom/svg-length-units-expected.txt: Removed.
     44        * svg/dom/svg-length-units.html: Removed. Test is obsolete now, as SVGLength* covers this in detail.
     45        * svg/dynamic-updates/script-tests/SVGCircleElement-svgdom-cx-prop.js:
     46        (executeTest): Fixed StrictTypeChecking correctness, don't assign strings as SVGLength value.
     47        * svg/dynamic-updates/script-tests/SVGCircleElement-svgdom-cy-prop.js:
     48        (executeTest): Ditto.
     49        * svg/dynamic-updates/script-tests/SVGCircleElement-svgdom-r-prop.js:
     50        (executeTest): Ditto.
     51        * svg/dynamic-updates/script-tests/SVGEllipseElement-svgdom-cx-prop.js:
     52        (executeTest): Ditto.
     53        * svg/dynamic-updates/script-tests/SVGEllipseElement-svgdom-cy-prop.js:
     54        (executeTest): Ditto.
     55        * svg/dynamic-updates/script-tests/SVGEllipseElement-svgdom-rx-prop.js:
     56        (executeTest): Ditto.
     57        * svg/dynamic-updates/script-tests/SVGEllipseElement-svgdom-ry-prop.js:
     58        (executeTest): Ditto.
     59        * svg/dynamic-updates/script-tests/SVGForeignObjectElement-svgdom-height-prop.js:
     60        (executeTest): Ditto.
     61        * svg/dynamic-updates/script-tests/SVGForeignObjectElement-svgdom-width-prop.js:
     62        (executeTest): Ditto.
     63        * svg/dynamic-updates/script-tests/SVGForeignObjectElement-svgdom-x-prop.js:
     64        (executeTest): Ditto.
     65        * svg/dynamic-updates/script-tests/SVGForeignObjectElement-svgdom-y-prop.js:
     66        (executeTest): Ditto.
     67
    1682010-11-01  Roland Steiner  <rolandsteiner@chromium.org>
    269
  • trunk/LayoutTests/svg/dom/SVGAngle-expected.txt

    r70410 r71014  
    1515PASS angle.convertToSpecifiedUnits(-1) threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9.
    1616PASS angle.convertToSpecifiedUnits(5) threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9.
     17PASS angle.convertToSpecifiedUnits('aString') threw exception TypeError: Type error.
     18PASS angle.convertToSpecifiedUnits(angle) threw exception TypeError: Type error.
     19PASS angle.convertToSpecifiedUnits(svgElement) threw exception TypeError: Type error.
     20PASS angle.convertToSpecifiedUnits() threw exception SyntaxError: Not enough arguments.
    1721PASS angle.unitType is SVGAngle.SVG_ANGLETYPE_UNSPECIFIED
    1822
     
    4347PASS angle.newValueSpecifiedUnits(-1, 50) threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9.
    4448PASS angle.newValueSpecifiedUnits(5, 50) threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9.
     49PASS angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG) threw exception SyntaxError: Not enough arguments.
     50PASS angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG, 'aString') threw exception TypeError: Type error.
     51PASS angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG, angle) threw exception TypeError: Type error.
     52PASS angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG, svgElement) threw exception TypeError: Type error.
     53PASS angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG) threw exception SyntaxError: Not enough arguments.
     54PASS angle.newValueSpecifiedUnits('aString', 4) threw exception TypeError: Type error.
     55PASS angle.newValueSpecifiedUnits(angle, 4) threw exception TypeError: Type error.
     56PASS angle.newValueSpecifiedUnits(svgElement, 4) threw exception TypeError: Type error.
     57PASS angle.newValueSpecifiedUnits('aString', 'aString') threw exception TypeError: Type error.
     58PASS angle.newValueSpecifiedUnits(angle, angle) threw exception TypeError: Type error.
     59PASS angle.newValueSpecifiedUnits(svgElement, svgElement) threw exception TypeError: Type error.
     60PASS angle.newValueSpecifiedUnits() threw exception SyntaxError: Not enough arguments.
    4561PASS angle.unitType is SVGAngle.SVG_ANGLETYPE_UNSPECIFIED
    4662
  • trunk/LayoutTests/svg/dom/SVGAnimatedBoolean-expected.txt

    r70977 r71014  
    1 This test checks the SVGExternalResourcesRequired API
     1This test checks the SVGAnimatedBoolean API - utilizing the externalResourcesRequired property of SVGRectElement
    22
    33On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
  • trunk/LayoutTests/svg/dom/SVGAnimatedBoolean.html

    r70977 r71014  
    88<p id="description"></p>
    99<div id="console"></div>
    10 <script src="script-tests/SVGExternalResourcesRequired.js"></script>
     10<script src="script-tests/SVGAnimatedBoolean.js"></script>
    1111<script src="../../fast/js/resources/js-test-post.js"></script>
    1212</body>
  • trunk/LayoutTests/svg/dom/SVGAnimatedNumberList-expected.txt

    r70979 r71014  
    1414PASS textElement.rotate.baseVal.getItem(0).value is 100
    1515
    16 Check assigning to baseVal has no effect, as no setter is defined
     16Check that assigning to baseVal has no effect, as no setter is defined
    1717PASS textElement.rotate.baseVal = -1 is -1
    1818PASS textElement.rotate.baseVal = 'aString' is "aString"
  • trunk/LayoutTests/svg/dom/script-tests/SVGAngle.js

    r70410 r71014  
    1717shouldThrow("angle.convertToSpecifiedUnits(-1)");
    1818shouldThrow("angle.convertToSpecifiedUnits(5)");
     19shouldThrow("angle.convertToSpecifiedUnits('aString')");
     20shouldThrow("angle.convertToSpecifiedUnits(angle)");
     21shouldThrow("angle.convertToSpecifiedUnits(svgElement)");
     22shouldThrow("angle.convertToSpecifiedUnits()");
    1923shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_UNSPECIFIED");
    2024
     
    5155shouldThrow("angle.newValueSpecifiedUnits(-1, 50)");
    5256shouldThrow("angle.newValueSpecifiedUnits(5, 50)");
     57shouldThrow("angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG)");
     58shouldThrow("angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG, 'aString')");
     59shouldThrow("angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG, angle)");
     60shouldThrow("angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG, svgElement)");
     61shouldThrow("angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG)");
     62shouldThrow("angle.newValueSpecifiedUnits('aString', 4)");
     63shouldThrow("angle.newValueSpecifiedUnits(angle, 4)");
     64shouldThrow("angle.newValueSpecifiedUnits(svgElement, 4)");
     65shouldThrow("angle.newValueSpecifiedUnits('aString', 'aString')");
     66shouldThrow("angle.newValueSpecifiedUnits(angle, angle)");
     67shouldThrow("angle.newValueSpecifiedUnits(svgElement, svgElement)");
     68shouldThrow("angle.newValueSpecifiedUnits()");
    5369shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_UNSPECIFIED");
    5470
  • trunk/LayoutTests/svg/dom/script-tests/SVGAnimatedBoolean.js

    r70977 r71014  
    1 description("This test checks the SVGExternalResourcesRequired API");
     1description("This test checks the SVGAnimatedBoolean API - utilizing the externalResourcesRequired property of SVGRectElement");
    22
    33var rectElement = document.createElementNS("http://www.w3.org/2000/svg", "rect");
  • trunk/LayoutTests/svg/dom/script-tests/SVGAnimatedNumberList.js

    r70979 r71014  
    1818
    1919debug("");
    20 debug("Check assigning to baseVal has no effect, as no setter is defined");
     20debug("Check that assigning to baseVal has no effect, as no setter is defined");
    2121shouldBe("textElement.rotate.baseVal = -1", "-1");
    2222shouldBeEqualToString("textElement.rotate.baseVal = 'aString'", "aString");
  • trunk/WebCore/ChangeLog

    r71010 r71014  
     12010-11-01  Nikolas Zimmermann  <nzimmermann@rim.com>
     2
     3        Reviewed by Rob Buis.
     4
     5        Enable StrictTypeChecking for all types using SVG(Animated)PropertyTearOff
     6        https://bugs.webkit.org/show_bug.cgi?id=48715
     7
     8        Enable StrictTypeChecking for all readwrite attributes and function calls of all types using the new SVG(Animated)PropertyTearOff concept.
     9        Also enable RequiresAllArguments=Raise for all function calls of these new types. Cover this functionality by tests for each of them.
     10
     11        When testing SVGLength it became obvious that quite a lot of functionality was missing.
     12        Conversion from relative arguments (percentage, ems, exs) to user specified units was missing, added that functionality and tested it.
     13        User units to pt conversion was wrong, fixed that.
     14
     15        Tests: svg/dom/SVGAnimatedAngle.html
     16               svg/dom/SVGAnimatedBoolean.html
     17               svg/dom/SVGAnimatedEnumeration.html
     18               svg/dom/SVGAnimatedInteger.html
     19               svg/dom/SVGAnimatedLength.html
     20               svg/dom/SVGAnimatedLengthList.html
     21               svg/dom/SVGAnimatedRect.html
     22               svg/dom/SVGLength-px-with-context.html
     23               svg/dom/SVGLength-px.html
     24               svg/dom/SVGLength.html
     25
     26        * bindings/js/JSSVGLengthCustom.cpp: These SVGLength methods now take an ExceptionCode parameter, adapt to that.
     27        (WebCore::JSSVGLength::value):
     28        (WebCore::JSSVGLength::setValue):
     29        (WebCore::JSSVGLength::convertToSpecifiedUnits):
     30        * bindings/scripts/CodeGeneratorObjC.pm: Remove FIXMEs, pass real context instead off null pointer. DOMSVGLength::value is functional now.
     31        * bindings/v8/custom/V8SVGLengthCustom.cpp: These SVGLength methods now take an ExceptionCode parameter, adapt to that.
     32        (WebCore::V8SVGLength::valueAccessorGetter):
     33        (WebCore::V8SVGLength::valueAccessorSetter):
     34        (WebCore::V8SVGLength::convertToSpecifiedUnitsCallback):
     35        * rendering/style/SVGRenderStyle.h: Adapt to SVGLength API changes.
     36        (WebCore::SVGRenderStyle::initialBaselineShiftValue):
     37        (WebCore::SVGRenderStyle::initialKerning):
     38        (WebCore::SVGRenderStyle::initialStrokeDashOffset):
     39        (WebCore::SVGRenderStyle::initialStrokeWidth):
     40        * svg/SVGAngle.idl: Add StrictTypeChecking, RequiresAllArguments=Raise to all methods.
     41        * svg/SVGAnimatedBoolean.idl: Remove StrictTypeChecking from animVal, it's readonly so this is useless.
     42        * svg/SVGAnimatedEnumeration.idl: Add StrictTypeChecking to all attributes.
     43        * svg/SVGAnimatedInteger.idl: Ditto.
     44        * svg/SVGLength.cpp: Implement all missing features of SVGLength. Conform to our style guide (s/.0f// etc)
     45        (WebCore::lengthTypeToString):
     46        (WebCore::SVGLength::SVGLength):
     47        (WebCore::SVGLength::value): Throw NOT_SUPPORTED_ERR when trying to obtain to relative units, when no context is given (SVGLength created by createSVGLength()).
     48        (WebCore::SVGLength::setValue): Ditto, for the setter.
     49        (WebCore::SVGLength::valueAsPercentage): Use m_valueInSpecifiedUnits instead of valueInSpecifiedUnits().
     50        (WebCore::SVGLength::setValueAsString): Throw SYNTAX_ERR if parsing failed.
     51        (WebCore::SVGLength::valueAsString): Use makeString() instead of String and operator+.
     52        (WebCore::SVGLength::newValueSpecifiedUnits): Add ExceptionCode parameter, throw NOT_SUPPORTED_ERR, if the given unit type is invalid.
     53        (WebCore::SVGLength::convertToSpecifiedUnits): Ditto.
     54        (WebCore::SVGLength::determineViewport): Added helper function used by convertValue*Percentage*.
     55        (WebCore::SVGLength::convertValueFromUserUnitsToPercentage): Add new helper functions, used by value/setValue.
     56        (WebCore::SVGLength::convertValueFromPercentageToUserUnits): Ditto.
     57        (WebCore::SVGLength::convertValueFromUserUnitsToEMS): Ditto.
     58        (WebCore::SVGLength::convertValueFromEMSToUserUnits): Ditto.
     59        (WebCore::SVGLength::convertValueFromUserUnitsToEXS): Ditto.
     60        (WebCore::SVGLength::convertValueFromEXSToUserUnits): Ditto.
     61        (WebCore::SVGLength::fromCSSPrimitiveValue): Adapt to newValueSpecifiedUnits API change.
     62        (WebCore::SVGLength::toCSSPrimitiveValue): Remove default switch case.
     63        * svg/SVGLength.h:
     64        (WebCore::SVGLength::valueInSpecifiedUnits): Inlined.
     65        (WebCore::SVGLength::setValueInSpecifiedUnits): Ditto.
     66        (WebCore::SVGLength::isRelative):
     67        * svg/SVGLength.idl: Add StrictTypeChecking for all attributes/functions and RequiresAllArguments=Raise for all functions.
     68        * svg/SVGLengthList.cpp: Adapt to SVGLength API changes.
     69        (WebCore::SVGLengthList::parse):
     70
    1712010-10-31  Pavel Feldman  <pfeldman@chromium.org>
    272
  • trunk/WebCore/bindings/js/JSSVGLengthCustom.cpp

    r70496 r71014  
    2323#include "JSSVGLength.h"
    2424
     25#include <runtime/Error.h>
    2526#include "SVGAnimatedProperty.h"
     27#include "SVGException.h"
    2628
    2729using namespace JSC;
     
    2931namespace WebCore {
    3032
    31 JSValue JSSVGLength::value(ExecState*) const
     33JSValue JSSVGLength::value(ExecState* exec) const
    3234{
    3335    SVGLength& podImp = impl()->propertyReference();
    34     return jsNumber(podImp.value(impl()->contextElement()));
     36    ExceptionCode ec = 0;
     37    float value = podImp.value(impl()->contextElement(), ec);
     38    if (ec) {
     39        setDOMException(exec, ec);
     40        return jsUndefined();
     41    }
     42
     43    return jsNumber(value);
     44}
     45
     46void JSSVGLength::setValue(ExecState* exec, JSValue value)
     47{
     48    if (!value.isUndefinedOrNull() && !value.isNumber() && !value.isBoolean()) {
     49        throwVMTypeError(exec);
     50        return;
     51    }
     52
     53    SVGLength& podImp = impl()->propertyReference();
     54
     55    ExceptionCode ec = 0;
     56    podImp.setValue(value.toFloat(exec), impl()->contextElement(), ec);
     57    if (ec) {
     58        setDOMException(exec, ec);
     59        return;
     60    }
     61
     62    impl()->commitChange();
    3563}
    3664
     
    3866{
    3967    SVGLength& podImp = impl()->propertyReference();
    40     podImp.convertToSpecifiedUnits(exec->argument(0).toInt32(exec), impl()->contextElement());
     68
     69    // Mimic the behaviour of RequiresAllArguments=Raise.
     70    if (exec->argumentCount() < 1)
     71        return throwError(exec, createSyntaxError(exec, "Not enough arguments"));
     72
     73    unsigned short unitType = exec->argument(0).toUInt32(exec);
     74    if (exec->hadException())
     75        return jsUndefined();
     76
     77    ExceptionCode ec = 0;
     78    podImp.convertToSpecifiedUnits(unitType, impl()->contextElement(), ec);
     79    if (ec) {
     80        setDOMException(exec, ec);
     81        return jsUndefined();
     82    }
    4183
    4284    impl()->commitChange();
  • trunk/WebCore/bindings/scripts/CodeGeneratorObjC.pm

    r70979 r71014  
    1 #
     1# 
    22# Copyright (C) 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
    33# Copyright (C) 2006 Anders Carlsson <andersca@mac.com>
     
    12471247                # TODO: Handle special case for DOMSVGLength. We do need Custom code support for this.
    12481248                if ($svgPropertyType eq "WebCore::SVGLength" and $attributeName eq "value") {
    1249                     $getterContentHead = "value(0 /* FIXME */";
     1249                    $getterContentHead = "value(IMPL->contextElement(), ";
    12501250                }
    12511251            }
     
    13941394                        push(@implContent, "    podImpl = $arg;\n");
    13951395                    } else {
    1396                         push(@implContent, "    podImpl.$coreSetterName($arg$ec);\n");
     1396                        # FIXME: Special case for DOMSVGLength. We do need Custom code support for this.
     1397                        if ($svgPropertyType eq "WebCore::SVGLength" and $attributeName eq "value") {
     1398                            push(@implContent, "    podImpl.$coreSetterName($arg, IMPL->contextElement()$ec);\n");
     1399                        } else {
     1400                            push(@implContent, "    podImpl.$coreSetterName($arg$ec);\n");
     1401                        }
    13971402                    }
    13981403
     
    15291534            my $svgLengthConvertToSpecifiedUnits = ($svgPropertyType and $svgPropertyType eq "WebCore::SVGLength" and $functionName eq "convertToSpecifiedUnits");
    15301535
     1536            push(@parameterNames, "IMPL->contextElement()") if $svgLengthConvertToSpecifiedUnits;
    15311537            push(@parameterNames, "ec") if $raisesExceptions and !($svgMatrixRotateFromVector || $svgMatrixInverse);
    1532             push(@parameterNames, "0 /* FIXME */") if $svgLengthConvertToSpecifiedUnits;
    15331538
    15341539            # Handle arguments that are 'SVGProperty' based (SVGAngle/SVGLength). We need to convert from SVGPropertyTearOff<Type>* to Type,
  • trunk/WebCore/bindings/v8/custom/V8SVGLengthCustom.cpp

    r70223 r71014  
    3636#include "SVGPropertyTearOff.h"
    3737#include "V8Binding.h"
     38#include "V8BindingMacros.h"
    3839
    3940namespace WebCore {
     
    4142v8::Handle<v8::Value> V8SVGLength::valueAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
    4243{
    43     INC_STATS("DOM.SVGLength.value");
     44    INC_STATS("DOM.SVGLength.value._get");
    4445    SVGPropertyTearOff<SVGLength>* wrapper = V8SVGLength::toNative(info.Holder());
    4546    SVGLength& imp = wrapper->propertyReference();
    46     return v8::Number::New(imp.value(wrapper->contextElement()));
     47    ExceptionCode ec = 0;
     48    float value = imp.value(wrapper->contextElement(), ec);
     49    if (UNLIKELY(ec)) {
     50        V8Proxy::setDOMException(ec);
     51        return v8::Handle<v8::Value>();
     52    }
     53    return v8::Number::New(value);
     54}
     55
     56void V8SVGLength::valueAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
     57{
     58    INC_STATS("DOM.SVGLength.value._set");
     59    if (!isUndefinedOrNull(value) && !value->IsNumber() && !value->IsBoolean()) {
     60        V8Proxy::throwTypeError();
     61        return;
     62    }
     63
     64    SVGPropertyTearOff<SVGLength>* wrapper = V8SVGLength::toNative(info.Holder());
     65    SVGLength& imp = wrapper->propertyReference();
     66    ExceptionCode ec = 0;
     67    imp.setValue(static_cast<float>(value->NumberValue()), wrapper->contextElement(), ec);
     68    if (UNLIKELY(ec))
     69        V8Proxy::setDOMException(ec);
     70    else
     71        wrapper->commitChange();
    4772}
    4873
     
    5075{
    5176    INC_STATS("DOM.SVGLength.convertToSpecifiedUnits");
     77    if (args.Length() < 1)
     78        return throwError("Not enough arguments", V8Proxy::SyntaxError);
     79
    5280    SVGPropertyTearOff<SVGLength>* wrapper = V8SVGLength::toNative(args.Holder());
    5381    SVGLength& imp = wrapper->propertyReference();
    54     imp.convertToSpecifiedUnits(toInt32(args[0]), wrapper->contextElement());
    55     wrapper->commitChange();
    56     return v8::Undefined();
     82    ExceptionCode ec = 0;
     83    EXCEPTION_BLOCK(int, unitType, toUInt32(args[0]));
     84    imp.convertToSpecifiedUnits(unitType, wrapper->contextElement(), ec);
     85    if (UNLIKELY(ec))
     86        V8Proxy::setDOMException(ec);
     87    else
     88        wrapper->commitChange();
     89    return v8::Handle<v8::Value>();
    5790}
    5891
  • trunk/WebCore/rendering/style/SVGRenderStyle.h

    r69220 r71014  
    9393    {
    9494        SVGLength length;
    95         length.newValueSpecifiedUnits(LengthTypeNumber, 0);
     95        ExceptionCode ec = 0;
     96        length.newValueSpecifiedUnits(LengthTypeNumber, 0, ec);
     97        ASSERT(!ec);
    9698        return length;
    9799    }
     
    100102    {
    101103        SVGLength length;
    102         length.newValueSpecifiedUnits(LengthTypeNumber, 0);
     104        ExceptionCode ec = 0;
     105        length.newValueSpecifiedUnits(LengthTypeNumber, 0, ec);
     106        ASSERT(!ec);
    103107        return length;
    104108    }
     
    107111    {
    108112        SVGLength length;
    109         length.newValueSpecifiedUnits(LengthTypeNumber, 0);
     113        ExceptionCode ec = 0;
     114        length.newValueSpecifiedUnits(LengthTypeNumber, 0, ec);
     115        ASSERT(!ec);
    110116        return length;
    111117    }
     
    114120    {
    115121        SVGLength length;
    116         length.newValueSpecifiedUnits(LengthTypeNumber, 1);
     122        ExceptionCode ec = 0;
     123        length.newValueSpecifiedUnits(LengthTypeNumber, 1, ec);
     124        ASSERT(!ec);
    117125        return length;
    118126    }
  • trunk/WebCore/svg/SVGAngle.idl

    r70631 r71014  
    3838            setter raises(DOMException);
    3939
    40         void newValueSpecifiedUnits(in unsigned short unitType, in float valueInSpecifiedUnits)
     40        [StrictTypeChecking, RequiresAllArguments=Raise] void newValueSpecifiedUnits(in unsigned short unitType, in float valueInSpecifiedUnits)
    4141            raises(DOMException);
    4242
    43         void convertToSpecifiedUnits(in unsigned short unitType)
     43        [StrictTypeChecking, RequiresAllArguments=Raise] void convertToSpecifiedUnits(in unsigned short unitType)
    4444            raises(DOMException);
    4545    };
  • trunk/WebCore/svg/SVGAnimatedBoolean.idl

    r70857 r71014  
    2828    interface [Conditional=SVG] SVGAnimatedBoolean {
    2929        attribute [StrictTypeChecking] boolean baseVal;
    30         readonly attribute [StrictTypeChecking] boolean animVal;
     30        readonly attribute boolean animVal;
    3131    };
    3232
  • trunk/WebCore/svg/SVGAnimatedEnumeration.idl

    r70872 r71014  
    2727
    2828    interface [Conditional=SVG] SVGAnimatedEnumeration {
    29         attribute unsigned short baseVal;
     29        attribute [StrictTypeChecking] unsigned short baseVal;
    3030        readonly attribute unsigned short animVal;
    3131    };
  • trunk/WebCore/svg/SVGAnimatedInteger.idl

    r64579 r71014  
    2727
    2828    interface [Conditional=SVG] SVGAnimatedInteger {
    29                  attribute long baseVal
    30                      /*setter raises(DOMException)*/;
     29        attribute [StrictTypeChecking] long baseVal;
    3130        readonly attribute long animVal;
    3231    };
  • trunk/WebCore/svg/SVGLength.cpp

    r68307 r71014  
    2828#include "FloatConversion.h"
    2929#include "FrameView.h"
    30 #include "NotImplemented.h"
    3130#include "RenderObject.h"
    3231#include "RenderView.h"
     
    3433#include "SVGSVGElement.h"
    3534
    36 #include <math.h>
    37 #include <wtf/Assertions.h>
     35#include <wtf/MathExtras.h>
     36#include <wtf/text/StringConcatenate.h>
    3837
    3938namespace WebCore {
     
    8483    }
    8584
     85    ASSERT_NOT_REACHED();
    8686    return String();
    8787}
     
    127127
    128128SVGLength::SVGLength(SVGLengthMode mode, const String& valueAsString)
    129     : m_valueInSpecifiedUnits(0.0f)
     129    : m_valueInSpecifiedUnits(0)
    130130    , m_unit(storeUnit(mode, LengthTypeNumber))
    131131{
    132     setValueAsString(valueAsString);
     132    ExceptionCode ec = 0;
     133    setValueAsString(valueAsString, ec);
    133134}
    134135
     
    157158float SVGLength::value(const SVGElement* context) const
    158159{
    159     SVGLengthType type = extractType(m_unit);
    160     if (type == LengthTypeUnknown)
    161         return 0.0f;
    162 
    163     switch (type) {
     160    ExceptionCode ec = 0;
     161    return value(context, ec);
     162}
     163
     164float SVGLength::value(const SVGElement* context, ExceptionCode& ec) const
     165{
     166    switch (extractType(m_unit)) {
     167    case LengthTypeUnknown:
     168        ec = NOT_SUPPORTED_ERR;
     169        return 0;
    164170    case LengthTypeNumber:
    165171        return m_valueInSpecifiedUnits;
    166172    case LengthTypePercentage:
    167         return SVGLength::PercentageOfViewport(m_valueInSpecifiedUnits / 100.0f, context, extractMode(m_unit));
     173        return convertValueFromPercentageToUserUnits(m_valueInSpecifiedUnits / 100, context, ec);
    168174    case LengthTypeEMS:
     175        return convertValueFromEMSToUserUnits(m_valueInSpecifiedUnits, context, ec);
    169176    case LengthTypeEXS:
    170     {
    171         RenderStyle* style = 0;
    172         if (context && context->renderer())
    173             style = context->renderer()->style();
    174         if (style) {
    175             float useSize = style->fontSize();
    176             ASSERT(useSize > 0);
    177             if (type == LengthTypeEMS)
    178                 return m_valueInSpecifiedUnits * useSize;
    179             else {
    180                 float xHeight = style->font().xHeight();
    181                 // Use of ceil allows a pixel match to the W3Cs expected output of coords-units-03-b.svg
    182                 // if this causes problems in real world cases maybe it would be best to remove this
    183                 return m_valueInSpecifiedUnits * ceilf(xHeight);
    184             }
    185         }
    186         return 0.0f;
    187     }
     177        return convertValueFromEXSToUserUnits(m_valueInSpecifiedUnits, context, ec);
    188178    case LengthTypePX:
    189179        return m_valueInSpecifiedUnits;
     
    195185        return m_valueInSpecifiedUnits * cssPixelsPerInch;
    196186    case LengthTypePT:
    197         return m_valueInSpecifiedUnits / 72.0f * cssPixelsPerInch;
     187        return m_valueInSpecifiedUnits / 72 * cssPixelsPerInch;
    198188    case LengthTypePC:
    199         return m_valueInSpecifiedUnits / 6.0f * cssPixelsPerInch;
    200     default:
    201         break;
     189        return m_valueInSpecifiedUnits / 6 * cssPixelsPerInch;
    202190    }
    203191
    204192    ASSERT_NOT_REACHED();
    205     return 0.0f;
    206 }
    207 
    208 void SVGLength::setValue(float value)
    209 {
    210     SVGLengthType type = extractType(m_unit);
    211     ASSERT(type != LengthTypeUnknown);
    212 
    213     switch (type) {
     193    return 0;
     194}
     195
     196void SVGLength::setValue(float value, const SVGElement* context, ExceptionCode& ec)
     197{
     198    switch (extractType(m_unit)) {
     199    case LengthTypeUnknown:
     200        ec = NOT_SUPPORTED_ERR;
     201        break;
    214202    case LengthTypeNumber:
    215203        m_valueInSpecifiedUnits = value;
    216204        break;
    217205    case LengthTypePercentage:
     206    {
     207        float result = convertValueFromUserUnitsToPercentage(value, context, ec);
     208        if (!ec)
     209            m_valueInSpecifiedUnits = result;
     210        break;
     211    }
    218212    case LengthTypeEMS:
     213    {
     214        float result = convertValueFromUserUnitsToEMS(value, context, ec);
     215        if (!ec)
     216            m_valueInSpecifiedUnits = result;
     217        break;
     218    }
    219219    case LengthTypeEXS:
    220         notImplemented();
    221         break;
     220    {
     221        float result = convertValueFromUserUnitsToEXS(value, context, ec);
     222        if (!ec)
     223            m_valueInSpecifiedUnits = result;
     224        break;
     225    }
    222226    case LengthTypePX:
    223227        m_valueInSpecifiedUnits = value;
     
    233237        break;
    234238    case LengthTypePT:
    235         m_valueInSpecifiedUnits = value * 72.0f / cssPixelsPerInch;
     239        m_valueInSpecifiedUnits = value * 72 / cssPixelsPerInch;
    236240        break;
    237241    case LengthTypePC:
    238         m_valueInSpecifiedUnits = value / 6.0f * cssPixelsPerInch;
    239         break;
    240     default:
    241         break;
    242     }
    243 }
    244 
    245 void SVGLength::setValueInSpecifiedUnits(float value)
    246 {
    247     m_valueInSpecifiedUnits = value;
    248 }
    249 
    250 float SVGLength::valueInSpecifiedUnits() const
    251 {
    252     return m_valueInSpecifiedUnits;
     242        m_valueInSpecifiedUnits = value * 6 / cssPixelsPerInch;
     243        break;
     244    }
    253245}
    254246
     
    257249    // 100% = 100.0 instead of 1.0 for historical reasons, this could eventually be changed
    258250    if (extractType(m_unit) == LengthTypePercentage)
    259         return valueInSpecifiedUnits() / 100.0f;
    260 
    261     return valueInSpecifiedUnits();
    262 }
    263 
    264 bool SVGLength::setValueAsString(const String& s)
    265 {
    266     if (s.isEmpty())
    267         return false;
    268 
    269     float convertedNumber = 0.0f;
    270     const UChar* ptr = s.characters();
    271     const UChar* end = ptr + s.length();
    272 
    273     if (!parseNumber(ptr, end, convertedNumber, false))
    274         return false;
     251        return m_valueInSpecifiedUnits / 100;
     252
     253    return m_valueInSpecifiedUnits;
     254}
     255
     256void SVGLength::setValueAsString(const String& string, ExceptionCode& ec)
     257{
     258    if (string.isEmpty())
     259        return;
     260
     261    float convertedNumber = 0;
     262    const UChar* ptr = string.characters();
     263    const UChar* end = ptr + string.length();
     264
     265    if (!parseNumber(ptr, end, convertedNumber, false)) {
     266        ec = SYNTAX_ERR;
     267        return;
     268    }
    275269
    276270    SVGLengthType type = stringToLengthType(ptr, end);
    277     if (type == LengthTypeUnknown)
    278         return false;
     271    if (type == LengthTypeUnknown) {
     272        ec = SYNTAX_ERR;
     273        return;
     274    }
    279275
    280276    m_unit = storeUnit(extractMode(m_unit), type);
    281277    m_valueInSpecifiedUnits = convertedNumber;
    282     return true;
    283278}
    284279
    285280String SVGLength::valueAsString() const
    286281{
    287     return String::number(m_valueInSpecifiedUnits) + lengthTypeToString(extractType(m_unit));
    288 }
    289 
    290 void SVGLength::newValueSpecifiedUnits(unsigned short type, float value)
    291 {
    292     if (type == LengthTypeUnknown || type > LengthTypePC)
    293         return;
    294 
    295     m_unit = storeUnit(extractMode(m_unit), (SVGLengthType) type);
     282    return makeString(String::number(m_valueInSpecifiedUnits), lengthTypeToString(extractType(m_unit)));
     283}
     284
     285void SVGLength::newValueSpecifiedUnits(unsigned short type, float value, ExceptionCode& ec)
     286{
     287    if (type == LengthTypeUnknown || type > LengthTypePC) {
     288        ec = NOT_SUPPORTED_ERR;
     289        return;
     290    }
     291
     292    m_unit = storeUnit(extractMode(m_unit), static_cast<SVGLengthType>(type));
    296293    m_valueInSpecifiedUnits = value;
    297294}
    298295
    299 void SVGLength::convertToSpecifiedUnits(unsigned short type, const SVGElement* context)
    300 {
    301     if (type == LengthTypeUnknown || type > LengthTypePC)
    302         return;
    303 
    304     float valueInUserUnits = value(context);
    305     m_unit = storeUnit(extractMode(m_unit), (SVGLengthType) type);
    306     setValue(valueInUserUnits);
    307 }
    308 
    309 float SVGLength::PercentageOfViewport(float value, const SVGElement* context, SVGLengthMode mode)
    310 {
    311     ASSERT(context);
    312 
    313     float width = 0.0f, height = 0.0f;
    314     SVGElement* viewportElement = context->viewportElement();
    315 
    316     // PercentageOfViewport() is used to resolve all relative-positioned values within a SVG document (fragment)
    317     Document* doc = context->document();
    318     if (doc->documentElement() == context) {
    319         // Resolve value against outermost <svg> element
    320         if (RenderView* view = toRenderView(doc->renderer())) {
     296void SVGLength::convertToSpecifiedUnits(unsigned short type, const SVGElement* context, ExceptionCode& ec)
     297{
     298    if (type == LengthTypeUnknown || type > LengthTypePC) {
     299        ec = NOT_SUPPORTED_ERR;
     300        return;
     301    }
     302
     303    float valueInUserUnits = value(context, ec);
     304    if (ec)
     305        return;
     306
     307    unsigned int originalUnitAndType = m_unit;   
     308    m_unit = storeUnit(extractMode(m_unit), static_cast<SVGLengthType>(type));
     309    setValue(valueInUserUnits, context, ec);
     310    if (!ec)
     311        return;
     312
     313    // Eventually restore old unit and type
     314    m_unit = originalUnitAndType;
     315}
     316
     317bool SVGLength::determineViewport(const SVGElement* context, float& width, float& height) const
     318{
     319    if (!context)
     320        return false;
     321
     322    // Take size from outermost <svg> element.
     323    Document* document = context->document();
     324    if (document->documentElement() == context) {
     325        if (RenderView* view = toRenderView(document->renderer())) {
    321326            width = view->viewWidth();
    322327            height = view->viewHeight();
    323          }
    324     } else if (viewportElement && viewportElement->isSVG()) {
    325         // Resolve value against nearest viewport element (common case: inner <svg> elements)
     328            return true;
     329        }
     330
     331        return false;
     332    }
     333
     334    // Resolve value against nearest viewport element (common case: inner <svg> elements)
     335    SVGElement* viewportElement = context->viewportElement();
     336    if (viewportElement && viewportElement->isSVG()) {
    326337        const SVGSVGElement* svg = static_cast<const SVGSVGElement*>(viewportElement);
    327338        if (svg->hasAttribute(SVGNames::viewBoxAttr)) {
     
    332343            height = svg->height().value(svg);
    333344        }
    334     } else if (context->parent() && !context->parent()->isSVGElement()) {
    335         // Resolve value against enclosing non-SVG RenderBox
    336         if (RenderObject* renderer = context->renderer()) {
    337             if (renderer->isBox()) {
    338                 RenderBox* box = toRenderBox(renderer);
    339                 width = box->width();
    340                 height = box->height();
    341             }
    342         }
    343     }
    344 
    345     if (mode == LengthModeWidth)
     345
     346        return true;
     347    }
     348   
     349    // Resolve value against enclosing non-SVG RenderBox
     350    if (!context->parent() || context->parent()->isSVGElement())
     351        return false;
     352
     353    RenderObject* renderer = context->renderer();
     354    if (!renderer || !renderer->isBox())
     355        return false;
     356
     357    RenderBox* box = toRenderBox(renderer);
     358    width = box->width();
     359    height = box->height();
     360    return true;
     361}
     362
     363float SVGLength::convertValueFromUserUnitsToPercentage(float value, const SVGElement* context, ExceptionCode& ec) const
     364{
     365    float width = 0;
     366    float height = 0;
     367    if (!determineViewport(context, width, height)) {
     368        ec = NOT_SUPPORTED_ERR;
     369        return 0;
     370    }
     371
     372    switch (extractMode(m_unit)) {
     373    case LengthModeWidth:
     374        return value / width * 100;
     375    case LengthModeHeight:
     376        return value / height * 100;
     377    case LengthModeOther:
     378        return value / (sqrtf((width * width + height * height) / 2)) * 100;
     379    };
     380
     381    ASSERT_NOT_REACHED();
     382    return 0;
     383}
     384
     385float SVGLength::convertValueFromPercentageToUserUnits(float value, const SVGElement* context, ExceptionCode& ec) const
     386{
     387    float width = 0;
     388    float height = 0;
     389    if (!determineViewport(context, width, height)) {
     390        ec = NOT_SUPPORTED_ERR;
     391        return 0;
     392    }
     393
     394    switch (extractMode(m_unit)) {
     395    case LengthModeWidth:
    346396        return value * width;
    347     else if (mode == LengthModeHeight)
     397    case LengthModeHeight:
    348398        return value * height;
    349     else if (mode == LengthModeOther)
    350         return value * sqrtf(powf(width, 2) + powf(height, 2)) / sqrtf(2.0f);
    351 
    352     return 0.0f;
     399    case LengthModeOther:
     400        return value * sqrtf((width * width + height * height) / 2);
     401    };
     402
     403    ASSERT_NOT_REACHED();
     404    return 0;
     405}
     406
     407float SVGLength::convertValueFromUserUnitsToEMS(float value, const SVGElement* context, ExceptionCode& ec) const
     408{
     409    if (!context || !context->renderer() || !context->renderer()->style()) {
     410        ec = NOT_SUPPORTED_ERR;
     411        return 0;
     412    }
     413
     414    RenderStyle* style = context->renderer()->style();
     415    float fontSize = style->fontSize();
     416    if (!fontSize) {
     417        ec = NOT_SUPPORTED_ERR;
     418        return 0;
     419    }
     420
     421    return value / fontSize;
     422}
     423
     424float SVGLength::convertValueFromEMSToUserUnits(float value, const SVGElement* context, ExceptionCode& ec) const
     425{
     426    if (!context || !context->renderer() || !context->renderer()->style()) {
     427        ec = NOT_SUPPORTED_ERR;
     428        return 0;
     429    }
     430
     431    RenderStyle* style = context->renderer()->style();
     432    return value * style->fontSize();
     433}
     434
     435float SVGLength::convertValueFromUserUnitsToEXS(float value, const SVGElement* context, ExceptionCode& ec) const
     436{
     437    if (!context || !context->renderer() || !context->renderer()->style()) {
     438        ec = NOT_SUPPORTED_ERR;
     439        return 0;
     440    }
     441
     442    RenderStyle* style = context->renderer()->style();
     443
     444    // Use of ceil allows a pixel match to the W3Cs expected output of coords-units-03-b.svg
     445    // if this causes problems in real world cases maybe it would be best to remove this
     446    float xHeight = ceilf(style->font().xHeight());
     447    if (!xHeight) {
     448        ec = NOT_SUPPORTED_ERR;
     449        return 0;
     450    }
     451
     452    return value / xHeight;
     453}
     454
     455float SVGLength::convertValueFromEXSToUserUnits(float value, const SVGElement* context, ExceptionCode& ec) const
     456{
     457    if (!context || !context->renderer() || !context->renderer()->style()) {
     458        ec = NOT_SUPPORTED_ERR;
     459        return 0;
     460    }
     461
     462    RenderStyle* style = context->renderer()->style();
     463    // Use of ceil allows a pixel match to the W3Cs expected output of coords-units-03-b.svg
     464    // if this causes problems in real world cases maybe it would be best to remove this
     465    return value * ceilf(style->font().xHeight());
    353466}
    354467
     
    398511        return SVGLength();
    399512
     513    ExceptionCode ec = 0;
    400514    SVGLength length;
    401     length.newValueSpecifiedUnits(svgType, value->getFloatValue());
     515    length.newValueSpecifiedUnits(svgType, value->getFloatValue(), ec);
     516    if (ec)   
     517        return SVGLength();
     518
    402519    return length;
    403520}
     
    439556        cssType = CSSPrimitiveValue::CSS_PC;
    440557        break;
    441     default:
    442         ASSERT_NOT_REACHED();
    443558    };
    444559
  • trunk/WebCore/svg/SVGLength.h

    r64830 r71014  
    2323
    2424#if ENABLE(SVG)
    25 #include "PlatformString.h"
     25#include "ExceptionCode.h"
     26#include <wtf/text/WTFString.h>
    2627
    2728namespace WebCore {
     
    7778
    7879    float value(const SVGElement* context) const;
    79     void setValue(float);
     80    float value(const SVGElement* context, ExceptionCode&) const;
     81    void setValue(float, const SVGElement* context, ExceptionCode&);
    8082
    81     float valueInSpecifiedUnits() const;
    82     void setValueInSpecifiedUnits(float);
    83    
     83    float valueInSpecifiedUnits() const { return m_valueInSpecifiedUnits; }
     84    void setValueInSpecifiedUnits(float value) { m_valueInSpecifiedUnits = value; }
     85
    8486    float valueAsPercentage() const;
    8587
    8688    String valueAsString() const;
    87     bool setValueAsString(const String&);
     89    void setValueAsString(const String&, ExceptionCode&);
    8890
    89     void newValueSpecifiedUnits(unsigned short, float valueInSpecifiedUnits);
    90     void convertToSpecifiedUnits(unsigned short, const SVGElement* context);
     91    void newValueSpecifiedUnits(unsigned short, float valueInSpecifiedUnits, ExceptionCode&);
     92    void convertToSpecifiedUnits(unsigned short, const SVGElement* context, ExceptionCode&);
    9193
    9294    // Helper functions
    93     static float PercentageOfViewport(float value, const SVGElement* context, SVGLengthMode);
    94 
    9595    inline bool isRelative() const
    9696    {
    9797        SVGLengthType type = unitType();
    98         return (type == LengthTypePercentage || type == LengthTypeEMS || type == LengthTypeEXS);
     98        return type == LengthTypePercentage || type == LengthTypeEMS || type == LengthTypeEXS;
    9999    }
    100100
    101101    static SVGLength fromCSSPrimitiveValue(CSSPrimitiveValue*);
    102102    static PassRefPtr<CSSPrimitiveValue> toCSSPrimitiveValue(const SVGLength&);
     103
     104private:
     105    bool determineViewport(const SVGElement* context, float& width, float& height) const;
     106
     107    float convertValueFromPercentageToUserUnits(float value, const SVGElement* context, ExceptionCode&) const;
     108    float convertValueFromUserUnitsToPercentage(float value, const SVGElement* context, ExceptionCode&) const;
     109
     110    float convertValueFromUserUnitsToEMS(float value, const SVGElement* context, ExceptionCode&) const;
     111    float convertValueFromEMSToUserUnits(float value, const SVGElement* context, ExceptionCode&) const;
     112
     113    float convertValueFromUserUnitsToEXS(float value, const SVGElement* context, ExceptionCode&) const;
     114    float convertValueFromEXSToUserUnits(float value, const SVGElement* context, ExceptionCode&) const;
    103115
    104116private:
  • trunk/WebCore/svg/SVGLength.idl

    r70631 r71014  
    3838
    3939        readonly attribute unsigned short unitType;
    40         attribute [CustomGetter] float value;
    41         attribute float valueInSpecifiedUnits;
    42         attribute [ConvertNullToNullString] DOMString valueAsString;
     40        attribute [Custom, StrictTypeChecking] float value
     41            setter raises(DOMException),
     42            getter raises(DOMException);
    4343
    44         void newValueSpecifiedUnits(in unsigned short unitType,
    45                                     in float valueInSpecifiedUnits);
     44        attribute [StrictTypeChecking] float valueInSpecifiedUnits;
     45        attribute [ConvertNullToNullString, StrictTypeChecking] DOMString valueAsString
     46            setter raises(DOMException);
    4647
    47         [Custom] void convertToSpecifiedUnits(in unsigned short unitType);
     48        [StrictTypeChecking, RequiresAllArguments=Raise] void newValueSpecifiedUnits(in unsigned short unitType,
     49                                                         in float valueInSpecifiedUnits)
     50            raises(DOMException);
     51
     52        [Custom, StrictTypeChecking, RequiresAllArguments=Raise] void convertToSpecifiedUnits(in unsigned short unitType)
     53            raises(DOMException);
    4854    };
    4955
  • trunk/WebCore/svg/SVGLengthList.cpp

    r70223 r71014  
    3232{
    3333    clear();
     34    ExceptionCode ec = 0;
    3435
    3536    const UChar* ptr = value.characters();
     
    4142        if (ptr == start)
    4243            break;
     44
    4345        SVGLength length(mode);
    44         if (!length.setValueAsString(String(start, ptr - start)))
     46        String valueString(start, ptr - start);
     47        if (valueString.isEmpty())
     48            return;
     49        length.setValueAsString(valueString, ec);
     50        if (ec)
    4551            return;
    4652        append(length);
Note: See TracChangeset for help on using the changeset viewer.