summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-10-03 16:28:14 +0200
committerAndreas Kling <kling@serenityos.org>2021-10-03 16:42:34 +0200
commit81ef2b646e9ffcf809110a5f8a4fd08986eb797b (patch)
tree3bdba271dbd45b19b5e5899a4020e5953889eaaa /Userland/Libraries/LibWeb
parentae71e5f99b58573c84642f827fe70c3c2257a9d7 (diff)
downloadserenity-81ef2b646e9ffcf809110a5f8a4fd08986eb797b.zip
LibWeb: Let HTML::EventLoop drive animation frame callbacks
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/DOM/Window.cpp22
-rw-r--r--Userland/Libraries/LibWeb/DOM/Window.h2
-rw-r--r--Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp18
3 files changed, 36 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Window.cpp b/Userland/Libraries/LibWeb/DOM/Window.cpp
index a3c47f081c..125253c201 100644
--- a/Userland/Libraries/LibWeb/DOM/Window.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Window.cpp
@@ -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));
diff --git a/Userland/Libraries/LibWeb/DOM/Window.h b/Userland/Libraries/LibWeb/DOM/Window.h
index cd50872f46..563afc4ed1 100644
--- a/Userland/Libraries/LibWeb/DOM/Window.h
+++ b/Userland/Libraries/LibWeb/DOM/Window.h
@@ -116,4 +116,6 @@ private:
HashMap<i32, NonnullRefPtr<RequestAnimationFrameCallback>> m_request_animation_frame_callbacks;
};
+void run_animation_frame_callbacks(DOM::Document&, double now);
+
}
diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
index 8a83844d55..0edfaa2207 100644
--- a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
+++ b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
@@ -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]