LibWeb/HTML: Return Promises from Window scroll methods

Corresponds to part of:
c548a9a1d4
This commit is contained in:
Sam Atkins
2025-12-18 16:45:18 +00:00
committed by Alexander Kalenik
parent cae526286a
commit a610639119
Notes: github-actions[bot] 2025-12-23 13:25:39 +00:00
7 changed files with 95 additions and 56 deletions

View File

@@ -2784,7 +2784,7 @@ RefPtr<Gfx::SkiaBackendContext> Navigable::skia_backend_context() const
}
// https://drafts.csswg.org/cssom-view/#viewport-perform-a-scroll
void Navigable::scroll_viewport_by_delta(CSSPixelPoint delta)
GC::Ref<WebIDL::Promise> Navigable::scroll_viewport_by_delta(CSSPixelPoint delta)
{
// 1. Let doc be the viewports associated Document.
auto doc = active_document();
@@ -2828,9 +2828,13 @@ void Navigable::scroll_viewport_by_delta(CSSPixelPoint delta)
// 13. Let element be docs root element if there is one, null otherwise.
// 14. Perform a scroll of the viewports scrolling box to its current scroll position + (layout dx, layout dy) with element as the associated element, and behavior as the scroll behavior.
// 14. Perform a scroll of the viewports scrolling box to its current scroll position + (layout dx, layout dy)
// with element as the associated element, and behavior as the scroll behavior. Let scrollPromise1 be the
// Promise returned from this step.
// FIXME: Get a Promise from this.
// AD-HOC: Skip scrolling unscrollable boxes.
if (!doc->paintable_box()->could_be_scrolled_by_wheel_event())
return;
return WebIDL::create_resolved_promise(doc->realm(), JS::js_undefined());
auto scrolling_area = doc->paintable_box()->scrollable_overflow_rect()->to_type<float>();
auto new_viewport_scroll_offset = m_viewport_scroll_offset.to_type<double>() + Gfx::Point(layout_dx, layout_dy);
// NOTE: Clamp to the scrolling area.
@@ -2838,9 +2842,21 @@ void Navigable::scroll_viewport_by_delta(CSSPixelPoint delta)
new_viewport_scroll_offset.set_y(max(0.0, min(new_viewport_scroll_offset.y(), scrolling_area.height() - viewport_size().height().to_double())));
perform_scroll_of_viewport(new_viewport_scroll_offset.to_type<CSSPixels>());
// 15. Perform a scroll of vvs scrolling box to its current scroll position + (visual dx, visual dy) with element as the associated element, and behavior as the scroll behavior.
// 15. Perform a scroll of vvs scrolling box to its current scroll position + (visual dx, visual dy) with element
// as the associated element, and behavior as the scroll behavior. Let scrollPromise2 be the Promise returned
// from this step.
// FIXME: Get a Promise from this.
vv->scroll_by({ visual_dx, visual_dy });
doc->set_needs_display(InvalidateDisplayList::No);
// 16. Let scrollPromise be a new Promise.
auto scroll_promise = WebIDL::create_promise(doc->realm());
// 17. Return scrollPromise, and run the remaining steps in parallel.
// 18. Resolve scrollPromise when both scrollPromise1 and scrollPromise2 have settled.
// FIXME: Actually wait for scroll to occur. For now, all our scrolls are instant.
WebIDL::resolve_promise(doc->realm(), scroll_promise);
return scroll_promise;
}
void Navigable::reset_zoom()