LibWeb: Use qualified names for SVG attribute reflectors

This commit is contained in:
Luke Wilde 2025-10-31 12:27:49 +00:00 committed by Tim Flynn
parent d211df8118
commit 60e1a136aa
Notes: github-actions[bot] 2025-11-06 16:46:15 +00:00
16 changed files with 51 additions and 44 deletions

View file

@ -15,12 +15,12 @@ namespace Web::SVG {
GC_DEFINE_ALLOCATOR(SVGAnimatedString);
GC::Ref<SVGAnimatedString> SVGAnimatedString::create(JS::Realm& realm, GC::Ref<SVGElement> element, FlyString reflected_attribute, Optional<FlyString> deprecated_reflected_attribute, Optional<FlyString> initial_value)
GC::Ref<SVGAnimatedString> SVGAnimatedString::create(JS::Realm& realm, GC::Ref<SVGElement> element, DOM::QualifiedName reflected_attribute, Optional<DOM::QualifiedName> deprecated_reflected_attribute, Optional<FlyString> initial_value)
{
return realm.create<SVGAnimatedString>(realm, element, move(reflected_attribute), move(deprecated_reflected_attribute), move(initial_value));
}
SVGAnimatedString::SVGAnimatedString(JS::Realm& realm, GC::Ref<SVGElement> element, FlyString reflected_attribute, Optional<FlyString> deprecated_reflected_attribute, Optional<FlyString> initial_value)
SVGAnimatedString::SVGAnimatedString(JS::Realm& realm, GC::Ref<SVGElement> element, DOM::QualifiedName reflected_attribute, Optional<DOM::QualifiedName> deprecated_reflected_attribute, Optional<FlyString> initial_value)
: Bindings::PlatformObject(realm)
, m_element(element)
, m_reflected_attribute(move(reflected_attribute))
@ -48,11 +48,11 @@ String SVGAnimatedString::base_val() const
{
// On getting baseVal or animVal, the following steps are run:
// 1. If the reflected attribute is not present, then:
if (!m_element->has_attribute(m_reflected_attribute)) {
if (!m_element->has_attribute_ns(m_reflected_attribute.namespace_(), m_reflected_attribute.local_name())) {
// 1. If the SVGAnimatedString object is defined to additionally reflect a second, deprecated attribute,
// and that attribute is present, then return its value.
if (m_deprecated_reflected_attribute.has_value()) {
if (auto attribute = m_element->get_attribute(m_deprecated_reflected_attribute.value()); attribute.has_value())
if (auto attribute = m_element->get_attribute_ns(m_deprecated_reflected_attribute->namespace_(), m_deprecated_reflected_attribute->local_name()); attribute.has_value())
return attribute.release_value();
}
@ -65,7 +65,7 @@ String SVGAnimatedString::base_val() const
}
// 2. Otherwise, the reflected attribute is present. Return its value.
return m_element->attribute(m_reflected_attribute).value();
return m_element->get_attribute_ns(m_reflected_attribute.namespace_(), m_reflected_attribute.local_name()).value();
}
// https://svgwg.org/svg2-draft/types.html#__svg__SVGAnimatedString__baseVal
@ -74,15 +74,15 @@ void SVGAnimatedString::set_base_val(String const& base_val)
// 1. If the reflected attribute is not present, the SVGAnimatedString object is defined to additionally reflect
// a second, deprecated attribute, and that deprecated attribute is present, then set that deprecated attribute
// to the specified value.
if (!m_element->has_attribute(m_reflected_attribute)
if (!m_element->has_attribute_ns(m_reflected_attribute.namespace_(), m_reflected_attribute.local_name())
&& m_deprecated_reflected_attribute.has_value()
&& m_element->has_attribute(m_deprecated_reflected_attribute.value())) {
MUST(m_element->set_attribute(m_deprecated_reflected_attribute.value(), base_val));
&& m_element->has_attribute_ns(m_deprecated_reflected_attribute->namespace_(), m_deprecated_reflected_attribute->local_name())) {
m_element->set_attribute_value(m_deprecated_reflected_attribute->local_name(), base_val, m_deprecated_reflected_attribute->prefix(), m_deprecated_reflected_attribute->namespace_());
return;
}
// 2. Otherwise, set the reflected attribute to the specified value.
MUST(m_element->set_attribute(m_reflected_attribute, base_val));
m_element->set_attribute_value(m_reflected_attribute.local_name(), base_val, m_reflected_attribute.prefix(), m_reflected_attribute.namespace_());
}
}