Bug 1014113 - Refine and enable zoom for find in page. r=margaret
☠☠ backed out by d522b57c3cb7 ☠ ☠
authorRobin Ricard <ricard.robin@gmail.com>
Thu, 12 Feb 2015 09:20:18 -0800
changeset 256067 32355c0d9d645fb8d4d4b69790b9da77730d87a9
parent 256066 2008ce7ec4ea70a02616da1214e4baf3f47ac10a
child 256068 bab1f360bf44141f3f1d6e710f3606e11e53e851
push id4610
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:32:55 +0000
treeherdermozilla-beta@4df54044d9ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs1014113, 1015395
milestone38.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 1014113 - Refine and enable zoom for find in page. r=margaret Defines a viewport factor around the highlighted word May need more testing (See bug 1015395)
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
@@ -145,14 +145,27 @@ var FindHelper = {
           // this should never happen
           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);
+      // Defines the space around the highlighted element as a factor of the element's size.
+      const spacingFactor = 6;
+
+      // We replace the start of the zoom rect to keep the highlighted word in the middle.
+      // We divide this offset by two to consider a spacing on each side of the rect.
+      let x = aData.rect.x + (aData.rect.width * (1 - spacingFactor)) / 2;
+      let y = aData.rect.y + (aData.rect.height * (1 - spacingFactor)) / 2;
+
+      let rect = new Rect(Math.max(x, 0),
+                          Math.max(y, 0),
+                          // we use a bigger viewport than just the highlighted word
+                          aData.rect.width * spacingFactor,
+                          aData.rect.height * spacingFactor);
+
+      ZoomHelper.zoomToRect(rect);
       this._viewportChanged = true;
     }
   }
 };
--- a/mobile/android/chrome/content/ZoomHelper.js
+++ b/mobile/android/chrome/content/ZoomHelper.js
@@ -118,16 +118,21 @@ var ZoomHelper = {
     }
   },
 
   /* 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) {
+    if(aRect.isEmpty()) {
+      // Protect from empty or negative-sized rects & potentials NaN in following calculations
+      return;
+    }
+
     let viewport = BrowserApp.selectedTab.getViewport();
 
     let rect = {
       x: aRect.x,
       y: aRect.y,
       w: aRect.width,
       h: Math.min(aRect.width * viewport.cssHeight / viewport.cssWidth, aRect.height)
     };