mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 02:37:35 +00:00
LibWeb: Let HTML::EventLoop keep track of live DOM::Document objects
This will be used by the event loop processing model.
This commit is contained in:
parent
6f0d7245d7
commit
ae71e5f99b
3 changed files with 36 additions and 0 deletions
|
@ -34,6 +34,7 @@
|
||||||
#include <LibWeb/DOM/Window.h>
|
#include <LibWeb/DOM/Window.h>
|
||||||
#include <LibWeb/Dump.h>
|
#include <LibWeb/Dump.h>
|
||||||
#include <LibWeb/HTML/AttributeNames.h>
|
#include <LibWeb/HTML/AttributeNames.h>
|
||||||
|
#include <LibWeb/HTML/EventLoop/EventLoop.h>
|
||||||
#include <LibWeb/HTML/EventNames.h>
|
#include <LibWeb/HTML/EventNames.h>
|
||||||
#include <LibWeb/HTML/HTMLAnchorElement.h>
|
#include <LibWeb/HTML/HTMLAnchorElement.h>
|
||||||
#include <LibWeb/HTML/HTMLAreaElement.h>
|
#include <LibWeb/HTML/HTMLAreaElement.h>
|
||||||
|
@ -70,6 +71,8 @@ Document::Document(const AK::URL& url)
|
||||||
, m_implementation(DOMImplementation::create(*this))
|
, m_implementation(DOMImplementation::create(*this))
|
||||||
, m_history(HTML::History::create(*this))
|
, m_history(HTML::History::create(*this))
|
||||||
{
|
{
|
||||||
|
HTML::main_thread_event_loop().register_document({}, *this);
|
||||||
|
|
||||||
m_style_update_timer = Core::Timer::create_single_shot(0, [this] {
|
m_style_update_timer = Core::Timer::create_single_shot(0, [this] {
|
||||||
update_style();
|
update_style();
|
||||||
});
|
});
|
||||||
|
@ -131,6 +134,9 @@ void Document::removed_last_ref()
|
||||||
|
|
||||||
m_in_removed_last_ref = false;
|
m_in_removed_last_ref = false;
|
||||||
m_deletion_has_begun = true;
|
m_deletion_has_begun = true;
|
||||||
|
|
||||||
|
HTML::main_thread_event_loop().unregister_document({}, *this);
|
||||||
|
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <LibCore/Timer.h>
|
#include <LibCore/Timer.h>
|
||||||
#include <LibJS/Runtime/VM.h>
|
#include <LibJS/Runtime/VM.h>
|
||||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||||
|
#include <LibWeb/DOM/Document.h>
|
||||||
#include <LibWeb/HTML/EventLoop/EventLoop.h>
|
#include <LibWeb/HTML/EventLoop/EventLoop.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
@ -242,4 +243,25 @@ void EventLoop::perform_a_microtask_checkpoint()
|
||||||
m_performing_a_microtask_checkpoint = false;
|
m_performing_a_microtask_checkpoint = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NonnullRefPtrVector<DOM::Document> EventLoop::documents_in_this_event_loop() const
|
||||||
|
{
|
||||||
|
NonnullRefPtrVector<DOM::Document> documents;
|
||||||
|
for (auto& document : m_documents) {
|
||||||
|
VERIFY(document);
|
||||||
|
documents.append(*document);
|
||||||
|
}
|
||||||
|
return documents;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventLoop::register_document(Badge<DOM::Document>, DOM::Document& document)
|
||||||
|
{
|
||||||
|
m_documents.append(&document);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventLoop::unregister_document(Badge<DOM::Document>, DOM::Document& document)
|
||||||
|
{
|
||||||
|
bool did_remove = m_documents.remove_first_matching([&](auto& entry) { return entry.ptr() == &document; });
|
||||||
|
VERIFY(did_remove);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
|
#include <AK/WeakPtr.h>
|
||||||
#include <LibCore/Forward.h>
|
#include <LibCore/Forward.h>
|
||||||
#include <LibJS/Forward.h>
|
#include <LibJS/Forward.h>
|
||||||
#include <LibWeb/HTML/EventLoop/TaskQueue.h>
|
#include <LibWeb/HTML/EventLoop/TaskQueue.h>
|
||||||
|
@ -49,6 +50,11 @@ public:
|
||||||
|
|
||||||
void perform_a_microtask_checkpoint();
|
void perform_a_microtask_checkpoint();
|
||||||
|
|
||||||
|
void register_document(Badge<DOM::Document>, DOM::Document&);
|
||||||
|
void unregister_document(Badge<DOM::Document>, DOM::Document&);
|
||||||
|
|
||||||
|
NonnullRefPtrVector<DOM::Document> documents_in_this_event_loop() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Type m_type { Type::Window };
|
Type m_type { Type::Window };
|
||||||
|
|
||||||
|
@ -64,6 +70,8 @@ private:
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/#performing-a-microtask-checkpoint
|
// https://html.spec.whatwg.org/#performing-a-microtask-checkpoint
|
||||||
bool m_performing_a_microtask_checkpoint { false };
|
bool m_performing_a_microtask_checkpoint { false };
|
||||||
|
|
||||||
|
Vector<WeakPtr<DOM::Document>> m_documents;
|
||||||
};
|
};
|
||||||
|
|
||||||
EventLoop& main_thread_event_loop();
|
EventLoop& main_thread_event_loop();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue