From 349fdd9f47f7b63b4dbdd97beb7df3d4fe3975ad Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Wed, 27 Aug 2025 23:59:26 +0200 Subject: [PATCH] LibWeb: Explicitly update LineBuilder's last line at end of IFC run Currently we're relying on LineBuilder's destructor to handle updating the last line, if required. In order to fix an issue with our absolute positioning code, we need to be able to update the last line earlier than that. Remove the destructor and replace it with an explicit call to LineBuilder::update_last_line(). No functional changes. --- Libraries/LibWeb/Layout/InlineFormattingContext.cpp | 2 ++ Libraries/LibWeb/Layout/LineBuilder.cpp | 12 +++++------- Libraries/LibWeb/Layout/LineBuilder.h | 1 - 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index 20d7d9d6a2b..5920c4db77b 100644 --- a/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -447,6 +447,8 @@ void InlineFormattingContext::generate_line_boxes() auto& box_state = m_state.get_mutable(*box); box_state.set_static_position_rect(calculate_static_position_rect(*box)); } + + line_builder.update_last_line(); } bool InlineFormattingContext::any_floats_intrude_at_block_offset(CSSPixels block_offset) const diff --git a/Libraries/LibWeb/Layout/LineBuilder.cpp b/Libraries/LibWeb/Layout/LineBuilder.cpp index fd524d77951..dd6effa3f57 100644 --- a/Libraries/LibWeb/Layout/LineBuilder.cpp +++ b/Libraries/LibWeb/Layout/LineBuilder.cpp @@ -21,12 +21,6 @@ LineBuilder::LineBuilder(InlineFormattingContext& context, LayoutState& layout_s begin_new_line(false); } -LineBuilder::~LineBuilder() -{ - if (m_last_line_needs_update) - update_last_line(); -} - void LineBuilder::break_line(ForcedBreak forced_break, Optional next_item_width) { // FIXME: Respect inline direction. @@ -35,7 +29,9 @@ void LineBuilder::break_line(ForcedBreak forced_break, Optional next_ last_line_box.m_has_break = true; last_line_box.m_has_forced_break = forced_break == ForcedBreak::Yes; + m_last_line_needs_update = true; update_last_line(); + size_t break_count = 0; bool floats_intrude_at_current_y = false; do { @@ -192,9 +188,11 @@ bool LineBuilder::should_break(CSSPixels next_item_width) void LineBuilder::update_last_line() { + if (!m_last_line_needs_update) + return; m_last_line_needs_update = false; - auto& line_boxes = m_containing_block_used_values.line_boxes; + auto& line_boxes = m_containing_block_used_values.line_boxes; if (line_boxes.is_empty()) return; diff --git a/Libraries/LibWeb/Layout/LineBuilder.h b/Libraries/LibWeb/Layout/LineBuilder.h index 9e1f2f03ca4..a8636972bed 100644 --- a/Libraries/LibWeb/Layout/LineBuilder.h +++ b/Libraries/LibWeb/Layout/LineBuilder.h @@ -16,7 +16,6 @@ class LineBuilder { public: LineBuilder(InlineFormattingContext&, LayoutState&, LayoutState::UsedValues& containing_block_used_values, CSS::Direction, CSS::WritingMode); - ~LineBuilder(); enum class ForcedBreak { No,