diff options
author | Andreas Kling <kling@serenityos.org> | 2022-03-18 12:31:26 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-18 15:18:48 +0100 |
commit | d3932b58802efe9e712a1ae2fe9da5b5f330f3cb (patch) | |
tree | 3f85f69e949e8442b5de2b01002ab97dbd18a738 | |
parent | 60c781ebc7fc15df0ebdd878b97ffaf7fcafc4b6 (diff) | |
download | serenity-d3932b58802efe9e712a1ae2fe9da5b5f330f3cb.zip |
LibWeb: Give FormattingState a reference to its root state
FormattingStates can have parents, in case we're performing nested
layouts to determine something's intrinsic size. In those cases, it will
soon be useful to find the outermost (root) state.
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/FormattingState.h | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/FormattingState.h b/Userland/Libraries/LibWeb/Layout/FormattingState.h index 0598d49e0f..523d69c98d 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingState.h +++ b/Userland/Libraries/LibWeb/Layout/FormattingState.h @@ -15,10 +15,23 @@ namespace Web::Layout { struct FormattingState { - FormattingState() { } + FormattingState() + : m_root(*this) + { + } + explicit FormattingState(FormattingState const* parent) : m_parent(parent) + , m_root(find_root()) + { + } + + FormattingState const& find_root() const { + FormattingState const* root = this; + for (auto* state = m_parent; state; state = state->m_parent) + root = state; + return *root; } struct NodeState { @@ -92,6 +105,7 @@ struct FormattingState { HashMap<NodeWithStyleAndBoxModelMetrics const*, IntrinsicSizes> mutable intrinsic_sizes; FormattingState const* m_parent { nullptr }; + FormattingState const& m_root; }; Gfx::FloatRect absolute_content_rect(Box const&, FormattingState const&); |