DOMRect.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/DOMRectPrototype.h>
  7. #include <LibWeb/Bindings/Intrinsics.h>
  8. #include <LibWeb/Geometry/DOMRect.h>
  9. #include <LibWeb/WebIDL/ExceptionOr.h>
  10. namespace Web::Geometry {
  11. GC_DEFINE_ALLOCATOR(DOMRect);
  12. WebIDL::ExceptionOr<GC::Ref<DOMRect>> DOMRect::construct_impl(JS::Realm& realm, double x, double y, double width, double height)
  13. {
  14. return create(realm, Gfx::FloatRect { x, y, width, height });
  15. }
  16. GC::Ref<DOMRect> DOMRect::create(JS::Realm& realm, Gfx::FloatRect const& rect)
  17. {
  18. return realm.create<DOMRect>(realm, rect.x(), rect.y(), rect.width(), rect.height());
  19. }
  20. GC::Ref<DOMRect> DOMRect::create(JS::Realm& realm)
  21. {
  22. return realm.create<DOMRect>(realm);
  23. }
  24. // https://drafts.fxtf.org/geometry/#create-a-domrect-from-the-dictionary
  25. GC::Ref<DOMRect> DOMRect::from_rect(JS::VM& vm, Geometry::DOMRectInit const& other)
  26. {
  27. auto& realm = *vm.current_realm();
  28. return realm.create<DOMRect>(realm, other.x, other.y, other.width, other.height);
  29. }
  30. DOMRect::DOMRect(JS::Realm& realm, double x, double y, double width, double height)
  31. : DOMRectReadOnly(realm, x, y, width, height)
  32. {
  33. }
  34. DOMRect::DOMRect(JS::Realm& realm)
  35. : DOMRectReadOnly(realm)
  36. {
  37. }
  38. DOMRect::~DOMRect() = default;
  39. void DOMRect::initialize(JS::Realm& realm)
  40. {
  41. Base::initialize(realm);
  42. WEB_SET_PROTOTYPE_FOR_INTERFACE(DOMRect);
  43. }
  44. }