Bug 942736 - Account for hidden margins when validating viewport metrics. r=kats
authorEugen Sawin <esawin@mozilla.com>
Wed, 29 Oct 2014 14:06:55 +0100
changeset 212936 8081294c87eee5e2ee54e8b6bb723922f59f6a42
parent 212935 42da94fcdfd9ec198404948488257354d41dc94e
child 212937 703cf7b92df4c2e68770cfba9ef8610e3b5b77e3
push id27736
push userryanvm@gmail.com
push dateWed, 29 Oct 2014 20:49:13 +0000
treeherdermozilla-central@80e18ff7c7b2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs942736
milestone36.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 942736 - Account for hidden margins when validating viewport metrics. r=kats
mobile/android/base/gfx/JavaPanZoomController.java
mobile/android/base/gfx/LayerMarginsAnimator.java
--- a/mobile/android/base/gfx/JavaPanZoomController.java
+++ b/mobile/android/base/gfx/JavaPanZoomController.java
@@ -1024,16 +1024,21 @@ class JavaPanZoomController
         return getValidViewportMetrics(getMetrics());
     }
 
     private ImmutableViewportMetrics getValidViewportMetrics(ImmutableViewportMetrics viewportMetrics) {
         /* First, we adjust the zoom factor so that we can make no overscrolled area visible. */
         float zoomFactor = viewportMetrics.zoomFactor;
         RectF pageRect = viewportMetrics.getPageRect();
         RectF viewport = viewportMetrics.getViewport();
+        RectF maxMargins = mTarget.getMaxMargins();
+        RectF margins = new RectF(Math.max(maxMargins.left, viewportMetrics.marginLeft),
+                                  Math.max(maxMargins.top, viewportMetrics.marginTop),
+                                  Math.max(maxMargins.right, viewportMetrics.marginRight),
+                                  Math.max(maxMargins.bottom, viewportMetrics.marginBottom));
 
         float focusX = viewport.width() / 2.0f;
         float focusY = viewport.height() / 2.0f;
 
         float minZoomFactor = 0.0f;
         float maxZoomFactor = MAX_ZOOM;
 
         ZoomConstraints constraints = mTarget.getZoomConstraints();
@@ -1045,28 +1050,24 @@ class JavaPanZoomController
 
         if (!constraints.getAllowZoom()) {
             // If allowZoom is false, clamp to the default zoom level.
             maxZoomFactor = minZoomFactor = constraints.getDefaultZoom();
         }
 
         // Ensure minZoomFactor keeps the page at least as big as the viewport.
         if (pageRect.width() > 0) {
-            float pageWidth = pageRect.width() +
-              viewportMetrics.marginLeft +
-              viewportMetrics.marginRight;
+            float pageWidth = pageRect.width() + margins.left + margins.right;
             float scaleFactor = viewport.width() / pageWidth;
             minZoomFactor = Math.max(minZoomFactor, zoomFactor * scaleFactor);
             if (viewport.width() > pageWidth)
                 focusX = 0.0f;
         }
         if (pageRect.height() > 0) {
-            float pageHeight = pageRect.height() +
-              viewportMetrics.marginTop +
-              viewportMetrics.marginBottom;
+            float pageHeight = pageRect.height() + margins.top + margins.bottom;
             float scaleFactor = viewport.height() / pageHeight;
             minZoomFactor = Math.max(minZoomFactor, zoomFactor * scaleFactor);
             if (viewport.height() > pageHeight)
                 focusY = 0.0f;
         }
 
         maxZoomFactor = Math.max(maxZoomFactor, minZoomFactor);
 
--- a/mobile/android/base/gfx/LayerMarginsAnimator.java
+++ b/mobile/android/base/gfx/LayerMarginsAnimator.java
@@ -88,17 +88,17 @@ public class LayerMarginsAnimator {
 
         // Update the Gecko-side global for fixed viewport margins.
         GeckoAppShell.sendEventToGecko(
             GeckoEvent.createBroadcastEvent("Viewport:FixedMarginsChanged",
                 "{ \"top\" : " + top + ", \"right\" : " + right
                 + ", \"bottom\" : " + bottom + ", \"left\" : " + left + " }"));
     }
 
-    RectF getMaxMargins() {
+    synchronized RectF getMaxMargins() {
         return mMaxMargins;
     }
 
     private void animateMargins(final float left, final float top, final float right, final float bottom, boolean immediately) {
         if (mAnimationTask != null) {
             mTarget.getView().removeRenderTask(mAnimationTask);
             mAnimationTask = null;
         }