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:
Andreas Kling
2026-02-26 11:36:17 +01:00
committed by Andreas Kling
parent 74109d2f6b
commit 787a83b50a
Notes: github-actions[bot] 2026-02-26 20:11:24 +00:00
4 changed files with 26 additions and 5 deletions

View File

@@ -449,6 +449,11 @@ void EventLoop::update_the_rendering()
// NOTE: Recalculation of styles is handled by update_layout()
document->update_layout(DOM::UpdateLayoutReason::HTMLEventLoopRenderingUpdate);
// Clamp viewport scroll offset to valid range after layout, in case the
// scrollable overflow area has shrunk (e.g. after a viewport size change).
if (auto navigable = document->navigable())
navigable->clamp_viewport_scroll_offset();
// 2. Let hadInitialVisibleContentVisibilityDetermination be false.
bool had_initial_visible_content_visibility_determination = false;