Bug 716673 - Completely encapsulate Axis variable firstTouchPos. r=pcwalton

This commit is contained in:
Kartikaya Gupta 2012-01-10 10:05:51 -05:00
parent cbc7a48aaa
commit 37b010df8a

View File

@ -50,6 +50,7 @@ import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.GeckoEventListener;
import android.graphics.PointF;
import android.graphics.RectF;
import android.util.FloatMath;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
@ -293,8 +294,9 @@ public class PanZoomController
Log.e(LOGTAG, "Received impossible touch move while in " + mState);
return false;
case TOUCHING:
if (panDistance(event) < PAN_THRESHOLD * GeckoAppShell.getDpi())
if (panDistance(event) < PAN_THRESHOLD * GeckoAppShell.getDpi()) {
return false;
}
cancelTouch();
// fall through
case PANNING_HOLD_LOCKED:
@ -370,9 +372,9 @@ public class PanZoomController
}
private float panDistance(MotionEvent move) {
float dx = mX.firstTouchPos - move.getX(0);
float dy = mY.firstTouchPos - move.getY(0);
return (float)Math.sqrt(dx * dx + dy * dy);
float dx = mX.panDistance(move.getX(0));
float dy = mY.panDistance(move.getY(0));
return FloatMath.sqrt(dx * dx + dy * dy);
}
private void track(float x, float y, long time) {
@ -386,7 +388,7 @@ public class PanZoomController
if (mState == PanZoomState.PANNING_LOCKED) {
// check to see if we should break the axis lock
double angle = Math.atan2(y - mY.firstTouchPos, x - mX.firstTouchPos); // range [-pi, pi]
double angle = Math.atan2(mY.panDistance(y), mX.panDistance(x)); // range [-pi, pi]
angle = Math.abs(angle); // range [0, pi]
if (angle < AXIS_LOCK_ANGLE || angle > (Math.PI - AXIS_LOCK_ANGLE)) {
// lock to x-axis
@ -699,7 +701,7 @@ public class PanZoomController
BOTH, // Overscrolled in both directions (page is zoomed to smaller than screen)
}
public float firstTouchPos; /* Position of the first touch event on the current drag. */
private float firstTouchPos; /* Position of the first touch event on the current drag. */
public float touchPos; /* Position of the most recent touch event on the current drag. */
public float lastTouchPos; /* Position of the touch event before touchPos. */
public float velocity; /* Velocity in this direction. */
@ -733,6 +735,10 @@ public class PanZoomController
firstTouchPos = touchPos = lastTouchPos = pos;
}
float panDistance(float currentPos) {
return currentPos - firstTouchPos;
}
void updateWithTouchAt(float pos, float timeDelta) {
float newVelocity = (touchPos - pos) / timeDelta * MS_PER_FRAME;