1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 01:17:34 +00:00

LibWeb+WebContent: Don't relayout page on every scroll event

The WebContent process was redoing page layout every time you scrolled
the page. This was a huge CPU hog for no reason. Fix this by only doing
a relayout when the viewport is resized, not when it moves around.
This commit is contained in:
Andreas Kling 2021-02-09 22:40:16 +01:00
parent 964894dee6
commit f24b674d7a
3 changed files with 24 additions and 4 deletions

View file

@ -108,6 +108,28 @@ void Frame::set_document(DOM::Document* document)
m_page->client().page_did_set_document_in_main_frame(m_document); m_page->client().page_did_set_document_in_main_frame(m_document);
} }
void Frame::set_viewport_rect(const Gfx::IntRect& rect)
{
bool did_change = false;
if (m_size != rect.size()) {
m_size = rect.size();
if (m_document)
m_document->update_layout();
did_change = true;
}
if (m_viewport_scroll_offset != rect.location()) {
m_viewport_scroll_offset = rect.location();
did_change = true;
}
if (did_change) {
for (auto* client : m_viewport_clients)
client->frame_did_set_viewport_rect(rect);
}
}
void Frame::set_size(const Gfx::IntSize& size) void Frame::set_size(const Gfx::IntSize& size)
{ {
if (m_size == size) if (m_size == size)

View file

@ -73,6 +73,7 @@ public:
void set_viewport_scroll_offset(const Gfx::IntPoint&); void set_viewport_scroll_offset(const Gfx::IntPoint&);
Gfx::IntRect viewport_rect() const { return { m_viewport_scroll_offset, m_size }; } Gfx::IntRect viewport_rect() const { return { m_viewport_scroll_offset, m_size }; }
void set_viewport_rect(const Gfx::IntRect&);
void did_scroll(Badge<InProcessWebView>); void did_scroll(Badge<InProcessWebView>);

View file

@ -100,10 +100,7 @@ void PageHost::paint(const Gfx::IntRect& content_rect, Gfx::Bitmap& target)
void PageHost::set_viewport_rect(const Gfx::IntRect& rect) void PageHost::set_viewport_rect(const Gfx::IntRect& rect)
{ {
page().main_frame().set_size(rect.size()); page().main_frame().set_viewport_rect(rect);
if (page().main_frame().document())
page().main_frame().document()->update_layout();
page().main_frame().set_viewport_scroll_offset(rect.location());
} }
void PageHost::page_did_invalidate(const Gfx::IntRect& content_rect) void PageHost::page_did_invalidate(const Gfx::IntRect& content_rect)