Bug 728614 - Part 2: Remove viewport offsets

This commit is contained in:
Ehsan Akhgari 2012-02-20 16:51:37 -05:00
parent 7781198b39
commit 71bd0669a9
3 changed files with 8 additions and 41 deletions

View File

@ -407,7 +407,6 @@ public abstract class GeckoLayerClient implements GeckoEventListener,
new ViewportMetrics(mLayerController.getViewportMetrics()); new ViewportMetrics(mLayerController.getViewportMetrics());
PointF viewportOffset = viewportMetrics.getOptimumViewportOffset(mBufferSize); PointF viewportOffset = viewportMetrics.getOptimumViewportOffset(mBufferSize);
viewportMetrics.setViewportOffset(viewportOffset);
viewportMetrics.setViewport(viewportMetrics.getClampedViewport()); viewportMetrics.setViewport(viewportMetrics.getClampedViewport());
GeckoAppShell.sendEventToGecko(GeckoEvent.createViewportEvent(viewportMetrics)); GeckoAppShell.sendEventToGecko(GeckoEvent.createViewportEvent(viewportMetrics));

View File

@ -62,7 +62,6 @@ public class ViewportMetrics {
private FloatSize mPageSize; private FloatSize mPageSize;
private RectF mViewportRect; private RectF mViewportRect;
private PointF mViewportOffset;
private float mZoomFactor; private float mZoomFactor;
// A scale from -1,-1 to 1,1 that represents what edge of the displayport // A scale from -1,-1 to 1,1 that represents what edge of the displayport
@ -76,7 +75,6 @@ public class ViewportMetrics {
mPageSize = new FloatSize(metrics.widthPixels, metrics.heightPixels); mPageSize = new FloatSize(metrics.widthPixels, metrics.heightPixels);
mViewportRect = new RectF(0, 0, metrics.widthPixels, metrics.heightPixels); mViewportRect = new RectF(0, 0, metrics.widthPixels, metrics.heightPixels);
mViewportOffset = new PointF(0, 0);
mZoomFactor = 1.0f; mZoomFactor = 1.0f;
mViewportBias = new PointF(0.0f, 0.0f); mViewportBias = new PointF(0.0f, 0.0f);
} }
@ -84,8 +82,6 @@ public class ViewportMetrics {
public ViewportMetrics(ViewportMetrics viewport) { public ViewportMetrics(ViewportMetrics viewport) {
mPageSize = new FloatSize(viewport.getPageSize()); mPageSize = new FloatSize(viewport.getPageSize());
mViewportRect = new RectF(viewport.getViewport()); mViewportRect = new RectF(viewport.getViewport());
PointF offset = viewport.getViewportOffset();
mViewportOffset = new PointF(offset.x, offset.y);
mZoomFactor = viewport.getZoomFactor(); mZoomFactor = viewport.getZoomFactor();
mViewportBias = viewport.mViewportBias; mViewportBias = viewport.mViewportBias;
} }
@ -97,22 +93,15 @@ public class ViewportMetrics {
float height = (float)json.getDouble("height"); float height = (float)json.getDouble("height");
float pageWidth = (float)json.getDouble("pageWidth"); float pageWidth = (float)json.getDouble("pageWidth");
float pageHeight = (float)json.getDouble("pageHeight"); float pageHeight = (float)json.getDouble("pageHeight");
float offsetX = (float)json.getDouble("offsetX");
float offsetY = (float)json.getDouble("offsetY");
float zoom = (float)json.getDouble("zoom"); float zoom = (float)json.getDouble("zoom");
mPageSize = new FloatSize(pageWidth, pageHeight); mPageSize = new FloatSize(pageWidth, pageHeight);
mViewportRect = new RectF(x, y, x + width, y + height); mViewportRect = new RectF(x, y, x + width, y + height);
mViewportOffset = new PointF(offsetX, offsetY);
mZoomFactor = zoom; mZoomFactor = zoom;
mViewportBias = new PointF(0.0f, 0.0f); mViewportBias = new PointF(0.0f, 0.0f);
} }
public PointF getOptimumViewportOffset(IntSize displayportSize) { public PointF getOptimumViewportOffset(IntSize displayportSize) {
/* XXX Until bug #524925 is fixed, changing the viewport origin will
* cause unnecessary relayouts. This may cause rendering time to
* increase and should be considered.
*/
RectF viewport = getClampedViewport(); RectF viewport = getClampedViewport();
FloatSize bufferSpace = new FloatSize(displayportSize.width - viewport.width(), FloatSize bufferSpace = new FloatSize(displayportSize.width - viewport.width(),
@ -142,8 +131,8 @@ public class ViewportMetrics {
} }
public PointF getDisplayportOrigin() { public PointF getDisplayportOrigin() {
return new PointF(mViewportRect.left - mViewportOffset.x, return new PointF(mViewportRect.left,
mViewportRect.top - mViewportOffset.y); mViewportRect.top);
} }
public FloatSize getSize() { public FloatSize getSize() {
@ -174,10 +163,6 @@ public class ViewportMetrics {
return clampedViewport; return clampedViewport;
} }
public PointF getViewportOffset() {
return mViewportOffset;
}
public FloatSize getPageSize() { public FloatSize getPageSize() {
return mPageSize; return mPageSize;
} }
@ -222,10 +207,6 @@ public class ViewportMetrics {
mViewportRect.bottom = mViewportRect.top + size.height; mViewportRect.bottom = mViewportRect.top + size.height;
} }
public void setViewportOffset(PointF offset) {
mViewportOffset = offset;
}
public void setZoomFactor(float zoomFactor) { public void setZoomFactor(float zoomFactor) {
mZoomFactor = zoomFactor; mZoomFactor = zoomFactor;
} }
@ -267,14 +248,12 @@ public class ViewportMetrics {
result.mPageSize = mPageSize.interpolate(to.mPageSize, t); result.mPageSize = mPageSize.interpolate(to.mPageSize, t);
result.mZoomFactor = FloatUtils.interpolate(mZoomFactor, to.mZoomFactor, t); result.mZoomFactor = FloatUtils.interpolate(mZoomFactor, to.mZoomFactor, t);
result.mViewportRect = RectUtils.interpolate(mViewportRect, to.mViewportRect, t); result.mViewportRect = RectUtils.interpolate(mViewportRect, to.mViewportRect, t);
result.mViewportOffset = PointUtils.interpolate(mViewportOffset, to.mViewportOffset, t);
return result; return result;
} }
public boolean fuzzyEquals(ViewportMetrics other) { public boolean fuzzyEquals(ViewportMetrics other) {
return mPageSize.fuzzyEquals(other.mPageSize) return mPageSize.fuzzyEquals(other.mPageSize)
&& RectUtils.fuzzyEquals(mViewportRect, other.mViewportRect) && RectUtils.fuzzyEquals(mViewportRect, other.mViewportRect)
&& FloatUtils.fuzzyEquals(mViewportOffset, other.mViewportOffset)
&& FloatUtils.fuzzyEquals(mZoomFactor, other.mZoomFactor); && FloatUtils.fuzzyEquals(mZoomFactor, other.mZoomFactor);
} }
@ -291,8 +270,6 @@ public class ViewportMetrics {
.append(", \"height\" : ").append(height) .append(", \"height\" : ").append(height)
.append(", \"pageWidth\" : ").append(mPageSize.width) .append(", \"pageWidth\" : ").append(mPageSize.width)
.append(", \"pageHeight\" : ").append(mPageSize.height) .append(", \"pageHeight\" : ").append(mPageSize.height)
.append(", \"offsetX\" : ").append(mViewportOffset.x)
.append(", \"offsetY\" : ").append(mViewportOffset.y)
.append(", \"zoom\" : ").append(mZoomFactor) .append(", \"zoom\" : ").append(mZoomFactor)
.append(" }"); .append(" }");
return sb.toString(); return sb.toString();
@ -303,9 +280,7 @@ public class ViewportMetrics {
StringBuffer buff = new StringBuffer(128); StringBuffer buff = new StringBuffer(128);
buff.append("v=").append(mViewportRect.toString()) buff.append("v=").append(mViewportRect.toString())
.append(" p=").append(mPageSize.toString()) .append(" p=").append(mPageSize.toString())
.append(" z=").append(mZoomFactor) .append(" z=").append(mZoomFactor);
.append(" o=").append(mViewportOffset.x)
.append(',').append(mViewportOffset.y);
return buff.toString(); return buff.toString();
} }
} }

View File

@ -1454,7 +1454,7 @@ function Tab(aURL, aParams) {
this.id = 0; this.id = 0;
this.showProgress = true; this.showProgress = true;
this.create(aURL, aParams); this.create(aURL, aParams);
this._viewport = { x: 0, y: 0, width: gScreenWidth, height: gScreenHeight, offsetX: 0, offsetY: 0, this._viewport = { x: 0, y: 0, width: gScreenWidth, height: gScreenHeight,
pageWidth: gScreenWidth, pageHeight: gScreenHeight, zoom: 1.0 }; pageWidth: gScreenWidth, pageHeight: gScreenHeight, zoom: 1.0 };
this.viewportExcess = { x: 0, y: 0 }; this.viewportExcess = { x: 0, y: 0 };
this.documentIdForCurrentViewport = null; this.documentIdForCurrentViewport = null;
@ -1605,12 +1605,6 @@ Tab.prototype = {
let cwu = window.top.QueryInterface(Ci.nsIInterfaceRequestor) let cwu = window.top.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils); .getInterface(Ci.nsIDOMWindowUtils);
if (aViewport.offsetX != this._viewport.offsetX) {
this._viewport.offsetX = aViewport.offsetX;
}
if (aViewport.offsetY != this._viewport.offsetY) {
this._viewport.offsetY = aViewport.offsetY;
}
if (Math.abs(zoom - this._viewport.zoom) >= 1e-6) { if (Math.abs(zoom - this._viewport.zoom) >= 1e-6) {
this._viewport.zoom = zoom; this._viewport.zoom = zoom;
cwu.setResolution(zoom, zoom); cwu.setResolution(zoom, zoom);
@ -1682,7 +1676,6 @@ Tab.prototype = {
this.viewportExcess = { x: 0, y: 0 }; this.viewportExcess = { x: 0, y: 0 };
this.viewport = { x: xpos, y: ypos, this.viewport = { x: xpos, y: ypos,
offsetX: 0, offsetY: 0,
width: this._viewport.width, height: this._viewport.height, width: this._viewport.width, height: this._viewport.height,
pageWidth: gScreenWidth, pageHeight: gScreenHeight, pageWidth: gScreenWidth, pageHeight: gScreenHeight,
zoom: zoom }; zoom: zoom };
@ -2483,8 +2476,8 @@ const ElementTouchHelper = {
let viewport = tab.viewport; let viewport = tab.viewport;
return [ return [
((aX - tab.viewportExcess.x) * viewport.zoom + viewport.offsetX), ((aX - tab.viewportExcess.x) * viewport.zoom),
((aY - tab.viewportExcess.y) * viewport.zoom + viewport.offsetY) ((aY - tab.viewportExcess.y) * viewport.zoom)
]; ];
}, },
@ -2502,8 +2495,8 @@ const ElementTouchHelper = {
let viewport = tab.viewport; let viewport = tab.viewport;
return [ return [
(aX - viewport.offsetX)/viewport.zoom + tab.viewportExcess.x, aX/viewport.zoom + tab.viewportExcess.x,
(aY - viewport.offsetY)/viewport.zoom + tab.viewportExcess.y aY/viewport.zoom + tab.viewportExcess.y
]; ];
}, },