IntersectionObserverEntry.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/Intrinsics.h>
  7. #include <LibWeb/DOM/Element.h>
  8. #include <LibWeb/IntersectionObserver/IntersectionObserverEntry.h>
  9. namespace Web::IntersectionObserver {
  10. JS_DEFINE_ALLOCATOR(IntersectionObserverEntry);
  11. WebIDL::ExceptionOr<JS::NonnullGCPtr<IntersectionObserverEntry>> IntersectionObserverEntry::construct_impl(JS::Realm& realm, Web::IntersectionObserver::IntersectionObserverEntryInit const& options)
  12. {
  13. auto& vm = realm.vm();
  14. JS::GCPtr<Geometry::DOMRectReadOnly> root_bounds;
  15. if (options.root_bounds.has_value())
  16. root_bounds = Geometry::DOMRectReadOnly::from_rect(vm, options.root_bounds.value());
  17. auto bounding_client_rect = Geometry::DOMRectReadOnly::from_rect(vm, options.bounding_client_rect);
  18. auto intersection_rect = Geometry::DOMRectReadOnly::from_rect(vm, options.intersection_rect);
  19. return realm.heap().allocate<IntersectionObserverEntry>(realm, realm, options.time, root_bounds, bounding_client_rect, intersection_rect, options.is_intersecting, options.intersection_ratio, *options.target);
  20. }
  21. IntersectionObserverEntry::IntersectionObserverEntry(JS::Realm& realm, HighResolutionTime::DOMHighResTimeStamp time, JS::GCPtr<Geometry::DOMRectReadOnly> root_bounds, JS::NonnullGCPtr<Geometry::DOMRectReadOnly> bounding_client_rect, JS::NonnullGCPtr<Geometry::DOMRectReadOnly> intersection_rect, bool is_intersecting, double intersection_ratio, JS::NonnullGCPtr<DOM::Element> target)
  22. : Bindings::PlatformObject(realm)
  23. , m_time(time)
  24. , m_root_bounds(root_bounds)
  25. , m_bounding_client_rect(bounding_client_rect)
  26. , m_intersection_rect(intersection_rect)
  27. , m_is_intersecting(is_intersecting)
  28. , m_intersection_ratio(intersection_ratio)
  29. , m_target(target)
  30. {
  31. }
  32. IntersectionObserverEntry::~IntersectionObserverEntry() = default;
  33. void IntersectionObserverEntry::initialize(JS::Realm& realm)
  34. {
  35. Base::initialize(realm);
  36. WEB_SET_PROTOTYPE_FOR_INTERFACE(IntersectionObserverEntry);
  37. }
  38. void IntersectionObserverEntry::visit_edges(JS::Cell::Visitor& visitor)
  39. {
  40. Base::visit_edges(visitor);
  41. visitor.visit(m_root_bounds);
  42. visitor.visit(m_bounding_client_rect);
  43. visitor.visit(m_intersection_rect);
  44. visitor.visit(m_target);
  45. }
  46. }