2021-10-13 14:20:50 -04:00
|
|
|
/*
|
2022-01-31 13:07:22 -05:00
|
|
|
* Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
|
2021-10-13 14:20:50 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-09-04 14:14:22 +02:00
|
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
2021-10-13 14:20:50 -04:00
|
|
|
|
|
|
|
namespace Web::IntersectionObserver {
|
|
|
|
|
|
|
|
struct IntersectionObserverInit {
|
2022-08-28 13:42:07 +02:00
|
|
|
Optional<Variant<JS::Handle<DOM::Element>, JS::Handle<DOM::Document>>> root;
|
2021-10-13 14:20:50 -04:00
|
|
|
String root_margin { "0px"sv };
|
2022-04-02 00:44:16 +03:00
|
|
|
Variant<double, Vector<double>> threshold { 0 };
|
2021-10-13 14:20:50 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// https://w3c.github.io/IntersectionObserver/#intersection-observer-interface
|
2022-09-04 14:14:22 +02:00
|
|
|
class IntersectionObserver : public Bindings::PlatformObject {
|
|
|
|
WEB_PLATFORM_OBJECT(IntersectionObserver, Bindings::PlatformObject);
|
|
|
|
|
2021-10-13 14:20:50 -04:00
|
|
|
public:
|
2022-09-04 14:14:22 +02:00
|
|
|
static JS::NonnullGCPtr<IntersectionObserver> create_with_global_object(HTML::Window&, Bindings::CallbackType* callback, IntersectionObserverInit const& options = {});
|
2021-10-13 14:20:50 -04:00
|
|
|
|
2022-09-04 14:14:22 +02:00
|
|
|
virtual ~IntersectionObserver() override;
|
2021-10-13 14:20:50 -04:00
|
|
|
|
|
|
|
void observe(DOM::Element& target);
|
|
|
|
void unobserve(DOM::Element& target);
|
|
|
|
void disconnect();
|
2022-09-04 14:14:22 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
explicit IntersectionObserver(HTML::Window&);
|
2021-10-13 14:20:50 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2022-09-04 14:14:22 +02:00
|
|
|
|
|
|
|
WRAPPER_HACK(IntersectionObserver, Web::IntersectionObserver)
|