diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index e5895b71acc..aabfab54be5 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -317,6 +317,7 @@ set(SOURCES SVG/SVGPathElement.cpp SVG/SVGCircleElement.cpp SVG/SVGEllipseElement.cpp + SVG/SVGLength.cpp SVG/SVGLineElement.cpp SVG/SVGPolygonElement.cpp SVG/SVGPolylineElement.cpp @@ -575,6 +576,7 @@ libweb_js_wrapper(SVG/SVGGeometryElement) libweb_js_wrapper(SVG/SVGGraphicsElement) libweb_js_wrapper(SVG/SVGCircleElement) libweb_js_wrapper(SVG/SVGEllipseElement) +libweb_js_wrapper(SVG/SVGLength) libweb_js_wrapper(SVG/SVGLineElement) libweb_js_wrapper(SVG/SVGPathElement) libweb_js_wrapper(SVG/SVGPolygonElement) diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 42de3509cca..0749d21b6cf 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -291,6 +291,7 @@ class SVGElement; class SVGEllipseElement; class SVGGeometryElement; class SVGGraphicsElement; +class SVGLength; class SVGLineElement; class SVGPathElement; class SVGPolygonElement; @@ -514,6 +515,7 @@ class SVGElementWrapper; class SVGEllipseElementWrapper; class SVGGeometryElementWrapper; class SVGGraphicsElementWrapper; +class SVGLengthWrapper; class SVGLineElementWrapper; class SVGPathElementWrapper; class SVGPolygonElementWrapper; diff --git a/Userland/Libraries/LibWeb/SVG/SVGLength.cpp b/Userland/Libraries/LibWeb/SVG/SVGLength.cpp new file mode 100644 index 00000000000..11c3865479d --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGLength.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022, Tim Flynn + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +namespace Web::SVG { + +NonnullRefPtr SVGLength::create(u8 unit_type, float value) +{ + return adopt_ref(*new SVGLength(unit_type, value)); +} + +SVGLength::SVGLength(u8 unit_type, float value) + : m_unit_type(unit_type) + , m_value(value) +{ +} + +// https://www.w3.org/TR/SVG11/types.html#__svg__SVGLength__value +DOM::ExceptionOr SVGLength::set_value(float value) +{ + // FIXME: Raise an exception if this is read-only. + m_value = value; + return {}; +} + +} diff --git a/Userland/Libraries/LibWeb/SVG/SVGLength.h b/Userland/Libraries/LibWeb/SVG/SVGLength.h new file mode 100644 index 00000000000..9e838775ebd --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGLength.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022, Tim Flynn + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace Web::SVG { + +// https://www.w3.org/TR/SVG11/types.html#InterfaceSVGLength +class SVGLength + : public RefCounted + , public Bindings::Wrappable + , public Weakable { +public: + using WrapperType = Bindings::SVGLengthWrapper; + + static NonnullRefPtr create(u8 unit_type, float value); + virtual ~SVGLength() = default; + + u8 unit_type() const { return m_unit_type; } + + float value() const { return m_value; } + DOM::ExceptionOr set_value(float value); + +private: + SVGLength(u8 unit_type, float value); + + u8 m_unit_type { 0 }; + float m_value { 0 }; +}; + +} diff --git a/Userland/Libraries/LibWeb/SVG/SVGLength.idl b/Userland/Libraries/LibWeb/SVG/SVGLength.idl new file mode 100644 index 00000000000..08e4e29e856 --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGLength.idl @@ -0,0 +1,24 @@ +interface SVGLength { + const unsigned short SVG_LENGTHTYPE_UNKNOWN = 0; + const unsigned short SVG_LENGTHTYPE_NUMBER = 1; + const unsigned short SVG_LENGTHTYPE_PERCENTAGE = 2; + const unsigned short SVG_LENGTHTYPE_EMS = 3; + const unsigned short SVG_LENGTHTYPE_EXS = 4; + const unsigned short SVG_LENGTHTYPE_PX = 5; + const unsigned short SVG_LENGTHTYPE_CM = 6; + const unsigned short SVG_LENGTHTYPE_MM = 7; + const unsigned short SVG_LENGTHTYPE_IN = 8; + const unsigned short SVG_LENGTHTYPE_PT = 9; + const unsigned short SVG_LENGTHTYPE_PC = 10; + + readonly attribute unsigned short unitType; + + // FIXME: Support setraises(). + attribute float value; // setraises(DOMException); + + // attribute float valueInSpecifiedUnits setraises(DOMException); + // attribute DOMString valueAsString setraises(DOMException); + + // void newValueSpecifiedUnits(in unsigned short unitType, in float valueInSpecifiedUnits) raises(DOMException); + // void convertToSpecifiedUnits(in unsigned short unitType) raises(DOMException); +};