/src/serenity/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserverEntry.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2023, Luke Wilde <lukew@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <LibWeb/Bindings/PlatformObject.h> |
10 | | #include <LibWeb/Geometry/DOMRect.h> |
11 | | #include <LibWeb/HighResolutionTime/DOMHighResTimeStamp.h> |
12 | | |
13 | | namespace Web::IntersectionObserver { |
14 | | |
15 | | struct IntersectionObserverEntryInit { |
16 | | // https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverentry-time |
17 | | HighResolutionTime::DOMHighResTimeStamp time { 0.0 }; |
18 | | |
19 | | // https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverentry-rootbounds |
20 | | Optional<Geometry::DOMRectInit> root_bounds; |
21 | | |
22 | | // https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverentry-boundingclientrect |
23 | | Geometry::DOMRectInit bounding_client_rect; |
24 | | |
25 | | // https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverentry-intersectionrect |
26 | | Geometry::DOMRectInit intersection_rect; |
27 | | |
28 | | // https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverentry-isintersecting |
29 | | bool is_intersecting { false }; |
30 | | |
31 | | // https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverentry-intersectionratio |
32 | | double intersection_ratio { 0.0 }; |
33 | | |
34 | | // https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverentry-target |
35 | | JS::Handle<DOM::Element> target; |
36 | | }; |
37 | | |
38 | | class IntersectionObserverEntry final : public Bindings::PlatformObject { |
39 | | WEB_PLATFORM_OBJECT(IntersectionObserverEntry, Bindings::PlatformObject); |
40 | | JS_DECLARE_ALLOCATOR(IntersectionObserverEntry); |
41 | | |
42 | | public: |
43 | | static WebIDL::ExceptionOr<JS::NonnullGCPtr<IntersectionObserverEntry>> construct_impl(JS::Realm&, IntersectionObserverEntryInit const& options); |
44 | | |
45 | | virtual ~IntersectionObserverEntry() override; |
46 | | |
47 | 0 | HighResolutionTime::DOMHighResTimeStamp time() const { return m_time; } |
48 | 0 | JS::GCPtr<Geometry::DOMRectReadOnly> root_bounds() const { return m_root_bounds; } |
49 | 0 | JS::NonnullGCPtr<Geometry::DOMRectReadOnly> bounding_client_rect() const { return m_bounding_client_rect; } |
50 | 0 | JS::NonnullGCPtr<Geometry::DOMRectReadOnly> intersection_rect() const { return m_intersection_rect; } |
51 | 0 | bool is_intersecting() const { return m_is_intersecting; } |
52 | 0 | double intersection_ratio() const { return m_intersection_ratio; } |
53 | 0 | JS::NonnullGCPtr<DOM::Element> target() const { return m_target; } |
54 | | |
55 | | private: |
56 | | IntersectionObserverEntry(JS::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); |
57 | | |
58 | | virtual void initialize(JS::Realm&) override; |
59 | | virtual void visit_edges(JS::Cell::Visitor&) override; |
60 | | |
61 | | // https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverentry-time |
62 | | HighResolutionTime::DOMHighResTimeStamp m_time { 0.0 }; |
63 | | |
64 | | // https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverentry-rootbounds |
65 | | JS::GCPtr<Geometry::DOMRectReadOnly> m_root_bounds; |
66 | | |
67 | | // https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverentry-boundingclientrect |
68 | | JS::NonnullGCPtr<Geometry::DOMRectReadOnly> m_bounding_client_rect; |
69 | | |
70 | | // https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverentry-intersectionrect |
71 | | JS::NonnullGCPtr<Geometry::DOMRectReadOnly> m_intersection_rect; |
72 | | |
73 | | // https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverentry-isintersecting |
74 | | bool m_is_intersecting { false }; |
75 | | |
76 | | // https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverentry-intersectionratio |
77 | | double m_intersection_ratio { 0.0 }; |
78 | | |
79 | | // https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverentry-target |
80 | | JS::NonnullGCPtr<DOM::Element> m_target; |
81 | | }; |
82 | | |
83 | | } |