Bug 1501106 - Drop nsIDocument::mAutoSize and relevant members. r=botond
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Wed, 24 Oct 2018 21:43:50 +0000
changeset 491228 40b1b00e610a2db492b645184336bc2097c0cd28
parent 491227 e46f20ef7d4c30d84f3ad8feccd2e33d60e0c989
child 491229 418b398baaeeb9e9b5652f0be376aa07bfe3f769
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersbotond
bugs1501106
milestone65.0a1
Bug 1501106 - Drop nsIDocument::mAutoSize and relevant members. r=botond I guess we can eventually replace the conditions for autoSize with `width == nsViewportInfo::Auto` or `height == nsViewportInfo::Auto`, but it will break current behavior so for now we are going to preserve the current behavior. For example, we currently consider no viewport meta tag means autoSize is disabled but it should be an autoSize case. Depends on D9461 Differential Revision: https://phabricator.services.mozilla.com/D9462
dom/base/nsDocument.cpp
dom/base/nsIDocument.h
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -1439,19 +1439,16 @@ nsIDocument::nsIDocument()
     mDOMCompleteSet(false),
     mAutoFocusFired(false),
     mScrolledToRefAlready(false),
     mChangeScrollPosWhenScrollingToRef(false),
     mHasWarnedAboutBoxObjects(false),
     mDelayFrameLoaderInitialization(false),
     mSynchronousDOMContentLoaded(false),
     mMaybeServiceWorkerControlled(false),
-    mValidWidth(false),
-    mValidHeight(false),
-    mAutoSize(false),
     mAllowZoom(false),
     mValidScaleFloat(false),
     mValidMaxScale(false),
     mScaleStrEmpty(false),
     mWidthStrEmpty(false),
     mParserAborted(false),
     mReportedUseCounters(false),
     mHasReportedShadowDOMUsage(false),
@@ -7432,38 +7429,16 @@ nsIDocument::GetViewportInfo(const Scree
 
     GetHeaderData(nsGkAtoms::viewport_height, heightStr);
     GetHeaderData(nsGkAtoms::viewport_width, widthStr);
 
     // Parse width and height properties
     // This function sets m{Min,Max}{Width,Height}.
     ParseWidthAndHeightInMetaViewport(widthStr, heightStr, scaleStr);
 
-    mAutoSize = false;
-    if (mMaxWidth == nsViewportInfo::DeviceSize) {
-      mAutoSize = true;
-    }
-    if (widthStr.IsEmpty() &&
-        (mMaxHeight == nsViewportInfo::DeviceSize ||
-         (mScaleFloat.scale == 1.0)))
-    {
-      mAutoSize = true;
-    }
-
-    // If width or height has not been set to a valid number by this point,
-    // fall back to a default value.
-    mValidWidth = (!widthStr.IsEmpty() && mMaxWidth > 0);
-    mValidHeight = (!heightStr.IsEmpty() && mMaxHeight > 0);
-
-    // If the width is set to some unrecognized value, and there is no
-    // height set, treat it as if device-width were specified.
-    if ((!mValidWidth && !widthStr.IsEmpty()) && !mValidHeight) {
-      mAutoSize = true;
-    }
-
     mAllowZoom = true;
     nsAutoString userScalable;
     GetHeaderData(nsGkAtoms::viewport_user_scalable, userScalable);
 
     if ((userScalable.EqualsLiteral("0")) ||
         (userScalable.EqualsLiteral("no")) ||
         (userScalable.EqualsLiteral("false"))) {
       mAllowZoom = false;
@@ -7603,17 +7578,26 @@ nsIDocument::GetViewportInfo(const Scree
     MOZ_ASSERT(width != nsViewportInfo::Auto && height != nsViewportInfo::Auto);
 
     CSSSize size(width, height);
 
     CSSToScreenScale scaleFloat = mScaleFloat * layoutDeviceScale;
     CSSToScreenScale scaleMinFloat = effectiveMinScale * layoutDeviceScale;
     CSSToScreenScale scaleMaxFloat = effectiveMaxScale * layoutDeviceScale;
 
-    if (mAutoSize) {
+    const bool autoSize =
+      mMaxWidth == nsViewportInfo::DeviceSize ||
+      (mWidthStrEmpty &&
+       (mMaxHeight == nsViewportInfo::DeviceSize ||
+        mScaleFloat.scale == 1.0f)) ||
+      (!mWidthStrEmpty && mMaxWidth == nsViewportInfo::Auto && mMaxHeight < 0);
+
+    // FIXME: Resolving width and height should be done above 'Resolve width
+    // value' and 'Resolve height value'.
+    if (autoSize) {
       size = displaySize;
     }
 
     size.width = clamped(size.width, float(kViewportMinSize.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) {
@@ -7631,17 +7615,17 @@ nsIDocument::GetViewportInfo(const Scree
       size.height = std::max(size.height, displaySize.height);
     } else if (effectiveValidMaxScale) {
       CSSSize displaySize = ScreenSize(aDisplaySize) / scaleMaxFloat;
       size.width = std::max(size.width, displaySize.width);
       size.height = std::max(size.height, displaySize.height);
     }
 
     return nsViewportInfo(scaleFloat, scaleMinFloat, scaleMaxFloat, size,
-                          mAutoSize, effectiveAllowZoom);
+                          autoSize, effectiveAllowZoom);
   }
 }
 
 void
 nsIDocument::UpdateViewportOverflowType(nscoord aScrolledWidth,
                                         nscoord aScrollportWidth)
 {
 #ifdef DEBUG
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -4313,19 +4313,16 @@ protected:
   bool mSynchronousDOMContentLoaded: 1;
 
   // Set to true when the document is possibly controlled by the ServiceWorker.
   // Used to prevent multiple requests to ServiceWorkerManager.
   bool mMaybeServiceWorkerControlled: 1;
 
   // These member variables cache information about the viewport so we don't
   // have to recalculate it each time.
-  bool mValidWidth: 1;
-  bool mValidHeight: 1;
-  bool mAutoSize: 1;
   bool mAllowZoom: 1;
   bool mValidScaleFloat: 1;
   bool mValidMaxScale: 1;
   bool mScaleStrEmpty: 1;
   bool mWidthStrEmpty: 1;
 
   // Parser aborted. True if the parser of this document was forcibly
   // terminated instead of letting it finish at its own pace.