Issue #2316 - Part 1: Use fallback element sizes for w/h-less SVG

Instead of completely failing the call, use the CSS specified intrinsic
default width/height of 300x150.
This commit is contained in:
Moonchild 2023-09-26 15:15:31 +02:00 committed by roytam1
commit af6a491bfe
2 changed files with 14 additions and 3 deletions

View file

@ -26,5 +26,9 @@
#define NS_INTRINSIC_WIDTH_UNKNOWN nscoord_MIN
// The fallback size of width is 300px and the aspect-ratio is 2:1, based on the
// spec definition in CSS2 section 10.3.2
#define REPLACED_ELEM_FALLBACK_PX_WIDTH 300
#define REPLACED_ELEM_FALLBACK_PX_HEIGHT 150
#endif // LayoutConstants_h___

View file

@ -7172,10 +7172,17 @@ nsLayoutUtils::SurfaceFromElement(nsIImageLoadingContent* aElement,
imgWidth = element->Width();
imgHeight = element->Height();
} else {
// No size declared by SVG, so use the image container size.
// As stated in css-sizing-3 Intrinsic Sizes, use the fallback size
// of 300 x 150 for the width and height as-needed.
rv = imgContainer->GetWidth(&imgWidth);
nsresult rv2 = imgContainer->GetHeight(&imgHeight);
if (NS_FAILED(rv) || NS_FAILED(rv2))
return result;
if (NS_FAILED(rv)) {
imgWidth = REPLACED_ELEM_FALLBACK_PX_WIDTH;
}
rv = imgContainer->GetHeight(&imgHeight);
if (NS_FAILED(rv)) {
imgHeight = REPLACED_ELEM_FALLBACK_PX_HEIGHT;
}
}
result.mSize = IntSize(imgWidth, imgHeight);