DOMRectReadOnly.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/Intrinsics.h>
  7. #include <LibWeb/Geometry/DOMRectReadOnly.h>
  8. #include <LibWeb/WebIDL/ExceptionOr.h>
  9. namespace Web::Geometry {
  10. WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRectReadOnly>> DOMRectReadOnly::construct_impl(JS::Realm& realm, double x, double y, double width, double height)
  11. {
  12. return realm.heap().allocate<DOMRectReadOnly>(realm, realm, x, y, width, height);
  13. }
  14. // https://drafts.fxtf.org/geometry/#create-a-domrect-from-the-dictionary
  15. JS::NonnullGCPtr<DOMRectReadOnly> DOMRectReadOnly::from_rect(JS::VM& vm, Geometry::DOMRectInit const& other)
  16. {
  17. auto& realm = *vm.current_realm();
  18. return realm.heap().allocate<DOMRectReadOnly>(realm, realm, other.x, other.y, other.width, other.height);
  19. }
  20. DOMRectReadOnly::DOMRectReadOnly(JS::Realm& realm, double x, double y, double width, double height)
  21. : PlatformObject(realm)
  22. , m_rect(x, y, width, height)
  23. {
  24. }
  25. DOMRectReadOnly::~DOMRectReadOnly() = default;
  26. void DOMRectReadOnly::initialize(JS::Realm& realm)
  27. {
  28. Base::initialize(realm);
  29. set_prototype(&Bindings::ensure_web_prototype<Bindings::DOMRectReadOnlyPrototype>(realm, "DOMRectReadOnly"));
  30. }
  31. }