Bug 1513232 - Avoid clamping the layout viewport size to be larger than the display size. r=kats, a=RyanVM
authorBotond Ballo <botond@mozilla.com>
Thu, 03 Jan 2019 05:53:52 +0000
changeset 509296 71e27c73bb26924823d74fa345a27fb243d4a0e9
parent 509295 8e9b7d32d8c8e94cde70b7f2046405c4e77dfbff
child 509297 3c697557546a791ba786a58478113d10f939c25c
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats, RyanVM
Bug 1513232 - Avoid clamping the layout viewport size to be larger than the display size. r=kats, a=RyanVM The clamping is intended to be a safeguard against extreme values in the meta viewport tag. If the layout viewport is sized to the display size, avoid the clamping, since the display size could legitimately be small (e.g. in Android 8's picture-in-picture mode). Differential Revision: https://phabricator.services.mozilla.com/D15605
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -6950,27 +6950,34 @@ nsViewportInfo nsIDocument::GetViewportI
       // FIXME: Resolving width and height should be done above 'Resolve width
       // value' and 'Resolve height value'.
       if (sizeFlag == nsViewportInfo::AutoSizeFlag::AutoSize) {
         size = displaySize;
-      size.width = clamped(size.width, float(kViewportMinSize.width),
+      // The purpose of clamping the viewport width to a minimum size is to
+      // prevent page authors from setting it to a ridiculously small value.
+      // If the page is actually being rendered in a very small area (as might
+      // happen in e.g. Android 8's picture-in-picture mode), we don't want to
+      // prevent the viewport from taking on that size.
+      CSSSize effectiveMinSize = Min(CSSSize(kViewportMinSize), displaySize);
+      size.width = clamped(size.width, effectiveMinSize.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;
-      size.height = clamped(size.height, float(kViewportMinSize.height),
+      size.height = clamped(size.height, effectiveMinSize.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 &&
           scaleFloat <= scaleMaxFloat) {
         CSSSize displaySize = ScreenSize(aDisplaySize) / scaleFloat;
         size.width = std::max(size.width, displaySize.width);