diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index ad49d9d6f40..21665601b81 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -593,7 +593,7 @@ void BlockFormattingContext::layout_floating_box(Box const& box, BlockContainer // If we have a LineBuilder, we're in the middle of inline layout, otherwise this is block layout. if (line_builder) { float y_offset = box_state.margin_box_top() + box_state.inset_top; - line_builder->break_if_needed(layout_mode, box_state.border_box_width(), false); + line_builder->break_if_needed(layout_mode, box_state.border_box_width()); box_state.offset.set_y(line_builder->current_y() + y_offset); line_builder->adjust_last_line_after_inserting_floating_box({}, box.computed_values().float_(), box_state.border_box_width()); } else { diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index 2291235ecd0..7e83192f456 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -241,7 +241,7 @@ void InlineFormattingContext::generate_line_boxes(LayoutMode layout_mode) break; case InlineLevelIterator::Item::Type::Element: { auto& box = verify_cast(*item.node); - line_builder.break_if_needed(layout_mode, item.border_box_width(), item.should_force_break); + line_builder.break_if_needed(layout_mode, item.border_box_width()); line_builder.append_box(box, item.border_start + item.padding_start, item.padding_end + item.border_end, item.margin_start, item.margin_end); break; } @@ -257,7 +257,7 @@ void InlineFormattingContext::generate_line_boxes(LayoutMode layout_mode) case InlineLevelIterator::Item::Type::Text: { auto& text_node = verify_cast(*item.node); - if (line_builder.break_if_needed(layout_mode, item.border_box_width(), item.should_force_break)) { + if (line_builder.break_if_needed(layout_mode, item.border_box_width())) { if (item.is_collapsible_whitespace) break; } diff --git a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp index c37aba6cf49..da9d88c9299 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp @@ -142,13 +142,19 @@ Optional InlineLevelIterator::next(float available_wi auto& chunk = chunk_opt.value(); float chunk_width = text_node.font().width(chunk.view) + text_node.font().glyph_spacing(); + + if (m_text_node_context->do_respect_linebreaks && chunk.has_breaking_newline) { + return Item { + .type = Item::Type::ForcedBreak, + }; + } + Item item { .type = Item::Type::Text, .node = &text_node, .offset_in_node = chunk.start, .length_in_node = chunk.length, .width = chunk_width, - .should_force_break = m_text_node_context->do_respect_linebreaks && chunk.has_breaking_newline, .is_collapsible_whitespace = m_text_node_context->do_collapse && chunk.is_all_whitespace, }; diff --git a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.h b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.h index e87c03005f7..6709c9735fa 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.h +++ b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.h @@ -40,7 +40,6 @@ public: float border_end { 0.0f }; float margin_start { 0.0f }; float margin_end { 0.0f }; - bool should_force_break { false }; bool is_collapsible_whitespace { false }; float border_box_width() const diff --git a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp index 9f4e36350a2..fe1b0caccad 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp +++ b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp @@ -79,12 +79,10 @@ void LineBuilder::append_text_chunk(TextNode const& text_node, size_t offset_in_ m_max_height_on_current_line = max(m_max_height_on_current_line, content_height); } -bool LineBuilder::should_break(LayoutMode layout_mode, float next_item_width, bool should_force_break) +bool LineBuilder::should_break(LayoutMode layout_mode, float next_item_width) { if (layout_mode == LayoutMode::MinContent) return true; - if (should_force_break) - return true; if (layout_mode == LayoutMode::MaxContent) return false; auto const& line_boxes = m_containing_block_state.line_boxes; diff --git a/Userland/Libraries/LibWeb/Layout/LineBuilder.h b/Userland/Libraries/LibWeb/Layout/LineBuilder.h index 740a374728a..0f28cfeb81d 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBuilder.h +++ b/Userland/Libraries/LibWeb/Layout/LineBuilder.h @@ -23,9 +23,9 @@ public: void append_text_chunk(TextNode const&, size_t offset_in_node, size_t length_in_node, float leading_size, float trailing_size, float leading_margin, float trailing_margin, float content_width, float content_height); // Returns whether a line break occurred. - bool break_if_needed(LayoutMode layout_mode, float next_item_width, bool should_force_break) + bool break_if_needed(LayoutMode layout_mode, float next_item_width) { - if (should_break(layout_mode, next_item_width, should_force_break)) { + if (should_break(layout_mode, next_item_width)) { break_line(); return true; } @@ -45,7 +45,7 @@ public: private: void begin_new_line(bool increment_y); - bool should_break(LayoutMode, float next_item_width, bool should_force_break); + bool should_break(LayoutMode, float next_item_width); LineBox& ensure_last_line_box();