1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:37:35 +00:00

LibWeb: Make CSS layout lazier

Instead of doing layout synchronously whenever something changes,
we now use a basic event loop timer to defer and coalesce relayouts.

If you did something that requires a relayout of the page, make sure
to call Document::set_needs_layout() and it will get coalesced with all
the other layout updates.

There's lots of room for improvement here, but this already makes many
web pages significantly snappier. :^)

Also, note that this exposes a number of layout bugs where we have been
relying on multiple relayouts to calculate the correct dimensions for
things. Now that we only do a single layout in many cases, these kind of
problems are much more noticeable. That should also make them easier to
figure out and fix. :^)
This commit is contained in:
Andreas Kling 2021-10-05 22:30:53 +02:00
parent 228a32effc
commit 0264ae23bc
10 changed files with 32 additions and 23 deletions

View file

@ -82,6 +82,8 @@ void BrowsingContext::set_viewport_rect(Gfx::IntRect const& rect)
if (m_size != rect.size()) {
m_size = rect.size();
if (auto* document = active_document())
document->set_needs_layout();
did_change = true;
}
@ -105,6 +107,9 @@ void BrowsingContext::set_size(Gfx::IntSize const& size)
return;
m_size = size;
if (auto* document = active_document())
document->set_needs_layout();
for (auto* client : m_viewport_clients)
client->browsing_context_did_set_viewport_rect(viewport_rect());