Skip to content

Commit 60e1a13

Browse files
Lubrsitrflynn89
authored andcommitted
LibWeb: Use qualified names for SVG attribute reflectors
1 parent d211df8 commit 60e1a13

16 files changed

+51
-44
lines changed

Libraries/LibWeb/SVG/SVGAElement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ i32 SVGAElement::default_tab_index_value() const
6666
GC::Ref<SVGAnimatedString> SVGAElement::target()
6767
{
6868
if (!m_target)
69-
m_target = SVGAnimatedString::create(realm(), *this, HTML::AttributeNames::target);
69+
m_target = SVGAnimatedString::create(realm(), *this, DOM::QualifiedName { HTML::AttributeNames::target, OptionalNone {}, OptionalNone {} });
7070
return *m_target;
7171
}
7272

Libraries/LibWeb/SVG/SVGAnimatedNumber.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ namespace Web::SVG {
1515
GC_DEFINE_ALLOCATOR(SVGAnimatedNumber);
1616

1717
GC::Ref<SVGAnimatedNumber> SVGAnimatedNumber::create(JS::Realm& realm, GC::Ref<SVGElement> element,
18-
FlyString reflected_attribute, float initial_value, SupportsSecondValue supports_second_value,
18+
DOM::QualifiedName reflected_attribute, float initial_value, SupportsSecondValue supports_second_value,
1919
ValueRepresented value_represented)
2020
{
2121
return realm.create<SVGAnimatedNumber>(realm, element, move(reflected_attribute), initial_value,
2222
supports_second_value, value_represented);
2323
}
2424

25-
SVGAnimatedNumber::SVGAnimatedNumber(JS::Realm& realm, GC::Ref<SVGElement> element, FlyString reflected_attribute,
25+
SVGAnimatedNumber::SVGAnimatedNumber(JS::Realm& realm, GC::Ref<SVGElement> element, DOM::QualifiedName reflected_attribute,
2626
float initial_value, SupportsSecondValue supports_second_value, ValueRepresented value_represented)
2727
: PlatformObject(realm)
2828
, m_element(element)
@@ -55,7 +55,7 @@ void SVGAnimatedNumber::set_base_val(float new_value)
5555
if (m_supports_second_value == SupportsSecondValue::Yes) {
5656
// 1. Let current be the value of the reflected attribute (using the attribute's initial value if it is not
5757
// present or invalid).
58-
auto current = m_element->get_attribute_value(m_reflected_attribute);
58+
auto current = m_element->get_attribute_value(m_reflected_attribute.local_name(), m_reflected_attribute.namespace_());
5959
auto current_values = MUST(current.split(' '));
6060

6161
// 2. Let first be the first number in current.
@@ -93,7 +93,7 @@ void SVGAnimatedNumber::set_base_val(float new_value)
9393
// (given the implementation's supported Precisionreal number precision), joined and separated by a single U+0020
9494
// SPACE character.
9595
auto new_attribute_value = MUST(String::join(' ', new_));
96-
m_element->set_attribute_value(m_reflected_attribute, new_attribute_value);
96+
m_element->set_attribute_value(m_reflected_attribute.local_name(), new_attribute_value, m_reflected_attribute.prefix(), m_reflected_attribute.namespace_());
9797
}
9898

9999
// https://svgwg.org/svg2-draft/types.html#__svg__SVGAnimatedNumber__animVal
@@ -116,7 +116,7 @@ float SVGAnimatedNumber::get_base_or_anim_value() const
116116
{
117117
// 1. Let value be the value of the reflected attribute (using the attribute's initial value if it is not present or
118118
// invalid).
119-
auto value = m_element->get_attribute_value(m_reflected_attribute);
119+
auto value = m_element->get_attribute_value(m_reflected_attribute.local_name(), m_reflected_attribute.namespace_());
120120

121121
// 2. If the reflected attribute is defined to take an number followed by an optional second number, then:
122122
if (m_supports_second_value == SupportsSecondValue::Yes) {

Libraries/LibWeb/SVG/SVGAnimatedNumber.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class SVGAnimatedNumber final : public Bindings::PlatformObject {
2828
};
2929

3030
[[nodiscard]] static GC::Ref<SVGAnimatedNumber> create(JS::Realm&, GC::Ref<SVGElement>,
31-
FlyString reflected_attribute, float initial_value, SupportsSecondValue = SupportsSecondValue::No,
31+
DOM::QualifiedName reflected_attribute, float initial_value, SupportsSecondValue = SupportsSecondValue::No,
3232
ValueRepresented = ValueRepresented::First);
3333
virtual ~SVGAnimatedNumber() override;
3434

@@ -38,7 +38,7 @@ class SVGAnimatedNumber final : public Bindings::PlatformObject {
3838
float anim_val() const;
3939

4040
private:
41-
SVGAnimatedNumber(JS::Realm&, GC::Ref<SVGElement>, FlyString, float, SupportsSecondValue, ValueRepresented);
41+
SVGAnimatedNumber(JS::Realm&, GC::Ref<SVGElement>, DOM::QualifiedName, float, SupportsSecondValue, ValueRepresented);
4242

4343
virtual void initialize(JS::Realm&) override;
4444
virtual void visit_edges(Visitor&) override;
@@ -47,7 +47,7 @@ class SVGAnimatedNumber final : public Bindings::PlatformObject {
4747
float get_base_or_anim_value() const;
4848

4949
GC::Ref<SVGElement> m_element;
50-
FlyString m_reflected_attribute;
50+
DOM::QualifiedName m_reflected_attribute;
5151
float m_initial_value;
5252
SupportsSecondValue m_supports_second_value;
5353
ValueRepresented m_value_represented;

Libraries/LibWeb/SVG/SVGAnimatedString.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ namespace Web::SVG {
1515

1616
GC_DEFINE_ALLOCATOR(SVGAnimatedString);
1717

18-
GC::Ref<SVGAnimatedString> SVGAnimatedString::create(JS::Realm& realm, GC::Ref<SVGElement> element, FlyString reflected_attribute, Optional<FlyString> deprecated_reflected_attribute, Optional<FlyString> initial_value)
18+
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)
1919
{
2020
return realm.create<SVGAnimatedString>(realm, element, move(reflected_attribute), move(deprecated_reflected_attribute), move(initial_value));
2121
}
2222

23-
SVGAnimatedString::SVGAnimatedString(JS::Realm& realm, GC::Ref<SVGElement> element, FlyString reflected_attribute, Optional<FlyString> deprecated_reflected_attribute, Optional<FlyString> initial_value)
23+
SVGAnimatedString::SVGAnimatedString(JS::Realm& realm, GC::Ref<SVGElement> element, DOM::QualifiedName reflected_attribute, Optional<DOM::QualifiedName> deprecated_reflected_attribute, Optional<FlyString> initial_value)
2424
: Bindings::PlatformObject(realm)
2525
, m_element(element)
2626
, m_reflected_attribute(move(reflected_attribute))
@@ -48,11 +48,11 @@ String SVGAnimatedString::base_val() const
4848
{
4949
// On getting baseVal or animVal, the following steps are run:
5050
// 1. If the reflected attribute is not present, then:
51-
if (!m_element->has_attribute(m_reflected_attribute)) {
51+
if (!m_element->has_attribute_ns(m_reflected_attribute.namespace_(), m_reflected_attribute.local_name())) {
5252
// 1. If the SVGAnimatedString object is defined to additionally reflect a second, deprecated attribute,
5353
// and that attribute is present, then return its value.
5454
if (m_deprecated_reflected_attribute.has_value()) {
55-
if (auto attribute = m_element->get_attribute(m_deprecated_reflected_attribute.value()); attribute.has_value())
55+
if (auto attribute = m_element->get_attribute_ns(m_deprecated_reflected_attribute->namespace_(), m_deprecated_reflected_attribute->local_name()); attribute.has_value())
5656
return attribute.release_value();
5757
}
5858

@@ -65,7 +65,7 @@ String SVGAnimatedString::base_val() const
6565
}
6666

6767
// 2. Otherwise, the reflected attribute is present. Return its value.
68-
return m_element->attribute(m_reflected_attribute).value();
68+
return m_element->get_attribute_ns(m_reflected_attribute.namespace_(), m_reflected_attribute.local_name()).value();
6969
}
7070

7171
// https://svgwg.org/svg2-draft/types.html#__svg__SVGAnimatedString__baseVal
@@ -74,15 +74,15 @@ void SVGAnimatedString::set_base_val(String const& base_val)
7474
// 1. If the reflected attribute is not present, the SVGAnimatedString object is defined to additionally reflect
7575
// a second, deprecated attribute, and that deprecated attribute is present, then set that deprecated attribute
7676
// to the specified value.
77-
if (!m_element->has_attribute(m_reflected_attribute)
77+
if (!m_element->has_attribute_ns(m_reflected_attribute.namespace_(), m_reflected_attribute.local_name())
7878
&& m_deprecated_reflected_attribute.has_value()
79-
&& m_element->has_attribute(m_deprecated_reflected_attribute.value())) {
80-
MUST(m_element->set_attribute(m_deprecated_reflected_attribute.value(), base_val));
79+
&& m_element->has_attribute_ns(m_deprecated_reflected_attribute->namespace_(), m_deprecated_reflected_attribute->local_name())) {
80+
m_element->set_attribute_value(m_deprecated_reflected_attribute->local_name(), base_val, m_deprecated_reflected_attribute->prefix(), m_deprecated_reflected_attribute->namespace_());
8181
return;
8282
}
8383

8484
// 2. Otherwise, set the reflected attribute to the specified value.
85-
MUST(m_element->set_attribute(m_reflected_attribute, base_val));
85+
m_element->set_attribute_value(m_reflected_attribute.local_name(), base_val, m_reflected_attribute.prefix(), m_reflected_attribute.namespace_());
8686
}
8787

8888
}

Libraries/LibWeb/SVG/SVGAnimatedString.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <AK/FlyString.h>
1010
#include <LibWeb/Bindings/PlatformObject.h>
11+
#include <LibWeb/DOM/QualifiedName.h>
1112
#include <LibWeb/Export.h>
1213

1314
namespace Web::SVG {
@@ -18,21 +19,21 @@ class WEB_API SVGAnimatedString final : public Bindings::PlatformObject {
1819
GC_DECLARE_ALLOCATOR(SVGAnimatedString);
1920

2021
public:
21-
[[nodiscard]] static GC::Ref<SVGAnimatedString> create(JS::Realm&, GC::Ref<SVGElement> element, FlyString reflected_attribute, Optional<FlyString> deprecated_reflected_attribute = {}, Optional<FlyString> initial_value = {});
22+
[[nodiscard]] static GC::Ref<SVGAnimatedString> create(JS::Realm&, GC::Ref<SVGElement> element, DOM::QualifiedName reflected_attribute, Optional<DOM::QualifiedName> deprecated_reflected_attribute = {}, Optional<FlyString> initial_value = {});
2223
virtual ~SVGAnimatedString() override;
2324

2425
String base_val() const;
2526
void set_base_val(String const& base_val);
2627

2728
private:
28-
SVGAnimatedString(JS::Realm&, GC::Ref<SVGElement> element, FlyString reflected_attribute, Optional<FlyString> deprecated_reflected_attribute, Optional<FlyString> initial_value);
29+
SVGAnimatedString(JS::Realm&, GC::Ref<SVGElement> element, DOM::QualifiedName reflected_attribute, Optional<DOM::QualifiedName> deprecated_reflected_attribute, Optional<FlyString> initial_value);
2930

3031
virtual void initialize(JS::Realm&) override;
3132
virtual void visit_edges(Cell::Visitor&) override;
3233

3334
GC::Ref<SVGElement> m_element;
34-
FlyString m_reflected_attribute;
35-
Optional<FlyString> m_deprecated_reflected_attribute;
35+
DOM::QualifiedName m_reflected_attribute;
36+
Optional<DOM::QualifiedName> m_deprecated_reflected_attribute;
3637
Optional<FlyString> m_initial_value;
3738
};
3839

Libraries/LibWeb/SVG/SVGElement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ GC::Ref<SVGAnimatedString> SVGElement::class_name()
279279
{
280280
// The className IDL attribute reflects the ‘class’ attribute.
281281
if (!m_class_name_animated_string)
282-
m_class_name_animated_string = SVGAnimatedString::create(realm(), *this, AttributeNames::class_);
282+
m_class_name_animated_string = SVGAnimatedString::create(realm(), *this, DOM::QualifiedName { AttributeNames::class_, OptionalNone {}, OptionalNone {} });
283283

284284
return *m_class_name_animated_string;
285285
}

Libraries/LibWeb/SVG/SVGFEBlendElement.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ void SVGFEBlendElement::attribute_changed(FlyString const& name, Optional<String
5555
GC::Ref<SVGAnimatedString> SVGFEBlendElement::in1()
5656
{
5757
if (!m_in1)
58-
m_in1 = SVGAnimatedString::create(realm(), *this, AttributeNames::in);
58+
m_in1 = SVGAnimatedString::create(realm(), *this, DOM::QualifiedName { AttributeNames::in, OptionalNone {}, OptionalNone {} });
5959

6060
return *m_in1;
6161
}
6262

6363
GC::Ref<SVGAnimatedString> SVGFEBlendElement::in2()
6464
{
6565
if (!m_in2)
66-
m_in2 = SVGAnimatedString::create(realm(), *this, AttributeNames::in2);
66+
m_in2 = SVGAnimatedString::create(realm(), *this, DOM::QualifiedName { AttributeNames::in2, OptionalNone {}, OptionalNone {} });
6767

6868
return *m_in2;
6969
}

Libraries/LibWeb/SVG/SVGFEColorMatrixElement.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void SVGFEColorMatrixElement::visit_edges(Cell::Visitor& visitor)
3535
GC::Ref<SVGAnimatedString> SVGFEColorMatrixElement::in1()
3636
{
3737
if (!m_in1)
38-
m_in1 = SVGAnimatedString::create(realm(), *this, AttributeNames::in);
38+
m_in1 = SVGAnimatedString::create(realm(), *this, DOM::QualifiedName { AttributeNames::in, OptionalNone {}, OptionalNone {} });
3939
return *m_in1;
4040
}
4141

@@ -62,7 +62,7 @@ GC::Ref<SVGAnimatedEnumeration> SVGFEColorMatrixElement::type() const
6262
GC::Ref<SVGAnimatedString> SVGFEColorMatrixElement::values()
6363
{
6464
if (!m_values)
65-
m_values = SVGAnimatedString::create(realm(), *this, AttributeNames::values);
65+
m_values = SVGAnimatedString::create(realm(), *this, DOM::QualifiedName { AttributeNames::values, OptionalNone {}, OptionalNone {} });
6666
return *m_values;
6767
}
6868

Libraries/LibWeb/SVG/SVGFECompositeElement.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ void SVGFECompositeElement::attribute_changed(FlyString const& name, Optional<St
7070
GC::Ref<SVGAnimatedString> SVGFECompositeElement::in1()
7171
{
7272
if (!m_in1)
73-
m_in1 = SVGAnimatedString::create(realm(), *this, AttributeNames::in);
73+
m_in1 = SVGAnimatedString::create(realm(), *this, DOM::QualifiedName { AttributeNames::in, OptionalNone {}, OptionalNone {} });
7474

7575
return *m_in1;
7676
}
7777

7878
GC::Ref<SVGAnimatedString> SVGFECompositeElement::in2()
7979
{
8080
if (!m_in2)
81-
m_in2 = SVGAnimatedString::create(realm(), *this, AttributeNames::in2);
81+
m_in2 = SVGAnimatedString::create(realm(), *this, DOM::QualifiedName { AttributeNames::in2, OptionalNone {}, OptionalNone {} });
8282

8383
return *m_in2;
8484
}
@@ -87,7 +87,7 @@ GC::Ref<SVGAnimatedString> SVGFECompositeElement::in2()
8787
GC::Ref<SVGAnimatedNumber> SVGFECompositeElement::k1()
8888
{
8989
if (!m_k1)
90-
m_k1 = SVGAnimatedNumber::create(realm(), *this, AttributeNames::k1, 0.f);
90+
m_k1 = SVGAnimatedNumber::create(realm(), *this, DOM::QualifiedName { AttributeNames::k1, OptionalNone {}, OptionalNone {} }, 0.f);
9191

9292
return *m_k1;
9393
}
@@ -96,7 +96,7 @@ GC::Ref<SVGAnimatedNumber> SVGFECompositeElement::k1()
9696
GC::Ref<SVGAnimatedNumber> SVGFECompositeElement::k2()
9797
{
9898
if (!m_k2)
99-
m_k2 = SVGAnimatedNumber::create(realm(), *this, AttributeNames::k2, 0.f);
99+
m_k2 = SVGAnimatedNumber::create(realm(), *this, DOM::QualifiedName { AttributeNames::k2, OptionalNone {}, OptionalNone {} }, 0.f);
100100

101101
return *m_k2;
102102
}
@@ -105,7 +105,7 @@ GC::Ref<SVGAnimatedNumber> SVGFECompositeElement::k2()
105105
GC::Ref<SVGAnimatedNumber> SVGFECompositeElement::k3()
106106
{
107107
if (!m_k3)
108-
m_k3 = SVGAnimatedNumber::create(realm(), *this, AttributeNames::k3, 0.f);
108+
m_k3 = SVGAnimatedNumber::create(realm(), *this, DOM::QualifiedName { AttributeNames::k3, OptionalNone {}, OptionalNone {} }, 0.f);
109109

110110
return *m_k3;
111111
}
@@ -114,7 +114,7 @@ GC::Ref<SVGAnimatedNumber> SVGFECompositeElement::k3()
114114
GC::Ref<SVGAnimatedNumber> SVGFECompositeElement::k4()
115115
{
116116
if (!m_k4)
117-
m_k4 = SVGAnimatedNumber::create(realm(), *this, AttributeNames::k4, 0.f);
117+
m_k4 = SVGAnimatedNumber::create(realm(), *this, DOM::QualifiedName { AttributeNames::k4, OptionalNone {}, OptionalNone {} }, 0.f);
118118

119119
return *m_k4;
120120
}

Libraries/LibWeb/SVG/SVGFEGaussianBlurElement.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void SVGFEGaussianBlurElement::visit_edges(Cell::Visitor& visitor)
3737
GC::Ref<SVGAnimatedString> SVGFEGaussianBlurElement::in1()
3838
{
3939
if (!m_in1)
40-
m_in1 = SVGAnimatedString::create(realm(), *this, AttributeNames::in);
40+
m_in1 = SVGAnimatedString::create(realm(), *this, DOM::QualifiedName { AttributeNames::in, OptionalNone {}, OptionalNone {} });
4141

4242
return *m_in1;
4343
}
@@ -46,7 +46,7 @@ GC::Ref<SVGAnimatedString> SVGFEGaussianBlurElement::in1()
4646
GC::Ref<SVGAnimatedNumber> SVGFEGaussianBlurElement::std_deviation_x()
4747
{
4848
if (!m_std_deviation_x) {
49-
m_std_deviation_x = SVGAnimatedNumber::create(realm(), *this, AttributeNames::stdDeviation, 0.f,
49+
m_std_deviation_x = SVGAnimatedNumber::create(realm(), *this, DOM::QualifiedName { AttributeNames::stdDeviation, OptionalNone {}, OptionalNone {} }, 0.f,
5050
SVGAnimatedNumber::SupportsSecondValue::Yes, SVGAnimatedNumber::ValueRepresented::First);
5151
}
5252
return *m_std_deviation_x;
@@ -56,7 +56,7 @@ GC::Ref<SVGAnimatedNumber> SVGFEGaussianBlurElement::std_deviation_x()
5656
GC::Ref<SVGAnimatedNumber> SVGFEGaussianBlurElement::std_deviation_y()
5757
{
5858
if (!m_std_deviation_y) {
59-
m_std_deviation_y = SVGAnimatedNumber::create(realm(), *this, AttributeNames::stdDeviation, 0.f,
59+
m_std_deviation_y = SVGAnimatedNumber::create(realm(), *this, DOM::QualifiedName { AttributeNames::stdDeviation, OptionalNone {}, OptionalNone {} }, 0.f,
6060
SVGAnimatedNumber::SupportsSecondValue::Yes, SVGAnimatedNumber::ValueRepresented::Second);
6161
}
6262
return *m_std_deviation_y;

0 commit comments

Comments
 (0)