Bug 1509552 - Ensure MobileViewportManager doesn't choose a zoom level that makes the content smaller than the visual viewport. r=kats
authorBotond Ballo <botond@mozilla.com>
Fri, 30 Nov 2018 00:59:11 +0000
changeset 508123 d8064028f0e66760a66105089a0bc1258877b6bf
parent 508122 038125c617dca34532412d7d641306c73c011150
child 508124 095c92e4b6b569c2af6e24990a36fac1c4d2e214
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1509552
milestone65.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 1509552 - Ensure MobileViewportManager doesn't choose a zoom level that makes the content smaller than the visual viewport. r=kats Differential Revision: https://phabricator.services.mozilla.com/D13315
layout/base/MobileViewportManager.cpp
--- a/layout/base/MobileViewportManager.cpp
+++ b/layout/base/MobileViewportManager.cpp
@@ -319,18 +319,31 @@ MobileViewportManager::UpdateResolution(
       if (aDisplayWidthChangeRatio) {
         newZoom = Some(ScaleZoomWithDisplayWidth(zoom, aDisplayWidthChangeRatio.value(),
           viewportSize, mMobileViewportSize));
       }
     }
   } else {  // aType == UpdateType::ContentSize
     MOZ_ASSERT(aType == UpdateType::ContentSize);
     MOZ_ASSERT(aDisplayWidthChangeRatio.isNothing());
-    if (zoom != intrinsicScale) {
-      newZoom = Some(intrinsicScale);
+
+    // We try to scale down the contents only IF the document has no initial-scale
+    // AND IF it's the initial paint AND IF it's not restored documents.
+    if (mIsFirstPaint && !mRestoreResolution &&
+        !aViewportInfo.IsDefaultZoomValid()) {
+      if (zoom != intrinsicScale) {
+        newZoom = Some(intrinsicScale);
+      }
+    } else {
+      // Even in other scenarios, we want to ensure that zoom level is
+      // not _smaller_ than the intrinsic scale, otherwise we might be
+      // trying to show regions where there is no content to show.
+      if (zoom < intrinsicScale) {
+        newZoom = Some(intrinsicScale);
+      }
     }
   }
 
   // If the zoom has changed, update the pres shell resolution and the
   // visual viewport size accordingly.
   if (newZoom) {
     LayoutDeviceToLayerScale resolution = ZoomToResolution(*newZoom, cssToDev);
     MVM_LOG("%p: setting resolution %f\n", this, resolution.scale);
@@ -511,23 +524,16 @@ MobileViewportManager::ShrinkToDisplaySi
 {
   if (!gfxPrefs::APZAllowZooming()) {
     // If the APZ is disabled, we don't scale down wider contents to fit them
     // into device screen because users won't be able to zoom out the tiny
     // contents.
     return;
   }
 
-  // We try to scale down the contents only IF the document has no initial-scale
-  // AND IF it's the initial paint AND IF it's not restored documents.
-  if (aViewportInfo.IsDefaultZoomValid() ||
-      !mIsFirstPaint || mRestoreResolution) {
-    return;
-  }
-
   nsIScrollableFrame* rootScrollableFrame =
     mPresShell->GetRootScrollFrameAsScrollable();
   if (rootScrollableFrame) {
     nsRect scrollableRect =
       nsLayoutUtils::CalculateScrollableRectForFrame(rootScrollableFrame,
                                                      nullptr);
     CSSSize contentSize = CSSSize::FromAppUnits(scrollableRect.Size());
     UpdateResolution(aViewportInfo, aDisplaySize, contentSize, Nothing(),