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,12 +15,25 @@ 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 { float content_width { 0 }; float content_height { 0 }; @@ -92,6 +105,7 @@ struct FormattingState { HashMap mutable intrinsic_sizes; FormattingState const* m_parent { nullptr }; + FormattingState const& m_root; }; Gfx::FloatRect absolute_content_rect(Box const&, FormattingState const&);