Skip to content

Commit caf45f2

Browse files
tcl3shannonbooth
authored andcommitted
LibWeb: Implement the SVGGeometryElement.pathLength attribute
1 parent 410e82c commit caf45f2

File tree

6 files changed

+54
-10
lines changed

6 files changed

+54
-10
lines changed

Libraries/LibWeb/SVG/SVGGeometryElement.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ void SVGGeometryElement::initialize(JS::Realm& realm)
2222
Base::initialize(realm);
2323
}
2424

25+
void SVGGeometryElement::visit_edges(Cell::Visitor& visitor)
26+
{
27+
Base::visit_edges(visitor);
28+
visitor.visit(m_path_length);
29+
}
30+
2531
GC::Ptr<Layout::Node> SVGGeometryElement::create_layout_node(GC::Ref<CSS::ComputedProperties> style)
2632
{
2733
return heap().allocate<Layout::SVGGeometryBox>(document(), *this, move(style));
@@ -38,4 +44,11 @@ GC::Ref<Geometry::DOMPoint> SVGGeometryElement::get_point_at_length(float distan
3844
return Geometry::DOMPoint::construct_impl(realm(), 0, 0, 0, 0);
3945
}
4046

47+
GC::Ref<SVGAnimatedNumber> SVGGeometryElement::path_length()
48+
{
49+
if (!m_path_length)
50+
m_path_length = SVGAnimatedNumber::create(realm(), *this, AttributeNames::pathLength, 0.f);
51+
return *m_path_length;
52+
}
53+
4154
}

Libraries/LibWeb/SVG/SVGGeometryElement.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@ class SVGGeometryElement : public SVGGraphicsElement {
2323
float get_total_length();
2424
GC::Ref<Geometry::DOMPoint> get_point_at_length(float distance);
2525

26+
GC::Ref<SVGAnimatedNumber> path_length();
27+
2628
protected:
2729
SVGGeometryElement(DOM::Document& document, DOM::QualifiedName qualified_name);
2830

2931
virtual void initialize(JS::Realm&) override;
32+
virtual void visit_edges(Cell::Visitor&) override;
33+
34+
private:
35+
GC::Ptr<SVGAnimatedNumber> m_path_length;
3036
};
3137

3238
}

Libraries/LibWeb/SVG/SVGGeometryElement.idl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// https://svgwg.org/svg2-draft/types.html#InterfaceSVGGeometryElement
66
[Exposed=Window]
77
interface SVGGeometryElement : SVGGraphicsElement {
8-
[FIXME, SameObject] readonly attribute SVGAnimatedNumber pathLength;
8+
[SameObject] readonly attribute SVGAnimatedNumber pathLength;
99

1010
[FIXME] boolean isPointInFill(optional DOMPointInit point = {});
1111
[FIXME] boolean isPointInStroke(optional DOMPointInit point = {});

Tests/LibWeb/Text/expected/wpt-import/svg/idlharness.window.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ Harness status: OK
22

33
Found 1781 tests
44

5-
927 Pass
6-
854 Fail
5+
934 Pass
6+
847 Fail
77
Pass idl_test setup
88
Pass idl_test validation
99
Pass Partial interface Document: original interface defined
@@ -80,7 +80,7 @@ Pass SVGGeometryElement interface object name
8080
Pass SVGGeometryElement interface: existence and properties of interface prototype object
8181
Pass SVGGeometryElement interface: existence and properties of interface prototype object's "constructor" property
8282
Pass SVGGeometryElement interface: existence and properties of interface prototype object's @@unscopables property
83-
Fail SVGGeometryElement interface: attribute pathLength
83+
Pass SVGGeometryElement interface: attribute pathLength
8484
Fail SVGGeometryElement interface: operation isPointInFill(optional DOMPointInit)
8585
Fail SVGGeometryElement interface: operation isPointInStroke(optional DOMPointInit)
8686
Pass SVGGeometryElement interface: operation getTotalLength()
@@ -866,7 +866,7 @@ Pass SVGRectElement interface: objects.rect must inherit property "width" with t
866866
Pass SVGRectElement interface: objects.rect must inherit property "height" with the proper type
867867
Pass SVGRectElement interface: objects.rect must inherit property "rx" with the proper type
868868
Pass SVGRectElement interface: objects.rect must inherit property "ry" with the proper type
869-
Fail SVGGeometryElement interface: objects.rect must inherit property "pathLength" with the proper type
869+
Pass SVGGeometryElement interface: objects.rect must inherit property "pathLength" with the proper type
870870
Fail SVGGeometryElement interface: objects.rect must inherit property "isPointInFill(optional DOMPointInit)" with the proper type
871871
Pass SVGGeometryElement interface: calling isPointInFill(optional DOMPointInit) on objects.rect with too few arguments must throw TypeError
872872
Fail SVGGeometryElement interface: objects.rect must inherit property "isPointInStroke(optional DOMPointInit)" with the proper type
@@ -900,7 +900,7 @@ Pass Stringification of objects.circle
900900
Pass SVGCircleElement interface: objects.circle must inherit property "cx" with the proper type
901901
Pass SVGCircleElement interface: objects.circle must inherit property "cy" with the proper type
902902
Pass SVGCircleElement interface: objects.circle must inherit property "r" with the proper type
903-
Fail SVGGeometryElement interface: objects.circle must inherit property "pathLength" with the proper type
903+
Pass SVGGeometryElement interface: objects.circle must inherit property "pathLength" with the proper type
904904
Fail SVGGeometryElement interface: objects.circle must inherit property "isPointInFill(optional DOMPointInit)" with the proper type
905905
Pass SVGGeometryElement interface: calling isPointInFill(optional DOMPointInit) on objects.circle with too few arguments must throw TypeError
906906
Fail SVGGeometryElement interface: objects.circle must inherit property "isPointInStroke(optional DOMPointInit)" with the proper type
@@ -936,7 +936,7 @@ Pass SVGEllipseElement interface: objects.ellipse must inherit property "cx" wit
936936
Pass SVGEllipseElement interface: objects.ellipse must inherit property "cy" with the proper type
937937
Pass SVGEllipseElement interface: objects.ellipse must inherit property "rx" with the proper type
938938
Pass SVGEllipseElement interface: objects.ellipse must inherit property "ry" with the proper type
939-
Fail SVGGeometryElement interface: objects.ellipse must inherit property "pathLength" with the proper type
939+
Pass SVGGeometryElement interface: objects.ellipse must inherit property "pathLength" with the proper type
940940
Fail SVGGeometryElement interface: objects.ellipse must inherit property "isPointInFill(optional DOMPointInit)" with the proper type
941941
Pass SVGGeometryElement interface: calling isPointInFill(optional DOMPointInit) on objects.ellipse with too few arguments must throw TypeError
942942
Fail SVGGeometryElement interface: objects.ellipse must inherit property "isPointInStroke(optional DOMPointInit)" with the proper type
@@ -972,7 +972,7 @@ Pass SVGLineElement interface: objects.line must inherit property "x1" with the
972972
Pass SVGLineElement interface: objects.line must inherit property "y1" with the proper type
973973
Pass SVGLineElement interface: objects.line must inherit property "x2" with the proper type
974974
Pass SVGLineElement interface: objects.line must inherit property "y2" with the proper type
975-
Fail SVGGeometryElement interface: objects.line must inherit property "pathLength" with the proper type
975+
Pass SVGGeometryElement interface: objects.line must inherit property "pathLength" with the proper type
976976
Fail SVGGeometryElement interface: objects.line must inherit property "isPointInFill(optional DOMPointInit)" with the proper type
977977
Pass SVGGeometryElement interface: calling isPointInFill(optional DOMPointInit) on objects.line with too few arguments must throw TypeError
978978
Fail SVGGeometryElement interface: objects.line must inherit property "isPointInStroke(optional DOMPointInit)" with the proper type
@@ -1036,7 +1036,7 @@ Pass SVGPolylineElement must be primary interface of objects.polyline
10361036
Pass Stringification of objects.polyline
10371037
Fail SVGPolylineElement interface: objects.polyline must inherit property "points" with the proper type
10381038
Fail SVGPolylineElement interface: objects.polyline must inherit property "animatedPoints" with the proper type
1039-
Fail SVGGeometryElement interface: objects.polyline must inherit property "pathLength" with the proper type
1039+
Pass SVGGeometryElement interface: objects.polyline must inherit property "pathLength" with the proper type
10401040
Fail SVGGeometryElement interface: objects.polyline must inherit property "isPointInFill(optional DOMPointInit)" with the proper type
10411041
Pass SVGGeometryElement interface: calling isPointInFill(optional DOMPointInit) on objects.polyline with too few arguments must throw TypeError
10421042
Fail SVGGeometryElement interface: objects.polyline must inherit property "isPointInStroke(optional DOMPointInit)" with the proper type
@@ -1068,7 +1068,7 @@ Pass SVGPolygonElement must be primary interface of objects.polygon
10681068
Pass Stringification of objects.polygon
10691069
Fail SVGPolygonElement interface: objects.polygon must inherit property "points" with the proper type
10701070
Fail SVGPolygonElement interface: objects.polygon must inherit property "animatedPoints" with the proper type
1071-
Fail SVGGeometryElement interface: objects.polygon must inherit property "pathLength" with the proper type
1071+
Pass SVGGeometryElement interface: objects.polygon must inherit property "pathLength" with the proper type
10721072
Fail SVGGeometryElement interface: objects.polygon must inherit property "isPointInFill(optional DOMPointInit)" with the proper type
10731073
Pass SVGGeometryElement interface: calling isPointInFill(optional DOMPointInit) on objects.polygon with too few arguments must throw TypeError
10741074
Fail SVGGeometryElement interface: objects.polygon must inherit property "isPointInStroke(optional DOMPointInit)" with the proper type
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Harness status: OK
2+
3+
Found 1 tests
4+
5+
1 Pass
6+
Pass line supports pathLength attribute
Lines changed: 19 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)