Changeset 64830 in webkit


Ignore:
Timestamp:
Aug 6, 2010 4:21:20 AM (14 years ago)
Author:
Nikolas Zimmermann
Message:

2010-08-06 Nikolas Zimmermann <nzimmermann@rim.com>

Reviewed by Dirk Schulze.

SVG - stroke-width:0 bug with stroke other than "none"
https://bugs.webkit.org/show_bug.cgi?id=42387

Stop storing refcounted CSSValue/CSSValueList objects in SVGRenderStyle, replacing them with SVGLength types.
Allows us to directly specify default values for stroke-dashoffset/width in the SVGRenderStyle, fixing a problem
with stroke-width animations when resetting to the original stored baseVal, exposed in svg/W3C-1.1/animate-elem-40-t.svg
Originally discovered by Fady Samuel.

Test: svg/custom/path-zero-strokewidth.svg

  • css/SVGCSSComputedStyleDeclaration.cpp: (WebCore::strokeDashArrayToCSSValueList): New helper function converting from Vector<SVGLength> to CSSValueList. (WebCore::CSSComputedStyleDeclaration::getSVGPropertyCSSValue): Convert SVGLength values to CSSPrimitiveValues.
  • css/SVGCSSStyleSelector.cpp: (WebCore::CSSStyleSelector::applySVGProperty): Convert CSSPrimitiveValues to SVGLength objects, for SVGRenderStyle storage.
  • rendering/RenderPath.cpp: (WebCore::RenderPath::calculateMarkerBoundsIfNeeded): Just grab strokeWidth SVGLength value from SVGRenderSTyle, no need to call cssPrimitiveToLength anymore.
  • rendering/RenderSVGText.cpp: (WebCore::RenderSVGText::strokeBoundingBox): Ditto.
  • rendering/SVGCharacterLayoutInfo.cpp: (WebCore::calculateBaselineShift): Ditto (for baseline-shift).
  • rendering/SVGInlineTextBox.cpp: (WebCore::SVGInlineTextBox::buildLayoutInformation): Ditto (for kerning).
  • rendering/SVGRenderSupport.cpp: (WebCore::SVGRenderSupport::applyStrokeStyleToContext): Ditto (for stroke-width/stroke-dashoffset/stroke-dasharray).
  • rendering/SVGRenderSupport.h:
  • rendering/SVGRenderTreeAsText.cpp: (WebCore::writeStyle): Ditto.
  • rendering/SVGTextLayoutUtilities.cpp: (WebCore::calculateCSSKerning): Ditto.
  • rendering/SVGTextLayoutUtilities.h:
  • rendering/style/SVGRenderStyle.cpp: Remove no longer needed cssPrimitiveToLength function.
  • rendering/style/SVGRenderStyle.h: Stop storing RefPtr<CSSValue> / RefPtr<CSSValueList> but use SVGLength/Vector<SVGLength>. (WebCore::SVGRenderStyle::initialStrokeDashArray): Allows us to specify correct default values, instead of null pointers. (WebCore::SVGRenderStyle::initialBaselineShiftValue): Specify 0px default value. (WebCore::SVGRenderStyle::initialKerning): Ditto. (WebCore::SVGRenderStyle::initialStrokeDashOffset): Ditto. (WebCore::SVGRenderStyle::initialStrokeWidth): Specify 1px default value. (WebCore::SVGRenderStyle::setStrokeDashArray): Takes a Vector<SVGLength> now, not a PassRefPtr<CSSValueList>. (WebCore::SVGRenderStyle::setStrokeWidth): Takes a SVGLength now, not a PassRefPtr<CSSValue>. (WebCore::SVGRenderStyle::setStrokeDashOffset): Ditto. (WebCore::SVGRenderStyle::setKerning): Ditto. (WebCore::SVGRenderStyle::setStopColor): Pass Color as const-reference. (WebCore::SVGRenderStyle::setFloodColor): Ditto. (WebCore::SVGRenderStyle::setLightingColor): Ditto. (WebCore::SVGRenderStyle::setBaselineShiftValue): Takes a SVGLength now, not a PassRefPtr<CSSValue>. (WebCore::SVGRenderStyle::setShadow): Reformat, had wrong style. (WebCore::SVGRenderStyle::setClipperResource): Pass String as const-reference. (WebCore::SVGRenderStyle::setFilterResource): Ditto. (WebCore::SVGRenderStyle::setMaskerResource): Ditto. (WebCore::SVGRenderStyle::setMarkerStartResource): Ditto. (WebCore::SVGRenderStyle::setMarkerMidResource): Ditto. (WebCore::SVGRenderStyle::setMarkerEndResource): Ditto. (WebCore::SVGRenderStyle::strokeDashArray): Return Vector<SVGLength>. (WebCore::SVGRenderStyle::strokeWidth): Return SVGLength. (WebCore::SVGRenderStyle::strokeDashOffset): Ditto. (WebCore::SVGRenderStyle::kerning): Ditto. (WebCore::SVGRenderStyle::baselineShiftValue): Ditto.
  • rendering/style/SVGRenderStyleDefs.cpp: (WebCore::StyleStrokeData::StyleStrokeData): Changed initialization order, to group stroke properties.
  • rendering/style/SVGRenderStyleDefs.h: Store SVGLength values instead of reference counted CSS objects.
  • svg/SVGLength.cpp: (WebCore::SVGLength::SVGLength): Add copy constructor. (WebCore::SVGLength::operator==): Add comparision operator. (WebCore::SVGLength::operator!=): Ditto. (WebCore::SVGLength::fromCSSPrimitiveValue): New static helper function to convert from a CSSPrimitiveValue. (WebCore::SVGLength::toCSSPrimitiveValue): New static helper function to convert to a CSSPrimitiveValue.
  • svg/SVGLength.h: Reindent.

2010-08-06 Nikolas Zimmermann <nzimmermann@rim.com>

Reviewed by Dirk Schulze.

SVG - stroke-width:0 bug with stroke other than "none"
https://bugs.webkit.org/show_bug.cgi?id=42387

  • platform/mac-leopard/svg/W3C-SVG-1.1/animate-elem-40-t-expected.checksum: Updated result, as fill="freeze" and stroke-width now works as expected.
  • platform/mac-leopard/svg/W3C-SVG-1.1/animate-elem-40-t-expected.png: Ditto.
  • platform/mac/fast/css/getComputedStyle/computed-style-expected.txt: kerning reports 0, stroke-dashoffset 0, stroke-width 1 instead of empty values.
  • platform/mac/fast/css/getComputedStyle/computed-style-without-renderer-expected.txt: Ditto.
  • platform/mac/svg/W3C-SVG-1.1/animate-elem-40-t-expected.txt: Updated result, as fill="freeze" and stroke-width now works as expected.
  • platform/mac/svg/custom/path-zero-strokewidth-expected.checksum: Added.
  • platform/mac/svg/custom/path-zero-strokewidth-expected.png: Added.
  • platform/mac/svg/custom/path-zero-strokewidth-expected.txt: Added.
  • svg/css/getComputedStyle-basic-expected.txt: An empty stroke-dasharray reports "none", as defined in the spec now.
  • svg/custom/path-zero-strokewidth.svg: Added.
Location:
trunk
Files:
4 added
25 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r64828 r64830  
     12010-08-06  Nikolas Zimmermann  <nzimmermann@rim.com>
     2
     3        Reviewed by Dirk Schulze.
     4
     5        SVG - stroke-width:0 bug with stroke other than "none"
     6        https://bugs.webkit.org/show_bug.cgi?id=42387
     7
     8        * platform/mac-leopard/svg/W3C-SVG-1.1/animate-elem-40-t-expected.checksum: Updated result, as fill="freeze" and stroke-width now works as expected.
     9        * platform/mac-leopard/svg/W3C-SVG-1.1/animate-elem-40-t-expected.png: Ditto.
     10        * platform/mac/fast/css/getComputedStyle/computed-style-expected.txt: kerning reports 0, stroke-dashoffset 0, stroke-width 1 instead of empty values.
     11        * platform/mac/fast/css/getComputedStyle/computed-style-without-renderer-expected.txt: Ditto.
     12        * platform/mac/svg/W3C-SVG-1.1/animate-elem-40-t-expected.txt: Updated result, as fill="freeze" and stroke-width now works as expected.
     13        * platform/mac/svg/custom/path-zero-strokewidth-expected.checksum: Added.
     14        * platform/mac/svg/custom/path-zero-strokewidth-expected.png: Added.
     15        * platform/mac/svg/custom/path-zero-strokewidth-expected.txt: Added.
     16        * svg/css/getComputedStyle-basic-expected.txt: An empty stroke-dasharray reports "none", as defined in the spec now.
     17        * svg/custom/path-zero-strokewidth.svg: Added.
     18
    1192010-08-05  Marcus Bulach  <bulach@chromium.org>
    220
  • trunk/LayoutTests/platform/mac-leopard/svg/W3C-SVG-1.1/animate-elem-40-t-expected.checksum

    r63721 r64830  
    1 85ddcb5e223a8f0afb4e155b798b782b
     1cc0120156f9e039da3b6643a16557377
  • trunk/LayoutTests/platform/mac/fast/css/getComputedStyle/computed-style-expected.txt

    r60885 r64830  
    195195stroke: none;
    196196stroke-dasharray: ;
    197 stroke-dashoffset: ;
     197stroke-dashoffset: 0;
    198198stroke-linecap: butt;
    199199stroke-linejoin: miter;
    200200stroke-miterlimit: 4;
    201201stroke-opacity: 1;
    202 stroke-width: ;
     202stroke-width: 1;
    203203alignment-baseline: auto;
    204204baseline-shift: baseline;
    205205dominant-baseline: auto;
    206 kerning: ;
     206kerning: 0;
    207207text-anchor: start;
    208208writing-mode: lr-tb;
  • trunk/LayoutTests/platform/mac/fast/css/getComputedStyle/computed-style-without-renderer-expected.txt

    r60885 r64830  
    194194    stroke: none
    195195    stroke-dasharray:
    196     stroke-dashoffset:
     196    stroke-dashoffset: 0
    197197    stroke-linecap: butt
    198198    stroke-linejoin: miter
    199199    stroke-miterlimit: 4
    200200    stroke-opacity: 1
    201     stroke-width:
     201    stroke-width: 1
    202202    alignment-baseline: auto
    203203    baseline-shift: baseline
    204204    dominant-baseline: auto
    205     kerning:
     205    kerning: 0
    206206    text-anchor: start
    207207    writing-mode: lr-tb
  • trunk/LayoutTests/platform/mac/svg/W3C-SVG-1.1/animate-elem-40-t-expected.txt

    r61393 r64830  
    152152          RenderSVGInlineText {#text} at (0,0) size 104x18
    153153            chunk 1 (middle anchor) text run 1 at (-51.50,60.00) startOffset 0 endOffset 16 width 103.00: "x/y on <text>(2)"
    154       RenderSVGContainer {g} at (138,168) size 82x121 [transform={m=((1.00,0.00)(0.00,1.00)) t=(180.00,210.00)}]
     154      RenderSVGContainer {g} at (138,168) size 83x121 [transform={m=((1.00,0.00)(0.00,1.00)) t=(180.00,210.00)}]
    155155        RenderSVGImage {image} at (140,170) size 50x50
    156156        RenderPath {rect} at (138,168) size 54x54 [stroke={[type=SOLID] [color=#FFB400] [stroke width=4.00]}] [data="M-40.00,-40.00 L10.00,-40.00 L10.00,10.00 L-40.00,10.00 Z"]
    157         RenderPath {rect} at (140,170) size 80x20 [stroke={[type=SOLID] [color=#FFB400] [stroke width=0.00]}] [data="M-40.00,-40.00 L40.00,-40.00 L40.00,-20.00 L-40.00,-20.00 Z"]
    158         RenderPath {rect} at (140,170) size 20x80 [stroke={[type=SOLID] [color=#FFB400] [stroke width=0.00]}] [data="M-40.00,-40.00 L-20.00,-40.00 L-20.00,40.00 L-40.00,40.00 Z"]
     157        RenderPath {rect} at (139,169) size 82x22 [stroke={[type=SOLID] [color=#FFB400]}] [data="M-40.00,-40.00 L40.00,-40.00 L40.00,-20.00 L-40.00,-20.00 Z"]
     158        RenderPath {rect} at (139,169) size 22x82 [stroke={[type=SOLID] [color=#FFB400]}] [data="M-40.00,-40.00 L-20.00,-40.00 L-20.00,40.00 L-40.00,40.00 Z"]
    159159        RenderSVGText {text} at (-40,46) size 80x18 contains 1 chunk(s)
    160160          RenderSVGInlineText {#text} at (0,0) size 80x18
     
    163163          RenderSVGInlineText {#text} at (0,0) size 76x18
    164164            chunk 1 (middle anchor) text run 1 at (-38.00,75.00) startOffset 0 endOffset 10 width 76.00: "on <image>"
    165       RenderSVGContainer {g} at (258,168) size 82x121 [transform={m=((1.00,0.00)(0.00,1.00)) t=(300.00,210.00)}]
     165      RenderSVGContainer {g} at (258,168) size 83x121 [transform={m=((1.00,0.00)(0.00,1.00)) t=(300.00,210.00)}]
    166166        RenderPath {rect} at (260,170) size 50x50 [fill={[type=SOLID] [color=#808080]}] [data="M-40.00,-40.00 L10.00,-40.00 L10.00,10.00 L-40.00,10.00 Z"]
    167167        RenderPath {rect} at (258,168) size 54x54 [stroke={[type=SOLID] [color=#FFB400] [stroke width=4.00]}] [data="M-40.00,-40.00 L10.00,-40.00 L10.00,10.00 L-40.00,10.00 Z"]
    168         RenderPath {rect} at (260,170) size 80x20 [stroke={[type=SOLID] [color=#FFB400] [stroke width=0.00]}] [data="M-40.00,-40.00 L40.00,-40.00 L40.00,-20.00 L-40.00,-20.00 Z"]
    169         RenderPath {rect} at (260,170) size 20x80 [stroke={[type=SOLID] [color=#FFB400] [stroke width=0.00]}] [data="M-40.00,-40.00 L-20.00,-40.00 L-20.00,40.00 L-40.00,40.00 Z"]
     168        RenderPath {rect} at (259,169) size 82x22 [stroke={[type=SOLID] [color=#FFB400]}] [data="M-40.00,-40.00 L40.00,-40.00 L40.00,-20.00 L-40.00,-20.00 Z"]
     169        RenderPath {rect} at (259,169) size 22x82 [stroke={[type=SOLID] [color=#FFB400]}] [data="M-40.00,-40.00 L-20.00,-40.00 L-20.00,40.00 L-40.00,40.00 Z"]
    170170        RenderSVGText {text} at (-40,46) size 80x18 contains 1 chunk(s)
    171171          RenderSVGInlineText {#text} at (0,0) size 80x18
  • trunk/LayoutTests/svg/css/getComputedStyle-basic-expected.txt

    r60885 r64830  
    385385rect: style.getPropertyValue(stroke) : #FFA500
    386386rect: style.getPropertyCSSValue(stroke) : [object SVGPaint]
    387 rect: style.getPropertyValue(stroke-dasharray) :
    388 rect: style.getPropertyCSSValue(stroke-dasharray) : null
    389 rect: style.getPropertyValue(stroke-dashoffset) :
    390 rect: style.getPropertyCSSValue(stroke-dashoffset) : null
     387rect: style.getPropertyValue(stroke-dasharray) : none
     388rect: style.getPropertyCSSValue(stroke-dasharray) : [object CSSPrimitiveValue]
     389rect: style.getPropertyValue(stroke-dashoffset) : 0
     390rect: style.getPropertyCSSValue(stroke-dashoffset) : [object CSSPrimitiveValue]
    391391rect: style.getPropertyValue(stroke-linecap) : butt
    392392rect: style.getPropertyCSSValue(stroke-linecap) : [object CSSPrimitiveValue]
     
    405405rect: style.getPropertyValue(dominant-baseline) : auto
    406406rect: style.getPropertyCSSValue(dominant-baseline) : [object CSSPrimitiveValue]
    407 rect: style.getPropertyValue(kerning) :
    408 rect: style.getPropertyCSSValue(kerning) : null
     407rect: style.getPropertyValue(kerning) : 0
     408rect: style.getPropertyCSSValue(kerning) : [object CSSPrimitiveValue]
    409409rect: style.getPropertyValue(text-anchor) : start
    410410rect: style.getPropertyCSSValue(text-anchor) : [object CSSPrimitiveValue]
     
    805805g: style.getPropertyValue(stroke) : #FFA500
    806806g: style.getPropertyCSSValue(stroke) : [object SVGPaint]
    807 g: style.getPropertyValue(stroke-dasharray) :
    808 g: style.getPropertyCSSValue(stroke-dasharray) : null
    809 g: style.getPropertyValue(stroke-dashoffset) :
    810 g: style.getPropertyCSSValue(stroke-dashoffset) : null
     807g: style.getPropertyValue(stroke-dasharray) : none
     808g: style.getPropertyCSSValue(stroke-dasharray) : [object CSSPrimitiveValue]
     809g: style.getPropertyValue(stroke-dashoffset) : 0
     810g: style.getPropertyCSSValue(stroke-dashoffset) : [object CSSPrimitiveValue]
    811811g: style.getPropertyValue(stroke-linecap) : butt
    812812g: style.getPropertyCSSValue(stroke-linecap) : [object CSSPrimitiveValue]
     
    825825g: style.getPropertyValue(dominant-baseline) : auto
    826826g: style.getPropertyCSSValue(dominant-baseline) : [object CSSPrimitiveValue]
    827 g: style.getPropertyValue(kerning) :
    828 g: style.getPropertyCSSValue(kerning) : null
     827g: style.getPropertyValue(kerning) : 0
     828g: style.getPropertyCSSValue(kerning) : [object CSSPrimitiveValue]
    829829g: style.getPropertyValue(text-anchor) : start
    830830g: style.getPropertyCSSValue(text-anchor) : [object CSSPrimitiveValue]
  • trunk/WebCore/ChangeLog

    r64829 r64830  
     12010-08-06  Nikolas Zimmermann  <nzimmermann@rim.com>
     2
     3        Reviewed by Dirk Schulze.
     4
     5        SVG - stroke-width:0 bug with stroke other than "none"
     6        https://bugs.webkit.org/show_bug.cgi?id=42387
     7
     8        Stop storing refcounted CSSValue/CSSValueList objects in SVGRenderStyle, replacing them with SVGLength types.
     9        Allows us to directly specify default values for stroke-dashoffset/width in the SVGRenderStyle, fixing a problem
     10        with stroke-width animations when resetting to the original stored baseVal, exposed in svg/W3C-1.1/animate-elem-40-t.svg
     11        Originally discovered by Fady Samuel.
     12
     13        Test: svg/custom/path-zero-strokewidth.svg
     14
     15        * css/SVGCSSComputedStyleDeclaration.cpp:
     16        (WebCore::strokeDashArrayToCSSValueList): New helper function converting from Vector<SVGLength> to CSSValueList.
     17        (WebCore::CSSComputedStyleDeclaration::getSVGPropertyCSSValue): Convert SVGLength values to CSSPrimitiveValues.
     18        * css/SVGCSSStyleSelector.cpp:
     19        (WebCore::CSSStyleSelector::applySVGProperty): Convert CSSPrimitiveValues to SVGLength objects, for SVGRenderStyle storage.
     20        * rendering/RenderPath.cpp:
     21        (WebCore::RenderPath::calculateMarkerBoundsIfNeeded): Just grab strokeWidth SVGLength value from SVGRenderSTyle, no need to call cssPrimitiveToLength anymore.
     22        * rendering/RenderSVGText.cpp:
     23        (WebCore::RenderSVGText::strokeBoundingBox): Ditto.
     24        * rendering/SVGCharacterLayoutInfo.cpp:
     25        (WebCore::calculateBaselineShift): Ditto (for baseline-shift).
     26        * rendering/SVGInlineTextBox.cpp:
     27        (WebCore::SVGInlineTextBox::buildLayoutInformation): Ditto (for kerning).
     28        * rendering/SVGRenderSupport.cpp:
     29        (WebCore::SVGRenderSupport::applyStrokeStyleToContext): Ditto (for stroke-width/stroke-dashoffset/stroke-dasharray).
     30        * rendering/SVGRenderSupport.h:
     31        * rendering/SVGRenderTreeAsText.cpp:
     32        (WebCore::writeStyle): Ditto.
     33        * rendering/SVGTextLayoutUtilities.cpp:
     34        (WebCore::calculateCSSKerning): Ditto.
     35        * rendering/SVGTextLayoutUtilities.h:
     36        * rendering/style/SVGRenderStyle.cpp: Remove no longer needed cssPrimitiveToLength function.
     37        * rendering/style/SVGRenderStyle.h: Stop storing RefPtr<CSSValue> / RefPtr<CSSValueList> but use SVGLength/Vector<SVGLength>.
     38        (WebCore::SVGRenderStyle::initialStrokeDashArray): Allows us to specify correct default values, instead of null pointers.
     39        (WebCore::SVGRenderStyle::initialBaselineShiftValue): Specify 0px default value.
     40        (WebCore::SVGRenderStyle::initialKerning): Ditto.
     41        (WebCore::SVGRenderStyle::initialStrokeDashOffset): Ditto.
     42        (WebCore::SVGRenderStyle::initialStrokeWidth): Specify 1px default value.
     43        (WebCore::SVGRenderStyle::setStrokeDashArray): Takes a Vector<SVGLength> now, not a PassRefPtr<CSSValueList>.
     44        (WebCore::SVGRenderStyle::setStrokeWidth): Takes a SVGLength now, not a PassRefPtr<CSSValue>.
     45        (WebCore::SVGRenderStyle::setStrokeDashOffset): Ditto.
     46        (WebCore::SVGRenderStyle::setKerning): Ditto.
     47        (WebCore::SVGRenderStyle::setStopColor): Pass Color as const-reference.
     48        (WebCore::SVGRenderStyle::setFloodColor): Ditto.
     49        (WebCore::SVGRenderStyle::setLightingColor): Ditto.
     50        (WebCore::SVGRenderStyle::setBaselineShiftValue): Takes a SVGLength now, not a PassRefPtr<CSSValue>.
     51        (WebCore::SVGRenderStyle::setShadow): Reformat, had wrong style.
     52        (WebCore::SVGRenderStyle::setClipperResource): Pass String as const-reference.
     53        (WebCore::SVGRenderStyle::setFilterResource): Ditto.
     54        (WebCore::SVGRenderStyle::setMaskerResource): Ditto.
     55        (WebCore::SVGRenderStyle::setMarkerStartResource): Ditto.
     56        (WebCore::SVGRenderStyle::setMarkerMidResource): Ditto.
     57        (WebCore::SVGRenderStyle::setMarkerEndResource): Ditto.
     58        (WebCore::SVGRenderStyle::strokeDashArray): Return Vector<SVGLength>.
     59        (WebCore::SVGRenderStyle::strokeWidth): Return SVGLength.
     60        (WebCore::SVGRenderStyle::strokeDashOffset): Ditto.
     61        (WebCore::SVGRenderStyle::kerning): Ditto.
     62        (WebCore::SVGRenderStyle::baselineShiftValue): Ditto.
     63        * rendering/style/SVGRenderStyleDefs.cpp:
     64        (WebCore::StyleStrokeData::StyleStrokeData): Changed initialization order, to group stroke properties.
     65        * rendering/style/SVGRenderStyleDefs.h: Store SVGLength values instead of reference counted CSS objects.
     66        * svg/SVGLength.cpp:
     67        (WebCore::SVGLength::SVGLength): Add copy constructor.
     68        (WebCore::SVGLength::operator==): Add comparision operator.
     69        (WebCore::SVGLength::operator!=): Ditto.
     70        (WebCore::SVGLength::fromCSSPrimitiveValue): New static helper function to convert from a CSSPrimitiveValue.
     71        (WebCore::SVGLength::toCSSPrimitiveValue): New static helper function to convert to a CSSPrimitiveValue.
     72        * svg/SVGLength.h: Reindent.
     73
    1742010-08-06  Luiz Agostini  <luiz.agostini@openbossa.org>
    275
  • trunk/WebCore/css/SVGCSSComputedStyleDeclaration.cpp

    r60885 r64830  
    4545            return 0;
    4646    }
     47}
     48
     49static PassRefPtr<CSSValue> strokeDashArrayToCSSValueList(const Vector<SVGLength>& dashes)
     50{
     51    if (dashes.isEmpty())
     52        return CSSPrimitiveValue::createIdentifier(CSSValueNone);
     53
     54    RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
     55    const Vector<SVGLength>::const_iterator end = dashes.end();
     56    for (Vector<SVGLength>::const_iterator it = dashes.begin(); it != end; ++it)
     57        list->append(SVGLength::toCSSPrimitiveValue(*it));
     58
     59    return list.release();
    4760}
    4861
     
    123136            return svgStyle->fillPaint();
    124137        case CSSPropertyKerning:
    125             return svgStyle->kerning();
     138            return SVGLength::toCSSPrimitiveValue(svgStyle->kerning());
    126139        case CSSPropertyMarkerEnd:
    127140            if (!svgStyle->markerEndResource().isEmpty())
     
    139152            return svgStyle->strokePaint();
    140153        case CSSPropertyStrokeDasharray:
    141             return svgStyle->strokeDashArray();
     154            return strokeDashArrayToCSSValueList(svgStyle->strokeDashArray());
    142155        case CSSPropertyStrokeDashoffset:
    143             return svgStyle->strokeDashOffset();
     156            return SVGLength::toCSSPrimitiveValue(svgStyle->strokeDashOffset());
    144157        case CSSPropertyStrokeWidth:
    145             return svgStyle->strokeWidth();
     158            return SVGLength::toCSSPrimitiveValue(svgStyle->strokeWidth());
    146159        case CSSPropertyBaselineShift: {
    147160            switch (svgStyle->baselineShift()) {
     
    153166                    return CSSPrimitiveValue::createIdentifier(CSSValueSub);
    154167                case BS_LENGTH:
    155                     return svgStyle->baselineShiftValue();
     168                    return SVGLength::toCSSPrimitiveValue(svgStyle->baselineShiftValue());
    156169            }
    157170        }
  • trunk/WebCore/css/SVGCSSStyleSelector.cpp

    r60885 r64830  
    154154            } else {
    155155                svgstyle->setBaselineShift(BS_LENGTH);
    156                 svgstyle->setBaselineShiftValue(primitiveValue);
     156                svgstyle->setBaselineShiftValue(SVGLength::fromCSSPrimitiveValue(primitiveValue));
    157157            }
    158158
     
    162162        {
    163163            HANDLE_INHERIT_AND_INITIAL(kerning, Kerning);
    164             svgstyle->setKerning(primitiveValue);
     164            svgstyle->setKerning(SVGLength::fromCSSPrimitiveValue(primitiveValue));
    165165            break;
    166166        }
     
    248248            HANDLE_INHERIT_AND_INITIAL(strokeWidth, StrokeWidth)
    249249            if (primitiveValue)
    250                 svgstyle->setStrokeWidth(primitiveValue);
     250                svgstyle->setStrokeWidth(SVGLength::fromCSSPrimitiveValue(primitiveValue));
    251251            break;
    252252        }
     
    254254        {
    255255            HANDLE_INHERIT_AND_INITIAL(strokeDashArray, StrokeDashArray)
    256             if (value->isValueList())
    257                 svgstyle->setStrokeDashArray(static_cast<CSSValueList*>(value));
     256            if (!value->isValueList())
     257                break;
     258
     259            CSSValueList* dashes = static_cast<CSSValueList*>(value);
     260
     261            Vector<SVGLength> array;
     262            size_t length = dashes->length();
     263            for (size_t i = 0; i < length; ++i) {
     264                CSSPrimitiveValue* dash = static_cast<CSSPrimitiveValue*>(dashes->itemWithoutBoundsCheck(i));
     265                if (!dash)
     266                    continue;
     267
     268                array.append(SVGLength::fromCSSPrimitiveValue(dash));
     269            }
     270
     271            svgstyle->setStrokeDashArray(array);
    258272            break;
    259273        }
     
    262276            HANDLE_INHERIT_AND_INITIAL(strokeDashOffset, StrokeDashOffset)
    263277            if (primitiveValue)
    264                 svgstyle->setStrokeDashOffset(primitiveValue);
     278                svgstyle->setStrokeDashOffset(SVGLength::fromCSSPrimitiveValue(primitiveValue));
    265279            break;
    266280        }
  • trunk/WebCore/rendering/RenderPath.cpp

    r64275 r64830  
    258258        return FloatRect();
    259259
    260     float strokeWidth = SVGRenderStyle::cssPrimitiveToLength(this, svgStyle->strokeWidth(), 1.0f);
    261     return m_markerLayoutInfo.calculateBoundaries(markerStart, markerMid, markerEnd, strokeWidth, m_path);
     260    return m_markerLayoutInfo.calculateBoundaries(markerStart, markerMid, markerEnd, svgStyle->strokeWidth().value(svgElement), m_path);
    262261}
    263262
  • trunk/WebCore/rendering/RenderSVGText.cpp

    r64275 r64830  
    164164{
    165165    FloatRect strokeBoundaries = objectBoundingBox();
    166     if (!style()->svgStyle()->hasStroke())
     166    const SVGRenderStyle* svgStyle = style()->svgStyle();
     167    if (!svgStyle->hasStroke())
    167168        return strokeBoundaries;
    168169
    169     strokeBoundaries.inflate(SVGRenderStyle::cssPrimitiveToLength(this, style()->svgStyle()->strokeWidth(), 1.0f));
     170    ASSERT(node());
     171    ASSERT(node()->isSVGElement());
     172    strokeBoundaries.inflate(svgStyle->strokeWidth().value(static_cast<SVGElement*>(node())));
    170173    return strokeBoundaries;
    171174}
  • trunk/WebCore/rendering/SVGCharacterLayoutInfo.cpp

    r61393 r64830  
    3838static float calculateBaselineShift(RenderObject* item)
    3939{
     40    ASSERT(item);
     41    ASSERT(item->style());
     42    ASSERT(item->node());
     43    ASSERT(item->node()->isSVGElement());
     44
    4045    const Font& font = item->style()->font();
    4146    const SVGRenderStyle* svgStyle = item->style()->svgStyle();
     
    4348    float baselineShift = 0.0f;
    4449    if (svgStyle->baselineShift() == BS_LENGTH) {
    45         CSSPrimitiveValue* primitive = static_cast<CSSPrimitiveValue*>(svgStyle->baselineShiftValue());
    46         baselineShift = primitive->getFloatValue();
    47 
    48         if (primitive->primitiveType() == CSSPrimitiveValue::CSS_PERCENTAGE)
    49             baselineShift = baselineShift / 100.0f * font.pixelSize();
     50        SVGLength baselineShiftValueLength = svgStyle->baselineShiftValue();
     51        if (baselineShiftValueLength.unitType() == LengthTypePercentage)
     52            baselineShift = baselineShiftValueLength.valueAsPercentage() * font.pixelSize();
     53        else
     54            baselineShift = baselineShiftValueLength.value(static_cast<SVGElement*>(item->node()));
    5055    } else {
    5156        float baselineAscent = font.ascent() + font.descent();
  • trunk/WebCore/rendering/SVGInlineTextBox.cpp

    r64275 r64830  
    639639    ASSERT(style);
    640640
     641    RenderObject* parentRenderer = parent()->renderer();
     642    ASSERT(parentRenderer);
     643    ASSERT(parentRenderer->node());
     644    ASSERT(parentRenderer->node()->isSVGElement());
     645    SVGElement* lengthContext = static_cast<SVGElement*>(parentRenderer->node());
     646
    641647    const Font& font = style->font();
    642648    const UChar* characters = textRenderer->characters();
     
    710716
    711717        // Take letter & word spacing and kerning into account
    712         float spacing = font.letterSpacing() + calculateCSSKerning(style);
     718        float spacing = font.letterSpacing() + calculateCSSKerning(lengthContext, style);
    713719
    714720        const UChar* currentCharacter = characters + (textDirection == RTL ? endPosition - i : startPosition + i);
  • trunk/WebCore/rendering/SVGRenderSupport.cpp

    r64277 r64830  
    321321}
    322322
    323 DashArray SVGRenderSupport::dashArrayFromRenderingStyle(const RenderStyle* style, RenderStyle* rootStyle)
    324 {
    325     DashArray array;
    326    
    327     CSSValueList* dashes = style->svgStyle()->strokeDashArray();
    328     if (!dashes)
    329         return array;
    330 
    331     CSSPrimitiveValue* dash = 0;
    332     unsigned long len = dashes->length();
    333     for (unsigned long i = 0; i < len; ++i) {
    334         dash = static_cast<CSSPrimitiveValue*>(dashes->itemWithoutBoundsCheck(i));
    335         if (!dash)
    336             continue;
    337 
    338         array.append(dash->computeLengthFloat(const_cast<RenderStyle*>(style), rootStyle));
    339     }
    340 
    341     return array;
    342 }
    343 
    344323void SVGRenderSupport::applyStrokeStyleToContext(GraphicsContext* context, const RenderStyle* style, const RenderObject* object)
    345324{
    346     context->setStrokeThickness(SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeWidth(), 1.0f));
    347     context->setLineCap(style->svgStyle()->capStyle());
    348     context->setLineJoin(style->svgStyle()->joinStyle());
    349     if (style->svgStyle()->joinStyle() == MiterJoin)
    350         context->setMiterLimit(style->svgStyle()->strokeMiterLimit());
    351 
    352     const DashArray& dashes = dashArrayFromRenderingStyle(object->style(), object->document()->documentElement()->renderStyle());
    353     float dashOffset = SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeDashOffset(), 0.0f);
     325    ASSERT(context);
     326    ASSERT(style);
     327    ASSERT(object);
     328    ASSERT(object->node());
     329    ASSERT(object->node()->isSVGElement());
     330
     331    const SVGRenderStyle* svgStyle = style->svgStyle();
     332    ASSERT(svgStyle);
     333
     334    SVGElement* lengthContext = static_cast<SVGElement*>(object->node());
     335    context->setStrokeThickness(svgStyle->strokeWidth().value(lengthContext));
     336    context->setLineCap(svgStyle->capStyle());
     337    context->setLineJoin(svgStyle->joinStyle());
     338    if (svgStyle->joinStyle() == MiterJoin)
     339        context->setMiterLimit(svgStyle->strokeMiterLimit());
     340
     341    const Vector<SVGLength>& dashes = svgStyle->strokeDashArray();
    354342    if (dashes.isEmpty())
    355343        context->setStrokeStyle(SolidStroke);
    356     else
    357         context->setLineDash(dashes, dashOffset);
     344    else {
     345        DashArray dashArray;
     346        const Vector<SVGLength>::const_iterator end = dashes.end();
     347        for (Vector<SVGLength>::const_iterator it = dashes.begin(); it != end; ++it)
     348            dashArray.append((*it).value(lengthContext));
     349
     350        context->setLineDash(dashArray, svgStyle->strokeDashOffset().value(lengthContext));
     351    }
    358352}
    359353
  • trunk/WebCore/rendering/SVGRenderSupport.h

    r64275 r64830  
    2727
    2828#if ENABLE(SVG)
    29 #include "DashArray.h"
    3029#include "PaintInfo.h"
    3130
     
    8281    // FIXME: These methods do not belong here.
    8382    static const RenderObject* findTextRootObject(const RenderObject* start);
    84     static DashArray dashArrayFromRenderingStyle(const RenderStyle* style, RenderStyle* rootStyle);
    8583
    8684private:
  • trunk/WebCore/rendering/SVGRenderTreeAsText.cpp

    r64275 r64830  
    366366    if (object.isRenderPath()) {
    367367        const RenderPath& path = static_cast<const RenderPath&>(object);
     368        ASSERT(path.node());
     369        ASSERT(path.node()->isSVGElement());
    368370
    369371        if (RenderSVGResource* strokePaintingResource = RenderSVGResource::strokePaintingResource(const_cast<RenderPath*>(&path), path.style())) {
     
    372374            writeSVGPaintingResource(ts, strokePaintingResource);
    373375
    374             double dashOffset = SVGRenderStyle::cssPrimitiveToLength(&path, svgStyle->strokeDashOffset(), 0.0f);
    375             const DashArray& dashArray = SVGRenderSupport::dashArrayFromRenderingStyle(style, object.document()->documentElement()->renderStyle());
    376             double strokeWidth = SVGRenderStyle::cssPrimitiveToLength(&path, svgStyle->strokeWidth(), 1.0f);
     376            SVGElement* element = static_cast<SVGElement*>(path.node());
     377            double dashOffset = svgStyle->strokeDashOffset().value(element);
     378            double strokeWidth = svgStyle->strokeWidth().value(element);
     379            const Vector<SVGLength>& dashes = svgStyle->strokeDashArray();
     380
     381            DashArray dashArray;
     382            const Vector<SVGLength>::const_iterator end = dashes.end();
     383            for (Vector<SVGLength>::const_iterator it = dashes.begin(); it != end; ++it)
     384                dashArray.append((*it).value(element));
    377385
    378386            writeIfNotDefault(ts, "opacity", svgStyle->strokeOpacity(), 1.0f);
  • trunk/WebCore/rendering/SVGTextLayoutUtilities.cpp

    r61393 r64830  
    316316}
    317317
    318 float calculateCSSKerning(const RenderStyle* style)
     318float calculateCSSKerning(SVGElement* context, const RenderStyle* style)
    319319{
    320320    const Font& font = style->font();
    321321    const SVGRenderStyle* svgStyle = style->svgStyle();
    322322
    323     float kerning = 0.0f;
    324     if (CSSPrimitiveValue* primitive = static_cast<CSSPrimitiveValue*>(svgStyle->kerning())) {
    325         kerning = primitive->getFloatValue();
    326 
    327         if (primitive->primitiveType() == CSSPrimitiveValue::CSS_PERCENTAGE && font.pixelSize())
    328             kerning = kerning / 100.0f * font.pixelSize();
    329     }
    330 
    331     return kerning;
     323    SVGLength kerningLength = svgStyle->kerning();
     324    if (kerningLength.unitType() == LengthTypePercentage)
     325        return kerningLength.valueAsPercentage() * font.pixelSize();
     326
     327    return kerningLength.value(context);
    332328}
    333329
  • trunk/WebCore/rendering/SVGTextLayoutUtilities.h

    r61393 r64830  
    3333class RenderObject;
    3434class RenderStyle;
     35class SVGElement;
    3536class SVGRenderStyle;
    3637class TextRun;
     
    6162TextRun svgTextRunForInlineTextBox(const UChar*, int length, const RenderStyle*, const InlineTextBox*);
    6263
    63 float calculateCSSKerning(const RenderStyle*);
     64float calculateCSSKerning(SVGElement* context, const RenderStyle*);
    6465bool applySVGKerning(SVGCharacterLayoutInfo&, const RenderStyle*, SVGLastGlyphInfo&, const String& unicodeString, const String& glyphName, bool isVerticalText);
    6566
  • trunk/WebCore/rendering/style/SVGRenderStyle.cpp

    r64275 r64830  
    212212}
    213213
    214 float SVGRenderStyle::cssPrimitiveToLength(const RenderObject* item, CSSValue* value, float defaultValue)
    215 {
    216     CSSPrimitiveValue* primitive = static_cast<CSSPrimitiveValue*>(value);
    217 
    218     unsigned short cssType = (primitive ? primitive->primitiveType() : (unsigned short) CSSPrimitiveValue::CSS_UNKNOWN);
    219     if (!(cssType > CSSPrimitiveValue::CSS_UNKNOWN && cssType <= CSSPrimitiveValue::CSS_PC))
    220         return defaultValue;
    221 
    222     if (cssType == CSSPrimitiveValue::CSS_PERCENTAGE) {
    223         SVGStyledElement* element = static_cast<SVGStyledElement*>(item->node());
    224         SVGElement* viewportElement = (element ? element->viewportElement() : 0);
    225         if (viewportElement) {
    226             float result = primitive->getFloatValue() / 100.0f;
    227             return SVGLength::PercentageOfViewport(result, element, LengthModeOther);
    228         }
    229     }
    230 
    231     return primitive->computeLengthFloat(const_cast<RenderStyle*>(item->style()), item->document()->documentElement()->renderStyle());
    232 }
    233 
    234214static void getSVGShadowExtent(ShadowData* shadow, float& top, float& right, float& bottom, float& left)
    235215{
  • trunk/WebCore/rendering/style/SVGRenderStyle.h

    r64367 r64830  
    7979    static float initialStrokeOpacity() { return 1.0f; }
    8080    static SVGPaint* initialStrokePaint() { return SVGPaint::defaultStroke(); }
    81     static CSSValueList* initialStrokeDashArray() { return 0; }
     81    static Vector<SVGLength> initialStrokeDashArray() { return Vector<SVGLength>(); }
    8282    static float initialStrokeMiterLimit() { return 4.0f; }
    83     static CSSValue* initialStrokeWidth() { return 0; }
    84     static CSSValue* initialStrokeDashOffset() { return 0; };
    85     static CSSValue* initialKerning() { return 0; }
    8683    static float initialStopOpacity() { return 1.0f; }
    8784    static Color initialStopColor() { return Color(0, 0, 0); }
     
    8986    static Color initialFloodColor() { return Color(0, 0, 0); }
    9087    static Color initialLightingColor() { return Color(255, 255, 255); }
    91     static CSSValue* initialBaselineShiftValue() { return 0; }
    9288    static ShadowData* initialShadow() { return 0; }
    9389    static String initialClipperResource() { return String(); }
     
    9793    static String initialMarkerMidResource() { return String(); }
    9894    static String initialMarkerEndResource() { return String(); }
     95
     96    static SVGLength initialBaselineShiftValue()
     97    {
     98        SVGLength length;
     99        length.newValueSpecifiedUnits(LengthTypeNumber, 0);
     100        return length;
     101    }
     102
     103    static SVGLength initialKerning()
     104    {
     105        SVGLength length;
     106        length.newValueSpecifiedUnits(LengthTypeNumber, 0);
     107        return length;
     108    }
     109
     110    static SVGLength initialStrokeDashOffset()
     111    {
     112        SVGLength length;
     113        length.newValueSpecifiedUnits(LengthTypeNumber, 0);
     114        return length;
     115    }
     116
     117    static SVGLength initialStrokeWidth()
     118    {
     119        SVGLength length;
     120        length.newValueSpecifiedUnits(LengthTypeNumber, 1);
     121        return length;
     122    }
    99123
    100124    // SVG CSS Property setters
     
    141165    }
    142166
    143     void setStrokeDashArray(PassRefPtr<CSSValueList> obj)
     167    void setStrokeDashArray(const Vector<SVGLength>& obj)
    144168    {
    145169        if (!(stroke->dashArray == obj))
     
    153177    }
    154178
    155     void setStrokeWidth(PassRefPtr<CSSValue> obj)
     179    void setStrokeWidth(const SVGLength& obj)
    156180    {
    157181        if (!(stroke->width == obj))
     
    159183    }
    160184
    161     void setStrokeDashOffset(PassRefPtr<CSSValue> obj)
     185    void setStrokeDashOffset(const SVGLength& obj)
    162186    {
    163187        if (!(stroke->dashOffset == obj))
     
    165189    }
    166190
    167     void setKerning(PassRefPtr<CSSValue> obj)
     191    void setKerning(const SVGLength& obj)
    168192    {
    169193        if (!(text->kerning == obj))
     
    177201    }
    178202
    179     void setStopColor(Color obj)
     203    void setStopColor(const Color& obj)
    180204    {
    181205        if (!(stops->color == obj))
     
    189213    }
    190214
    191     void setFloodColor(Color obj)
     215    void setFloodColor(const Color& obj)
    192216    {
    193217        if (!(misc->floodColor == obj))
     
    195219    }
    196220
    197     void setLightingColor(Color obj)
     221    void setLightingColor(const Color& obj)
    198222    {
    199223        if (!(misc->lightingColor == obj))
     
    201225    }
    202226
    203     void setBaselineShiftValue(PassRefPtr<CSSValue> obj)
     227    void setBaselineShiftValue(const SVGLength& obj)
    204228    {
    205229        if (!(misc->baselineShiftValue == obj))
     
    207231    }
    208232
    209     void setShadow(PassOwnPtr<ShadowData> obj) { shadowSVG.access()->shadow = obj;
    210     }
     233    void setShadow(PassOwnPtr<ShadowData> obj) { shadowSVG.access()->shadow = obj; }
    211234
    212235    // Setters for non-inherited resources
    213     void setClipperResource(String obj)
     236    void setClipperResource(const String& obj)
    214237    {
    215238        if (!(resources->clipper == obj))
     
    217240    }
    218241
    219     void setFilterResource(String obj)
     242    void setFilterResource(const String& obj)
    220243    {
    221244        if (!(resources->filter == obj))
     
    223246    }
    224247
    225     void setMaskerResource(String obj)
     248    void setMaskerResource(const String& obj)
    226249    {
    227250        if (!(resources->masker == obj))
     
    230253
    231254    // Setters for inherited resources
    232     void setMarkerStartResource(String obj)
     255    void setMarkerStartResource(const String& obj)
    233256    {
    234257        if (!(inheritedResources->markerStart == obj))
     
    236259    }
    237260
    238     void setMarkerMidResource(String obj)
     261    void setMarkerMidResource(const String& obj)
    239262    {
    240263        if (!(inheritedResources->markerMid == obj))
     
    242265    }
    243266
    244     void setMarkerEndResource(String obj)
     267    void setMarkerEndResource(const String& obj)
    245268    {
    246269        if (!(inheritedResources->markerEnd == obj))
     
    270293    float strokeOpacity() const { return stroke->opacity; }
    271294    SVGPaint* strokePaint() const { return stroke->paint.get(); }
    272     CSSValueList* strokeDashArray() const { return stroke->dashArray.get(); }
     295    Vector<SVGLength> strokeDashArray() const { return stroke->dashArray; }
    273296    float strokeMiterLimit() const { return stroke->miterLimit; }
    274     CSSValue* strokeWidth() const { return stroke->width.get(); }
    275     CSSValue* strokeDashOffset() const { return stroke->dashOffset.get(); }
    276     CSSValue* kerning() const { return text->kerning.get(); }
     297    SVGLength strokeWidth() const { return stroke->width; }
     298    SVGLength strokeDashOffset() const { return stroke->dashOffset; }
     299    SVGLength kerning() const { return text->kerning; }
    277300    float stopOpacity() const { return stops->opacity; }
    278301    Color stopColor() const { return stops->color; }
     
    280303    Color floodColor() const { return misc->floodColor; }
    281304    Color lightingColor() const { return misc->lightingColor; }
    282     CSSValue* baselineShiftValue() const { return misc->baselineShiftValue.get(); }
     305    SVGLength baselineShiftValue() const { return misc->baselineShiftValue; }
    283306    ShadowData* shadow() const { return shadowSVG->shadow.get(); }
    284307    String clipperResource() const { return resources->clipper; }
     
    296319    bool hasStroke() const { return strokePaint()->paintType() != SVGPaint::SVG_PAINTTYPE_NONE; }
    297320    bool hasFill() const { return fillPaint()->paintType() != SVGPaint::SVG_PAINTTYPE_NONE; }
    298 
    299     static float cssPrimitiveToLength(const RenderObject*, CSSValue*, float defaultValue = 0.0f);
    300321
    301322protected:
  • trunk/WebCore/rendering/style/SVGRenderStyleDefs.cpp

    r57575 r64830  
    7474    , width(SVGRenderStyle::initialStrokeWidth())
    7575    , dashOffset(SVGRenderStyle::initialStrokeDashOffset())
     76    , dashArray(SVGRenderStyle::initialStrokeDashArray())
    7677    , paint(SVGRenderStyle::initialStrokePaint())
    77     , dashArray(SVGRenderStyle::initialStrokeDashArray())
    7878{
    7979}
     
    8585    , width(other.width)
    8686    , dashOffset(other.dashOffset)
     87    , dashArray(other.dashArray)
    8788    , paint(other.paint)
    88     , dashArray(other.dashArray)
    8989{
    9090}
  • trunk/WebCore/rendering/style/SVGRenderStyleDefs.h

    r64367 r64830  
    3030
    3131#if ENABLE(SVG)
    32 
    3332#include "Color.h"
    3433#include "PlatformString.h"
     34#include "SVGLength.h"
    3535#include "ShadowData.h"
    3636#include <wtf/OwnPtr.h>
     
    128128        float miterLimit;
    129129
    130         RefPtr<CSSValue> width;
    131         RefPtr<CSSValue> dashOffset;
     130        SVGLength width;
     131        SVGLength dashOffset;
     132        Vector<SVGLength> dashArray;
    132133
    133134        RefPtr<SVGPaint> paint;
    134         RefPtr<CSSValueList> dashArray;
    135135
    136136    private:       
     
    169169        }
    170170
    171         RefPtr<CSSValue> kerning;
     171        SVGLength kerning;
    172172
    173173    private:
     
    193193
    194194        // non-inherited text stuff lives here not in StyleTextData.
    195         RefPtr<CSSValue> baselineShiftValue;
     195        SVGLength baselineShiftValue;
    196196
    197197    private:
  • trunk/WebCore/svg/SVGLength.cpp

    r64579 r64830  
    117117{
    118118    setValueAsString(valueAsString);
     119}
     120
     121SVGLength::SVGLength(const SVGLength& other)
     122    : m_valueInSpecifiedUnits(other.m_valueInSpecifiedUnits)
     123    , m_unit(other.m_unit)
     124{
     125}
     126
     127bool SVGLength::operator==(const SVGLength& other) const
     128{
     129    return m_unit == other.m_unit
     130        && m_valueInSpecifiedUnits == other.m_valueInSpecifiedUnits;
     131}
     132
     133bool SVGLength::operator!=(const SVGLength& other) const
     134{
     135    return !operator==(other);
    119136}
    120137
     
    320337}
    321338
     339SVGLength SVGLength::fromCSSPrimitiveValue(CSSPrimitiveValue* value)
     340{
     341    ASSERT(value);
     342
     343    SVGLengthType svgType;
     344    switch (value->primitiveType()) {
     345    case CSSPrimitiveValue::CSS_NUMBER:
     346        svgType = LengthTypeNumber;
     347        break;
     348    case CSSPrimitiveValue::CSS_PERCENTAGE:
     349        svgType = LengthTypePercentage;
     350        break;
     351    case CSSPrimitiveValue::CSS_EMS:
     352        svgType = LengthTypeEMS;
     353        break;
     354    case CSSPrimitiveValue::CSS_EXS:
     355        svgType = LengthTypeEXS;
     356        break;
     357    case CSSPrimitiveValue::CSS_PX:
     358        svgType = LengthTypePX;
     359        break;
     360    case CSSPrimitiveValue::CSS_CM:
     361        svgType = LengthTypeCM;
     362        break;
     363    case CSSPrimitiveValue::CSS_MM:
     364        svgType = LengthTypeMM;
     365        break;
     366    case CSSPrimitiveValue::CSS_IN:
     367        svgType = LengthTypeIN;
     368        break;
     369    case CSSPrimitiveValue::CSS_PT:
     370        svgType = LengthTypePT;
     371        break;
     372    case CSSPrimitiveValue::CSS_PC:
     373        svgType = LengthTypePC;
     374        break;
     375    case CSSPrimitiveValue::CSS_UNKNOWN:
     376    default:
     377        svgType = LengthTypeUnknown;
     378        break;
     379    };
     380
     381    if (svgType == LengthTypeUnknown)
     382        return SVGLength();
     383
     384    SVGLength length;
     385    length.newValueSpecifiedUnits(svgType, value->getFloatValue());
     386    return length;
     387}
     388
     389PassRefPtr<CSSPrimitiveValue> SVGLength::toCSSPrimitiveValue(const SVGLength& length)
     390{
     391    CSSPrimitiveValue::UnitTypes cssType;
     392    switch (length.unitType()) {
     393    case LengthTypeUnknown:
     394        cssType = CSSPrimitiveValue::CSS_UNKNOWN;
     395        break;
     396    case LengthTypeNumber:
     397        cssType = CSSPrimitiveValue::CSS_NUMBER;
     398        break;
     399    case LengthTypePercentage:
     400        cssType = CSSPrimitiveValue::CSS_PERCENTAGE;
     401        break;
     402    case LengthTypeEMS:
     403        cssType = CSSPrimitiveValue::CSS_EMS;
     404        break;
     405    case LengthTypeEXS:
     406        cssType = CSSPrimitiveValue::CSS_EXS;
     407        break;
     408    case LengthTypePX:
     409        cssType = CSSPrimitiveValue::CSS_PX;
     410        break;
     411    case LengthTypeCM:
     412        cssType = CSSPrimitiveValue::CSS_CM;
     413        break;
     414    case LengthTypeMM:
     415        cssType = CSSPrimitiveValue::CSS_MM;
     416        break;
     417    case LengthTypeIN:
     418        cssType = CSSPrimitiveValue::CSS_IN;
     419        break;
     420    case LengthTypePT:
     421        cssType = CSSPrimitiveValue::CSS_PT;
     422        break;
     423    case LengthTypePC:
     424        cssType = CSSPrimitiveValue::CSS_PC;
     425        break;
     426    default:
     427        ASSERT_NOT_REACHED();
     428    };
     429
     430    return CSSPrimitiveValue::create(length.valueInSpecifiedUnits(), cssType);
     431}
     432
    322433}
    323434
  • trunk/WebCore/svg/SVGLength.h

    r64579 r64830  
    2727namespace WebCore {
    2828
    29     enum SVGLengthType {
    30         LengthTypeUnknown = 0,
    31         LengthTypeNumber = 1,
    32         LengthTypePercentage = 2,
    33         LengthTypeEMS = 3,
    34         LengthTypeEXS = 4,
    35         LengthTypePX = 5,
    36         LengthTypeCM = 6,
    37         LengthTypeMM = 7,
    38         LengthTypeIN = 8,
    39         LengthTypePT = 9,
    40         LengthTypePC = 10
     29class CSSPrimitiveValue;
     30
     31enum SVGLengthType {
     32    LengthTypeUnknown = 0,
     33    LengthTypeNumber = 1,
     34    LengthTypePercentage = 2,
     35    LengthTypeEMS = 3,
     36    LengthTypeEXS = 4,
     37    LengthTypePX = 5,
     38    LengthTypeCM = 6,
     39    LengthTypeMM = 7,
     40    LengthTypeIN = 8,
     41    LengthTypePT = 9,
     42    LengthTypePC = 10
     43};
     44
     45enum SVGLengthMode {
     46    LengthModeWidth = 0,
     47    LengthModeHeight,
     48    LengthModeOther
     49};
     50
     51class SVGElement;
     52
     53class SVGLength {
     54public:
     55    // Forward declare these enums in the w3c naming scheme, for IDL generation
     56    enum {
     57        SVG_LENGTHTYPE_UNKNOWN = LengthTypeUnknown,
     58        SVG_LENGTHTYPE_NUMBER = LengthTypeNumber,
     59        SVG_LENGTHTYPE_PERCENTAGE = LengthTypePercentage,
     60        SVG_LENGTHTYPE_EMS = LengthTypeEMS,
     61        SVG_LENGTHTYPE_EXS = LengthTypeEXS,
     62        SVG_LENGTHTYPE_PX = LengthTypePX,
     63        SVG_LENGTHTYPE_CM = LengthTypeCM,
     64        SVG_LENGTHTYPE_MM = LengthTypeMM,
     65        SVG_LENGTHTYPE_IN = LengthTypeIN,
     66        SVG_LENGTHTYPE_PT = LengthTypePT,
     67        SVG_LENGTHTYPE_PC = LengthTypePC
    4168    };
    4269
    43     enum SVGLengthMode {
    44         LengthModeWidth = 0,
    45         LengthModeHeight,
    46         LengthModeOther
    47     };
     70    SVGLength(SVGLengthMode mode = LengthModeOther, const String& valueAsString = String());
     71    SVGLength(const SVGLength&);
    4872
    49     class SVGElement;
     73    SVGLengthType unitType() const;
    5074
    51     class SVGLength {
    52     public:
    53         // Forward declare these enums in the w3c naming scheme, for IDL generation
    54         enum {
    55             SVG_LENGTHTYPE_UNKNOWN = LengthTypeUnknown,
    56             SVG_LENGTHTYPE_NUMBER = LengthTypeNumber,
    57             SVG_LENGTHTYPE_PERCENTAGE = LengthTypePercentage,
    58             SVG_LENGTHTYPE_EMS = LengthTypeEMS,
    59             SVG_LENGTHTYPE_EXS = LengthTypeEXS,
    60             SVG_LENGTHTYPE_PX = LengthTypePX,
    61             SVG_LENGTHTYPE_CM = LengthTypeCM,
    62             SVG_LENGTHTYPE_MM = LengthTypeMM,
    63             SVG_LENGTHTYPE_IN = LengthTypeIN,
    64             SVG_LENGTHTYPE_PT = LengthTypePT,
    65             SVG_LENGTHTYPE_PC = LengthTypePC
    66         };
     75    bool operator==(const SVGLength&) const;
     76    bool operator!=(const SVGLength&) const;
    6777
    68         SVGLength(SVGLengthMode mode = LengthModeOther, const String& valueAsString = String());
     78    float value(const SVGElement* context) const;
     79    void setValue(float);
    6980
    70         SVGLengthType unitType() const;
     81    float valueInSpecifiedUnits() const;
     82    void setValueInSpecifiedUnits(float);
     83   
     84    float valueAsPercentage() const;
    7185
    72         float value(const SVGElement* context) const;
    73         void setValue(float);
     86    String valueAsString() const;
     87    bool setValueAsString(const String&);
    7488
    75         float valueInSpecifiedUnits() const;
    76         void setValueInSpecifiedUnits(float);
    77        
    78         float valueAsPercentage() const;
     89    void newValueSpecifiedUnits(unsigned short, float valueInSpecifiedUnits);
     90    void convertToSpecifiedUnits(unsigned short, const SVGElement* context);
    7991
    80         String valueAsString() const;
    81         bool setValueAsString(const String&);
     92    // Helper functions
     93    static float PercentageOfViewport(float value, const SVGElement* context, SVGLengthMode);
    8294
    83         void newValueSpecifiedUnits(unsigned short, float valueInSpecifiedUnits);
    84         void convertToSpecifiedUnits(unsigned short, const SVGElement* context);
     95    inline bool isRelative() const
     96    {
     97        SVGLengthType type = unitType();
     98        return (type == LengthTypePercentage || type == LengthTypeEMS || type == LengthTypeEXS);
     99    }
    85100
    86         // Helper functions
    87         static float PercentageOfViewport(float value, const SVGElement* context, SVGLengthMode);
     101    static SVGLength fromCSSPrimitiveValue(CSSPrimitiveValue*);
     102    static PassRefPtr<CSSPrimitiveValue> toCSSPrimitiveValue(const SVGLength&);
    88103
    89         inline bool isRelative() const
    90         {
    91             SVGLengthType type = unitType();
    92             return (type == LengthTypePercentage || type == LengthTypeEMS || type == LengthTypeEXS);
    93         }
    94  
    95     private:
    96         float m_valueInSpecifiedUnits;
    97         unsigned int m_unit;
    98     };
     104private:
     105    float m_valueInSpecifiedUnits;
     106    unsigned int m_unit;
     107};
    99108
    100109} // namespace WebCore
Note: See TracChangeset for help on using the changeset viewer.