зеркало из https://github.com/mozilla/pjs.git
Bug 716673 - Misc cleanups in PanZoomController. r=pcwalton
- Remove unused imports. - Move all class variables together, and make some final. - Fix up some comments. - Remove unused methods. - Remove some dead code - Move some functions around so they are grouped based on behaviour.
This commit is contained in:
Родитель
55a1baeb49
Коммит
dc546a9b9f
|
@ -54,8 +54,6 @@ import android.util.Log;
|
|||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ScaleGestureDetector;
|
||||
import java.lang.Math;
|
||||
import java.util.Date;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
|
@ -71,8 +69,6 @@ public class PanZoomController
|
|||
{
|
||||
private static final String LOGTAG = "GeckoPanZoomController";
|
||||
|
||||
private LayerController mController;
|
||||
|
||||
// This fraction of velocity remains after every animation frame when the velocity is low.
|
||||
private static final float FRICTION_SLOW = 0.85f;
|
||||
// This fraction of velocity remains after every animation frame when the velocity is high.
|
||||
|
@ -122,19 +118,6 @@ public class PanZoomController
|
|||
0.99309f, /* 15 */
|
||||
};
|
||||
|
||||
/* The timer that handles flings or bounces. */
|
||||
private Timer mAnimationTimer;
|
||||
/* The runnable being scheduled by the animation timer. */
|
||||
private AnimationRunnable mAnimationRunnable;
|
||||
/* Information about the X axis. */
|
||||
private AxisX mX;
|
||||
/* Information about the Y axis. */
|
||||
private AxisY mY;
|
||||
/* The zoom focus at the first zoom event (in page coordinates). */
|
||||
private PointF mLastZoomFocus;
|
||||
/* The time the last motion event took place. */
|
||||
private long mLastEventTime;
|
||||
|
||||
private enum PanZoomState {
|
||||
NOTHING, /* no touch-start events received */
|
||||
FLING, /* all touches removed, but we're still scrolling page */
|
||||
|
@ -148,6 +131,19 @@ public class PanZoomController
|
|||
ANIMATED_ZOOM /* animated zoom to a new rect */
|
||||
}
|
||||
|
||||
private final LayerController mController;
|
||||
private final Axis mX;
|
||||
private final Axis mY;
|
||||
|
||||
/* The timer that handles flings or bounces. */
|
||||
private Timer mAnimationTimer;
|
||||
/* The runnable being scheduled by the animation timer. */
|
||||
private AnimationRunnable mAnimationRunnable;
|
||||
/* The zoom focus at the first zoom event (in page coordinates). */
|
||||
private PointF mLastZoomFocus;
|
||||
/* The time the last motion event took place. */
|
||||
private long mLastEventTime;
|
||||
/* Current state the pan/zoom UI is in. */
|
||||
private PanZoomState mState;
|
||||
|
||||
private boolean mOverridePanning;
|
||||
|
@ -156,7 +152,8 @@ public class PanZoomController
|
|||
|
||||
public PanZoomController(LayerController controller) {
|
||||
mController = controller;
|
||||
mX = new AxisX(); mY = new AxisY();
|
||||
mX = new AxisX();
|
||||
mY = new AxisY();
|
||||
mState = PanZoomState.NOTHING;
|
||||
|
||||
GeckoAppShell.registerGeckoEventListener("Browser:ZoomToRect", this);
|
||||
|
@ -183,38 +180,34 @@ public class PanZoomController
|
|||
}
|
||||
});
|
||||
} else if (event.equals("Browser:ZoomToRect")) {
|
||||
if (mController != null) {
|
||||
float scale = mController.getZoomFactor();
|
||||
float x = (float)message.getDouble("x");
|
||||
float y = (float)message.getDouble("y");
|
||||
final RectF zoomRect = new RectF(x, y,
|
||||
x + (float)message.getDouble("w"),
|
||||
y + (float)message.getDouble("h"));
|
||||
mController.post(new Runnable() {
|
||||
public void run() {
|
||||
animatedZoomTo(zoomRect);
|
||||
}
|
||||
});
|
||||
}
|
||||
float scale = mController.getZoomFactor();
|
||||
float x = (float)message.getDouble("x");
|
||||
float y = (float)message.getDouble("y");
|
||||
final RectF zoomRect = new RectF(x, y,
|
||||
x + (float)message.getDouble("w"),
|
||||
y + (float)message.getDouble("h"));
|
||||
mController.post(new Runnable() {
|
||||
public void run() {
|
||||
animatedZoomTo(zoomRect);
|
||||
}
|
||||
});
|
||||
} else if (event.equals("Browser:ZoomToPageWidth")) {
|
||||
if (mController != null) {
|
||||
float scale = mController.getZoomFactor();
|
||||
FloatSize pageSize = mController.getPageSize();
|
||||
float scale = mController.getZoomFactor();
|
||||
FloatSize pageSize = mController.getPageSize();
|
||||
|
||||
RectF viewableRect = mController.getViewport();
|
||||
float y = viewableRect.top;
|
||||
// attempt to keep zoom keep focused on the center of the viewport
|
||||
float dh = viewableRect.height()*(1 - pageSize.width/viewableRect.width()); // increase in the height
|
||||
final RectF r = new RectF(0.0f,
|
||||
y + dh/2,
|
||||
pageSize.width,
|
||||
(y + pageSize.width * viewableRect.height()/viewableRect.width()));
|
||||
mController.post(new Runnable() {
|
||||
public void run() {
|
||||
animatedZoomTo(r);
|
||||
}
|
||||
});
|
||||
}
|
||||
RectF viewableRect = mController.getViewport();
|
||||
float y = viewableRect.top;
|
||||
// attempt to keep zoom keep focused on the center of the viewport
|
||||
float dh = viewableRect.height()*(1 - pageSize.width/viewableRect.width()); // increase in the height
|
||||
final RectF r = new RectF(0.0f,
|
||||
y + dh/2,
|
||||
pageSize.width,
|
||||
(y + pageSize.width * viewableRect.height()/viewableRect.width()));
|
||||
mController.post(new Runnable() {
|
||||
public void run() {
|
||||
animatedZoomTo(r);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
|
||||
|
@ -245,8 +238,8 @@ public class PanZoomController
|
|||
// fall through
|
||||
case ANIMATED_ZOOM:
|
||||
// the zoom that's in progress likely makes no sense any more (such as if
|
||||
// the screen orientation changed) so abort it and start a new one to
|
||||
// ensure the viewport doesn't contain out-of-bounds areas
|
||||
// the screen orientation changed) so abort it
|
||||
// fall through
|
||||
case NOTHING:
|
||||
// Don't do animations here; they're distracting and can cause flashes on page
|
||||
// transitions.
|
||||
|
@ -474,9 +467,6 @@ public class PanZoomController
|
|||
}
|
||||
|
||||
private void fling() {
|
||||
if (mState != PanZoomState.FLING)
|
||||
mX.velocity = mY.velocity = 0.0f;
|
||||
|
||||
mX.disableSnap = mY.disableSnap = mOverridePanning;
|
||||
|
||||
mX.displace(mOverridePanning); mY.displace(mOverridePanning);
|
||||
|
@ -721,10 +711,6 @@ public class PanZoomController
|
|||
mController.notifyLayerClientOfGeometryChange();
|
||||
}
|
||||
|
||||
private float computeElasticity(float excess, float viewportLength) {
|
||||
return 1.0f - excess / (viewportLength * SNAP_LIMIT);
|
||||
}
|
||||
|
||||
// Physics information for one axis (X or Y).
|
||||
private abstract static class Axis {
|
||||
public enum FlingStates {
|
||||
|
@ -928,6 +914,22 @@ public class PanZoomController
|
|||
/*
|
||||
* Zooming
|
||||
*/
|
||||
@Override
|
||||
public boolean onScaleBegin(ScaleGestureDetector detector) {
|
||||
Log.d(LOGTAG, "onScaleBegin in " + mState);
|
||||
|
||||
if (mState == PanZoomState.ANIMATED_ZOOM)
|
||||
return false;
|
||||
|
||||
mState = PanZoomState.PINCHING;
|
||||
mLastZoomFocus = new PointF(detector.getFocusX(), detector.getFocusY());
|
||||
GeckoApp.mAppContext.hidePluginViews();
|
||||
GeckoApp.mAppContext.mAutoCompletePopup.hide();
|
||||
cancelTouch();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onScale(ScaleGestureDetector detector) {
|
||||
Log.d(LOGTAG, "onScale in state " + mState);
|
||||
|
@ -975,22 +977,6 @@ public class PanZoomController
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onScaleBegin(ScaleGestureDetector detector) {
|
||||
Log.d(LOGTAG, "onScaleBegin in " + mState);
|
||||
|
||||
if (mState == PanZoomState.ANIMATED_ZOOM)
|
||||
return false;
|
||||
|
||||
mState = PanZoomState.PINCHING;
|
||||
mLastZoomFocus = new PointF(detector.getFocusX(), detector.getFocusY());
|
||||
GeckoApp.mAppContext.hidePluginViews();
|
||||
GeckoApp.mAppContext.mAutoCompletePopup.hide();
|
||||
cancelTouch();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScaleEnd(ScaleGestureDetector detector) {
|
||||
Log.d(LOGTAG, "onScaleEnd in " + mState);
|
||||
|
@ -1013,6 +999,10 @@ public class PanZoomController
|
|||
mLastEventTime = detector.getEventTime();
|
||||
}
|
||||
|
||||
public boolean getRedrawHint() {
|
||||
return (mState == PanZoomState.NOTHING || mState == PanZoomState.FLING);
|
||||
}
|
||||
|
||||
private void sendPointToGecko(String event, MotionEvent motionEvent) {
|
||||
String json;
|
||||
try {
|
||||
|
@ -1035,10 +1025,6 @@ public class PanZoomController
|
|||
sendPointToGecko("Gesture:LongPress", motionEvent);
|
||||
}
|
||||
|
||||
public boolean getRedrawHint() {
|
||||
return (mState == PanZoomState.NOTHING || mState == PanZoomState.FLING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDown(MotionEvent motionEvent) {
|
||||
sendPointToGecko("Gesture:ShowPress", motionEvent);
|
||||
|
@ -1052,17 +1038,17 @@ public class PanZoomController
|
|||
return true;
|
||||
}
|
||||
|
||||
private void cancelTouch() {
|
||||
GeckoEvent e = new GeckoEvent("Gesture:CancelTouch", "");
|
||||
GeckoAppShell.sendEventToGecko(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDoubleTap(MotionEvent motionEvent) {
|
||||
sendPointToGecko("Gesture:DoubleTap", motionEvent);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void cancelTouch() {
|
||||
GeckoEvent e = new GeckoEvent("Gesture:CancelTouch", "");
|
||||
GeckoAppShell.sendEventToGecko(e);
|
||||
}
|
||||
|
||||
private boolean animatedZoomTo(RectF zoomToRect) {
|
||||
GeckoApp.mAppContext.hidePluginViews();
|
||||
GeckoApp.mAppContext.mAutoCompletePopup.hide();
|
||||
|
|
Загрузка…
Ссылка в новой задаче