ソースを参照

LibWeb: Use SVGGraphicsBox for `<symbol>` and `<use>` elements

This allows various SVG properties (like masking) to be applied to these
elements.
MacDue 1 年間 前
コミット
15e3b0ebde

+ 5 - 5
Tests/LibWeb/Layout/expected/flex/svg-flex-item-with-percentage-max-size.txt

@@ -2,9 +2,9 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
   BlockContainer <html> at (0,0) content-size 800x116 [BFC] children: not-inline
     Box <body> at (8,8) content-size 784x100 flex-container(row) [FFC] children: not-inline
       Box <div> at (8,8) content-size 100x100 flex-container(row) flex-item [FFC] children: not-inline
-        SVGSVGBox <svg.c-ico> at (8,8) content-size 100x100 flex-item [SVG] children: inline
-          Box <use> at (8,8) content-size 100x100 children: inline
-            Box <symbol#icon-cart> at (8,8) content-size 100x100 [BFC] children: not-inline
+        SVGSVGBox <svg.c-ico> at (8,8) content-size 100x100 flex-item [SVG] children: not-inline
+          SVGGraphicsBox <use> at (8,8) content-size 100x100 children: not-inline
+            SVGGraphicsBox <symbol#icon-cart> at (8,8) content-size 100x100 [BFC] children: not-inline
               SVGGeometryBox <rect> at (8,8) content-size 100x100 children: not-inline
 
 ViewportPaintable (Viewport<#document>) [0,0 800x600]
@@ -12,6 +12,6 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
     PaintableBox (Box<BODY>) [8,8 784x100]
       PaintableBox (Box<DIV>) [8,8 100x100]
         SVGSVGPaintable (SVGSVGBox<svg>.c-ico) [8,8 100x100]
-          PaintableBox (Box<use>) [8,8 100x100]
-            PaintableBox (Box<symbol>#icon-cart) [8,8 100x100]
+          SVGGraphicsPaintable (SVGGraphicsBox<use>) [8,8 100x100]
+            SVGGraphicsPaintable (SVGGraphicsBox<symbol>#icon-cart) [8,8 100x100]
               SVGPathPaintable (SVGGeometryBox<rect>) [8,8 100x100]

+ 4 - 4
Tests/LibWeb/Layout/expected/svg/svg-symbol-with-viewbox.txt

@@ -9,8 +9,8 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
         TextNode <#text>
         SVGSVGBox <svg> at (8,8) content-size 300x150 [SVG] children: inline
           TextNode <#text>
-          Box <use> at (8,8) content-size 300x150 children: inline
-            Box <symbol#braces> at (92.375,26.75) content-size 131.25x112.15625 [BFC] children: inline
+          SVGGraphicsBox <use> at (92.375,26.75) content-size 131.25x112.15625 children: not-inline
+            SVGGraphicsBox <symbol#braces> at (92.375,26.75) content-size 131.25x112.15625 [BFC] children: inline
               TextNode <#text>
               SVGGeometryBox <path> at (92.375,26.75) content-size 131.25x112.15625 children: inline
                 TextNode <#text>
@@ -24,6 +24,6 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
       PaintableWithLines (BlockContainer(anonymous)) [8,8 784x0]
       PaintableWithLines (BlockContainer<DIV>) [8,8 784x150]
         SVGSVGPaintable (SVGSVGBox<svg>) [8,8 300x150]
-          PaintableBox (Box<use>) [8,8 300x150]
-            PaintableBox (Box<symbol>#braces) [92.375,26.75 131.25x112.15625]
+          SVGGraphicsPaintable (SVGGraphicsBox<use>) [92.375,26.75 131.25x112.15625]
+            SVGGraphicsPaintable (SVGGraphicsBox<symbol>#braces) [92.375,26.75 131.25x112.15625]
               SVGPathPaintable (SVGGeometryBox<path>) [92.375,26.75 131.25x112.15625]

+ 2 - 2
Tests/LibWeb/Layout/expected/svg/use-honor-outer-viewBox.txt

@@ -4,7 +4,7 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
       frag 0 from SVGSVGBox start: 0, length: 0, rect: [9,9 100x100] baseline: 102
       SVGSVGBox <svg#outer> at (9,9) content-size 100x100 [SVG] children: inline
         TextNode <#text>
-        Box <use> at (9,9) content-size 100x100 children: inline
+        SVGGraphicsBox <use> at (9,9) content-size 50x50 children: inline
           SVGSVGBox <svg#whee> at (9,9) content-size 100x100 [SVG] children: inline
             TextNode <#text>
             SVGGeometryBox <rect> at (9,9) content-size 50x50 children: inline
@@ -16,6 +16,6 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
   PaintableWithLines (BlockContainer<HTML>) [0,0 800x118]
     PaintableWithLines (BlockContainer<BODY>) [8,8 784x102]
       SVGSVGPaintable (SVGSVGBox<svg>#outer) [8,8 102x102]
-        PaintableBox (Box<use>) [9,9 100x100]
+        SVGGraphicsPaintable (SVGGraphicsBox<use>) [9,9 50x50]
           SVGSVGPaintable (SVGSVGBox<svg>#whee) [9,9 100x100]
             SVGPathPaintable (SVGGeometryBox<rect>) [9,9 50x50]

+ 2 - 2
Userland/Libraries/LibWeb/SVG/SVGSymbolElement.cpp

@@ -10,7 +10,7 @@
 #include <LibWeb/CSS/StyleValues/IdentifierStyleValue.h>
 #include <LibWeb/CSS/StyleValues/ShorthandStyleValue.h>
 #include <LibWeb/DOM/ShadowRoot.h>
-#include <LibWeb/Layout/Box.h>
+#include <LibWeb/Layout/SVGGraphicsBox.h>
 #include <LibWeb/SVG/AttributeNames.h>
 #include <LibWeb/SVG/SVGSymbolElement.h>
 #include <LibWeb/SVG/SVGUseElement.h>
@@ -61,7 +61,7 @@ bool SVGSymbolElement::is_direct_child_of_use_shadow_tree() const
 
 JS::GCPtr<Layout::Node> SVGSymbolElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
 {
-    return heap().allocate_without_realm<Layout::Box>(document(), this, move(style));
+    return heap().allocate_without_realm<Layout::SVGGraphicsBox>(document(), *this, move(style));
 }
 
 }

+ 2 - 1
Userland/Libraries/LibWeb/SVG/SVGUseElement.cpp

@@ -10,6 +10,7 @@
 #include <LibWeb/DOM/Event.h>
 #include <LibWeb/DOM/ShadowRoot.h>
 #include <LibWeb/Layout/Box.h>
+#include <LibWeb/Layout/SVGGraphicsBox.h>
 #include <LibWeb/Namespace.h>
 #include <LibWeb/SVG/AttributeNames.h>
 #include <LibWeb/SVG/SVGSVGElement.h>
@@ -186,7 +187,7 @@ JS::GCPtr<SVGElement> SVGUseElement::animated_instance_root() const
 
 JS::GCPtr<Layout::Node> SVGUseElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
 {
-    return heap().allocate_without_realm<Layout::Box>(document(), this, move(style));
+    return heap().allocate_without_realm<Layout::SVGGraphicsBox>(document(), *this, move(style));
 }
 
 }