From 96d67ded3ed6c34862deda119f7beda0220a0be5 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Wed, 20 Mar 2024 18:19:58 +0100 Subject: [PATCH] LibWeb: Always run layout and style updates from event loop processing Before this change, we ran style and layout updates from both event loop processing and update timers. This could have caused missed resize observer updates and unnecessary updating of style or layout more than once before repaint. Also, we can now be sure unnecessary style or layout updates won't happen in `EventLoop::spin_processing_tasks_with_source_until()`. --- Userland/Libraries/LibWeb/DOM/Document.cpp | 20 ++++---------------- Userland/Libraries/LibWeb/DOM/Document.h | 3 --- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 7d34316b529..717d83932d0 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -356,14 +356,6 @@ Document::Document(JS::Realm& realm, const URL::URL& url) }; HTML::main_thread_event_loop().register_document({}, *this); - - m_style_update_timer = Core::Timer::create_single_shot(0, [this] { - update_style(); - }).release_value_but_fixme_should_propagate_errors(); - - m_layout_update_timer = Core::Timer::create_single_shot(0, [this] { - update_layout(); - }).release_value_but_fixme_should_propagate_errors(); } Document::~Document() @@ -681,16 +673,14 @@ void Document::set_origin(HTML::Origin const& origin) void Document::schedule_style_update() { - if (m_style_update_timer->is_active()) - return; - m_style_update_timer->start(); + // NOTE: Update of the style is a step in HTML event loop processing. + HTML::main_thread_event_loop().schedule(); } void Document::schedule_layout_update() { - if (m_layout_update_timer->is_active()) - return; - m_layout_update_timer->start(); + // NOTE: Update of the layout is a step in HTML event loop processing. + HTML::main_thread_event_loop().schedule(); } bool Document::is_child_allowed(Node const& node) const @@ -1113,7 +1103,6 @@ void Document::update_layout() paintable()->recompute_selection_states(); m_needs_layout = false; - m_layout_update_timer->stop(); } [[nodiscard]] static CSS::RequiredInvalidationAfterStyleChange update_style_recursively(Node& node) @@ -1196,7 +1185,6 @@ void Document::update_style() invalidate_stacking_context_tree(); } m_needs_full_style_update = false; - m_style_update_timer->stop(); } void Document::update_paint_and_hit_testing_properties_if_needed() diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index 2c7eb1a7449..b8fc0f29ee5 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -656,9 +656,6 @@ private: Optional m_active_link_color; Optional m_visited_link_color; - RefPtr m_style_update_timer; - RefPtr m_layout_update_timer; - JS::GCPtr m_parser; bool m_active_parser_was_aborted { false };