From d1bf65d2b9a1c32909c99f9b4fc369c826dc4e4b Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Wed, 7 Nov 2012 11:47:07 -0500 Subject: [PATCH] Bug 809199 - Modify methods in PanZoomTarget to take ImmutableViewportMetrics instead of ViewportMetrics. r=Cwiiis --- mobile/android/base/gfx/GeckoLayerClient.java | 15 ++++----- .../base/gfx/ImmutableViewportMetrics.java | 16 ++++++++++ mobile/android/base/gfx/ViewportMetrics.java | 7 ---- mobile/android/base/ui/PanZoomController.java | 32 +++++++++---------- mobile/android/base/ui/PanZoomTarget.java | 5 ++- 5 files changed, 41 insertions(+), 34 deletions(-) diff --git a/mobile/android/base/gfx/GeckoLayerClient.java b/mobile/android/base/gfx/GeckoLayerClient.java index 141b1795aa7..751c6b40b31 100644 --- a/mobile/android/base/gfx/GeckoLayerClient.java +++ b/mobile/android/base/gfx/GeckoLayerClient.java @@ -336,7 +336,7 @@ public class GeckoLayerClient mGeckoViewport = newMetrics; } }); - setViewportMetrics(newMetrics, type == ViewportMessageType.UPDATE); + setViewportMetrics(new ImmutableViewportMetrics(newMetrics), type == ViewportMessageType.UPDATE); mDisplayPort = DisplayPortCalculator.calculate(getViewportMetrics(), null); } return mDisplayPort; @@ -483,7 +483,7 @@ public class GeckoLayerClient mGeckoViewport = currentMetrics; } }); - setViewportMetrics(currentMetrics); + setViewportMetrics(new ImmutableViewportMetrics(currentMetrics)); Tab tab = Tabs.getInstance().getSelectedTab(); mView.setCheckerboardColor(tab.getCheckerboardColor()); @@ -662,13 +662,12 @@ public class GeckoLayerClient } /** Implementation of PanZoomTarget */ - public void setAnimationTarget(ViewportMetrics viewport) { + public void setAnimationTarget(ImmutableViewportMetrics metrics) { if (mGeckoIsReady) { // 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 // accordingly. This way we should have the content pre-rendered by the // time the animation is done. - ImmutableViewportMetrics metrics = new ImmutableViewportMetrics(viewport); DisplayPortMetrics displayPort = DisplayPortCalculator.calculate(metrics, null); adjustViewport(displayPort); } @@ -677,12 +676,12 @@ public class GeckoLayerClient /** Implementation of PanZoomTarget * You must hold the monitor while calling this. */ - public void setViewportMetrics(ViewportMetrics viewport) { - setViewportMetrics(viewport, true); + public void setViewportMetrics(ImmutableViewportMetrics metrics) { + setViewportMetrics(metrics, true); } - private void setViewportMetrics(ViewportMetrics viewport, boolean notifyGecko) { - mViewportMetrics = new ImmutableViewportMetrics(viewport); + private void setViewportMetrics(ImmutableViewportMetrics metrics, boolean notifyGecko) { + mViewportMetrics = metrics; mView.requestRender(); if (notifyGecko && mGeckoIsReady) { geometryChanged(); diff --git a/mobile/android/base/gfx/ImmutableViewportMetrics.java b/mobile/android/base/gfx/ImmutableViewportMetrics.java index f40f2b65f5d..e01f5bfdcd2 100644 --- a/mobile/android/base/gfx/ImmutableViewportMetrics.java +++ b/mobile/android/base/gfx/ImmutableViewportMetrics.java @@ -143,6 +143,22 @@ public class ImmutableViewportMetrics { 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 public String toString() { return "ImmutableViewportMetrics v=(" + viewportRectLeft + "," + viewportRectTop + "," diff --git a/mobile/android/base/gfx/ViewportMetrics.java b/mobile/android/base/gfx/ViewportMetrics.java index 885724a6d9b..7832a7520e7 100644 --- a/mobile/android/base/gfx/ViewportMetrics.java +++ b/mobile/android/base/gfx/ViewportMetrics.java @@ -178,13 +178,6 @@ public class ViewportMetrics { 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() { // 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. diff --git a/mobile/android/base/ui/PanZoomController.java b/mobile/android/base/ui/PanZoomController.java index 7ff3e5892df..3c419965398 100644 --- a/mobile/android/base/ui/PanZoomController.java +++ b/mobile/android/base/ui/PanZoomController.java @@ -259,8 +259,8 @@ public class PanZoomController public void pageRectUpdated() { if (mState == PanZoomState.NOTHING) { synchronized (mTarget.getLock()) { - ViewportMetrics validated = getValidViewportMetrics(); - if (! getMutableMetrics().fuzzyEquals(validated)) { + ImmutableViewportMetrics validated = getValidViewportMetrics(); + if (!getMetrics().fuzzyEquals(validated)) { // page size changed such that we are now in overscroll. snap to the // the nearest valid viewport mTarget.setViewportMetrics(validated); @@ -491,7 +491,7 @@ public class PanZoomController origin.offset(point.x, point.y); viewportMetrics.setOrigin(origin); - mTarget.setViewportMetrics(viewportMetrics); + mTarget.setViewportMetrics(new ImmutableViewportMetrics(viewportMetrics)); } private void fling() { @@ -507,10 +507,10 @@ public class PanZoomController } /* Performs a bounce-back animation to the given viewport metrics. */ - private void bounce(ViewportMetrics metrics) { + private void bounce(ImmutableViewportMetrics metrics) { stopAnimationTimer(); - ViewportMetrics bounceStartMetrics = getMutableMetrics(); + ImmutableViewportMetrics bounceStartMetrics = getMetrics(); if (bounceStartMetrics.fuzzyEquals(metrics)) { setState(PanZoomState.NOTHING); return; @@ -625,9 +625,9 @@ public class PanZoomController private ImmutableViewportMetrics mBounceStartMetrics; private ImmutableViewportMetrics mBounceEndMetrics; - BounceRunnable(ViewportMetrics startMetrics, ViewportMetrics endMetrics) { - mBounceStartMetrics = new ImmutableViewportMetrics(startMetrics); - mBounceEndMetrics = new ImmutableViewportMetrics(endMetrics); + BounceRunnable(ImmutableViewportMetrics startMetrics, ImmutableViewportMetrics endMetrics) { + mBounceStartMetrics = startMetrics; + mBounceEndMetrics = endMetrics; } protected void animateFrame() { @@ -658,7 +658,7 @@ public class PanZoomController synchronized (mTarget.getLock()) { float t = easeOut(mBounceFrame * Axis.MS_PER_FRAME / 256f); ImmutableViewportMetrics newMetrics = mBounceStartMetrics.interpolate(mBounceEndMetrics, t); - mTarget.setViewportMetrics(new ViewportMetrics(newMetrics)); + mTarget.setViewportMetrics(newMetrics); mBounceFrame++; } } @@ -666,7 +666,7 @@ public class PanZoomController /* Concludes a bounce animation and snaps the viewport into place. */ private void finishBounce() { synchronized (mTarget.getLock()) { - mTarget.setViewportMetrics(new ViewportMetrics(mBounceEndMetrics)); + mTarget.setViewportMetrics(mBounceEndMetrics); mBounceFrame = -1; } } @@ -731,11 +731,11 @@ public class PanZoomController } /* Returns the nearest viewport metrics with no overscroll visible. */ - private ViewportMetrics getValidViewportMetrics() { + private ImmutableViewportMetrics getValidViewportMetrics() { 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. */ float zoomFactor = viewportMetrics.getZoomFactor(); RectF pageRect = viewportMetrics.getPageRect(); @@ -791,7 +791,7 @@ public class PanZoomController /* Now we pan to the right origin. */ viewportMetrics.setViewport(viewportMetrics.getClampedViewport()); - return viewportMetrics; + return new ImmutableViewportMetrics(viewportMetrics); } private class AxisX extends Axis { @@ -937,7 +937,7 @@ public class PanZoomController private void scaleWithFocus(float zoomFactor, PointF focus) { ViewportMetrics viewportMetrics = getMutableMetrics(); viewportMetrics.scaleTo(zoomFactor, focus); - mTarget.setViewportMetrics(viewportMetrics); + mTarget.setViewportMetrics(new ImmutableViewportMetrics(viewportMetrics)); } public boolean getRedrawHint() { @@ -1049,9 +1049,9 @@ public class PanZoomController // 2. now run getValidViewportMetrics on it, so that the target viewport is // clamped down to prevent overscroll, over-zoom, and other bad conditions. - finalMetrics = getValidViewportMetrics(finalMetrics); + ImmutableViewportMetrics finalValidMetrics = getValidViewportMetrics(finalMetrics); - bounce(finalMetrics); + bounce(finalValidMetrics); return true; } diff --git a/mobile/android/base/ui/PanZoomTarget.java b/mobile/android/base/ui/PanZoomTarget.java index ac4b6c48e9e..ef8a641bf5e 100644 --- a/mobile/android/base/ui/PanZoomTarget.java +++ b/mobile/android/base/ui/PanZoomTarget.java @@ -7,7 +7,6 @@ package org.mozilla.gecko.ui; import org.mozilla.gecko.ZoomConstraints; import org.mozilla.gecko.gfx.ImmutableViewportMetrics; -import org.mozilla.gecko.gfx.ViewportMetrics; import android.graphics.PointF; @@ -15,8 +14,8 @@ public interface PanZoomTarget { public ImmutableViewportMetrics getViewportMetrics(); public ZoomConstraints getZoomConstraints(); - public void setAnimationTarget(ViewportMetrics viewport); - public void setViewportMetrics(ViewportMetrics viewport); + public void setAnimationTarget(ImmutableViewportMetrics viewport); + public void setViewportMetrics(ImmutableViewportMetrics viewport); public void setForceRedraw(); public boolean post(Runnable action);