Bug 994724 - Clean up ZoomHelper logic. r=margaret

This commit is contained in:
Robin Ricard 2014-09-17 01:37:00 +02:00
parent adfedbd7d8
commit 5b1d5bab23
2 changed files with 25 additions and 26 deletions

View File

@ -78,7 +78,7 @@ var FindHelper = {
}
} else {
// Disabled until bug 1014113 is fixed
//ZoomHelper.zoomToRect(aData.rect, -1, false, true);
// ZoomHelper.zoomToRect(aData.rect);
this._viewportChanged = true;
}
}

View File

@ -81,24 +81,16 @@ var ZoomHelper = {
*/
zoomToElement: function(aElement, aClickY = -1, aCanZoomOut = true, aCanScrollHorizontally = true) {
let rect = ElementTouchHelper.getBoundingContentRect(aElement);
ZoomHelper.zoomToRect(rect, aClickY, aCanZoomOut, aCanScrollHorizontally, aElement);
},
zoomToRect: function(aRect, aClickY = -1, aCanZoomOut = true, aCanScrollHorizontally = true, aElement) {
const margin = 15;
if(!aRect.h || !aRect.w) {
aRect.h = aRect.height;
aRect.w = aRect.width;
}
let viewport = BrowserApp.selectedTab.getViewport();
let bRect = new Rect(aCanScrollHorizontally ? Math.max(viewport.cssPageLeft, aRect.x - margin) : viewport.cssX,
aRect.y,
aCanScrollHorizontally ? aRect.w + 2 * margin : viewport.cssWidth,
aRect.h);
rect = new Rect(aCanScrollHorizontally ? Math.max(viewport.cssPageLeft, rect.x - margin) : viewport.cssX,
rect.y,
aCanScrollHorizontally ? rect.w + 2 * margin : viewport.cssWidth,
rect.h);
// constrict the rect to the screen's right edge
bRect.width = Math.min(bRect.width, viewport.cssPageRight - bRect.x);
rect.width = Math.min(rect.width, viewport.cssPageRight - rect.x);
// if the rect is already taking up most of the visible area and is stretching the
// width of the page, then we want to zoom out instead.
@ -106,37 +98,44 @@ var ZoomHelper = {
if (BrowserEventHandler.mReflozPref) {
let zoomFactor = BrowserApp.selectedTab.getZoomToMinFontSize(aElement);
bRect.width = zoomFactor <= 1.0 ? bRect.width : gScreenWidth / zoomFactor;
bRect.height = zoomFactor <= 1.0 ? bRect.height : bRect.height / zoomFactor;
if (zoomFactor == 1.0 || ZoomHelper.isRectZoomedIn(bRect, viewport)) {
rect.width = zoomFactor <= 1.0 ? rect.width : gScreenWidth / zoomFactor;
rect.height = zoomFactor <= 1.0 ? rect.height : rect.height / zoomFactor;
if (zoomFactor == 1.0 || ZoomHelper.isRectZoomedIn(rect, viewport)) {
if (aCanZoomOut) {
ZoomHelper.zoomOut();
}
return;
}
} else if (ZoomHelper.isRectZoomedIn(bRect, viewport)) {
} else if (ZoomHelper.isRectZoomedIn(rect, viewport)) {
if (aCanZoomOut) {
ZoomHelper.zoomOut();
}
return;
}
}
let rect = {};
ZoomHelper.zoomToRect(rect, aClickY);
}
},
/* Zoom to a specific part of the screen defined by a rect,
* optionally keeping a particular part of it in view
* if it is really tall.
*/
zoomToRect: function(aRect, aClickY = -1) {
let rect = new Rect(aRect.x,
aRect.y,
aRect.width,
Math.min(aRect.width * viewport.cssHeight / viewport.cssWidth, aRect.height));
rect.type = "Browser:ZoomToRect";
rect.x = bRect.x;
rect.y = bRect.y;
rect.w = bRect.width;
rect.h = Math.min(bRect.width * viewport.cssHeight / viewport.cssWidth, bRect.height);
if (aClickY >= 0) {
// if the block we're zooming to is really tall, and we want to keep a particular
// part of it in view, then adjust the y-coordinate of the target rect accordingly.
// the 1.2 multiplier is just a little fuzz to compensate for bRect including horizontal
// the 1.2 multiplier is just a little fuzz to compensate for aRect including horizontal
// margins but not vertical ones.
let cssTapY = viewport.cssY + aClickY;
if ((bRect.height > rect.h) && (cssTapY > rect.y + (rect.h * 1.2))) {
if ((aRect.height > rect.h) && (cssTapY > rect.y + (rect.h * 1.2))) {
rect.y = cssTapY - (rect.h / 2);
}
}