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.
This commit is contained in:
Timothy Flynn 2023-08-29 10:48:48 -04:00 committed by Andrew Kaster
parent 1ffe0d3590
commit 85b2782052
Notes: sideshowbarker 2024-07-17 14:33:07 +09:00

View file

@ -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];
};