diff options
Diffstat (limited to 'Userland/Libraries/LibWeb/SVG')
-rw-r--r-- | Userland/Libraries/LibWeb/SVG/SVGLength.cpp | 30 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/SVG/SVGLength.h | 40 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/SVG/SVGLength.idl | 24 |
3 files changed, 94 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/SVG/SVGLength.cpp b/Userland/Libraries/LibWeb/SVG/SVGLength.cpp new file mode 100644 index 0000000000..11c3865479 --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGLength.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <LibWeb/SVG/SVGLength.h> + +namespace Web::SVG { + +NonnullRefPtr<SVGLength> 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<void> SVGLength::set_value(float value) +{ + // FIXME: Raise an exception if this <length> 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 0000000000..9e838775eb --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGLength.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/RefCounted.h> +#include <AK/Types.h> +#include <AK/Weakable.h> +#include <LibWeb/Bindings/Wrappable.h> +#include <LibWeb/DOM/ExceptionOr.h> + +namespace Web::SVG { + +// https://www.w3.org/TR/SVG11/types.html#InterfaceSVGLength +class SVGLength + : public RefCounted<SVGLength> + , public Bindings::Wrappable + , public Weakable<SVGLength> { +public: + using WrapperType = Bindings::SVGLengthWrapper; + + static NonnullRefPtr<SVGLength> 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<void> 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 0000000000..08e4e29e85 --- /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); +}; |