From 33ce39f7b10b056675c85f30d81fa3966ac1afc6 Mon Sep 17 00:00:00 2001 From: Eugen Sawin Date: Wed, 29 Oct 2014 14:06:55 +0100 Subject: [PATCH] Bug 942736 - Account for hidden margins when validating viewport metrics. r=kats --- mobile/android/base/gfx/JavaPanZoomController.java | 13 +++++++------ mobile/android/base/gfx/LayerMarginsAnimator.java | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/mobile/android/base/gfx/JavaPanZoomController.java b/mobile/android/base/gfx/JavaPanZoomController.java index 4967c029136b..9ba06a897328 100644 --- a/mobile/android/base/gfx/JavaPanZoomController.java +++ b/mobile/android/base/gfx/JavaPanZoomController.java @@ -1029,6 +1029,11 @@ class JavaPanZoomController 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; @@ -1050,18 +1055,14 @@ class JavaPanZoomController // 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) diff --git a/mobile/android/base/gfx/LayerMarginsAnimator.java b/mobile/android/base/gfx/LayerMarginsAnimator.java index 3dfd073cdc4e..cfc750828d04 100644 --- a/mobile/android/base/gfx/LayerMarginsAnimator.java +++ b/mobile/android/base/gfx/LayerMarginsAnimator.java @@ -93,7 +93,7 @@ public class LayerMarginsAnimator { + ", \"bottom\" : " + bottom + ", \"left\" : " + left + " }")); } - RectF getMaxMargins() { + synchronized RectF getMaxMargins() { return mMaxMargins; }