diff --git a/Tests/LibWeb/Layout/expected/svg/svg-symbol-with-viewbox.txt b/Tests/LibWeb/Layout/expected/svg/svg-symbol-with-viewbox.txt index 8b2b2d5922..499fc9338a 100644 --- a/Tests/LibWeb/Layout/expected/svg/svg-symbol-with-viewbox.txt +++ b/Tests/LibWeb/Layout/expected/svg/svg-symbol-with-viewbox.txt @@ -10,8 +10,8 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline TextNode <#text> SVGSVGBox at (8,8) content-size 300x150 [SVG] children: inline TextNode <#text> - Box at (8,8) content-size 0x0 children: inline - Box at (8,8) content-size 0x0 [BFC] children: inline + Box at (8,8) content-size 215.625x130.90625 children: inline + Box at (92.375,26.75) content-size 131.25x112.15625 [BFC] children: inline TextNode <#text> SVGGeometryBox at (92.375,26.75) content-size 131.25x112.15625 children: inline TextNode <#text> @@ -25,6 +25,6 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer(anonymous)) [8,8 784x0] PaintableWithLines (BlockContainer
) [8,8 784x150] SVGSVGPaintable (SVGSVGBox) [8,8 300x150] - PaintableBox (Box) [8,8 0x0] - PaintableBox (Box#braces) [8,8 0x0] + PaintableBox (Box) [8,8 215.625x130.90625] + PaintableBox (Box#braces) [92.375,26.75 131.25x112.15625] SVGPathPaintable (SVGGeometryBox) [92.375,26.75 131.25x112.15625] diff --git a/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp index f2e859c026..347a59c030 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include #include @@ -134,16 +136,20 @@ static ViewBoxTransform scale_and_align_viewbox_content(SVG::PreserveAspectRatio return viewbox_transform; } -static bool should_ensure_creation_of_paintable(Node const& node) +static bool is_container_element(Node const& node) { - if (is(node)) + // https://svgwg.org/svg2-draft/struct.html#GroupsOverview + auto* dom_node = node.dom_node(); + if (!dom_node) + return false; + if (is(dom_node)) + return true; + if (is(dom_node)) + return true; + if (is(dom_node)) + return true; + if (is(dom_node)) return true; - if (node.dom_node()) { - if (is(*node.dom_node())) - return true; - if (is(*node.dom_node())) - return true; - } return false; } @@ -260,10 +266,6 @@ void SVGFormattingContext::run(Box const& box, LayoutMode layout_mode, Available } else if (is(descendant)) { SVGFormattingContext nested_context(m_state, static_cast(descendant), this); nested_context.run(static_cast(descendant), layout_mode, available_space); - } else if (should_ensure_creation_of_paintable(descendant)) { - // NOTE: This hack creates a layout state to ensure the existence of - // a paintable in LayoutState::commit(). - m_state.get_mutable(static_cast(descendant)); } return IterationDecision::Continue; @@ -273,10 +275,7 @@ void SVGFormattingContext::run(Box const& box, LayoutMode layout_mode, Available // 5.2. Grouping: the ā€˜g’ element // The ā€˜g’ element is a container element for grouping together related graphics elements. box.for_each_in_subtree_of_type([&](Box const& descendant) { - if (is(descendant) && !is(descendant) && !is(descendant)) { - auto const& svg_graphics_box = static_cast(descendant); - auto& graphics_box_state = m_state.get_mutable(svg_graphics_box); - + if (is_container_element(descendant)) { Gfx::BoundingBox bounding_box; descendant.for_each_in_subtree_of_type([&](Box const& child_of_svg_container) { auto& box_state = m_state.get(child_of_svg_container); @@ -285,10 +284,11 @@ void SVGFormattingContext::run(Box const& box, LayoutMode layout_mode, Available return IterationDecision::Continue; }); - graphics_box_state.set_content_x(bounding_box.x()); - graphics_box_state.set_content_y(bounding_box.y()); - graphics_box_state.set_content_width(bounding_box.width()); - graphics_box_state.set_content_height(bounding_box.height()); + auto& box_state = m_state.get_mutable(descendant); + box_state.set_content_x(bounding_box.x()); + box_state.set_content_y(bounding_box.y()); + box_state.set_content_width(bounding_box.width()); + box_state.set_content_height(bounding_box.height()); } return IterationDecision::Continue; });