Bug 52045

Summary: SVG image in HTML changes size as the window is resized
Product: WebKit Reporter: Simon Fraser (smfr) <simon.fraser>
Component: SVGAssignee: Nikolas Zimmermann <zimmermann>
Status: RESOLVED FIXED    
Severity: Normal CC: bdakin, eric, krit, simon.fraser, thorton, zimmermann
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: PC   
OS: OS X 10.5   
Bug Depends on: 47156    
Bug Blocks:    
Attachments:
Description Flags
SVG image for testcase
none
Testcase none

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!