Skip to content

Truly independent web browser

Compositor: Smooth scroll to where the scrollbar gutter is pressed

Andreas Klingbdbba44c5dbc
diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cpp
index 55e7eff2486..35b950b66f6 100644
--- a/Services/Compositor/CompositorState.cpp
+++ b/Services/Compositor/CompositorState.cpp
@@ -673,9 +673,10 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId c
// Schedules the present, publishes the scroll updates the event produced and asks for a rendering update, all of
// which reach WebContent ahead of the event itself on the same connection.
auto handled = apply_context_update_result(context_id, *context, result);
+ // A wheel event that lets go of a stretched scroller presents nothing itself; the rebound does from here on. A press
+ // beside the thumb of a scrollbar scrolls there in an animation too.
+ schedule_animation_frames_if_needed(*context);
if (is_wheel_event) {
- // A wheel event that lets go of a stretched scroller presents nothing itself; the rebound does from here on.
- schedule_animation_frames_if_needed(*context);
event.async_scroll_performed_default_action = handled;
} else if (handled) {
// The page still sees the events of a drag the compositor scrolls for a scrollbar the display list paints.
diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cpp
index b554d4b4394..db7f52e6c49 100644
--- a/Services/Compositor/ContextState.cpp
+++ b/Services/Compositor/ContextState.cpp
@@ -397,6 +397,7 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event(Web::MouseEve
auto drag = m_scrollbar_controller.begin_drag(m_async_scroll_tree, m_scene.visual_context_tree_for_compositing(), m_scroll_state_snapshot, position);
if (!drag.has_value())
return ContextUpdateResult::declined(Web::InputRoutingDecision::NotOverAScrollbar);
+ m_scrollbar_press_scroll_operation.clear();
ContextUpdateResult result;
result.accepted = true;
@@ -1828,10 +1829,41 @@ Optional<PendingFrame> ContextState::apply_scrollbar_drag(ScrollbarController::D
auto old_scroll_offset = m_async_scroll_tree.scroll_offset_for_node(node_id, m_scroll_state_snapshot);
if (!node || !old_scroll_offset.has_value())
return {};
- if (m_async_scroll_tree.clamped_scroll_offset_for_node(node_id, dragged_to->scroll_offset) == *old_scroll_offset)
+ auto destination = m_async_scroll_tree.clamped_scroll_offset_for_node(node_id, dragged_to->scroll_offset);
+
+ // A press beside the thumb scrolls there smoothly, as a page step does. Dragging on before that scroll has ended
+ // moves where it goes.
+ if (m_scrollbar_press_scroll_operation.has_value()) {
+ auto running_animation = m_smooth_scroll_animations.find_if([&](auto const& animation) { return animation.operation_id == *m_scrollbar_press_scroll_operation; });
+ if (running_animation != m_smooth_scroll_animations.end()) {
+ if (running_animation->animation.destination_offset() == destination)
+ return {};
+ retarget_user_scroll(*running_animation, destination, MonotonicTime::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);
+ }
+ m_scrollbar_press_scroll_operation.clear();
+ }
+
+ if (destination == *old_scroll_offset)
return {};
cancel_smooth_scroll_taken_over_by_user_input(node_id);
+
+ if (drag.is_press_beside_thumb) {
+ 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(),
+ .is_user_scroll = true,
+ });
+ report_started_user_scroll(operation_id, node->stable_node_id, *old_scroll_offset, destination, Compositing::ScrollAnimationKind::SmoothScroll, true);
+ m_scrollbar_press_scroll_operation = operation_id;
+ return PendingFrame::repainting_changes(m_async_scrolling_viewport_rect);
+ }
+
auto new_scroll_offset = m_async_scroll_tree.set_scroll_offset(node_id, dragged_to->scroll_offset, m_scene.current_visual_context_tree(), m_scroll_state_snapshot);
VERIFY(new_scroll_offset.has_value());
rebuild_wheel_hit_test_targets();
diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.h
index db6f0c0b5e3..4f3a678dbfe 100644
--- a/Services/Compositor/ContextState.h
+++ b/Services/Compositor/ContextState.h
@@ -354,6 +354,8 @@ private:
RefPtr<Core::Timer> m_scroll_step_gesture_input_timer;
WheelGestureRouting m_wheel_gesture_routing;
Vector<ActiveSmoothScrollAnimation> m_smooth_scroll_animations;
+ // The smooth scroll that a press beside the thumb of the captured scrollbar started.
+ Optional<Compositing::AsyncScrollOperationID> m_scrollbar_press_scroll_operation;
ScrollFlingController m_scroll_fling_controller;
ElasticOverscrollController m_elastic_overscroll_controller;
Gfx::IntRect m_async_scrolling_viewport_rect;
diff --git a/Services/Compositor/ScrollbarController.cpp b/Services/Compositor/ScrollbarController.cpp
index 7f42438a9b8..f58759543cd 100644
--- a/Services/Compositor/ScrollbarController.cpp
+++ b/Services/Compositor/ScrollbarController.cpp
@@ -237,7 +237,7 @@ Optional<ScrollbarController::Drag> ScrollbarController::begin_drag(Compositing:
m_hovered_scrollbar_index = *scrollbar_index;
m_thumb_grab_position = thumb_grab_position;
m_last_primary_position_of_captured_drag = primary_position;
- return Drag { *scrollbar_index, primary_position, thumb_grab_position };
+ return Drag { *scrollbar_index, primary_position, thumb_grab_position, !position_is_along_thumb };
}
// A drag usually leaves the clip of its scrollbar, and the spaces above the scrollbar may move while it lasts, so the
diff --git a/Services/Compositor/ScrollbarController.h b/Services/Compositor/ScrollbarController.h
index 39ed135d691..2b566500d4d 100644
--- a/Services/Compositor/ScrollbarController.h
+++ b/Services/Compositor/ScrollbarController.h
@@ -38,6 +38,8 @@ public:
size_t scrollbar_index { 0 };
float primary_position { 0 };
float thumb_grab_position { 0 };
+ // Whether this is the press that began the drag, beside the thumb rather than on it.
+ bool is_press_beside_thumb { false };
};
struct ScrollOffset {