Truly independent web browser
LibWeb: Remove the main thread's momentum snapping
Aliaksandr Kalenik9ff4d07ddffc
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex 76461cb007c..e201db8f9df 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -5282,16 +5282,12 @@ void LocalNavigable::note_user_scroll_gesture_phase(Web::ScrollGesturePhase phasswitch (phase) {case Web::ScrollGesturePhase::None:m_user_scroll_gesture_travels_under_momentum = false;- reset_momentum_fling_state();release_wheel_user_scroll_gesture_hold();break;case Web::ScrollGesturePhase::Ongoing:case Web::ScrollGesturePhase::Momentum: {bool travels_under_momentum = phase == Web::ScrollGesturePhase::Momentum;- if (!travels_under_momentum)- reset_momentum_fling_state();-// Fingers that touch down during momentum start another gesture, which settles the flicked one.if (m_wheel_user_scroll_gesture_hold && m_user_scroll_gesture_travels_under_momentum && !travels_under_momentum)release_wheel_user_scroll_gesture_hold();@@ -5303,7 +5299,6 @@ void LocalNavigable::note_user_scroll_gesture_phase(Web::ScrollGesturePhase phas}case Web::ScrollGesturePhase::Ended:m_user_scroll_gesture_travels_under_momentum = false;- reset_momentum_fling_state();if (m_wheel_user_scroll_gesture_hold) {release_wheel_user_scroll_gesture_hold();break;@@ -5340,12 +5335,6 @@ void LocalNavigable::release_wheel_user_scroll_gesture_hold()m_wheel_user_scroll_gesture_hold = nullptr;}-void LocalNavigable::reset_momentum_fling_state()-{- m_momentum_snap_position_selection = MomentumSnapPositionSelection::NotSelectedYet;- m_momentum_fling_estimator.reset();-}-void LocalNavigable::snap_user_scroll_gestures_that_awaited_layout(){bool any_gesture_awaited_layout = false;@@ -7591,7 +7580,7 @@ GC::Ref<WebIDL::Promise> LocalNavigable::perform_a_scroll_of_an_element(DOM::Elebool LocalNavigable::perform_a_scroll_step_for_key_input(Layout::Node& scroll_container, CSSPixelPoint delta, Compositing::SnapSelectionStrategy::Type strategy_type){- if (perform_a_snapped_relative_user_scroll(scroll_container, delta, strategy_type, SnapStepAccumulation::UntilScrollFinishes))+ if (perform_a_snapped_relative_user_scroll(scroll_container, delta, strategy_type))return true;auto document = active_document();@@ -7632,7 +7621,7 @@ bool LocalNavigable::perform_a_scroll_step_for_key_input(Layout::Node& scroll_coreturn true;}-bool LocalNavigable::perform_a_snapped_relative_user_scroll(Layout::Node& scroll_container, CSSPixelPoint delta, Compositing::SnapSelectionStrategy::Type strategy_type, SnapStepAccumulation step_accumulation, Compositing::ScrollAnimationKind animation_kind, Painting::ScrollKind scroll_kind)+bool LocalNavigable::perform_a_snapped_relative_user_scroll(Layout::Node& scroll_container, CSSPixelPoint delta, Compositing::SnapSelectionStrategy::Type strategy_type, Painting::ScrollKind scroll_kind){auto document = active_document();if (!document)@@ -7657,8 +7646,7 @@ bool LocalNavigable::perform_a_snapped_relative_user_scroll(Layout::Node& scroll// snap position it is scrolling to, so a burst of steps advances by the distance they asked for instead of by one// snap position each.auto* latched_gesture = user_scroll_gesture_for(*stable_node_id);- bool travels_from_input_deltas = latched_gesture- && (step_accumulation == SnapStepAccumulation::UntilGestureSettles || in_flight_destination.has_value());+ bool travels_from_input_deltas = latched_gesture && in_flight_destination.has_value();auto step_start = travels_from_input_deltas? latched_gesture->unsnapped_scroll_destination.value_or(*current_scroll_offset): *current_scroll_offset;@@ -7700,34 +7688,11 @@ bool LocalNavigable::perform_a_snapped_relative_user_scroll(Layout::Node& scroll.position = snap_destination.position,.behavior = Bindings::ScrollBehavior::Smooth,.trigger = ScrollTrigger::UserInput,- .animation_kind = animation_kind,.scroll_kind = scroll_kind,});return true;}-// https://drafts.csswg.org/css-scroll-snap-1/#choosing-bool LocalNavigable::perform_a_snapped_momentum_scroll(Layout::Node& scroll_container, CSSPixelPoint momentum_delta)-{- if (m_momentum_snap_position_selection == MomentumSnapPositionSelection::ScrollingToSelectedPosition)- return true;-- if (m_momentum_snap_position_selection == MomentumSnapPositionSelection::NoPositionSelected)- return false;-- auto remaining_displacement = m_momentum_fling_estimator.estimate_remaining_displacement(momentum_delta);- if (!remaining_displacement.has_value())- return false;-- if (!perform_a_snapped_relative_user_scroll(scroll_container, *remaining_displacement, Compositing::SnapSelectionStrategy::Type::EndPositionAndDirection, SnapStepAccumulation::UntilScrollFinishes, Compositing::ScrollAnimationKind::Momentum)) {- m_momentum_snap_position_selection = MomentumSnapPositionSelection::NoPositionSelected;- return false;- }-- m_momentum_snap_position_selection = MomentumSnapPositionSelection::ScrollingToSelectedPosition;- return true;-}-Optional<CSSPixelPoint> LocalNavigable::in_flight_user_scroll_destination(Web::AsyncScrollNodeStableID stable_node_id, Compositing::ScrollAnimationKind animation_kind) const{auto in_flight_scroll = in_flight_scroll_for(stable_node_id);diff --git a/Libraries/LibWeb/HTML/LocalNavigable.h b/Libraries/LibWeb/HTML/LocalNavigable.hindex cf8b42d5446..7c729fb6cd9 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.h+++ b/Libraries/LibWeb/HTML/LocalNavigable.h@@ -398,23 +398,13 @@ public:PerScroll,};- // How long the offset a gesture's input deltas have reached goes on being the offset its next step travels from.- // A wheel gesture stays latched between its steps, so its deltas keep accumulating until it settles, and crossing a- // snap position costs the distance between them however slowly the steps arrive. Keys are separate commands rather- // than one gesture, so each press travels from the scrolling box itself.- enum class SnapStepAccumulation {- UntilScrollFinishes,- UntilGestureSettles,- };-bool scroll_scrolling_box_by_delta(Layout::Node&, CSSPixelPoint delta, Painting::ScrollKind, Compositing::ScrollAnimationKind = Compositing::ScrollAnimationKind::SmoothScroll);bool continued_scroll_step_moves(Layout::Node&, CSSPixelPoint delta, Compositing::ScrollAnimationKind);bool scroll_viewport_by_delta(CSSPixelPoint delta, Bindings::ScrollBehavior, Painting::ScrollKind, Compositing::ScrollAnimationKind = Compositing::ScrollAnimationKind::SmoothScroll);GC::Ref<WebIDL::Promise> perform_a_scroll_of_the_viewport(CSSPixelPoint position, Bindings::ScrollBehavior = Bindings::ScrollBehavior::Auto, ScrollTrigger = ScrollTrigger::Programmatic, Optional<CSSPixelPoint> relative_displacement = {}, Painting::ScrollKind = Painting::ScrollKind::Absolute, Compositing::ScrollAnimationKind = Compositing::ScrollAnimationKind::SmoothScroll);GC::Ref<WebIDL::Promise> perform_a_scroll_of_an_element(DOM::Element&, CSSPixelPoint position, Bindings::ScrollBehavior, Optional<CSSPixelPoint> relative_displacement = {});- bool perform_a_snapped_relative_user_scroll(Layout::Node&, CSSPixelPoint delta, Compositing::SnapSelectionStrategy::Type, SnapStepAccumulation, Compositing::ScrollAnimationKind = Compositing::ScrollAnimationKind::SmoothScroll, Painting::ScrollKind = Painting::ScrollKind::Relative);+ bool perform_a_snapped_relative_user_scroll(Layout::Node&, CSSPixelPoint delta, Compositing::SnapSelectionStrategy::Type, Painting::ScrollKind = Painting::ScrollKind::Relative);bool perform_a_scroll_step_for_key_input(Layout::Node&, CSSPixelPoint delta, Compositing::SnapSelectionStrategy::Type);- bool perform_a_snapped_momentum_scroll(Layout::Node&, CSSPixelPoint momentum_delta);Layout::Node* layout_node_for_async_scroll_node_stable_id(Web::AsyncScrollNodeStableID);void re_snap_scroll_containers_after_layout_change(Layout::BegunRead const& read);void abort_in_flight_smooth_scrolls(Web::AsyncScrollNodeStableID);@@ -588,7 +578,6 @@ private:void abandon_snapping_of_user_scroll_gesture(Web::AsyncScrollNodeStableID);void note_user_scroll_gesture_input_ended(Web::AsyncScrollNodeStableID);void release_wheel_user_scroll_gesture_hold();- void reset_momentum_fling_state();void cancel_scroll_sequences();void schedule_hover_update_after_async_scroll();void update_hover_after_async_scroll_stops();@@ -690,15 +679,6 @@ private:bool m_scroll_sequences_may_have_completed { false };Compositing::SnapSelectionStrategy::Type m_user_scroll_input_intent { Compositing::SnapSelectionStrategy::Type::EndPosition };bool m_user_scroll_gesture_travels_under_momentum { false };- // Momentum that selects no snap position is scrolled by for the rest of the gesture rather than being asked again- // for each delta it produces.- enum class MomentumSnapPositionSelection : u8 {- NotSelectedYet,- ScrollingToSelectedPosition,- NoPositionSelected,- };- MomentumSnapPositionSelection m_momentum_snap_position_selection { MomentumSnapPositionSelection::NotSelectedYet };- Compositing::MomentumFlingEstimator m_momentum_fling_estimator;bool m_is_re_snapping_scroll_containers { false };struct PendingAsyncScrollOperation {diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cppindex 1c976b92af2..f089a9c70fd 100644--- a/Libraries/LibWeb/Page/EventHandler.cpp+++ b/Libraries/LibWeb/Page/EventHandler.cpp@@ -2230,7 +2230,7 @@ EventResult EventHandler::handle_keydown(UIEvents::KeyCode key, u32 modifiers, uauto* scrolling_box = scrolling_box_for_key_input(read, delta);if (!scrolling_box)return false;- return m_navigable->perform_a_snapped_relative_user_scroll(*scrolling_box, delta, Compositing::SnapSelectionStrategy::Type::EndPosition, HTML::LocalNavigable::SnapStepAccumulation::UntilScrollFinishes, Compositing::ScrollAnimationKind::SmoothScroll, Painting::ScrollKind::Absolute);+ return m_navigable->perform_a_snapped_relative_user_scroll(*scrolling_box, delta, Compositing::SnapSelectionStrategy::Type::EndPosition, Painting::ScrollKind::Absolute);};auto scroll_by_for_key_input = [&](CSSPixels delta_x, CSSPixels delta_y, Compositing::SnapSelectionStrategy::Type intent) {auto key_holds_boxes_it_scrolls = hold_scroll_gesture_until_key_release(intent);diff --git a/Libraries/LibWeb/Painting/ScrollSnap.h b/Libraries/LibWeb/Painting/ScrollSnap.hindex 0189e9d8024..55a684e781e 100644--- a/Libraries/LibWeb/Painting/ScrollSnap.h+++ b/Libraries/LibWeb/Painting/ScrollSnap.h@@ -17,7 +17,6 @@namespace Web::Painting {-using Compositing::MomentumFlingEstimator;using Compositing::SnapAreaGeometry;using Compositing::SnapAreaIdentity;using Compositing::SnapAxes;