mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
LibWeb/HTML: Port Window.cancelIdleCallback() to IDL
This commit is contained in:
parent
b410804f54
commit
86589f09dc
Notes:
sideshowbarker
2024-07-17 10:39:39 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/86589f09dc Pull-request: https://github.com/SerenityOS/serenity/pull/17752 Reviewed-by: https://github.com/awesomekling
@ -826,22 +826,6 @@ void Window::invoke_idle_callbacks()
|
||||
}
|
||||
}
|
||||
|
||||
// https://w3c.github.io/requestidlecallback/#the-cancelidlecallback-method
|
||||
void Window::cancel_idle_callback_impl(u32 handle)
|
||||
{
|
||||
// 1. Let window be this Window object.
|
||||
auto& window = *this;
|
||||
// 2. Find the entry in either the window's list of idle request callbacks or list of runnable idle callbacks
|
||||
// that is associated with the value handle.
|
||||
// 3. If there is such an entry, remove it from both window's list of idle request callbacks and the list of runnable idle callbacks.
|
||||
window.m_idle_request_callbacks.remove_first_matching([handle](auto& callback) {
|
||||
return callback->handle() == handle;
|
||||
});
|
||||
window.m_runnable_idle_callbacks.remove_first_matching([handle](auto& callback) {
|
||||
return callback->handle() == handle;
|
||||
});
|
||||
}
|
||||
|
||||
void Window::set_associated_document(DOM::Document& document)
|
||||
{
|
||||
m_associated_document = &document;
|
||||
@ -932,8 +916,6 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm
|
||||
|
||||
define_native_function(realm, "queueMicrotask", queue_microtask, 1, attr);
|
||||
|
||||
define_native_function(realm, "cancelIdleCallback", cancel_idle_callback, 1, attr);
|
||||
|
||||
define_native_function(realm, "structuredClone", structured_clone, 1, attr);
|
||||
|
||||
define_native_function(realm, "fetch", Bindings::fetch, 1, attr);
|
||||
@ -1480,6 +1462,22 @@ u32 Window::request_idle_callback(WebIDL::CallbackType& callback, RequestIdleCal
|
||||
(void)options;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/requestidlecallback/#dom-window-cancelidlecallback
|
||||
void Window::cancel_idle_callback(u32 handle)
|
||||
{
|
||||
// 1. Let window be this Window object.
|
||||
|
||||
// 2. Find the entry in either the window's list of idle request callbacks or list of runnable idle callbacks
|
||||
// that is associated with the value handle.
|
||||
// 3. If there is such an entry, remove it from both window's list of idle request callbacks and the list of runnable idle callbacks.
|
||||
m_idle_request_callbacks.remove_first_matching([&](auto& callback) {
|
||||
return callback->handle() == handle;
|
||||
});
|
||||
m_runnable_idle_callbacks.remove_first_matching([&](auto& callback) {
|
||||
return callback->handle() == handle;
|
||||
});
|
||||
}
|
||||
|
||||
// https://w3c.github.io/selection-api/#dom-window-getselection
|
||||
JS::GCPtr<Selection::Selection> Window::get_selection() const
|
||||
{
|
||||
@ -1617,16 +1615,6 @@ JS_DEFINE_NATIVE_FUNCTION(Window::queue_microtask)
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::cancel_idle_callback)
|
||||
{
|
||||
auto* impl = TRY(impl_from(vm));
|
||||
if (!vm.argument_count())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "cancelIdleCallback");
|
||||
auto id = TRY(vm.argument(0).to_u32(vm));
|
||||
impl->cancel_idle_callback_impl(id);
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/window-object.html#number-of-document-tree-child-browsing-contexts
|
||||
size_t Window::document_tree_child_browsing_context_count() const
|
||||
{
|
||||
|
@ -120,8 +120,6 @@ public:
|
||||
|
||||
void start_an_idle_period();
|
||||
|
||||
void cancel_idle_callback_impl(u32);
|
||||
|
||||
AnimationFrameCallbackDriver& animation_frame_callback_driver() { return m_animation_frame_callback_driver; }
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/interaction.html#transient-activation
|
||||
@ -181,6 +179,7 @@ public:
|
||||
double device_pixel_ratio() const;
|
||||
|
||||
u32 request_idle_callback(WebIDL::CallbackType&, RequestIdleCallback::IdleRequestOptions const&);
|
||||
void cancel_idle_callback(u32 handle);
|
||||
|
||||
JS::GCPtr<Selection::Selection> get_selection() const;
|
||||
|
||||
@ -264,8 +263,6 @@ private:
|
||||
|
||||
JS_DECLARE_NATIVE_FUNCTION(queue_microtask);
|
||||
|
||||
JS_DECLARE_NATIVE_FUNCTION(cancel_idle_callback);
|
||||
|
||||
HTML::Location* m_location { nullptr };
|
||||
|
||||
// [[CrossOriginPropertyDescriptorMap]], https://html.spec.whatwg.org/multipage/browsers.html#crossoriginpropertydescriptormap
|
||||
|
@ -80,6 +80,7 @@ interface Window : EventTarget {
|
||||
|
||||
// https://w3c.github.io/requestidlecallback/#window_extensions
|
||||
unsigned long requestIdleCallback(IdleRequestCallback callback, optional IdleRequestOptions options = {});
|
||||
undefined cancelIdleCallback(unsigned long handle);
|
||||
|
||||
// https://w3c.github.io/selection-api/#extensions-to-window-interface
|
||||
Selection? getSelection();
|
||||
|
Loading…
Reference in New Issue
Block a user