Bug 685541 - Fix zooming when in tablet mode [r=mfinkle]
authorMatt Brubeck <mbrubeck@mozilla.com>
Thu, 08 Sep 2011 12:32:31 -0700
changeset 76768 a720fe135cfa886f528582c2c8c947e9e1945a3b
parent 76767 9c44e657553462ff4d44263bc752a26ee5300ea0
child 76769 b57d50c6c0469330e0a4c9c460203c644f64f820
child 76772 1d1143dde4bb02719e47da7488424041c03952ff
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersmfinkle
bugs685541
milestone9.0a1
Bug 685541 - Fix zooming when in tablet mode [r=mfinkle]
mobile/chrome/content/AnimatedZoom.js
mobile/chrome/content/input.js
--- a/mobile/chrome/content/AnimatedZoom.js
+++ b/mobile/chrome/content/AnimatedZoom.js
@@ -71,32 +71,32 @@ const AnimatedZoom = {
       event.initEvent("AnimatedZoomBegin", true, true);
       window.dispatchEvent(event);
     }
   },
 
   start: function start() {
     this.tab = Browser.selectedTab;
     this.browser = this.tab.browser;
+    this.bcr = this.browser.getBoundingClientRect();
     this.zoomFrom = this.zoomRect || this.getStartRect();
     this.startScale = this.browser.scale;
     this.beginTime = mozAnimationStartTime;
   },
 
   /** Get the visible rect, in device pixels relative to the content origin. */
   getStartRect: function getStartRect() {
     let browser = this.browser;
-    let bcr = browser.getBoundingClientRect();
     let scroll = browser.getRootView().getPosition();
-    return new Rect(scroll.x, scroll.y, bcr.width, bcr.height);
+    return new Rect(scroll.x, scroll.y, this.bcr.width, this.bcr.height);
   },
 
   /** Update the visible rect, in device pixels relative to the content origin. */
   updateTo: function(nextRect) {
-    let zoomRatio = window.innerWidth / nextRect.width;
+    let zoomRatio = this.bcr.width / nextRect.width;
     let scale = this.startScale * zoomRatio;
     let scrollX = nextRect.left * zoomRatio;
     let scrollY = nextRect.top * zoomRatio;
 
     this.browser.fuzzyZoom(scale, scrollX, scrollY);
 
     this.zoomRect = nextRect;
   },
--- a/mobile/chrome/content/input.js
+++ b/mobile/chrome/content/input.js
@@ -1204,37 +1204,38 @@ GestureModule.prototype = {
 
   _pinchUpdate: function _pinchUpdate(aEvent) {
     if (!AnimatedZoom.isZooming() || !aEvent.delta)
       return;
 
     let delta = 0;
     let browser = AnimatedZoom.browser;
     let oldScale = browser.scale;
+    let bcr = this._browserBCR;
 
     // Accumulate pinch delta. Small changes are just jitter.
     this._pinchDelta += aEvent.delta;
     if (Math.abs(this._pinchDelta) >= oldScale) {
       delta = this._pinchDelta;
       this._pinchDelta = 0;
     }
 
     // decrease the pinchDelta min/max values to limit zooming out/in speed
     delta = Util.clamp(delta, -this._maxShrink, this._maxGrowth);
 
     let newScale = Browser.selectedTab.clampZoomLevel(oldScale * (1 + delta / this._scalingFactor));
     let startScale = AnimatedZoom.startScale;
     let scaleRatio = startScale / newScale;
-    let cX = aEvent.clientX - this._browserBCR.left;
-    let cY = aEvent.clientY - this._browserBCR.top;
+    let cX = aEvent.clientX - bcr.left;
+    let cY = aEvent.clientY - bcr.top;
 
     // Calculate the new zoom rect.
     let rect = AnimatedZoom.zoomFrom.clone();
-    rect.translate(this._pinchStartX - cX + (1-scaleRatio) * cX * rect.width / window.innerWidth,
-                   this._pinchStartY - cY + (1-scaleRatio) * cY * rect.height / window.innerHeight);
+    rect.translate(this._pinchStartX - cX + (1-scaleRatio) * cX * rect.width / bcr.width,
+                   this._pinchStartY - cY + (1-scaleRatio) * cY * rect.height / bcr.height);
 
     rect.width *= scaleRatio;
     rect.height *= scaleRatio;
 
     this.translateInside(rect, new Rect(0, 0, browser.contentDocumentWidth * startScale,
                                               browser.contentDocumentHeight * startScale));
 
     // redraw zoom canvas according to new zoom rect