зеркало из https://github.com/mozilla/gecko-dev.git
Bug 804320 - Provide more inertia when the user does little gestures. r=schien, a=lsblakk
This commit is contained in:
Родитель
1bed39a8fc
Коммит
14e49bd10f
|
@ -560,7 +560,7 @@ const ContentPanning = {
|
|||
ContentPanning.init();
|
||||
|
||||
// Min/max velocity of kinetic panning. This is in pixels/millisecond.
|
||||
const kMinVelocity = 0.4;
|
||||
const kMinVelocity = 0.2;
|
||||
const kMaxVelocity = 6;
|
||||
|
||||
// Constants that affect the "friction" of the scroll pane.
|
||||
|
@ -590,27 +590,39 @@ const KineticPanning = {
|
|||
this.target = target;
|
||||
|
||||
// Calculate the initial velocity of the movement based on user input
|
||||
let momentums = this.momentums.slice(-kSamples);
|
||||
let momentums = this.momentums;
|
||||
let flick = momentums[momentums.length - 1].time - momentums[0].time < 300;
|
||||
|
||||
// Calculate the panning based on the last moves.
|
||||
momentums = momentums.slice(-kSamples);
|
||||
|
||||
let distance = new Point(0, 0);
|
||||
momentums.forEach(function(momentum) {
|
||||
distance.add(momentum.dx, momentum.dy);
|
||||
});
|
||||
|
||||
let elapsed = momentums[momentums.length - 1].time - momentums[0].time;
|
||||
|
||||
function clampFromZero(x, min, max) {
|
||||
if (x >= 0)
|
||||
return Math.max(min, Math.min(max, x));
|
||||
return Math.min(-min, Math.max(-max, x));
|
||||
}
|
||||
|
||||
let elapsed = momentums[momentums.length - 1].time - momentums[0].time;
|
||||
let velocityX = clampFromZero(distance.x / elapsed, 0, kMaxVelocity);
|
||||
let velocityY = clampFromZero(distance.y / elapsed, 0, kMaxVelocity);
|
||||
|
||||
let velocity = this._velocity;
|
||||
velocity.set(Math.abs(velocityX) < kMinVelocity ? 0 : velocityX,
|
||||
Math.abs(velocityY) < kMinVelocity ? 0 : velocityY);
|
||||
if (flick) {
|
||||
// Very fast pan action that does not generate a click are very often pan
|
||||
// action. If this is a small gesture then it will not move the view a lot
|
||||
// and so it will be above the minimun threshold and not generate any
|
||||
// kinetic panning. This does not look on a device since this is often
|
||||
// a real gesture, so let's lower the velocity threshold for such moves.
|
||||
velocity.set(velocityX, velocityY);
|
||||
} else {
|
||||
velocity.set(Math.abs(velocityX) < kMinVelocity ? 0 : velocityX,
|
||||
Math.abs(velocityY) < kMinVelocity ? 0 : velocityY);
|
||||
}
|
||||
this.momentums = [];
|
||||
|
||||
// Set acceleration vector to opposite signs of velocity
|
||||
|
|
Загрузка…
Ссылка в новой задаче