1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:57:35 +00:00

LibWeb: Add FormattingContext::automatic_content_height()

This function should return the automatic height of the formatting
context's root box.

Until now, we've been relying on some magical handshakes between parent
and child context, when negotiating the height of child context root
boxes. This is a step towards something more reasonable.
This commit is contained in:
Andreas Kling 2022-09-24 13:39:43 +02:00
parent b52165c5d7
commit 62974160da
14 changed files with 48 additions and 2 deletions

View file

@ -39,6 +39,11 @@ bool BlockFormattingContext::is_initial() const
return is<InitialContainingBlock>(root());
}
float BlockFormattingContext::automatic_content_height() const
{
return compute_auto_height_for_block_formatting_context_root(m_state, root());
}
void BlockFormattingContext::run(Box const&, LayoutMode layout_mode)
{
if (is_initial()) {

View file

@ -23,6 +23,7 @@ public:
virtual void run(Box const&, LayoutMode) override;
virtual void run_intrinsic_sizing(Box const&) override;
virtual float automatic_content_height() const override;
bool is_initial() const;

View file

@ -52,6 +52,11 @@ FlexFormattingContext::FlexFormattingContext(LayoutState& state, Box const& flex
FlexFormattingContext::~FlexFormattingContext() = default;
float FlexFormattingContext::automatic_content_height() const
{
return m_state.get(flex_container()).content_height();
}
void FlexFormattingContext::run(Box const& run_box, LayoutMode layout_mode)
{
VERIFY(&run_box == &flex_container());

View file

@ -19,6 +19,7 @@ public:
virtual bool inhibits_floating() const override { return true; }
virtual void run(Box const&, LayoutMode) override;
virtual float automatic_content_height() const override;
Box const& flex_container() const { return context_box(); }

View file

@ -103,6 +103,7 @@ OwnPtr<FormattingContext> FormattingContext::create_independent_formatting_conte
: FormattingContext(Type::Block, state, box)
{
}
virtual float automatic_content_height() const override { return 0; };
virtual void run(Box const&, LayoutMode) override { }
};
return make<ReplacedFormattingContext>(state, child_box);
@ -144,6 +145,7 @@ OwnPtr<FormattingContext> FormattingContext::create_independent_formatting_conte
: FormattingContext(Type::Block, state, box)
{
}
virtual float automatic_content_height() const override { return 0; };
virtual void run(Box const&, LayoutMode) override { }
};
return make<DummyFormattingContext>(state, child_box);

View file

@ -26,6 +26,9 @@ public:
virtual void run(Box const&, LayoutMode) = 0;
// This function returns the automatic content height of the context's root box.
virtual float automatic_content_height() const = 0;
Box const& context_box() const { return m_context_box; }
FormattingContext* parent() { return m_parent; }

View file

@ -1002,7 +1002,12 @@ void GridFormattingContext::run(Box const& box, LayoutMode)
float total_y = 0;
for (auto& grid_row : grid_rows)
total_y += grid_row.base_size;
box_state.set_content_height(total_y);
m_automatic_content_height = total_y;
}
float GridFormattingContext::automatic_content_height() const
{
return m_automatic_content_height;
}
}

View file

@ -18,6 +18,10 @@ public:
~GridFormattingContext();
virtual void run(Box const&, LayoutMode) override;
virtual float automatic_content_height() const override;
private:
float m_automatic_content_height { 0 };
};
}

View file

@ -78,6 +78,11 @@ float InlineFormattingContext::available_space_for_line(float y) const
return space.right - space.left;
}
float InlineFormattingContext::automatic_content_height() const
{
return compute_auto_height_for_block_formatting_context_root(m_state, containing_block());
}
void InlineFormattingContext::run(Box const&, LayoutMode layout_mode)
{
VERIFY(containing_block().children_are_inline());

View file

@ -24,6 +24,7 @@ public:
BlockContainer const& containing_block() const { return static_cast<BlockContainer const&>(context_box()); }
virtual void run(Box const&, LayoutMode) override;
virtual float automatic_content_height() const override;
void dimension_box_on_line(Box const&, LayoutMode);

View file

@ -20,6 +20,11 @@ SVGFormattingContext::SVGFormattingContext(LayoutState& state, Box const& box, F
SVGFormattingContext::~SVGFormattingContext() = default;
float SVGFormattingContext::automatic_content_height() const
{
return 0;
}
void SVGFormattingContext::run(Box const& box, LayoutMode)
{
auto& svg_svg_element = verify_cast<SVG::SVGSVGElement>(*box.dom_node());

View file

@ -17,6 +17,7 @@ public:
~SVGFormattingContext();
virtual void run(Box const&, LayoutMode) override;
virtual float automatic_content_height() const override;
};
}

View file

@ -107,7 +107,7 @@ void TableFormattingContext::run(Box const& box, LayoutMode)
box_state.set_content_width(total_content_width);
// FIXME: This is a total hack, we should respect the 'height' property.
box_state.set_content_height(total_content_height);
m_automatic_content_height = total_content_height;
}
void TableFormattingContext::calculate_column_widths(Box const& row, CSS::Length const& table_width, Vector<ColumnWidth>& column_widths)
@ -209,4 +209,9 @@ void TableFormattingContext::layout_row(Box const& row, Vector<ColumnWidth>& col
}
}
float TableFormattingContext::automatic_content_height() const
{
return m_automatic_content_height;
}
}

View file

@ -24,10 +24,13 @@ public:
~TableFormattingContext();
virtual void run(Box const&, LayoutMode) override;
virtual float automatic_content_height() const override;
private:
void calculate_column_widths(Box const& row, CSS::Length const& table_width, Vector<ColumnWidth>& column_widths);
void layout_row(Box const& row, Vector<ColumnWidth>& column_widths);
float m_automatic_content_height { 0 };
};
}