mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-06 16:45:03 +00:00
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.
This commit is contained in:
@@ -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 {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user