summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
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 /Userland/Libraries/LibWeb
parent64df30230d75f1fa92231659a4cc3511740384e8 (diff)
downloadserenity-11bb6e045fe9b88115c65546178220e0006878a5.zip
LibWeb: Add the IdleDeadline interface from the RequestIdleCallback spec
Diffstat (limited to 'Userland/Libraries/LibWeb')
-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
5 files changed, 73 insertions, 0 deletions
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;
+
+};