diff options
author | Andreas Kling <kling@serenityos.org> | 2022-01-20 19:06:25 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-23 01:22:41 +0100 |
commit | 2b631cde45ce3987d78cdc87d12fcd6109283852 (patch) | |
tree | 82404c72535e428219c7639c60d0c101cf89057a /Userland/Libraries/LibWeb/Layout | |
parent | 251b2f49a23ebaca50b461b600cf839c04a7a609 (diff) | |
download | serenity-2b631cde45ce3987d78cdc87d12fcd6109283852.zip |
LibWeb: Avoid creating an empty first line box in block containers
Diffstat (limited to 'Userland/Libraries/LibWeb/Layout')
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/LineBuilder.cpp | 8 |
2 files changed, 5 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index 1fcc42a270..27ca5447aa 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -158,7 +158,6 @@ void InlineFormattingContext::dimension_box_on_line(Box& box, LayoutMode layout_ void InlineFormattingContext::generate_line_boxes(LayoutMode layout_mode) { containing_block().line_boxes().clear(); - containing_block().ensure_last_line_box(); InlineLevelIterator iterator(containing_block(), layout_mode); LineBuilder line_builder(*this); diff --git a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp index 1b9eed559d..ad13a7b3aa 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp +++ b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp @@ -36,13 +36,13 @@ void LineBuilder::begin_new_line() void LineBuilder::append_box(Box& box) { - m_context.containing_block().line_boxes().last().add_fragment(box, 0, 0, box.width(), box.height()); + m_context.containing_block().ensure_last_line_box().add_fragment(box, 0, 0, box.width(), box.height()); m_max_height_on_current_line = max(m_max_height_on_current_line, box.height()); } void LineBuilder::append_text_chunk(TextNode& text_node, size_t offset_in_node, size_t length_in_node, float width, float height) { - m_context.containing_block().line_boxes().last().add_fragment(text_node, offset_in_node, length_in_node, width, height); + m_context.containing_block().ensure_last_line_box().add_fragment(text_node, offset_in_node, length_in_node, width, height); m_max_height_on_current_line = max(m_max_height_on_current_line, height); } @@ -54,7 +54,9 @@ bool LineBuilder::should_break(LayoutMode layout_mode, float next_item_width, bo return true; if (layout_mode == LayoutMode::OnlyRequiredLineBreaks) return false; - auto current_line_width = m_context.containing_block().line_boxes().last().width(); + auto current_line_width = 0.0f; + if (!m_context.containing_block().line_boxes().is_empty()) + current_line_width = m_context.containing_block().line_boxes().last().width(); return (current_line_width + next_item_width) > m_available_width_for_current_line; } |