diff options
author | Andreas Kling <kling@serenityos.org> | 2020-07-22 01:36:07 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-22 01:39:51 +0200 |
commit | f43590f5349da8207fa831b16cf677192b0787b3 (patch) | |
tree | c8eef79aa4be4f9a074e136cb9e0ba21431a31f3 /Libraries | |
parent | a3feb46ad7f2bc249f350bb671e51ba108ae9d20 (diff) | |
download | serenity-f43590f5349da8207fa831b16cf677192b0787b3.zip |
LibWeb: Set the intrinsic width/height of <img> 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.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutImage.cpp | 23 |
1 files 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<HTMLImageElement>(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); } |