From e424e4749fb973321a0d643b2743f66f9e9687f8 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 29 Nov 2020 15:29:10 +0100 Subject: [PATCH] LibWeb: Allow layout boxes to have children We can't say that "no replaced boxes can have children", since that breaks SVG. Instead, let each LayoutNode decide whether it's allowed to have children. Fixes #4223. --- Libraries/LibWeb/Layout/Node.h | 2 ++ Libraries/LibWeb/Layout/ReplacedBox.h | 2 ++ Libraries/LibWeb/Layout/SVGSVGBox.h | 2 ++ Libraries/LibWeb/Layout/TreeBuilder.cpp | 6 +----- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Libraries/LibWeb/Layout/Node.h b/Libraries/LibWeb/Layout/Node.h index 4725ecbdf82..512d4b3bd5a 100644 --- a/Libraries/LibWeb/Layout/Node.h +++ b/Libraries/LibWeb/Layout/Node.h @@ -103,6 +103,8 @@ public: virtual bool is_list_item() const { return false; } bool has_style() const { return m_has_style; } + virtual bool can_have_children() const { return true; } + bool is_inline() const { return m_inline; } void set_inline(bool b) { m_inline = b; } diff --git a/Libraries/LibWeb/Layout/ReplacedBox.h b/Libraries/LibWeb/Layout/ReplacedBox.h index aff5ccd5ca8..1a9ded51afc 100644 --- a/Libraries/LibWeb/Layout/ReplacedBox.h +++ b/Libraries/LibWeb/Layout/ReplacedBox.h @@ -62,6 +62,8 @@ public: virtual void prepare_for_replaced_layout() { } + virtual bool can_have_children() const override { return false; } + protected: virtual void split_into_lines(Layout::BlockBox& container, LayoutMode) override; diff --git a/Libraries/LibWeb/Layout/SVGSVGBox.h b/Libraries/LibWeb/Layout/SVGSVGBox.h index a03d28d2891..70b2efd4ab2 100644 --- a/Libraries/LibWeb/Layout/SVGSVGBox.h +++ b/Libraries/LibWeb/Layout/SVGSVGBox.h @@ -43,6 +43,8 @@ public: virtual void before_children_paint(PaintContext& context, PaintPhase phase) override; virtual void after_children_paint(PaintContext& context, PaintPhase phase) override; + virtual bool can_have_children() const override { return true; } + private: const char* class_name() const override { return "SVGSVGBox"; } }; diff --git a/Libraries/LibWeb/Layout/TreeBuilder.cpp b/Libraries/LibWeb/Layout/TreeBuilder.cpp index 7d7b3494334..7a554d7f553 100644 --- a/Libraries/LibWeb/Layout/TreeBuilder.cpp +++ b/Libraries/LibWeb/Layout/TreeBuilder.cpp @@ -129,11 +129,7 @@ void TreeBuilder::create_layout_tree(DOM::Node& dom_node) } } - // Ignore fallback content inside replaced elements. - if (layout_node->is_replaced()) - return; - - if (dom_node.has_children()) { + if (dom_node.has_children() && layout_node->can_have_children()) { push_parent(*layout_node); downcast(dom_node).for_each_child([&](auto& dom_child) { create_layout_tree(dom_child);