diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-09-27 12:47:47 +0200 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-09-28 22:32:47 +0200 |
commit | 0151bf3f28b476a2fd0993c6a60fbf9a9f555c3a (patch) | |
tree | 69141e0bb4dfc2e4d45f97a40798751e26f353c0 /android | |
parent | 94e7296fc51e1e85715bbab91cf233f3d7ce67f3 (diff) |
android: move scrollBy & scaleWithFocus to PZC (Fennec Import)
Change-Id: Ie0d23b302994134f9d382e255b0408f7c9f1c1fb
Diffstat (limited to 'android')
3 files changed, 32 insertions, 36 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 db43db2c2ce5..0898397188bb 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 @@ -135,18 +135,6 @@ public class LayerController implements PanZoomTarget { } } - /** Scrolls the viewport by the given offset. You must hold the monitor while calling this. */ - public void scrollBy(PointF point) { - ViewportMetrics viewportMetrics = new ViewportMetrics(mViewportMetrics); - PointF origin = viewportMetrics.getOrigin(); - origin.offset(point.x, point.y); - viewportMetrics.setOrigin(origin); - mViewportMetrics = new ImmutableViewportMetrics(viewportMetrics); - - notifyLayerClientOfGeometryChange(); - mView.requestRender(); - } - /** Sets the current page rect. You must hold the monitor while calling this. */ public void setPageRect(RectF rect, RectF cssRect) { // Since the "rect" is always just a multiple of "cssRect" we don't need to @@ -193,21 +181,6 @@ public class LayerController implements PanZoomTarget { } } - /** - * Scales the viewport, keeping the given focus point in the same place before and after the - * scale operation. You must hold the monitor while calling this. - */ - public void scaleWithFocus(float zoomFactor, PointF focus) { - ViewportMetrics viewportMetrics = new ViewportMetrics(mViewportMetrics); - viewportMetrics.scaleTo(zoomFactor, focus); - mViewportMetrics = new ImmutableViewportMetrics(viewportMetrics); - - // We assume the zoom level will only be modified by the - // PanZoomController, so no need to notify it of this change. - notifyLayerClientOfGeometryChange(); - mView.requestRender(); - } - public boolean post(Runnable action) { return mView.post(action); } /** 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 ef45fd3bc76f..876f62673f14 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 @@ -133,6 +133,10 @@ public class PanZoomController return mTarget.getViewportMetrics(); } + private ViewportMetrics getMutableMetrics() { + return new ViewportMetrics(getMetrics()); + } + // for debugging bug 713011; it can be taken out once that is resolved. private void checkMainThread() { if (mMainThread != Thread.currentThread()) { @@ -225,7 +229,7 @@ public class PanZoomController if (mState == PanZoomState.NOTHING) { synchronized (mTarget.getLock()) { ViewportMetrics validated = getValidViewportMetrics(); - if (! (new ViewportMetrics(getMetrics())).fuzzyEquals(validated)) { + if (! getMutableMetrics().fuzzyEquals(validated)) { // page size changed such that we are now in overscroll. snap to the // the nearest valid viewport mTarget.setViewportMetrics(validated); @@ -449,6 +453,16 @@ public class PanZoomController updatePosition(); } + private void scrollBy(PointF point) { + ViewportMetrics viewportMetrics = getMutableMetrics(); + PointF origin = viewportMetrics.getOrigin(); + origin.offset(point.x, point.y); + viewportMetrics.setOrigin(origin); + + mTarget.setViewportMetrics(viewportMetrics); + mTarget.notifyLayerClientOfGeometryChange(); + } + private void fling() { updatePosition(); @@ -465,7 +479,7 @@ public class PanZoomController private void bounce(ViewportMetrics metrics) { stopAnimationTimer(); - ViewportMetrics bounceStartMetrics = new ViewportMetrics(getMetrics()); + ViewportMetrics bounceStartMetrics = getMutableMetrics(); if (bounceStartMetrics.fuzzyEquals(metrics)) { setState(PanZoomState.NOTHING); return; @@ -539,7 +553,7 @@ public class PanZoomController } if (! mSubscroller.scrollBy(displacement)) { synchronized (mTarget.getLock()) { - mTarget.scrollBy(displacement); + scrollBy(displacement); } } } @@ -690,7 +704,7 @@ public class PanZoomController /* Returns the nearest viewport metrics with no overscroll visible. */ private ViewportMetrics getValidViewportMetrics() { - return getValidViewportMetrics(new ViewportMetrics(getMetrics())); + return getValidViewportMetrics(getMutableMetrics()); } private ViewportMetrics getValidViewportMetrics(ViewportMetrics viewportMetrics) { @@ -848,10 +862,10 @@ public class PanZoomController newZoomFactor = maxZoomFactor + excessZoom; } - mTarget.scrollBy(new PointF(mLastZoomFocus.x - detector.getFocusX(), + scrollBy(new PointF(mLastZoomFocus.x - detector.getFocusX(), mLastZoomFocus.y - detector.getFocusY())); PointF focus = new PointF(detector.getFocusX(), detector.getFocusY()); - mTarget.scaleWithFocus(newZoomFactor, focus); + scaleWithFocus(newZoomFactor, focus); } mLastZoomFocus.set(detector.getFocusX(), detector.getFocusY()); @@ -872,6 +886,17 @@ public class PanZoomController mTarget.notifyLayerClientOfGeometryChange(); } + /** + * Scales the viewport, keeping the given focus point in the same place before and after the + * scale operation. You must hold the monitor while calling this. + */ + private void scaleWithFocus(float zoomFactor, PointF focus) { + ViewportMetrics viewportMetrics = getMutableMetrics(); + viewportMetrics.scaleTo(zoomFactor, focus); + mTarget.setViewportMetrics(viewportMetrics); + mTarget.notifyLayerClientOfGeometryChange(); + } + public boolean getRedrawHint() { switch (mState) { case PINCHING: @@ -944,7 +969,7 @@ public class PanZoomController float finalZoom = viewport.width() / zoomToRect.width(); - ViewportMetrics finalMetrics = new ViewportMetrics(getMetrics()); + ViewportMetrics finalMetrics = getMutableMetrics(); finalMetrics.setOrigin(new PointF(zoomToRect.left * finalMetrics.getZoomFactor(), zoomToRect.top * finalMetrics.getZoomFactor())); finalMetrics.scaleTo(finalZoom, new PointF(0.0f, 0.0f)); 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 index 7ab1c566da66..fcbc00f10448 100644 --- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ui/PanZoomTarget.java +++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ui/PanZoomTarget.java @@ -17,8 +17,6 @@ public interface PanZoomTarget { 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(); |