From 0f15d1f94792cdc44dc79c049ae29a9f33c1ace6 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 21 Feb 2022 16:53:38 +0100 Subject: [PATCH] LibWeb: Add hack to avoid crashing on !child_display.is_flow_inside() When encountering a box that claims to have block-level children, but its CSS display type isn't actually "flow" inside, we would previously crash due to a VERIFY() failure. However, many sites choke on this due to freestanding table-related boxes like those created by "table-row" and "table-row-group". We're supposed to fix those up by wrapping them in a full set of table boxes during layout tree construction, but that algorithm obviously isn't working correctly in all cases. So let's work around the crashes for now, allowing many more sites to load (even if visually incorrect.) This is a rather monstrous hack, and we should get rid of it as soon as it's not needed anymore. --- .../LibWeb/Layout/FormattingContext.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index 4a2cfd84be..47124e8936 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -100,8 +100,22 @@ OwnPtr FormattingContext::create_independent_formatting_conte // The child box is a block container that doesn't create its own BFC. // It will be formatted by this BFC. - VERIFY(child_display.is_flow_inside()); + if (!child_display.is_flow_inside()) { + dbgln("FIXME: Child box doesn't create BFC, but inside is also not flow! display={}", child_display.to_string()); + // HACK: Instead of crashing, create a dummy formatting context that does nothing. + // FIXME: Remove this once it's no longer needed. It currently swallows problem with standalone + // table-related boxes that don't get fixed up by CSS anonymous table box generation. + struct DummyFormattingContext : public FormattingContext { + DummyFormattingContext(FormattingState& state, Box const& box) + : FormattingContext(Type::Block, state, box) + { + } + virtual void run(Box const&, LayoutMode) override { } + }; + return make(m_state, child_box); + } VERIFY(child_box.is_block_container()); + VERIFY(child_display.is_flow_inside()); return {}; }