Bug 1935269 Comment 6 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

Here is WebKit's [`HTMLImageElement::naturalWidth()`](https://searchfox.org/wubkat/rev/48c752dce43162935898b93cefa254a21a5e84c5/Source/WebCore/html/HTMLImageElement.cpp#631) implementation.

With a bit of guesswork about the exact codepath, I think that function ends up calling this stack of functions to reach the relevant SVG-image sizing code:
[`CachedImage::unclampedImageSizeForRenderer`](https://searchfox.org/wubkat/rev/48c752dce43162935898b93cefa254a21a5e84c5/Source/WebCore/loader/cache/CachedImage.cpp#334)
[`CachedImage::imageSizeForRenderer`](https://searchfox.org/wubkat/rev/48c752dce43162935898b93cefa254a21a5e84c5/Source/WebCore/loader/cache/CachedImage.cpp#314)
[`SVGImageCache::imageSizeForRenderer`](https://searchfox.org/wubkat/rev/48c752dce43162935898b93cefa254a21a5e84c5/Source/WebCore/svg/graphics/SVGImageCache.cpp#80)
[`SVGImage::size`](https://searchfox.org/wubkat/rev/48c752dce43162935898b93cefa254a21a5e84c5/Source/WebCore/svg/graphics/SVGImage.h#54)

That `size` function just returns `SVGImage::m_intrinsicSize` which would have gotten its value in [`SVGImage::containerSize`](https://searchfox.org/wubkat/rev/48c752dce43162935898b93cefa254a21a5e84c5/Source/WebCore/svg/graphics/SVGImage.cpp#148)

And specifically this section seems to fall back to 300x150 when setting that value:
https://searchfox.org/wubkat/rev/48c752dce43162935898b93cefa254a21a5e84c5/Source/WebCore/svg/graphics/SVGImage.cpp#148,172-180
```cpp
IntSize SVGImage::containerSize() const
...
    FloatSize currentSize;
    if (rootElement->hasIntrinsicWidth() && rootElement->hasIntrinsicHeight())
        currentSize = rootElement->currentViewportSizeExcludingZoom();
    else
        currentSize = rootElement->currentViewBoxRect().size();

    // Use the default CSS intrinsic size if the above failed.
    if (currentSize.isEmpty())
        return IntSize(300, 150);
```
Here is WebKit's [`HTMLImageElement::naturalWidth()`](https://searchfox.org/wubkat/rev/48c752dce43162935898b93cefa254a21a5e84c5/Source/WebCore/html/HTMLImageElement.cpp#631) implementation.

With a bit of guesswork about the exact codepath, I think that function ends up calling this stack of functions to reach the relevant SVG-image sizing code:
[`CachedImage::unclampedImageSizeForRenderer`](https://searchfox.org/wubkat/rev/48c752dce43162935898b93cefa254a21a5e84c5/Source/WebCore/loader/cache/CachedImage.cpp#334)
[`CachedImage::imageSizeForRenderer`](https://searchfox.org/wubkat/rev/48c752dce43162935898b93cefa254a21a5e84c5/Source/WebCore/loader/cache/CachedImage.cpp#314)
[`SVGImageCache::imageSizeForRenderer`](https://searchfox.org/wubkat/rev/48c752dce43162935898b93cefa254a21a5e84c5/Source/WebCore/svg/graphics/SVGImageCache.cpp#80)
[`SVGImage::size`](https://searchfox.org/wubkat/rev/48c752dce43162935898b93cefa254a21a5e84c5/Source/WebCore/svg/graphics/SVGImage.h#54)

That `size` function just returns `SVGImage::m_intrinsicSize` which would have gotten its value in [`SVGImage::containerSize`](https://searchfox.org/wubkat/rev/48c752dce43162935898b93cefa254a21a5e84c5/Source/WebCore/svg/graphics/SVGImage.cpp#148)

And specifically this section seems to fall back to 300x150 when setting that value:https://searchfox.org/wubkat/rev/48c752dce43162935898b93cefa254a21a5e84c5/Source/WebCore/svg/graphics/SVGImage.cpp#148-149,172-180
```cpp
IntSize SVGImage::containerSize() const
{
...
    FloatSize currentSize;
    if (rootElement->hasIntrinsicWidth() && rootElement->hasIntrinsicHeight())
        currentSize = rootElement->currentViewportSizeExcludingZoom();
    else
        currentSize = rootElement->currentViewBoxRect().size();

    // Use the default CSS intrinsic size if the above failed.
    if (currentSize.isEmpty())
        return IntSize(300, 150);
```

Back to Bug 1935269 Comment 6