Bug 1638773: Allow initial-scale clamping when user-scalable=no, add WPT. r=hiro
authorBrad Werth <bwerth@mozilla.com>
Wed, 20 May 2020 15:15:07 +0000
changeset 531258 0143fd91ba203aab4103c98f09d0dc2bf7b21e30
parent 531257 abfc2ef2d4ea8abc5c7ccd1d3c5fbd9dd8b91691
child 531259 96fdfd1887ce56a148cffceebf5f3dc0cc446b31
push id37436
push userncsoregi@mozilla.com
push dateWed, 20 May 2020 21:30:50 +0000
treeherdermozilla-central@6c10970490f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershiro
bugs1638773
milestone78.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 1638773: Allow initial-scale clamping when user-scalable=no, add WPT. r=hiro This corrects the handling of user-scalable=no to first clamp scale (whether specified or default) between min and max scales, then applies the resulting value to initial-scale, min and max. Differential Revision: https://phabricator.services.mozilla.com/D76056
dom/base/Document.cpp
testing/web-platform/meta/css/css-device-adapt/__dir__.ini
testing/web-platform/meta/css/css-device-adapt/viewport-user-scalable-no-wide-content.tentative.html.ini
testing/web-platform/tests/css/css-device-adapt/viewport-user-scalable-no-clamp-to-max.tentative.html
testing/web-platform/tests/css/css-device-adapt/viewport-user-scalable-no-clamp-to-min.tentative.html
--- a/dom/base/Document.cpp
+++ b/dom/base/Document.cpp
@@ -9782,22 +9782,24 @@ nsViewportInfo Document::GetViewportInfo
       if (!mValidScaleFloat && !mWidthStrEmpty) {
         CSSToScreenScale bestFitScale(float(aDisplaySize.width) / size.width);
         scaleFloat = (scaleFloat > bestFitScale) ? scaleFloat : bestFitScale;
       }
 
       size.height = clamped(size.height, effectiveMinSize.height,
                             float(kViewportMaxSize.height));
 
-      // In cases of user-scalable=no, if we have a positive scale, use it for
-      // both min and max. If we don't have a positive scale, assert that we
-      // are setting the auto scale flag.
+      // In cases of user-scalable=no, if we have a positive scale, clamp it to
+      // min and max, and then use the clamped value for the scale, the min, and
+      // the max. If we don't have a positive scale, assert that we are setting
+      // the auto scale flag.
       if (effectiveZoomFlag == nsViewportInfo::ZoomFlag::DisallowZoom &&
           scaleFloat > CSSToScreenScale(0.0f)) {
-        scaleMinFloat = scaleMaxFloat = scaleFloat;
+        scaleFloat = scaleMinFloat = scaleMaxFloat =
+            clamped(scaleFloat, scaleMinFloat, scaleMaxFloat);
       }
       MOZ_ASSERT(
           scaleFloat > CSSToScreenScale(0.0f) || !mValidScaleFloat,
           "If we don't have a positive scale, we should be using auto scale.");
 
       // We need to perform a conversion, but only if the initial or maximum
       // scale were set explicitly by the user.
       if (mValidScaleFloat && scaleFloat >= scaleMinFloat &&
--- a/testing/web-platform/meta/css/css-device-adapt/__dir__.ini
+++ b/testing/web-platform/meta/css/css-device-adapt/__dir__.ini
@@ -1,1 +1,4 @@
 implementation-status: not-implementing
+prefs: [dom.visualviewport.enabled:true,
+        dom.meta-viewport.enabled:true,
+        apz.allow_zooming:true]
deleted file mode 100644
--- a/testing/web-platform/meta/css/css-device-adapt/viewport-user-scalable-no-wide-content.tentative.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[viewport-user-scalable-no-wide-content.tentative.html]
-  prefs: [dom.visualviewport.enabled:true,
-          dom.meta-viewport.enabled:true,
-          apz.allow_zooming:true]
-
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/css/css-device-adapt/viewport-user-scalable-no-clamp-to-max.tentative.html
@@ -0,0 +1,29 @@
+<!doctype html>
+<meta charset=utf-8>
+<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=device-width, maximum-scale=1.0">
+<link rel="help" href="https://drafts.csswg.org/css-device-adapt/">
+<link rel="help" href="https://webcompat.com/issues/52856">
+<style>
+body {
+  margin: 0;
+}
+#content {
+  width: 100px;
+  height: 100px;
+  background: green;
+}
+</style>
+
+<div id="content">Content</div>
+
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script>
+'use strict';
+test(() => {
+  assert_equals(window.visualViewport.scale, 1.0,
+    'visual viewport scale should be 1.0');
+}, 'Page with meta viewport "width=device-width, user-scalable=no, ' +
+   'initial-scale=device-width, maximum-scale=1.0" ' +
+   'should scale to 1.0.');
+</script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/css/css-device-adapt/viewport-user-scalable-no-clamp-to-min.tentative.html
@@ -0,0 +1,29 @@
+<!doctype html>
+<meta charset=utf-8>
+<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=0.25, minimum-scale=1.0">
+<link rel="help" href="https://drafts.csswg.org/css-device-adapt/">
+<link rel="help" href="https://webcompat.com/issues/52856">
+<style>
+body {
+  margin: 0;
+}
+#content {
+  width: 100px;
+  height: 100px;
+  background: green;
+}
+</style>
+
+<div id="content">Content</div>
+
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script>
+'use strict';
+test(() => {
+  assert_equals(window.visualViewport.scale, 1.0,
+    'visual viewport scale should be 1.0');
+}, 'Page with meta viewport "width=device-width, user-scalable=no, ' +
+   'initial-scale=0.25, minimum-scale=1.0" ' +
+   'should scale to 1.0.');
+</script>