diff --git a/Libraries/LibWeb/SVG/SVGUseElement.cpp b/Libraries/LibWeb/SVG/SVGUseElement.cpp index 49a426afcf2..51c579bb164 100644 --- a/Libraries/LibWeb/SVG/SVGUseElement.cpp +++ b/Libraries/LibWeb/SVG/SVGUseElement.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include namespace Web::SVG { @@ -184,6 +185,20 @@ void SVGUseElement::clone_element_tree_as_our_shadow_tree(Element* to_clone) if (to_clone && is_valid_reference_element(*to_clone)) { // The ‘use’ element references another element, a copy of which is rendered in place of the ‘use’ in the document. auto cloned_reference_node = MUST(to_clone->clone_node(nullptr, true)); + if (is(cloned_reference_node.ptr()) || is(cloned_reference_node.ptr())) { + auto& cloned_element = as(*cloned_reference_node); + + // The width and height properties on the ‘use’ element override the values for the corresponding + // properties on a referenced ‘svg’ or ‘symbol’ element when determining the used value for that property + // on the instance root element. However, if the computed value for the property on the ‘use’ element is + // auto, then the property is computed as normal for the element instance. + if (has_attribute(AttributeNames::width)) { + MUST(cloned_element.set_attribute(AttributeNames::width, get_attribute_value(AttributeNames::width))); + } + if (has_attribute(AttributeNames::height)) { + MUST(cloned_element.set_attribute(AttributeNames::height, get_attribute_value(AttributeNames::height))); + } + } shadow_root()->append_child(cloned_reference_node).release_value_but_fixme_should_propagate_errors(); } } diff --git a/Tests/LibWeb/Ref/expected/svg/use-element-geometry-properties-ref.html b/Tests/LibWeb/Ref/expected/svg/use-element-geometry-properties-ref.html new file mode 100644 index 00000000000..217b3f9ceed --- /dev/null +++ b/Tests/LibWeb/Ref/expected/svg/use-element-geometry-properties-ref.html @@ -0,0 +1,4 @@ + + + + diff --git a/Tests/LibWeb/Ref/input/svg/use-element-geometry-properties.html b/Tests/LibWeb/Ref/input/svg/use-element-geometry-properties.html new file mode 100644 index 00000000000..901703ba0a1 --- /dev/null +++ b/Tests/LibWeb/Ref/input/svg/use-element-geometry-properties.html @@ -0,0 +1,13 @@ + + + + + + + + + + + + +