summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-03-22 16:31:52 +0000
committerAndreas Kling <kling@serenityos.org>2022-03-22 22:33:17 +0100
commitb51ea3a67c640a564740438ceb19f9c7e0bb516e (patch)
tree81afdb28e656bb211a91d5ff38a0bd378582796a /Userland/Libraries
parentb5ef900ccde41dd8bf922eeae8ebdcc964539f46 (diff)
downloadserenity-b51ea3a67c640a564740438ceb19f9c7e0bb516e.zip
LibWeb: Expose SVGLineElement attributes to JS
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/SVG/SVGLineElement.cpp40
-rw-r--r--Userland/Libraries/LibWeb/SVG/SVGLineElement.h6
-rw-r--r--Userland/Libraries/LibWeb/SVG/SVGLineElement.idl9
3 files changed, 51 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWeb/SVG/SVGLineElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGLineElement.cpp
index 2eada4e70c..cb40d5c9f7 100644
--- a/Userland/Libraries/LibWeb/SVG/SVGLineElement.cpp
+++ b/Userland/Libraries/LibWeb/SVG/SVGLineElement.cpp
@@ -55,4 +55,44 @@ Gfx::Path& SVGLineElement::get_path()
return m_path.value();
}
+// https://www.w3.org/TR/SVG11/shapes.html#LineElementX1Attribute
+NonnullRefPtr<SVGAnimatedLength> SVGLineElement::x1() const
+{
+ // FIXME: Populate the unit type when it is parsed (0 here is "unknown").
+ // FIXME: Create a proper animated value when animations are supported.
+ auto base_length = SVGLength::create(0, m_x1.value_or(0));
+ auto anim_length = SVGLength::create(0, m_x1.value_or(0));
+ return SVGAnimatedLength::create(move(base_length), move(anim_length));
+}
+
+// https://www.w3.org/TR/SVG11/shapes.html#LineElementY1Attribute
+NonnullRefPtr<SVGAnimatedLength> SVGLineElement::y1() const
+{
+ // FIXME: Populate the unit type when it is parsed (0 here is "unknown").
+ // FIXME: Create a proper animated value when animations are supported.
+ auto base_length = SVGLength::create(0, m_y1.value_or(0));
+ auto anim_length = SVGLength::create(0, m_y1.value_or(0));
+ return SVGAnimatedLength::create(move(base_length), move(anim_length));
+}
+
+// https://www.w3.org/TR/SVG11/shapes.html#LineElementX2Attribute
+NonnullRefPtr<SVGAnimatedLength> SVGLineElement::x2() const
+{
+ // FIXME: Populate the unit type when it is parsed (0 here is "unknown").
+ // FIXME: Create a proper animated value when animations are supported.
+ auto base_length = SVGLength::create(0, m_x2.value_or(0));
+ auto anim_length = SVGLength::create(0, m_x2.value_or(0));
+ return SVGAnimatedLength::create(move(base_length), move(anim_length));
+}
+
+// https://www.w3.org/TR/SVG11/shapes.html#LineElementY2Attribute
+NonnullRefPtr<SVGAnimatedLength> SVGLineElement::y2() const
+{
+ // FIXME: Populate the unit type when it is parsed (0 here is "unknown").
+ // FIXME: Create a proper animated value when animations are supported.
+ auto base_length = SVGLength::create(0, m_y2.value_or(0));
+ auto anim_length = SVGLength::create(0, m_y2.value_or(0));
+ return SVGAnimatedLength::create(move(base_length), move(anim_length));
+}
+
}
diff --git a/Userland/Libraries/LibWeb/SVG/SVGLineElement.h b/Userland/Libraries/LibWeb/SVG/SVGLineElement.h
index ba476efdaa..6078272d0a 100644
--- a/Userland/Libraries/LibWeb/SVG/SVGLineElement.h
+++ b/Userland/Libraries/LibWeb/SVG/SVGLineElement.h
@@ -6,6 +6,7 @@
#pragma once
+#include <LibWeb/SVG/SVGAnimatedLength.h>
#include <LibWeb/SVG/SVGGeometryElement.h>
namespace Web::SVG {
@@ -21,6 +22,11 @@ public:
virtual Gfx::Path& get_path() override;
+ NonnullRefPtr<SVGAnimatedLength> x1() const;
+ NonnullRefPtr<SVGAnimatedLength> y1() const;
+ NonnullRefPtr<SVGAnimatedLength> x2() const;
+ NonnullRefPtr<SVGAnimatedLength> y2() const;
+
private:
Optional<Gfx::Path> m_path;
diff --git a/Userland/Libraries/LibWeb/SVG/SVGLineElement.idl b/Userland/Libraries/LibWeb/SVG/SVGLineElement.idl
index 76f38a7201..9f68b9b771 100644
--- a/Userland/Libraries/LibWeb/SVG/SVGLineElement.idl
+++ b/Userland/Libraries/LibWeb/SVG/SVGLineElement.idl
@@ -1,9 +1,10 @@
+#import <SVG/SVGAnimatedLength.idl>
#import <SVG/SVGGeometryElement.idl>
[Exposed=Window]
interface SVGLineElement : SVGGeometryElement {
- // [SameObject] readonly attribute SVGAnimatedLength x1;
- // [SameObject] readonly attribute SVGAnimatedLength y1;
- // [SameObject] readonly attribute SVGAnimatedLength x2;
- // [SameObject] readonly attribute SVGAnimatedLength y2;
+ [SameObject] readonly attribute SVGAnimatedLength x1;
+ [SameObject] readonly attribute SVGAnimatedLength y1;
+ [SameObject] readonly attribute SVGAnimatedLength x2;
+ [SameObject] readonly attribute SVGAnimatedLength y2;
};