summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-07-22 01:36:07 +0200
committerAndreas Kling <kling@serenityos.org>2020-07-22 01:39:51 +0200
commitf43590f5349da8207fa831b16cf677192b0787b3 (patch)
treec8eef79aa4be4f9a074e136cb9e0ba21431a31f3 /Libraries
parenta3feb46ad7f2bc249f350bb671e51ba108ae9d20 (diff)
downloadserenity-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.cpp23
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);
}