Changeset 28856 in webkit


Ignore:
Timestamp:
Dec 18, 2007 11:53:52 PM (16 years ago)
Author:
Beth Dakin
Message:

WebCore:

Reviewed by Oliver.

Fix for <rdar://problem/5616982> SVGs with width and height 100%
fail to render when used as <img> or CSS image (16167)

This final part of the work fixes the <img> tag.

This is the real fix.

  • rendering/RenderImage.cpp: (WebCore::RenderImage::calcReplacedWidth): Set the container size on the image. Setting the container size only actually sticks if the values are non-zero, so if the container size really was set, use the imageSize that is calculated using the container size. If it did not stick but the image does have relative width (meaning that the container size is 0), set the width to 0 by hand. We want to avoid setting the width before we have a container size or we will end up incorrectly using the default size of 300x150. (WebCore::RenderImage::calcReplacedHeight): Same as above, but for height.

A few more pieces of information have to be exposed through cached
image to make this happen.

  • loader/CachedImage.cpp: (WebCore::CachedImage::usesImageContainerSize): As mentioned above, when setContainerSize() is called, the container size is only actually set if the values are non-zero. This call tells you if it was set. (WebCore::CachedImage::imageHasRelativeWidth): (WebCore::CachedImage::imageHasRelativeHeight):
  • loader/CachedImage.h:
  • platform/graphics/Image.h: (WebCore::Image::usesContainerSize):
  • svg/graphics/SVGImage.cpp: (WebCore::SVGImage::usesContainerSize):
  • svg/graphics/SVGImage.h:

LayoutTests:

Reviewed by Oliver.

Test for <rdar://problem/5616982> SVGs with width and height 100%
fail to render when used as <img> or CSS image (16167)

  • fast/images/resources/green-relative-size-rect.svg: Added.
  • fast/images/svg-as-relative-image.html: Added.
  • platform/mac/fast/images/svg-as-relative-image-expected.checksum: Added.
  • platform/mac/fast/images/svg-as-relative-image-expected.png: Added.
  • platform/mac/fast/images/svg-as-relative-image-expected.txt: Added.
Location:
trunk
Files:
5 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r28845 r28856  
     12007-12-18  Beth Dakin  <bdakin@apple.com>
     2
     3        Reviewed by Oliver.
     4
     5        Test for <rdar://problem/5616982> SVGs with width and height 100%
     6        fail to render when used as <img> or CSS image (16167)
     7
     8        * fast/images/resources/green-relative-size-rect.svg: Added.
     9        * fast/images/svg-as-relative-image.html: Added.
     10        * platform/mac/fast/images/svg-as-relative-image-expected.checksum: Added.
     11        * platform/mac/fast/images/svg-as-relative-image-expected.png: Added.
     12        * platform/mac/fast/images/svg-as-relative-image-expected.txt: Added.
     13
    1142007-12-18  Dan Bernstein  <mitz@apple.com>
    215
  • trunk/WebCore/ChangeLog

    r28846 r28856  
     12007-12-18  Beth Dakin  <bdakin@apple.com>
     2
     3        Reviewed by Oliver.
     4
     5        Fix for <rdar://problem/5616982> SVGs with width and height 100%
     6        fail to render when used as <img> or CSS image (16167)
     7
     8        This final part of the work fixes the <img> tag.
     9
     10        This is the real fix.
     11        * rendering/RenderImage.cpp:
     12        (WebCore::RenderImage::calcReplacedWidth): Set the container size
     13        on the image. Setting the container size only actually sticks if
     14        the values are non-zero, so if the container size really was set,
     15        use the imageSize that is calculated using the container size. If
     16        it did not stick but the image does have relative width (meaning
     17        that the container size is 0), set the width to 0 by hand. We want
     18        to avoid setting the width before we have a container size or we
     19        will end up incorrectly using the default size of 300x150.
     20        (WebCore::RenderImage::calcReplacedHeight): Same as above, but for
     21        height.
     22
     23        A few more pieces of information have to be exposed through cached
     24        image to make this happen.
     25        * loader/CachedImage.cpp:
     26        (WebCore::CachedImage::usesImageContainerSize): As mentioned above,
     27        when setContainerSize() is called, the container size is only
     28        actually set if the values are non-zero. This call tells you if it
     29        was set.
     30        (WebCore::CachedImage::imageHasRelativeWidth):
     31        (WebCore::CachedImage::imageHasRelativeHeight):
     32        * loader/CachedImage.h:
     33        * platform/graphics/Image.h:
     34        (WebCore::Image::usesContainerSize):
     35        * svg/graphics/SVGImage.cpp:
     36        (WebCore::SVGImage::usesContainerSize):
     37        * svg/graphics/SVGImage.h:
     38
    1392007-12-18  Mark Rowe  <mrowe@apple.com>
    240
  • trunk/WebCore/loader/CachedImage.cpp

    r28637 r28856  
    118118    if (m_image)
    119119        m_image->setContainerSize(containerSize);
     120}
     121
     122bool CachedImage::usesImageContainerSize() const
     123{
     124    if (m_image)
     125        return m_image->usesContainerSize();
     126
     127    return false;
     128}
     129
     130bool CachedImage::imageHasRelativeWidth() const
     131{
     132    if (m_image)
     133        return m_image->hasRelativeWidth();
     134
     135    return false;
     136}
     137
     138bool CachedImage::imageHasRelativeHeight() const
     139{
     140    if (m_image)
     141        return m_image->hasRelativeHeight();
     142
     143    return false;
    120144}
    121145
  • trunk/WebCore/loader/CachedImage.h

    r28637 r28856  
    4747    bool canRender() const { return !errorOccurred() && imageSize().width() > 0 && imageSize().height() > 0; }
    4848
     49    // These are ony used for SVGImage right now
    4950    void setImageContainerSize(const IntSize&);
     51    bool usesImageContainerSize() const;
     52    bool imageHasRelativeWidth() const;
     53    bool imageHasRelativeHeight() const;
    5054   
    5155    IntSize imageSize() const;  // returns the size of the complete image
  • trunk/WebCore/platform/graphics/Image.h

    r28637 r28856  
    8383    // These are ony used for SVGImage right now
    8484    virtual void setContainerSize(const IntSize&) { }
     85    virtual bool usesContainerSize() const { return false; }
    8586    virtual bool hasRelativeWidth() const { return false; }
    8687    virtual bool hasRelativeHeight() const { return false; }
  • trunk/WebCore/rendering/RenderImage.cpp

    r28397 r28856  
    325325int RenderImage::calcReplacedWidth() const
    326326{
     327    if (m_cachedImage && m_cachedImage->imageHasRelativeWidth() && !m_cachedImage->usesImageContainerSize())
     328        if (RenderObject* cb = isPositioned() ? container() : containingBlock())
     329            m_cachedImage->setImageContainerSize(IntSize(cb->availableWidth(), cb->availableHeight()));
     330   
    327331    int width;
    328332    if (isWidthSpecified())
    329333        width = calcReplacedWidthUsing(style()->width());
     334    else if (m_cachedImage && m_cachedImage->usesImageContainerSize())
     335        width = m_cachedImage->imageSize().width();
     336    else if (m_cachedImage && m_cachedImage->imageHasRelativeWidth())
     337        width = 0; // If the image is relatively-sized, set the width to 0 until there is a set container size.
    330338    else
    331339        width = calcAspectRatioWidth();
     
    342350    if (isHeightSpecified())
    343351        height = calcReplacedHeightUsing(style()->height());
     352    else if (m_cachedImage && m_cachedImage->usesImageContainerSize())
     353        height = m_cachedImage->imageSize().height();
     354    else if (m_cachedImage && m_cachedImage->imageHasRelativeHeight())
     355        height = 0; // If the image is relatively-sized, set the height to 0 until there is a set container size.
    344356    else
    345357        height = calcAspectRatioHeight();
  • trunk/WebCore/svg/graphics/SVGImage.cpp

    r28637 r28856  
    7777}
    7878
     79bool SVGImage::usesContainerSize() const
     80{
     81    SVGSVGElement* rootElement = static_cast<SVGDocument*>(m_frame->document())->rootElement();
     82    if (!rootElement)
     83        return false;
     84
     85    return rootElement->hasSetContainerSize();
     86}
     87
    7988IntSize SVGImage::size() const
    8089{
  • trunk/WebCore/svg/graphics/SVGImage.h

    r28637 r28856  
    4747
    4848        virtual void setContainerSize(const IntSize&);
     49        virtual bool usesContainerSize() const;
    4950        virtual bool hasRelativeWidth() const;
    5051        virtual bool hasRelativeHeight() const;
Note: See TracChangeset for help on using the changeset viewer.