Skip to content

Truly independent web browser

Everywhere: End a script's instant scroll once the compositor answers

Zaggy1024ff500d83ba6c
diff --git a/Libraries/LibCompositing/Types.cpp b/Libraries/LibCompositing/Types.cpp
index da763e8d363..afb65653bce 100644
--- a/Libraries/LibCompositing/Types.cpp
+++ b/Libraries/LibCompositing/Types.cpp
@@ -138,6 +138,23 @@ ErrorOr<Compositing::StartedUserScroll> decode(Decoder& decoder)
};
}
+template<>
+ErrorOr<void> encode(Encoder& encoder, Compositing::AppliedScrollRequest const& applied_scroll_request)
+{
+ TRY(encoder.encode(applied_scroll_request.stable_node_id));
+ TRY(encoder.encode(applied_scroll_request.request_id));
+ return {};
+}
+
+template<>
+ErrorOr<Compositing::AppliedScrollRequest> decode(Decoder& decoder)
+{
+ return Compositing::AppliedScrollRequest {
+ .stable_node_id = TRY(decoder.decode<Web::AsyncScrollNodeStableID>()),
+ .request_id = TRY(decoder.decode<u64>()),
+ };
+}
+
template<>
ErrorOr<void> encode(Encoder& encoder, Compositing::PendingAsyncScrollUpdates const& updates)
{
@@ -147,6 +164,7 @@ ErrorOr<void> encode(Encoder& encoder, Compositing::PendingAsyncScrollUpdates co
TRY(encoder.encode(updates.completed_operation_ids));
TRY(encoder.encode(updates.operation_ids_taken_over_by_user_input));
TRY(encoder.encode(updates.started_user_scrolls));
+ TRY(encoder.encode(updates.applied_scroll_requests));
TRY(encoder.encode(updates.user_scroll_gesture_in_progress));
TRY(encoder.encode(updates.user_scroll_gesture_ended));
return {};
@@ -162,6 +180,7 @@ ErrorOr<Compositing::PendingAsyncScrollUpdates> decode(Decoder& decoder)
.completed_operation_ids = TRY(decoder.decode<Vector<Compositing::AsyncScrollOperationID>>()),
.operation_ids_taken_over_by_user_input = TRY(decoder.decode<Vector<Compositing::AsyncScrollOperationID>>()),
.started_user_scrolls = TRY(decoder.decode<Vector<Compositing::StartedUserScroll>>()),
+ .applied_scroll_requests = TRY(decoder.decode<Vector<Compositing::AppliedScrollRequest>>()),
.user_scroll_gesture_in_progress = TRY(decoder.decode<bool>()),
.user_scroll_gesture_ended = TRY(decoder.decode<bool>()),
};
diff --git a/Libraries/LibCompositing/Types.h b/Libraries/LibCompositing/Types.h
index a3945f13758..ac36bdff99c 100644
--- a/Libraries/LibCompositing/Types.h
+++ b/Libraries/LibCompositing/Types.h
@@ -77,6 +77,12 @@ struct KeyboardScrollState {
float arrow_scroll_distance { 0 };
};
+// A scroll request the compositor applied, which it tells the main thread of whether or not the box is there.
+struct AppliedScrollRequest {
+ Web::AsyncScrollNodeStableID stable_node_id;
+ u64 request_id { 0 };
+};
+
struct PendingAsyncScrollUpdates {
Optional<Web::UniqueNodeID> document_id;
// The publication these updates were handed out in, per context and increasing. A scroll state
@@ -86,6 +92,7 @@ struct PendingAsyncScrollUpdates {
Vector<AsyncScrollOperationID> completed_operation_ids;
Vector<AsyncScrollOperationID> operation_ids_taken_over_by_user_input;
Vector<StartedUserScroll> started_user_scrolls;
+ Vector<AppliedScrollRequest> applied_scroll_requests;
bool user_scroll_gesture_in_progress { false };
bool user_scroll_gesture_ended { false };
};
@@ -260,6 +267,11 @@ COMPOSITING_API ErrorOr<void> encode(Encoder&, Compositing::StartedUserScroll co
template<>
COMPOSITING_API ErrorOr<Compositing::StartedUserScroll> decode(Decoder&);
+template<>
+COMPOSITING_API ErrorOr<void> encode(Encoder&, Compositing::AppliedScrollRequest const&);
+template<>
+COMPOSITING_API ErrorOr<Compositing::AppliedScrollRequest> decode(Decoder&);
+
template<>
COMPOSITING_API ErrorOr<void> encode(Encoder&, Compositing::PendingAsyncScrollUpdates const&);
template<>
diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.cpp b/Libraries/LibWeb/Compositor/CompositorConnection.cpp
index 94699126702..38466f4f315 100644
--- a/Libraries/LibWeb/Compositor/CompositorConnection.cpp
+++ b/Libraries/LibWeb/Compositor/CompositorConnection.cpp
@@ -592,6 +592,7 @@ Compositing::PendingAsyncScrollUpdates CompositorConnection::take_pending_async_
updates.completed_operation_ids = move(pending->completed_operation_ids);
updates.operation_ids_taken_over_by_user_input = move(pending->operation_ids_taken_over_by_user_input);
updates.started_user_scrolls = move(pending->started_user_scrolls);
+ updates.applied_scroll_requests = move(pending->applied_scroll_requests);
updates.document_id = pending->document_id;
updates.user_scroll_gesture_in_progress = pending->user_scroll_gesture_in_progress;
updates.user_scroll_gesture_ended = pending->user_scroll_gesture_ended;
@@ -601,6 +602,7 @@ Compositing::PendingAsyncScrollUpdates CompositorConnection::take_pending_async_
pending->completed_operation_ids.clear();
pending->operation_ids_taken_over_by_user_input.clear();
pending->started_user_scrolls.clear();
+ pending->applied_scroll_requests.clear();
pending->user_scroll_gesture_ended = false;
return updates;
}
@@ -627,6 +629,7 @@ void CompositorConnection::merge_async_scroll_updates(Web::CompositorContextId c
pending.completed_operation_ids.extend(move(updates.completed_operation_ids));
pending.operation_ids_taken_over_by_user_input.extend(move(updates.operation_ids_taken_over_by_user_input));
pending.started_user_scrolls.extend(move(updates.started_user_scrolls));
+ pending.applied_scroll_requests.extend(move(updates.applied_scroll_requests));
if (is_newest) {
pending.document_id = updates.document_id;
pending.user_scroll_gesture_in_progress = updates.user_scroll_gesture_in_progress;
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index c544bfb1656..29fdbc4a7b9 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -846,6 +846,8 @@ void LocalNavigable::visit_edges(Cell::Visitor& visitor)
for (auto& async_scroll_operation : m_pending_async_scroll_operations)
visitor.visit(async_scroll_operation.promises);
+ for (auto& instant_scroll : m_instant_scrolls_awaiting_answers)
+ visitor.visit(instant_scroll.promise);
for (auto& smooth_scroll : m_main_thread_smooth_scrolls)
visitor.visit(smooth_scroll.promises);
for (auto& entry : m_pending_user_scrollend_targets)
@@ -4956,8 +4958,35 @@ void LocalNavigable::resolve_async_scroll_operation(Compositing::AsyncScrollOper
settle_user_scroll_gesture_if_input_deadline_passed();
}
+// https://drafts.csswg.org/cssom-view-1/#perform-a-scroll
+// 7. If scrollPromise is still in the pending state:
+// 1. If the scroll position changed as a result of this call, emit the scrollend event.
+// 2. Resolve scrollPromise.
+void LocalNavigable::finish_instant_scrolls_answered_by(Compositing::AppliedScrollRequest const& applied_scroll_request)
+{
+ auto document = active_document();
+ m_instant_scrolls_awaiting_answers.remove_all_matching([&](auto const& instant_scroll) {
+ if (instant_scroll.stable_node_id != applied_scroll_request.stable_node_id || instant_scroll.request_id > applied_scroll_request.request_id)
+ return false;
+ auto final_scroll_offset = scroll_offset_for(instant_scroll.stable_node_id);
+ auto target = document ? scroll_event_target_for_async_scroll_node(*document, instant_scroll.stable_node_id) : nullptr;
+ // NB: A user's gesture that holds the box has not completed the scroll, and delivers the event once it does.
+ if (target && final_scroll_offset.has_value() && final_scroll_offset.value() != instant_scroll.initial_scroll_offset
+ && !latched_user_scroll_gesture_for(*target, instant_scroll.stable_node_id)) {
+ document->append_pending_scroll_event({ *target, EventNames::scrollend });
+ page().client().request_frame();
+ }
+ queue_async_scroll_operation_promise_resolution(instant_scroll.promise);
+ return true;
+ });
+}
+
void LocalNavigable::resolve_all_pending_async_scroll_operations()
{
+ for (auto const& instant_scroll : m_instant_scrolls_awaiting_answers)
+ queue_async_scroll_operation_promise_resolution(instant_scroll.promise);
+ m_instant_scrolls_awaiting_answers.clear();
+
while (!m_pending_async_scroll_operations.is_empty()) {
auto pending = finished_scroll(m_pending_async_scroll_operations.take_last());
queue_scrollend_event_and_promise_resolution_for_finished_scroll(pending.stable_node_id, pending.trigger, pending.initial_scroll_offset, pending.promises);
@@ -5619,6 +5648,19 @@ void LocalNavigable::user_scroll_did_settle(UserScrollSettlement settlement)
void LocalNavigable::resolve_pending_smooth_scrolls(Web::AsyncScrollNodeStableID stable_node_id, SmoothScrollAbortCause abort_cause)
{
+ // NB: A script's instant scroll that another scroll of the box replaces before the compositor answered ends with
+ // where this navigable has the box.
+ auto document = active_document();
+ m_instant_scrolls_awaiting_answers.remove_all_matching([&](auto const& instant_scroll) {
+ if (instant_scroll.stable_node_id != stable_node_id)
+ return false;
+ auto target = document ? scroll_event_target_for_async_scroll_node(*document, stable_node_id) : nullptr;
+ if (target && scroll_offset_for(stable_node_id) != instant_scroll.initial_scroll_offset)
+ document->append_pending_scroll_event({ *target, EventNames::scrollend });
+ queue_async_scroll_operation_promise_resolution(instant_scroll.promise);
+ return true;
+ });
+
Vector<FinishedScroll> finished_async_scroll_operations;
m_pending_async_scroll_operations.remove_all_matching([&](auto const& pending) {
if (pending.stable_node_id != stable_node_id)
@@ -5751,12 +5793,14 @@ void LocalNavigable::adopt_pending_async_scroll_offsets(Compositing::AsyncScroll
m_compositor_user_scroll_gesture_hold = nullptr;
};
- if (async_scroll_updates.scroll_offsets.is_empty() && async_scroll_updates.completed_operation_ids.is_empty() && async_scroll_updates.started_user_scrolls.is_empty())
+ if (async_scroll_updates.scroll_offsets.is_empty() && async_scroll_updates.completed_operation_ids.is_empty() && async_scroll_updates.started_user_scrolls.is_empty() && async_scroll_updates.applied_scroll_requests.is_empty())
return;
if (!document) {
for (auto operation_id : async_scroll_updates.completed_operation_ids)
resolve_async_scroll_operation(operation_id);
+ for (auto const& applied_scroll_request : async_scroll_updates.applied_scroll_requests)
+ finish_instant_scrolls_answered_by(applied_scroll_request);
return;
}
@@ -5858,6 +5902,9 @@ void LocalNavigable::adopt_pending_async_scroll_offsets(Compositing::AsyncScroll
if (adopted_any_scroll_offset)
schedule_hover_update_after_async_scroll();
+ for (auto const& applied_scroll_request : async_scroll_updates.applied_scroll_requests)
+ finish_instant_scrolls_answered_by(applied_scroll_request);
+
for (auto operation_id : async_scroll_updates.completed_operation_ids) {
auto completion = async_scroll_updates.operation_ids_taken_over_by_user_input.contains_slow(operation_id)
? AsyncScrollCompletion::TakenOverByUserInput
@@ -7401,6 +7448,16 @@ LocalNavigable::PerformedScroll LocalNavigable::perform_a_scroll_of_a_scrolling_
else
request_scroll_jump(stable_node_id, trigger);
}
+ // The compositor decides where a script's scroll leaves the box, which the scroll ends at once it says.
+ if (has_compositor_context() && trigger == ScrollTrigger::Programmatic) {
+ m_instant_scrolls_awaiting_answers.append({
+ .stable_node_id = stable_node_id,
+ .request_id = last_scroll_request_id_for(stable_node_id),
+ .initial_scroll_offset = *initial_scroll_offset,
+ .promise = scroll_promise,
+ });
+ return { scroll_promise, goes_to_a_snap_position };
+ }
if (did_scroll)
queue_scrollend_event(stable_node_id, trigger, initial_scroll_offset);
WebIDL::resolve_promise(scroll_promise);
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.h b/Libraries/LibWeb/HTML/LocalNavigable.h
index 7b668200940..95d7dc6896d 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.h
+++ b/Libraries/LibWeb/HTML/LocalNavigable.h
@@ -686,6 +686,15 @@ private:
Compositing::ScrollAnimationKind animation_kind { Compositing::ScrollAnimationKind::SmoothScroll };
};
Vector<PendingAsyncScrollOperation> m_pending_async_scroll_operations;
+ // A script's instant scroll, which ends once the compositor answers its request with where the box went.
+ struct InstantScrollAwaitingAnswer {
+ Web::AsyncScrollNodeStableID stable_node_id;
+ u64 request_id { 0 };
+ CSSPixelPoint initial_scroll_offset;
+ GC::Ref<WebIDL::Promise> promise;
+ };
+ Vector<InstantScrollAwaitingAnswer> m_instant_scrolls_awaiting_answers;
+ void finish_instant_scrolls_answered_by(Compositing::AppliedScrollRequest const&);
// The registry entry of an operation, whether the scroll was registered when it was started or is first heard of
// from the compositor's report of it.
PendingAsyncScrollOperation& ensure_pending_async_scroll_operation(Compositing::AsyncScrollOperationID);
diff --git a/Services/Compositor/AsyncScrollUpdateOutbox.cpp b/Services/Compositor/AsyncScrollUpdateOutbox.cpp
index 8622e4504fb..e0eed82927b 100644
--- a/Services/Compositor/AsyncScrollUpdateOutbox.cpp
+++ b/Services/Compositor/AsyncScrollUpdateOutbox.cpp
@@ -34,6 +34,7 @@ bool AsyncScrollUpdateOutbox::has_updates(bool user_scroll_gesture_in_progress)
|| !m_completed_operation_ids.is_empty()
|| !m_operation_ids_taken_over_by_user_input.is_empty()
|| !m_started_user_scrolls.is_empty()
+ || !m_applied_scroll_requests.is_empty()
|| m_user_scroll_gesture_ended
|| user_scroll_gesture_in_progress != m_published_user_scroll_gesture_in_progress;
}
@@ -46,6 +47,7 @@ Compositing::PendingAsyncScrollUpdates AsyncScrollUpdateOutbox::take_updates(boo
AK::swap(updates.completed_operation_ids, m_completed_operation_ids);
AK::swap(updates.operation_ids_taken_over_by_user_input, m_operation_ids_taken_over_by_user_input);
AK::swap(updates.started_user_scrolls, m_started_user_scrolls);
+ AK::swap(updates.applied_scroll_requests, m_applied_scroll_requests);
updates.user_scroll_gesture_in_progress = user_scroll_gesture_in_progress;
updates.user_scroll_gesture_ended = m_user_scroll_gesture_ended;
m_user_scroll_gesture_ended = false;
diff --git a/Services/Compositor/AsyncScrollUpdateOutbox.h b/Services/Compositor/AsyncScrollUpdateOutbox.h
index 81895b5fee4..f87ebbf225f 100644
--- a/Services/Compositor/AsyncScrollUpdateOutbox.h
+++ b/Services/Compositor/AsyncScrollUpdateOutbox.h
@@ -21,6 +21,7 @@ public:
void record_scroll_offsets(ReadonlySpan<Compositing::AsyncScrollOffset>);
void record_started_user_scroll(Compositing::StartedUserScroll started_user_scroll) { m_started_user_scrolls.append(move(started_user_scroll)); }
void note_user_scroll_gesture_ended() { m_user_scroll_gesture_ended = true; }
+ void note_scroll_request_applied(Compositing::AppliedScrollRequest applied_scroll_request) { m_applied_scroll_requests.append(applied_scroll_request); }
bool has_updates(bool user_scroll_gesture_in_progress) const;
Compositing::PendingAsyncScrollUpdates take_updates(bool user_scroll_gesture_in_progress);
@@ -32,6 +33,7 @@ private:
Vector<Compositing::AsyncScrollOperationID> m_completed_operation_ids;
Vector<Compositing::AsyncScrollOperationID> m_operation_ids_taken_over_by_user_input;
Vector<Compositing::StartedUserScroll> m_started_user_scrolls;
+ Vector<Compositing::AppliedScrollRequest> m_applied_scroll_requests;
bool m_user_scroll_gesture_ended { false };
bool m_published_user_scroll_gesture_in_progress { false };
};
diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cpp
index d8d89d6818e..833b9207d36 100644
--- a/Services/Compositor/ContextState.cpp
+++ b/Services/Compositor/ContextState.cpp
@@ -1008,6 +1008,7 @@ Optional<PendingFrame> ContextState::apply_scroll_requests(ReadonlySpan<Composit
for (auto const& scroll_request : scroll_requests) {
// The box's offsets are reported as of this request from here on, whether or not the box is here yet.
m_applied_scroll_request_ids.set(scroll_request.stable_node_id, scroll_request.request_id);
+ m_async_scroll_update_outbox.note_scroll_request_applied({ scroll_request.stable_node_id, scroll_request.request_id });
if (scroll_request.stable_node_id.kind == Web::AsyncScrollNodeKind::VisualViewport) {
apply_visual_viewport_scroll_request(scroll_request, answers);
continue;
@@ -1170,8 +1171,10 @@ Optional<PendingFrame> ContextState::apply_scroll_requests(ReadonlySpan<Composit
answer_with_the_offset_of_the_box();
}
- if (answers.is_empty())
+ if (answers.is_empty()) {
+ request_rendering_update();
return {};
+ }
store_pending_async_scroll_offsets(answers);
if (m_has_async_scrolling_state)
rebuild_wheel_hit_test_targets();
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.ini
index 37256e38a12..c61f4765ff1 100644
--- a/Tests/LibWeb/TestConfig.ini
+++ b/Tests/LibWeb/TestConfig.ini
@@ -1087,6 +1087,9 @@ Text/input/wpt-import/sanitizer-api/sethtmlunsafe-toplevel-template-script.html
Text/input/wpt-import/css/cssom-view/scroll-behavior-default-css.html
Text/input/wpt-import/css/cssom-view/scroll-behavior-scrollintoview-nested.html
Text/input/wpt-import/css/cssom-view/position-sticky-root-scroller-with-scroll-behavior.html
+; Expect an instant scroll's scrollend within a count of frames, which can pass before the compositor answers the scroll
+Text/input/wpt-import/dom/events/scrolling/scrollend-event-fired-after-instant-scroll-in-microtask.html
+Text/input/wpt-import/dom/events/scrolling/scrollend-event-handler-content-attributes.html
; Expects an animation's 1ms delay to elapse within two frames
Text/input/wpt-import/css/css-animations/event-dispatch.tentative.html
; Waits for scrolls that animate in real time, which uncapped frames only spin through
diff --git a/Tests/LibWeb/Text/expected/async-scrolling/instant-script-scroll-of-a-box-gone-before-the-compositor-answers.txt b/Tests/LibWeb/Text/expected/async-scrolling/instant-script-scroll-of-a-box-gone-before-the-compositor-answers.txt
new file mode 100644
index 00000000000..3fc4c9cb9a9
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/async-scrolling/instant-script-scroll-of-a-box-gone-before-the-compositor-answers.txt
@@ -0,0 +1,2 @@
+The scroll of a removed scroller finished
+The scroll of a scroller that stopped being rendered finished
diff --git a/Tests/LibWeb/Text/expected/async-scrolling/script-scroll-during-a-thumb-drag.txt b/Tests/LibWeb/Text/expected/async-scrolling/script-scroll-during-a-thumb-drag.txt
index 24de2f7dfa8..a7caa022a51 100644
--- a/Tests/LibWeb/Text/expected/async-scrolling/script-scroll-during-a-thumb-drag.txt
+++ b/Tests/LibWeb/Text/expected/async-scrolling/script-scroll-during-a-thumb-drag.txt
@@ -1,3 +1,4 @@
dragged away from the top: true
held where the drag left it: true
+scrollend events during the drag: 0
still there once released: true
diff --git a/Tests/LibWeb/Text/input/async-scrolling/hidden-axis-programmatic-scroll-preserved.html b/Tests/LibWeb/Text/input/async-scrolling/hidden-axis-programmatic-scroll-preserved.html
index 47e454a406f..2e7fda874b6 100644
--- a/Tests/LibWeb/Text/input/async-scrolling/hidden-axis-programmatic-scroll-preserved.html
+++ b/Tests/LibWeb/Text/input/async-scrolling/hidden-axis-programmatic-scroll-preserved.html
@@ -20,10 +20,10 @@
<div id="scroller"><div id="spacer"></div></div>
<script>
promiseTest(async () => {
- scroller.scrollLeft = 50;
- scroller.scrollTop = 0;
- await animationFrame();
- await animationFrame();
+ await scrollSettled(scroller, () => {
+ scroller.scrollLeft = 50;
+ scroller.scrollTop = 0;
+ });
println(`initial scrollLeft: ${scroller.scrollLeft}`);
println(`vertical wheel target: ${wheelTargetToString(internals.compositorWheelTargetAt(50, 50, 0, 100))}`);
println(`horizontal wheel target: ${wheelTargetToString(internals.compositorWheelTargetAt(50, 50, 100, 0))}`);
diff --git a/Tests/LibWeb/Text/input/async-scrolling/instant-script-scroll-of-a-box-gone-before-the-compositor-answers.html b/Tests/LibWeb/Text/input/async-scrolling/instant-script-scroll-of-a-box-gone-before-the-compositor-answers.html
new file mode 100644
index 00000000000..29f2ac19075
--- /dev/null
+++ b/Tests/LibWeb/Text/input/async-scrolling/instant-script-scroll-of-a-box-gone-before-the-compositor-answers.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<style>
+ .scroller {
+ width: 100px;
+ height: 100px;
+ overflow: auto;
+ }
+
+ .content {
+ height: 400px;
+ }
+</style>
+<script src="../include.js"></script>
+<div id="removedScroller" class="scroller"><div class="content"></div></div>
+<div id="hiddenScroller" class="scroller"><div class="content"></div></div>
+<script>
+ promiseTest(async () => {
+ await animationFrame();
+ await animationFrame();
+
+ // The compositor has no scroller left to scroll once the box is gone, and answers the scroll without an offset.
+ // That answer still finishes the scroll.
+ const scrollOfRemovedScroller = removedScroller.scrollTo(0, 50);
+ removedScroller.remove();
+ await scrollOfRemovedScroller;
+ println("The scroll of a removed scroller finished");
+
+ const scrollOfHiddenScroller = hiddenScroller.scrollTo(0, 50);
+ hiddenScroller.style.display = "none";
+ await scrollOfHiddenScroller;
+ println("The scroll of a scroller that stopped being rendered finished");
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/async-scrolling/script-scroll-during-a-thumb-drag.html b/Tests/LibWeb/Text/input/async-scrolling/script-scroll-during-a-thumb-drag.html
index e692d3db99f..9f5ae7a3372 100644
--- a/Tests/LibWeb/Text/input/async-scrolling/script-scroll-during-a-thumb-drag.html
+++ b/Tests/LibWeb/Text/input/async-scrolling/script-scroll-during-a-thumb-drag.html
@@ -24,17 +24,23 @@
await internals.mouseEventThroughUIProcess("mousemove", 147, 5);
await internals.mouseEventThroughUIProcess("mousedown", 147, 5);
+ const nextScroll = () => new Promise(resolve => scroller.addEventListener("scroll", resolve, { once: true }));
await internals.mouseEventThroughUIProcess("mousemove", 147, 60, { buttons: 1 });
- await animationFrame();
- await animationFrame();
+ while (scroller.scrollTop === 0)
+ await nextScroll();
const draggedTo = scroller.scrollTop;
println(`dragged away from the top: ${draggedTo > 0}`);
- // The thumb stays under the pointer that holds it, so the script's scroll does not move the box along its axis.
+ // The thumb stays under the pointer that holds it, so the script's scroll does not move the box along its axis,
+ // and the box has not come to rest while the drag goes on.
+ let scrollendCount = 0;
+ scroller.addEventListener("scrollend", () => ++scrollendCount);
scroller.scrollTop = 0;
- for (let frame = 0; frame < 4; frame++)
- await animationFrame();
+ // The compositor's answer to the script's scroll puts the box back where the thumb holds it.
+ while (scroller.scrollTop === 0)
+ await nextScroll();
println(`held where the drag left it: ${scroller.scrollTop === draggedTo}`);
+ println(`scrollend events during the drag: ${scrollendCount}`);
await internals.mouseEventThroughUIProcess("mouseup", 147, 60);
await animationFrame();
diff --git a/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-over-iframe-it-cannot-scroll-scrolls-the-page.html b/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-over-iframe-it-cannot-scroll-scrolls-the-page.html
index 0880421e79b..f4437a192af 100644
--- a/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-over-iframe-it-cannot-scroll-scrolls-the-page.html
+++ b/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-over-iframe-it-cannot-scroll-scrolls-the-page.html
@@ -37,9 +37,7 @@
printInputTrace(internals.takeInputTrace(), { stages: ["compositor"] });
println(`frame scrolled: ${frame.contentWindow.scrollY !== frameScrollY}`);
println(`window.scrollY: ${window.scrollY}`);
- window.scrollTo(0, 0);
- await animationFrame();
- await animationFrame();
+ await scrollSettled(document, () => window.scrollTo(0, 0));
}
});
</script>