From 85b27820525264b0069e58ae776d7a7dfeeb3a01 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 29 Aug 2023 10:48:48 -0400 Subject: [PATCH] Ladybird: Do not scroll the AppKit web view beyond its document rect For example, the JavaScript console will invoke window.scrollTo(0, INF) to scroll to the bottom of the console after updating its contents. The NSScrollView being scrolled here seems to behave oddly if we scroll beyond its limit (e.g. mouse events stop working). Prevent this by limiting scrolling to the NSScrollView's document rect. --- Ladybird/AppKit/UI/LadybirdWebView.mm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Ladybird/AppKit/UI/LadybirdWebView.mm b/Ladybird/AppKit/UI/LadybirdWebView.mm index ce49a5ce4c..787e21011a 100644 --- a/Ladybird/AppKit/UI/LadybirdWebView.mm +++ b/Ladybird/AppKit/UI/LadybirdWebView.mm @@ -244,7 +244,17 @@ struct HideCursor { }; m_web_view_bridge->on_scroll_to_point = [self](auto position) { - [self scrollToPoint:Ladybird::gfx_point_to_ns_point(position)]; + auto content_rect = [self frame]; + auto document_rect = [[self documentView] frame]; + auto ns_position = Ladybird::gfx_point_to_ns_point(position); + + ns_position.x = max(ns_position.x, document_rect.origin.x); + ns_position.x = min(ns_position.x, document_rect.size.width - content_rect.size.width); + + ns_position.y = max(ns_position.y, document_rect.origin.y); + ns_position.y = min(ns_position.y, document_rect.size.height - content_rect.size.height); + + [self scrollToPoint:ns_position]; [[self scrollView] reflectScrolledClipView:self]; [self updateViewportRect:Ladybird::WebViewBridge::ForResize::No]; };