From ca2807ba42588722b9134c8aef152b551586afdc Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 11 Apr 2022 00:09:56 +0200 Subject: [PATCH] AK: Honor box's own intrinsic size in calculate_intrinsic_sizes() If a layout box claims to have both intrinsic width and height, we can simply return those instead of performing any kind of layout. --- .../Libraries/LibWeb/Layout/FormattingContext.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index a63bfdbb4c..3033d53ae1 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -799,6 +799,17 @@ void FormattingContext::compute_inset(Box const& box) FormattingState::IntrinsicSizes FormattingContext::calculate_intrinsic_sizes(Layout::Box const& box) const { + // FIXME: This should handle replaced elements with "native" intrinsic size properly! + + if (box.has_intrinsic_width() && box.has_intrinsic_height()) { + auto const& replaced_box = static_cast(box); + Gfx::FloatSize size { replaced_box.intrinsic_width().value_or(0), replaced_box.intrinsic_height().value_or(0) }; + return FormattingState::IntrinsicSizes { + .min_content_size = size, + .max_content_size = size, + }; + } + auto& root_state = m_state.m_root; // If we have cached intrinsic sizes for this box, use them. @@ -807,7 +818,6 @@ FormattingState::IntrinsicSizes FormattingContext::calculate_intrinsic_sizes(Lay return it->value; // Nothing cached, perform two throwaway layouts to determine the intrinsic sizes. - // FIXME: This should handle replaced elements with "native" intrinsic size properly! FormattingState::IntrinsicSizes cached_box_sizes; auto const& containing_block = *box.containing_block();