IntersectionObserverEntry.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. WebIDL::ExceptionOr<JS::NonnullGCPtr<IntersectionObserverEntry>> IntersectionObserverEntry::construct_impl(JS::Realm& realm, Web::IntersectionObserver::IntersectionObserverEntryInit const& options)
  11. {
  12. auto& vm = realm.vm();
  13. JS::GCPtr<Geometry::DOMRectReadOnly> root_bounds;
  14. if (options.root_bounds.has_value())
  15. root_bounds = Geometry::DOMRectReadOnly::from_rect(vm, options.root_bounds.value());
  16. auto bounding_client_rect = Geometry::DOMRectReadOnly::from_rect(vm, options.bounding_client_rect);
  17. auto intersection_rect = Geometry::DOMRectReadOnly::from_rect(vm, options.intersection_rect);
  18. return realm.heap().allocate<IntersectionObserverEntry>(realm, realm, options.time, root_bounds, bounding_client_rect, intersection_rect, options.is_intersecting, options.intersection_ratio, *options.target);
  19. }
  20. 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)
  21. : Bindings::PlatformObject(realm)
  22. , m_time(time)
  23. , m_root_bounds(root_bounds)
  24. , m_bounding_client_rect(bounding_client_rect)
  25. , m_intersection_rect(intersection_rect)
  26. , m_is_intersecting(is_intersecting)
  27. , m_intersection_ratio(intersection_ratio)
  28. , m_target(target)
  29. {
  30. }
  31. IntersectionObserverEntry::~IntersectionObserverEntry() = default;
  32. void IntersectionObserverEntry::initialize(JS::Realm& realm)
  33. {
  34. Base::initialize(realm);
  35. set_prototype(&Bindings::ensure_web_prototype<Bindings::IntersectionObserverEntryPrototype>(realm, "IntersectionObserverEntry"));
  36. }
  37. void IntersectionObserverEntry::visit_edges(JS::Cell::Visitor& visitor)
  38. {
  39. Base::visit_edges(visitor);
  40. visitor.visit(m_root_bounds);
  41. visitor.visit(m_bounding_client_rect);
  42. visitor.visit(m_intersection_rect);
  43. visitor.visit(m_target);
  44. }
  45. }