mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 15:27:34 +00:00
LibWeb+WebContent: Add abstraction layer for event loop and timers
Instead of using Core::EventLoop and Core::Timer directly, LibWeb now goes through a Web::Platform abstraction layer instead. This will allow us to plug in Qt's event loop (and QTimer) over in Ladybird, to avoid having to deal with multiple event loops.
This commit is contained in:
parent
7e5a8bd4b0
commit
9567e211e7
28 changed files with 365 additions and 42 deletions
|
@ -8,8 +8,8 @@
|
|||
|
||||
#include <AK/Function.h>
|
||||
#include <AK/IDAllocator.h>
|
||||
#include <LibCore/Timer.h>
|
||||
#include <LibWeb/HTML/EventLoop/EventLoop.h>
|
||||
#include <LibWeb/Platform/Timer.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
@ -18,7 +18,7 @@ struct AnimationFrameCallbackDriver {
|
|||
|
||||
AnimationFrameCallbackDriver()
|
||||
{
|
||||
m_timer = Core::Timer::create_single_shot(16, [] {
|
||||
m_timer = Platform::Timer::create_single_shot(16, [] {
|
||||
HTML::main_thread_event_loop().schedule();
|
||||
});
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ struct AnimationFrameCallbackDriver {
|
|||
private:
|
||||
HashMap<i32, Callback> m_callbacks;
|
||||
IDAllocator m_id_allocator;
|
||||
RefPtr<Core::Timer> m_timer;
|
||||
RefPtr<Platform::Timer> m_timer;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -229,7 +229,7 @@ BrowsingContext::BrowsingContext(Page& page, HTML::BrowsingContextContainer* con
|
|||
, m_event_handler({}, *this)
|
||||
, m_container(container)
|
||||
{
|
||||
m_cursor_blink_timer = Core::Timer::construct(500, [this] {
|
||||
m_cursor_blink_timer = Platform::Timer::create_repeating(500, [this] {
|
||||
if (!is_focused_context())
|
||||
return;
|
||||
if (m_cursor_position.node() && m_cursor_position.node()->layout_node()) {
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include <AK/Noncopyable.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <LibCore/Timer.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibGfx/Rect.h>
|
||||
#include <LibGfx/Size.h>
|
||||
|
@ -20,6 +19,7 @@
|
|||
#include <LibWeb/HTML/SessionHistoryEntry.h>
|
||||
#include <LibWeb/Loader/FrameLoader.h>
|
||||
#include <LibWeb/Page/EventHandler.h>
|
||||
#include <LibWeb/Platform/Timer.h>
|
||||
#include <LibWeb/TreeNode.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
@ -148,7 +148,7 @@ private:
|
|||
Gfx::IntPoint m_viewport_scroll_offset;
|
||||
|
||||
DOM::Position m_cursor_position;
|
||||
RefPtr<Core::Timer> m_cursor_blink_timer;
|
||||
RefPtr<Platform::Timer> m_cursor_blink_timer;
|
||||
bool m_cursor_blink_state { false };
|
||||
|
||||
HashTable<ViewportClient*> m_viewport_clients;
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibCore/EventLoop.h>
|
||||
#include <LibCore/Timer.h>
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
|
@ -15,6 +13,8 @@
|
|||
#include <LibWeb/HTML/Scripting/Environments.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/HighResolutionTime/Performance.h>
|
||||
#include <LibWeb/Platform/EventLoopPlugin.h>
|
||||
#include <LibWeb/Platform/Timer.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
@ -29,7 +29,7 @@ EventLoop::~EventLoop() = default;
|
|||
void EventLoop::schedule()
|
||||
{
|
||||
if (!m_system_event_loop_timer) {
|
||||
m_system_event_loop_timer = Core::Timer::create_single_shot(0, [this] {
|
||||
m_system_event_loop_timer = Platform::Timer::create_single_shot(0, [this] {
|
||||
process();
|
||||
});
|
||||
}
|
||||
|
@ -74,13 +74,7 @@ void EventLoop::spin_until(Function<bool()> goal_condition)
|
|||
// NOTE: This is achieved by returning from the function.
|
||||
|
||||
// 1. Wait until the condition goal is met.
|
||||
Core::EventLoop loop;
|
||||
loop.spin_until([&]() -> bool {
|
||||
if (goal_condition())
|
||||
return true;
|
||||
|
||||
return goal_condition();
|
||||
});
|
||||
Platform::EventLoopPlugin::the().spin_until(move(goal_condition));
|
||||
|
||||
// 7. Stop task, allowing whatever algorithm that invoked it to resume.
|
||||
// NOTE: This is achieved by returning from the function.
|
||||
|
|
|
@ -84,7 +84,7 @@ private:
|
|||
|
||||
JS::VM* m_vm { nullptr };
|
||||
|
||||
RefPtr<Core::Timer> m_system_event_loop_timer;
|
||||
RefPtr<Platform::Timer> m_system_event_loop_timer;
|
||||
|
||||
// https://html.spec.whatwg.org/#performing-a-microtask-checkpoint
|
||||
bool m_performing_a_microtask_checkpoint { false };
|
||||
|
|
|
@ -4,14 +4,14 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibCore/Timer.h>
|
||||
#include <LibWeb/HTML/HTMLBlinkElement.h>
|
||||
#include <LibWeb/Platform/Timer.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
HTMLBlinkElement::HTMLBlinkElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
||||
: HTMLElement(document, move(qualified_name))
|
||||
, m_timer(Core::Timer::construct())
|
||||
, m_timer(Platform::Timer::create())
|
||||
{
|
||||
m_timer->set_interval(500);
|
||||
m_timer->on_timeout = [this] { blink(); };
|
||||
|
|
|
@ -22,7 +22,7 @@ private:
|
|||
|
||||
void blink();
|
||||
|
||||
NonnullRefPtr<Core::Timer> m_timer;
|
||||
NonnullRefPtr<Platform::Timer> m_timer;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibCore/Timer.h>
|
||||
#include <LibWeb/HTML/Timer.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/Platform/Timer.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
@ -20,7 +20,7 @@ Timer::Timer(Window& window, i32 milliseconds, Function<void()> callback, i32 id
|
|||
, m_callback(move(callback))
|
||||
, m_id(id)
|
||||
{
|
||||
m_timer = Core::Timer::create_single_shot(milliseconds, [this] {
|
||||
m_timer = Platform::Timer::create_single_shot(milliseconds, [this] {
|
||||
m_callback();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ private:
|
|||
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
RefPtr<Core::Timer> m_timer;
|
||||
RefPtr<Platform::Timer> m_timer;
|
||||
JS::NonnullGCPtr<Window> m_window;
|
||||
Function<void()> m_callback;
|
||||
i32 m_id { 0 };
|
||||
|
|
|
@ -8,7 +8,9 @@
|
|||
|
||||
#include <AK/Badge.h>
|
||||
#include <AK/IDAllocator.h>
|
||||
#include <AK/NonnullRefPtrVector.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/TypeCasts.h>
|
||||
#include <AK/URL.h>
|
||||
#include <LibJS/Heap/Heap.h>
|
||||
#include <LibWeb/Bindings/CrossOriginAbstractOperations.h>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue