SVGLength.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/Bindings/PlatformObject.h>
  8. #include <LibWeb/WebIDL/ExceptionOr.h>
  9. namespace Web::SVG {
  10. // https://www.w3.org/TR/SVG11/types.html#InterfaceSVGLength
  11. class SVGLength : public Bindings::PlatformObject {
  12. WEB_PLATFORM_OBJECT(SVGLength, Bindings::PlatformObject);
  13. JS_DECLARE_ALLOCATOR(SVGLength);
  14. public:
  15. [[nodiscard]] static JS::NonnullGCPtr<SVGLength> create(JS::Realm&, u8 unit_type, float value);
  16. virtual ~SVGLength() override;
  17. u8 unit_type() const { return m_unit_type; }
  18. float value() const { return m_value; }
  19. WebIDL::ExceptionOr<void> set_value(float value);
  20. [[nodiscard]] static JS::NonnullGCPtr<SVGLength> from_length_percentage(JS::Realm&, CSS::LengthPercentage const&);
  21. private:
  22. SVGLength(JS::Realm&, u8 unit_type, float value);
  23. virtual void initialize(JS::Realm&) override;
  24. u8 m_unit_type { 0 };
  25. float m_value { 0 };
  26. };
  27. }