diff --git a/Userland/Libraries/LibWeb/Layout/Box.cpp b/Userland/Libraries/LibWeb/Layout/Box.cpp index ccc1fa14c0..5ca73e3439 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.cpp +++ b/Userland/Libraries/LibWeb/Layout/Box.cpp @@ -236,7 +236,7 @@ const Gfx::FloatRect Box::absolute_rect() const return rect; } -void Box::set_containing_line_box_fragment(LineBoxFragmentCoordinate fragment_coordinate) +void Box::set_containing_line_box_fragment(Optional fragment_coordinate) { m_containing_line_box_fragment = fragment_coordinate; } diff --git a/Userland/Libraries/LibWeb/Layout/Box.h b/Userland/Libraries/LibWeb/Layout/Box.h index 557c4548b9..8148c8f72a 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.h +++ b/Userland/Libraries/LibWeb/Layout/Box.h @@ -14,6 +14,11 @@ namespace Web::Layout { +struct LineBoxFragmentCoordinate { + size_t line_box_index { 0 }; + size_t fragment_index { 0 }; +}; + class Box : public NodeWithStyleAndBoxModelMetrics { public: struct OverflowData { @@ -82,11 +87,7 @@ public: bool is_body() const; - struct LineBoxFragmentCoordinate { - size_t line_box_index { 0 }; - size_t fragment_index { 0 }; - }; - void set_containing_line_box_fragment(LineBoxFragmentCoordinate); + void set_containing_line_box_fragment(Optional); StackingContext* stacking_context() { return m_stacking_context; } const StackingContext* stacking_context() const { return m_stacking_context; } diff --git a/Userland/Libraries/LibWeb/Layout/FormattingState.cpp b/Userland/Libraries/LibWeb/Layout/FormattingState.cpp index 8c7a464f66..ebfda928e9 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingState.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingState.cpp @@ -44,6 +44,7 @@ void FormattingState::commit() box.set_offset(node_state.offset); box.set_content_size(node_state.content_width, node_state.content_height); box.set_overflow_data(move(node_state.overflow_data)); + box.set_containing_line_box_fragment(node_state.containing_line_box_fragment); } // For block containers, transfer line boxes. diff --git a/Userland/Libraries/LibWeb/Layout/FormattingState.h b/Userland/Libraries/LibWeb/Layout/FormattingState.h index 12e3f9264c..9a68830efe 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingState.h +++ b/Userland/Libraries/LibWeb/Layout/FormattingState.h @@ -63,6 +63,8 @@ struct FormattingState { return *overflow_data; } + Optional containing_line_box_fragment; + // NOTE: NodeState is ref-counted and accessed via copy-on-write helpers below. size_t ref_count { 1 }; void ref() diff --git a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp index e4421a16ac..b1f0cef2b9 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp +++ b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp @@ -51,16 +51,15 @@ LineBox& LineBuilder::ensure_last_line_box() void LineBuilder::append_box(Box const& box, float leading_size, float trailing_size) { - auto const& box_state = m_formatting_state.get(box); + 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()); m_max_height_on_current_line = max(m_max_height_on_current_line, box_state.content_height); - // FIXME: Move this to FormattingContext! - const_cast(box).set_containing_line_box_fragment({ + box_state.containing_line_box_fragment = LineBoxFragmentCoordinate { .line_box_index = m_containing_block_state.line_boxes.size() - 1, .fragment_index = line_box.fragments().size() - 1, - }); + }; } 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)