summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.com>2014-09-27 12:42:39 +0200
committerTomaž Vajngerl <tomaz.vajngerl@collabora.com>2014-09-28 22:32:47 +0200
commit94e7296fc51e1e85715bbab91cf233f3d7ce67f3 (patch)
tree65874e2d11de60ad2e308bc25c9fd311f34b3804
parent3e4d5713c171f2be68276a95a7da7a5073dab25c (diff)
android: add PanZoomTarget (Fennec import)
Change-Id: Ib946b7a95cd59833a732e3da6c139e848778e1bc
-rw-r--r--android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerController.java4
-rw-r--r--android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ui/PanZoomController.java71
-rw-r--r--android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ui/PanZoomTarget.java29
3 files changed, 67 insertions, 37 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerController.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerController.java
index 303cb670be46..db43db2c2ce5 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerController.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerController.java
@@ -17,6 +17,7 @@ import android.view.GestureDetector;
import org.mozilla.gecko.ZoomConstraints;
import org.mozilla.gecko.ui.PanZoomController;
+import org.mozilla.gecko.ui.PanZoomTarget;
import org.mozilla.gecko.ui.SimpleScaleGestureDetector;
/**
@@ -26,7 +27,7 @@ import org.mozilla.gecko.ui.SimpleScaleGestureDetector;
*
* Many methods require that the monitor be held, with a synchronized (controller) { ... } block.
*/
-public class LayerController {
+public class LayerController implements PanZoomTarget {
private static final String LOGTAG = "GeckoLayerController";
private Layer mRootLayer; /* The root layer. */
@@ -92,6 +93,7 @@ public class LayerController {
public LayerView getView() { return mView; }
public Context getContext() { return mContext; }
public ImmutableViewportMetrics getViewportMetrics() { return mViewportMetrics; }
+ public Object getLock() { return this; }
public FloatSize getViewportSize() {
return mViewportMetrics.getSize();
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ui/PanZoomController.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ui/PanZoomController.java
index 1d7d52c57ef6..ef45fd3bc76f 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ui/PanZoomController.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ui/PanZoomController.java
@@ -16,7 +16,6 @@ import org.libreoffice.LOKitShell;
import org.libreoffice.LibreOfficeMainActivity;
import org.mozilla.gecko.ZoomConstraints;
import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
-import org.mozilla.gecko.gfx.LayerController;
import org.mozilla.gecko.gfx.ViewportMetrics;
import org.mozilla.gecko.util.FloatUtils;
@@ -92,7 +91,7 @@ public class PanZoomController
prevented the default actions yet. we still need to abort animations. */
}
- private final LayerController mController;
+ private final PanZoomTarget mTarget;
private final SubdocumentScrollHelper mSubscroller;
private final Axis mX;
private final Axis mY;
@@ -110,8 +109,8 @@ public class PanZoomController
/* Current state the pan/zoom UI is in. */
private PanZoomState mState;
- public PanZoomController(LayerController controller) {
- mController = controller;
+ public PanZoomController(PanZoomTarget target) {
+ mTarget = target;
mSubscroller = new SubdocumentScrollHelper();
mX = new AxisX(mSubscroller);
mY = new AxisY(mSubscroller);
@@ -131,7 +130,7 @@ public class PanZoomController
}
private ImmutableViewportMetrics getMetrics() {
- return mController.getViewportMetrics();
+ return mTarget.getViewportMetrics();
}
// for debugging bug 713011; it can be taken out once that is resolved.
@@ -190,9 +189,9 @@ public class PanZoomController
case NOTHING:
// Don't do animations here; they're distracting and can cause flashes on page
// transitions.
- synchronized (mController) {
- mController.setViewportMetrics(getValidViewportMetrics());
- mController.notifyLayerClientOfGeometryChange();
+ synchronized (mTarget.getLock()) {
+ mTarget.setViewportMetrics(getValidViewportMetrics());
+ mTarget.notifyLayerClientOfGeometryChange();
}
break;
}
@@ -224,13 +223,13 @@ public class PanZoomController
/** This must be called on the UI thread. */
public void pageRectUpdated() {
if (mState == PanZoomState.NOTHING) {
- synchronized (mController) {
+ synchronized (mTarget.getLock()) {
ViewportMetrics validated = getValidViewportMetrics();
if (! (new ViewportMetrics(getMetrics())).fuzzyEquals(validated)) {
// page size changed such that we are now in overscroll. snap to the
// the nearest valid viewport
- mController.setViewportMetrics(validated);
- mController.notifyLayerClientOfGeometryChange();
+ mTarget.setViewportMetrics(validated);
+ mTarget.notifyLayerClientOfGeometryChange();
}
}
}
@@ -250,8 +249,8 @@ public class PanZoomController
// We just interrupted a double-tap animation, so force a redraw in
// case this touchstart is just a tap that doesn't end up triggering
// a redraw
- mController.setForceRedraw();
- mController.notifyLayerClientOfGeometryChange();
+ mTarget.setForceRedraw();
+ mTarget.notifyLayerClientOfGeometryChange();
// fall through
case FLING:
case BOUNCE:
@@ -476,7 +475,7 @@ public class PanZoomController
// getRedrawHint() is returning false. This means we can safely call
// setAnimationTarget to set the new final display port and not have it get
// clobbered by display ports from intermediate animation frames.
- mController.setAnimationTarget(metrics);
+ mTarget.setAnimationTarget(metrics);
startAnimationTimer(new BounceRunnable(bounceStartMetrics, metrics));
}
@@ -497,7 +496,7 @@ public class PanZoomController
mAnimationRunnable = runnable;
mAnimationTimer.scheduleAtFixedRate(new TimerTask() {
@Override
- public void run() { mController.post(runnable); }
+ public void run() { mTarget.post(runnable); }
}, 0, 1000L/60L);
}
@@ -539,8 +538,8 @@ public class PanZoomController
return;
}
if (! mSubscroller.scrollBy(displacement)) {
- synchronized (mController) {
- mController.scrollBy(displacement);
+ synchronized (mTarget.getLock()) {
+ mTarget.scrollBy(displacement);
}
}
}
@@ -611,20 +610,20 @@ public class PanZoomController
/* Performs one frame of a bounce animation. */
private void advanceBounce() {
- synchronized (mController) {
+ synchronized (mTarget.getLock()) {
float t = ZOOM_ANIMATION_FRAMES[mBounceFrame];
ViewportMetrics newMetrics = mBounceStartMetrics.interpolate(mBounceEndMetrics, t);
- mController.setViewportMetrics(newMetrics);
- mController.notifyLayerClientOfGeometryChange();
+ mTarget.setViewportMetrics(newMetrics);
+ mTarget.notifyLayerClientOfGeometryChange();
mBounceFrame++;
}
}
/* Concludes a bounce animation and snaps the viewport into place. */
private void finishBounce() {
- synchronized (mController) {
- mController.setViewportMetrics(mBounceEndMetrics);
- mController.notifyLayerClientOfGeometryChange();
+ synchronized (mTarget.getLock()) {
+ mTarget.setViewportMetrics(mBounceEndMetrics);
+ mTarget.notifyLayerClientOfGeometryChange();
mBounceFrame = -1;
}
}
@@ -685,8 +684,8 @@ public class PanZoomController
stopAnimationTimer();
// Force a viewport synchronisation
- mController.setForceRedraw();
- mController.notifyLayerClientOfGeometryChange();
+ mTarget.setForceRedraw();
+ mTarget.notifyLayerClientOfGeometryChange();
}
/* Returns the nearest viewport metrics with no overscroll visible. */
@@ -706,7 +705,7 @@ public class PanZoomController
float minZoomFactor = 0.0f;
float maxZoomFactor = MAX_ZOOM;
- ZoomConstraints constraints = mController.getZoomConstraints();
+ ZoomConstraints constraints = mTarget.getZoomConstraints();
if (constraints.getMinZoom() > 0)
minZoomFactor = constraints.getMinZoom();
@@ -785,7 +784,7 @@ public class PanZoomController
if (mState == PanZoomState.ANIMATED_ZOOM)
return false;
- if (!mController.getZoomConstraints().getAllowZoom())
+ if (!mTarget.getZoomConstraints().getAllowZoom())
return false;
setState(PanZoomState.PINCHING);
@@ -818,12 +817,12 @@ public class PanZoomController
else
spanRatio = 1.0f - (1.0f - spanRatio) * resistance;
- synchronized (mController) {
- float newZoomFactor = mController.getViewportMetrics().zoomFactor * spanRatio;
+ synchronized (mTarget.getLock()) {
+ float newZoomFactor = getMetrics().zoomFactor * spanRatio;
float minZoomFactor = 0.0f;
float maxZoomFactor = MAX_ZOOM;
- ZoomConstraints constraints = mController.getZoomConstraints();
+ ZoomConstraints constraints = mTarget.getZoomConstraints();
if (constraints.getMinZoom() > 0)
minZoomFactor = constraints.getMinZoom();
@@ -849,10 +848,10 @@ public class PanZoomController
newZoomFactor = maxZoomFactor + excessZoom;
}
- mController.scrollBy(new PointF(mLastZoomFocus.x - detector.getFocusX(),
- mLastZoomFocus.y - detector.getFocusY()));
+ mTarget.scrollBy(new PointF(mLastZoomFocus.x - detector.getFocusX(),
+ mLastZoomFocus.y - detector.getFocusY()));
PointF focus = new PointF(detector.getFocusX(), detector.getFocusY());
- mController.scaleWithFocus(newZoomFactor, focus);
+ mTarget.scaleWithFocus(newZoomFactor, focus);
}
mLastZoomFocus.set(detector.getFocusX(), detector.getFocusY());
@@ -869,8 +868,8 @@ public class PanZoomController
startTouch(detector.getFocusX(), detector.getFocusY(), detector.getEventTime());
// Force a viewport synchronisation
- mController.setForceRedraw();
- mController.notifyLayerClientOfGeometryChange();
+ mTarget.setForceRedraw();
+ mTarget.notifyLayerClientOfGeometryChange();
}
public boolean getRedrawHint() {
@@ -920,7 +919,7 @@ public class PanZoomController
*/
private boolean animatedZoomTo(RectF zoomToRect) {
setState(PanZoomState.ANIMATED_ZOOM);
- final float startZoom = mController.getViewportMetrics().zoomFactor;
+ final float startZoom = getMetrics().zoomFactor;
RectF viewport = getMetrics().getViewport();
// 1. adjust the aspect ratio of zoomToRect to match that of the current viewport,
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ui/PanZoomTarget.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ui/PanZoomTarget.java
new file mode 100644
index 000000000000..7ab1c566da66
--- /dev/null
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ui/PanZoomTarget.java
@@ -0,0 +1,29 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko.ui;
+
+import android.graphics.PointF;
+
+import org.mozilla.gecko.ZoomConstraints;
+import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
+import org.mozilla.gecko.gfx.ViewportMetrics;
+
+public interface PanZoomTarget {
+ public ImmutableViewportMetrics getViewportMetrics();
+ public ZoomConstraints getZoomConstraints();
+
+ public void setAnimationTarget(ViewportMetrics viewport);
+ public void setViewportMetrics(ViewportMetrics viewport);
+ public void scrollBy(PointF point);
+ public void scaleWithFocus(float zoomFactor, PointF focus);
+
+ public void notifyLayerClientOfGeometryChange();
+ public void setForceRedraw();
+
+ public boolean post(Runnable action);
+ public Object getLock();
+ public PointF convertViewPointToLayerPoint(PointF viewPoint);
+}