1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:57:44 +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

@ -144,19 +144,20 @@ public:
void set_visited_link_color(Color);
void force_layout();
void invalidate_layout();
void ensure_layout();
void update_style();
void update_layout();
void set_needs_layout();
virtual bool is_child_allowed(const Node&) const override;
const Layout::InitialContainingBlock* layout_node() const;
Layout::InitialContainingBlock* layout_node();
void schedule_style_update();
void schedule_forced_layout();
void schedule_layout_update();
NonnullRefPtr<HTMLCollection> get_elements_by_name(String const&);
NonnullRefPtr<HTMLCollection> get_elements_by_class_name(FlyString const&);
@ -352,7 +353,7 @@ private:
Optional<Color> m_visited_link_color;
RefPtr<Core::Timer> m_style_update_timer;
RefPtr<Core::Timer> m_forced_layout_timer;
RefPtr<Core::Timer> m_layout_update_timer;
String m_source;
@ -399,6 +400,8 @@ private:
// Used by evaluate_media_queries_and_report_changes().
Vector<WeakPtr<CSS::MediaQueryList>> m_media_query_lists;
bool m_needs_layout { false };
};
}