mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:37:34 +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:
parent
ff66218631
commit
ebe704a03d
7 changed files with 131 additions and 2 deletions
|
@ -207,6 +207,8 @@
|
|||
#include <LibWeb/Bindings/ImageConstructor.h>
|
||||
#include <LibWeb/Bindings/ImageDataConstructor.h>
|
||||
#include <LibWeb/Bindings/ImageDataPrototype.h>
|
||||
#include <LibWeb/Bindings/IntersectionObserverConstructor.h>
|
||||
#include <LibWeb/Bindings/IntersectionObserverPrototype.h>
|
||||
#include <LibWeb/Bindings/MediaQueryListConstructor.h>
|
||||
#include <LibWeb/Bindings/MediaQueryListEventConstructor.h>
|
||||
#include <LibWeb/Bindings/MediaQueryListEventPrototype.h>
|
||||
|
@ -386,6 +388,7 @@
|
|||
ADD_WINDOW_OBJECT_INTERFACE(HTMLUnknownElement) \
|
||||
ADD_WINDOW_OBJECT_INTERFACE(HTMLVideoElement) \
|
||||
ADD_WINDOW_OBJECT_INTERFACE(ImageData) \
|
||||
ADD_WINDOW_OBJECT_INTERFACE(IntersectionObserver) \
|
||||
ADD_WINDOW_OBJECT_INTERFACE(MediaQueryList) \
|
||||
ADD_WINDOW_OBJECT_INTERFACE(MediaQueryListEvent) \
|
||||
ADD_WINDOW_OBJECT_INTERFACE(MessageChannel) \
|
||||
|
|
|
@ -188,7 +188,8 @@ set(SOURCES
|
|||
HTML/WebSocket.cpp
|
||||
HighResolutionTime/Performance.cpp
|
||||
InProcessWebView.cpp
|
||||
Layout/BlockContainer.cpp
|
||||
IntersectionObserver/IntersectionObserver.cpp
|
||||
Layout/BlockContainer.cpp
|
||||
Layout/BlockFormattingContext.cpp
|
||||
Layout/Box.cpp
|
||||
Layout/BoxModelMetrics.cpp
|
||||
|
@ -472,6 +473,7 @@ libweb_js_wrapper(HTML/PromiseRejectionEvent)
|
|||
libweb_js_wrapper(HTML/SubmitEvent)
|
||||
libweb_js_wrapper(HTML/WebSocket)
|
||||
libweb_js_wrapper(HighResolutionTime/Performance)
|
||||
libweb_js_wrapper(IntersectionObserver/IntersectionObserver)
|
||||
libweb_js_wrapper(NavigationTiming/PerformanceTiming)
|
||||
libweb_js_wrapper(RequestIdleCallback/IdleDeadline)
|
||||
libweb_js_wrapper(ResizeObserver/ResizeObserver)
|
||||
|
|
|
@ -204,6 +204,10 @@ namespace Web::HighResolutionTime {
|
|||
class Performance;
|
||||
}
|
||||
|
||||
namespace Web::IntersectionObserver {
|
||||
class IntersectionObserver;
|
||||
}
|
||||
|
||||
namespace Web::NavigationTiming {
|
||||
class PerformanceTiming;
|
||||
}
|
||||
|
@ -386,6 +390,7 @@ class HTMLUnknownElementWrapper;
|
|||
class HTMLVideoElementWrapper;
|
||||
class IdleDeadlineWrapper;
|
||||
class ImageDataWrapper;
|
||||
class IntersectionObserverWrapper;
|
||||
class KeyboardEventWrapper;
|
||||
class LocationObject;
|
||||
class MediaQueryListWrapper;
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Tim Flynn <trflynn89@pm.me>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/IntersectionObserver/IntersectionObserver.h>
|
||||
|
||||
namespace Web::IntersectionObserver {
|
||||
|
||||
// https://w3c.github.io/IntersectionObserver/#dom-intersectionobserver-intersectionobserver
|
||||
NonnullRefPtr<IntersectionObserver> IntersectionObserver::create_with_global_object(JS::GlobalObject& global_object, JS::Value callback, IntersectionObserverInit const& options)
|
||||
{
|
||||
// FIXME: Implement
|
||||
(void)global_object;
|
||||
(void)callback;
|
||||
(void)options;
|
||||
|
||||
return adopt_ref(*new IntersectionObserver);
|
||||
}
|
||||
|
||||
// https://w3c.github.io/IntersectionObserver/#dom-intersectionobserver-observe
|
||||
void IntersectionObserver::observe(DOM::Element& target)
|
||||
{
|
||||
// FIXME: Implement
|
||||
(void)target;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/IntersectionObserver/#dom-intersectionobserver-unobserve
|
||||
void IntersectionObserver::unobserve(DOM::Element& target)
|
||||
{
|
||||
// FIXME: Implement
|
||||
(void)target;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/IntersectionObserver/#dom-intersectionobserver-disconnect
|
||||
void IntersectionObserver::disconnect()
|
||||
{
|
||||
// FIXME: Implement
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
[Exposed=(Window)]
|
||||
interface IntersectionObserver {
|
||||
// FIXME: Should be: IntersectionObserverCallback
|
||||
constructor(any callback, optional IntersectionObserverInit options = {});
|
||||
|
||||
undefined observe(Element target);
|
||||
undefined unobserve(Element target);
|
||||
undefined disconnect();
|
||||
|
||||
// FIXME:
|
||||
// sequence<IntersectionObserverEntry> takeRecords();
|
||||
};
|
||||
|
||||
dictionary IntersectionObserverInit {
|
||||
// FIXME: Should be: (Element or Document)?
|
||||
Node? root = null;
|
||||
|
||||
DOMString rootMargin = "0px";
|
||||
|
||||
// FIXME: Should be: (double or sequence<double>)
|
||||
any threshold = 0;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue