Skip to content

Commit b51ea3a

Browse files
AtkinsSJawesomekling
authored andcommitted
LibWeb: Expose SVGLineElement attributes to JS
1 parent b5ef900 commit b51ea3a

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

Userland/Libraries/LibWeb/SVG/SVGLineElement.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,44 @@ Gfx::Path& SVGLineElement::get_path()
5555
return m_path.value();
5656
}
5757

58+
// https://www.w3.org/TR/SVG11/shapes.html#LineElementX1Attribute
59+
NonnullRefPtr<SVGAnimatedLength> SVGLineElement::x1() const
60+
{
61+
// FIXME: Populate the unit type when it is parsed (0 here is "unknown").
62+
// FIXME: Create a proper animated value when animations are supported.
63+
auto base_length = SVGLength::create(0, m_x1.value_or(0));
64+
auto anim_length = SVGLength::create(0, m_x1.value_or(0));
65+
return SVGAnimatedLength::create(move(base_length), move(anim_length));
66+
}
67+
68+
// https://www.w3.org/TR/SVG11/shapes.html#LineElementY1Attribute
69+
NonnullRefPtr<SVGAnimatedLength> SVGLineElement::y1() const
70+
{
71+
// FIXME: Populate the unit type when it is parsed (0 here is "unknown").
72+
// FIXME: Create a proper animated value when animations are supported.
73+
auto base_length = SVGLength::create(0, m_y1.value_or(0));
74+
auto anim_length = SVGLength::create(0, m_y1.value_or(0));
75+
return SVGAnimatedLength::create(move(base_length), move(anim_length));
76+
}
77+
78+
// https://www.w3.org/TR/SVG11/shapes.html#LineElementX2Attribute
79+
NonnullRefPtr<SVGAnimatedLength> SVGLineElement::x2() const
80+
{
81+
// FIXME: Populate the unit type when it is parsed (0 here is "unknown").
82+
// FIXME: Create a proper animated value when animations are supported.
83+
auto base_length = SVGLength::create(0, m_x2.value_or(0));
84+
auto anim_length = SVGLength::create(0, m_x2.value_or(0));
85+
return SVGAnimatedLength::create(move(base_length), move(anim_length));
86+
}
87+
88+
// https://www.w3.org/TR/SVG11/shapes.html#LineElementY2Attribute
89+
NonnullRefPtr<SVGAnimatedLength> SVGLineElement::y2() const
90+
{
91+
// FIXME: Populate the unit type when it is parsed (0 here is "unknown").
92+
// FIXME: Create a proper animated value when animations are supported.
93+
auto base_length = SVGLength::create(0, m_y2.value_or(0));
94+
auto anim_length = SVGLength::create(0, m_y2.value_or(0));
95+
return SVGAnimatedLength::create(move(base_length), move(anim_length));
96+
}
97+
5898
}

Userland/Libraries/LibWeb/SVG/SVGLineElement.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#pragma once
88

9+
#include <LibWeb/SVG/SVGAnimatedLength.h>
910
#include <LibWeb/SVG/SVGGeometryElement.h>
1011

1112
namespace Web::SVG {
@@ -21,6 +22,11 @@ class SVGLineElement final : public SVGGeometryElement {
2122

2223
virtual Gfx::Path& get_path() override;
2324

25+
NonnullRefPtr<SVGAnimatedLength> x1() const;
26+
NonnullRefPtr<SVGAnimatedLength> y1() const;
27+
NonnullRefPtr<SVGAnimatedLength> x2() const;
28+
NonnullRefPtr<SVGAnimatedLength> y2() const;
29+
2430
private:
2531
Optional<Gfx::Path> m_path;
2632

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
#import <SVG/SVGAnimatedLength.idl>
12
#import <SVG/SVGGeometryElement.idl>
23

34
[Exposed=Window]
45
interface SVGLineElement : SVGGeometryElement {
5-
// [SameObject] readonly attribute SVGAnimatedLength x1;
6-
// [SameObject] readonly attribute SVGAnimatedLength y1;
7-
// [SameObject] readonly attribute SVGAnimatedLength x2;
8-
// [SameObject] readonly attribute SVGAnimatedLength y2;
6+
[SameObject] readonly attribute SVGAnimatedLength x1;
7+
[SameObject] readonly attribute SVGAnimatedLength y1;
8+
[SameObject] readonly attribute SVGAnimatedLength x2;
9+
[SameObject] readonly attribute SVGAnimatedLength y2;
910
};

0 commit comments

Comments
 (0)