mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
LibWeb: Let HTML::EventLoop drive animation frame callbacks
This commit is contained in:
parent
ae71e5f99b
commit
81ef2b646e
Notes:
sideshowbarker
2024-07-18 03:08:48 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/81ef2b646e9
@ -47,11 +47,7 @@ struct RequestAnimationFrameDriver {
|
||||
RequestAnimationFrameDriver()
|
||||
{
|
||||
m_timer = Core::Timer::create_single_shot(16, [this] {
|
||||
auto taken_callbacks = move(m_callbacks);
|
||||
for (auto& it : taken_callbacks) {
|
||||
if (!it.value->is_cancelled())
|
||||
it.value->invoke();
|
||||
}
|
||||
HTML::main_thread_event_loop().schedule();
|
||||
});
|
||||
}
|
||||
|
||||
@ -75,6 +71,15 @@ struct RequestAnimationFrameDriver {
|
||||
return true;
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
auto taken_callbacks = move(m_callbacks);
|
||||
for (auto& it : taken_callbacks) {
|
||||
if (!it.value->is_cancelled())
|
||||
it.value->invoke();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
HashMap<i32, NonnullRefPtr<RequestAnimationFrameCallback>> m_callbacks;
|
||||
IDAllocator m_id_allocator;
|
||||
@ -87,6 +92,13 @@ static RequestAnimationFrameDriver& request_animation_frame_driver()
|
||||
return driver;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/#run-the-animation-frame-callbacks
|
||||
void run_animation_frame_callbacks(DOM::Document&, double)
|
||||
{
|
||||
// FIXME: Bring this closer to the spec.
|
||||
request_animation_frame_driver().run();
|
||||
}
|
||||
|
||||
NonnullRefPtr<Window> Window::create_with_document(Document& document)
|
||||
{
|
||||
return adopt_ref(*new Window(document));
|
||||
|
@ -116,4 +116,6 @@ private:
|
||||
HashMap<i32, NonnullRefPtr<RequestAnimationFrameCallback>> m_request_animation_frame_callbacks;
|
||||
};
|
||||
|
||||
void run_animation_frame_callbacks(DOM::Document&, double now);
|
||||
|
||||
}
|
||||
|
@ -9,7 +9,9 @@
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Window.h>
|
||||
#include <LibWeb/HTML/EventLoop/EventLoop.h>
|
||||
#include <LibWeb/HighResolutionTime/Performance.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
@ -127,10 +129,21 @@ void EventLoop::process()
|
||||
// FIXME: 1. Let docs be all Document objects whose relevant agent's event loop is this event loop, sorted arbitrarily except that the following conditions must be met:
|
||||
// - Any Document B whose browsing context's container document is A must be listed after A in the list.
|
||||
// - If there are two documents A and B whose browsing contexts are both child browsing contexts whose container documents are another Document C, then the order of A and B in the list must match the shadow-including tree order of their respective browsing context containers in C's node tree.
|
||||
// FIXME: NOTE: The sort order specified above is missing here!
|
||||
NonnullRefPtrVector<DOM::Document> docs = documents_in_this_event_loop();
|
||||
|
||||
auto for_each_fully_active_document_in_docs = [&](auto&& callback) {
|
||||
for (auto& document : docs) {
|
||||
if (document.is_fully_active())
|
||||
callback(document);
|
||||
}
|
||||
};
|
||||
|
||||
// FIXME: 2. Rendering opportunities: Remove from docs all Document objects whose browsing context do not have a rendering opportunity.
|
||||
|
||||
// FIXME: 3. If docs is not empty, then set hasARenderingOpportunity to true.
|
||||
// 3. If docs is not empty, then set hasARenderingOpportunity to true.
|
||||
if (!docs.is_empty())
|
||||
has_a_rendering_opportunity = true;
|
||||
|
||||
// FIXME: 4. Unnecessary rendering: Remove from docs all Document objects which meet both of the following conditions:
|
||||
// - The user agent believes that updating the rendering of the Document's browsing context would have no visible effect, and
|
||||
@ -153,6 +166,9 @@ void EventLoop::process()
|
||||
// FIXME: 12. For each fully active Document in docs, if the user agent detects that the backing storage associated with a CanvasRenderingContext2D or an OffscreenCanvasRenderingContext2D, context, has been lost, then it must run the context lost steps for each such context:
|
||||
|
||||
// FIXME: 13. For each fully active Document in docs, run the animation frame callbacks for that Document, passing in now as the timestamp.
|
||||
for_each_fully_active_document_in_docs([&](DOM::Document& document) {
|
||||
run_animation_frame_callbacks(document, document.window().performance().now());
|
||||
});
|
||||
|
||||
// FIXME: 14. For each fully active Document in docs, run the update intersection observations steps for that Document, passing in now as the timestamp. [INTERSECTIONOBSERVER]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user