Skip to content

Commit 39ad783

Browse files
committed
LibWeb: Do not render SVG <symbol> elements unless part of <use>
We were always rendering <symbol> SVG elements, but we should only render them if they are a child of a <use>'s shadow root. This caused practically all instances of <symbol> to be drawn at least one time too many.
1 parent 632854d commit 39ad783

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

Libraries/LibWeb/SVG/SVGSymbolElement.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ bool SVGSymbolElement::is_direct_child_of_use_shadow_tree() const
6262

6363
GC::Ptr<Layout::Node> SVGSymbolElement::create_layout_node(GC::Ref<CSS::ComputedProperties> style)
6464
{
65-
return heap().allocate<Layout::SVGGraphicsBox>(document(), *this, move(style));
65+
// https://svgwg.org/svg2-draft/render.html#TermNeverRenderedElement
66+
// [..] it also includes a ‘symbol’ element that is not the instance root of a use-element shadow tree.
67+
if (!is_direct_child_of_use_shadow_tree())
68+
return {};
69+
70+
return heap().allocate<Layout::SVGGraphicsBox>(document(), *this, style);
6671
}
6772

6873
}

Tests/LibWeb/Layout/expected/layout-tree-update/simple-update-inside-svg-subtree.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not-
33
BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 150 0+0+8] children: inline
44
frag 0 from SVGSVGBox start: 0, length: 0, rect: [8,8 300x150] baseline: 150
55
SVGSVGBox <svg> at [8,8] [0+0+0 300 0+0+0] [0+0+0 150 0+0+0] [SVG] children: inline
6-
SVGGraphicsBox <symbol> at [8,8] [0+0+0 300 0+0+0] [0+0+0 150 0+0+0] [BFC] children: inline
7-
InlineNode <set#set> at [8,8] [0+0+0 0 0+0+0] [0+0+0 18 0+0+0]
8-
TextNode <#text> (not painted)
6+
SVGGraphicsBox <use> at [8,8] [0+0+0 300 0+0+0] [0+0+0 150 0+0+0] children: not-inline
7+
SVGGraphicsBox <symbol#a> at [8,8] [0+0+0 300 0+0+0] [0+0+0 150 0+0+0] [BFC] children: inline
8+
InlineNode <set#set> at [8,8] [0+0+0 0 0+0+0] [0+0+0 18 0+0+0]
9+
TextNode <#text> (not painted)
910
TextNode <#text> (not painted)
1011
TextNode <#text> (not painted)
1112

1213
ViewportPaintable (Viewport<#document>) [0,0 800x600]
1314
PaintableWithLines (BlockContainer<HTML>) [0,0 800x166]
1415
PaintableWithLines (BlockContainer<BODY>) [8,8 784x150]
1516
SVGSVGPaintable (SVGSVGBox<svg>) [8,8 300x150]
16-
SVGGraphicsPaintable (SVGGraphicsBox<symbol>) [8,8 300x150]
17-
PaintableWithLines (InlineNode<set>#set) [8,8 0x18]
17+
SVGGraphicsPaintable (SVGGraphicsBox<use>) [8,8 300x150]
18+
SVGGraphicsPaintable (SVGGraphicsBox<symbol>#a) [8,8 300x150]
19+
PaintableWithLines (InlineNode<set>#set) [8,8 0x18]
1820

1921
SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto)
2022
SC for BlockContainer<HTML> [0,0 800x166] [children: 0] (z-index: auto)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not-inline
2+
BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 166 0+0+0] [BFC] children: not-inline
3+
BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 150 0+0+8] children: inline
4+
frag 0 from SVGSVGBox start: 0, length: 0, rect: [8,8 300x150] baseline: 150
5+
SVGSVGBox <svg> at [8,8] [0+0+0 300 0+0+0] [0+0+0 150 0+0+0] [SVG] children: inline
6+
TextNode <#text> (not painted)
7+
TextNode <#text> (not painted)
8+
TextNode <#text> (not painted)
9+
10+
ViewportPaintable (Viewport<#document>) [0,0 800x600]
11+
PaintableWithLines (BlockContainer<HTML>) [0,0 800x166]
12+
PaintableWithLines (BlockContainer<BODY>) [8,8 784x150]
13+
SVGSVGPaintable (SVGSVGBox<svg>) [8,8 300x150]
14+
15+
SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto)
16+
SC for BlockContainer<HTML> [0,0 800x166] [children: 0] (z-index: auto)

Tests/LibWeb/Layout/input/layout-tree-update/simple-update-inside-svg-subtree.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<body><svg><symbol><set id="set"></set></symbol></body>
2+
<body><svg><symbol id="a"><set id="set"></set></symbol><use href="#a"></use></body>
33
<script>
44
document.body.offsetWidth;
55
set.prepend("x");
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!DOCTYPE html>
2+
<svg xmlns="http://www.w3.org/2000/svg">
3+
<symbol viewBox="0 0 16 16">
4+
<rect x="1" y="1" width="14" height="14" fill="red" />
5+
</symbol>
6+
</svg>

0 commit comments

Comments
 (0)