Skip to content

Truly independent web browser

LibWeb: Make SVGNumberList and SVGLengthList reflect their attributes

Andreas Kling3919adf4d16f
diff --git a/Libraries/LibWeb/SVG/SVGAnimatedLengthList.cpp b/Libraries/LibWeb/SVG/SVGAnimatedLengthList.cpp
index b2fc2fe5068..8b034ad2183 100644
--- a/Libraries/LibWeb/SVG/SVGAnimatedLengthList.cpp
+++ b/Libraries/LibWeb/SVG/SVGAnimatedLengthList.cpp
@@ -11,13 +11,20 @@ namespace Web::SVG {
GC_DEFINE_ALLOCATOR(SVGAnimatedLengthList);
-GC::Ref<SVGAnimatedLengthList> SVGAnimatedLengthList::create(GC::Ref<SVGLengthList> base_val)
+// https://svgwg.org/svg2-draft/types.html#InterfaceSVGAnimatedLengthList
+GC::Ref<SVGAnimatedLengthList> SVGAnimatedLengthList::create(GC::Ref<SVGElement> element, Utf16FlyString reflected_attribute, SVGLength::Directionality directionality)
{
- return GC::Heap::the().allocate<SVGAnimatedLengthList>(base_val);
+ // On getting baseVal or animVal, an SVGLengthList object is returned that reflects the base value of the reflected
+ // attribute.
+ // NB: List interface objects reflected through the animVal IDL attribute are always read only.
+ auto base_val = SVGLengthList::create(element, reflected_attribute, directionality, ReadOnlyList::No);
+ auto anim_val = SVGLengthList::create(element, move(reflected_attribute), directionality, ReadOnlyList::Yes);
+ return GC::Heap::the().allocate<SVGAnimatedLengthList>(base_val, anim_val);
}
-SVGAnimatedLengthList::SVGAnimatedLengthList(GC::Ref<SVGLengthList> base_val)
+SVGAnimatedLengthList::SVGAnimatedLengthList(GC::Ref<SVGLengthList> base_val, GC::Ref<SVGLengthList> anim_val)
: m_base_val(base_val)
+ , m_anim_val(anim_val)
{
}
@@ -25,6 +32,13 @@ void SVGAnimatedLengthList::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_base_val);
+ visitor.visit(m_anim_val);
+}
+
+void SVGAnimatedLengthList::synchronize()
+{
+ m_base_val->synchronize();
+ m_anim_val->synchronize();
}
}
diff --git a/Libraries/LibWeb/SVG/SVGAnimatedLengthList.h b/Libraries/LibWeb/SVG/SVGAnimatedLengthList.h
index 8f1b58d7f46..53bffe84e3c 100644
--- a/Libraries/LibWeb/SVG/SVGAnimatedLengthList.h
+++ b/Libraries/LibWeb/SVG/SVGAnimatedLengthList.h
@@ -18,21 +18,26 @@ class SVGAnimatedLengthList final : public Bindings::GCAllocatedWrappable {
public:
static constexpr size_t base_val_offset() { return offsetof(SVGAnimatedLengthList, m_base_val); }
- [[nodiscard]] static GC::Ref<SVGAnimatedLengthList> create(GC::Ref<SVGLengthList>);
+ static constexpr size_t anim_val_offset() { return offsetof(SVGAnimatedLengthList, m_anim_val); }
+ [[nodiscard]] static GC::Ref<SVGAnimatedLengthList> create(GC::Ref<SVGElement>, Utf16FlyString reflected_attribute, SVGLength::Directionality);
virtual ~SVGAnimatedLengthList() override = default;
// https://svgwg.org/svg2-draft/types.html#__svg__SVGAnimatedLengthList__baseVal
GC::Ref<SVGLengthList> base_val() const { return m_base_val; }
// https://svgwg.org/svg2-draft/types.html#__svg__SVGAnimatedLengthList__animVal
- GC::Ref<SVGLengthList> anim_val() const { return m_base_val; }
+ GC::Ref<SVGLengthList> anim_val() const { return m_anim_val; }
+
+ // https://svgwg.org/svg2-draft/types.html#SynchronizingReflectedValues
+ void synchronize();
private:
- SVGAnimatedLengthList(GC::Ref<SVGLengthList>);
+ SVGAnimatedLengthList(GC::Ref<SVGLengthList> base_val, GC::Ref<SVGLengthList> anim_val);
virtual void visit_edges(Visitor&) override;
GC::Ref<SVGLengthList> m_base_val;
+ GC::Ref<SVGLengthList> m_anim_val;
};
}
diff --git a/Libraries/LibWeb/SVG/SVGAnimatedNumberList.cpp b/Libraries/LibWeb/SVG/SVGAnimatedNumberList.cpp
index d2b5f862b89..65f1810bda2 100644
--- a/Libraries/LibWeb/SVG/SVGAnimatedNumberList.cpp
+++ b/Libraries/LibWeb/SVG/SVGAnimatedNumberList.cpp
@@ -11,13 +11,20 @@ namespace Web::SVG {
GC_DEFINE_ALLOCATOR(SVGAnimatedNumberList);
-GC::Ref<SVGAnimatedNumberList> SVGAnimatedNumberList::create(GC::Ref<SVGNumberList> base_val)
+// https://svgwg.org/svg2-draft/types.html#InterfaceSVGAnimatedNumberList
+GC::Ref<SVGAnimatedNumberList> SVGAnimatedNumberList::create(GC::Ref<SVGElement> element, Utf16FlyString reflected_attribute)
{
- return GC::Heap::the().allocate<SVGAnimatedNumberList>(base_val);
+ // On getting baseVal or animVal, an SVGNumberList object is returned that reflects the base value of the reflected
+ // attribute.
+ // NB: List interface objects reflected through the animVal IDL attribute are always read only.
+ auto base_val = SVGNumberList::create(element, reflected_attribute, ReadOnlyList::No);
+ auto anim_val = SVGNumberList::create(element, move(reflected_attribute), ReadOnlyList::Yes);
+ return GC::Heap::the().allocate<SVGAnimatedNumberList>(base_val, anim_val);
}
-SVGAnimatedNumberList::SVGAnimatedNumberList(GC::Ref<SVGNumberList> base_val)
+SVGAnimatedNumberList::SVGAnimatedNumberList(GC::Ref<SVGNumberList> base_val, GC::Ref<SVGNumberList> anim_val)
: m_base_val(base_val)
+ , m_anim_val(anim_val)
{
}
@@ -25,6 +32,13 @@ void SVGAnimatedNumberList::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_base_val);
+ visitor.visit(m_anim_val);
+}
+
+void SVGAnimatedNumberList::synchronize()
+{
+ m_base_val->synchronize();
+ m_anim_val->synchronize();
}
}
diff --git a/Libraries/LibWeb/SVG/SVGAnimatedNumberList.h b/Libraries/LibWeb/SVG/SVGAnimatedNumberList.h
index dc17157650a..73fa18254e5 100644
--- a/Libraries/LibWeb/SVG/SVGAnimatedNumberList.h
+++ b/Libraries/LibWeb/SVG/SVGAnimatedNumberList.h
@@ -18,21 +18,26 @@ class SVGAnimatedNumberList final : public Bindings::GCAllocatedWrappable {
public:
static constexpr size_t base_val_offset() { return offsetof(SVGAnimatedNumberList, m_base_val); }
- [[nodiscard]] static GC::Ref<SVGAnimatedNumberList> create(GC::Ref<SVGNumberList>);
+ static constexpr size_t anim_val_offset() { return offsetof(SVGAnimatedNumberList, m_anim_val); }
+ [[nodiscard]] static GC::Ref<SVGAnimatedNumberList> create(GC::Ref<SVGElement>, Utf16FlyString reflected_attribute);
virtual ~SVGAnimatedNumberList() override = default;
// https://www.w3.org/TR/SVG2/types.html#__svg__SVGAnimatedLengthList__baseVal
GC::Ref<SVGNumberList> base_val() const { return m_base_val; }
// https://www.w3.org/TR/SVG2/types.html#__svg__SVGAnimatedLengthList__animVal
- GC::Ref<SVGNumberList> anim_val() const { return m_base_val; }
+ GC::Ref<SVGNumberList> anim_val() const { return m_anim_val; }
+
+ // https://svgwg.org/svg2-draft/types.html#SynchronizingReflectedValues
+ void synchronize();
private:
- SVGAnimatedNumberList(GC::Ref<SVGNumberList>);
+ SVGAnimatedNumberList(GC::Ref<SVGNumberList> base_val, GC::Ref<SVGNumberList> anim_val);
virtual void visit_edges(Visitor&) override;
GC::Ref<SVGNumberList> m_base_val;
+ GC::Ref<SVGNumberList> m_anim_val;
};
}
diff --git a/Libraries/LibWeb/SVG/SVGComponentTransferFunctionElement.cpp b/Libraries/LibWeb/SVG/SVGComponentTransferFunctionElement.cpp
index 6aced3d838d..d6b3550e07a 100644
--- a/Libraries/LibWeb/SVG/SVGComponentTransferFunctionElement.cpp
+++ b/Libraries/LibWeb/SVG/SVGComponentTransferFunctionElement.cpp
@@ -39,9 +39,8 @@ void SVGComponentTransferFunctionElement::attribute_changed(Utf16FlyString const
{
Base::attribute_changed(name, old_value, value, namespace_);
- // FIXME: Support reflection instead of invalidating the list.
- if (name == AttributeNames::tableValues)
- m_table_values = {};
+ if (name == AttributeNames::tableValues && m_table_values)
+ m_table_values->synchronize();
// Clear our cached color table on any attribute change.
m_cached_color_table.clear();
@@ -76,17 +75,8 @@ GC::Ref<SVGAnimatedEnumeration> SVGComponentTransferFunctionElement::type()
// https://drafts.fxtf.org/filter-effects-1/#element-attrdef-fecomponenttransfer-tablevalues
GC::Ref<SVGAnimatedNumberList> SVGComponentTransferFunctionElement::table_values()
{
- if (!m_table_values) {
- auto numbers = parse_table_values(get_attribute_value(AttributeNames::tableValues));
-
- auto items = GC::Heap::the().allocate<SVGNumberList::List>();
- items->elements().ensure_capacity(numbers.size());
- for (auto number : numbers)
- items->elements().unchecked_append(SVGNumber::create(number, SVGNumber::ReadOnly::Yes));
-
- auto number_list = SVGNumberList::create(items, ReadOnlyList::Yes);
- m_table_values = SVGAnimatedNumberList::create(number_list);
- }
+ if (!m_table_values)
+ m_table_values = SVGAnimatedNumberList::create(*this, AttributeNames::tableValues);
return *m_table_values;
}
diff --git a/Libraries/LibWeb/SVG/SVGFEColorMatrixElement.cpp b/Libraries/LibWeb/SVG/SVGFEColorMatrixElement.cpp
index 8c727b36b96..48fe0f39313 100644
--- a/Libraries/LibWeb/SVG/SVGFEColorMatrixElement.cpp
+++ b/Libraries/LibWeb/SVG/SVGFEColorMatrixElement.cpp
@@ -32,9 +32,8 @@ void SVGFEColorMatrixElement::attribute_changed(Utf16FlyString const& name, Opti
{
Base::attribute_changed(name, old_value, value, namespace_);
- // FIXME: Support reflection instead of invalidating the list.
- if (name == AttributeNames::values)
- m_values = {};
+ if (name == AttributeNames::values && m_values)
+ m_values->synchronize();
}
GC::Ref<SVGAnimatedString> SVGFEColorMatrixElement::in1()
@@ -58,18 +57,8 @@ GC::Ref<SVGAnimatedEnumeration> SVGFEColorMatrixElement::type()
GC::Ref<SVGAnimatedNumberList> SVGFEColorMatrixElement::values()
{
- if (!m_values) {
- auto numbers = parse_table_values(get_attribute_value(AttributeNames::values));
-
- auto items = GC::Heap::the().allocate<SVGNumberList::List>();
- items->elements().ensure_capacity(numbers.size());
- for (auto number : numbers)
- items->elements().unchecked_append(SVGNumber::create(number, SVGNumber::ReadOnly::Yes));
-
- auto number_list = SVGNumberList::create(items, ReadOnlyList::Yes);
- m_values = SVGAnimatedNumberList::create(number_list);
- }
-
+ if (!m_values)
+ m_values = SVGAnimatedNumberList::create(*this, AttributeNames::values);
return *m_values;
}
diff --git a/Libraries/LibWeb/SVG/SVGFEConvolveMatrixElement.cpp b/Libraries/LibWeb/SVG/SVGFEConvolveMatrixElement.cpp
index 007455f3b40..087f0be5398 100644
--- a/Libraries/LibWeb/SVG/SVGFEConvolveMatrixElement.cpp
+++ b/Libraries/LibWeb/SVG/SVGFEConvolveMatrixElement.cpp
@@ -41,9 +41,8 @@ void SVGFEConvolveMatrixElement::attribute_changed(Utf16FlyString const& name, O
{
Base::attribute_changed(name, old_value, value, namespace_);
- // FIXME: Support reflection instead of invalidating the list.
- if (name == AttributeNames::kernelMatrix)
- m_kernel_matrix = {};
+ if (name == AttributeNames::kernelMatrix && m_kernel_matrix)
+ m_kernel_matrix->synchronize();
}
// https://drafts.fxtf.org/filter-effects/#dom-svgfeconvolvematrixelement-in1
@@ -75,17 +74,8 @@ GC::Ref<SVGAnimatedInteger> SVGFEConvolveMatrixElement::order_y()
// https://drafts.fxtf.org/filter-effects/#dom-svgfeconvolvematrixelement-kernelmatrix
GC::Ref<SVGAnimatedNumberList> SVGFEConvolveMatrixElement::kernel_matrix()
{
- if (!m_kernel_matrix) {
- auto numbers = parse_table_values(get_attribute_value(AttributeNames::kernelMatrix));
-
- auto items = GC::Heap::the().allocate<SVGNumberList::List>();
- items->elements().ensure_capacity(numbers.size());
- for (auto number : numbers)
- items->elements().unchecked_append(SVGNumber::create(number, SVGNumber::ReadOnly::Yes));
-
- auto number_list = SVGNumberList::create(items, ReadOnlyList::Yes);
- m_kernel_matrix = SVGAnimatedNumberList::create(number_list);
- }
+ if (!m_kernel_matrix)
+ m_kernel_matrix = SVGAnimatedNumberList::create(*this, AttributeNames::kernelMatrix);
return *m_kernel_matrix;
}
diff --git a/Libraries/LibWeb/SVG/SVGLength.cpp b/Libraries/LibWeb/SVG/SVGLength.cpp
index 8289052da3e..69a2906a7e4 100644
--- a/Libraries/LibWeb/SVG/SVGLength.cpp
+++ b/Libraries/LibWeb/SVG/SVGLength.cpp
@@ -14,6 +14,7 @@
#include <LibWeb/SVG/SVGElement.h>
#include <LibWeb/SVG/SVGForeignObjectElement.h>
#include <LibWeb/SVG/SVGLength.h>
+#include <LibWeb/SVG/SVGLengthList.h>
namespace Web::SVG {
@@ -24,6 +25,16 @@ GC::Ref<SVGLength> SVGLength::create_detached(JS::Realm& realm, SVGLengthValue v
return realm.create<SVGLength>(realm, nullptr, Directionality::Unspecified, DetachedSource { .value = value }, read_only);
}
+GC::Ref<SVGLength> SVGLength::create_detached_copy() const
+{
+ auto value = internal_value().visit(
+ [](SVGLengthValue const& scalar) -> Variant<SVGLengthValue, Utf16String> { return scalar; },
+ [](NonnullRefPtr<CSS::StyleValue const> const& style_value) -> Variant<SVGLengthValue, Utf16String> {
+ return style_value->to_utf16_string(CSS::SerializationMode::Normal);
+ });
+ return m_realm->create<SVGLength>(*m_realm, nullptr, Directionality::Unspecified, DetachedSource { .value = move(value) }, ReadOnly::No);
+}
+
GC::Ref<SVGLength> SVGLength::create_reflected_attribute(JS::Realm& realm, GC::Ref<SVGElement> element, Utf16FlyString name, Directionality directionality, ReflectedAttributeType type, SVGLengthValue default_value, ReadOnly read_only)
{
return realm.create<SVGLength>(realm, element, directionality, ReflectedAttributeSource { .name = move(name), .type = type, .default_value = default_value }, read_only);
@@ -42,9 +53,42 @@ SVGLength::SVGLength(JS::Realm& realm, GC::Ptr<SVGElement> associated_element, D
void SVGLength::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
- if (m_source.has<ReflectedAttributeSource>())
- visitor.visit(m_element);
+ visitor.visit(m_element);
visitor.visit(m_realm);
+ visitor.visit(m_list);
+}
+
+// https://svgwg.org/svg2-draft/types.html#TermAttach
+void SVGLength::attach(GC::Ref<SVGLengthList> list, GC::Ref<SVGElement> element, Directionality directionality, ReadOnly read_only)
+{
+ // Associate the SVGLength with the element that the list interface object is associated with and set its
+ // directionality to that specified by the attribute being reflected. Additionally, depending on which IDL attribute
+ // the list interface object is reflected through:
+ // baseVal: Set the SVGLength to reflect an element of the base value.
+ // animVal: Set the SVGLength to reflect an element of the base value. Set the SVGLength to be read only.
+ VERIFY(m_source.has<DetachedSource>());
+ m_list = list;
+ m_element = element;
+ m_directionality = directionality;
+ m_read_only = read_only;
+}
+
+// https://svgwg.org/svg2-draft/types.html#TermDetach
+void SVGLength::detach()
+{
+ // Set the SVGLength to no longer be associated with any element. If the SVGLength is read only, set it to be no
+ // longer read only. Set the SVGLength to have unspecified directionality.
+ VERIFY(m_source.has<DetachedSource>());
+ m_list = nullptr;
+ m_element = nullptr;
+ m_read_only = ReadOnly::No;
+ m_directionality = Directionality::Unspecified;
+}
+
+void SVGLength::set_value_from_reflected_attribute(SVGLengthValue value)
+{
+ VERIFY(m_source.has<DetachedSource>());
+ m_source.get<DetachedSource>().value = value;
}
SVGLength::~SVGLength() = default;
@@ -271,6 +315,14 @@ static RefPtr<CSS::StyleValue const> parse_css_length_value(Utf16View const& val
return nullptr;
}
+Optional<SVGLengthValue> SVGLength::parse_scalar_value(Utf16View value)
+{
+ auto parsed_value = parse_css_length_value(value);
+ if (!parsed_value)
+ return {};
+ return SVGLengthValue::from_style_value(*parsed_value);
+}
+
SVGLength::InternalValue SVGLength::internal_value() const
{
return m_source.visit(
@@ -407,8 +459,9 @@ WebIDL::ExceptionOr<void> SVGLength::set_value(float value)
// 4. If the SVGLength reflects the base value of a reflected attribute, reflects a presentation attribute, or
// reflects an element of the base value of a reflected attribute, then reserialize the reflected attribute.
- // FIXME: Implement this for "reflects a presentation attribute" and "reflects an element of the base value of a
- // reflected attribute" if/when we support those modes.
+ // FIXME: Implement this for "reflects a presentation attribute" if/when we support that mode.
+ if (m_list)
+ m_list->reserialize_reflected_attribute();
if (m_source.has<ReflectedAttributeSource>()) {
// NB: All attribute reflecting lengths should have an associated element
VERIFY(m_element);
@@ -481,8 +534,9 @@ WebIDL::ExceptionOr<void> SVGLength::set_value_in_specified_units(float value)
// 6. If the SVGLength reflects the base value of a reflected attribute or reflects an element of the base value of
// a reflected attribute, then reserialize the reflected attribute.
- // FIXME: Implement this for "reflects an element of the base value of a reflected attribute" when we support it.
// FIXME: Should this also happen for "reflects a presentation attribute" as we do with set_value()?
+ if (m_list)
+ m_list->reserialize_reflected_attribute();
if (m_source.has<ReflectedAttributeSource>()) {
// NB: All attribute reflecting lengths should have an associated element
VERIFY(m_element);
@@ -559,8 +613,9 @@ WebIDL::ExceptionOr<void> SVGLength::set_value_as_string(Utf16String value)
// 6. If the SVGLength reflects the base value of a reflected attribute or reflects an element of the base value of
// a reflected attribute, then reserialize the reflected attribute.
- // FIXME: Implement this for "reflects an element of the base value of a reflected attribute" when we support it.
// FIXME: Should this also happen for "reflects a presentation attribute" as we do with set_value()?
+ if (m_list)
+ m_list->reserialize_reflected_attribute();
if (m_source.has<ReflectedAttributeSource>()) {
// NB: All attribute reflecting lengths should have an associated element
VERIFY(m_element);
@@ -636,8 +691,9 @@ WebIDL::ExceptionOr<void> SVGLength::new_value_specified_units(u16 unit_type, fl
// 4. If the SVGLength reflects the base value of a reflected attribute or reflects an element of the base value of
// a reflected attribute, then reserialize the reflected attribute.
- // FIXME: Implement this for "reflects an element of the base value of a reflected attribute" when we support it.
// FIXME: Should this also happen for "reflects a presentation attribute" as we do with set_value()?
+ if (m_list)
+ m_list->reserialize_reflected_attribute();
if (m_source.has<ReflectedAttributeSource>()) {
// NB: All attribute reflecting lengths should have an associated element
VERIFY(m_element);
@@ -700,8 +756,9 @@ WebIDL::ExceptionOr<void> SVGLength::convert_to_specified_units(u16 unit_type)
// 8. If the SVGLength reflects the base value of a reflected attribute or reflects an element of the base value of
// a reflected attribute, then reserialize the reflected attribute.
- // FIXME: Implement this for "reflects an element of the base value of a reflected attribute" when we support it.
// FIXME: Should this also happen for "reflects a presentation attribute" as we do with set_value()?
+ if (m_list)
+ m_list->reserialize_reflected_attribute();
if (m_source.has<ReflectedAttributeSource>()) {
// NB: All attribute reflecting lengths should have an associated element
VERIFY(m_element);
diff --git a/Libraries/LibWeb/SVG/SVGLength.h b/Libraries/LibWeb/SVG/SVGLength.h
index 72a7409b255..9761facc085 100644
--- a/Libraries/LibWeb/SVG/SVGLength.h
+++ b/Libraries/LibWeb/SVG/SVGLength.h
@@ -70,6 +70,23 @@ public:
ReadOnly read_only() const { return m_read_only; }
+ // https://svgwg.org/svg2-draft/types.html#TermAttach
+ void attach(GC::Ref<SVGLengthList>, GC::Ref<SVGElement>, Directionality, ReadOnly);
+
+ // https://svgwg.org/svg2-draft/types.html#TermDetach
+ void detach();
+
+ bool is_detached() const { return !m_list && m_source.has<DetachedSource>(); }
+
+ // Creates a detached, writable SVGLength that has the same value as this one.
+ [[nodiscard]] GC::Ref<SVGLength> create_detached_copy() const;
+
+ // Parses a value using the CSS syntax [ <number> | <length> | <percentage> ], if it parses to a scalar value.
+ static Optional<SVGLengthValue> parse_scalar_value(Utf16View);
+
+ // Sets the value when the list this length belongs to is synchronized with its reflected attribute.
+ void set_value_from_reflected_attribute(SVGLengthValue);
+
private:
// An SVGLength object can be associated with a particular element, as well as being designated with a
// directionality: horizontal, vertical or unspecified.
@@ -92,7 +109,7 @@ private:
// 3. reflect an element of the base value of a reflected animatable attribute (being exposed through the methods on
// the baseVal member of an SVGAnimatedLengthList), or
- // FIXME: Implement this - we currently use a detached SVGLength for this.
+ // NB: Such a length holds its value like a detached one, and additionally has the list it is an element of.
// 4. be detached, which is the case for SVGLength objects created with createSVGLength.
struct DetachedSource {
@@ -114,6 +131,9 @@ private:
Source m_source;
+ // The list this length is an element of, if it reflects an element of the base value of a reflected attribute.
+ GC::Ptr<SVGLengthList> m_list;
+
// https://svgwg.org/svg2-draft/types.html#ReadOnlyLength
ReadOnly m_read_only;
};
diff --git a/Libraries/LibWeb/SVG/SVGLengthList.cpp b/Libraries/LibWeb/SVG/SVGLengthList.cpp
index 46977cf281d..3ff8748dadf 100644
--- a/Libraries/LibWeb/SVG/SVGLengthList.cpp
+++ b/Libraries/LibWeb/SVG/SVGLengthList.cpp
@@ -4,38 +4,129 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/TemporaryChange.h>
+#include <AK/Utf16StringBuilder.h>
#include <LibGC/Heap.h>
-#include <LibWeb/SVG/SVGLength.h>
+#include <LibWeb/DOM/Document.h>
+#include <LibWeb/HTML/Scripting/Environments.h>
+#include <LibWeb/SVG/SVGElement.h>
#include <LibWeb/SVG/SVGLengthList.h>
namespace Web::SVG {
GC_DEFINE_ALLOCATOR(SVGLengthList);
-GC::Ref<SVGLengthList> SVGLengthList::create(GC::Ref<List> items, ReadOnlyList read_only)
+GC::Ref<SVGLengthList> SVGLengthList::create(GC::Ref<SVGElement> element, Utf16FlyString reflected_attribute, SVGLength::Directionality directionality, ReadOnlyList read_only)
{
- return GC::Heap::the().allocate<SVGLengthList>(items, read_only);
+ return GC::Heap::the().allocate<SVGLengthList>(element, move(reflected_attribute), directionality, read_only);
}
-GC::Ref<SVGLengthList> SVGLengthList::create(ReadOnlyList read_only)
+SVGLengthList::SVGLengthList(GC::Ref<SVGElement> element, Utf16FlyString reflected_attribute, SVGLength::Directionality directionality, ReadOnlyList read_only)
+ : SVGList(read_only)
+ , m_element(element)
+ , m_reflected_attribute(move(reflected_attribute))
+ , m_directionality(directionality)
{
- return GC::Heap::the().allocate<SVGLengthList>(read_only);
+ synchronize();
}
-SVGLengthList::SVGLengthList(GC::Ref<List> items, ReadOnlyList read_only)
- : SVGList(move(items->elements()), read_only)
+void SVGLengthList::visit_edges(Visitor& visitor)
{
+ Base::visit_edges(visitor);
+ SVGList::visit_edges(visitor);
+ visitor.visit(m_element);
}
-SVGLengthList::SVGLengthList(ReadOnlyList read_only)
- : SVGList(read_only)
+void SVGLengthList::attach(GC::Ref<SVGLength> const& length)
{
+ length->attach(*this, m_element, m_directionality, read_only() == ReadOnlyList::Yes ? SVGLength::ReadOnly::Yes : SVGLength::ReadOnly::No);
}
-void SVGLengthList::visit_edges(Visitor& visitor)
+void SVGLengthList::detach(GC::Ref<SVGLength> const& length)
{
- Base::visit_edges(visitor);
- SVGList::visit_edges(visitor);
+ length->detach();
+}
+
+GC::Ref<SVGLength> SVGLengthList::copy_if_not_detached(GC::Ref<SVGLength> length)
+{
+ if (length->is_detached())
+ return length;
+ return length->create_detached_copy();
+}
+
+// Parses a list of lengths, percentages and numbers that are separated by commas and/or whitespace.
+static Vector<SVGLengthValue> parse_length_list(Utf16View input)
+{
+ Vector<SVGLengthValue> values;
+ auto is_separator = [](char16_t code_unit) { return code_unit == ',' || code_unit == ' ' || code_unit == '\t' || code_unit == '\n' || code_unit == '\r' || code_unit == '\f'; };
+
+ size_t position = 0;
+ auto length = input.length_in_code_units();
+ while (true) {
+ // Skip whitespace, and at most one comma.
+ bool seen_comma = false;
+ while (position < length && is_separator(input.code_unit_at(position))) {
+ if (input.code_unit_at(position) == ',') {
+ // A comma must separate two values.
+ if (seen_comma || values.is_empty())
+ return {};
+ seen_comma = true;
+ }
+ ++position;
+ }
+ if (position >= length) {
+ // A trailing comma is invalid.
+ if (seen_comma)
+ return {};
+ break;
+ }
+
+ auto start = position;
+ while (position < length && !is_separator(input.code_unit_at(position)))
+ ++position;
+ auto value = SVGLength::parse_scalar_value(input.substring_view(start, position - start));
+ if (!value.has_value())
+ return {};
+ values.append(*value);
+ }
+ return values;
+}
+
+// https://svgwg.org/svg2-draft/types.html#TermSynchronizeList
+void SVGLengthList::synchronize()
+{
+ // NB: The list does not need to be synchronized with a value that it has just reserialized itself.
+ if (m_is_reserializing)
+ return;
+
+ // 1. Let value be the base value of the reflected content attribute (using the attribute's initial value if it is
+ // not present or invalid).
+ // NB: The initial value of every attribute reflected by an SVGLengthList is the empty list.
+ auto value = parse_length_list(m_element->get_attribute_value(m_reflected_attribute));
+
+ auto& realm = m_element->document().relevant_settings_object().realm();
+ synchronize_items(value, [&] { return SVGLength::create_detached(realm, SVGLengthValue::number(0), SVGLength::ReadOnly::No); }, [](GC::Ref<SVGLength> const& item, SVGLengthValue const& length) { item->set_value_from_reflected_attribute(length); });
+}
+
+// https://svgwg.org/svg2-draft/types.html#TermReserialize
+void SVGLengthList::reserialize_reflected_attribute()
+{
+ // 1. Let elements be the list of values in value.
+ // 2. Let serialized elements be a list of strings, where each string is formed based on the corresponding value in
+ // elements and its type:
+ // an SVGLength object: The string is the value that would be returned from getting the value's valueAsString
+ // member.
+ // 3. Set the content attribute to a string consisting of the strings in serialized elements joined and separated by
+ // single U+0020 SPACE characters.
+ Utf16StringBuilder builder;
+ for (size_t index = 0; index < items().size(); ++index) {
+ if (index > 0)
+ builder.append_code_unit(' ');
+ builder.append(items()[index]->value_as_string());
+ }
+
+ TemporaryChange change { m_is_reserializing, true };
+ m_element->set_attribute_value(m_reflected_attribute, builder.to_string());
}
}
diff --git a/Libraries/LibWeb/SVG/SVGLengthList.h b/Libraries/LibWeb/SVG/SVGLengthList.h
index 6efa8e0bbbf..47c08621f9d 100644
--- a/Libraries/LibWeb/SVG/SVGLengthList.h
+++ b/Libraries/LibWeb/SVG/SVGLengthList.h
@@ -6,7 +6,7 @@
#pragma once
-#include <LibGC/HeapVector.h>
+#include <AK/Utf16FlyString.h>
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/SVG/SVGLength.h>
#include <LibWeb/SVG/SVGList.h>
@@ -21,17 +21,28 @@ class SVGLengthList final
GC_DECLARE_ALLOCATOR(SVGLengthList);
public:
- using List = GC::HeapVector<GC::Ref<SVGLength>>;
-
- [[nodiscard]] static GC::Ref<SVGLengthList> create(GC::Ref<List>, ReadOnlyList);
- [[nodiscard]] static GC::Ref<SVGLengthList> create(ReadOnlyList);
+ [[nodiscard]] static GC::Ref<SVGLengthList> create(GC::Ref<SVGElement>, Utf16FlyString reflected_attribute, SVGLength::Directionality, ReadOnlyList);
virtual ~SVGLengthList() override = default;
+ // https://svgwg.org/svg2-draft/types.html#TermSynchronizeList
+ void synchronize();
+
+ // https://svgwg.org/svg2-draft/types.html#TermReserialize
+ virtual void reserialize_reflected_attribute() override;
+
private:
- SVGLengthList(GC::Ref<List>, ReadOnlyList);
- explicit SVGLengthList(ReadOnlyList);
+ SVGLengthList(GC::Ref<SVGElement>, Utf16FlyString reflected_attribute, SVGLength::Directionality, ReadOnlyList);
virtual void visit_edges(Visitor&) override;
+
+ virtual void attach(GC::Ref<SVGLength> const&) override;
+ virtual void detach(GC::Ref<SVGLength> const&) override;
+ virtual GC::Ref<SVGLength> copy_if_not_detached(GC::Ref<SVGLength>) override;
+
+ GC::Ref<SVGElement> m_element;
+ Utf16FlyString m_reflected_attribute;
+ SVGLength::Directionality m_directionality;
+ bool m_is_reserializing { false };
};
}
diff --git a/Libraries/LibWeb/SVG/SVGList.h b/Libraries/LibWeb/SVG/SVGList.h
index ae7a590bfc3..0231115b962 100644
--- a/Libraries/LibWeb/SVG/SVGList.h
+++ b/Libraries/LibWeb/SVG/SVGList.h
@@ -63,6 +63,60 @@ protected:
Vector<T>& mutable_items() { return m_items; }
+ // https://svgwg.org/svg2-draft/types.html#TermSynchronizeList
+ // The steps for synchronizing a list interface object whose list element type is an object type, given the values
+ // of the reflected attribute, a function that creates a new item, and a function that sets an item's value.
+ template<typename Values, typename CreateItem, typename SetItemValue>
+ void synchronize_items(Values const& value, CreateItem&& create_item, SetItemValue&& set_item_value)
+ {
+ // 2. Let length be the number of items in the list.
+ auto length = m_items.size();
+
+ // 3. Let new length be the number of values in value.
+ auto new_length = value.size();
+
+ // 4. If the list element type is SVGNumber, SVGLength, DOMPoint or SVGTransform, then:
+ // 1. If length > new length, then:
+ if (length > new_length) {
+ // 1. Detach each object in the list at an index greater than or equal to new length.
+ for (size_t index = new_length; index < length; ++index)
+ detach(m_items[index]);
+
+ // 2. Truncate the list to length new length.
+ m_items.shrink(new_length);
+
+ // 3. Set length to new length.
+ length = new_length;
+ }
+
+ // 2. While length < new length:
+ while (length < new_length) {
+ // 1. Let item be a newly created object of the list element type.
+ T item = create_item();
+
+ // 2. Attach item to this list interface object.
+ attach(item);
+
+ // 3. Append item to the list.
+ m_items.append(item);
+
+ // 4. Set length to length + 1.
+ ++length;
+ }
+
+ // 3. Let index be 0.
+ // 4. While index < length:
+ for (size_t index = 0; index < length; ++index) {
+ // 1. Let item be the object in the list at index index.
+ // 2. Let v be the value in value at index index.
+ // 3. Set item's value to v.
+ // 4. If item is an SVGTransform object, then set the components of its matrix object to match the new
+ // transform function value.
+ // 5. Set index to index + 1.
+ set_item_value(m_items[index], value[index]);
+ }
+ }
+
private:
Vector<T> m_items;
diff --git a/Libraries/LibWeb/SVG/SVGNumber.cpp b/Libraries/LibWeb/SVG/SVGNumber.cpp
index d8338e507e0..407d47be1f9 100644
--- a/Libraries/LibWeb/SVG/SVGNumber.cpp
+++ b/Libraries/LibWeb/SVG/SVGNumber.cpp
@@ -6,6 +6,7 @@
#include <LibGC/Heap.h>
#include <LibWeb/SVG/SVGNumber.h>
+#include <LibWeb/SVG/SVGNumberList.h>
namespace Web::SVG {
@@ -22,6 +23,33 @@ SVGNumber::SVGNumber(float value, ReadOnly read_only)
{
}
+void SVGNumber::visit_edges(Cell::Visitor& visitor)
+{
+ Base::visit_edges(visitor);
+ visitor.visit(m_list);
+}
+
+// https://svgwg.org/svg2-draft/types.html#TermAttach
+void SVGNumber::attach(GC::Ref<SVGNumberList> list, ReadOnly read_only)
+{
+ // Associate the SVGNumber with the element that the list interface object is associated with. Additionally,
+ // depending on which IDL attribute the list interface object is reflected through:
+ // baseVal: Set the SVGNumber to reflect an element of the base value.
+ // animVal: Set the SVGNumber to reflect an element of the base value.
+ // NB: SVGNumber objects reflected through the animVal IDL attribute are always read only.
+ m_list = list;
+ m_read_only = read_only;
+}
+
+// https://svgwg.org/svg2-draft/types.html#TermDetach
+void SVGNumber::detach()
+{
+ // Set the SVGNumber to no longer be associated with any element. If the SVGNumber is read only, set it to be no
+ // longer read only.
+ m_list = nullptr;
+ m_read_only = ReadOnly::No;
+}
+
// https://www.w3.org/TR/SVG2/types.html#__svg__SVGNumber__value
WebIDL::ExceptionOr<void> SVGNumber::set_value(float value)
{
@@ -32,8 +60,10 @@ WebIDL::ExceptionOr<void> SVGNumber::set_value(float value)
// 2. Set the SVGNumber's value to the value being assigned to the value member.
m_value = value;
- // FIXME: 3. If the SVGNumber reflects an element of the base value of a reflected attribute, then reserialize the
+ // 3. If the SVGNumber reflects an element of the base value of a reflected attribute, then reserialize the
// reflected attribute.
+ if (m_list)
+ m_list->reserialize_reflected_attribute();
return {};
}
diff --git a/Libraries/LibWeb/SVG/SVGNumber.h b/Libraries/LibWeb/SVG/SVGNumber.h
index 983e8c4b9a3..2230bdafd34 100644
--- a/Libraries/LibWeb/SVG/SVGNumber.h
+++ b/Libraries/LibWeb/SVG/SVGNumber.h
@@ -7,6 +7,7 @@
#pragma once
#include <LibWeb/Bindings/Wrappable.h>
+#include <LibWeb/Forward.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::SVG {
@@ -30,11 +31,27 @@ public:
ReadOnly read_only() const { return m_read_only; }
+ // https://svgwg.org/svg2-draft/types.html#TermAttach
+ void attach(GC::Ref<SVGNumberList>, ReadOnly);
+
+ // https://svgwg.org/svg2-draft/types.html#TermDetach
+ void detach();
+
+ bool is_detached() const { return !m_list; }
+
+ // Sets the value when the list this number belongs to is synchronized with its reflected attribute.
+ void set_value_from_reflected_attribute(float value) { m_value = value; }
+
private:
SVGNumber(float value, ReadOnly);
+ virtual void visit_edges(Cell::Visitor&) override;
+
float m_value { 0 };
+ // The list this number is an element of, if it reflects an element of the base value of a reflected attribute.
+ GC::Ptr<SVGNumberList> m_list;
+
// https://www.w3.org/TR/SVG2/types.html#ReadOnlyNumber
ReadOnly m_read_only;
};
diff --git a/Libraries/LibWeb/SVG/SVGNumberList.cpp b/Libraries/LibWeb/SVG/SVGNumberList.cpp
index 49156a1e249..9db18096453 100644
--- a/Libraries/LibWeb/SVG/SVGNumberList.cpp
+++ b/Libraries/LibWeb/SVG/SVGNumberList.cpp
@@ -4,7 +4,12 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/TemporaryChange.h>
+#include <AK/Utf16StringBuilder.h>
#include <LibGC/Heap.h>
+#include <LibWeb/CSS/Serialize.h>
+#include <LibWeb/SVG/AttributeParsing.h>
+#include <LibWeb/SVG/SVGElement.h>
#include <LibWeb/SVG/SVGNumber.h>
#include <LibWeb/SVG/SVGNumberList.h>
@@ -12,30 +17,79 @@ namespace Web::SVG {
GC_DEFINE_ALLOCATOR(SVGNumberList);
-GC::Ref<SVGNumberList> SVGNumberList::create(GC::Ref<List> items, ReadOnlyList read_only)
+GC::Ref<SVGNumberList> SVGNumberList::create(GC::Ref<SVGElement> element, Utf16FlyString reflected_attribute, ReadOnlyList read_only)
{
- return GC::Heap::the().allocate<SVGNumberList>(items, read_only);
+ return GC::Heap::the().allocate<SVGNumberList>(element, move(reflected_attribute), read_only);
}
-GC::Ref<SVGNumberList> SVGNumberList::create(ReadOnlyList read_only)
+SVGNumberList::SVGNumberList(GC::Ref<SVGElement> element, Utf16FlyString reflected_attribute, ReadOnlyList read_only)
+ : SVGList(read_only)
+ , m_element(element)
+ , m_reflected_attribute(move(reflected_attribute))
{
- return GC::Heap::the().allocate<SVGNumberList>(read_only);
+ synchronize();
}
-SVGNumberList::SVGNumberList(GC::Ref<List> items, ReadOnlyList read_only)
- : SVGList(move(items->elements()), read_only)
+void SVGNumberList::visit_edges(Visitor& visitor)
{
+ Base::visit_edges(visitor);
+ SVGList::visit_edges(visitor);
+ visitor.visit(m_element);
}
-SVGNumberList::SVGNumberList(ReadOnlyList read_only)
- : SVGList(read_only)
+void SVGNumberList::attach(GC::Ref<SVGNumber> const& number)
{
+ number->attach(*this, read_only() == ReadOnlyList::Yes ? SVGNumber::ReadOnly::Yes : SVGNumber::ReadOnly::No);
}
-void SVGNumberList::visit_edges(Visitor& visitor)
+void SVGNumberList::detach(GC::Ref<SVGNumber> const& number)
{
- Base::visit_edges(visitor);
- SVGList::visit_edges(visitor);
+ number->detach();
+}
+
+GC::Ref<SVGNumber> SVGNumberList::copy_if_not_detached(GC::Ref<SVGNumber> number)
+{
+ if (number->is_detached())
+ return number;
+ return SVGNumber::create(number->value(), SVGNumber::ReadOnly::No);
+}
+
+// https://svgwg.org/svg2-draft/types.html#TermSynchronizeList
+void SVGNumberList::synchronize()
+{
+ // NB: The list does not need to be synchronized with a value that it has just reserialized itself.
+ if (m_is_reserializing)
+ return;
+
+ // 1. Let value be the base value of the reflected content attribute (using the attribute's initial value if it is
+ // not present or invalid).
+ // NB: The initial value of every attribute reflected by an SVGNumberList is the empty list, which is also what an
+ // invalid list of numbers parses to.
+ auto value = parse_table_values(m_element->get_attribute_value(m_reflected_attribute));
+
+ synchronize_items(value, [] { return SVGNumber::create(0, SVGNumber::ReadOnly::No); }, [](GC::Ref<SVGNumber> const& item, float number) { item->set_value_from_reflected_attribute(number); });
+}
+
+// https://svgwg.org/svg2-draft/types.html#TermReserialize
+void SVGNumberList::reserialize_reflected_attribute()
+{
+ // 1. Let elements be the list of values in value.
+ // 2. Let serialized elements be a list of strings, where each string is formed based on the corresponding value in
+ // elements and its type:
+ // an SVGNumber object: The string is an implementation specific string that, if parsed as a <number> using CSS
+ // syntax, would return the number value closest to the SVGNumber object's value member, given the
+ // implementation's supported real number precision.
+ // 3. Set the content attribute to a string consisting of the strings in serialized elements joined and separated by
+ // single U+0020 SPACE characters.
+ Utf16StringBuilder builder;
+ for (size_t index = 0; index < items().size(); ++index) {
+ if (index > 0)
+ builder.append_code_unit(' ');
+ CSS::serialize_a_number(builder, items()[index]->value());
+ }
+
+ TemporaryChange change { m_is_reserializing, true };
+ m_element->set_attribute_value(m_reflected_attribute, builder.to_string());
}
}
diff --git a/Libraries/LibWeb/SVG/SVGNumberList.h b/Libraries/LibWeb/SVG/SVGNumberList.h
index f12d0fae144..c39daf4252b 100644
--- a/Libraries/LibWeb/SVG/SVGNumberList.h
+++ b/Libraries/LibWeb/SVG/SVGNumberList.h
@@ -6,8 +6,9 @@
#pragma once
-#include <LibGC/HeapVector.h>
+#include <AK/Utf16FlyString.h>
#include <LibWeb/Bindings/Wrappable.h>
+#include <LibWeb/Forward.h>
#include <LibWeb/SVG/SVGList.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
@@ -21,17 +22,27 @@ class SVGNumberList final
GC_DECLARE_ALLOCATOR(SVGNumberList);
public:
- using List = GC::HeapVector<GC::Ref<SVGNumber>>;
-
- [[nodiscard]] static GC::Ref<SVGNumberList> create(GC::Ref<List>, ReadOnlyList);
- [[nodiscard]] static GC::Ref<SVGNumberList> create(ReadOnlyList);
+ [[nodiscard]] static GC::Ref<SVGNumberList> create(GC::Ref<SVGElement>, Utf16FlyString reflected_attribute, ReadOnlyList);
virtual ~SVGNumberList() override = default;
+ // https://svgwg.org/svg2-draft/types.html#TermSynchronizeList
+ void synchronize();
+
+ // https://svgwg.org/svg2-draft/types.html#TermReserialize
+ virtual void reserialize_reflected_attribute() override;
+
private:
- SVGNumberList(GC::Ref<List>, ReadOnlyList);
- explicit SVGNumberList(ReadOnlyList);
+ SVGNumberList(GC::Ref<SVGElement>, Utf16FlyString reflected_attribute, ReadOnlyList);
virtual void visit_edges(Visitor&) override;
+
+ virtual void attach(GC::Ref<SVGNumber> const&) override;
+ virtual void detach(GC::Ref<SVGNumber> const&) override;
+ virtual GC::Ref<SVGNumber> copy_if_not_detached(GC::Ref<SVGNumber>) override;
+
+ GC::Ref<SVGElement> m_element;
+ Utf16FlyString m_reflected_attribute;
+ bool m_is_reserializing { false };
};
}
diff --git a/Libraries/LibWeb/SVG/SVGTextPositioningElement.cpp b/Libraries/LibWeb/SVG/SVGTextPositioningElement.cpp
index 5dbfa1f2548..4f69bafa9b8 100644
--- a/Libraries/LibWeb/SVG/SVGTextPositioningElement.cpp
+++ b/Libraries/LibWeb/SVG/SVGTextPositioningElement.cpp
@@ -39,16 +39,17 @@ void SVGTextPositioningElement::attribute_changed(Utf16FlyString const& name, Op
{
Base::attribute_changed(name, old_value, value, namespace_);
- if (name == AttributeNames::x)
- m_x = {};
- else if (name == AttributeNames::y)
- m_y = {};
- else if (name == AttributeNames::dx)
- m_dx = {};
- else if (name == AttributeNames::dy)
- m_dy = {};
- else if (name == AttributeNames::rotate)
- m_rotate = {};
+ // https://svgwg.org/svg2-draft/types.html#SynchronizingReflectedValues
+ if (name == AttributeNames::x && m_x)
+ m_x->synchronize();
+ else if (name == AttributeNames::y && m_y)
+ m_y->synchronize();
+ else if (name == AttributeNames::dx && m_dx)
+ m_dx->synchronize();
+ else if (name == AttributeNames::dy && m_dy)
+ m_dy->synchronize();
+ else if (name == AttributeNames::rotate && m_rotate)
+ m_rotate->synchronize();
}
SVGTextPositioningElement::ParsedTextPositioning SVGTextPositioningElement::parsed_text_positioning() const
@@ -86,70 +87,42 @@ SVGTextPositioningElement::ParsedTextPositioning SVGTextPositioningElement::pars
}
GC::Ref<SVGAnimatedLengthList> SVGTextPositioningElement::ensure_length_list(GC::Ptr<SVGAnimatedLengthList>& list,
- Utf16FlyString const& attribute_name) const
+ Utf16FlyString const& attribute_name, SVGLength::Directionality directionality)
{
- if (!list) {
- // FIXME: This only handles single values, not lists.
- float value = 0.f;
- auto maybe_number_percentage = parse_number_percentage(get_attribute_value(attribute_name));
- if (maybe_number_percentage.has_value())
- value = maybe_number_percentage.release_value().value();
-
- auto length = SVGLength::create_detached(document().relevant_settings_object().realm(), SVGLengthValue::number(value), SVGLength::ReadOnly::Yes);
-
- auto items = GC::Heap::the().allocate<SVGLengthList::List>();
- items->elements().append(length);
-
- auto length_list = SVGLengthList::create(items, ReadOnlyList::Yes);
- list = SVGAnimatedLengthList::create(length_list);
- }
-
+ if (!list)
+ list = SVGAnimatedLengthList::create(*this, attribute_name, directionality);
return *list;
}
// https://svgwg.org/svg2-draft/text.html#__svg__SVGTextPositioningElement__x
GC::Ref<SVGAnimatedLengthList> SVGTextPositioningElement::x()
{
- return ensure_length_list(m_x, AttributeNames::x);
+ return ensure_length_list(m_x, AttributeNames::x, SVGLength::Directionality::Horizontal);
}
// https://svgwg.org/svg2-draft/text.html#__svg__SVGTextPositioningElement__y
GC::Ref<SVGAnimatedLengthList> SVGTextPositioningElement::y()
{
- return ensure_length_list(m_y, AttributeNames::y);
+ return ensure_length_list(m_y, AttributeNames::y, SVGLength::Directionality::Vertical);
}
// https://svgwg.org/svg2-draft/text.html#__svg__SVGTextPositioningElement__dx
GC::Ref<SVGAnimatedLengthList> SVGTextPositioningElement::dx()
{
- return ensure_length_list(m_dx, AttributeNames::dx);
+ return ensure_length_list(m_dx, AttributeNames::dx, SVGLength::Directionality::Horizontal);
}
// https://svgwg.org/svg2-draft/text.html#__svg__SVGTextPositioningElement__dy
GC::Ref<SVGAnimatedLengthList> SVGTextPositioningElement::dy()
{
- return ensure_length_list(m_dy, AttributeNames::dy);
+ return ensure_length_list(m_dy, AttributeNames::dy, SVGLength::Directionality::Vertical);
}
// https://svgwg.org/svg2-draft/text.html#__svg__SVGTextPositioningElement__rotate
GC::Ref<SVGAnimatedNumberList> SVGTextPositioningElement::rotate()
{
- if (!m_rotate) {
- // FIXME: This only handles single values, not lists.
- float value = 0.f;
- auto maybe_number_percentage = parse_number_percentage(get_attribute_value(AttributeNames::rotate));
- if (maybe_number_percentage.has_value() && !maybe_number_percentage.value().is_percentage())
- value = maybe_number_percentage.release_value().value();
-
- auto number = SVGNumber::create(value, SVGNumber::ReadOnly::Yes);
-
- auto items = GC::Heap::the().allocate<SVGNumberList::List>();
- items->elements().append(number);
-
- auto number_list = SVGNumberList::create(items, ReadOnlyList::Yes);
- m_rotate = SVGAnimatedNumberList::create(number_list);
- }
-
+ if (!m_rotate)
+ m_rotate = SVGAnimatedNumberList::create(*this, AttributeNames::rotate);
return *m_rotate;
}
diff --git a/Libraries/LibWeb/SVG/SVGTextPositioningElement.h b/Libraries/LibWeb/SVG/SVGTextPositioningElement.h
index 385cf11b05c..774413d5987 100644
--- a/Libraries/LibWeb/SVG/SVGTextPositioningElement.h
+++ b/Libraries/LibWeb/SVG/SVGTextPositioningElement.h
@@ -42,7 +42,7 @@ protected:
private:
virtual bool is_svg_text_positioning_element() const final { return true; }
- GC::Ref<SVGAnimatedLengthList> ensure_length_list(GC::Ptr<SVGAnimatedLengthList>&, Utf16FlyString const& attribute_name) const;
+ GC::Ref<SVGAnimatedLengthList> ensure_length_list(GC::Ptr<SVGAnimatedLengthList>&, Utf16FlyString const& attribute_name, SVGLength::Directionality);
GC::Ptr<SVGAnimatedLengthList> m_x;
GC::Ptr<SVGAnimatedLengthList> m_y;
diff --git a/Tests/LibWeb/Text/expected/SVG/svg-length-list-indexed-setter.txt b/Tests/LibWeb/Text/expected/SVG/svg-length-list-indexed-setter.txt
index 91bd9b62218..012c2629b67 100644
--- a/Tests/LibWeb/Text/expected/SVG/svg-length-list-indexed-setter.txt
+++ b/Tests/LibWeb/Text/expected/SVG/svg-length-list-indexed-setter.txt
@@ -1,6 +1,5 @@
initial length: 1
initial [0]: 5
same wrapper: true
-existing index: NoModificationAllowedError: Cannot modify a read-only list
-new index: NoModificationAllowedError: Cannot modify a read-only list
+new index: IndexSizeError: List index out of bounds
wrong type: TypeError: Value must be an SVGLength
diff --git a/Tests/LibWeb/Text/expected/SVG/svg-number-list-indexed-setter.txt b/Tests/LibWeb/Text/expected/SVG/svg-number-list-indexed-setter.txt
index 493046505ab..fd82aaf070a 100644
--- a/Tests/LibWeb/Text/expected/SVG/svg-number-list-indexed-setter.txt
+++ b/Tests/LibWeb/Text/expected/SVG/svg-number-list-indexed-setter.txt
@@ -1,6 +1,4 @@
-initial length: 1
-initial [0]: 0
+initial length: 2
+initial [0]: 10
same wrapper: true
-existing index: NoModificationAllowedError: Cannot modify a read-only list
-new index: NoModificationAllowedError: Cannot modify a read-only list
wrong type: TypeError: Value must be an SVGNumber
diff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGList-animVal-reflects-base-value.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGList-animVal-reflects-base-value.txt
index 092f9d16cdd..442f4ec2baf 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGList-animVal-reflects-base-value.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGList-animVal-reflects-base-value.txt
@@ -2,17 +2,17 @@ Harness status: OK
Found 20 tests
-3 Pass
-17 Fail
-Fail SVGNumberList (rotate on text): animVal read before an attribute change reports the new item count
-Fail SVGNumberList (rotate on text): animVal read before an attribute change reports the new value
-Fail SVGNumberList (rotate on text): the animVal list object survives an attribute change
-Fail SVGNumberList (rotate on text): animVal reports the new item count after a baseVal DOM change
+11 Pass
+9 Fail
+Pass SVGNumberList (rotate on text): animVal read before an attribute change reports the new item count
+Pass SVGNumberList (rotate on text): animVal read before an attribute change reports the new value
+Pass SVGNumberList (rotate on text): the animVal list object survives an attribute change
+Pass SVGNumberList (rotate on text): animVal reports the new item count after a baseVal DOM change
Pass SVGNumberList (rotate on text): animVal items are read only
-Fail SVGLengthList (x on text): animVal read before an attribute change reports the new item count
-Fail SVGLengthList (x on text): animVal read before an attribute change reports the new value
-Fail SVGLengthList (x on text): the animVal list object survives an attribute change
-Fail SVGLengthList (x on text): animVal reports the new item count after a baseVal DOM change
+Pass SVGLengthList (x on text): animVal read before an attribute change reports the new item count
+Pass SVGLengthList (x on text): animVal read before an attribute change reports the new value
+Pass SVGLengthList (x on text): the animVal list object survives an attribute change
+Pass SVGLengthList (x on text): animVal reports the new item count after a baseVal DOM change
Pass SVGLengthList (x on text): animVal items are read only
Fail SVGPointList (points on polyline, animatedPoints): animVal read before an attribute change reports the new item count
Fail SVGPointList (points on polyline, animatedPoints): animVal read before an attribute change reports the new value
diff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGList-reflected-attribute-synchronize.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGList-reflected-attribute-synchronize.txt
index 66b2c34550e..bac5eafca29 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGList-reflected-attribute-synchronize.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGList-reflected-attribute-synchronize.txt
@@ -2,28 +2,28 @@ Harness status: OK
Found 59 tests
-6 Pass
-53 Fail
+22 Pass
+37 Fail
Pass SVGNumberList (rotate on text): getItem returns the same object for one index, with no attribute change
-Fail SVGNumberList (rotate on text): a same-count change updates the values of the held items
+Pass SVGNumberList (rotate on text): a same-count change updates the values of the held items
Pass SVGNumberList (rotate on text): a same-count change keeps the held item in the list
-Fail SVGNumberList (rotate on text): the held item is still attached after a same-count change
-Fail SVGNumberList (rotate on text): a grow updates the held item and appends new ones
-Fail SVGNumberList (rotate on text): a shrink updates the held items that are still in range
-Fail SVGNumberList (rotate on text): a shrink detaches the truncated item, which keeps its value
-Fail SVGNumberList (rotate on text): the truncated item stops reaching the element and stops being read only
-Fail SVGNumberList (rotate on text): the list interface object survives the change
-Fail SVGNumberList (rotate on text): an empty string empties the list and detaches every item
+Pass SVGNumberList (rotate on text): the held item is still attached after a same-count change
+Pass SVGNumberList (rotate on text): a grow updates the held item and appends new ones
+Pass SVGNumberList (rotate on text): a shrink updates the held items that are still in range
+Pass SVGNumberList (rotate on text): a shrink detaches the truncated item, which keeps its value
+Pass SVGNumberList (rotate on text): the truncated item stops reaching the element and stops being read only
+Pass SVGNumberList (rotate on text): the list interface object survives the change
+Pass SVGNumberList (rotate on text): an empty string empties the list and detaches every item
Pass SVGLengthList (x on text): getItem returns the same object for one index, with no attribute change
-Fail SVGLengthList (x on text): a same-count change updates the values of the held items
+Pass SVGLengthList (x on text): a same-count change updates the values of the held items
Pass SVGLengthList (x on text): a same-count change keeps the held item in the list
-Fail SVGLengthList (x on text): the held item is still attached after a same-count change
-Fail SVGLengthList (x on text): a grow updates the held item and appends new ones
-Fail SVGLengthList (x on text): a shrink updates the held items that are still in range
-Fail SVGLengthList (x on text): a shrink detaches the truncated item, which keeps its value
-Fail SVGLengthList (x on text): the truncated item stops reaching the element and stops being read only
-Fail SVGLengthList (x on text): the list interface object survives the change
-Fail SVGLengthList (x on text): an empty string empties the list and detaches every item
+Pass SVGLengthList (x on text): the held item is still attached after a same-count change
+Pass SVGLengthList (x on text): a grow updates the held item and appends new ones
+Pass SVGLengthList (x on text): a shrink updates the held items that are still in range
+Pass SVGLengthList (x on text): a shrink detaches the truncated item, which keeps its value
+Pass SVGLengthList (x on text): the truncated item stops reaching the element and stops being read only
+Pass SVGLengthList (x on text): the list interface object survives the change
+Pass SVGLengthList (x on text): an empty string empties the list and detaches every item
Fail SVGPointList (points on polyline): getItem returns the same object for one index, with no attribute change
Fail SVGPointList (points on polyline): a same-count change updates the values of the held items
Fail SVGPointList (points on polyline): a same-count change keeps the held item in the list