Bug 716673 - Refactor some repeated code into a startTouch method. r=pcwalton
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 10 Jan 2012 10:05:48 -0500
changeset 85437 4f670580388f0b585d1062d6248269562c97f15c
parent 85436 9b10d778278b8e36ae1d81513d228f6bb0680e4e
child 85438 c7eb5f95bb59056a6b38e8e73bcd59b445fee970
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspcwalton
bugs716673
milestone12.0a1
Bug 716673 - Refactor some repeated code into a startTouch method. r=pcwalton
mobile/android/base/ui/PanZoomController.java
--- a/mobile/android/base/ui/PanZoomController.java
+++ b/mobile/android/base/ui/PanZoomController.java
@@ -260,22 +260,17 @@ public class PanZoomController
         stopAnimationTimer();
         mOverridePanning = false;
 
         switch (mState) {
         case ANIMATED_ZOOM:
             return false;
         case FLING:
         case NOTHING:
-            mState = PanZoomState.TOUCHING;
-            mX.velocity = mY.velocity = 0.0f;
-            mX.locked = mY.locked = false;
-            mX.lastTouchPos = mX.firstTouchPos = mX.touchPos = event.getX(0);
-            mY.lastTouchPos = mY.firstTouchPos = mY.touchPos = event.getY(0);
-            mLastEventTime = event.getEventTime();
+            startTouch(event.getX(0), event.getY(0), event.getEventTime());
             return false;
         case TOUCHING:
         case PANNING:
         case PANNING_LOCKED:
         case PANNING_HOLD:
         case PANNING_HOLD_LOCKED:
         case PINCHING:
             Log.e(LOGTAG, "Received impossible touch down while in " + mState);
@@ -360,16 +355,23 @@ public class PanZoomController
         Log.d(LOGTAG, "onTouchCancel in " + mState);
 
         mState = PanZoomState.NOTHING;
         // ensure we snap back if we're overscrolled
         bounce();
         return false;
     }
 
+    private void startTouch(float x, float y, long time) {
+        mX.startTouch(x);
+        mY.startTouch(y);
+        mState = PanZoomState.TOUCHING;
+        mLastEventTime = time;
+    }
+
     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);
     }
 
     private float clampByFactor(float oldValue, float newValue, float factor) {
         float maxChange = Math.abs(oldValue * factor);
@@ -751,16 +753,22 @@ public class PanZoomController
         public FlingStates getFlingState() { return mFlingState; }
 
         public void setFlingState(FlingStates aFlingState) {
             mFlingState = aFlingState;
         }
 
         private float getViewportEnd() { return getOrigin() + getViewportLength(); }
 
+        public void startTouch(float pos) {
+            velocity = 0.0f;
+            locked = false;
+            firstTouchPos = touchPos = lastTouchPos = pos;
+        }
+
         public Overscroll getOverscroll() {
             boolean minus = (getOrigin() < 0.0f);
             boolean plus = (getViewportEnd() > getPageLength());
             if (minus && plus)
                 return Overscroll.BOTH;
             else if (minus)
                 return Overscroll.MINUS;
             else if (plus)
@@ -979,29 +987,23 @@ public class PanZoomController
 
     @Override
     public void onScaleEnd(ScaleGestureDetector detector) {
         Log.d(LOGTAG, "onScaleEnd in " + mState);
 
         if (mState == PanZoomState.ANIMATED_ZOOM)
             return;
 
-        mState = PanZoomState.PANNING_HOLD_LOCKED;
-        mX.firstTouchPos = mX.lastTouchPos = mX.touchPos = detector.getFocusX();
-        mY.firstTouchPos = mY.lastTouchPos = mY.touchPos = detector.getFocusY();
+        // switch back to the touching state
+        startTouch(detector.getFocusX(), detector.getFocusY(), detector.getEventTime());
 
         // Force a viewport synchronisation
         mController.setForceRedraw();
         mController.notifyLayerClientOfGeometryChange();
         GeckoApp.mAppContext.showPluginViews();
-
-        mState = PanZoomState.TOUCHING;
-        mX.velocity = mY.velocity = 0.0f;
-        mX.locked = mY.locked = false;
-        mLastEventTime = detector.getEventTime();
     }
 
     public boolean getRedrawHint() {
         return (mState == PanZoomState.NOTHING || mState == PanZoomState.FLING);
     }
 
     private void sendPointToGecko(String event, MotionEvent motionEvent) {
         String json;