mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 13:43:45 +03:00
LibWeb: Use 'now' from EventLoop for animation frame callbacks
Previously, 'now' was set to the time `requestAnimationFrame()` was called, and the EventLoop's 'now' was ignored. This was a little odd and meant the time was always in the past.
This commit is contained in:
parent
0577a664dd
commit
38855de829
Notes:
sideshowbarker
2024-07-17 18:23:22 +09:00
Author: https://github.com/MacDue Commit: https://github.com/SerenityOS/serenity/commit/38855de829 Pull-request: https://github.com/SerenityOS/serenity/pull/23069 Issue: https://github.com/SerenityOS/serenity/issues/23004
@ -43,11 +43,11 @@ struct AnimationFrameCallbackDriver {
|
||||
return true;
|
||||
}
|
||||
|
||||
void run()
|
||||
void run(double now)
|
||||
{
|
||||
auto taken_callbacks = move(m_callbacks);
|
||||
for (auto& [id, callback] : taken_callbacks)
|
||||
callback(id);
|
||||
callback(now);
|
||||
}
|
||||
|
||||
bool has_callbacks() const
|
||||
|
@ -76,10 +76,10 @@ namespace Web::HTML {
|
||||
JS_DEFINE_ALLOCATOR(Window);
|
||||
|
||||
// https://html.spec.whatwg.org/#run-the-animation-frame-callbacks
|
||||
void run_animation_frame_callbacks(DOM::Document& document, double)
|
||||
void run_animation_frame_callbacks(DOM::Document& document, double now)
|
||||
{
|
||||
// FIXME: Bring this closer to the spec.
|
||||
document.window().animation_frame_callback_driver().run();
|
||||
document.window().animation_frame_callback_driver().run(now);
|
||||
}
|
||||
|
||||
class IdleCallback : public RefCounted<IdleCallback> {
|
||||
@ -1409,8 +1409,7 @@ double Window::device_pixel_ratio() const
|
||||
i32 Window::request_animation_frame(WebIDL::CallbackType& callback)
|
||||
{
|
||||
// FIXME: Make this fully spec compliant. Currently implements a mix of 'requestAnimationFrame()' and 'run the animation frame callbacks'.
|
||||
auto now = HighResolutionTime::unsafe_shared_current_time();
|
||||
return m_animation_frame_callback_driver.add([this, now, callback = JS::make_handle(callback)](auto) {
|
||||
return m_animation_frame_callback_driver.add([this, callback = JS::make_handle(callback)](double now) {
|
||||
// 3. Invoke callback, passing now as the only argument, and if an exception is thrown, report the exception.
|
||||
auto result = WebIDL::invoke_callback(*callback, {}, JS::Value(now));
|
||||
if (result.is_error())
|
||||
|
Loading…
Reference in New Issue
Block a user