Bug 942736 - Account for hidden margins when validating viewport metrics. r=kats, a=lsblakk
authorEugen Sawin <esawin@mozilla.com>
Wed, 29 Oct 2014 14:06:55 +0100
changeset 233883 079e6ec1b93c84e00ddd06f3c0aaec94e0856dc7
parent 233882 eb67769e73f28ff3ac9a2d176e656e349794b65a
child 233884 9c152a920e451e59f758b250398a60665b0bb9f0
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats, lsblakk
bugs942736
milestone35.0a2
Bug 942736 - Account for hidden margins when validating viewport metrics. r=kats, a=lsblakk
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;
         }