Skip to content

Commit

Permalink
Bug 708921 - Bounce back during overscroll when the magnitude of the …
Browse files Browse the repository at this point in the history
…velocity vector exceeds the stopped threshold. r=kats
  • Loading branch information
Patrick Walton committed Dec 9, 2011
1 parent 1d51cb7 commit 0ae8295
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions mobile/android/base/gfx/PointUtils.java
Expand Up @@ -67,5 +67,10 @@ public static PointF interpolate(PointF startPoint, PointF endPoint, float weigh
float y = FloatUtils.interpolate(startPoint.y, endPoint.y, weight);
return new PointF(x, y);
}

/* Computes the magnitude of the given vector. */
public static float distance(PointF point) {
return (float)Math.sqrt(point.x * point.x + point.y * point.y);
}
}

13 changes: 11 additions & 2 deletions mobile/android/base/ui/PanZoomController.java
Expand Up @@ -631,13 +631,17 @@ public void run() {
if (flingingY)
mY.advanceFling();

/* If we're still flinging in any direction, update the origin and finish here. */
/* If we're still flinging in any direction, update the origin. */
if (flingingX || flingingY) {
mX.displace(); mY.displace();
updatePosition();
return;
}

/* If we're still flinging with an appreciable velocity, stop here. */
PointF velocityVector = new PointF(mX.getRealVelocity(), mY.getRealVelocity());
if (PointUtils.distance(velocityVector) >= STOPPED_THRESHOLD)
return;

/*
* Perform a bounce-back animation if overscrolled, unless panning is being overridden
* (which happens e.g. when the user is panning an iframe).
Expand Down Expand Up @@ -747,6 +751,11 @@ public void applyEdgeResistance() {
velocity *= SNAP_LIMIT - excess / getViewportLength();
}

/* Returns the velocity. If the axis is locked, returns 0. */
public float getRealVelocity() {
return locked ? 0.0f : velocity;
}

public void startFling(boolean stopped) {
if (!stopped) {
setFlingState(FlingStates.FLINGING);
Expand Down

0 comments on commit 0ae8295

Please sign in to comment.