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 {
}
}
/** 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); }
/**
......
......@@ -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));
......
......@@ -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();
......
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