mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
LibWeb: Stop calling Window::scroll_by() during layout
Replace the Window::scroll_by(0, 0) call at the end of Document::update_layout() with a dedicated Navigable::clamp_viewport_scroll_offset() that directly clamps the viewport scroll offset to valid bounds. The old approach re-entered layout from within layout, since scroll_by() would trigger another layout update. The new approach is called from the event loop's rendering steps, after layout is complete.
This commit is contained in:
committed by
Andreas Kling
parent
74109d2f6b
commit
787a83b50a
Notes:
github-actions[bot]
2026-02-26 20:11:24 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/787a83b50ab Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8182
@@ -2622,6 +2622,26 @@ void Navigable::set_viewport_size(CSSPixelSize size, InvalidateDisplayList inval
|
||||
}
|
||||
}
|
||||
|
||||
void Navigable::clamp_viewport_scroll_offset()
|
||||
{
|
||||
auto document = active_document();
|
||||
if (!document)
|
||||
return;
|
||||
if (!document->paintable_box())
|
||||
return;
|
||||
auto scrollable_overflow_rect = document->paintable_box()->scrollable_overflow_rect();
|
||||
if (!scrollable_overflow_rect.has_value())
|
||||
return;
|
||||
auto max_x = scrollable_overflow_rect->width() - m_viewport_size.width();
|
||||
auto max_y = scrollable_overflow_rect->height() - m_viewport_size.height();
|
||||
CSSPixelPoint clamped = {
|
||||
max(CSSPixels(0), min(m_viewport_scroll_offset.x(), max_x)),
|
||||
max(CSSPixels(0), min(m_viewport_scroll_offset.y(), max_y)),
|
||||
};
|
||||
if (clamped != m_viewport_scroll_offset)
|
||||
perform_scroll_of_viewport_scrolling_box(clamped);
|
||||
}
|
||||
|
||||
void Navigable::perform_scroll_of_viewport_scrolling_box(CSSPixelPoint new_position)
|
||||
{
|
||||
// NB: This method is ad-hoc, but is currently called where "perform a scroll of a scrolling box" would be,
|
||||
|
||||
Reference in New Issue
Block a user