From f43590f5349da8207fa831b16cf677192b0787b3 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 22 Jul 2020 01:36:07 +0200 Subject: [PATCH] LibWeb: Set the intrinsic width/height of instead of hacking it Images were added before replaced element layout knew about intrinsic sizes, so this was a bit backwards. We now instead transfer the known intrinsic sizes from the ImageLoader to the LayoutImage. --- Libraries/LibWeb/Layout/LayoutImage.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Libraries/LibWeb/Layout/LayoutImage.cpp b/Libraries/LibWeb/Layout/LayoutImage.cpp index eb81544f5c..b61e0c9473 100644 --- a/Libraries/LibWeb/Layout/LayoutImage.cpp +++ b/Libraries/LibWeb/Layout/LayoutImage.cpp @@ -54,12 +54,23 @@ int LayoutImage::preferred_height() const void LayoutImage::layout(LayoutMode layout_mode) { - if (preferred_width() && preferred_height()) { + if (m_image_loader.width()) { set_has_intrinsic_width(true); + set_intrinsic_width(m_image_loader.width()); + } + if (m_image_loader.height()) { set_has_intrinsic_height(true); - set_intrinsic_width(preferred_width()); - set_intrinsic_height(preferred_height()); - } else if (renders_as_alt_text()) { + set_intrinsic_height(m_image_loader.height()); + } + + if (m_image_loader.width() && m_image_loader.height()) { + set_has_intrinsic_ratio(true); + set_intrinsic_ratio((float)m_image_loader.width() / (float)m_image_loader.height()); + } else { + set_has_intrinsic_ratio(false); + } + + if (renders_as_alt_text()) { auto& image_element = to(node()); auto& font = Gfx::Font::default_font(); auto alt = image_element.alt(); @@ -67,7 +78,9 @@ void LayoutImage::layout(LayoutMode layout_mode) alt = image_element.src(); set_width(font.width(alt) + 16); set_height(font.glyph_height() + 16); - } else { + } + + if (!has_intrinsic_width() && !has_intrinsic_height()) { set_width(16); set_height(16); }