From cdf9a72c917891e39ef3c2ce0339b149a627e800 Mon Sep 17 00:00:00 2001 From: Taras Glek Date: Tue, 3 Mar 2009 15:54:27 -0800 Subject: [PATCH] Bug 480595: Do not show navbar on zoomToElement r=gavin --- mobile/chrome/content/CanvasBrowser.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/mobile/chrome/content/CanvasBrowser.js b/mobile/chrome/content/CanvasBrowser.js index fbcade55f77b..19b0276020d7 100644 --- a/mobile/chrome/content/CanvasBrowser.js +++ b/mobile/chrome/content/CanvasBrowser.js @@ -399,18 +399,24 @@ CanvasBrowser.prototype = { zoomToElement: function(aElement) { const margin = 15; - // scale to the element's width - let [canvasW, ] = this.canvasDimensions; - let elRect = this._getPagePosition(aElement); - let zoomLevel = canvasW / (elRect.width + (2 * margin)); - + let elWidth = elRect.width; + let visibleViewportWidth = this._pageToScreen(this._visibleBounds.width); + /* Try to set zoom-level such that once zoomed element is as wide + * as the visible viewport */ + let zoomLevel = visibleViewportWidth / (elWidth + (2 * margin)); ws.beginUpdateBatch(); - this.zoomLevel = Math.min(zoomLevel, 10); + this.zoomLevel = zoomLevel; + + /* If zoomLevel ends up clamped to less than asked for, calculate + * how many more screen pixels will fit horizontally in addition to + * element's width. This ensures that more of the webpage is + * showing instead of the navbar. Bug 480595. */ + let xpadding = Math.max(margin, visibleViewportWidth - this._pageToScreen(elWidth)); // pan to the element - ws.panTo(Math.floor(Math.max(this._pageToScreen(elRect.x) - margin, 0)), + ws.panTo(Math.floor(Math.max(this._pageToScreen(elRect.x) - xpadding, 0)), Math.floor(Math.max(this._pageToScreen(elRect.y) - margin, 0))); ws.endUpdateBatch();