mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
LibWeb/HTML: Return Promises from Window scroll methods
Corresponds to part of:
c548a9a1d4
This commit is contained in:
committed by
Alexander Kalenik
parent
cae526286a
commit
a610639119
Notes:
github-actions[bot]
2025-12-23 13:25:39 +00:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/LadybirdBrowser/ladybird/commit/a6106391196 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7184 Reviewed-by: https://github.com/kalenikaliaksandr ✅
@@ -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 viewport’s associated Document.
|
||||
auto doc = active_document();
|
||||
@@ -2828,9 +2828,13 @@ void Navigable::scroll_viewport_by_delta(CSSPixelPoint delta)
|
||||
|
||||
// 13. Let element be doc’s root element if there is one, null otherwise.
|
||||
|
||||
// 14. Perform a scroll of the viewport’s 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 viewport’s 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 vv’s 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 vv’s 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()
|
||||
|
||||
Reference in New Issue
Block a user