Bug 1638773: Allow initial-scale clamping when user-scalable=no, add WPT. r=hiro, a=RyanVM
authorBrad Werth <bwerth@mozilla.com>
Wed, 20 May 2020 15:15:07 +0000
changeset 591548 d4b281989ea6aded83371f294e56a3536424361d
parent 591547 6300450479416459fad0ad5d12d86fe4201e0a39
child 591549 054895dbfa5020a7545ca2e6fc06d7f92ef61fa2
push id13173
push userryanvm@gmail.com
push dateThu, 21 May 2020 20:26:54 +0000
treeherdermozilla-beta@5bb288cd58d3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershiro, RyanVM
bugs1638773
milestone77.0
Bug 1638773: Allow initial-scale clamping when user-scalable=no, add WPT. r=hiro, a=RyanVM 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
@@ -9812,22 +9812,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>