/src/serenity/Userland/Libraries/LibWeb/SVG/SVGLength.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <LibWeb/Bindings/PlatformObject.h> |
10 | | #include <LibWeb/WebIDL/ExceptionOr.h> |
11 | | |
12 | | namespace Web::SVG { |
13 | | |
14 | | // https://www.w3.org/TR/SVG11/types.html#InterfaceSVGLength |
15 | | class SVGLength : public Bindings::PlatformObject { |
16 | | WEB_PLATFORM_OBJECT(SVGLength, Bindings::PlatformObject); |
17 | | JS_DECLARE_ALLOCATOR(SVGLength); |
18 | | |
19 | | public: |
20 | | // Same as SVGLength.idl |
21 | | static constexpr unsigned short SVG_LENGTHTYPE_UNKNOWN = 0; |
22 | | static constexpr unsigned short SVG_LENGTHTYPE_NUMBER = 1; |
23 | | static constexpr unsigned short SVG_LENGTHTYPE_PERCENTAGE = 2; |
24 | | static constexpr unsigned short SVG_LENGTHTYPE_EMS = 3; |
25 | | static constexpr unsigned short SVG_LENGTHTYPE_EXS = 4; |
26 | | static constexpr unsigned short SVG_LENGTHTYPE_PX = 5; |
27 | | static constexpr unsigned short SVG_LENGTHTYPE_CM = 6; |
28 | | static constexpr unsigned short SVG_LENGTHTYPE_MM = 7; |
29 | | static constexpr unsigned short SVG_LENGTHTYPE_IN = 8; |
30 | | static constexpr unsigned short SVG_LENGTHTYPE_PT = 9; |
31 | | static constexpr unsigned short SVG_LENGTHTYPE_PC = 10; |
32 | | |
33 | | [[nodiscard]] static JS::NonnullGCPtr<SVGLength> create(JS::Realm&, u8 unit_type, float value); |
34 | | virtual ~SVGLength() override; |
35 | | |
36 | 0 | u8 unit_type() const { return m_unit_type; } |
37 | | |
38 | 0 | float value() const { return m_value; } |
39 | | WebIDL::ExceptionOr<void> set_value(float value); |
40 | | |
41 | | [[nodiscard]] static JS::NonnullGCPtr<SVGLength> from_length_percentage(JS::Realm&, CSS::LengthPercentage const&); |
42 | | |
43 | | private: |
44 | | SVGLength(JS::Realm&, u8 unit_type, float value); |
45 | | |
46 | | virtual void initialize(JS::Realm&) override; |
47 | | |
48 | | u8 m_unit_type { 0 }; |
49 | | float m_value { 0 }; |
50 | | }; |
51 | | |
52 | | } |