summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-17 01:42:36 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-17 13:20:18 +0200
commit11bb6e045fe9b88115c65546178220e0006878a5 (patch)
tree1accabd02b8cdbe303ff7791112f731999f481e6
parent64df30230d75f1fa92231659a4cc3511740384e8 (diff)
downloadserenity-11bb6e045fe9b88115c65546178220e0006878a5.zip
LibWeb: Add the IdleDeadline interface from the RequestIdleCallback spec
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp11
-rw-r--r--Userland/Libraries/LibWeb/CMakeLists.txt2
-rw-r--r--Userland/Libraries/LibWeb/Forward.h5
-rw-r--r--Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp26
-rw-r--r--Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.h34
-rw-r--r--Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.idl6
6 files changed, 83 insertions, 1 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp
index 69b540352c..76b65dc180 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp
@@ -439,7 +439,7 @@ int main(int argc, char** argv)
return 1;
}
- if (namespace_.is_one_of("CSS", "DOM", "HTML", "UIEvents", "HighResolutionTime", "NavigationTiming", "SVG", "XHR", "URL")) {
+ if (namespace_.is_one_of("CSS", "DOM", "HTML", "UIEvents", "HighResolutionTime", "NavigationTiming", "RequestIdleCallback", "SVG", "XHR", "URL")) {
StringBuilder builder;
builder.append(namespace_);
builder.append("::");
@@ -966,6 +966,8 @@ static void generate_header(IDL::Interface const& interface)
# include <LibWeb/HighResolutionTime/@name@.h>
#elif __has_include(<LibWeb/NavigationTiming/@name@.h>)
# include <LibWeb/NavigationTiming/@name@.h>
+#elif __has_include(<LibWeb/RequestIdleCallback/@name@.h>)
+# include <LibWeb/RequestIdleCallback/@name@.h>
#elif __has_include(<LibWeb/SVG/@name@.h>)
# include <LibWeb/SVG/@name@.h>
#elif __has_include(<LibWeb/XHR/@name@.h>)
@@ -1099,6 +1101,7 @@ void generate_implementation(IDL::Interface const& interface)
using namespace Web::CSS;
using namespace Web::DOM;
using namespace Web::HTML;
+using namespace Web::RequestIdleCallback;
namespace Web::Bindings {
@@ -1235,6 +1238,8 @@ void generate_constructor_implementation(IDL::Interface const& interface)
# include <LibWeb/HighResolutionTime/@name@.h>
#elif __has_include(<LibWeb/NavigationTiming/@name@.h>)
# include <LibWeb/NavigationTiming/@name@.h>
+#elif __has_include(<LibWeb/RequestIdleCallback/@name@.h>)
+# include <LibWeb/RequestIdleCallback/@name@.h>
#elif __has_include(<LibWeb/SVG/@name@.h>)
# include <LibWeb/SVG/@name@.h>
#elif __has_include(<LibWeb/XHR/@name@.h>)
@@ -1247,6 +1252,7 @@ void generate_constructor_implementation(IDL::Interface const& interface)
using namespace Web::CSS;
using namespace Web::DOM;
using namespace Web::HTML;
+using namespace Web::RequestIdleCallback;
namespace Web::Bindings {
@@ -1507,6 +1513,8 @@ void generate_prototype_implementation(IDL::Interface const& interface)
# include <LibWeb/HighResolutionTime/@name@.h>
#elif __has_include(<LibWeb/NavigationTiming/@name@.h>)
# include <LibWeb/NavigationTiming/@name@.h>
+#elif __has_include(<LibWeb/RequestIdleCallback/@name@.h>)
+# include <LibWeb/RequestIdleCallback/@name@.h>
#elif __has_include(<LibWeb/SVG/@name@.h>)
# include <LibWeb/SVG/@name@.h>
#elif __has_include(<LibWeb/XHR/@name@.h>)
@@ -1520,6 +1528,7 @@ using namespace Web::CSS;
using namespace Web::DOM;
using namespace Web::HTML;
using namespace Web::NavigationTiming;
+using namespace Web::RequestIdleCallback;
using namespace Web::XHR;
using namespace Web::URL;
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt
index 641756688d..3e47e6f54a 100644
--- a/Userland/Libraries/LibWeb/CMakeLists.txt
+++ b/Userland/Libraries/LibWeb/CMakeLists.txt
@@ -221,6 +221,7 @@ set(SOURCES
Page/Page.cpp
Painting/BorderPainting.cpp
Painting/StackingContext.cpp
+ RequestIdleCallback/IdleDeadline.cpp
SVG/AttributeNames.cpp
SVG/SVGElement.cpp
SVG/SVGGeometryElement.cpp
@@ -414,6 +415,7 @@ libweb_js_wrapper(HTML/SubmitEvent)
libweb_js_wrapper(HTML/WebSocket)
libweb_js_wrapper(HighResolutionTime/Performance)
libweb_js_wrapper(NavigationTiming/PerformanceTiming)
+libweb_js_wrapper(RequestIdleCallback/IdleDeadline)
libweb_js_wrapper(SVG/SVGElement)
libweb_js_wrapper(SVG/SVGGeometryElement)
libweb_js_wrapper(SVG/SVGGraphicsElement)
diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h
index 840a33817c..de21054194 100644
--- a/Userland/Libraries/LibWeb/Forward.h
+++ b/Userland/Libraries/LibWeb/Forward.h
@@ -153,6 +153,10 @@ namespace Web::NavigationTiming {
class PerformanceTiming;
}
+namespace Web::RequestIdleCallback {
+class IdleDeadline;
+}
+
namespace Web::SVG {
class SVGElement;
class SVGGeometryElement;
@@ -302,6 +306,7 @@ class HTMLTrackElementWrapper;
class HTMLUListElementWrapper;
class HTMLUnknownElementWrapper;
class HTMLVideoElementWrapper;
+class IdleDeadlineWrapper;
class ImageDataWrapper;
class LocationObject;
class MediaQueryListWrapper;
diff --git a/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp b/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp
new file mode 100644
index 0000000000..cc89aaf5ad
--- /dev/null
+++ b/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibWeb/RequestIdleCallback/IdleDeadline.h>
+
+namespace Web::RequestIdleCallback {
+
+NonnullRefPtr<IdleDeadline> IdleDeadline::create(double time_remaining, bool did_timeout)
+{
+ return adopt_ref(*new IdleDeadline(time_remaining, did_timeout));
+}
+
+IdleDeadline::IdleDeadline(double time_remaining, bool did_timeout)
+ : m_time_remaining(time_remaining)
+ , m_did_timeout(did_timeout)
+{
+}
+
+IdleDeadline::~IdleDeadline()
+{
+}
+
+}
diff --git a/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.h b/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.h
new file mode 100644
index 0000000000..5222b3c0ab
--- /dev/null
+++ b/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/StdLibExtras.h>
+#include <LibWeb/Bindings/Wrappable.h>
+
+namespace Web::RequestIdleCallback {
+
+class IdleDeadline final
+ : public RefCounted<IdleDeadline>
+ , public Bindings::Wrappable {
+public:
+ using WrapperType = Bindings::IdleDeadlineWrapper;
+ using AllowOwnPtr = TrueType;
+
+ static NonnullRefPtr<IdleDeadline> create(double time_remaining, bool did_timeout);
+ virtual ~IdleDeadline() override;
+
+ double time_remaining() const { return m_time_remaining; }
+ bool did_timeout() const { return m_did_timeout; }
+
+private:
+ IdleDeadline(double time_remaining, bool did_timeout);
+
+ double m_time_remaining { 0 };
+ bool m_did_timeout { false };
+};
+
+}
diff --git a/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.idl b/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.idl
new file mode 100644
index 0000000000..0088fa3c68
--- /dev/null
+++ b/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.idl
@@ -0,0 +1,6 @@
+[Exposed=Window] interface IdleDeadline {
+
+ double timeRemaining();
+ readonly attribute boolean didTimeout;
+
+};