diff --git a/Userland/Libraries/LibWeb/HTML/AnimationFrameProvider.idl b/Userland/Libraries/LibWeb/HTML/AnimationFrameProvider.idl new file mode 100644 index 0000000000..91db5edabb --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/AnimationFrameProvider.idl @@ -0,0 +1,8 @@ +#import + +callback FrameRequestCallback = undefined (DOMHighResTimeStamp time); + +// https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#animationframeprovider +interface mixin AnimationFrameProvider { + unsigned long requestAnimationFrame(FrameRequestCallback callback); +}; diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index bf83d56ab1..22d077b44f 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -536,21 +536,6 @@ i32 Window::run_timer_initialization_steps(TimerHandler handler, i32 timeout, JS return id; } -// https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#run-the-animation-frame-callbacks -i32 Window::request_animation_frame_impl(WebIDL::CallbackType& js_callback) -{ - // FIXME: `now` is supposed to be passed in - auto now = HighResolutionTime::unsafe_shared_current_time(); - return m_animation_frame_callback_driver.add([this, now, js_callback = JS::make_handle(js_callback)](auto) { - // 3. Invoke callback, passing now as the only argument, - auto result = WebIDL::invoke_callback(*js_callback, {}, JS::Value(now)); - - // and if an exception is thrown, report the exception. - if (result.is_error()) - HTML::report_exception(result, realm()); - }); -} - void Window::cancel_animation_frame_impl(i32 id) { m_animation_frame_callback_driver.remove(id); @@ -911,7 +896,6 @@ WebIDL::ExceptionOr Window::initialize_web_interfaces(Badge(JS::ErrorType::BadArgCountOne, "requestAnimationFrame"); - auto* callback_object = TRY(vm.argument(0).to_object(vm)); - if (!callback_object->is_function()) - return vm.throw_completion(JS::ErrorType::NotAFunctionNoParam); - auto callback = vm.heap().allocate_without_realm(*callback_object, HTML::incumbent_settings_object()); - return JS::Value(impl->request_animation_frame_impl(*callback)); -} - JS_DEFINE_NATIVE_FUNCTION(Window::cancel_animation_frame) { auto* impl = TRY(impl_from(vm)); diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index 1935e63018..ef8cd46d08 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.h +++ b/Userland/Libraries/LibWeb/HTML/Window.h @@ -88,7 +88,6 @@ public: void set_import_maps_allowed(bool import_maps_allowed) { m_import_maps_allowed = import_maps_allowed; } WebIDL::ExceptionOr> open_impl(StringView url, StringView target, StringView features); - i32 request_animation_frame_impl(WebIDL::CallbackType& js_callback); void cancel_animation_frame_impl(i32); bool has_animation_frame_callbacks() const { return m_animation_frame_callback_driver.has_callbacks(); } @@ -178,6 +177,8 @@ public: i32 outer_height() const; double device_pixel_ratio() const; + i32 request_animation_frame(WebIDL::CallbackType&); + u32 request_idle_callback(WebIDL::CallbackType&, RequestIdleCallback::IdleRequestOptions const&); void cancel_idle_callback(u32 handle); @@ -258,7 +259,6 @@ private: JS_DECLARE_NATIVE_FUNCTION(set_timeout); JS_DECLARE_NATIVE_FUNCTION(clear_interval); JS_DECLARE_NATIVE_FUNCTION(clear_timeout); - JS_DECLARE_NATIVE_FUNCTION(request_animation_frame); JS_DECLARE_NATIVE_FUNCTION(cancel_animation_frame); JS_DECLARE_NATIVE_FUNCTION(queue_microtask); diff --git a/Userland/Libraries/LibWeb/HTML/Window.idl b/Userland/Libraries/LibWeb/HTML/Window.idl index 08b093efd6..ed2d7997da 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.idl +++ b/Userland/Libraries/LibWeb/HTML/Window.idl @@ -5,6 +5,7 @@ #import #import #import +#import #import #import #import @@ -92,6 +93,7 @@ interface Window : EventTarget { // https://w3c.github.io/webcrypto/#crypto-interface [SameObject] readonly attribute Crypto crypto; }; +Window includes AnimationFrameProvider; Window includes GlobalEventHandlers; Window includes WindowEventHandlers; Window includes WindowOrWorkerGlobalScope;