Skip to content

Truly independent web browser

LibCompositing: Manually scroll out of overscroll without stiffness

Zaggy1024e68b9f90184f
diff --git a/Libraries/LibCompositing/Scrolling/ElasticOverscroll.cpp b/Libraries/LibCompositing/Scrolling/ElasticOverscroll.cpp
index 3e62b598d28..b976ec3f8d2 100644
--- a/Libraries/LibCompositing/Scrolling/ElasticOverscroll.cpp
+++ b/Libraries/LibCompositing/Scrolling/ElasticOverscroll.cpp
@@ -9,7 +9,7 @@
namespace Compositing {
-// The stretch is the overscroll divided by the stiffness, and a released stretch S0 with velocity V0 is
+// A pull stretches by the overscroll divided by the stiffness, and a released stretch S0 with velocity V0 is
// (S0 + amplitude * V0 * t) * exp(-t * stiffness / period) after t seconds.
static constexpr double rubber_band_stiffness = 20;
static constexpr double rubber_band_amplitude = 0.31;
@@ -46,12 +46,11 @@ static float relax_axis_by(float& stretch, float delta)
bool delta_points_back_to_scroll_range = (stretch > 0 && delta < 0) || (stretch < 0 && delta > 0);
if (!delta_points_back_to_scroll_range)
return delta;
- auto stretch_delta = static_cast<float>(delta / rubber_band_stiffness);
- if (AK::abs(stretch_delta) <= AK::abs(stretch)) {
- stretch += stretch_delta;
+ if (AK::abs(delta) <= AK::abs(stretch)) {
+ stretch += delta;
return 0;
}
- auto delta_left_to_scroll_with = static_cast<float>(delta + stretch * rubber_band_stiffness);
+ auto delta_left_to_scroll_with = delta + stretch;
stretch = 0;
return delta_left_to_scroll_with;
}
diff --git a/Tests/LibCompositing/TestElasticOverscroll.cpp b/Tests/LibCompositing/TestElasticOverscroll.cpp
index 74ba4ec3327..d33117a8de8 100644
--- a/Tests/LibCompositing/TestElasticOverscroll.cpp
+++ b/Tests/LibCompositing/TestElasticOverscroll.cpp
@@ -37,18 +37,19 @@ TEST_CASE(pull_never_stretches_past_the_scrollport_length)
EXPECT_EQ(overscroll.stretch(), Gfx::FloatPoint(800, 600));
}
-TEST_CASE(delta_back_to_the_scroll_range_relaxes_the_stretch_before_it_scrolls)
+TEST_CASE(delta_back_to_the_scroll_range_relaxes_the_stretch_one_to_one_before_it_scrolls)
{
ElasticOverscroll overscroll { scrollport_size };
overscroll.pull_by({ 0, -400 });
+ EXPECT_EQ(overscroll.stretch(), Gfx::FloatPoint(0, -20));
- EXPECT_EQ(overscroll.relax_by({ 7, 100 }), Gfx::FloatPoint(7, 0));
+ EXPECT_EQ(overscroll.relax_by({ 7, 5 }), Gfx::FloatPoint(7, 0));
EXPECT_EQ(overscroll.stretch(), Gfx::FloatPoint(0, -15));
EXPECT_EQ(overscroll.relax_by({ 0, -50 }), Gfx::FloatPoint(0, -50));
EXPECT_EQ(overscroll.stretch(), Gfx::FloatPoint(0, -15));
- EXPECT_EQ(overscroll.relax_by({ 0, 350 }), Gfx::FloatPoint(0, 50));
+ EXPECT_EQ(overscroll.relax_by({ 0, 65 }), Gfx::FloatPoint(0, 50));
EXPECT(overscroll.is_at_rest());
}
diff --git a/Tests/LibWeb/Text/expected/async-scrolling/elastic-overscroll-gesture-starting-at-an-edge.txt b/Tests/LibWeb/Text/expected/async-scrolling/elastic-overscroll-gesture-starting-at-an-edge.txt
index 00529601c09..88f34069f33 100644
--- a/Tests/LibWeb/Text/expected/async-scrolling/elastic-overscroll-gesture-starting-at-an-edge.txt
+++ b/Tests/LibWeb/Text/expected/async-scrolling/elastic-overscroll-gesture-starting-at-an-edge.txt
@@ -1,5 +1,5 @@
pulled past the top of the page: viewport stretch=0,-20 window.scrollY=0 nested stretch=0 nested.scrollTop=0
sprung back: viewport stretch=0,0 window.scrollY=0 nested stretch=0 nested.scrollTop=0
pulled over the nested scroller: viewport stretch=0,-20 window.scrollY=0 nested stretch=0 nested.scrollTop=0
-moved back into the scroll range: viewport stretch=0,0 window.scrollY=100 nested stretch=0 nested.scrollTop=0
+moved back into the scroll range: viewport stretch=0,0 window.scrollY=480 nested stretch=0 nested.scrollTop=0
pulled sideways: viewport stretch=0,0 window.scrollY=0 nested stretch=0 nested.scrollTop=0
diff --git a/Tests/LibWeb/Text/expected/async-scrolling/elastic-overscroll-stretches-scroller-at-its-edge.txt b/Tests/LibWeb/Text/expected/async-scrolling/elastic-overscroll-stretches-scroller-at-its-edge.txt
index edbfa624ee0..37156c1bd0b 100644
--- a/Tests/LibWeb/Text/expected/async-scrolling/elastic-overscroll-stretches-scroller-at-its-edge.txt
+++ b/Tests/LibWeb/Text/expected/async-scrolling/elastic-overscroll-stretches-scroller-at-its-edge.txt
@@ -2,5 +2,5 @@ inside the scroll range: nested.scrollTop=150 nested stretch=0 window.scrollY=0
reaching the edge: nested.scrollTop=200 nested stretch=5 window.scrollY=0 viewport stretch=0
pulling at the edge: nested.scrollTop=200 nested stretch=10 window.scrollY=0 viewport stretch=0
horizontal stretch: 0
-moving back: nested.scrollTop=200 nested stretch=5 window.scrollY=0 viewport stretch=0
-moving back into the scroll range: nested.scrollTop=150 nested stretch=0 window.scrollY=0 viewport stretch=0
+moving back: nested.scrollTop=110 nested stretch=0 window.scrollY=0 viewport stretch=0
+moving back into the scroll range: nested.scrollTop=0 nested stretch=-2 window.scrollY=0 viewport stretch=0