Skip to content

Commit

Permalink
LibWeb: Give FormattingState a reference to its root state
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
awesomekling committed Mar 18, 2022
1 parent 60c781e commit d3932b5
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Userland/Libraries/LibWeb/Layout/FormattingState.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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&);
Expand Down

0 comments on commit d3932b5

Please sign in to comment.