Bug 744939 - Make animatedZoomTo operate in CSS pixels instead of device pixels. r=kats a=blocking-fennec

This commit is contained in:
Joe Drew 2012-04-14 13:18:10 -04:00
parent 5248a80c1d
commit 6885673109
5 changed files with 35 additions and 16 deletions

View File

@ -70,6 +70,10 @@ public class ImmutableViewportMetrics {
viewportRectBottom);
}
public RectF getCssViewport() {
return RectUtils.scale(getViewport(), 1/zoomFactor);
}
public FloatSize getPageSize() {
return new FloatSize(pageSizeWidth, pageSizeHeight);
}

View File

@ -128,6 +128,10 @@ public class LayerController {
return mViewportMetrics.getViewport();
}
public RectF getCssViewport() {
return mViewportMetrics.getCssViewport();
}
public FloatSize getViewportSize() {
return mViewportMetrics.getSize();
}

View File

@ -122,6 +122,10 @@ public class ViewportMetrics {
return mViewportRect;
}
public RectF getCssViewport() {
return RectUtils.scale(mViewportRect, 1/mZoomFactor);
}
/** Returns the viewport rectangle, clamped within the page-size. */
public RectF getClampedViewport() {
RectF clampedViewport = new RectF(mViewportRect);

View File

@ -194,9 +194,9 @@ public class PanZoomController
}
});
} else if (MESSAGE_ZOOM_PAGE.equals(event)) {
FloatSize pageSize = mController.getPageSize();
FloatSize pageSize = mController.getCssPageSize();
RectF viewableRect = mController.getViewport();
RectF viewableRect = mController.getCssViewport();
float y = viewableRect.top;
// attempt to keep zoom keep focused on the center of the viewport
float newHeight = viewableRect.height() * pageSize.width / viewableRect.width();
@ -979,6 +979,12 @@ public class PanZoomController
GeckoAppShell.sendEventToGecko(e);
}
/**
* Zoom to a specified rect IN CSS PIXELS.
*
* While we usually use device pixels, @zoomToRect must be specified in CSS
* pixels.
*/
private boolean animatedZoomTo(RectF zoomToRect) {
GeckoApp.mFormAssistPopup.hide();
@ -1006,10 +1012,11 @@ public class PanZoomController
zoomToRect.right = zoomToRect.left + newWidth;
}
float finalZoom = viewport.width() * startZoom / zoomToRect.width();
float finalZoom = viewport.width() / zoomToRect.width();
ViewportMetrics finalMetrics = new ViewportMetrics(mController.getViewportMetrics());
finalMetrics.setOrigin(new PointF(zoomToRect.left, zoomToRect.top));
finalMetrics.setOrigin(new PointF(zoomToRect.left * finalMetrics.getZoomFactor(),
zoomToRect.top * finalMetrics.getZoomFactor()));
finalMetrics.scaleTo(finalZoom, new PointF(0.0f, 0.0f));
// 2. now run getValidViewportMetrics on it, so that the target viewport is

View File

@ -1769,6 +1769,8 @@ Tab.prototype = {
let viewport = {
width: gScreenWidth,
height: gScreenHeight,
cssWidth: gScreenWidth / this._zoom,
cssHeight: gScreenHeight / this._zoom,
pageWidth: gScreenWidth,
pageHeight: gScreenHeight,
// We make up matching css page dimensions
@ -1778,16 +1780,16 @@ Tab.prototype = {
};
// Set the viewport offset to current scroll offset
viewport.x = this.browser.contentWindow.scrollX || 0;
viewport.y = this.browser.contentWindow.scrollY || 0;
viewport.cssX = this.browser.contentWindow.scrollX || 0;
viewport.cssY = this.browser.contentWindow.scrollY || 0;
// Transform coordinates based on zoom
viewport.x = Math.round(viewport.x * viewport.zoom);
viewport.y = Math.round(viewport.y * viewport.zoom);
viewport.x = Math.round(viewport.cssX * viewport.zoom);
viewport.y = Math.round(viewport.cssY * viewport.zoom);
let doc = this.browser.contentDocument;
if (doc != null) {
let [pageWidth, pageHeight] = this.getPageSize(doc, viewport.width, viewport.height);
let [pageWidth, pageHeight] = this.getPageSize(doc, viewport.cssWidth, viewport.cssHeight);
let cssPageWidth = pageWidth;
let cssPageHeight = pageHeight;
@ -2521,16 +2523,14 @@ var BrowserEventHandler = {
let rect = ElementTouchHelper.getBoundingContentRect(element);
let viewport = BrowserApp.selectedTab.getViewport();
let vRect = new Rect(viewport.x, viewport.y, viewport.width, viewport.height);
let zoom = viewport.zoom;
let vRect = new Rect(viewport.cssX, viewport.cssY, viewport.cssWidth, viewport.cssHeight);
let bRect = new Rect(Math.max(0,rect.x - margin),
rect.y,
rect.w + 2*margin,
rect.h);
// constrict the rect to the screen width
bRect.width = Math.min(bRect.width, viewport.pageWidth/zoom - bRect.x);
bRect.scale(zoom, zoom);
bRect.width = Math.min(bRect.width, viewport.cssPageWidth - bRect.x);
let overlap = vRect.intersect(bRect);
let overlapArea = overlap.width*overlap.height;
@ -2538,8 +2538,8 @@ var BrowserEventHandler = {
// on the screen at any time and if its already stretching the width of the screen
let availHeight = Math.min(bRect.width*vRect.height/vRect.width, bRect.height);
let showing = overlapArea/(bRect.width*availHeight);
let dw = (bRect.width - vRect.width)/zoom;
let dx = (bRect.x - vRect.x)/zoom;
let dw = (bRect.width - vRect.width);
let dx = (bRect.x - vRect.x);
if (showing > 0.9 &&
dx > minDifference && dx < maxDifference &&