LibWeb: Implement more IntersectionObserver attributes

This commit is contained in:
Psychpsyo 2024-11-22 12:01:42 +01:00 committed by Andreas Kling
commit 3e536a4cd7
Notes: github-actions[bot] 2024-11-23 08:53:22 +00:00
9 changed files with 345 additions and 17 deletions

View file

@ -16,7 +16,10 @@ namespace Web::IntersectionObserver {
struct IntersectionObserverInit {
Optional<Variant<GC::Root<DOM::Element>, GC::Root<DOM::Document>>> root;
String root_margin { "0px"_string };
String scroll_margin { "0px"_string };
Variant<double, Vector<double>> threshold { 0 };
long delay = 0;
bool track_visibility = false;
};
// https://www.w3.org/TR/intersection-observer/#intersectionobserverregistration
@ -53,7 +56,11 @@ public:
Vector<GC::Ref<DOM::Element>> const& observation_targets() const { return m_observation_targets; }
Variant<GC::Root<DOM::Element>, GC::Root<DOM::Document>, Empty> root() const;
String root_margin() const;
String scroll_margin() const;
Vector<double> const& thresholds() const { return m_thresholds; }
long delay() const { return m_delay; }
bool track_visibility() const { return m_track_visibility; }
Variant<GC::Root<DOM::Element>, GC::Root<DOM::Document>> intersection_root() const;
CSSPixelRect root_intersection_rectangle() const;
@ -63,21 +70,35 @@ public:
WebIDL::CallbackType& callback() { return *m_callback; }
private:
explicit IntersectionObserver(JS::Realm&, GC::Ptr<WebIDL::CallbackType> callback, Optional<Variant<GC::Root<DOM::Element>, GC::Root<DOM::Document>>> const& root, Vector<double>&& thresholds);
explicit IntersectionObserver(JS::Realm&, GC::Ptr<WebIDL::CallbackType> callback, Optional<Variant<GC::Root<DOM::Element>, GC::Root<DOM::Document>>> const& root, Vector<CSS::LengthPercentage> root_margin, Vector<CSS::LengthPercentage> scroll_margin, Vector<double>&& thresholds, double debug, bool track_visibility);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(JS::Cell::Visitor&) override;
virtual void finalize() override;
static Optional<Vector<CSS::LengthPercentage>> parse_a_margin(JS::Realm&, String);
// https://www.w3.org/TR/intersection-observer/#dom-intersectionobserver-callback-slot
GC::Ptr<WebIDL::CallbackType> m_callback;
// https://www.w3.org/TR/intersection-observer/#dom-intersectionobserver-root
GC::Ptr<DOM::Node> m_root;
// https://www.w3.org/TR/intersection-observer/#dom-intersectionobserver-rootmargin
Vector<CSS::LengthPercentage> m_root_margin;
// https://www.w3.org/TR/intersection-observer/#dom-intersectionobserver-scrollmargin
Vector<CSS::LengthPercentage> m_scroll_margin;
// https://www.w3.org/TR/intersection-observer/#dom-intersectionobserver-thresholds
Vector<double> m_thresholds;
// https://w3c.github.io/IntersectionObserver/#dom-intersectionobserver-delay
long m_delay;
// https://w3c.github.io/IntersectionObserver/#dom-intersectionobserver-trackvisibility
bool m_track_visibility;
// https://www.w3.org/TR/intersection-observer/#dom-intersectionobserver-queuedentries-slot
Vector<GC::Ref<IntersectionObserverEntry>> m_queued_entries;