diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-03-21 14:20:48 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-21 21:04:39 +0100 |
commit | ebf3829f1cfc7f19f53bae46a42fcf130952250c (patch) | |
tree | b95e8ba3298e90c7960a0f5a8d1b0f6b4a233dab /Userland/Libraries/LibWeb/SVG | |
parent | 3ebc5cc58e82aa9fe31cf371dab80112454e1ac0 (diff) | |
download | serenity-ebf3829f1cfc7f19f53bae46a42fcf130952250c.zip |
LibWeb: Begin implementing the SVGLength type
There are a few unimplemented features for this type:
1. The value setter should throw a DOMException if it is invoked on an
SVGLength that was declared readonly in another IDL file.
2. SVG::AttributeParser does not parse unit types when it parses lengths
so all SVGLength will have an "unknown" unit for now.
3. Due to (2), methods which convert between units are unimplemented.
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); +}; |