DOMRect.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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
  11. : public DOMRectReadOnly {
  12. public:
  13. using WrapperType = Bindings::DOMRectWrapper;
  14. static NonnullRefPtr<DOMRect> create_with_global_object(Bindings::WindowObject&, double x = 0, double y = 0, double width = 0, double height = 0)
  15. {
  16. return DOMRect::create(x, y, width, height);
  17. }
  18. static NonnullRefPtr<DOMRect> create(double x = 0, double y = 0, double width = 0, double height = 0)
  19. {
  20. return adopt_ref(*new DOMRect(x, y, width, height));
  21. }
  22. static NonnullRefPtr<DOMRect> create(Gfx::FloatRect const& rect)
  23. {
  24. return adopt_ref(*new DOMRect(rect.x(), rect.y(), rect.width(), rect.height()));
  25. }
  26. double x() const { return m_rect.x(); }
  27. double y() const { return m_rect.y(); }
  28. double width() const { return m_rect.width(); }
  29. double height() const { return m_rect.height(); }
  30. void set_x(double x) { m_rect.set_x(x); }
  31. void set_y(double y) { m_rect.set_y(y); }
  32. void set_width(double width) { m_rect.set_width(width); }
  33. void set_height(double height) { m_rect.set_height(height); }
  34. private:
  35. DOMRect(float x, float y, float width, float height)
  36. : DOMRectReadOnly(x, y, width, height)
  37. {
  38. }
  39. };
  40. }