Bug 994724 - Clean up ZoomHelper logic. r=margaret
authorRobin Ricard <ricard.robin@gmail.com>
Wed, 17 Sep 2014 01:37:00 +0200
changeset 206036 79bf6ebacb09d14111055dddc445330da32e1517
parent 206035 37f902fba2dedc79f4dc43ffbd77a7a165f58746
child 206037 60881e5c48b33d2768b69b7c3e74e9116961f87e
push id49338
push userkwierso@gmail.com
push dateThu, 18 Sep 2014 23:10:09 +0000
treeherdermozilla-inbound@245051c6a7ed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs994724
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 994724 - Clean up ZoomHelper logic. r=margaret
mobile/android/chrome/content/FindHelper.js
mobile/android/chrome/content/ZoomHelper.js
--- a/mobile/android/chrome/content/FindHelper.js
+++ b/mobile/android/chrome/content/FindHelper.js
@@ -73,13 +73,13 @@ var FindHelper = {
           Cu.reportError("Warning: selected tab changed during find!");
           // fall through and restore viewport on the initial tab anyway
         }
         this._targetTab.setViewport(JSON.parse(this._initialViewport));
         this._targetTab.sendViewportUpdate();
       }
     } else {
       // Disabled until bug 1014113 is fixed
-      //ZoomHelper.zoomToRect(aData.rect, -1, false, true);
+      // ZoomHelper.zoomToRect(aData.rect);
       this._viewportChanged = true;
     }
   }
 };
--- a/mobile/android/chrome/content/ZoomHelper.js
+++ b/mobile/android/chrome/content/ZoomHelper.js
@@ -76,72 +76,71 @@ var ZoomHelper = {
             dw > minDifference && dw < maxDifference);
   },
 
   /* Zoom to an element, optionally keeping a particular part of it
    * in view if it is really tall.
    */
   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.
     if (aElement) {
       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;
       }
+
+      ZoomHelper.zoomToRect(rect, aClickY);
     }
+  },
 
-    let rect = {};
+  /* 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);
       }
     }
 
     if (rect.w > viewport.cssWidth || rect.h > viewport.cssHeight) {
       BrowserEventHandler.resetMaxLineBoxWidth();
     }