Skip to content

Truly independent web browser

Compositor: Scroll fling steps where wheel events from the UI are

Aliaksandr Kalenikdbae2071fe98
diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cpp
index a4284315418..c78fae04e2c 100644
--- a/Services/Compositor/CompositorState.cpp
+++ b/Services/Compositor/CompositorState.cpp
@@ -521,7 +521,7 @@ bool CompositorState::handle_key_event(Web::CompositorContextId context_id, Web:
if (!context)
return false;
if (event.type == Web::KeyEvent::Type::KeyDown && Web::is_keyboard_scroll_key(event.key, Web::UIEvents::Mod_None))
- dispatch_scroll_fling_step(context_id, *context, context->end_scroll_fling(MonotonicTime::now()));
+ dispatch_scroll_fling_step(context_id, *context, context->end_scroll_fling(), MonotonicTime::now());
return apply_context_update_result(context_id, *context, context->handle_key_event(event));
}
@@ -550,7 +550,7 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId c
}
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(), MonotonicTime::now());
auto is_wheel_event = event.type == Web::MouseEvent::Type::MouseWheel;
if (is_wheel_event) {
@@ -565,7 +565,7 @@ 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));
+ dispatch_scroll_fling_step(context_id, *context, context->interrupt_scroll_fling(event), MonotonicTime::now());
// If the gesture continues as a fling, the end of the fling is the end of the gesture.
if (m_synthesizes_scroll_momentum && event.scroll_gesture_phase == Web::ScrollGesturePhase::Ended && context->start_scroll_fling_if_flicked(event)) {
@@ -578,7 +578,7 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId c
ContextState::ContextUpdateResult result;
if (is_wheel_event)
- result = context->handle_wheel_event(event);
+ result = scroll_for_wheel_step(*context, event, WheelStepOrigin::UI);
else
result = context->handle_mouse_event(event);
if (result.routing_decision.has_value()) {
@@ -626,16 +626,30 @@ bool CompositorState::nested_context_scrolled_since_last_frame(Web::CompositorCo
return false;
}
-void CompositorState::dispatch_scroll_fling_step(Web::CompositorContextId context_id, ContextState& context, Optional<ContextState::ScrollFlingStep> step)
+ContextState::ContextUpdateResult CompositorState::scroll_for_wheel_step(ContextState& context, Web::MouseEvent const& event, WheelStepOrigin origin, Optional<MonotonicTime> fling_step_time)
+{
+ if (origin == WheelStepOrigin::UI)
+ return context.handle_wheel_event(event);
+
+ auto result = context.scroll_for_fling_step(event, fling_step_time.value_or(MonotonicTime::now()));
+ // If the compositor accepts a momentum step of the fling but does not scroll, the scroller is at its edge.
+ // Alternatively, a snap scroll uses the step. The next display tick ends the fling.
+ if (event.scroll_gesture_phase == Web::ScrollGesturePhase::Momentum && result.accepted && !result.frame_to_present.has_value())
+ context.end_scroll_fling_on_next_step();
+ return result;
+}
+
+void CompositorState::dispatch_scroll_fling_step(Web::CompositorContextId context_id, ContextState& context, Optional<Web::MouseEvent> event, MonotonicTime now)
{
// Send each fling step on the same route as a wheel event from the UI.
- if (!step.has_value())
+ if (!event.has_value())
return;
- if (step->result.routing_decision.has_value())
- context.input_trace().record({ .input_event_id = step->event.id, .stage = Web::InputTraceStage::Compositor, .decision = *step->result.routing_decision, .scroller = step->result.routed_scroller });
- step->event.async_scroll_performed_default_action = apply_context_update_result(context_id, context, step->result);
+ auto result = scroll_for_wheel_step(context, *event, WheelStepOrigin::Fling, now);
+ if (result.routing_decision.has_value())
+ context.input_trace().record({ .input_event_id = event->id, .stage = Web::InputTraceStage::Compositor, .decision = *result.routing_decision, .scroller = result.routed_scroller });
+ event->async_scroll_performed_default_action = apply_context_update_result(context_id, context, result);
schedule_animation_frames_if_needed(context);
- context.dispatch_mouse_event_to_web_content(step->event);
+ context.dispatch_mouse_event_to_web_content(*event);
}
void CompositorState::handle_pinch_event(Web::CompositorContextId context_id, Web::PinchEvent const& event)
@@ -760,7 +774,7 @@ void CompositorState::set_context_visibility(Web::CompositorContextId 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(), MonotonicTime::now());
if (!context->set_visibility(visibility))
return;
@@ -988,7 +1002,7 @@ void CompositorState::present_pending_frames_on_vsync(Optional<u64> display_id,
auto presents_on_display = context.has_pending_present_frame_scheduled_on(display_id) || has_active_animation_on_display;
if (presents_on_display) {
if (display_id_for_context(context) == display_id)
- dispatch_scroll_fling_step(context_id, context, context.take_scroll_fling_step(frame_time));
+ dispatch_scroll_fling_step(context_id, context, context.take_scroll_fling_step(frame_time), frame_time);
if (auto animation_frame = context.advance_smooth_scroll_animations(frame_time); animation_frame.has_value())
context.presenter().queue_present_frame(PendingFrame::repainting_changes(*animation_frame));
if (auto rebound_frame = context.advance_elastic_overscroll_rebounds(frame_time); rebound_frame.has_value())
diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.h
index 2caafa9197f..d2778f90cda 100644
--- a/Services/Compositor/CompositorState.h
+++ b/Services/Compositor/CompositorState.h
@@ -214,7 +214,13 @@ private:
ContextState&,
ContextState::ContextUpdateResult const&);
void schedule_animation_frames_if_needed(ContextState&);
- void dispatch_scroll_fling_step(Web::CompositorContextId, ContextState&, Optional<ContextState::ScrollFlingStep>);
+ enum class WheelStepOrigin : u8 {
+ UI,
+ Fling,
+ };
+ // A fling step is scrolled at the frame time the fling synthesized it for.
+ ContextState::ContextUpdateResult scroll_for_wheel_step(ContextState&, Web::MouseEvent const&, WheelStepOrigin, Optional<MonotonicTime> fling_step_time = {});
+ void dispatch_scroll_fling_step(Web::CompositorContextId, ContextState&, Optional<Web::MouseEvent>, MonotonicTime now);
void present_frame(Web::CompositorContextId, ContextState&, PendingFrame);
void schedule_present_frame(Web::CompositorContextId, ContextState&, PendingFrame);
void schedule_present_frame(Web::CompositorContextId, ContextState&, Gfx::IntRect viewport_rect);
diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cpp
index a0e90d0e4b1..2ce82418181 100644
--- a/Services/Compositor/ContextState.cpp
+++ b/Services/Compositor/ContextState.cpp
@@ -1120,41 +1120,29 @@ bool ContextState::start_scroll_fling_if_flicked(Web::MouseEvent const& gesture_
return m_scroll_fling_controller.start_if_flicked(gesture_end_event, now_for_testing.value_or(MonotonicTime::now()));
}
-Optional<ContextState::ScrollFlingStep> ContextState::interrupt_scroll_fling(Web::MouseEvent const& event, Optional<MonotonicTime> now_for_testing)
+Optional<Web::MouseEvent> ContextState::interrupt_scroll_fling(Web::MouseEvent const& event, Optional<MonotonicTime> now_for_testing)
{
- auto now = now_for_testing.value_or(MonotonicTime::now());
- auto end_event = m_scroll_fling_controller.interrupt(event, now);
- if (!end_event.has_value())
- return {};
- return scroll_for_fling_event(end_event.release_value(), now);
+ return m_scroll_fling_controller.interrupt(event, now_for_testing.value_or(MonotonicTime::now()));
}
-Optional<ContextState::ScrollFlingStep> ContextState::take_scroll_fling_step(MonotonicTime frame_time)
+Optional<Web::MouseEvent> ContextState::take_scroll_fling_step(MonotonicTime frame_time)
{
- auto event = m_scroll_fling_controller.take_step(frame_time);
- if (!event.has_value())
- return {};
- auto step = scroll_for_fling_event(event.release_value(), frame_time);
+ return m_scroll_fling_controller.take_step(frame_time);
+}
- // If the compositor accepts the step but does not scroll, the scroller is at its edge.
- // Alternatively, a snap scroll uses the step. The next display tick ends the fling.
- if (step.event.scroll_gesture_phase == Web::ScrollGesturePhase::Momentum && step.result.accepted && !step.result.frame_to_present.has_value())
- m_scroll_fling_controller.end_on_next_step();
- return step;
+Optional<Web::MouseEvent> ContextState::end_scroll_fling()
+{
+ return m_scroll_fling_controller.end();
}
-Optional<ContextState::ScrollFlingStep> ContextState::end_scroll_fling(MonotonicTime now)
+ContextState::ContextUpdateResult ContextState::scroll_for_fling_step(Web::MouseEvent const& event, MonotonicTime now)
{
- auto end_event = m_scroll_fling_controller.end();
- if (!end_event.has_value())
- return {};
- return scroll_for_fling_event(end_event.release_value(), now);
+ return scroll_for_wheel_event(event, now);
}
-ContextState::ScrollFlingStep ContextState::scroll_for_fling_event(Web::MouseEvent event, MonotonicTime now)
+void ContextState::end_scroll_fling_on_next_step()
{
- auto result = scroll_for_wheel_event(event, now);
- return ScrollFlingStep { move(event), move(result) };
+ m_scroll_fling_controller.end_on_next_step();
}
ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event(Web::MouseEvent const& event, MonotonicTime now)
diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.h
index 03684289f64..3b7c33b8693 100644
--- a/Services/Compositor/ContextState.h
+++ b/Services/Compositor/ContextState.h
@@ -142,17 +142,16 @@ public:
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_presenter.ui_overlay_fades_need_frame(); }
bool has_active_scroll_fling() const { return m_scroll_fling_controller.is_active(); }
- struct ScrollFlingStep {
- Web::MouseEvent event;
- ContextUpdateResult result;
- };
- Optional<ScrollFlingStep> take_scroll_fling_step(MonotonicTime frame_time);
- Optional<ScrollFlingStep> end_scroll_fling(MonotonicTime now);
+ // The wheel event of the next step of the fling, which is scrolled by like a wheel event from the UI.
+ Optional<Web::MouseEvent> take_scroll_fling_step(MonotonicTime frame_time);
+ Optional<Web::MouseEvent> end_scroll_fling();
+ ContextUpdateResult scroll_for_fling_step(Web::MouseEvent const&, MonotonicTime now);
+ 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 = {});
// Ends the fling before a wheel event from a new gesture or other input.
- Optional<ScrollFlingStep> interrupt_scroll_fling(Web::MouseEvent const&, Optional<MonotonicTime> now_for_testing = {});
+ Optional<Web::MouseEvent> interrupt_scroll_fling(Web::MouseEvent const&, Optional<MonotonicTime> now_for_testing = {});
void set_scrolls_elastically(bool);
Optional<Gfx::IntRect> advance_elastic_overscroll_rebounds(MonotonicTime frame_time);
// The installed scrolling state, its routing admission, and how far the given scroller is stretched, as JSON.
@@ -261,7 +260,6 @@ private:
ContextUpdateResult scroll_for_wheel_event(Web::MouseEvent const&, MonotonicTime now);
Gfx::FloatPoint wheel_event_delta_in_device_pixels(Web::MouseEvent const&) const;
bool step_continues_touchpad_gesture_the_page_let_through(Optional<Compositing::AsyncScrollNodeID> const& latched_node_id, Web::WheelDeltaPrecision, Web::ScrollGesturePhase) const;
- ScrollFlingStep scroll_for_fling_event(Web::MouseEvent, MonotonicTime now);
Optional<Gfx::FloatPoint> in_flight_wheel_destination(Web::AsyncScrollNodeStableID) const;
AsyncScrollResult smooth_wheel_scroll_by(Optional<Compositing::WheelScrollTarget> const&, Gfx::IntRect viewport_rect, MonotonicTime now);
void retarget_user_scroll(ActiveSmoothScrollAnimation&, Gfx::FloatPoint destination_offset, MonotonicTime now);