mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:17:34 +00:00
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.
This commit is contained in:
parent
a3feb46ad7
commit
f43590f534
1 changed files with 18 additions and 5 deletions
|
@ -54,12 +54,23 @@ int LayoutImage::preferred_height() const
|
||||||
|
|
||||||
void LayoutImage::layout(LayoutMode layout_mode)
|
void LayoutImage::layout(LayoutMode layout_mode)
|
||||||
{
|
{
|
||||||
if (preferred_width() && preferred_height()) {
|
if (m_image_loader.width()) {
|
||||||
set_has_intrinsic_width(true);
|
set_has_intrinsic_width(true);
|
||||||
|
set_intrinsic_width(m_image_loader.width());
|
||||||
|
}
|
||||||
|
if (m_image_loader.height()) {
|
||||||
set_has_intrinsic_height(true);
|
set_has_intrinsic_height(true);
|
||||||
set_intrinsic_width(preferred_width());
|
set_intrinsic_height(m_image_loader.height());
|
||||||
set_intrinsic_height(preferred_height());
|
}
|
||||||
} else if (renders_as_alt_text()) {
|
|
||||||
|
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& image_element = to<HTMLImageElement>(node());
|
||||||
auto& font = Gfx::Font::default_font();
|
auto& font = Gfx::Font::default_font();
|
||||||
auto alt = image_element.alt();
|
auto alt = image_element.alt();
|
||||||
|
@ -67,7 +78,9 @@ void LayoutImage::layout(LayoutMode layout_mode)
|
||||||
alt = image_element.src();
|
alt = image_element.src();
|
||||||
set_width(font.width(alt) + 16);
|
set_width(font.width(alt) + 16);
|
||||||
set_height(font.glyph_height() + 16);
|
set_height(font.glyph_height() + 16);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if (!has_intrinsic_width() && !has_intrinsic_height()) {
|
||||||
set_width(16);
|
set_width(16);
|
||||||
set_height(16);
|
set_height(16);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue