فهرست منبع

LibWeb: Add the IdleDeadline interface from the RequestIdleCallback spec

Andreas Kling 3 سال پیش
والد
کامیت
11bb6e045f

+ 10 - 1
Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp

@@ -439,7 +439,7 @@ int main(int argc, char** argv)
         return 1;
         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;
         StringBuilder builder;
         builder.append(namespace_);
         builder.append(namespace_);
         builder.append("::");
         builder.append("::");
@@ -966,6 +966,8 @@ static void generate_header(IDL::Interface const& interface)
 #    include <LibWeb/HighResolutionTime/@name@.h>
 #    include <LibWeb/HighResolutionTime/@name@.h>
 #elif __has_include(<LibWeb/NavigationTiming/@name@.h>)
 #elif __has_include(<LibWeb/NavigationTiming/@name@.h>)
 #    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>)
 #elif __has_include(<LibWeb/SVG/@name@.h>)
 #    include <LibWeb/SVG/@name@.h>
 #    include <LibWeb/SVG/@name@.h>
 #elif __has_include(<LibWeb/XHR/@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::CSS;
 using namespace Web::DOM;
 using namespace Web::DOM;
 using namespace Web::HTML;
 using namespace Web::HTML;
+using namespace Web::RequestIdleCallback;
 
 
 namespace Web::Bindings {
 namespace Web::Bindings {
 
 
@@ -1235,6 +1238,8 @@ void generate_constructor_implementation(IDL::Interface const& interface)
 #    include <LibWeb/HighResolutionTime/@name@.h>
 #    include <LibWeb/HighResolutionTime/@name@.h>
 #elif __has_include(<LibWeb/NavigationTiming/@name@.h>)
 #elif __has_include(<LibWeb/NavigationTiming/@name@.h>)
 #    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>)
 #elif __has_include(<LibWeb/SVG/@name@.h>)
 #    include <LibWeb/SVG/@name@.h>
 #    include <LibWeb/SVG/@name@.h>
 #elif __has_include(<LibWeb/XHR/@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::CSS;
 using namespace Web::DOM;
 using namespace Web::DOM;
 using namespace Web::HTML;
 using namespace Web::HTML;
+using namespace Web::RequestIdleCallback;
 
 
 namespace Web::Bindings {
 namespace Web::Bindings {
 
 
@@ -1507,6 +1513,8 @@ void generate_prototype_implementation(IDL::Interface const& interface)
 #    include <LibWeb/HighResolutionTime/@name@.h>
 #    include <LibWeb/HighResolutionTime/@name@.h>
 #elif __has_include(<LibWeb/NavigationTiming/@name@.h>)
 #elif __has_include(<LibWeb/NavigationTiming/@name@.h>)
 #    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>)
 #elif __has_include(<LibWeb/SVG/@name@.h>)
 #    include <LibWeb/SVG/@name@.h>
 #    include <LibWeb/SVG/@name@.h>
 #elif __has_include(<LibWeb/XHR/@name@.h>)
 #elif __has_include(<LibWeb/XHR/@name@.h>)
@@ -1520,6 +1528,7 @@ using namespace Web::CSS;
 using namespace Web::DOM;
 using namespace Web::DOM;
 using namespace Web::HTML;
 using namespace Web::HTML;
 using namespace Web::NavigationTiming;
 using namespace Web::NavigationTiming;
+using namespace Web::RequestIdleCallback;
 using namespace Web::XHR;
 using namespace Web::XHR;
 using namespace Web::URL;
 using namespace Web::URL;
 
 

+ 2 - 0
Userland/Libraries/LibWeb/CMakeLists.txt

@@ -221,6 +221,7 @@ set(SOURCES
     Page/Page.cpp
     Page/Page.cpp
     Painting/BorderPainting.cpp
     Painting/BorderPainting.cpp
     Painting/StackingContext.cpp
     Painting/StackingContext.cpp
+    RequestIdleCallback/IdleDeadline.cpp
     SVG/AttributeNames.cpp
     SVG/AttributeNames.cpp
     SVG/SVGElement.cpp
     SVG/SVGElement.cpp
     SVG/SVGGeometryElement.cpp
     SVG/SVGGeometryElement.cpp
@@ -414,6 +415,7 @@ libweb_js_wrapper(HTML/SubmitEvent)
 libweb_js_wrapper(HTML/WebSocket)
 libweb_js_wrapper(HTML/WebSocket)
 libweb_js_wrapper(HighResolutionTime/Performance)
 libweb_js_wrapper(HighResolutionTime/Performance)
 libweb_js_wrapper(NavigationTiming/PerformanceTiming)
 libweb_js_wrapper(NavigationTiming/PerformanceTiming)
+libweb_js_wrapper(RequestIdleCallback/IdleDeadline)
 libweb_js_wrapper(SVG/SVGElement)
 libweb_js_wrapper(SVG/SVGElement)
 libweb_js_wrapper(SVG/SVGGeometryElement)
 libweb_js_wrapper(SVG/SVGGeometryElement)
 libweb_js_wrapper(SVG/SVGGraphicsElement)
 libweb_js_wrapper(SVG/SVGGraphicsElement)

+ 5 - 0
Userland/Libraries/LibWeb/Forward.h

@@ -153,6 +153,10 @@ namespace Web::NavigationTiming {
 class PerformanceTiming;
 class PerformanceTiming;
 }
 }
 
 
+namespace Web::RequestIdleCallback {
+class IdleDeadline;
+}
+
 namespace Web::SVG {
 namespace Web::SVG {
 class SVGElement;
 class SVGElement;
 class SVGGeometryElement;
 class SVGGeometryElement;
@@ -302,6 +306,7 @@ class HTMLTrackElementWrapper;
 class HTMLUListElementWrapper;
 class HTMLUListElementWrapper;
 class HTMLUnknownElementWrapper;
 class HTMLUnknownElementWrapper;
 class HTMLVideoElementWrapper;
 class HTMLVideoElementWrapper;
+class IdleDeadlineWrapper;
 class ImageDataWrapper;
 class ImageDataWrapper;
 class LocationObject;
 class LocationObject;
 class MediaQueryListWrapper;
 class MediaQueryListWrapper;

+ 26 - 0
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()
+{
+}
+
+}

+ 34 - 0
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 };
+};
+
+}

+ 6 - 0
Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.idl

@@ -0,0 +1,6 @@
+[Exposed=Window] interface IdleDeadline {
+
+    double timeRemaining();
+    readonly attribute boolean didTimeout;
+
+};