DOMRectReadOnly.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibGfx/Rect.h>
  8. #include <LibWeb/Bindings/PlatformObject.h>
  9. #include <LibWeb/Forward.h>
  10. namespace Web::Geometry {
  11. // https://drafts.fxtf.org/geometry/#domrectreadonly
  12. class DOMRectReadOnly : public Bindings::PlatformObject {
  13. WEB_PLATFORM_OBJECT(DOMRectReadOnly, Bindings::PlatformObject);
  14. public:
  15. static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRectReadOnly>> construct_impl(JS::Realm&, double x = 0, double y = 0, double width = 0, double height = 0);
  16. virtual ~DOMRectReadOnly() override;
  17. double x() const { return m_rect.x(); }
  18. double y() const { return m_rect.y(); }
  19. double width() const { return m_rect.width(); }
  20. double height() const { return m_rect.height(); }
  21. double top() const { return min(y(), y() + height()); }
  22. double right() const { return max(x(), x() + width()); }
  23. double bottom() const { return max(y(), y() + height()); }
  24. double left() const { return min(x(), x() + width()); }
  25. protected:
  26. DOMRectReadOnly(JS::Realm&, double x, double y, double width, double height);
  27. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  28. Gfx::FloatRect m_rect;
  29. };
  30. }