diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index 1223aae905..616241e004 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -39,6 +39,11 @@ bool BlockFormattingContext::is_initial() const return is(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()) { diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h index 00636684ed..d8559c166e 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h @@ -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; diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp index cc6a319356..bef6c052d5 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp @@ -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()); diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h index 5b53852a76..87458d240e 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h @@ -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(); } diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index d6b764b426..c71ab6e83f 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -103,6 +103,7 @@ OwnPtr 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(state, child_box); @@ -144,6 +145,7 @@ OwnPtr 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(state, child_box); diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.h b/Userland/Libraries/LibWeb/Layout/FormattingContext.h index 6ab8ff073e..3597bf4a38 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.h @@ -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; } diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp index a0e7c4ed52..c9f68f9c2f 100644 --- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp @@ -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; } } diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h index c0bf6ad72e..05696a3d38 100644 --- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h @@ -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 }; }; } diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index 6640229e4d..c6f5069232 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -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()); diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h index 0eeb452aa7..e5dd3a29ed 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h @@ -24,6 +24,7 @@ public: BlockContainer const& containing_block() const { return static_cast(context_box()); } virtual void run(Box const&, LayoutMode) override; + virtual float automatic_content_height() const override; void dimension_box_on_line(Box const&, LayoutMode); diff --git a/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp index d9ce91c9c8..e7cf8757fb 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp @@ -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(*box.dom_node()); diff --git a/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.h b/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.h index 6d343b5f95..bfc561947f 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.h @@ -17,6 +17,7 @@ public: ~SVGFormattingContext(); virtual void run(Box const&, LayoutMode) override; + virtual float automatic_content_height() const override; }; } diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp index 1fa59a03f1..23eca43e10 100644 --- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp @@ -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& column_widths) @@ -209,4 +209,9 @@ void TableFormattingContext::layout_row(Box const& row, Vector& col } } +float TableFormattingContext::automatic_content_height() const +{ + return m_automatic_content_height; +} + } diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h index 170fd14969..05690f8e8c 100644 --- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h @@ -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& column_widths); void layout_row(Box const& row, Vector& column_widths); + + float m_automatic_content_height { 0 }; }; }