From 66d08d24173de26b38e647aa70353caf2e6cb64f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 8 Jul 2022 22:07:42 +0200 Subject: [PATCH] LibWeb: Move IFC result measurement from IFC to BFC Before this change, IFC would first generate all of its line boxes and then measure them. It would then write some of the values into the state of the IFC's containing block. We now move that up to BFC::layout_inline_children() instead, which is a much more natural place to decide metrics for the block. --- .../LibWeb/Layout/BlockFormattingContext.cpp | 16 ++++++++++++++++ .../LibWeb/Layout/InlineFormattingContext.cpp | 17 ----------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index c84220ce51..e4be518ad8 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -396,6 +396,22 @@ void BlockFormattingContext::layout_inline_children(BlockContainer const& block_ InlineFormattingContext context(m_state, block_container, *this); context.run(block_container, layout_mode); + + float max_line_width = 0; + float content_height = 0; + + auto& block_container_state = m_state.get_mutable(block_container); + + for (auto& line_box : block_container_state.line_boxes) { + max_line_width = max(max_line_width, line_box.width()); + content_height += line_box.height(); + } + + if (layout_mode != LayoutMode::Normal) { + block_container_state.content_width = max_line_width; + } + + block_container_state.content_height = content_height; } void BlockFormattingContext::layout_block_level_children(BlockContainer const& block_container, LayoutMode layout_mode) diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index c276de356c..d8652a0315 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -66,24 +66,7 @@ float InlineFormattingContext::available_space_for_line(float y) const void InlineFormattingContext::run(Box const&, LayoutMode layout_mode) { VERIFY(containing_block().children_are_inline()); - generate_line_boxes(layout_mode); - - float max_line_width = 0; - float content_height = 0; - - for (auto& line_box : m_state.get(containing_block()).line_boxes) { - max_line_width = max(max_line_width, line_box.width()); - content_height += line_box.height(); - } - - auto& containing_block_state = m_state.get_mutable(containing_block()); - - if (layout_mode != LayoutMode::Normal) { - containing_block_state.content_width = max_line_width; - } - - containing_block_state.content_height = content_height; } void InlineFormattingContext::dimension_box_on_line(Box const& box, LayoutMode layout_mode)