diff options
author | Andreas Kling <kling@serenityos.org> | 2021-02-09 22:40:16 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-09 22:40:16 +0100 |
commit | f24b674d7ad052e6eb68600fd7dddfd692920143 (patch) | |
tree | e6ea5b2bcb417046fe62013aa072f98e1ab33d4f | |
parent | 964894dee628ac88a2e9c27a0f97fa75a6747e48 (diff) | |
download | serenity-f24b674d7ad052e6eb68600fd7dddfd692920143.zip |
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.
-rw-r--r-- | Userland/Libraries/LibWeb/Page/Frame.cpp | 22 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Page/Frame.h | 1 | ||||
-rw-r--r-- | Userland/Services/WebContent/PageHost.cpp | 5 |
3 files changed, 24 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWeb/Page/Frame.cpp b/Userland/Libraries/LibWeb/Page/Frame.cpp index 29decc7d08..ac1cbb8c4c 100644 --- a/Userland/Libraries/LibWeb/Page/Frame.cpp +++ b/Userland/Libraries/LibWeb/Page/Frame.cpp @@ -108,6 +108,28 @@ void Frame::set_document(DOM::Document* 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) { if (m_size == size) diff --git a/Userland/Libraries/LibWeb/Page/Frame.h b/Userland/Libraries/LibWeb/Page/Frame.h index aad2e566b8..eae2e89692 100644 --- a/Userland/Libraries/LibWeb/Page/Frame.h +++ b/Userland/Libraries/LibWeb/Page/Frame.h @@ -73,6 +73,7 @@ public: void set_viewport_scroll_offset(const Gfx::IntPoint&); Gfx::IntRect viewport_rect() const { return { m_viewport_scroll_offset, m_size }; } + void set_viewport_rect(const Gfx::IntRect&); void did_scroll(Badge<InProcessWebView>); diff --git a/Userland/Services/WebContent/PageHost.cpp b/Userland/Services/WebContent/PageHost.cpp index d37ff61054..929cfac044 100644 --- a/Userland/Services/WebContent/PageHost.cpp +++ b/Userland/Services/WebContent/PageHost.cpp @@ -100,10 +100,7 @@ void PageHost::paint(const Gfx::IntRect& content_rect, Gfx::Bitmap& target) void PageHost::set_viewport_rect(const Gfx::IntRect& rect) { - page().main_frame().set_size(rect.size()); - if (page().main_frame().document()) - page().main_frame().document()->update_layout(); - page().main_frame().set_viewport_scroll_offset(rect.location()); + page().main_frame().set_viewport_rect(rect); } void PageHost::page_did_invalidate(const Gfx::IntRect& content_rect) |