IntersectionObserverEntry.cpp 2.3 KB

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