LibWeb: Implement pausing the event loop a bit closer to the spec

Namely, this is to update the rendering before pausing the event loop.
This commit is contained in:
Timothy Flynn 2024-11-05 08:54:10 -05:00 committed by Andreas Kling
commit f4111ef1e1
Notes: github-actions[bot] 2024-11-06 09:51:32 +00:00
3 changed files with 60 additions and 6 deletions

View file

@ -7,10 +7,13 @@
#pragma once
#include <AK/Function.h>
#include <AK/Noncopyable.h>
#include <AK/WeakPtr.h>
#include <LibCore/Forward.h>
#include <LibJS/Forward.h>
#include <LibJS/Heap/GCPtr.h>
#include <LibWeb/HTML/EventLoop/TaskQueue.h>
#include <LibWeb/HighResolutionTime/DOMHighResTimeStamp.h>
namespace Web::HTML {
@ -18,6 +21,18 @@ class EventLoop : public JS::Cell {
JS_CELL(EventLoop, JS::Cell);
JS_DECLARE_ALLOCATOR(EventLoop);
struct PauseHandle {
PauseHandle(EventLoop&, JS::Object const& global, HighResolutionTime::DOMHighResTimeStamp);
~PauseHandle();
AK_MAKE_NONCOPYABLE(PauseHandle);
AK_MAKE_NONMOVABLE(PauseHandle);
JS::NonnullGCPtr<EventLoop> event_loop;
JS::NonnullGCPtr<JS::Object const> global;
HighResolutionTime::DOMHighResTimeStamp const time_before_pause;
};
public:
enum class Type {
// https://html.spec.whatwg.org/multipage/webappapis.html#window-event-loop
@ -71,8 +86,8 @@ public:
double compute_deadline() const;
// https://html.spec.whatwg.org/multipage/webappapis.html#pause
void set_execution_paused(bool execution_paused) { m_execution_paused = execution_paused; }
[[nodiscard]] PauseHandle pause();
void unpause(Badge<PauseHandle>, JS::Object const& global, HighResolutionTime::DOMHighResTimeStamp);
bool execution_paused() const { return m_execution_paused; }
private: