Changeset 160774 in webkit


Ignore:
Timestamp:
Dec 18, 2013 10:14:12 AM (10 years ago)
Author:
commit-queue@webkit.org
Message:

Fix ASSERTION FAILED in WebCore::SVGLengthContext::determineViewport
https://bugs.webkit.org/show_bug.cgi?id=120284

Patch by Tamas Gergely <tgergely.u-szeged@partner.samsung.com> on 2013-12-18
Reviewed by Philip Rogers.

Source/WebCore:

Added handling of root <svg> elements.
Blink merge: https://chromium.googlesource.com/chromium/blink/+/a7dedf81eb7008276bb6854f0e46465e039788f8

SVGLengthContext::determineViewport() currently asserts that we're not
resolving lengths for the topmost element, but there's nothing to
prevent such calls.

The patch updates determineViewport() to handle root elements geracefully
(using their current viewport). It also changes the signature slightly
to operate directly on a FloatSize, reducing some of the boiler-plate
client code.

Tests: svg/custom/svg-length-value-handled.svg

svg/dom/svg-root-lengths.html

  • svg/SVGLengthContext.cpp:

(WebCore::SVGLengthContext::convertValueFromUserUnitsToPercentage):
(WebCore::SVGLengthContext::convertValueFromPercentageToUserUnits):
(WebCore::SVGLengthContext::determineViewport):

  • svg/SVGLengthContext.h:
  • svg/graphics/filters/SVGFEImage.cpp:

(WebCore::FEImage::platformApplySoftware):

LayoutTests:

Added tests of handling root <svg> elements.
Blink merge: https://chromium.googlesource.com/chromium/blink/+/a7dedf81eb7008276bb6854f0e46465e039788f8

  • svg/custom/svg-length-value-handled-expected.txt: Added.
  • svg/custom/svg-length-value-handled.svg: Added.

Tests whether root svg elements sizes are handled.

  • svg/dom/svg-root-lengths-expected.txt: Added.
  • svg/dom/svg-root-lengths.html: Added.

Tests the correct handling of root svg elements sizes.

Location:
trunk
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r160771 r160774  
     12013-12-18  Tamas Gergely  <tgergely.u-szeged@partner.samsung.com>
     2
     3        Fix ASSERTION FAILED in WebCore::SVGLengthContext::determineViewport
     4        https://bugs.webkit.org/show_bug.cgi?id=120284
     5
     6        Reviewed by Philip Rogers.
     7
     8        Added tests of handling root <svg> elements.
     9        Blink merge: https://chromium.googlesource.com/chromium/blink/+/a7dedf81eb7008276bb6854f0e46465e039788f8
     10
     11        * svg/custom/svg-length-value-handled-expected.txt: Added.
     12        * svg/custom/svg-length-value-handled.svg: Added.
     13            Tests whether root svg elements sizes are handled.
     14        * svg/dom/svg-root-lengths-expected.txt: Added.
     15        * svg/dom/svg-root-lengths.html: Added.
     16            Tests the correct handling of root svg elements sizes.
     17
    1182013-12-18  Darin Adler  <darin@apple.com>
    219
  • trunk/Source/WebCore/ChangeLog

    r160771 r160774  
     12013-12-18  Tamas Gergely  <tgergely.u-szeged@partner.samsung.com>
     2
     3        Fix ASSERTION FAILED in WebCore::SVGLengthContext::determineViewport
     4        https://bugs.webkit.org/show_bug.cgi?id=120284
     5
     6        Reviewed by Philip Rogers.
     7
     8        Added handling of root <svg> elements.
     9        Blink merge: https://chromium.googlesource.com/chromium/blink/+/a7dedf81eb7008276bb6854f0e46465e039788f8
     10
     11        SVGLengthContext::determineViewport() currently asserts that we're not
     12        resolving lengths for the topmost element, but there's nothing to
     13        prevent such calls.
     14
     15        The patch updates determineViewport() to handle root elements geracefully
     16        (using their current viewport). It also changes the signature slightly
     17        to operate directly on a FloatSize, reducing some of the boiler-plate
     18        client code.
     19
     20        Tests: svg/custom/svg-length-value-handled.svg
     21               svg/dom/svg-root-lengths.html
     22
     23        * svg/SVGLengthContext.cpp:
     24        (WebCore::SVGLengthContext::convertValueFromUserUnitsToPercentage):
     25        (WebCore::SVGLengthContext::convertValueFromPercentageToUserUnits):
     26        (WebCore::SVGLengthContext::determineViewport):
     27        * svg/SVGLengthContext.h:
     28        * svg/graphics/filters/SVGFEImage.cpp:
     29        (WebCore::FEImage::platformApplySoftware):
     30
    1312013-12-18  Darin Adler  <darin@apple.com>
    232
  • trunk/Source/WebCore/svg/SVGLengthContext.cpp

    r158163 r160774  
    162162float SVGLengthContext::convertValueFromUserUnitsToPercentage(float value, SVGLengthMode mode, ExceptionCode& ec) const
    163163{
    164     float width = 0;
    165     float height = 0;
    166     if (!determineViewport(width, height)) {
     164    FloatSize viewportSize;
     165    if (!determineViewport(viewportSize)) {
    167166        ec = NOT_SUPPORTED_ERR;
    168167        return 0;
     
    171170    switch (mode) {
    172171    case LengthModeWidth:
    173         return value / width * 100;
     172        return value / viewportSize.width() * 100;
    174173    case LengthModeHeight:
    175         return value / height * 100;
     174        return value / viewportSize.height() * 100;
    176175    case LengthModeOther:
    177         return value / (sqrtf((width * width + height * height) / 2)) * 100;
     176        return value / (sqrtf(viewportSize.diagonalLengthSquared() / 2)) * 100;
    178177    };
    179178
     
    184183float SVGLengthContext::convertValueFromPercentageToUserUnits(float value, SVGLengthMode mode, ExceptionCode& ec) const
    185184{
    186     float width = 0;
    187     float height = 0;
    188     if (!determineViewport(width, height)) {
     185    FloatSize viewportSize;
     186    if (!determineViewport(viewportSize)) {
    189187        ec = NOT_SUPPORTED_ERR;
    190188        return 0;
     
    193191    switch (mode) {
    194192    case LengthModeWidth:
    195         return value * width;
     193        return value * viewportSize.width();
    196194    case LengthModeHeight:
    197         return value * height;
     195        return value * viewportSize.height();
    198196    case LengthModeOther:
    199         return value * sqrtf((width * width + height * height) / 2);
     197        return value * sqrtf(viewportSize.diagonalLengthSquared() / 2);
    200198    };
    201199
     
    281279}
    282280
    283 bool SVGLengthContext::determineViewport(float& width, float& height) const
     281bool SVGLengthContext::determineViewport(FloatSize& viewportSize) const
    284282{
    285283    if (!m_context)
     
    288286    // If an overriden viewport is given, it has precedence.
    289287    if (!m_overridenViewport.isEmpty()) {
    290         width = m_overridenViewport.width();
    291         height = m_overridenViewport.height();
     288        viewportSize = m_overridenViewport.size();
    292289        return true;
    293290    }
    294291
    295     // SVGLengthContext should NEVER be used to resolve width/height values for <svg> elements,
    296     // as they require special treatment, due the relationship with the CSS width/height properties.
    297     ASSERT(m_context->document().documentElement() != m_context);
     292    // Root <svg> element lengths are resolved against the top level viewport.
     293    if (m_context->isOutermostSVGSVGElement()) {
     294        viewportSize = toSVGSVGElement(m_context)->currentViewportSize();
     295        return true;
     296    }
    298297
    299298    // Take size from nearest viewport element.
     
    301300    if (!viewportElement || !isSVGSVGElement(viewportElement))
    302301        return false;
    303    
     302
    304303    const SVGSVGElement* svg = toSVGSVGElement(viewportElement);
    305     FloatSize viewportSize = svg->currentViewBoxRect().size();
     304    viewportSize = svg->currentViewBoxRect().size();
    306305    if (viewportSize.isEmpty())
    307306        viewportSize = svg->currentViewportSize();
    308307
    309     width = viewportSize.width();
    310     height = viewportSize.height();
    311308    return true;
    312309}
  • trunk/Source/WebCore/svg/SVGLengthContext.h

    r106113 r160774  
    6969    float convertValueFromUserUnits(float, SVGLengthMode, SVGLengthType toUnit, ExceptionCode&) const;
    7070
    71     bool determineViewport(float& width, float& height) const;
     71    bool determineViewport(FloatSize&) const;
    7272
    7373private:
  • trunk/Source/WebCore/svg/graphics/filters/SVGFEImage.cpp

    r159277 r160774  
    129129        if (contextNode->hasRelativeLengths()) {
    130130            SVGLengthContext lengthContext(contextNode);
    131             float width = 0;
    132             float height = 0;
     131            FloatSize viewportSize;
    133132
    134133            // If we're referencing an element with percentage units, eg. <rect with="30%"> those values were resolved against the viewport.
    135134            // Build up a transformation that maps from the viewport space to the filter primitive subregion.
    136             if (lengthContext.determineViewport(width, height))
    137                 resultImage->context()->concatCTM(makeMapBetweenRects(FloatRect(0, 0, width, height), destRect));
     135            if (lengthContext.determineViewport(viewportSize))
     136                resultImage->context()->concatCTM(makeMapBetweenRects(FloatRect(FloatPoint(), viewportSize), destRect));
    138137        }
    139138
Note: See TracChangeset for help on using the changeset viewer.