DOMRect.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/Geometry/DOMRectReadOnly.h>
  8. namespace Web::Geometry {
  9. // https://drafts.fxtf.org/geometry/#DOMRect
  10. class DOMRect final : public DOMRectReadOnly {
  11. WEB_PLATFORM_OBJECT(DOMRect, DOMRectReadOnly);
  12. JS_DECLARE_ALLOCATOR(DOMRect);
  13. public:
  14. static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRect>> construct_impl(JS::Realm&, double x = 0, double y = 0, double width = 0, double height = 0);
  15. [[nodiscard]] static JS::NonnullGCPtr<DOMRect> create(JS::Realm&, Gfx::FloatRect const&);
  16. [[nodiscard]] static JS::NonnullGCPtr<DOMRect> create(JS::Realm&);
  17. [[nodiscard]] static JS::NonnullGCPtr<DOMRect> from_rect(JS::VM&, DOMRectInit const&);
  18. virtual ~DOMRect() override;
  19. double x() const { return m_rect.x(); }
  20. double y() const { return m_rect.y(); }
  21. double width() const { return m_rect.width(); }
  22. double height() const { return m_rect.height(); }
  23. void set_x(double x) { m_rect.set_x(x); }
  24. void set_y(double y) { m_rect.set_y(y); }
  25. void set_width(double width) { m_rect.set_width(width); }
  26. void set_height(double height) { m_rect.set_height(height); }
  27. virtual StringView interface_name() const override { return "DOMRect"sv; }
  28. private:
  29. DOMRect(JS::Realm&, double x, double y, double width, double height);
  30. explicit DOMRect(JS::Realm&);
  31. virtual void initialize(JS::Realm&) override;
  32. };
  33. }