Bug 1431601 - Implement "Resolve min-zoom and max-zoom values" in the spec. r=botond
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Mon, 15 Oct 2018 23:53:44 +0000
changeset 499852 2e7851b166cebcab9f5df591f33bc8d234f1ff7c
parent 499851 02de107cdac4bcd2dc17d26bb2a70fc2662d4707
child 499869 b6f7a0b4345849cc9cf9a40abe1ff16cf1a6d905
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1431601
milestone64.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 1431601 - Implement "Resolve min-zoom and max-zoom values" in the spec. r=botond https://drafts.csswg.org/css-device-adapt/#constraining-min-max-zoom The test case in this commit fails without this change, width will be 8000 and height will be 4800 respectively when it fails. Depends on D8320 Differential Revision: https://phabricator.services.mozilla.com/D8321
dom/base/nsDocument.cpp
dom/base/test/mochitest.ini
dom/base/test/test_meta_viewport_maximum_scale_0.html
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -7297,20 +7297,20 @@ nsIDocument::GetViewportInfo(const Scree
         return nsViewportInfo(aDisplaySize, defaultScale,
                               /*allowZoom*/true);
       }
     }
 
     nsAutoString minScaleStr;
     GetHeaderData(nsGkAtoms::viewport_minimum_scale, minScaleStr);
 
-    nsresult errorCode;
-    mScaleMinFloat = LayoutDeviceToScreenScale(minScaleStr.ToFloat(&errorCode));
-
-    if (NS_FAILED(errorCode)) {
+    nsresult scaleMinErrorCode;
+    mScaleMinFloat = LayoutDeviceToScreenScale(minScaleStr.ToFloat(&scaleMinErrorCode));
+
+    if (NS_FAILED(scaleMinErrorCode)) {
       mScaleMinFloat = kViewportMinScale;
     }
 
     mScaleMinFloat = mozilla::clamped(
         mScaleMinFloat, kViewportMinScale, kViewportMaxScale);
 
     nsAutoString maxScaleStr;
     GetHeaderData(nsGkAtoms::viewport_maximum_scale, maxScaleStr);
@@ -7319,16 +7319,22 @@ nsIDocument::GetViewportInfo(const Scree
     // because they are used later (see the width calculations).
     nsresult scaleMaxErrorCode;
     mScaleMaxFloat = LayoutDeviceToScreenScale(maxScaleStr.ToFloat(&scaleMaxErrorCode));
 
     if (NS_FAILED(scaleMaxErrorCode)) {
       mScaleMaxFloat = kViewportMaxScale;
     }
 
+    // Resolve min-zoom and max-zoom values.
+    // https://drafts.csswg.org/css-device-adapt/#constraining-min-max-zoom
+    if (NS_SUCCEEDED(scaleMaxErrorCode) && NS_SUCCEEDED(scaleMinErrorCode)) {
+      mScaleMaxFloat = std::max(mScaleMinFloat, mScaleMaxFloat);
+    }
+
     mScaleMaxFloat = mozilla::clamped(
         mScaleMaxFloat, kViewportMinScale, kViewportMaxScale);
 
     nsAutoString scaleStr;
     GetHeaderData(nsGkAtoms::viewport_initial_scale, scaleStr);
 
     nsresult scaleErrorCode;
     mScaleFloat = LayoutDeviceToScreenScale(scaleStr.ToFloat(&scaleErrorCode));
--- a/dom/base/test/mochitest.ini
+++ b/dom/base/test/mochitest.ini
@@ -687,16 +687,17 @@ skip-if = !e10s # Track Bug 1281415
 [test_meta_viewport0.html]
 [test_meta_viewport1.html]
 [test_meta_viewport2.html]
 [test_meta_viewport3.html]
 [test_meta_viewport4.html]
 [test_meta_viewport5.html]
 [test_meta_viewport6.html]
 [test_meta_viewport7.html]
+[test_meta_viewport_maximum_scale_0.html]
 [test_mozbrowser_apis_blocked.html]
 [test_mozMatchesSelector.html]
 [test_mutationobserver_anonymous.html]
 [test_mutationobservers.html]
 [test_named_frames.html]
 [test_navigator_hardwareConcurrency.html]
 [test_navigator_language.html]
 [test_navigatorPrefOverride.html]
new file mode 100644
--- /dev/null
+++ b/dom/base/test/test_meta_viewport_maximum_scale_0.html
@@ -0,0 +1,29 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>meta viewport test</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/AddTask.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=0">
+  <script src="viewport_helpers.js"></script>
+</head>
+<body>
+  <p>width=device-width, minimum-scale=1, maximum-scale=0</p>
+  <script type="application/javascript">
+    "use strict";
+
+    add_task(async function test1() {
+      await SpecialPowers.pushPrefEnv(scaleRatio(1.0));
+
+      let info = getViewportInfo(800, 480);
+      is(info.maxZoom,     1,   "maximum_scale should be clamped");
+      is(info.defaultZoom, 1,   "initial scale should be 1");
+      is(info.minZoom,     1,   "minimum scale should be 1");
+      is(info.width,       800, "width should be 800");
+      is(info.height,      480, "height should be 480");
+    });
+  </script>
+</body>
+</html>