Truly independent web browser
Compositor: Pass the clock into the scroll and input logic
Aliaksandr Kalenik99f7d2688d8d
diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cppindex 92d369b869d..5133429ef05 100644--- a/Services/Compositor/CompositorState.cpp+++ b/Services/Compositor/CompositorState.cpp@@ -274,6 +274,7 @@ void CompositorState::stop_presenting_to_client(Web::CompositorContextId contextvoid CompositorState::update_display_list(Web::CompositorContextId context_id, NonnullRefPtr<Compositing::DisplayList> display_list, Compositing::AccumulatedVisualContextTree visual_context_tree, Compositing::DisplayListResourceTransaction&& resource_transaction, Compositing::ScrollStateSnapshot&& scroll_state_snapshot){+ auto now = MonotonicTime::now();auto* context = context_if_present(context_id);VERIFY(context);@@ -290,7 +291,7 @@ void CompositorState::update_display_list(Web::CompositorContextId context_id, Ncontext->presenter().apply_resource_transaction(move(resource_transaction));context->presenter().set_display_list(display_list);- context->install_display_list_update(move(display_list), move(visual_context_tree), move(scroll_state_snapshot));+ context->install_display_list_update(move(display_list), move(visual_context_tree), move(scroll_state_snapshot), now);resolve_video_sinks(*context);show_animated_image_frames_in(*context);@@ -307,10 +308,11 @@ void CompositorState::update_display_list_resources(Web::CompositorContextId convoid CompositorState::update_visual_context_tree(Web::CompositorContextId context_id, Compositing::AccumulatedVisualContextTree visual_context_tree, Compositing::DisplayListResourceTransaction&& resource_transaction){+ auto now = MonotonicTime::now();auto* context = context_if_present(context_id);VERIFY(context);- if (context->update_visual_context_tree(move(visual_context_tree)))+ if (context->update_visual_context_tree(move(visual_context_tree), now))context->presenter().apply_resource_transaction(move(resource_transaction));show_animated_image_frames_in(*context);}@@ -755,6 +757,7 @@ void CompositorState::invalidate_keyboard_scroll_state(Web::CompositorContextIdvoid CompositorState::handle_and_dispatch_key_event(Web::CompositorContextId context_id, Web::KeyEvent event, bool allow_keyboard_scroll){+ auto now = MonotonicTime::now();// NB: The presentation connection only passes on input for the contexts bound to it.auto* presentation = presentation_for_context(context_id);VERIFY(presentation);@@ -767,8 +770,8 @@ void CompositorState::handle_and_dispatch_key_event(Web::CompositorContextId conbool later_keys_need_not_wait = false;if (allow_keyboard_scroll) {if (auto box = context->box_scrolled_for_key_event(event); box.has_value())- dispatch_scroll_fling_step(context_id, *context, context->end_momentum_scrolling(box.value()), MonotonicTime::now());- auto result = context->handle_key_event(event);+ dispatch_scroll_fling_step(context_id, *context, context->end_momentum_scrolling(box.value()), now);+ auto result = context->handle_key_event(event, now);later_keys_need_not_wait = apply_context_update_result(context_id, *context, result) && event.type == Web::KeyEvent::Type::KeyDown;event.async_scroll_performed_default_action = later_keys_need_not_wait && !result.key_found_nothing_to_scroll;if (later_keys_need_not_wait && result.key_found_nothing_to_scroll)@@ -783,6 +786,7 @@ void CompositorState::handle_and_dispatch_key_event(Web::CompositorContextId convoid CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId context_id, Web::MouseEvent event){+ auto now = MonotonicTime::now();// NB: The presentation connection only passes on input for the contexts bound to it.auto* presentation = presentation_for_context(context_id);VERIFY(presentation);@@ -803,7 +807,7 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId ccontext->note_pointer_position({});if (event.type == Web::MouseEvent::Type::MouseDown)- dispatch_scroll_fling_step(context_id, *context, context->end_scroll_fling(), MonotonicTime::now());+ dispatch_scroll_fling_step(context_id, *context, context->end_scroll_fling(), now);auto is_wheel_event = event.type == Web::MouseEvent::Type::MouseWheel;bool is_first_wheel_event_with_delta = false;@@ -815,7 +819,7 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId cpresentation->did_consume_input_event(context_id, event.id);return;}- auto noted = context->note_wheel_event_from_ui(event);+ auto noted = context->note_wheel_event_from_ui(event, now);event.wheel_gesture_mark = noted.wheel_gesture_mark;is_first_wheel_event_with_delta = noted.is_first_wheel_event_with_delta;@@ -828,10 +832,10 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId c}// A new gesture must not continue the gesture of the fling, so the fling ends first.- dispatch_scroll_fling_step(context_id, *context, context->interrupt_scroll_fling(event), MonotonicTime::now());+ dispatch_scroll_fling_step(context_id, *context, context->interrupt_scroll_fling(event, now), now);// If the gesture continues as a fling, the end of the fling is the end of the gesture.- if (m_presentations.get(presentation)->synthesizes_scroll_momentum && event.scroll_gesture_phase == Web::ScrollGesturePhase::Ended && context->start_scroll_fling_if_flicked(event)) {+ if (m_presentations.get(presentation)->synthesizes_scroll_momentum && event.scroll_gesture_phase == Web::ScrollGesturePhase::Ended && context->start_scroll_fling_if_flicked(event, now)) {record_routing(Web::InputRoutingDecision::FlingStarted);presentation->did_consume_input_event(context_id, event.id);schedule_animation_frames_if_needed(*context);@@ -841,9 +845,9 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId cContextState::ContextUpdateResult result;if (is_wheel_event)- result = scroll_for_wheel_step(context_id, *context, event, WheelStepOrigin::UI, is_first_wheel_event_with_delta, Compositing::AsyncScrollOperationTracking::No, MonotonicTime::now());+ result = scroll_for_wheel_step(context_id, *context, event, WheelStepOrigin::UI, is_first_wheel_event_with_delta, Compositing::AsyncScrollOperationTracking::No, now);else- result = handle_mouse_event_in_nested_contexts(context_id, *context, event);+ result = handle_mouse_event_in_nested_contexts(context_id, *context, event, now);if (result.nested_context_hand_off.has_value())record_routing(*result.nested_context_hand_off);if (result.routing_decision.has_value()) {@@ -928,7 +932,7 @@ Optional<Gfx::FloatPoint> CompositorState::position_in_nested_context_ignoring_creturn position;}-ContextState::ContextUpdateResult CompositorState::handle_mouse_event_in_nested_contexts(Web::CompositorContextId context_id, ContextState& context, Web::MouseEvent const& event)+ContextState::ContextUpdateResult CompositorState::handle_mouse_event_in_nested_contexts(Web::CompositorContextId context_id, ContextState& context, Web::MouseEvent const& event, MonotonicTime now){using Type = Web::MouseEvent::Type;auto& pointer = context.pointer_in_nested_contexts();@@ -966,7 +970,7 @@ ContextState::ContextUpdateResult CompositorState::handle_mouse_event_in_nested_if (auto position_in_nested_context = position_in_nested_context_ignoring_clips(context_id, context, *context_with_captured_scrollbar, position); position_in_nested_context.has_value())pointer.last_position_in_context_with_captured_scrollbar = *position_in_nested_context;}- auto nested_result = context_with_captured_scrollbar->handle_mouse_event_from_containing_context(event_to_send, pointer.last_position_in_context_with_captured_scrollbar);+ auto nested_result = context_with_captured_scrollbar->handle_mouse_event_from_containing_context(event_to_send, pointer.last_position_in_context_with_captured_scrollbar, now);auto result = result_of_nested_context(nested_context_id, *context_with_captured_scrollbar, nested_result, {});if (!context_with_captured_scrollbar->has_captured_scrollbar()) {pointer.context_with_captured_scrollbar.clear();@@ -1000,7 +1004,7 @@ ContextState::ContextUpdateResult CompositorState::handle_mouse_event_in_nested_(void)send_to_context_with_captured_scrollbar(cancel_event);}- auto result = context.handle_mouse_event(event);+ auto result = context.handle_mouse_event(event, now);if (!result.nested_context_mouse_hit.has_value()) {note_context_under_pointer({});return result;@@ -1031,7 +1035,7 @@ ContextState::ContextUpdateResult CompositorState::handle_mouse_event_in_nested_containing_context_id = hit.child_context_id;containing_context = nested_context;position = *position_in_nested_context_content;- result = nested_context->handle_mouse_event_from_containing_context(event, position);+ result = nested_context->handle_mouse_event_from_containing_context(event, position, now);}note_context_under_pointer(containing_context_id);@@ -1044,7 +1048,7 @@ ContextState::ContextUpdateResult CompositorState::handle_mouse_event_in_nested_case Type::MouseUp:if (context_with_captured_scrollbar)return send_to_context_with_captured_scrollbar(event);- return context.handle_mouse_event(event);+ return context.handle_mouse_event(event, now);case Type::MouseLeave:case Type::MouseCancel: {// The pointer leaves every nested context it was in, and a cancel ends the drag of one, as in this context.@@ -1055,20 +1059,20 @@ ContextState::ContextUpdateResult CompositorState::handle_mouse_event_in_nested_result_of_context_with_captured_scrollbar = send_to_context_with_captured_scrollbar(event);}if (auto* context_under_pointer = context_still_nested_in(context_id, pointer.context_under_pointer); context_under_pointer && pointer.context_under_pointer != context_with_captured_scrollbar_id) {- auto nested_result = context_under_pointer->handle_mouse_event_from_containing_context(event, {});+ auto nested_result = context_under_pointer->handle_mouse_event_from_containing_context(event, {}, now);apply_context_update_result(*pointer.context_under_pointer, *context_under_pointer, nested_result);schedule_animation_frames_if_needed(*context_under_pointer);}pointer.context_under_pointer.clear();- auto result = context.handle_mouse_event(event);+ auto result = context.handle_mouse_event(event, now);if (!result_of_context_with_captured_scrollbar.has_value())return result;result_of_context_with_captured_scrollbar->frame_to_present = result.frame_to_present;return result_of_context_with_captured_scrollbar.release_value();}case Type::MouseWheel:- return context.handle_mouse_event(event);+ return context.handle_mouse_event(event, now);}VERIFY_NOT_REACHED();}@@ -1404,10 +1408,10 @@ Compositing::WheelEventAnswer CompositorState::wheel_event_answer_for(AppliedWheCompositing::WheelEventAnswer CompositorState::take_wheel_event_from_main_thread(Web::CompositorContextId context_id, Web::MouseEvent const& event, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelEventRouting routing){+ auto now = MonotonicTime::now();auto* context = context_if_present(context_id);VERIFY(context);- auto now = MonotonicTime::now();auto noted = context->note_wheel_event_from_main_thread(event, now);if (routing == Compositing::WheelEventRouting::AfterDispatch)return { .wheel_gesture_mark = noted.wheel_gesture_mark };@@ -1417,12 +1421,12 @@ Compositing::WheelEventAnswer CompositorState::take_wheel_event_from_main_threadCompositing::WheelEventAnswer CompositorState::scroll_for_wheel_event_the_page_let_through(Web::CompositorContextId listener_context_id, Compositing::WheelStepLetThrough const& let_through, Compositing::AsyncScrollOperationTracking operation_tracking, CompositorStateWebContentClient const& page_client){+ auto now = MonotonicTime::now();auto* listener_context = context_if_present(listener_context_id);VERIFY(listener_context);if (listener_context->document_id() != let_through.document_id)return { .routing_decision = Web::InputRoutingDecision::ScrollerInOtherDocument };- auto now = MonotonicTime::now();auto gesture_id = let_through.wheel_gesture_mark.gesture_id;// A step that moves along no axis goes to the page as no wheel event, so the page had no say in letting it through,// and it decides nothing for the steps after it.@@ -1500,18 +1504,18 @@ static bool scroll_request_smoothly_scrolls_for_script(Compositing::ScrollRequesvoid CompositorState::apply_scroll_requests(Web::CompositorContextId context_id, ReadonlySpan<Compositing::ScrollRequest> scroll_requests){+ auto now = MonotonicTime::now();auto* context = context_if_present(context_id);if (!context)return;// A script's smooth scroll of a box ends the momentum scrolling it, as a key's does. A script's instant scroll only// moves the box, and the momentum goes on from there: pages keep their content in place under a flick that way.- auto now = MonotonicTime::now();for (auto const& scroll_request : scroll_requests) {if (scroll_request.takes_over_from_momentum || scroll_request_smoothly_scrolls_for_script(scroll_request))dispatch_scroll_fling_step(context_id, *context, context->end_momentum_scrolling(scroll_request.stable_node_id), now);}- if (auto frame_to_present = context->apply_scroll_requests(scroll_requests); frame_to_present.has_value())+ if (auto frame_to_present = context->apply_scroll_requests(scroll_requests, now); frame_to_present.has_value())schedule_present_frame(context_id, *context, frame_to_present.value());schedule_animation_frames_if_needed(*context);publish_pending_async_scroll_updates(context_id, *context);@@ -1592,11 +1596,12 @@ void CompositorState::set_display_metadata(Web::CompositorContextId context_id,void CompositorState::set_context_visibility(Web::CompositorContextId context_id, Compositing::ContextVisibility visibility){+ auto now = MonotonicTime::now();auto* context = context_if_present(context_id);if (!context)return;if (visibility == Compositing::ContextVisibility::Hidden)- dispatch_scroll_fling_step(context_id, *context, context->end_scroll_fling(), MonotonicTime::now());+ dispatch_scroll_fling_step(context_id, *context, context->end_scroll_fling(), now);if (!context->set_visibility(visibility))return;@@ -1699,7 +1704,7 @@ void CompositorState::present_frame(Web::CompositorContextId context_id, Gfx::Invoid CompositorState::present_frame(Web::CompositorContextId context_id, ContextState& context, PendingFrame pending_frame){auto composited_context_resolver = resolver_for(context_id);- auto prepared_frame = context.presenter().prepare_frame(*m_display_list_player, pending_frame, context.frame_inputs(), &composited_context_resolver);+ auto prepared_frame = context.presenter().prepare_frame(*m_display_list_player, pending_frame, context.frame_inputs(MonotonicTime::now()), &composited_context_resolver);if (!prepared_frame.has_value())return;@@ -1762,9 +1767,9 @@ void CompositorState::schedule_pending_present_frame(Web::CompositorContextId coschedule_pending_present_frame_on_vsync(context_id, context);}-static bool needs_animation_frames(ContextState& context)+static bool needs_animation_frames(ContextState& context, MonotonicTime now){- return context.needs_animation_frames() || context.presenter().ui_overlay_fades_need_frame();+ return context.needs_animation_frames(now) || context.presenter().ui_overlay_fades_need_frame();}static bool has_pending_present_frame_scheduled_on(ContextState const& context, Optional<u64> display_id)@@ -1774,7 +1779,7 @@ static bool has_pending_present_frame_scheduled_on(ContextState const& context,void CompositorState::schedule_animation_frames_if_needed(ContextState& context){- if (needs_animation_frames(context) && context_is_effectively_visible(context))+ if (needs_animation_frames(context, MonotonicTime::now()) && context_is_effectively_visible(context))vsync_scheduler_for_display(display_id_for_context(context)).schedule(display_refresh_rate_for_context(context));}@@ -1848,6 +1853,7 @@ void CompositorState::present_pending_frames_on_vsync(Optional<u64> display_id,update_video_sinks_for_display(display_id);for (auto& context_entry : m_contexts) {+ auto now = MonotonicTime::now();auto context_id = context_entry.key;auto& context = *context_entry.value;if (!context_is_effectively_visible(context)) {@@ -1866,7 +1872,7 @@ void CompositorState::present_pending_frames_on_vsync(Optional<u64> display_id,}}- auto has_active_animation_on_display = needs_animation_frames(context) && display_id_for_context(context) == display_id;+ auto has_active_animation_on_display = needs_animation_frames(context, now) && display_id_for_context(context) == display_id;auto presents_on_display = has_pending_present_frame_scheduled_on(context, display_id) || has_active_animation_on_display;if (presents_on_display) {if (display_id_for_context(context) == display_id)@@ -1900,7 +1906,7 @@ void CompositorState::present_pending_frames_on_vsync(Optional<u64> display_id,continue;publish_pending_async_scroll_updates(context_id, context);- if (context.visual_animations_need_frame()) {+ if (context.visual_animations_need_frame(now)) {context.advance_visual_animations(frame_time);if (auto viewport_rect = context.presenter().viewport_rect_for_ui_overlay(); viewport_rect.has_value())context.presenter().queue_present_frame(PendingFrame::repainting_changes(*viewport_rect));@@ -1909,12 +1915,12 @@ void CompositorState::present_pending_frames_on_vsync(Optional<u64> display_id,add_backing_store_for_pending_frame_if_needed(context_id, context);auto pending_present_frame = context.presenter().take_pending_present_frame_if_unblocked();if (!pending_present_frame.has_value()) {- has_active_animation_on_display = needs_animation_frames(context) && display_id_for_context(context) == display_id;+ has_active_animation_on_display = needs_animation_frames(context, now) && display_id_for_context(context) == display_id;if (has_pending_present_frame_scheduled_on(context, display_id) || has_active_animation_on_display)vsync_scheduler_for_display(display_id).schedule(display_refresh_rate_for_context(context));continue;}- if (needs_animation_frames(context))+ if (needs_animation_frames(context, now))schedule_present_frame(context_id, context, PendingFrame::repainting_changes(pending_present_frame->viewport_rect));present_frame(context_id, context, *pending_present_frame);}@@ -1922,6 +1928,7 @@ void CompositorState::present_pending_frames_on_vsync(Optional<u64> display_id,bool CompositorState::request_screenshot(Web::CompositorContextId context_id, Gfx::ShareableBitmap& target_bitmap){+ auto now = MonotonicTime::now();auto* context = context_if_present(context_id);VERIFY(context);@@ -1929,7 +1936,7 @@ bool CompositorState::request_screenshot(Web::CompositorContextId context_id, Gfreturn false;auto composited_context_resolver = resolver_for(context_id);- auto screenshot_inputs = context->frame_inputs_for_screenshot();+ auto screenshot_inputs = context->frame_inputs_for_screenshot(now);context->presenter().paint_screenshot(*m_display_list_player, target_bitmap, screenshot_inputs.frame_inputs, &composited_context_resolver);if (!screenshot_inputs.scrollbar_fade_damage_rect.is_empty()) {if (auto viewport_rect = context->presenter().viewport_rect_for_ui_overlay(); viewport_rect.has_value())@@ -2098,7 +2105,7 @@ CompositedContextSurface CompositorState::resolve_composited_context(Web::Composif (child_context->presenter().needs_rasterization()) {auto composited_context_resolver = resolver_for(child_context_id);DisplayListPlayerSkia display_list_player { m_skia_backend_context };- child_context->presenter().present_synchronously(display_list_player, child_context->frame_inputs(), &composited_context_resolver);+ child_context->presenter().present_synchronously(display_list_player, child_context->frame_inputs(MonotonicTime::now()), &composited_context_resolver);}return child_context->presenter().composited_surface();diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.hindex 718801f23ba..bc694d72cf4 100644--- a/Services/Compositor/CompositorState.h+++ b/Services/Compositor/CompositorState.h@@ -299,7 +299,7 @@ private:Optional<Web::CompositorContextId> routing_context_of_wheel_gesture(Web::CompositorContextId, u64 gesture_id);// The scrollbars of a context nested in the presenting context `context_id` take the pointer over that context's// content, and a drag of one of them takes the pointer wherever it goes until the drag ends.- ContextState::ContextUpdateResult handle_mouse_event_in_nested_contexts(Web::CompositorContextId, ContextState&, Web::MouseEvent const&);+ ContextState::ContextUpdateResult handle_mouse_event_in_nested_contexts(Web::CompositorContextId, ContextState&, Web::MouseEvent const&, MonotonicTime now);ContextState* context_still_nested_in(Web::CompositorContextId containing_context_id, Optional<Web::CompositorContextId>);// Where the position in the presenting context lands in the nested context, through each context in between and// without regard to where their content is or what clips it.diff --git a/Services/Compositor/ContextScene.cpp b/Services/Compositor/ContextScene.cppindex a102b9fdfc1..570f34ed722 100644--- a/Services/Compositor/ContextScene.cpp+++ b/Services/Compositor/ContextScene.cpp@@ -9,9 +9,8 @@namespace Compositor {-static void update_visual_animation_sampling_state(Compositing::AccumulatedVisualContextTree const& visual_context_tree, Optional<i64>& sample_time_ns, bool& has_active_animations)+static void update_visual_animation_sampling_state(Compositing::AccumulatedVisualContextTree const& visual_context_tree, Optional<i64>& sample_time_ns, bool& has_active_animations, MonotonicTime now){- auto now = MonotonicTime::now();has_active_animations = visual_context_tree.has_active_visual_animation_at(now.nanoseconds());// A replacement tree can be presented before the next vsync. Keep the most recent sample so that presentation// remains continuous, but sample dormant and completed descriptors at the current boundary when necessary.@@ -21,15 +20,15 @@ static void update_visual_animation_sampling_state(Compositing::AccumulatedVisuasample_time_ns = now.nanoseconds();}-void ContextScene::install(NonnullRefPtr<Compositing::DisplayList> display_list, Compositing::AccumulatedVisualContextTree visual_context_tree)+void ContextScene::install(NonnullRefPtr<Compositing::DisplayList> display_list, Compositing::AccumulatedVisualContextTree visual_context_tree, MonotonicTime now){invalidate_visual_context_tree_for_compositing();m_display_list = move(display_list);m_visual_context_tree = move(visual_context_tree);- update_visual_animation_sampling_state(*m_visual_context_tree, m_visual_animation_sample_time_ns, m_has_active_visual_animations);+ update_visual_animation_sampling_state(*m_visual_context_tree, m_visual_animation_sample_time_ns, m_has_active_visual_animations, now);}-bool ContextScene::replace_visual_context_tree(Compositing::AccumulatedVisualContextTree visual_context_tree)+bool ContextScene::replace_visual_context_tree(Compositing::AccumulatedVisualContextTree visual_context_tree, MonotonicTime now){if (!m_display_list || m_display_list->compatible_visual_context_tree_structural_epoch() != visual_context_tree.structural_epoch()) {dbgln("Compositor: Dropping stale visual context tree update (tree epoch {}, display list epoch {})",@@ -39,7 +38,7 @@ bool ContextScene::replace_visual_context_tree(Compositing::AccumulatedVisualCon}invalidate_visual_context_tree_for_compositing();m_visual_context_tree = move(visual_context_tree);- update_visual_animation_sampling_state(*m_visual_context_tree, m_visual_animation_sample_time_ns, m_has_active_visual_animations);+ update_visual_animation_sampling_state(*m_visual_context_tree, m_visual_animation_sample_time_ns, m_has_active_visual_animations, now);return true;}@@ -116,14 +115,14 @@ bool ContextScene::advance_visual_animations(MonotonicTime now)return m_has_active_visual_animations;}-bool ContextScene::visual_animations_need_frame(Compositing::ScrollStateSnapshot const& scroll_state_snapshot, Gfx::IntSize viewport_size)+bool ContextScene::visual_animations_need_frame(Compositing::ScrollStateSnapshot const& scroll_state_snapshot, Gfx::IntSize viewport_size, MonotonicTime now){if (!m_has_active_visual_animations)return false;if (m_animated_content_may_affect_viewport.has_value())return *m_animated_content_may_affect_viewport;- auto sample_time_ns = m_visual_animation_sample_time_ns.value_or(MonotonicTime::now().nanoseconds());+ auto sample_time_ns = m_visual_animation_sample_time_ns.value_or(now.nanoseconds());auto tree = m_async_visual_viewport_transform.has_value()? current_visual_context_tree().with_visual_viewport_transform(*m_async_visual_viewport_transform): current_visual_context_tree();diff --git a/Services/Compositor/ContextScene.h b/Services/Compositor/ContextScene.hindex 9cf3f28434f..252110712c1 100644--- a/Services/Compositor/ContextScene.h+++ b/Services/Compositor/ContextScene.h@@ -28,9 +28,9 @@ class ContextScene {public:ContextScene() = default;- void install(NonnullRefPtr<Compositing::DisplayList>, Compositing::AccumulatedVisualContextTree);+ void install(NonnullRefPtr<Compositing::DisplayList>, Compositing::AccumulatedVisualContextTree, MonotonicTime now);// Returns false, leaving everything as it was, for a tree that does not fit the installed display list.- bool replace_visual_context_tree(Compositing::AccumulatedVisualContextTree);+ bool replace_visual_context_tree(Compositing::AccumulatedVisualContextTree, MonotonicTime now);RefPtr<Compositing::DisplayList const> const& display_list() const { return m_display_list; }Optional<Compositing::AccumulatedVisualContextTree> const& visual_context_tree() const { return m_visual_context_tree; }@@ -47,7 +47,7 @@ public:void drop_async_visual_viewport_transform();bool advance_visual_animations(MonotonicTime now);- bool visual_animations_need_frame(Compositing::ScrollStateSnapshot const&, Gfx::IntSize viewport_size);+ bool visual_animations_need_frame(Compositing::ScrollStateSnapshot const&, Gfx::IntSize viewport_size, MonotonicTime now);void forget_whether_animated_content_may_affect_viewport() { m_animated_content_may_affect_viewport.clear(); }private:diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cppindex f6adba9ed69..ce9fff999e5 100644--- a/Services/Compositor/ContextState.cpp+++ b/Services/Compositor/ContextState.cpp@@ -144,11 +144,12 @@ void ContextState::set_parent_context(Optional<Web::CompositorContextId> parent_void ContextState::install_display_list_update(NonnullRefPtr<Compositing::DisplayList> display_list,Compositing::AccumulatedVisualContextTree visual_context_tree,- Compositing::ScrollStateSnapshot&& scroll_state_snapshot)+ Compositing::ScrollStateSnapshot&& scroll_state_snapshot,+ MonotonicTime now){VERIFY(display_list->compatible_visual_context_tree_structural_epoch() == visual_context_tree.structural_epoch());auto scroll_offsets_of_known_nodes = scroll_offsets_by_stable_id();- m_scene.install(move(display_list), move(visual_context_tree));+ m_scene.install(move(display_list), move(visual_context_tree), now);m_keyboard_scroll_controller.forget_target();m_scroll_state_snapshot = move(scroll_state_snapshot);m_scroll_state_snapshot.set_node_count(m_scene.visual_context_tree()->spatial_node_count());@@ -209,9 +210,9 @@ Gfx::IntRect ContextState::damage_rect_of_blinking_carets()return damage_rect;}-bool ContextState::update_visual_context_tree(Compositing::AccumulatedVisualContextTree visual_context_tree)+bool ContextState::update_visual_context_tree(Compositing::AccumulatedVisualContextTree visual_context_tree, MonotonicTime now){- if (!m_scene.replace_visual_context_tree(move(visual_context_tree)))+ if (!m_scene.replace_visual_context_tree(move(visual_context_tree), now))return false;// A constraints refresh changes sticky payloads without a new snapshot, and the snapshot that// pairs with this tree arrives in a separate message.@@ -293,7 +294,7 @@ Optional<Web::AsyncScrollNodeStableID> ContextState::box_scrolled_for_key_event(return m_async_scroll_tree.scroll_node_for_index(*key_scroll->target_scroll_node_index)->stable_node_id;}-ContextState::ContextUpdateResult ContextState::handle_key_event(Web::KeyEvent const& event)+ContextState::ContextUpdateResult ContextState::handle_key_event(Web::KeyEvent const& event, MonotonicTime now){if (!Web::is_keyboard_scroll_key(event.key, Web::UIEvents::Mod_None))return {};@@ -343,7 +344,6 @@ ContextState::ContextUpdateResult ContextState::handle_key_event(Web::KeyEvent cif (delta.is_zero())return result_of_pan();auto scrolls_to_extent = key_step.scrolls_to_extent;- auto now = MonotonicTime::now();auto target_scroll_node_index = *key_scroll->target_scroll_node_index;m_keyboard_scroll_controller.hold_key(event.key);@@ -437,7 +437,7 @@ Compositing::ScrollStateSnapshot ContextState::scroll_state_snapshot_at_keyboardreturn snapshot;}-ContextState::ContextUpdateResult ContextState::handle_mouse_event(Web::MouseEvent const& event)+ContextState::ContextUpdateResult ContextState::handle_mouse_event(Web::MouseEvent const& event, MonotonicTime now){if (!presents_to_client())return ContextUpdateResult::declined(Web::InputRoutingDecision::ContextNotPresenting);@@ -446,16 +446,16 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event(Web::MouseEvestatic_cast<float>(event.position.x().value()),static_cast<float>(event.position.y().value()),};- return handle_mouse_event_at(event, position);+ return handle_mouse_event_at(event, position, now);}-ContextState::ContextUpdateResult ContextState::handle_mouse_event_from_containing_context(Web::MouseEvent const& event, Gfx::FloatPoint position)+ContextState::ContextUpdateResult ContextState::handle_mouse_event_from_containing_context(Web::MouseEvent const& event, Gfx::FloatPoint position, MonotonicTime now){if (event.type == Web::MouseEvent::Type::MouseMove)note_pointer_position(position);else if (first_is_one_of(event.type, Web::MouseEvent::Type::MouseLeave, Web::MouseEvent::Type::MouseCancel))note_pointer_position({});- return handle_mouse_event_at(event, position);+ return handle_mouse_event_at(event, position, now);}void ContextState::note_pointer_position(Optional<Gfx::FloatPoint> position)@@ -514,7 +514,7 @@ Optional<Compositing::NestedContextHit> ContextState::position_in_content_of_nesreturn m_async_scroll_tree.position_in_content_of_nested_context(nested_context_id, m_scene.visual_context_tree_for_compositing(), position);}-ContextState::ContextUpdateResult ContextState::handle_mouse_event_at(Web::MouseEvent const& event, Gfx::FloatPoint position)+ContextState::ContextUpdateResult ContextState::handle_mouse_event_at(Web::MouseEvent const& event, Gfx::FloatPoint position, MonotonicTime now){if (m_scrollbar_controller.is_empty() && !m_async_scroll_tree.has_nested_contexts())return ContextUpdateResult::declined(Web::InputRoutingDecision::NotOverAScrollbar);@@ -563,19 +563,20 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event_at(Web::Mouse.direction = m_scrollbar_controller.paging_direction(drag->scrollbar_index, drag->primary_position, *scroll_offset),.primary_position = drag->primary_position,};- if (auto frame_to_present = page_captured_scrollbar(); frame_to_present.has_value()) {+ if (auto frame_to_present = page_captured_scrollbar(now); frame_to_present.has_value()) {result.frame_to_present = *frame_to_present;result.should_request_rendering_update = true;}if (!m_scrollbar_paging_timer) {m_scrollbar_paging_timer = Core::Timer::create_single_shot(scrollbar_paging_initial_delay, [this] {+ auto now = MonotonicTime::now();// Paging ends with the press, and with the scrollbar the press holds.if (!m_scrollbar_paging.has_value() || !m_scrollbar_controller.has_captured_scrollbar()) {stop_scrollbar_paging();return;}// Once the thumb reaches the pointer, paging waits for the pointer to move.- if (!page_captured_scrollbar().has_value())+ if (!page_captured_scrollbar(now).has_value())return;request_rendering_update();if (m_request_animation_frames)@@ -587,7 +588,7 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event_at(Web::Mousereturn result;}- if (auto frame_to_present = apply_scrollbar_drag(*drag); frame_to_present.has_value()) {+ if (auto frame_to_present = apply_scrollbar_drag(*drag, now); frame_to_present.has_value()) {result.frame_to_present = *frame_to_present;result.should_request_rendering_update = true;}@@ -605,7 +606,7 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event_at(Web::Mouseif (!m_scrollbar_paging_timer->is_active())m_scrollbar_paging_timer->restart(scrollbar_paging_repeat_interval);} else {- frame_to_present = apply_scrollbar_drag(*drag);+ frame_to_present = apply_scrollbar_drag(*drag, now);}return {.accepted = true,@@ -660,7 +661,7 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event_at(Web::Mouseresult.should_request_rendering_update = true;result.frame_to_present = frame_repainting_scrollbars();if (!was_paging) {- if (auto frame_to_present = apply_scrollbar_drag(*drag); frame_to_present.has_value())+ if (auto frame_to_present = apply_scrollbar_drag(*drag, now); frame_to_present.has_value())result.frame_to_present = *frame_to_present;}@@ -834,7 +835,7 @@ Gfx::IntRect ContextState::note_async_scrolling_viewport_rect(Gfx::IntRect viewpreturn viewport_rect;}-ContextState::WheelScrollOutcome ContextState::perform_wheel_scroll_of_node(Compositing::SpatialNodeIndex scroll_node_index, Gfx::FloatPoint delta, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, Compositing::AsyncScrollOperationTracking operation_tracking, Gfx::IntRect viewport_rect, MonotonicTime now, Compositing::ScrollChaining scroll_chaining, VisualViewportPanning visual_viewport_panning)+ContextState::WheelScrollOutcome ContextState::perform_wheel_scroll_of_node(Compositing::SpatialNodeIndex scroll_node_index, Gfx::FloatPoint delta, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, Compositing::AsyncScrollOperationTracking operation_tracking, Gfx::IntRect viewport_rect, Compositing::ScrollChaining scroll_chaining, VisualViewportPanning visual_viewport_panning, MonotonicTime now){bool pans_visual_viewport = visual_viewport_panning == VisualViewportPanning::BeforeScrolling;auto magnification = pans_visual_viewport ? m_scene.visual_viewport_magnification() : 1.0f;@@ -884,7 +885,7 @@ ContextState::WheelScrollOutcome ContextState::perform_wheel_scroll_of_node(CompOptional<Gfx::FloatPoint> delta_the_scroller_did_not_scroll_by;if (!visual_viewport_took_rest_of_step) {- auto node_scroll = scroll_node_by_wheel_delta(scroll_node_index, delta_left.scaled(1.0f / magnification), wheel_delta_precision, scroll_gesture_phase, operation_tracking, viewport_rect, now, scroll_chaining);+ auto node_scroll = scroll_node_by_wheel_delta(scroll_node_index, delta_left.scaled(1.0f / magnification), wheel_delta_precision, scroll_gesture_phase, operation_tracking, viewport_rect, scroll_chaining, now);outcome.operation_id = node_scroll.outcome.operation_id;if (node_scroll.outcome.viewport_rect_to_present.has_value())outcome.viewport_rect_to_present = node_scroll.outcome.viewport_rect_to_present;@@ -909,7 +910,7 @@ ContextState::WheelScrollOutcome ContextState::perform_wheel_scroll_of_node(Compreturn outcome;}-ContextState::NodeScrollByWheelDelta ContextState::scroll_node_by_wheel_delta(Compositing::SpatialNodeIndex scroll_node_index, Gfx::FloatPoint delta, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, Compositing::AsyncScrollOperationTracking operation_tracking, Gfx::IntRect viewport_rect, MonotonicTime now, Compositing::ScrollChaining scroll_chaining)+ContextState::NodeScrollByWheelDelta ContextState::scroll_node_by_wheel_delta(Compositing::SpatialNodeIndex scroll_node_index, Gfx::FloatPoint delta, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, Compositing::AsyncScrollOperationTracking operation_tracking, Gfx::IntRect viewport_rect, Compositing::ScrollChaining scroll_chaining, MonotonicTime now){WheelScrollOutcome outcome;Optional<Compositing::WheelScrollTarget> wheel_scroll_target;@@ -1011,7 +1012,7 @@ Optional<Gfx::Orientation> ContextState::axis_held_by_scrollbar_of(Compositing::return scrollbar.vertical ? Gfx::Orientation::Vertical : Gfx::Orientation::Horizontal;}-Optional<PendingFrame> ContextState::apply_scroll_requests(ReadonlySpan<Compositing::ScrollRequest> scroll_requests)+Optional<PendingFrame> ContextState::apply_scroll_requests(ReadonlySpan<Compositing::ScrollRequest> scroll_requests, MonotonicTime now){Vector<Compositing::AsyncScrollOffset> answers;for (auto const& scroll_request : scroll_requests) {@@ -1142,14 +1143,14 @@ Optional<PendingFrame> ContextState::apply_scroll_requests(ReadonlySpan<Compositauto destination_offset = running_animation->animation.destination_offset();auto clamped_destination_offset = m_async_scroll_tree.clamped_scroll_offset_for_node(scroll_node_index.value(), destination_offset);if (clamped_destination_offset != destination_offset)- running_animation->animation.retarget(clamped_destination_offset, MonotonicTime::now() - running_animation->started_at);+ running_animation->animation.retarget(clamped_destination_offset, now - running_animation->started_at);}}if (instant_scroll_is_for_script)m_elastic_overscroll_controller.drop_stretch_moved_by(scroll_request.stable_node_id, instant_scroll_delta);if (smooth_scroll_is_for_script)- m_elastic_overscroll_controller.release_stretch_of(scroll_request.stable_node_id, MonotonicTime::now());+ m_elastic_overscroll_controller.release_stretch_of(scroll_request.stable_node_id, now);if (smooth_scroll.has_value()) {auto destination_offset = smooth_scroll->destination_offset;@@ -1161,7 +1162,7 @@ Optional<PendingFrame> ContextState::apply_scroll_requests(ReadonlySpan<Composit}destination_offset = m_async_scroll_tree.clamped_scroll_offset_for_node(scroll_node_index.value(), destination_offset);if (retargets_running_animation) {- retarget_user_scroll(*running_animation, destination_offset, MonotonicTime::now());+ retarget_user_scroll(*running_animation, destination_offset, now);} else {auto start_offset = m_async_scroll_tree.scroll_offset_for_node(scroll_node_index.value(), m_scroll_state_snapshot).value();Compositing::SmoothScrollAnimation animation { start_offset, destination_offset, m_async_scroll_tree.device_pixels_per_css_pixel(), smooth_scroll->animation_kind };@@ -1172,7 +1173,7 @@ Optional<PendingFrame> ContextState::apply_scroll_requests(ReadonlySpan<Composit.stable_node_id = scroll_request.stable_node_id,.operation_id = smooth_scroll->operation_id,.animation = move(animation),- .started_at = MonotonicTime::now(),+ .started_at = now,.is_user_scroll = smooth_scroll->initiator == Compositing::SmoothScrollInitiator::UserInput,.heads_to_an_extent = false,});@@ -1421,12 +1422,11 @@ Optional<Gfx::IntRect> ContextState::advance_smooth_scroll_animations(MonotonicTreturn {};}-ContextState::ContextUpdateResult ContextState::handle_wheel_event(Web::MouseEvent const& event, bool is_first_wheel_event_with_delta, WheelEventListenerGate const& listener_gate, Optional<MonotonicTime> now_for_testing)+ContextState::ContextUpdateResult ContextState::handle_wheel_event(Web::MouseEvent const& event, bool is_first_wheel_event_with_delta, WheelEventListenerGate const& listener_gate, MonotonicTime now){VERIFY(event.type == Web::MouseEvent::Type::MouseWheel);if (!presents_to_client())return ContextUpdateResult::declined(Web::InputRoutingDecision::ContextNotPresenting);- auto now = now_for_testing.value_or(MonotonicTime::now());m_scroll_fling_controller.note_wheel_event(event, now);return scroll_for_wheel_event(event, is_first_wheel_event_with_delta, listener_gate, Compositing::AsyncScrollOperationTracking::No, now);}@@ -1485,9 +1485,8 @@ ContextState::NotedWheelEvent ContextState::note_wheel_event(Web::MouseEvent con};}-ContextState::NotedWheelEvent ContextState::note_wheel_event_from_ui(Web::MouseEvent const& event, Optional<MonotonicTime> now_for_testing)+ContextState::NotedWheelEvent ContextState::note_wheel_event_from_ui(Web::MouseEvent const& event, MonotonicTime now){- auto now = now_for_testing.value_or(MonotonicTime::now());auto phase = event.scroll_gesture_phase;auto noted = note_wheel_event(event, now);@@ -1510,14 +1509,14 @@ ContextState::NotedWheelEvent ContextState::note_wheel_event_from_main_thread(Wereturn note_wheel_event(event, now);}-bool ContextState::start_scroll_fling_if_flicked(Web::MouseEvent const& gesture_end_event, Optional<MonotonicTime> now_for_testing)+bool ContextState::start_scroll_fling_if_flicked(Web::MouseEvent const& gesture_end_event, MonotonicTime now){- return m_scroll_fling_controller.start_if_flicked(gesture_end_event, now_for_testing.value_or(MonotonicTime::now()));+ return m_scroll_fling_controller.start_if_flicked(gesture_end_event, now);}-Optional<Web::MouseEvent> ContextState::interrupt_scroll_fling(Web::MouseEvent const& event, Optional<MonotonicTime> now_for_testing)+Optional<Web::MouseEvent> ContextState::interrupt_scroll_fling(Web::MouseEvent const& event, MonotonicTime now){- return m_scroll_fling_controller.interrupt(event, now_for_testing.value_or(MonotonicTime::now()));+ return m_scroll_fling_controller.interrupt(event, now);}Optional<Web::MouseEvent> ContextState::interrupt_reported_scroll_momentum()@@ -1652,7 +1651,7 @@ ContextState::ContextUpdateResult ContextState::scroll_for_overtaken_wheel_step(return ContextUpdateResult::declined(Web::InputRoutingDecision::StepOvertaken);m_scroll_snap_controller.note_gesture_phase(step.scroll_gesture_phase);- auto node_scroll = scroll_node_by_wheel_delta(*scroll_target.scroll_node_index, delta, step.wheel_delta_precision, step.scroll_gesture_phase, step.operation_tracking, m_async_scrolling_viewport_rect, now, Compositing::ScrollChaining::ToScrollableAncestors);+ auto node_scroll = scroll_node_by_wheel_delta(*scroll_target.scroll_node_index, delta, step.wheel_delta_precision, step.scroll_gesture_phase, step.operation_tracking, m_async_scrolling_viewport_rect, Compositing::ScrollChaining::ToScrollableAncestors, now);auto const& outcome = node_scroll.outcome;return {.accepted = true,@@ -1753,7 +1752,7 @@ ContextState::ContextUpdateResult ContextState::scroll_for_wheel_step_in_this_co}auto scroll_chaining = is_first_step_of_gesture ? Compositing::ScrollChaining::ToScrollableAncestors : Compositing::ScrollChaining::None;- auto outcome = perform_wheel_scroll_of_node(*latched_scroll_node_index, delta, step.wheel_delta_precision, step.scroll_gesture_phase, step.operation_tracking, m_async_scrolling_viewport_rect, now, scroll_chaining, VisualViewportPanning::BeforeScrolling);+ auto outcome = perform_wheel_scroll_of_node(*latched_scroll_node_index, delta, step.wheel_delta_precision, step.scroll_gesture_phase, step.operation_tracking, m_async_scrolling_viewport_rect, scroll_chaining, VisualViewportPanning::BeforeScrolling, now);return {.accepted = true,.frame_to_present = outcome.viewport_rect_to_present.map([](auto const& rect) { return PendingFrame::repainting_changes(rect); }),@@ -1902,7 +1901,7 @@ ContextState::ContextUpdateResult ContextState::take_wheel_step_from_containing_{m_scroll_snap_controller.note_gesture_phase(step.scroll_gesture_phase);auto delta = step.delta_in_css_pixels.scaled(static_cast<float>(m_async_scroll_tree.device_pixels_per_css_pixel()));- auto outcome = perform_wheel_scroll_of_node(scroll_node_index, delta, step.wheel_delta_precision, step.scroll_gesture_phase, step.operation_tracking, m_async_scrolling_viewport_rect, now, scroll_chaining, VisualViewportPanning::No);+ auto outcome = perform_wheel_scroll_of_node(scroll_node_index, delta, step.wheel_delta_precision, step.scroll_gesture_phase, step.operation_tracking, m_async_scrolling_viewport_rect, scroll_chaining, VisualViewportPanning::No, now);return {.accepted = true,.frame_to_present = outcome.viewport_rect_to_present.map([](auto const& rect) { return PendingFrame::repainting_changes(rect); }),@@ -2060,11 +2059,10 @@ FrameInputs ContextState::frame_inputs_as_presented_now()// Each frame shows the scrollbars as of when it is painted. An elastic overscroll moves the presented scroll offsets// only, and shows the scrollbars of the stretched scroller as a scroll does.-void ContextState::update_scrollbar_visibility()+void ContextState::update_scrollbar_visibility(MonotonicTime now){auto stretched_scroll_state_snapshot = scroll_state_snapshot_stretched_by_elastic_overscrolls();auto const& presented_scroll_state_snapshot = stretched_scroll_state_snapshot.has_value() ? *stretched_scroll_state_snapshot : m_scroll_state_snapshot;- auto now = MonotonicTime::now();m_scrollbar_controller.update_visibility(presented_scroll_state_snapshot, now);report_scrollbar_visibility_changes();@@ -2109,23 +2107,23 @@ Gfx::IntRect ContextState::advance_scrollbar_fades_and_return_damage_rect(Monotoreturn damage_rect;}-Optional<FrameInputs> ContextState::frame_inputs()+Optional<FrameInputs> ContextState::frame_inputs(MonotonicTime now){- update_scrollbar_visibility();+ update_scrollbar_visibility(now);if (!m_scene.display_list())return {};return frame_inputs_as_presented_now();}-ContextState::ScreenshotInputs ContextState::frame_inputs_for_screenshot()+ContextState::ScreenshotInputs ContextState::frame_inputs_for_screenshot(MonotonicTime now){VERIFY(m_scene.display_list());// Screenshot requests can arrive between display ticks, so sample animations and scrollbar visibility at capture// time.- auto capture_time = MonotonicTime::now();+ auto capture_time = now;advance_visual_animations(capture_time);- update_scrollbar_visibility();+ update_scrollbar_visibility(now);auto scrollbar_fade_damage_rect = advance_scrollbar_fades_and_return_damage_rect(capture_time);return { .frame_inputs = frame_inputs_as_presented_now(), .scrollbar_fade_damage_rect = scrollbar_fade_damage_rect };@@ -2389,7 +2387,8 @@ void ContextState::schedule_end_of_scroll_step_gestures(MonotonicTime now)}if (!m_scroll_step_gesture_input_timer) {m_scroll_step_gesture_input_timer = Core::Timer::create_single_shot(AK::Duration::from_milliseconds(0), [this] {- end_scroll_step_gestures_whose_input_ran_out(MonotonicTime::now());+ auto now = MonotonicTime::now();+ end_scroll_step_gestures_whose_input_ran_out(now);});}m_scroll_step_gesture_input_timer->restart(max(*deadline - now, AK::Duration::zero()));@@ -2404,14 +2403,14 @@ void ContextState::end_scroll_step_gestures_whose_input_ran_out(MonotonicTime noschedule_end_of_scroll_step_gestures(now);}-Optional<PendingFrame> ContextState::start_scrollbar_press_scroll(Compositing::AsyncScrollNode const& node, Gfx::FloatPoint old_scroll_offset, Gfx::FloatPoint destination, bool is_absolute_scroll)+Optional<PendingFrame> ContextState::start_scrollbar_press_scroll(Compositing::AsyncScrollNode const& node, Gfx::FloatPoint old_scroll_offset, Gfx::FloatPoint destination, bool is_absolute_scroll, MonotonicTime now){auto operation_id = m_async_scroll_update_outbox.allocate_operation_id();m_smooth_scroll_animations.append({.stable_node_id = node.stable_node_id,.operation_id = operation_id,.animation = Compositing::SmoothScrollAnimation { old_scroll_offset, destination, m_async_scroll_tree.device_pixels_per_css_pixel() },- .started_at = MonotonicTime::now(),+ .started_at = now,.is_user_scroll = true,.heads_to_an_extent = false,});@@ -2431,7 +2430,7 @@ static float scrollbar_page_step(float scrollport_length, float device_pixels_pe// Pages the scroller of the captured scrollbar once toward the pointer, from where a page scroll in flight goes, unless// the thumb has reached the pointer there.-Optional<PendingFrame> ContextState::page_captured_scrollbar()+Optional<PendingFrame> ContextState::page_captured_scrollbar(MonotonicTime now){auto scrollbar_index = m_scrollbar_controller.captured_scrollbar_index();if (!scrollbar_index.has_value() || !m_scrollbar_paging.has_value() || m_scrollbar_paging->direction == 0)@@ -2456,12 +2455,12 @@ Optional<PendingFrame> ContextState::page_captured_scrollbar()return {};if (running_animation) {- retarget_user_scroll(*running_animation, destination, MonotonicTime::now());+ retarget_user_scroll(*running_animation, destination, now);report_started_user_scroll(running_animation->operation_id, node->stable_node_id, step_start, destination, Compositing::ScrollAnimationKind::SmoothScroll, false);return PendingFrame::repainting_changes(m_async_scrolling_viewport_rect);}cancel_smooth_scroll_taken_over_by_user_input(scrollbar.scroll_node_index);- return start_scrollbar_press_scroll(*node, *old_scroll_offset, destination, false);+ return start_scrollbar_press_scroll(*node, *old_scroll_offset, destination, false, now);}ContextState::ActiveSmoothScrollAnimation* ContextState::running_scrollbar_press_scroll()@@ -2483,7 +2482,7 @@ void ContextState::stop_scrollbar_paging()m_scrollbar_paging_timer->stop();}-Optional<PendingFrame> ContextState::apply_scrollbar_drag(ScrollbarController::Drag const& drag)+Optional<PendingFrame> ContextState::apply_scrollbar_drag(ScrollbarController::Drag const& drag, MonotonicTime now){auto dragged_to = m_scrollbar_controller.scroll_offset_for_drag(m_async_scroll_tree, m_scroll_state_snapshot, drag);if (!dragged_to.has_value())@@ -2502,7 +2501,7 @@ Optional<PendingFrame> ContextState::apply_scrollbar_drag(ScrollbarController::Dif (auto* running_animation = running_scrollbar_press_scroll()) {if (running_animation->animation.destination_offset() == destination)return {};- retarget_user_scroll(*running_animation, destination, MonotonicTime::now());+ retarget_user_scroll(*running_animation, destination, now);report_started_user_scroll(running_animation->operation_id, node->stable_node_id, *old_scroll_offset, destination, Compositing::ScrollAnimationKind::SmoothScroll, true);return PendingFrame::repainting_changes(m_async_scrolling_viewport_rect);}@@ -2513,7 +2512,7 @@ Optional<PendingFrame> ContextState::apply_scrollbar_drag(ScrollbarController::Dcancel_smooth_scroll_taken_over_by_user_input(scroll_node_index);if (drag.is_press_beside_thumb)- return start_scrollbar_press_scroll(*node, *old_scroll_offset, destination, true);+ return start_scrollbar_press_scroll(*node, *old_scroll_offset, destination, true, now);auto new_scroll_offset = m_async_scroll_tree.set_scroll_offset(scroll_node_index, dragged_to->scroll_offset, m_scene.current_visual_context_tree(), m_scroll_state_snapshot);note_user_input_scrolled(node->stable_node_id);@@ -2548,9 +2547,9 @@ void ContextState::rebuild_wheel_hit_test_targets()m_scroll_state_snapshot);}-bool ContextState::visual_animations_need_frame()+bool ContextState::visual_animations_need_frame(MonotonicTime now){- return m_scene.visual_animations_need_frame(m_scroll_state_snapshot, m_viewport_size);+ return m_scene.visual_animations_need_frame(m_scroll_state_snapshot, m_viewport_size, now);}bool ContextState::advance_visual_animations(MonotonicTime now)diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.hindex 0b475059ab6..054e65a7c53 100644--- a/Services/Compositor/ContextState.h+++ b/Services/Compositor/ContextState.h@@ -184,18 +184,19 @@ public:void install_display_list_update(NonnullRefPtr<Compositing::DisplayList>,Compositing::AccumulatedVisualContextTree,- Compositing::ScrollStateSnapshot&&);+ Compositing::ScrollStateSnapshot&&,+ MonotonicTime now);// Returns false, leaving everything as it was, for a tree that does not fit the installed display list.- bool update_visual_context_tree(Compositing::AccumulatedVisualContextTree);+ bool update_visual_context_tree(Compositing::AccumulatedVisualContextTree, MonotonicTime now);void update_scroll_state(Compositing::ScrollStateSnapshot&&, Compositing::KeyboardScrollState);void invalidate_wheel_event_listener_state(u64 generation);void invalidate_keyboard_scroll_state(u64 generation);- ContextUpdateResult handle_key_event(Web::KeyEvent const&);+ ContextUpdateResult handle_key_event(Web::KeyEvent const&, MonotonicTime now);Optional<Web::AsyncScrollNodeStableID> box_scrolled_for_key_event(Web::KeyEvent const&) const;- ContextUpdateResult handle_mouse_event(Web::MouseEvent const&);+ ContextUpdateResult handle_mouse_event(Web::MouseEvent const&, MonotonicTime now);// A mouse event that the context this one is nested in hands to it, at a position in this context's device pixels.- ContextUpdateResult handle_mouse_event_from_containing_context(Web::MouseEvent const&, Gfx::FloatPoint position);+ ContextUpdateResult handle_mouse_event_from_containing_context(Web::MouseEvent const&, Gfx::FloatPoint position, MonotonicTime now);bool has_captured_scrollbar() const { return m_scrollbar_controller.has_captured_scrollbar(); }// The pointer left the scrollbar it was over here for a context nested in this one, or for the one around it.Optional<PendingFrame> clear_scrollbar_hover();@@ -218,12 +219,12 @@ public:};// Takes note of a wheel event from the UI as it arrives, ahead of anything that may turn it away or leave it to// the page.- NotedWheelEvent note_wheel_event_from_ui(Web::MouseEvent const&, Optional<MonotonicTime> now_for_testing = {});+ NotedWheelEvent note_wheel_event_from_ui(Web::MouseEvent const&, MonotonicTime now);// Takes note of a wheel event that the main thread has and the UI did not send here, as the UI's events are noted.// Such an event adds nothing to the velocity of a flick or of a stretch release.NotedWheelEvent note_wheel_event_from_main_thread(Web::MouseEvent const&, MonotonicTime now);// The UI's wheel deltas are in CSS pixels; this scales them for the scroll tree, which works in device pixels.- ContextUpdateResult handle_wheel_event(Web::MouseEvent const&, bool is_first_wheel_event_with_delta, WheelEventListenerGate const&, Optional<MonotonicTime> now_for_testing = {});+ ContextUpdateResult handle_wheel_event(Web::MouseEvent const&, bool is_first_wheel_event_with_delta, WheelEventListenerGate const&, MonotonicTime now);// Routes the event like one from the UI, also in a context that is nested in another one.ContextUpdateResult scroll_for_wheel_event_from_main_thread(Web::MouseEvent const&, bool is_first_wheel_event_with_delta, WheelEventListenerGate const&, Compositing::AsyncScrollOperationTracking, MonotonicTime now);Optional<u64> wheel_gesture_id() const { return m_wheel_gesture_routing.gesture_id(); }@@ -275,10 +276,10 @@ public:// nothing.ContextUpdateResult scroll_for_overtaken_wheel_step(WheelStep const&, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain, MonotonicTime now);Optional<Web::UniqueNodeID> document_id() const { return m_async_scroll_tree.document_id(); }- Optional<PendingFrame> apply_scroll_requests(ReadonlySpan<Compositing::ScrollRequest>);+ Optional<PendingFrame> apply_scroll_requests(ReadonlySpan<Compositing::ScrollRequest>, MonotonicTime now);void cancel_smooth_scroll(Web::AsyncScrollNodeStableID);Optional<Gfx::IntRect> advance_smooth_scroll_animations(MonotonicTime now);- bool needs_animation_frames() { return has_active_smooth_scroll_animations() || has_active_scroll_fling() || m_elastic_overscroll_controller.has_rebound() || visual_animations_need_frame() || m_scrollbar_controller.fades_need_frame(MonotonicTime::now()); }+ bool needs_animation_frames(MonotonicTime now) { return has_active_smooth_scroll_animations() || has_active_scroll_fling() || m_elastic_overscroll_controller.has_rebound() || visual_animations_need_frame(now) || m_scrollbar_controller.fades_need_frame(now); }bool has_active_scroll_fling() const { return m_scroll_fling_controller.is_active(); }// The wheel event of the next step of the fling, which is scrolled by like a wheel event from the UI.@@ -288,9 +289,9 @@ public:void end_scroll_fling_on_next_step();// Starts a fling if the gesture that the event ends was a flick. Use only on platforms that send no momentum// scroll events.- bool start_scroll_fling_if_flicked(Web::MouseEvent const& gesture_end_event, Optional<MonotonicTime> now_for_testing = {});+ bool start_scroll_fling_if_flicked(Web::MouseEvent const& gesture_end_event, MonotonicTime now);// Ends the fling before a wheel event from a new gesture or other input.- Optional<Web::MouseEvent> interrupt_scroll_fling(Web::MouseEvent const&, Optional<MonotonicTime> now_for_testing = {});+ Optional<Web::MouseEvent> interrupt_scroll_fling(Web::MouseEvent const&, MonotonicTime now);// Ends the fling, or the gesture whose momentum the platform is reporting, if it scrolls the box, so that the rest of// its momentum scrolls nothing. Returns the end of the gesture to send on to WebContent.Optional<Web::MouseEvent> end_momentum_scrolling(Web::AsyncScrollNodeStableID);@@ -311,7 +312,7 @@ public:// Where the first step of a wheel gesture at the position, by the delta in CSS pixels, would go.Compositing::FirstWheelStepRouteForTesting route_first_wheel_step_for_testing(Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels, Compositing::NestedContextRegions);bool advance_visual_animations(MonotonicTime now);- bool visual_animations_need_frame();+ bool visual_animations_need_frame(MonotonicTime now);// Where the pointer is in this context's device pixels, as the mouse event the context takes or hands on says, or// nowhere, as the pointer leaves it.void note_pointer_position(Optional<Gfx::FloatPoint>);@@ -348,13 +349,13 @@ public:// Each frame shows the scrollbars as of when it is painted, so this updates which of them are shown. Empty until a// display list is installed.- Optional<FrameInputs> frame_inputs();+ Optional<FrameInputs> frame_inputs(MonotonicTime now);struct ScreenshotInputs {FrameInputs frame_inputs;// The scrollbar fade damage that the screenshot does not present on screen.Gfx::IntRect scrollbar_fade_damage_rect;};- ScreenshotInputs frame_inputs_for_screenshot();+ ScreenshotInputs frame_inputs_for_screenshot(MonotonicTime now);private:struct ActiveSmoothScrollAnimation {@@ -411,13 +412,13 @@ private:// A step of a wheel gesture that is latched to the node. A stretch of the node is relaxed before the visual// viewport is panned, the node only scrolls by what both leave of the step, and what the node cannot scroll by// either is what pulls it past its edge.- WheelScrollOutcome perform_wheel_scroll_of_node(Compositing::SpatialNodeIndex, Gfx::FloatPoint delta, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, Compositing::AsyncScrollOperationTracking, Gfx::IntRect viewport_rect, MonotonicTime now, Compositing::ScrollChaining, VisualViewportPanning);+ WheelScrollOutcome perform_wheel_scroll_of_node(Compositing::SpatialNodeIndex, Gfx::FloatPoint delta, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, Compositing::AsyncScrollOperationTracking, Gfx::IntRect viewport_rect, Compositing::ScrollChaining, VisualViewportPanning, MonotonicTime now);struct NodeScrollByWheelDelta {WheelScrollOutcome outcome;// Empty when a wheel animation or a snap scroll took the delta, and when it scrolled an ancestor of the node.Optional<Gfx::FloatPoint> delta_the_node_did_not_scroll_by;};- NodeScrollByWheelDelta scroll_node_by_wheel_delta(Compositing::SpatialNodeIndex, Gfx::FloatPoint delta, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, Compositing::AsyncScrollOperationTracking, Gfx::IntRect viewport_rect, MonotonicTime now, Compositing::ScrollChaining);+ NodeScrollByWheelDelta scroll_node_by_wheel_delta(Compositing::SpatialNodeIndex, Gfx::FloatPoint delta, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, Compositing::AsyncScrollOperationTracking, Gfx::IntRect viewport_rect, Compositing::ScrollChaining, MonotonicTime now);WheelGestureRouting::ResolvedLatch resolve_wheel_scroll_latch(Web::ScrollGesturePhase, Optional<u64> gesture_id);struct WheelGestureLatchAttempt {Web::InputRoutingDecision decision;@@ -457,20 +458,20 @@ private:// A gesture whose steps this context chains ends once they stop arriving, which is reported to WebContent so// that it settles the gesture then rather than on a clock of its own.void end_scroll_step_gestures_whose_input_ran_out(MonotonicTime now);- ContextUpdateResult handle_mouse_event_at(Web::MouseEvent const&, Gfx::FloatPoint position);+ ContextUpdateResult handle_mouse_event_at(Web::MouseEvent const&, Gfx::FloatPoint position, MonotonicTime now);Optional<Compositing::NestedContextHit> nested_context_taking_mouse_event_at(Web::MouseEvent::Type, Gfx::FloatPoint position);Optional<PendingFrame> frame_repainting_scrollbars() const;Optional<size_t> scrollbar_under_pointer(Gfx::FloatPoint position);- Optional<PendingFrame> apply_scrollbar_drag(ScrollbarController::Drag const&);- Optional<PendingFrame> start_scrollbar_press_scroll(Compositing::AsyncScrollNode const&, Gfx::FloatPoint old_scroll_offset, Gfx::FloatPoint destination, bool is_absolute_scroll);- Optional<PendingFrame> page_captured_scrollbar();+ Optional<PendingFrame> apply_scrollbar_drag(ScrollbarController::Drag const&, MonotonicTime now);+ Optional<PendingFrame> start_scrollbar_press_scroll(Compositing::AsyncScrollNode const&, Gfx::FloatPoint old_scroll_offset, Gfx::FloatPoint destination, bool is_absolute_scroll, MonotonicTime now);+ Optional<PendingFrame> page_captured_scrollbar(MonotonicTime now);void stop_scrollbar_paging();// The smooth scroll that a press beside the thumb started, while it lasts.ActiveSmoothScrollAnimation* running_scrollbar_press_scroll();void rebuild_wheel_hit_test_targets();FrameInputs frame_inputs_as_presented_now();Gfx::IntRect damage_rect_of_blinking_carets();- void update_scrollbar_visibility();+ void update_scrollbar_visibility(MonotonicTime now);void report_scrollbar_visibility_changes();CompositorStateWebContentClient& m_web_content_client;diff --git a/Tests/Compositor/TestContextState.cpp b/Tests/Compositor/TestContextState.cppindex 3fdad8e495a..6ed832f0898 100644--- a/Tests/Compositor/TestContextState.cpp+++ b/Tests/Compositor/TestContextState.cpp@@ -36,7 +36,7 @@ static void install_display_list_without_scroll_nodes(Compositor::ContextState&auto visual_context_tree = builder.finish();auto display_list = Compositing::DisplayList::create(visual_context_tree);display_list->set_async_scrolling_metadata({ .document_id = document_id, .viewport_rect = { 0, 0, 800, 600 } });- context.install_display_list_update(display_list, move(visual_context_tree), {});+ context.install_display_list_update(display_list, move(visual_context_tree), {}, MonotonicTime::now());}static Web::PinchEvent pinch_event(double scale_delta)@@ -121,7 +121,7 @@ TEST_CASE(pinch_zoom_is_presented_until_the_main_thread_asks_for_another).smooth_scroll = {},.takes_over_from_momentum = false,};- (void)context.apply_scroll_requests({ &reset_zoom, 1 });+ (void)context.apply_scroll_requests({ &reset_zoom, 1 }, MonotonicTime::now());EXPECT(context.handle_pinch_event(pinch_event(1.0)).frame_to_present.has_value());}@@ -139,11 +139,11 @@ TEST_CASE(wheel_pans_the_zoomed_visual_viewport_of_a_page_without_scroll_nodes)wheel_event.wheel_delta_precision = Web::WheelDeltaPrecision::Precise;// Before the page is zoomed in, there is nothing for the wheel to pan.- EXPECT(!context.handle_wheel_event(wheel_event, false, {}).accepted);+ EXPECT(!context.handle_wheel_event(wheel_event, false, {}, MonotonicTime::now()).accepted);EXPECT(context.handle_pinch_event(pinch_event(1.0)).accepted);(void)context.take_pending_async_scroll_updates();- auto result = context.handle_wheel_event(wheel_event, false, {});+ auto result = context.handle_wheel_event(wheel_event, false, {}, MonotonicTime::now());EXPECT(result.accepted);EXPECT(result.frame_to_present.has_value());