Kaydet (Commit) 0151bf3f authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

android: move scrollBy & scaleWithFocus to PZC (Fennec Import)

Change-Id: Ie0d23b302994134f9d382e255b0408f7c9f1c1fb
üst 94e7296f
...@@ -135,18 +135,6 @@ public class LayerController implements PanZoomTarget { ...@@ -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. */ /** Sets the current page rect. You must hold the monitor while calling this. */
public void setPageRect(RectF rect, RectF cssRect) { public void setPageRect(RectF rect, RectF cssRect) {
// Since the "rect" is always just a multiple of "cssRect" we don't need to // Since the "rect" is always just a multiple of "cssRect" we don't need to
...@@ -193,21 +181,6 @@ public class LayerController implements PanZoomTarget { ...@@ -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); } public boolean post(Runnable action) { return mView.post(action); }
/** /**
......
...@@ -133,6 +133,10 @@ public class PanZoomController ...@@ -133,6 +133,10 @@ public class PanZoomController
return mTarget.getViewportMetrics(); return mTarget.getViewportMetrics();
} }
private ViewportMetrics getMutableMetrics() {
return new ViewportMetrics(getMetrics());
}
// for debugging bug 713011; it can be taken out once that is resolved. // for debugging bug 713011; it can be taken out once that is resolved.
private void checkMainThread() { private void checkMainThread() {
if (mMainThread != Thread.currentThread()) { if (mMainThread != Thread.currentThread()) {
...@@ -225,7 +229,7 @@ public class PanZoomController ...@@ -225,7 +229,7 @@ public class PanZoomController
if (mState == PanZoomState.NOTHING) { if (mState == PanZoomState.NOTHING) {
synchronized (mTarget.getLock()) { synchronized (mTarget.getLock()) {
ViewportMetrics validated = getValidViewportMetrics(); 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 // page size changed such that we are now in overscroll. snap to the
// the nearest valid viewport // the nearest valid viewport
mTarget.setViewportMetrics(validated); mTarget.setViewportMetrics(validated);
...@@ -449,6 +453,16 @@ public class PanZoomController ...@@ -449,6 +453,16 @@ public class PanZoomController
updatePosition(); 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() { private void fling() {
updatePosition(); updatePosition();
...@@ -465,7 +479,7 @@ public class PanZoomController ...@@ -465,7 +479,7 @@ public class PanZoomController
private void bounce(ViewportMetrics metrics) { private void bounce(ViewportMetrics metrics) {
stopAnimationTimer(); stopAnimationTimer();
ViewportMetrics bounceStartMetrics = new ViewportMetrics(getMetrics()); ViewportMetrics bounceStartMetrics = getMutableMetrics();
if (bounceStartMetrics.fuzzyEquals(metrics)) { if (bounceStartMetrics.fuzzyEquals(metrics)) {
setState(PanZoomState.NOTHING); setState(PanZoomState.NOTHING);
return; return;
...@@ -539,7 +553,7 @@ public class PanZoomController ...@@ -539,7 +553,7 @@ public class PanZoomController
} }
if (! mSubscroller.scrollBy(displacement)) { if (! mSubscroller.scrollBy(displacement)) {
synchronized (mTarget.getLock()) { synchronized (mTarget.getLock()) {
mTarget.scrollBy(displacement); scrollBy(displacement);
} }
} }
} }
...@@ -690,7 +704,7 @@ public class PanZoomController ...@@ -690,7 +704,7 @@ public class PanZoomController
/* Returns the nearest viewport metrics with no overscroll visible. */ /* Returns the nearest viewport metrics with no overscroll visible. */
private ViewportMetrics getValidViewportMetrics() { private ViewportMetrics getValidViewportMetrics() {
return getValidViewportMetrics(new ViewportMetrics(getMetrics())); return getValidViewportMetrics(getMutableMetrics());
} }
private ViewportMetrics getValidViewportMetrics(ViewportMetrics viewportMetrics) { private ViewportMetrics getValidViewportMetrics(ViewportMetrics viewportMetrics) {
...@@ -848,10 +862,10 @@ public class PanZoomController ...@@ -848,10 +862,10 @@ public class PanZoomController
newZoomFactor = maxZoomFactor + excessZoom; newZoomFactor = maxZoomFactor + excessZoom;
} }
mTarget.scrollBy(new PointF(mLastZoomFocus.x - detector.getFocusX(), scrollBy(new PointF(mLastZoomFocus.x - detector.getFocusX(),
mLastZoomFocus.y - detector.getFocusY())); mLastZoomFocus.y - detector.getFocusY()));
PointF focus = new PointF(detector.getFocusX(), detector.getFocusY()); PointF focus = new PointF(detector.getFocusX(), detector.getFocusY());
mTarget.scaleWithFocus(newZoomFactor, focus); scaleWithFocus(newZoomFactor, focus);
} }
mLastZoomFocus.set(detector.getFocusX(), detector.getFocusY()); mLastZoomFocus.set(detector.getFocusX(), detector.getFocusY());
...@@ -872,6 +886,17 @@ public class PanZoomController ...@@ -872,6 +886,17 @@ public class PanZoomController
mTarget.notifyLayerClientOfGeometryChange(); 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() { public boolean getRedrawHint() {
switch (mState) { switch (mState) {
case PINCHING: case PINCHING:
...@@ -944,7 +969,7 @@ public class PanZoomController ...@@ -944,7 +969,7 @@ public class PanZoomController
float finalZoom = viewport.width() / zoomToRect.width(); float finalZoom = viewport.width() / zoomToRect.width();
ViewportMetrics finalMetrics = new ViewportMetrics(getMetrics()); ViewportMetrics finalMetrics = getMutableMetrics();
finalMetrics.setOrigin(new PointF(zoomToRect.left * finalMetrics.getZoomFactor(), finalMetrics.setOrigin(new PointF(zoomToRect.left * finalMetrics.getZoomFactor(),
zoomToRect.top * finalMetrics.getZoomFactor())); zoomToRect.top * finalMetrics.getZoomFactor()));
finalMetrics.scaleTo(finalZoom, new PointF(0.0f, 0.0f)); finalMetrics.scaleTo(finalZoom, new PointF(0.0f, 0.0f));
......
...@@ -17,8 +17,6 @@ public interface PanZoomTarget { ...@@ -17,8 +17,6 @@ public interface PanZoomTarget {
public void setAnimationTarget(ViewportMetrics viewport); public void setAnimationTarget(ViewportMetrics viewport);
public void setViewportMetrics(ViewportMetrics viewport); public void setViewportMetrics(ViewportMetrics viewport);
public void scrollBy(PointF point);
public void scaleWithFocus(float zoomFactor, PointF focus);
public void notifyLayerClientOfGeometryChange(); public void notifyLayerClientOfGeometryChange();
public void setForceRedraw(); public void setForceRedraw();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment