DOMPointReadOnly.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
  4. * Copyright (c) 2024, Kenneth Myhra <kennethmyhra@serenityos.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <LibGfx/Point.h>
  10. #include <LibWeb/Bindings/PlatformObject.h>
  11. #include <LibWeb/Bindings/Serializable.h>
  12. #include <LibWeb/Forward.h>
  13. namespace Web::Geometry {
  14. struct DOMPointInit {
  15. double x { 0 };
  16. double y { 0 };
  17. double z { 0 };
  18. double w { 1 };
  19. };
  20. // https://drafts.fxtf.org/geometry/#dompointreadonly
  21. class DOMPointReadOnly
  22. : public Bindings::PlatformObject
  23. , public Bindings::Serializable {
  24. WEB_PLATFORM_OBJECT(DOMPointReadOnly, Bindings::PlatformObject);
  25. JS_DECLARE_ALLOCATOR(DOMPointReadOnly);
  26. public:
  27. static JS::NonnullGCPtr<DOMPointReadOnly> construct_impl(JS::Realm&, double x = 0, double y = 0, double z = 0, double w = 1);
  28. static JS::NonnullGCPtr<DOMPointReadOnly> create(JS::Realm&);
  29. static JS::NonnullGCPtr<DOMPointReadOnly> from_point(JS::VM&, DOMPointInit const&);
  30. virtual ~DOMPointReadOnly() override;
  31. double x() const { return m_x; }
  32. double y() const { return m_y; }
  33. double z() const { return m_z; }
  34. double w() const { return m_w; }
  35. WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMPoint>> matrix_transform(DOMMatrixInit&) const;
  36. virtual StringView interface_name() const override { return "DOMPointReadOnly"sv; }
  37. virtual WebIDL::ExceptionOr<void> serialization_steps(HTML::SerializationRecord&, bool for_storage, HTML::SerializationMemory&) override;
  38. virtual WebIDL::ExceptionOr<void> deserialization_steps(ReadonlySpan<u32> const&, size_t& position, HTML::DeserializationMemory&) override;
  39. protected:
  40. DOMPointReadOnly(JS::Realm&, double x, double y, double z, double w);
  41. explicit DOMPointReadOnly(JS::Realm&);
  42. virtual void initialize(JS::Realm&) override;
  43. double m_x;
  44. double m_y;
  45. double m_z;
  46. double m_w;
  47. };
  48. }