Serenity Operating System
1/*
2 * Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#pragma once
8
9#include <LibJS/Heap/Handle.h>
10#include <LibWeb/Bindings/PlatformObject.h>
11
12namespace Web::IntersectionObserver {
13
14struct IntersectionObserverInit {
15 Optional<Variant<JS::Handle<DOM::Element>, JS::Handle<DOM::Document>>> root;
16 DeprecatedString root_margin { "0px"sv };
17 Variant<double, Vector<double>> threshold { 0 };
18};
19
20// https://w3c.github.io/IntersectionObserver/#intersection-observer-interface
21class IntersectionObserver : public Bindings::PlatformObject {
22 WEB_PLATFORM_OBJECT(IntersectionObserver, Bindings::PlatformObject);
23
24public:
25 static WebIDL::ExceptionOr<JS::NonnullGCPtr<IntersectionObserver>> construct_impl(JS::Realm&, WebIDL::CallbackType* callback, IntersectionObserverInit const& options = {});
26
27 virtual ~IntersectionObserver() override;
28
29 void observe(DOM::Element& target);
30 void unobserve(DOM::Element& target);
31 void disconnect();
32
33private:
34 explicit IntersectionObserver(JS::Realm&);
35
36 virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
37};
38
39}