summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp21
-rw-r--r--Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h3
-rw-r--r--Userland/Libraries/LibWeb/CMakeLists.txt4
-rw-r--r--Userland/Libraries/LibWeb/Forward.h5
-rw-r--r--Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp43
-rw-r--r--Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h35
-rw-r--r--Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.idl22
7 files changed, 131 insertions, 2 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp
index 2bcff977b7..4922267f78 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp
@@ -750,7 +750,7 @@ int main(int argc, char** argv)
auto interface = IDL::parse_interface(path, data, import_base_path);
- if (namespace_.is_one_of("Crypto", "CSS", "DOM", "HTML", "UIEvents", "Geometry", "HighResolutionTime", "NavigationTiming", "RequestIdleCallback", "ResizeObserver", "SVG", "Selection", "XHR", "URL")) {
+ if (namespace_.is_one_of("Crypto", "CSS", "DOM", "HTML", "UIEvents", "Geometry", "HighResolutionTime", "IntersectionObserver", "NavigationTiming", "RequestIdleCallback", "ResizeObserver", "SVG", "Selection", "XHR", "URL")) {
StringBuilder builder;
builder.append(namespace_);
builder.append("::");
@@ -1421,6 +1421,8 @@ static void generate_header(IDL::Interface const& interface)
# include <LibWeb/UIEvents/@name@.h>
#elif __has_include(<LibWeb/HighResolutionTime/@name@.h>)
# include <LibWeb/HighResolutionTime/@name@.h>
+#elif __has_include(<LibWeb/IntersectionObserver/@name@.h>)
+# include <LibWeb/IntersectionObserver/@name@.h>
#elif __has_include(<LibWeb/NavigationTiming/@name@.h>)
# include <LibWeb/NavigationTiming/@name@.h>
#elif __has_include(<LibWeb/RequestIdleCallback/@name@.h>)
@@ -1589,6 +1591,7 @@ void generate_implementation(IDL::Interface const& interface)
#include <LibWeb/DOM/Element.h>
#include <LibWeb/DOM/EventListener.h>
#include <LibWeb/HTML/HTMLElement.h>
+#include <LibWeb/IntersectionObserver/IntersectionObserver.h>
#include <LibWeb/Origin.h>
#include <LibWeb/ResizeObserver/ResizeObserver.h>
@@ -1597,6 +1600,7 @@ using namespace Web::CSS;
using namespace Web::DOM;
using namespace Web::Geometry;
using namespace Web::HTML;
+using namespace Web::IntersectionObserver;
using namespace Web::RequestIdleCallback;
using namespace Web::ResizeObserver;
using namespace Web::Selection;
@@ -2493,6 +2497,7 @@ void generate_constructor_implementation(IDL::Interface const& interface)
#include <LibWeb/Bindings/EventTargetWrapperFactory.h>
#include <LibWeb/Bindings/EventWrapperFactory.h>
#include <LibWeb/Bindings/ExceptionOrUtils.h>
+#include <LibWeb/Bindings/NodeWrapper.h>
#include <LibWeb/Bindings/NodeWrapperFactory.h>
#include <LibWeb/Bindings/WindowObject.h>
#if __has_include(<LibWeb/Crypto/@name@.h>)
@@ -2509,6 +2514,8 @@ void generate_constructor_implementation(IDL::Interface const& interface)
# include <LibWeb/UIEvents/@name@.h>
#elif __has_include(<LibWeb/HighResolutionTime/@name@.h>)
# include <LibWeb/HighResolutionTime/@name@.h>
+#elif __has_include(<LibWeb/IntersectionObserver/@name@.h>)
+# include <LibWeb/IntersectionObserver/@name@.h>
#elif __has_include(<LibWeb/NavigationTiming/@name@.h>)
# include <LibWeb/NavigationTiming/@name@.h>
#elif __has_include(<LibWeb/RequestIdleCallback/@name@.h>)
@@ -2530,6 +2537,7 @@ using namespace Web::CSS;
using namespace Web::DOM;
using namespace Web::Geometry;
using namespace Web::HTML;
+using namespace Web::IntersectionObserver;
using namespace Web::RequestIdleCallback;
using namespace Web::ResizeObserver;
using namespace Web::Selection;
@@ -2822,6 +2830,8 @@ void generate_prototype_implementation(IDL::Interface const& interface)
# include <LibWeb/UIEvents/@name@.h>
#elif __has_include(<LibWeb/HighResolutionTime/@name@.h>)
# include <LibWeb/HighResolutionTime/@name@.h>
+#elif __has_include(<LibWeb/IntersectionObserver/@name@.h>)
+# include <LibWeb/IntersectionObserver/@name@.h>
#elif __has_include(<LibWeb/NavigationTiming/@name@.h>)
# include <LibWeb/NavigationTiming/@name@.h>
#elif __has_include(<LibWeb/RequestIdleCallback/@name@.h>)
@@ -2854,6 +2864,8 @@ void generate_prototype_implementation(IDL::Interface const& interface)
# include <LibWeb/UIEvents/@iterator_name@.h>
#elif __has_include(<LibWeb/HighResolutionTime/@iterator_name@.h>)
# include <LibWeb/HighResolutionTime/@iterator_name@.h>
+#elif __has_include(<LibWeb/IntersectionObserver/@name@.h>)
+# include <LibWeb/IntersectionObserver/@name@.h>
#elif __has_include(<LibWeb/NavigationTiming/@iterator_name@.h>)
# include <LibWeb/NavigationTiming/@iterator_name@.h>
#elif __has_include(<LibWeb/RequestIdleCallback/@iterator_name@.h>)
@@ -2879,6 +2891,7 @@ using namespace Web::CSS;
using namespace Web::DOM;
using namespace Web::Geometry;
using namespace Web::HTML;
+using namespace Web::IntersectionObserver;
using namespace Web::NavigationTiming;
using namespace Web::RequestIdleCallback;
using namespace Web::ResizeObserver;
@@ -3298,6 +3311,8 @@ static void generate_iterator_header(IDL::Interface const& interface)
# include <LibWeb/UIEvents/@name@.h>
#elif __has_include(<LibWeb/HighResolutionTime/@name@.h>)
# include <LibWeb/HighResolutionTime/@name@.h>
+#elif __has_include(<LibWeb/IntersectionObserver/@name@.h>)
+# include <LibWeb/IntersectionObserver/@name@.h>
#elif __has_include(<LibWeb/NavigationTiming/@name@.h>)
# include <LibWeb/NavigationTiming/@name@.h>
#elif __has_include(<LibWeb/RequestIdleCallback/@name@.h>)
@@ -3371,6 +3386,7 @@ using namespace Web::CSS;
using namespace Web::DOM;
using namespace Web::Geometry;
using namespace Web::HTML;
+using namespace Web::IntersectionObserver;
using namespace Web::RequestIdleCallback;
using namespace Web::ResizeObserver;
using namespace Web::Selection;
@@ -3483,6 +3499,8 @@ void generate_iterator_prototype_implementation(IDL::Interface const& interface)
# include <LibWeb/UIEvents/@name@.h>
#elif __has_include(<LibWeb/HighResolutionTime/@name@.h>)
# include <LibWeb/HighResolutionTime/@name@.h>
+#elif __has_include(<LibWeb/IntersectionObserver/@name@.h>)
+# include <LibWeb/IntersectionObserver/@name@.h>
#elif __has_include(<LibWeb/NavigationTiming/@name@.h>)
# include <LibWeb/NavigationTiming/@name@.h>
#elif __has_include(<LibWeb/RequestIdleCallback/@name@.h>)
@@ -3504,6 +3522,7 @@ using namespace Web::CSS;
using namespace Web::DOM;
using namespace Web::Geometry;
using namespace Web::HTML;
+using namespace Web::IntersectionObserver;
using namespace Web::NavigationTiming;
using namespace Web::RequestIdleCallback;
using namespace Web::ResizeObserver;
diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h
index 49239fb903..7988bc1966 100644
--- a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h
+++ b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h
@@ -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) \
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt
index 7bd0d6b7d3..d3188546b6 100644
--- a/Userland/Libraries/LibWeb/CMakeLists.txt
+++ b/Userland/Libraries/LibWeb/CMakeLists.txt
@@ -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)
diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h
index c545a04e2e..39764e2dad 100644
--- a/Userland/Libraries/LibWeb/Forward.h
+++ b/Userland/Libraries/LibWeb/Forward.h
@@ -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;
diff --git a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp
new file mode 100644
index 0000000000..adbc7e1336
--- /dev/null
+++ b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp
@@ -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
+}
+
+}
diff --git a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h
new file mode 100644
index 0000000000..43c4bff783
--- /dev/null
+++ b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h
@@ -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();
+};
+
+}
diff --git a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.idl b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.idl
new file mode 100644
index 0000000000..651a9fce17
--- /dev/null
+++ b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.idl
@@ -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;
+};