1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:17:45 +00:00

LibWeb: Stub out a basic IntersectionObserver interface

Note there are a couple of type differences between the spec and the IDL
file added in this commit. For example, we will need to support a type
of Variant to handle spec types such as "(double or sequence<double>)".
But for now, this allows web pages to construct an IntersectionObserver
with any valid type.
This commit is contained in:
Timothy Flynn 2021-10-13 14:20:50 -04:00 committed by Andreas Kling
parent ff66218631
commit ebe704a03d
7 changed files with 131 additions and 2 deletions

View file

@ -0,0 +1,35 @@
/*
* Copyright (c) 2021, Tim Flynn <trflynn89@pm.me>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/NonnullRefPtr.h>
#include <AK/RefCounted.h>
#include <LibWeb/Bindings/Wrappable.h>
namespace Web::IntersectionObserver {
struct IntersectionObserverInit {
DOM::Node* root { nullptr };
String root_margin { "0px"sv };
JS::Value threshold { 0 };
};
// https://w3c.github.io/IntersectionObserver/#intersection-observer-interface
class IntersectionObserver
: public RefCounted<IntersectionObserver>
, public Bindings::Wrappable {
public:
using WrapperType = Bindings::IntersectionObserverWrapper;
static NonnullRefPtr<IntersectionObserver> create_with_global_object(JS::GlobalObject&, JS::Value callback, IntersectionObserverInit const& options = {});
void observe(DOM::Element& target);
void unobserve(DOM::Element& target);
void disconnect();
};
}