Bug 1501665 Part 6: Fix an edge case in Document::GetViewportInfo to return css scaled sizes. r=botond
☠☠ backed out by af46b1e88998 ☠ ☠
authorBrad Werth <bwerth@mozilla.com>
Mon, 18 Mar 2019 14:57:47 +0000
changeset 464813 9eebe767ef20b9ec635d90fc9844cf7dbe3403de
parent 464812 6a84e97d0e62839c3028a3c3ac89cd944f8e39e5
child 464814 178210eb72baa05f877b3a35e0c94d0b23880d13
push id80720
push userbwerth@mozilla.com
push dateMon, 18 Mar 2019 15:02:22 +0000
treeherderautoland@2fa518cb0dfc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1501665
milestone68.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 1501665 Part 6: Fix an edge case in Document::GetViewportInfo to return css scaled sizes. r=botond This fixes a problem in an edge case that we are evidently not testing. If width is 0 and height is auto, we are currently setting height to the unscaled (not CSS units) display height value. In addition to this fix, this patch does two drive-by cleanups of code that uses "defaultScale": The redundantly-defined defaultPixelScale is removed. The masking block-level definition of defaultScale is renamed to bestFitScale. Differential Revision: https://phabricator.services.mozilla.com/D16774
dom/base/Document.cpp
--- a/dom/base/Document.cpp
+++ b/dom/base/Document.cpp
@@ -6767,20 +6767,19 @@ nsViewportInfo Document::GetViewportInfo
       float extendZoom = ComputeExtendZoom();
 
       CSSCoord minWidth = mMinWidth;
       CSSCoord maxWidth = mMaxWidth;
       CSSCoord minHeight = mMinHeight;
       CSSCoord maxHeight = mMaxHeight;
 
       // aDisplaySize is in screen pixels; convert them to CSS pixels for the
-      // viewport size.
-      CSSToScreenScale defaultPixelScale =
-          layoutDeviceScale * LayoutDeviceToScreenScale(1.0f);
-      CSSSize displaySize = ScreenSize(aDisplaySize) / defaultPixelScale;
+      // viewport size. We need to use this scaled size for any clamping of
+      // width or height.
+      CSSSize displaySize = ScreenSize(aDisplaySize) / defaultScale;
 
       // Resolve device-width and device-height first.
       if (maxWidth == nsViewportInfo::DeviceSize) {
         maxWidth = displaySize.width;
       }
       if (maxHeight == nsViewportInfo::DeviceSize) {
         maxHeight = displaySize.height;
       }
@@ -6847,17 +6846,17 @@ nsViewportInfo Document::GetViewportInfo
           width = height * aDisplaySize.width / aDisplaySize.height;
         }
       }
 
       // Resolve height value
       // https://drafts.csswg.org/css-device-adapt/#resolve-height
       if (height == nsViewportInfo::Auto) {
         if (aDisplaySize.width == 0) {
-          height = aDisplaySize.height;
+          height = displaySize.height;
         } else {
           height = width * aDisplaySize.height / aDisplaySize.width;
         }
       }
       MOZ_ASSERT(width != nsViewportInfo::Auto &&
                  height != nsViewportInfo::Auto);
 
       CSSSize size(width, height);
@@ -6890,18 +6889,18 @@ nsViewportInfo Document::GetViewportInfo
       CSSSize effectiveMinSize = Min(CSSSize(kViewportMinSize), displaySize);
 
       size.width = clamped(size.width, effectiveMinSize.width,
                            float(kViewportMaxSize.width));
 
       // Also recalculate the default zoom, if it wasn't specified in the
       // metadata, and the width is specified.
       if (mScaleStrEmpty && !mWidthStrEmpty) {
-        CSSToScreenScale defaultScale(float(aDisplaySize.width) / size.width);
-        scaleFloat = (scaleFloat > defaultScale) ? scaleFloat : defaultScale;
+        CSSToScreenScale bestFitScale(float(aDisplaySize.width) / size.width);
+        scaleFloat = (scaleFloat > bestFitScale) ? scaleFloat : bestFitScale;
       }
 
       size.height = clamped(size.height, effectiveMinSize.height,
                             float(kViewportMaxSize.height));
 
       // We need to perform a conversion, but only if the initial or maximum
       // scale were set explicitly by the user.
       if (mValidScaleFloat && scaleFloat >= scaleMinFloat &&