Bug 1501665 Part 6: Fix an edge case in Document::GetViewportInfo to return css scaled sizes. r=botond
authorBrad Werth <bwerth@mozilla.com>
Mon, 18 Mar 2019 14:57:47 +0000
changeset 464841 7d0c48d43cbd967bd70aa05fb1866571f061324f
parent 464840 05efd157254b238c0bcb14807bf8ce2ddec20250
child 464842 67b1eb6b5087063a4ea8f62ca901a8bb7297a500
push id35727
push userdvarga@mozilla.com
push dateTue, 19 Mar 2019 09:48:59 +0000
treeherdermozilla-central@70baa37ae1eb [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 &&