Bug 809199 - Modify methods in PanZoomTarget to take ImmutableViewportMetrics instead of ViewportMetrics. r=Cwiiis

This commit is contained in:
Kartikaya Gupta 2012-11-07 11:47:07 -05:00
parent a3140f12d3
commit d1bf65d2b9
5 changed files with 41 additions and 34 deletions

View File

@ -336,7 +336,7 @@ public class GeckoLayerClient
mGeckoViewport = newMetrics; mGeckoViewport = newMetrics;
} }
}); });
setViewportMetrics(newMetrics, type == ViewportMessageType.UPDATE); setViewportMetrics(new ImmutableViewportMetrics(newMetrics), type == ViewportMessageType.UPDATE);
mDisplayPort = DisplayPortCalculator.calculate(getViewportMetrics(), null); mDisplayPort = DisplayPortCalculator.calculate(getViewportMetrics(), null);
} }
return mDisplayPort; return mDisplayPort;
@ -483,7 +483,7 @@ public class GeckoLayerClient
mGeckoViewport = currentMetrics; mGeckoViewport = currentMetrics;
} }
}); });
setViewportMetrics(currentMetrics); setViewportMetrics(new ImmutableViewportMetrics(currentMetrics));
Tab tab = Tabs.getInstance().getSelectedTab(); Tab tab = Tabs.getInstance().getSelectedTab();
mView.setCheckerboardColor(tab.getCheckerboardColor()); mView.setCheckerboardColor(tab.getCheckerboardColor());
@ -662,13 +662,12 @@ public class GeckoLayerClient
} }
/** Implementation of PanZoomTarget */ /** Implementation of PanZoomTarget */
public void setAnimationTarget(ViewportMetrics viewport) { public void setAnimationTarget(ImmutableViewportMetrics metrics) {
if (mGeckoIsReady) { if (mGeckoIsReady) {
// We know what the final viewport of the animation is going to be, so // We know what the final viewport of the animation is going to be, so
// immediately request a draw of that area by setting the display port // immediately request a draw of that area by setting the display port
// accordingly. This way we should have the content pre-rendered by the // accordingly. This way we should have the content pre-rendered by the
// time the animation is done. // time the animation is done.
ImmutableViewportMetrics metrics = new ImmutableViewportMetrics(viewport);
DisplayPortMetrics displayPort = DisplayPortCalculator.calculate(metrics, null); DisplayPortMetrics displayPort = DisplayPortCalculator.calculate(metrics, null);
adjustViewport(displayPort); adjustViewport(displayPort);
} }
@ -677,12 +676,12 @@ public class GeckoLayerClient
/** Implementation of PanZoomTarget /** Implementation of PanZoomTarget
* You must hold the monitor while calling this. * You must hold the monitor while calling this.
*/ */
public void setViewportMetrics(ViewportMetrics viewport) { public void setViewportMetrics(ImmutableViewportMetrics metrics) {
setViewportMetrics(viewport, true); setViewportMetrics(metrics, true);
} }
private void setViewportMetrics(ViewportMetrics viewport, boolean notifyGecko) { private void setViewportMetrics(ImmutableViewportMetrics metrics, boolean notifyGecko) {
mViewportMetrics = new ImmutableViewportMetrics(viewport); mViewportMetrics = metrics;
mView.requestRender(); mView.requestRender();
if (notifyGecko && mGeckoIsReady) { if (notifyGecko && mGeckoIsReady) {
geometryChanged(); geometryChanged();

View File

@ -143,6 +143,22 @@ public class ImmutableViewportMetrics {
FloatUtils.interpolate(zoomFactor, to.zoomFactor, t)); FloatUtils.interpolate(zoomFactor, to.zoomFactor, t));
} }
public boolean fuzzyEquals(ImmutableViewportMetrics other) {
return FloatUtils.fuzzyEquals(pageRectLeft, other.pageRectLeft)
&& FloatUtils.fuzzyEquals(pageRectTop, other.pageRectTop)
&& FloatUtils.fuzzyEquals(pageRectRight, other.pageRectRight)
&& FloatUtils.fuzzyEquals(pageRectBottom, other.pageRectBottom)
&& FloatUtils.fuzzyEquals(cssPageRectLeft, other.cssPageRectLeft)
&& FloatUtils.fuzzyEquals(cssPageRectTop, other.cssPageRectTop)
&& FloatUtils.fuzzyEquals(cssPageRectRight, other.cssPageRectRight)
&& FloatUtils.fuzzyEquals(cssPageRectBottom, other.cssPageRectBottom)
&& FloatUtils.fuzzyEquals(viewportRectLeft, other.viewportRectLeft)
&& FloatUtils.fuzzyEquals(viewportRectTop, other.viewportRectTop)
&& FloatUtils.fuzzyEquals(viewportRectRight, other.viewportRectRight)
&& FloatUtils.fuzzyEquals(viewportRectBottom, other.viewportRectBottom)
&& FloatUtils.fuzzyEquals(zoomFactor, other.zoomFactor);
}
@Override @Override
public String toString() { public String toString() {
return "ImmutableViewportMetrics v=(" + viewportRectLeft + "," + viewportRectTop + "," return "ImmutableViewportMetrics v=(" + viewportRectLeft + "," + viewportRectTop + ","

View File

@ -178,13 +178,6 @@ public class ViewportMetrics {
mZoomFactor = newZoomFactor; mZoomFactor = newZoomFactor;
} }
public boolean fuzzyEquals(ViewportMetrics other) {
return RectUtils.fuzzyEquals(mPageRect, other.mPageRect)
&& RectUtils.fuzzyEquals(mCssPageRect, other.mCssPageRect)
&& RectUtils.fuzzyEquals(mViewportRect, other.mViewportRect)
&& FloatUtils.fuzzyEquals(mZoomFactor, other.mZoomFactor);
}
public String toJSON() { public String toJSON() {
// Round off height and width. Since the height and width are the size of the screen, it // Round off height and width. Since the height and width are the size of the screen, it
// makes no sense to send non-integer coordinates to Gecko. // makes no sense to send non-integer coordinates to Gecko.

View File

@ -259,8 +259,8 @@ public class PanZoomController
public void pageRectUpdated() { public void pageRectUpdated() {
if (mState == PanZoomState.NOTHING) { if (mState == PanZoomState.NOTHING) {
synchronized (mTarget.getLock()) { synchronized (mTarget.getLock()) {
ViewportMetrics validated = getValidViewportMetrics(); ImmutableViewportMetrics validated = getValidViewportMetrics();
if (! getMutableMetrics().fuzzyEquals(validated)) { if (!getMetrics().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);
@ -491,7 +491,7 @@ public class PanZoomController
origin.offset(point.x, point.y); origin.offset(point.x, point.y);
viewportMetrics.setOrigin(origin); viewportMetrics.setOrigin(origin);
mTarget.setViewportMetrics(viewportMetrics); mTarget.setViewportMetrics(new ImmutableViewportMetrics(viewportMetrics));
} }
private void fling() { private void fling() {
@ -507,10 +507,10 @@ public class PanZoomController
} }
/* Performs a bounce-back animation to the given viewport metrics. */ /* Performs a bounce-back animation to the given viewport metrics. */
private void bounce(ViewportMetrics metrics) { private void bounce(ImmutableViewportMetrics metrics) {
stopAnimationTimer(); stopAnimationTimer();
ViewportMetrics bounceStartMetrics = getMutableMetrics(); ImmutableViewportMetrics bounceStartMetrics = getMetrics();
if (bounceStartMetrics.fuzzyEquals(metrics)) { if (bounceStartMetrics.fuzzyEquals(metrics)) {
setState(PanZoomState.NOTHING); setState(PanZoomState.NOTHING);
return; return;
@ -625,9 +625,9 @@ public class PanZoomController
private ImmutableViewportMetrics mBounceStartMetrics; private ImmutableViewportMetrics mBounceStartMetrics;
private ImmutableViewportMetrics mBounceEndMetrics; private ImmutableViewportMetrics mBounceEndMetrics;
BounceRunnable(ViewportMetrics startMetrics, ViewportMetrics endMetrics) { BounceRunnable(ImmutableViewportMetrics startMetrics, ImmutableViewportMetrics endMetrics) {
mBounceStartMetrics = new ImmutableViewportMetrics(startMetrics); mBounceStartMetrics = startMetrics;
mBounceEndMetrics = new ImmutableViewportMetrics(endMetrics); mBounceEndMetrics = endMetrics;
} }
protected void animateFrame() { protected void animateFrame() {
@ -658,7 +658,7 @@ public class PanZoomController
synchronized (mTarget.getLock()) { synchronized (mTarget.getLock()) {
float t = easeOut(mBounceFrame * Axis.MS_PER_FRAME / 256f); float t = easeOut(mBounceFrame * Axis.MS_PER_FRAME / 256f);
ImmutableViewportMetrics newMetrics = mBounceStartMetrics.interpolate(mBounceEndMetrics, t); ImmutableViewportMetrics newMetrics = mBounceStartMetrics.interpolate(mBounceEndMetrics, t);
mTarget.setViewportMetrics(new ViewportMetrics(newMetrics)); mTarget.setViewportMetrics(newMetrics);
mBounceFrame++; mBounceFrame++;
} }
} }
@ -666,7 +666,7 @@ public class PanZoomController
/* Concludes a bounce animation and snaps the viewport into place. */ /* Concludes a bounce animation and snaps the viewport into place. */
private void finishBounce() { private void finishBounce() {
synchronized (mTarget.getLock()) { synchronized (mTarget.getLock()) {
mTarget.setViewportMetrics(new ViewportMetrics(mBounceEndMetrics)); mTarget.setViewportMetrics(mBounceEndMetrics);
mBounceFrame = -1; mBounceFrame = -1;
} }
} }
@ -731,11 +731,11 @@ 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 ImmutableViewportMetrics getValidViewportMetrics() {
return getValidViewportMetrics(getMutableMetrics()); return getValidViewportMetrics(getMutableMetrics());
} }
private ViewportMetrics getValidViewportMetrics(ViewportMetrics viewportMetrics) { private ImmutableViewportMetrics getValidViewportMetrics(ViewportMetrics viewportMetrics) {
/* First, we adjust the zoom factor so that we can make no overscrolled area visible. */ /* First, we adjust the zoom factor so that we can make no overscrolled area visible. */
float zoomFactor = viewportMetrics.getZoomFactor(); float zoomFactor = viewportMetrics.getZoomFactor();
RectF pageRect = viewportMetrics.getPageRect(); RectF pageRect = viewportMetrics.getPageRect();
@ -791,7 +791,7 @@ public class PanZoomController
/* Now we pan to the right origin. */ /* Now we pan to the right origin. */
viewportMetrics.setViewport(viewportMetrics.getClampedViewport()); viewportMetrics.setViewport(viewportMetrics.getClampedViewport());
return viewportMetrics; return new ImmutableViewportMetrics(viewportMetrics);
} }
private class AxisX extends Axis { private class AxisX extends Axis {
@ -937,7 +937,7 @@ public class PanZoomController
private void scaleWithFocus(float zoomFactor, PointF focus) { private void scaleWithFocus(float zoomFactor, PointF focus) {
ViewportMetrics viewportMetrics = getMutableMetrics(); ViewportMetrics viewportMetrics = getMutableMetrics();
viewportMetrics.scaleTo(zoomFactor, focus); viewportMetrics.scaleTo(zoomFactor, focus);
mTarget.setViewportMetrics(viewportMetrics); mTarget.setViewportMetrics(new ImmutableViewportMetrics(viewportMetrics));
} }
public boolean getRedrawHint() { public boolean getRedrawHint() {
@ -1049,9 +1049,9 @@ public class PanZoomController
// 2. now run getValidViewportMetrics on it, so that the target viewport is // 2. now run getValidViewportMetrics on it, so that the target viewport is
// clamped down to prevent overscroll, over-zoom, and other bad conditions. // clamped down to prevent overscroll, over-zoom, and other bad conditions.
finalMetrics = getValidViewportMetrics(finalMetrics); ImmutableViewportMetrics finalValidMetrics = getValidViewportMetrics(finalMetrics);
bounce(finalMetrics); bounce(finalValidMetrics);
return true; return true;
} }

View File

@ -7,7 +7,6 @@ package org.mozilla.gecko.ui;
import org.mozilla.gecko.ZoomConstraints; import org.mozilla.gecko.ZoomConstraints;
import org.mozilla.gecko.gfx.ImmutableViewportMetrics; import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
import org.mozilla.gecko.gfx.ViewportMetrics;
import android.graphics.PointF; import android.graphics.PointF;
@ -15,8 +14,8 @@ public interface PanZoomTarget {
public ImmutableViewportMetrics getViewportMetrics(); public ImmutableViewportMetrics getViewportMetrics();
public ZoomConstraints getZoomConstraints(); public ZoomConstraints getZoomConstraints();
public void setAnimationTarget(ViewportMetrics viewport); public void setAnimationTarget(ImmutableViewportMetrics viewport);
public void setViewportMetrics(ViewportMetrics viewport); public void setViewportMetrics(ImmutableViewportMetrics viewport);
public void setForceRedraw(); public void setForceRedraw();
public boolean post(Runnable action); public boolean post(Runnable action);