diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index 228d3b3285..28fd861989 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -190,7 +190,7 @@ void InlineFormattingContext::generate_line_boxes(LayoutMode layout_mode) 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.append_box(box, item.border_start + item.padding_start, item.padding_end + item.border_end); + line_builder.append_box(box, item.border_start + item.padding_start, item.padding_end + item.border_end, item.margin_start, item.margin_end); break; } case InlineLevelIterator::Item::Type::AbsolutelyPositionedElement: @@ -207,6 +207,8 @@ void InlineFormattingContext::generate_line_boxes(LayoutMode layout_mode) item.length_in_node, item.border_start + item.padding_start, item.padding_end + item.border_end, + item.margin_start, + item.margin_end, item.width, text_node.computed_values().font_size()); break; diff --git a/Userland/Libraries/LibWeb/Layout/LineBox.cpp b/Userland/Libraries/LibWeb/Layout/LineBox.cpp index 5e5912ee51..1e795ddcdd 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/LineBox.cpp @@ -15,7 +15,7 @@ namespace Web::Layout { -void LineBox::add_fragment(Node const& layout_node, int start, int length, float leading_size, float trailing_size, float content_width, float content_height, float border_box_top, float border_box_bottom, LineBoxFragment::Type fragment_type) +void LineBox::add_fragment(Node const& layout_node, int start, int length, float leading_size, float trailing_size, float leading_margin, float trailing_margin, float content_width, float content_height, float border_box_top, float border_box_bottom, LineBoxFragment::Type fragment_type) { bool text_align_is_justify = layout_node.computed_values().text_align() == CSS::TextAlign::Justify; if (!text_align_is_justify && !m_fragments.is_empty() && &m_fragments.last().layout_node() == &layout_node) { @@ -24,9 +24,11 @@ void LineBox::add_fragment(Node const& layout_node, int start, int length, float m_fragments.last().m_length = (start - m_fragments.last().m_start) + length; m_fragments.last().set_width(m_fragments.last().width() + content_width); } else { - m_fragments.append(LineBoxFragment { layout_node, start, length, Gfx::FloatPoint(m_width + leading_size, 0.0f), Gfx::FloatSize(content_width, content_height), border_box_top, border_box_bottom, fragment_type }); + float x_offset = leading_margin + leading_size + m_width; + float y_offset = 0.0f; + m_fragments.append(LineBoxFragment { layout_node, start, length, Gfx::FloatPoint(x_offset, y_offset), Gfx::FloatSize(content_width, content_height), border_box_top, border_box_bottom, fragment_type }); } - m_width += content_width + leading_size + trailing_size; + m_width += leading_margin + leading_size + content_width + trailing_size + trailing_margin; } void LineBox::trim_trailing_whitespace() diff --git a/Userland/Libraries/LibWeb/Layout/LineBox.h b/Userland/Libraries/LibWeb/Layout/LineBox.h index 12928cc767..53cf79bf00 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBox.h +++ b/Userland/Libraries/LibWeb/Layout/LineBox.h @@ -19,7 +19,7 @@ public: float bottom() const { return m_bottom; } float baseline() const { return m_baseline; } - void add_fragment(Node const& layout_node, int start, int length, float leading_size, float trailing_size, float content_width, float content_height, float border_box_top, float border_box_bottom, LineBoxFragment::Type = LineBoxFragment::Type::Normal); + void add_fragment(Node const& layout_node, int start, int length, float leading_size, float trailing_size, float leading_margin, float trailing_margin, float content_width, float content_height, float border_box_top, float border_box_bottom, LineBoxFragment::Type = LineBoxFragment::Type::Normal); Vector const& fragments() const { return m_fragments; } Vector& fragments() { return m_fragments; } diff --git a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp index 2a4d80bb75..65c4db3880 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp +++ b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp @@ -49,11 +49,11 @@ LineBox& LineBuilder::ensure_last_line_box() return line_boxes.last(); } -void LineBuilder::append_box(Box const& box, float leading_size, float trailing_size) +void LineBuilder::append_box(Box const& box, float leading_size, float trailing_size, float leading_margin, float trailing_margin) { auto& box_state = m_formatting_state.get_mutable(box); auto& line_box = ensure_last_line_box(); - line_box.add_fragment(box, 0, 0, leading_size, trailing_size, box_state.content_width, box_state.content_height, box_state.border_box_top(), box_state.border_box_bottom()); + line_box.add_fragment(box, 0, 0, leading_size, trailing_size, leading_margin, trailing_margin, box_state.content_width, box_state.content_height, box_state.border_box_top(), box_state.border_box_bottom()); m_max_height_on_current_line = max(m_max_height_on_current_line, box_state.border_box_height()); box_state.containing_line_box_fragment = LineBoxFragmentCoordinate { @@ -62,9 +62,9 @@ void LineBuilder::append_box(Box const& box, float leading_size, float trailing_ }; } -void LineBuilder::append_text_chunk(TextNode const& text_node, size_t offset_in_node, size_t length_in_node, float leading_size, float trailing_size, float content_width, float content_height) +void LineBuilder::append_text_chunk(TextNode const& text_node, 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) { - ensure_last_line_box().add_fragment(text_node, offset_in_node, length_in_node, leading_size, trailing_size, content_width, content_height, 0, 0); + ensure_last_line_box().add_fragment(text_node, offset_in_node, length_in_node, leading_size, trailing_size, leading_margin, trailing_margin, content_width, content_height, 0, 0); m_max_height_on_current_line = max(m_max_height_on_current_line, content_height); } diff --git a/Userland/Libraries/LibWeb/Layout/LineBuilder.h b/Userland/Libraries/LibWeb/Layout/LineBuilder.h index b4bf74c868..bcadc64dfb 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBuilder.h +++ b/Userland/Libraries/LibWeb/Layout/LineBuilder.h @@ -19,8 +19,8 @@ public: ~LineBuilder(); void break_line(); - void append_box(Box const&, float leading_size, float trailing_size); - void append_text_chunk(TextNode const&, size_t offset_in_node, size_t length_in_node, float leading_size, float trailing_size, float content_width, float content_height); + void append_box(Box const&, float leading_size, float trailing_size, float leading_margin, float trailing_margin); + 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); void break_if_needed(LayoutMode layout_mode, float next_item_width, bool should_force_break) {