From af6a491bfe014a4d015ea8e452f7f0f9aad42ea9 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Tue, 26 Sep 2023 15:15:31 +0200 Subject: [PATCH] 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. --- layout/base/LayoutConstants.h | 4 ++++ layout/base/nsLayoutUtils.cpp | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/layout/base/LayoutConstants.h b/layout/base/LayoutConstants.h index d624a1a196..08cae5f12a 100644 --- a/layout/base/LayoutConstants.h +++ b/layout/base/LayoutConstants.h @@ -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___ diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index fbf0a04792..2c974074fc 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -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);