LibWeb: Factor out "process the URL" AO for SVGUseElement

This commit is contained in:
Shannon Booth 2024-07-27 15:43:56 +12:00 committed by Andreas Kling
parent 5151f94d39
commit ab70932681
Notes: github-actions[bot] 2024-08-05 09:28:11 +00:00
2 changed files with 12 additions and 3 deletions

View file

@ -60,11 +60,18 @@ void SVGUseElement::attribute_changed(FlyString const& name, Optional<String> co
} else if (name == SVG::AttributeNames::y) {
m_y = AttributeParser::parse_coordinate(value.value_or(String {}));
} else if (name == SVG::AttributeNames::href || name == "xlink:href"_fly_string) {
m_referenced_id = parse_id_from_href(value.value_or(String {}));
// When the href attribute is set (or, in the absence of an href attribute, an xlink:href attribute), the user agent must process the URL.
process_the_url(value);
}
}
// https://www.w3.org/TR/SVG2/linking.html#processingURL
void SVGUseElement::process_the_url(Optional<String> const& href)
{
m_referenced_id = parse_id_from_href(href.value_or(String {}));
clone_element_tree_as_our_shadow_tree(referenced_element());
}
}
Optional<FlyString> SVGUseElement::parse_id_from_href(StringView href)
{

View file

@ -51,6 +51,8 @@ private:
virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
void process_the_url(Optional<String> const& href);
static Optional<FlyString> parse_id_from_href(StringView);
JS::GCPtr<DOM::Element> referenced_element();