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