diff options
author | Andreas Kling <kling@serenityos.org> | 2022-04-11 00:39:43 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-11 01:03:47 +0200 |
commit | edfa4508a57dab99d8e8a3efb90896cb647d89d7 (patch) | |
tree | e5d4153cbd4275981368b16e2a1cdd8f8cc12ef9 /Userland/Libraries/LibWeb/Layout/FormattingContext.cpp | |
parent | b1a6a8600a8940a8980fe6d88421a18e2eb73875 (diff) | |
download | serenity-edfa4508a57dab99d8e8a3efb90896cb647d89d7.zip |
LibWeb: Create a no-op formatting context for childless replaced boxes
This is a hack that allows block-level replaced elements to be flex
items. Flexbox layout currently assumes (in many places) that it's
always possible to create an independent formatting context for each of
its items.
Diffstat (limited to 'Userland/Libraries/LibWeb/Layout/FormattingContext.cpp')
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/FormattingContext.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index 3033d53ae1..7c7ef0f040 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -75,6 +75,22 @@ bool FormattingContext::creates_block_formatting_context(Box const& box) OwnPtr<FormattingContext> FormattingContext::create_independent_formatting_context_if_needed(FormattingState& state, Box const& child_box) { + if (child_box.is_replaced_box() && !child_box.can_have_children()) { + // NOTE: This is a bit strange. + // Basically, we create a pretend formatting context for replaced elements that does nothing. + // This allows other formatting contexts to treat them like elements that actually need inside layout + // without having separate code to handle replaced elements. + // FIXME: Find a better abstraction for this. + struct ReplacedFormattingContext : public FormattingContext { + ReplacedFormattingContext(FormattingState& state, Box const& box) + : FormattingContext(Type::Block, state, box) + { + } + virtual void run(Box const&, LayoutMode) override { } + }; + return make<ReplacedFormattingContext>(state, child_box); + } + if (!child_box.can_have_children()) return {}; |