Skip to content

Truly independent web browser

LibWeb: Reflect the textLength attribute of SVGTextContentElement

Andreas Klinga3cca9199f66
diff --git a/Libraries/LibWeb/SVG/SVGTextContentElement.h b/Libraries/LibWeb/SVG/SVGTextContentElement.h
index 987377d2976..19f0635c69d 100644
--- a/Libraries/LibWeb/SVG/SVGTextContentElement.h
+++ b/Libraries/LibWeb/SVG/SVGTextContentElement.h
@@ -9,6 +9,7 @@
#include <LibWeb/Geometry/DOMPoint.h>
#include <LibWeb/Geometry/DOMRect.h>
#include <LibWeb/Layout/LayoutRustFFI.h>
+#include <LibWeb/SVG/AttributeNames.h>
#include <LibWeb/SVG/AttributeParsing.h>
#include <LibWeb/SVG/SVGGraphicsElement.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
@@ -27,6 +28,12 @@ public:
GC::Ref<SVGAnimatedEnumeration> length_adjust();
+ // https://svgwg.org/svg2-draft/text.html#__svg__SVGTextContentElement__textLength
+ // The initial value of the ‘textLength’ content attribute is defined to equal the user-agent's calculated length
+ // for the element.
+ // FIXME: Use the calculated length of the element as the initial value, rather than 0.
+ REFLECT_ANIMATED_LENGTH_ATTRIBUTE_WITH_GETTER(textLength, text_length, Horizontal, SVGLengthValue::number(0));
+
WebIDL::ExceptionOr<WebIDL::Long> get_number_of_chars();
WebIDL::ExceptionOr<float> get_computed_text_length();
WebIDL::ExceptionOr<float> get_sub_string_length(WebIDL::UnsignedLong charnum, WebIDL::UnsignedLong nchars);
diff --git a/Libraries/LibWeb/SVG/SVGTextContentElement.idl b/Libraries/LibWeb/SVG/SVGTextContentElement.idl
index 7afa1434dcf..c0e1c5996fd 100644
--- a/Libraries/LibWeb/SVG/SVGTextContentElement.idl
+++ b/Libraries/LibWeb/SVG/SVGTextContentElement.idl
@@ -7,7 +7,7 @@ interface SVGTextContentElement : SVGGraphicsElement {
const unsigned short LENGTHADJUST_SPACING = 1;
const unsigned short LENGTHADJUST_SPACINGANDGLYPHS = 2;
- [FIXME, SameObject] readonly attribute SVGAnimatedLength textLength;
+ [SameObject] readonly attribute SVGAnimatedLength textLength;
[SameObject] readonly attribute SVGAnimatedEnumeration lengthAdjust;
long getNumberOfChars();
diff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/idlharness.window.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/idlharness.window.txt
index 0b78220f32f..3a1ba2b7e6f 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/svg/idlharness.window.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/idlharness.window.txt
@@ -2,8 +2,8 @@ Harness status: OK
Found 1780 tests
-1582 Pass
-198 Fail
+1586 Pass
+194 Fail
Pass idl_test setup
Pass idl_test validation
Pass Partial interface Document: original interface defined
@@ -1104,7 +1104,7 @@ Pass SVGTextContentElement interface: constant LENGTHADJUST_SPACING on interface
Pass SVGTextContentElement interface: constant LENGTHADJUST_SPACING on interface prototype object
Pass SVGTextContentElement interface: constant LENGTHADJUST_SPACINGANDGLYPHS on interface object
Pass SVGTextContentElement interface: constant LENGTHADJUST_SPACINGANDGLYPHS on interface prototype object
-Fail SVGTextContentElement interface: attribute textLength
+Pass SVGTextContentElement interface: attribute textLength
Pass SVGTextContentElement interface: attribute lengthAdjust
Pass SVGTextContentElement interface: operation getNumberOfChars()
Pass SVGTextContentElement interface: operation getComputedTextLength()
@@ -1142,7 +1142,7 @@ Pass SVGTextPositioningElement interface: objects.text must inherit property "ro
Pass SVGTextContentElement interface: objects.text must inherit property "LENGTHADJUST_UNKNOWN" with the proper type
Pass SVGTextContentElement interface: objects.text must inherit property "LENGTHADJUST_SPACING" with the proper type
Pass SVGTextContentElement interface: objects.text must inherit property "LENGTHADJUST_SPACINGANDGLYPHS" with the proper type
-Fail SVGTextContentElement interface: objects.text must inherit property "textLength" with the proper type
+Pass SVGTextContentElement interface: objects.text must inherit property "textLength" with the proper type
Pass SVGTextContentElement interface: objects.text must inherit property "lengthAdjust" with the proper type
Pass SVGTextContentElement interface: objects.text must inherit property "getNumberOfChars()" with the proper type
Pass SVGTextContentElement interface: objects.text must inherit property "getComputedTextLength()" with the proper type
@@ -1188,7 +1188,7 @@ Pass SVGTextPositioningElement interface: objects.tspan must inherit property "r
Pass SVGTextContentElement interface: objects.tspan must inherit property "LENGTHADJUST_UNKNOWN" with the proper type
Pass SVGTextContentElement interface: objects.tspan must inherit property "LENGTHADJUST_SPACING" with the proper type
Pass SVGTextContentElement interface: objects.tspan must inherit property "LENGTHADJUST_SPACINGANDGLYPHS" with the proper type
-Fail SVGTextContentElement interface: objects.tspan must inherit property "textLength" with the proper type
+Pass SVGTextContentElement interface: objects.tspan must inherit property "textLength" with the proper type
Pass SVGTextContentElement interface: objects.tspan must inherit property "lengthAdjust" with the proper type
Pass SVGTextContentElement interface: objects.tspan must inherit property "getNumberOfChars()" with the proper type
Pass SVGTextContentElement interface: objects.tspan must inherit property "getComputedTextLength()" with the proper type
@@ -1255,7 +1255,7 @@ Pass SVGTextPathElement interface: objects.textPath must inherit property "href"
Pass SVGTextContentElement interface: objects.textPath must inherit property "LENGTHADJUST_UNKNOWN" with the proper type
Pass SVGTextContentElement interface: objects.textPath must inherit property "LENGTHADJUST_SPACING" with the proper type
Pass SVGTextContentElement interface: objects.textPath must inherit property "LENGTHADJUST_SPACINGANDGLYPHS" with the proper type
-Fail SVGTextContentElement interface: objects.textPath must inherit property "textLength" with the proper type
+Pass SVGTextContentElement interface: objects.textPath must inherit property "textLength" with the proper type
Pass SVGTextContentElement interface: objects.textPath must inherit property "lengthAdjust" with the proper type
Pass SVGTextContentElement interface: objects.textPath must inherit property "getNumberOfChars()" with the proper type
Pass SVGTextContentElement interface: objects.textPath must inherit property "getComputedTextLength()" with the proper type
diff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGAnimatedLength-initial-values.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGAnimatedLength-initial-values.txt
index ea272a12363..21c418af098 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGAnimatedLength-initial-values.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGAnimatedLength-initial-values.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 130 tests
-128 Pass
-2 Fail
+130 Pass
Pass SVGAnimatedLength, initial values, SVGCircleElement.prototype.cx (remove)
Pass SVGAnimatedLength, initial values, SVGCircleElement.prototype.cx (invalid value)
Pass SVGAnimatedLength, initial values, SVGCircleElement.prototype.cy (remove)
@@ -122,8 +121,8 @@ Pass SVGAnimatedLength, initial values, SVGSVGElement.prototype.width (remove)
Pass SVGAnimatedLength, initial values, SVGSVGElement.prototype.width (invalid value)
Pass SVGAnimatedLength, initial values, SVGSVGElement.prototype.height (remove)
Pass SVGAnimatedLength, initial values, SVGSVGElement.prototype.height (invalid value)
-Fail SVGAnimatedLength, initial values, SVGTextContentElement.prototype.textLength (remove)
-Fail SVGAnimatedLength, initial values, SVGTextContentElement.prototype.textLength (invalid value)
+Pass SVGAnimatedLength, initial values, SVGTextContentElement.prototype.textLength (remove)
+Pass SVGAnimatedLength, initial values, SVGTextContentElement.prototype.textLength (invalid value)
Pass SVGAnimatedLength, initial values, SVGTextPathElement.prototype.startOffset (remove)
Pass SVGAnimatedLength, initial values, SVGTextPathElement.prototype.startOffset (invalid value)
Pass SVGAnimatedLength, initial values, SVGUseElement.prototype.x (remove)