From e8d10fb42933f548add3076cb1beaa4dc201d9d4 Mon Sep 17 00:00:00 2001 From: K-Adam Date: Thu, 5 Aug 2021 10:26:09 +0200 Subject: LibWeb: Ignore svg elements outside of when building layout tree An svg layout element without a `SVGSVGElement` ancestor caused a failed assertion before, because the svg context does not exist when `paint()` is called --- Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp') diff --git a/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp b/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp index 47fc97363a..74b52e9b41 100644 --- a/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp +++ b/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp @@ -4,6 +4,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include +#include #include #include #include @@ -70,12 +72,20 @@ static Layout::Node& insertion_parent_for_block_node(Layout::Node& layout_parent return layout_parent; } -void TreeBuilder::create_layout_tree(DOM::Node& dom_node) +void TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder::Context& context) { // If the parent doesn't have a layout node, we don't need one either. if (dom_node.parent_or_shadow_host() && !dom_node.parent_or_shadow_host()->layout_node()) return; + Optional> has_svg_root_change; + + if (dom_node.is_svg_container()) { + has_svg_root_change.emplace(context.has_svg_root, true); + } else if (dom_node.requires_svg_container() && !context.has_svg_root) { + return; + } + auto layout_node = dom_node.create_layout_node(); if (!layout_node) return; @@ -108,9 +118,9 @@ void TreeBuilder::create_layout_tree(DOM::Node& dom_node) if ((dom_node.has_children() || shadow_root) && layout_node->can_have_children()) { push_parent(verify_cast(*layout_node)); if (shadow_root) - create_layout_tree(*shadow_root); + create_layout_tree(*shadow_root, context); verify_cast(dom_node).for_each_child([&](auto& dom_child) { - create_layout_tree(dom_child); + create_layout_tree(dom_child, context); }); pop_parent(); } @@ -124,7 +134,8 @@ RefPtr TreeBuilder::build(DOM::Node& dom_node) m_parent_stack.prepend(verify_cast(ancestor)); } - create_layout_tree(dom_node); + Context context; + create_layout_tree(dom_node, context); if (auto* root = dom_node.document().layout_node()) fixup_tables(*root); -- cgit v1.2.3