1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:37:35 +00:00

LibWeb: Size non-loaded <img> to fit the replacement (alt) text

We achieve this by simply setting the intrinsic size to the size needed
to render the replacement text.

This fixes a long-standing issue where non-loaded images would default
to the goofy-looking 300x150 fallback size for replaced elements.
This commit is contained in:
Andreas Kling 2021-11-03 10:25:01 +01:00
parent 409b20e316
commit 642915215f

View file

@ -60,8 +60,8 @@ void ImageBox::prepare_for_replaced_layout()
auto alt = image_element.alt();
if (alt.is_empty())
alt = image_element.src();
set_width(font.width(alt) + 16);
set_height(font.glyph_height() + 16);
set_intrinsic_width(font.width(alt) + 16);
set_intrinsic_height(font.glyph_height() + 16);
}
if (!has_intrinsic_width() && !has_intrinsic_height()) {