Bug 52045 - SVG image in HTML changes size as the window is resized
Summary: SVG image in HTML changes size as the window is resized
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: SVG (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Nikolas Zimmermann
URL:
Keywords: InRadar
Depends on: 47156
Blocks:
  Show dependency treegraph
 
Reported: 2011-01-06 22:14 PST by Simon Fraser (smfr)
Modified: 2011-10-31 08:31 PDT (History)
6 users (show)

See Also:


Attachments
SVG image for testcase (30.46 KB, image/svg+xml)
2011-01-06 22:14 PST, Simon Fraser (smfr)
no flags Details
Testcase (301 bytes, text/html)
2011-01-06 22:16 PST, Simon Fraser (smfr)
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Fraser (smfr) 2011-01-06 22:14:55 PST
Created attachment 78209 [details]
SVG image for testcase

I'm seeing a very weird effect with butterfly.svg in an <img> element. Testcase coming.
Comment 1 Simon Fraser (smfr) 2011-01-06 22:16:44 PST
Created attachment 78210 [details]
Testcase

For some reason, the butterfly image in the <img> changes size based on the window size.
Comment 2 Nikolas Zimmermann 2011-01-07 01:30:20 PST
Ouch, stupid bug. One of the many cases, where we're not taking care of the SVG embedded in HTML correctly. 
If you set isLayoutSizeChanged to false, hardcoded in SVGRenderSupport.cpp:

void SVGRenderSupport::layoutChildren(RenderObject* start, bool selfNeedsLayout)
{
    bool layoutSizeChanged = false; //findTreeRootObject(start)->isLayoutSizeChanged();

Does the problem disappear?
Comment 3 Simon Fraser (smfr) 2011-01-07 22:10:41 PST
> void SVGRenderSupport::layoutChildren(RenderObject* start, bool selfNeedsLayout)
> {
>     bool layoutSizeChanged = false; //findTreeRootObject(start)->isLayoutSizeChanged();
> 
> Does the problem disappear?

No.
Comment 4 Simon Fraser (smfr) 2011-01-07 22:17:14 PST
This seems to be related to this code in RenderImage::computeReplacedLogicalWidth():

    if (m_imageResource->imageHasRelativeWidth())
        if (RenderObject* cb = isPositioned() ? container() : containingBlock()) {
            if (cb->isBox())
                m_imageResource->setImageContainerSize(IntSize(toRenderBox(cb)->availableWidth(), toRenderBox(cb)->availableHeight()));
        }

which was added in http://trac.webkit.org/changeset/28856

I don't grok why the image container size would be relative to the size of the containing block. Beth, do you recall?
Comment 5 Beth Dakin 2011-01-10 11:35:53 PST
(In reply to comment #4)
> This seems to be related to this code in RenderImage::computeReplacedLogicalWidth():
> 
>     if (m_imageResource->imageHasRelativeWidth())
>         if (RenderObject* cb = isPositioned() ? container() : containingBlock()) {
>             if (cb->isBox())
>                 m_imageResource->setImageContainerSize(IntSize(toRenderBox(cb)->availableWidth(), toRenderBox(cb)->availableHeight()));
>         }
> 
> which was added in http://trac.webkit.org/changeset/28856
> 
> I don't grok why the image container size would be relative to the size of the containing block. Beth, do you recall?

I don't recall all of the specifics…but I think that we decided to treat SVG-as-image as a regular image with width:100%, which would calculate based on the containing block.
Comment 6 Simon Fraser (smfr) 2011-01-10 11:37:52 PST
(In reply to comment #5)
> (In reply to comment #4)
> > This seems to be related to this code in RenderImage::computeReplacedLogicalWidth():
> > 
> >     if (m_imageResource->imageHasRelativeWidth())
> >         if (RenderObject* cb = isPositioned() ? container() : containingBlock()) {
> >             if (cb->isBox())
> >                 m_imageResource->setImageContainerSize(IntSize(toRenderBox(cb)->availableWidth(), toRenderBox(cb)->availableHeight()));
> >         }
> > 
> > which was added in http://trac.webkit.org/changeset/28856
> > 
> > I don't grok why the image container size would be relative to the size of the containing block. Beth, do you recall?
> 
> I don't recall all of the specifics…but I think that we decided to treat SVG-as-image as a regular image with width:100%, which would calculate based on the containing block.

But in this testcase the image has a fixed size. I don't see why the containing block would come into it.
Comment 7 Beth Dakin 2011-01-10 11:43:38 PST
(In reply to comment #6)
n this testcase the image has a fixed size. I don't see why the containing block would come into it.

Yeah, I definitely agree that there is a bug in the code.
Comment 8 Tim Horton 2011-07-07 14:13:52 PDT
<rdar://problem/5812360>
Comment 9 Nikolas Zimmermann 2011-07-23 05:02:07 PDT
47156 fixes this.
Comment 10 Nikolas Zimmermann 2011-10-31 08:31:03 PDT
Fixed in r98852. Thanks for the testcase!