Changeset 172711 in webkit


Ignore:
Timestamp:
Aug 18, 2014 11:18:16 AM (10 years ago)
Author:
krit@webkit.org
Message:

calc() doesn't work for SVG CSS properties
https://bugs.webkit.org/show_bug.cgi?id=136026

Reviewed by Andreas Kling.

Source/WebCore:

Make calc() work on SVG CSS properties as well. stroke-width and
stroke-dashoffset used SVGLength. SVGLength doesn't work together with
cross units length arguments like % and px (just returns 0 in these
cases). I moved these properties over to Length. All modified files
beside to SVGCSSParser are related to this switch.

Test: svg/css/parse-calc-length.html

  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::ComputedStyleExtractor::propertyValue):

  • css/DeprecatedStyleBuilder.cpp:

(WebCore::DeprecatedStyleBuilder::DeprecatedStyleBuilder):

  • css/SVGCSSComputedStyleDeclaration.cpp:

(WebCore::ComputedStyleExtractor::svgPropertyValue):

  • css/SVGCSSParser.cpp:

(WebCore::CSSParser::parseSVGValue):

  • css/SVGCSSStyleSelector.cpp:

(WebCore::StyleResolver::applySVGProperty):

  • page/animation/CSSPropertyAnimation.cpp:

(WebCore::CSSPropertyAnimationWrapperMap::CSSPropertyAnimationWrapperMap):

  • rendering/style/RenderStyle.h:
  • rendering/style/SVGRenderStyle.h:

(WebCore::SVGRenderStyle::setStrokeWidth):
(WebCore::SVGRenderStyle::setStrokeDashOffset):
(WebCore::SVGRenderStyle::strokeWidth):
(WebCore::SVGRenderStyle::strokeDashOffset):
(WebCore::SVGRenderStyle::initialStrokeDashOffset): Deleted.
(WebCore::SVGRenderStyle::initialStrokeWidth): Deleted.

  • rendering/style/SVGRenderStyleDefs.cpp:

(WebCore::StyleStrokeData::StyleStrokeData):

  • rendering/style/SVGRenderStyleDefs.h:
  • rendering/svg/RenderSVGShape.cpp:

(WebCore::RenderSVGShape::strokeWidth):

  • rendering/svg/RenderSVGText.cpp:

(WebCore::RenderSVGText::strokeBoundingBox):

  • rendering/svg/SVGRenderSupport.cpp:

(WebCore::SVGRenderSupport::applyStrokeStyleToContext):

  • rendering/svg/SVGRenderTreeAsText.cpp:

(WebCore::writeStyle):

  • svg/SVGLengthContext.cpp:

(WebCore::SVGLengthContext::valueForLength):

LayoutTests:

Test calc() on length properties for SVG.

  • svg/css/getComputedStyle-basic-expected.txt:
  • svg/css/parse-calc-length-expected.txt: Added.
  • svg/css/parse-calc-length.html: Added.
Location:
trunk
Files:
2 added
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r172709 r172711  
     12014-08-18  Dirk Schulze  <krit@webkit.org>
     2
     3        calc() doesn't work for SVG CSS properties
     4        https://bugs.webkit.org/show_bug.cgi?id=136026
     5
     6        Reviewed by Andreas Kling.
     7
     8        Test calc() on length properties for SVG.
     9
     10        * svg/css/getComputedStyle-basic-expected.txt:
     11        * svg/css/parse-calc-length-expected.txt: Added.
     12        * svg/css/parse-calc-length.html: Added.
     13
    1142014-08-18  Andy Estes  <aestes@apple.com>
    215
  • trunk/LayoutTests/fast/css/getComputedStyle/computed-style-expected.txt

    r170996 r172711  
    241241stroke: none;
    242242stroke-dasharray: none;
    243 stroke-dashoffset: 0;
     243stroke-dashoffset: 0px;
    244244stroke-linecap: butt;
    245245stroke-linejoin: miter;
    246246stroke-miterlimit: 4;
    247247stroke-opacity: 1;
    248 stroke-width: 1;
     248stroke-width: 1px;
    249249alignment-baseline: auto;
    250250baseline-shift: baseline;
  • trunk/LayoutTests/fast/css/getComputedStyle/computed-style-without-renderer-expected.txt

    r170996 r172711  
    240240stroke: none
    241241stroke-dasharray: none
    242 stroke-dashoffset: 0
     242stroke-dashoffset: 0px
    243243stroke-linecap: butt
    244244stroke-linejoin: miter
    245245stroke-miterlimit: 4
    246246stroke-opacity: 1
    247 stroke-width: 1
     247stroke-width: 1px
    248248alignment-baseline: auto
    249249baseline-shift: baseline
  • trunk/LayoutTests/svg/css/getComputedStyle-basic-expected.txt

    r171341 r172711  
    479479rect: style.getPropertyValue(stroke-dasharray) : none
    480480rect: style.getPropertyCSSValue(stroke-dasharray) : [object CSSPrimitiveValue]
    481 rect: style.getPropertyValue(stroke-dashoffset) : 0
     481rect: style.getPropertyValue(stroke-dashoffset) : 0px
    482482rect: style.getPropertyCSSValue(stroke-dashoffset) : [object CSSPrimitiveValue]
    483483rect: style.getPropertyValue(stroke-linecap) : butt
     
    991991g: style.getPropertyValue(stroke-dasharray) : none
    992992g: style.getPropertyCSSValue(stroke-dasharray) : [object CSSPrimitiveValue]
    993 g: style.getPropertyValue(stroke-dashoffset) : 0
     993g: style.getPropertyValue(stroke-dashoffset) : 0px
    994994g: style.getPropertyCSSValue(stroke-dashoffset) : [object CSSPrimitiveValue]
    995995g: style.getPropertyValue(stroke-linecap) : butt
  • trunk/Source/WebCore/ChangeLog

    r172709 r172711  
     12014-08-18  Dirk Schulze  <krit@webkit.org>
     2
     3        calc() doesn't work for SVG CSS properties
     4        https://bugs.webkit.org/show_bug.cgi?id=136026
     5
     6        Reviewed by Andreas Kling.
     7
     8        Make calc() work on SVG CSS properties as well. stroke-width and
     9        stroke-dashoffset used SVGLength. SVGLength doesn't work together with
     10        cross units length arguments like % and px (just returns 0 in these
     11        cases). I moved these properties over to Length. All modified files
     12        beside to SVGCSSParser are related to this switch.
     13
     14        Test: svg/css/parse-calc-length.html
     15
     16        * css/CSSComputedStyleDeclaration.cpp:
     17        (WebCore::ComputedStyleExtractor::propertyValue):
     18        * css/DeprecatedStyleBuilder.cpp:
     19        (WebCore::DeprecatedStyleBuilder::DeprecatedStyleBuilder):
     20        * css/SVGCSSComputedStyleDeclaration.cpp:
     21        (WebCore::ComputedStyleExtractor::svgPropertyValue):
     22        * css/SVGCSSParser.cpp:
     23        (WebCore::CSSParser::parseSVGValue):
     24        * css/SVGCSSStyleSelector.cpp:
     25        (WebCore::StyleResolver::applySVGProperty):
     26        * page/animation/CSSPropertyAnimation.cpp:
     27        (WebCore::CSSPropertyAnimationWrapperMap::CSSPropertyAnimationWrapperMap):
     28        * rendering/style/RenderStyle.h:
     29        * rendering/style/SVGRenderStyle.h:
     30        (WebCore::SVGRenderStyle::setStrokeWidth):
     31        (WebCore::SVGRenderStyle::setStrokeDashOffset):
     32        (WebCore::SVGRenderStyle::strokeWidth):
     33        (WebCore::SVGRenderStyle::strokeDashOffset):
     34        (WebCore::SVGRenderStyle::initialStrokeDashOffset): Deleted.
     35        (WebCore::SVGRenderStyle::initialStrokeWidth): Deleted.
     36        * rendering/style/SVGRenderStyleDefs.cpp:
     37        (WebCore::StyleStrokeData::StyleStrokeData):
     38        * rendering/style/SVGRenderStyleDefs.h:
     39        * rendering/svg/RenderSVGShape.cpp:
     40        (WebCore::RenderSVGShape::strokeWidth):
     41        * rendering/svg/RenderSVGText.cpp:
     42        (WebCore::RenderSVGText::strokeBoundingBox):
     43        * rendering/svg/SVGRenderSupport.cpp:
     44        (WebCore::SVGRenderSupport::applyStrokeStyleToContext):
     45        * rendering/svg/SVGRenderTreeAsText.cpp:
     46        (WebCore::writeStyle):
     47        * svg/SVGLengthContext.cpp:
     48        (WebCore::SVGLengthContext::valueForLength):
     49
    1502014-08-18  Andy Estes  <aestes@apple.com>
    251
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp

    r172642 r172711  
    29712971            break;
    29722972
    2973         // New positioning properties for SVG.
     2973        // Length properties for SVG.
    29742974        case CSSPropertyCx:
    29752975            return zoomAdjustedPixelValueForLength(style->svgStyle().cx(), style.get());
     
    29822982        case CSSPropertyRy:
    29832983            return zoomAdjustedPixelValueForLength(style->svgStyle().ry(), style.get());
     2984        case CSSPropertyStrokeWidth:
     2985            return zoomAdjustedPixelValueForLength(style->svgStyle().strokeWidth(), style.get());
     2986        case CSSPropertyStrokeDashoffset:
     2987            return zoomAdjustedPixelValueForLength(style->svgStyle().strokeDashOffset(), style.get());
    29842988        case CSSPropertyX:
    29852989            return zoomAdjustedPixelValueForLength(style->svgStyle().x(), style.get());
     
    31043108        case CSSPropertyStroke:
    31053109        case CSSPropertyStrokeDasharray:
    3106         case CSSPropertyStrokeDashoffset:
    31073110        case CSSPropertyStrokeLinecap:
    31083111        case CSSPropertyStrokeLinejoin:
    31093112        case CSSPropertyStrokeMiterlimit:
    31103113        case CSSPropertyStrokeOpacity:
    3111         case CSSPropertyStrokeWidth:
    31123114        case CSSPropertyAlignmentBaseline:
    31133115        case CSSPropertyBaselineShift:
  • trunk/Source/WebCore/css/DeprecatedStyleBuilder.cpp

    r172642 r172711  
    26002600    setPropertyHandler(CSSPropertyRx, ApplyPropertyLength<&RenderStyle::rx, &RenderStyle::setRx, &RenderStyle::initialZeroLength>::createHandler());
    26012601    setPropertyHandler(CSSPropertyRy, ApplyPropertyLength<&RenderStyle::ry, &RenderStyle::setRy, &RenderStyle::initialZeroLength>::createHandler());
     2602    setPropertyHandler(CSSPropertyStrokeWidth, ApplyPropertyLength<&RenderStyle::strokeWidth, &RenderStyle::setStrokeWidth, &RenderStyle::initialOneLength>::createHandler());
     2603    setPropertyHandler(CSSPropertyStrokeDashoffset, ApplyPropertyLength<&RenderStyle::strokeDashOffset, &RenderStyle::setStrokeDashOffset, &RenderStyle::initialZeroLength>::createHandler());
    26022604    setPropertyHandler(CSSPropertyX, ApplyPropertyLength<&RenderStyle::x, &RenderStyle::setX, &RenderStyle::initialZeroLength>::createHandler());
    26032605    setPropertyHandler(CSSPropertyY, ApplyPropertyLength<&RenderStyle::y, &RenderStyle::setY, &RenderStyle::initialZeroLength>::createHandler());
  • trunk/Source/WebCore/css/SVGCSSComputedStyleDeclaration.cpp

    r172536 r172711  
    191191        case CSSPropertyStrokeDasharray:
    192192            return strokeDashArrayToCSSValueList(svgStyle.strokeDashArray());
    193         case CSSPropertyStrokeDashoffset:
    194             return SVGLength::toCSSPrimitiveValue(svgStyle.strokeDashOffset());
    195         case CSSPropertyStrokeWidth:
    196             return SVGLength::toCSSPrimitiveValue(svgStyle.strokeWidth());
    197193        case CSSPropertyBaselineShift: {
    198194            switch (svgStyle.baselineShift()) {
  • trunk/Source/WebCore/css/SVGCSSParser.cpp

    r172642 r172711  
    325325        else if (value->unit >= CSSParserValue::Q_EMS)
    326326            parsedValue = CSSPrimitiveValue::createAllowingMarginQuirk(value->fValue, CSSPrimitiveValue::CSS_EMS);
    327         if (isCalculation(value)) {
    328             // FIXME calc() http://webkit.org/b/16662 : actually create a CSSPrimitiveValue here, ie
    329             // parsedValue = CSSPrimitiveValue::create(m_parsedCalculation.release());
    330             m_parsedCalculation.release();
    331             parsedValue = 0;
    332         }
     327        if (isCalculation(value))
     328            parsedValue = CSSPrimitiveValue::create(m_parsedCalculation.release());
    333329        m_valueList->next();
    334330    }
  • trunk/Source/WebCore/css/SVGCSSStyleSelector.cpp

    r170774 r172711  
    290290            break;
    291291        }
    292         case CSSPropertyStrokeWidth:
    293         {
    294             HANDLE_INHERIT_AND_INITIAL(strokeWidth, StrokeWidth)
    295             if (primitiveValue)
    296                 svgStyle.setStrokeWidth(SVGLength::fromCSSPrimitiveValue(primitiveValue));
    297             break;
    298         }
    299292        case CSSPropertyStrokeDasharray:
    300293        {
     
    319312
    320313            svgStyle.setStrokeDashArray(array);
    321             break;
    322         }
    323         case CSSPropertyStrokeDashoffset:
    324         {
    325             HANDLE_INHERIT_AND_INITIAL(strokeDashOffset, StrokeDashOffset)
    326             if (primitiveValue)
    327                 svgStyle.setStrokeDashOffset(SVGLength::fromCSSPrimitiveValue(primitiveValue));
    328314            break;
    329315        }
  • trunk/Source/WebCore/page/animation/CSSPropertyAnimation.cpp

    r172642 r172711  
    12521252        new PropertyWrapperSVGPaint(CSSPropertyStroke, &RenderStyle::strokePaintType, &RenderStyle::strokePaintColor, &RenderStyle::setStrokePaintColor),
    12531253        new PropertyWrapper<float>(CSSPropertyStrokeOpacity, &RenderStyle::strokeOpacity, &RenderStyle::setStrokeOpacity),
    1254         new PropertyWrapper<SVGLength>(CSSPropertyStrokeWidth, &RenderStyle::strokeWidth, &RenderStyle::setStrokeWidth),
    12551254        new PropertyWrapper< Vector<SVGLength>>(CSSPropertyStrokeDasharray, &RenderStyle::strokeDashArray, &RenderStyle::setStrokeDashArray),
    1256         new PropertyWrapper<SVGLength>(CSSPropertyStrokeDashoffset, &RenderStyle::strokeDashOffset, &RenderStyle::setStrokeDashOffset),
    12571255        new PropertyWrapper<float>(CSSPropertyStrokeMiterlimit, &RenderStyle::strokeMiterLimit, &RenderStyle::setStrokeMiterLimit),
    12581256
     
    12621260        new LengthPropertyWrapper<Length>(CSSPropertyRx, &RenderStyle::rx, &RenderStyle::setRx),
    12631261        new LengthPropertyWrapper<Length>(CSSPropertyRy, &RenderStyle::ry, &RenderStyle::setRy),
     1262        new LengthPropertyWrapper<Length>(CSSPropertyStrokeDashoffset, &RenderStyle::strokeDashOffset, &RenderStyle::setStrokeDashOffset),
     1263        new LengthPropertyWrapper<Length>(CSSPropertyStrokeWidth, &RenderStyle::strokeWidth, &RenderStyle::setStrokeWidth),
    12641264        new LengthPropertyWrapper<Length>(CSSPropertyX, &RenderStyle::x, &RenderStyle::setX),
    12651265        new LengthPropertyWrapper<Length>(CSSPropertyY, &RenderStyle::y, &RenderStyle::setY),
  • trunk/Source/WebCore/rendering/style/RenderStyle.h

    r172656 r172711  
    16571657    float strokeOpacity() const { return svgStyle().strokeOpacity(); }
    16581658    void setStrokeOpacity(float f) { accessSVGStyle().setStrokeOpacity(f); }
    1659     SVGLength strokeWidth() const { return svgStyle().strokeWidth(); }
    1660     void setStrokeWidth(SVGLength w) { accessSVGStyle().setStrokeWidth(w); }
     1659    const Length& strokeWidth() const { return svgStyle().strokeWidth(); }
     1660    void setStrokeWidth(Length w) { accessSVGStyle().setStrokeWidth(w); }
    16611661    Vector<SVGLength> strokeDashArray() const { return svgStyle().strokeDashArray(); }
    16621662    void setStrokeDashArray(Vector<SVGLength> array) { accessSVGStyle().setStrokeDashArray(array); }
    1663     SVGLength strokeDashOffset() const { return svgStyle().strokeDashOffset(); }
    1664     void setStrokeDashOffset(SVGLength d) { accessSVGStyle().setStrokeDashOffset(d); }
     1663    const Length& strokeDashOffset() const { return svgStyle().strokeDashOffset(); }
     1664    void setStrokeDashOffset(Length d) { accessSVGStyle().setStrokeDashOffset(d); }
    16651665    float strokeMiterLimit() const { return svgStyle().strokeMiterLimit(); }
    16661666    void setStrokeMiterLimit(float f) { accessSVGStyle().setStrokeMiterLimit(f); }
     
    18371837    static Length initialTextIndent() { return Length(Fixed); }
    18381838    static Length initialZeroLength() { return Length(Fixed); }
     1839    static Length initialOneLength() { return Length(1, Fixed); }
    18391840#if ENABLE(CSS3_TEXT)
    18401841    static TextIndentLine initialTextIndentLine() { return TextIndentFirstLine; }
  • trunk/Source/WebCore/rendering/style/SVGRenderStyle.h

    r172642 r172711  
    113113    }
    114114
    115     static SVGLength initialStrokeDashOffset()
    116     {
    117         SVGLength length;
    118         length.newValueSpecifiedUnits(LengthTypeNumber, 0, ASSERT_NO_EXCEPTION);
    119         return length;
    120     }
    121 
    122     static SVGLength initialStrokeWidth()
    123     {
    124         SVGLength length;
    125         length.newValueSpecifiedUnits(LengthTypeNumber, 1, ASSERT_NO_EXCEPTION);
    126         return length;
    127     }
    128 
    129115    // SVG CSS Property setters
    130116    void setAlignmentBaseline(EAlignmentBaseline val) { svg_noninherited_flags.f._alignmentBaseline = val; }
     
    247233    }
    248234
    249     void setStrokeWidth(const SVGLength& obj)
     235    void setStrokeWidth(const Length& obj)
    250236    {
    251237        if (!(stroke->width == obj))
     
    253239    }
    254240
    255     void setStrokeDashOffset(const SVGLength& obj)
     241    void setStrokeDashOffset(const Length& obj)
    256242    {
    257243        if (!(stroke->dashOffset == obj))
     
    369355    Vector<SVGLength> strokeDashArray() const { return stroke->dashArray; }
    370356    float strokeMiterLimit() const { return stroke->miterLimit; }
    371     SVGLength strokeWidth() const { return stroke->width; }
    372     SVGLength strokeDashOffset() const { return stroke->dashOffset; }
     357    const Length& strokeWidth() const { return stroke->width; }
     358    const Length& strokeDashOffset() const { return stroke->dashOffset; }
    373359    SVGLength kerning() const { return text->kerning; }
    374360    float stopOpacity() const { return stops->opacity; }
  • trunk/Source/WebCore/rendering/style/SVGRenderStyleDefs.cpp

    r172642 r172711  
    7777    : opacity(SVGRenderStyle::initialStrokeOpacity())
    7878    , miterLimit(SVGRenderStyle::initialStrokeMiterLimit())
    79     , width(SVGRenderStyle::initialStrokeWidth())
    80     , dashOffset(SVGRenderStyle::initialStrokeDashOffset())
     79    , width(RenderStyle::initialOneLength())
     80    , dashOffset(RenderStyle::initialZeroLength())
    8181    , dashArray(SVGRenderStyle::initialStrokeDashArray())
    8282    , paintType(SVGRenderStyle::initialStrokePaintType())
  • trunk/Source/WebCore/rendering/style/SVGRenderStyleDefs.h

    r172642 r172711  
    154154        float miterLimit;
    155155
    156         SVGLength width;
    157         SVGLength dashOffset;
     156        Length width;
     157        Length dashOffset;
    158158        Vector<SVGLength> dashArray;
    159159
  • trunk/Source/WebCore/rendering/svg/RenderSVGShape.cpp

    r170774 r172711  
    433433{
    434434    SVGLengthContext lengthContext(&graphicsElement());
    435     return style().svgStyle().strokeWidth().value(lengthContext);
     435    return lengthContext.valueForLength(style().svgStyle().strokeWidth());
    436436}
    437437
  • trunk/Source/WebCore/rendering/svg/RenderSVGText.cpp

    r170774 r172711  
    517517
    518518    SVGLengthContext lengthContext(&textElement());
    519     strokeBoundaries.inflate(svgStyle.strokeWidth().value(lengthContext));
     519    strokeBoundaries.inflate(lengthContext.valueForLength(svgStyle.strokeWidth()));
    520520    return strokeBoundaries;
    521521}
  • trunk/Source/WebCore/rendering/svg/SVGRenderSupport.cpp

    r171046 r172711  
    413413
    414414    SVGLengthContext lengthContext(toSVGElement(renderer.element()));
    415     context->setStrokeThickness(svgStyle.strokeWidth().value(lengthContext));
     415    context->setStrokeThickness(lengthContext.valueForLength(svgStyle.strokeWidth()));
    416416    context->setLineCap(svgStyle.capStyle());
    417417    context->setLineJoin(svgStyle.joinStyle());
     
    428428            dashArray.uncheckedAppend(dash.value(lengthContext));
    429429
    430         context->setLineDash(dashArray, svgStyle.strokeDashOffset().value(lengthContext));
     430        context->setLineDash(dashArray, lengthContext.valueForLength(svgStyle.strokeDashOffset()));
    431431    }
    432432}
  • trunk/Source/WebCore/rendering/svg/SVGRenderTreeAsText.cpp

    r167568 r172711  
    269269
    270270            SVGLengthContext lengthContext(&shape.graphicsElement());
    271             double dashOffset = svgStyle.strokeDashOffset().value(lengthContext);
    272             double strokeWidth = svgStyle.strokeWidth().value(lengthContext);
     271            double dashOffset = lengthContext.valueForLength(svgStyle.strokeDashOffset());
     272            double strokeWidth = lengthContext.valueForLength(svgStyle.strokeWidth());
    273273            const Vector<SVGLength>& dashes = svgStyle.strokeDashArray();
    274274
  • trunk/Source/WebCore/svg/SVGLengthContext.cpp

    r171591 r172711  
    9090float SVGLengthContext::valueForLength(const Length& length, SVGLengthMode mode)
    9191{
    92     if (length.isPercent())
     92    if (length.isPercent() && !length.isCalculated())
    9393        return convertValueFromPercentageToUserUnits(length.value() / 100, mode, IGNORE_EXCEPTION);
    9494    if (length.isAuto())
Note: See TracChangeset for help on using the changeset viewer.