From 68271c4fcea40aefb263ce4d5b195742d3a26ef4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 14 May 2023 17:26:40 +0200 Subject: [PATCH] Ladybird: Floor the WebContentView viewport offset at 0, 0 This fixes an unpleasant visual glitch when resizing the window. When the user makes our QAbstractScrollArea larger, the scroll bars can end up with negative values, which we were happily forwarding to the WebContent process and asking it to paint the whole page at an offset. --- Ladybird/WebContentView.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp index 6e6a3ff840..1368343ef5 100644 --- a/Ladybird/WebContentView.cpp +++ b/Ladybird/WebContentView.cpp @@ -397,12 +397,12 @@ void WebContentView::focusOutEvent(QFocusEvent*) Gfx::IntPoint WebContentView::to_content(Gfx::IntPoint viewport_position) const { - return viewport_position.translated(horizontalScrollBar()->value(), verticalScrollBar()->value()); + return viewport_position.translated(max(0, horizontalScrollBar()->value()), max(0, verticalScrollBar()->value())); } Gfx::IntPoint WebContentView::to_widget(Gfx::IntPoint content_position) const { - return content_position.translated(-horizontalScrollBar()->value(), -verticalScrollBar()->value()); + return content_position.translated(-(max(0, horizontalScrollBar()->value())), -(max(0, verticalScrollBar()->value()))); } void WebContentView::paintEvent(QPaintEvent*) @@ -484,7 +484,7 @@ void WebContentView::update_viewport_rect() { auto scaled_width = int(viewport()->width() / m_inverse_pixel_scaling_ratio); auto scaled_height = int(viewport()->height() / m_inverse_pixel_scaling_ratio); - Gfx::IntRect rect(horizontalScrollBar()->value(), verticalScrollBar()->value(), scaled_width, scaled_height); + Gfx::IntRect rect(max(0, horizontalScrollBar()->value()), max(0, verticalScrollBar()->value()), scaled_width, scaled_height); set_viewport_rect(rect); @@ -787,8 +787,8 @@ void WebContentView::notify_server_did_change_title(Badge, Dep void WebContentView::notify_server_did_request_scroll(Badge, i32 x_delta, i32 y_delta) { - horizontalScrollBar()->setValue(horizontalScrollBar()->value() + x_delta); - verticalScrollBar()->setValue(verticalScrollBar()->value() + y_delta); + horizontalScrollBar()->setValue(max(0, horizontalScrollBar()->value() + x_delta)); + verticalScrollBar()->setValue(max(0, verticalScrollBar()->value() + y_delta)); } void WebContentView::notify_server_did_request_scroll_to(Badge, Gfx::IntPoint scroll_position)