diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index 463c4b6519..657d2eb9af 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -384,7 +384,7 @@ void BlockFormattingContext::compute_position(Box& box) void BlockFormattingContext::layout_inline_children(BlockContainer& block_container, LayoutMode layout_mode) { - InlineFormattingContext context(block_container, this); + InlineFormattingContext context(block_container, *this); context.run(block_container, layout_mode); } diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp index 01cdfae536..18c5a25af4 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp @@ -455,7 +455,7 @@ float FlexFormattingContext::layout_for_maximum_main_size(Box& box) auto& block_container = verify_cast(box); BlockFormattingContext bfc(block_container, this); bfc.run(box, LayoutMode::Default); - InlineFormattingContext ifc(block_container, &bfc); + InlineFormattingContext ifc(block_container, bfc); if (is_row_layout()) { ifc.run(box, LayoutMode::OnlyRequiredLineBreaks); @@ -805,7 +805,7 @@ float FlexFormattingContext::determine_hypothetical_cross_size_of_item(Box& box) auto& block_container = verify_cast(box); BlockFormattingContext bfc(block_container, this); bfc.run(box, LayoutMode::Default); - InlineFormattingContext ifc(block_container, &bfc); + InlineFormattingContext ifc(block_container, bfc); ifc.run(box, LayoutMode::OnlyRequiredLineBreaks); return is_row_layout() ? box.height() : box.width(); diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index b3f589f202..5295b35f9b 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -95,7 +95,7 @@ OwnPtr FormattingContext::create_independent_formatting_conte VERIFY(is_block_formatting_context()); if (child_box.children_are_inline()) - return make(verify_cast(child_box), this); + return make(verify_cast(child_box), static_cast(*this)); // The child box is a block container that doesn't create its own BFC. // It will be formatted by this BFC. diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index dba4ec6941..9bad45c3cc 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -17,8 +17,8 @@ namespace Web::Layout { -InlineFormattingContext::InlineFormattingContext(BlockContainer& containing_block, FormattingContext* parent) - : FormattingContext(Type::Inline, containing_block, parent) +InlineFormattingContext::InlineFormattingContext(BlockContainer& containing_block, BlockFormattingContext& parent) + : FormattingContext(Type::Inline, containing_block, &parent) { } @@ -26,14 +26,21 @@ InlineFormattingContext::~InlineFormattingContext() { } +BlockFormattingContext& InlineFormattingContext::parent() +{ + return static_cast(*FormattingContext::parent()); +} + +BlockFormattingContext const& InlineFormattingContext::parent() const +{ + return static_cast(*FormattingContext::parent()); +} + InlineFormattingContext::AvailableSpaceForLineInfo InlineFormattingContext::available_space_for_line(float y) const { - if (!parent()->is_block_formatting_context()) - return { 0, context_box().width() }; - AvailableSpaceForLineInfo info; - auto const& bfc = static_cast(*parent()); + auto const& bfc = parent(); for (ssize_t i = bfc.left_side_floats().boxes.size() - 1; i >= 0; --i) { auto const& floating_box = bfc.left_side_floats().boxes.at(i); diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h index c2aa557d67..b4882a1b6c 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h @@ -15,9 +15,12 @@ namespace Web::Layout { class InlineFormattingContext final : public FormattingContext { public: - InlineFormattingContext(BlockContainer& containing_block, FormattingContext* parent); + InlineFormattingContext(BlockContainer& containing_block, BlockFormattingContext& parent); ~InlineFormattingContext(); + BlockFormattingContext& parent(); + BlockFormattingContext const& parent() const; + BlockContainer& containing_block() { return static_cast(context_box()); } BlockContainer const& containing_block() const { return static_cast(context_box()); }