From 2615728d6bc352d6011f98fa202a8ba821bb3755 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 21 Feb 2022 11:22:08 +0100 Subject: [PATCH] LibWeb: Store overflow data in the FormattingState --- .../LibWeb/Layout/BlockFormattingContext.cpp | 6 ++---- Userland/Libraries/LibWeb/Layout/Box.h | 9 +-------- Userland/Libraries/LibWeb/Layout/FormattingState.cpp | 3 ++- Userland/Libraries/LibWeb/Layout/FormattingState.h | 11 ++++++++++- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index a1040b4057..895b79339d 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -528,6 +528,7 @@ void BlockFormattingContext::layout_initial_containing_block(LayoutMode layout_m auto viewport_rect = root().browsing_context().viewport_rect(); auto& icb = verify_cast(root()); + auto& icb_state = m_state.ensure(icb); VERIFY(!icb.children_are_inline()); layout_block_level_children(root(), layout_mode); @@ -546,13 +547,10 @@ void BlockFormattingContext::layout_initial_containing_block(LayoutMode layout_m if (bottom_edge >= viewport_rect.height() || right_edge >= viewport_rect.width()) { // FIXME: Move overflow data to FormattingState! - auto& overflow_data = const_cast(icb).ensure_overflow_data(); + auto& overflow_data = icb_state.ensure_overflow_data(); overflow_data.scrollable_overflow_rect = viewport_rect.to_type(); // NOTE: The edges are *within* the rectangle, so we add 1 to get the width and height. overflow_data.scrollable_overflow_rect.set_size(right_edge + 1, bottom_edge + 1); - } else { - // FIXME: Move overflow data to FormattingState! - const_cast(icb).clear_overflow_data(); } } diff --git a/Userland/Libraries/LibWeb/Layout/Box.h b/Userland/Libraries/LibWeb/Layout/Box.h index a46fff8bbd..ed5733c5b4 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.h +++ b/Userland/Libraries/LibWeb/Layout/Box.h @@ -113,14 +113,7 @@ public: return m_overflow_data->scrollable_overflow_rect; } - OverflowData& ensure_overflow_data() - { - if (!m_overflow_data) - m_overflow_data = make(); - return *m_overflow_data; - } - - void clear_overflow_data() { m_overflow_data = nullptr; } + void set_overflow_data(OwnPtr data) { m_overflow_data = move(data); } virtual void before_children_paint(PaintContext&, PaintPhase) override; virtual void after_children_paint(PaintContext&, PaintPhase) override; diff --git a/Userland/Libraries/LibWeb/Layout/FormattingState.cpp b/Userland/Libraries/LibWeb/Layout/FormattingState.cpp index f293c07e1b..04f460c34d 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingState.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingState.cpp @@ -21,11 +21,12 @@ void FormattingState::commit() node.box_model().border = { node_state.border_top, node_state.border_right, node_state.border_bottom, node_state.border_left }; node.box_model().margin = { node_state.margin_top, node_state.margin_right, node_state.margin_bottom, node_state.margin_left }; - // For boxes, transfer relative offset and size. + // For boxes, transfer relative offset, size, and overflow data. if (is(node)) { auto& box = static_cast(node); 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)); } // For block containers, transfer line boxes. diff --git a/Userland/Libraries/LibWeb/Layout/FormattingState.h b/Userland/Libraries/LibWeb/Layout/FormattingState.h index 23956ee8b0..b3168c0999 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingState.h +++ b/Userland/Libraries/LibWeb/Layout/FormattingState.h @@ -8,8 +8,8 @@ #include #include +#include #include -#include namespace Web::Layout { @@ -53,6 +53,15 @@ struct FormattingState { float border_box_width() const { return border_box_left() + content_width + border_box_right(); } float border_box_height() const { return border_box_top() + content_height + border_box_bottom(); } + + OwnPtr overflow_data; + + Layout::Box::OverflowData& ensure_overflow_data() + { + if (!overflow_data) + overflow_data = make(); + return *overflow_data; + } }; void commit();