Improve overscroll handling.

This commit is contained in:
John Preston 2023-07-14 16:08:47 +04:00
parent b6cb6cb770
commit fd1752a5c2
2 changed files with 11 additions and 11 deletions

View file

@ -412,7 +412,8 @@ void ElasticScroll::touchDeaccelerate(int32 elapsed) {
}
void ElasticScroll::overscrollReturn() {
_ignoreMomentum = _overscrollReturning = true;
_overscrollReturning = true;
_ignoreMomentumFromOverscroll = _overscroll;
if (overscrollFinish()) {
_overscrollReturnAnimation.stop();
return;
@ -647,20 +648,19 @@ bool ElasticScroll::handleWheelEvent(not_null<QWheelEvent*> e, bool touch) {
const auto guard = gsl::finally([&] {
_lastScroll = now;
});
if (_ignoreMomentum) {
if (momentum) {
if (!_overscrollReturnAnimation.animating()) {
return true;
}
} else {
_ignoreMomentum = false;
}
}
const auto pixels = ScrollDelta(e);
auto delta = _vertical ? -pixels.y() : pixels.x();
if (std::abs(_vertical ? pixels.x() : pixels.y()) >= std::abs(delta)) {
delta = 0;
}
if (_ignoreMomentumFromOverscroll) {
if (!momentum) {
_ignoreMomentumFromOverscroll = 0;
} else if (!_overscrollReturnAnimation.animating()
&& !base::OppositeSigns(_ignoreMomentumFromOverscroll, delta)) {
return true;
}
}
if (phase == Qt::NoScrollPhase) {
if (_overscroll == currentOverscrollDefault()) {
tryScrollTo(_state.visibleFrom + delta);

View file

@ -239,6 +239,7 @@ private:
crl::time _lastScroll = 0;
TouchScrollState _touchScrollState = TouchScrollState::Manual;
int _overscrollAccumulated = 0;
int _ignoreMomentumFromOverscroll = 0;
bool _touchDisabled : 1 = false;
bool _touchScroll : 1 = false;
bool _touchPress : 1 = false;
@ -249,7 +250,6 @@ private:
bool _widgetAcceptsTouch : 1 = false;
bool _disabled : 1 = false;
bool _dirtyState : 1 = false;
bool _ignoreMomentum : 1 = false;
bool _overscrollReturning : 1 = false;
Fn<bool(not_null<QWheelEvent*>)> _customWheelProcess;