LibWeb: Until an image has loaded or failed, don't occupy layout size

This patch makes images have an implicit zero intrinsic size before
they have either loaded or failed to load. This is tracked by the
ImageLoader object.

This fixes a long-standing issue with images occupying empty 150x150
rectangles of space.
This commit is contained in:
Andreas Kling 2020-08-12 13:47:55 +02:00
commit 305e2ef69c
Notes: sideshowbarker 2024-07-19 03:43:36 +09:00
3 changed files with 33 additions and 11 deletions

View file

@ -54,20 +54,27 @@ int LayoutImage::preferred_height() const
void LayoutImage::layout(LayoutMode layout_mode)
{
if (m_image_loader.width()) {
if (!m_image_loader.has_loaded_or_failed()) {
set_has_intrinsic_width(true);
set_intrinsic_width(m_image_loader.width());
}
if (m_image_loader.height()) {
set_has_intrinsic_height(true);
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());
set_intrinsic_width(0);
set_intrinsic_height(0);
} else {
set_has_intrinsic_ratio(false);
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_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()) {