Bug 1423709 - Change boolean arguments for nsViewportInfo to enum classes. r=botond
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Tue, 20 Nov 2018 01:24:57 +0000
changeset 503607 e00d7edbb963f9d88fd4c7f477c88a5ccb04344f
parent 503606 408a5c502d131500a050ecfb929e6cf7f0e403b3
child 503608 e5485cbe65cd889b633e48405bd3525f198c477e
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1423709
milestone65.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 1423709 - Change boolean arguments for nsViewportInfo to enum classes. r=botond Differential Revision: https://phabricator.services.mozilla.com/D10194
dom/base/nsDocument.cpp
dom/base/nsViewportInfo.h
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -7313,34 +7313,34 @@ nsIDocument::GetViewportInfo(const Scree
   if (win && win->IsDesktopModeViewport() && !IsAboutPage()) {
     CSSCoord viewportWidth = gfxPrefs::DesktopViewportWidth() / fullZoom;
     CSSToScreenScale scaleToFit(aDisplaySize.width / viewportWidth);
     float aspectRatio = (float)aDisplaySize.height / aDisplaySize.width;
     CSSSize viewportSize(viewportWidth, viewportWidth * aspectRatio);
     ScreenIntSize fakeDesktopSize = RoundedToInt(viewportSize * scaleToFit);
     return nsViewportInfo(fakeDesktopSize,
                           scaleToFit,
-                          /*allowZoom*/ true);
+                          nsViewportInfo::ZoomFlag::AllowZoom);
   }
 
   if (!nsLayoutUtils::ShouldHandleMetaViewport(this)) {
     return nsViewportInfo(aDisplaySize,
                           defaultScale,
-                          /*allowZoom*/ false);
+                          nsViewportInfo::ZoomFlag::DisallowZoom);
   }
 
   // In cases where the width of the CSS viewport is less than or equal to the width
   // of the display (i.e. width <= device-width) then we disable double-tap-to-zoom
   // behaviour. See bug 941995 for details.
 
   switch (mViewportType) {
   case DisplayWidthHeight:
     return nsViewportInfo(aDisplaySize,
                           defaultScale,
-                          /*allowZoom*/ true);
+                          nsViewportInfo::ZoomFlag::AllowZoom);
   case Unknown:
   {
     nsAutoString viewport;
     GetHeaderData(nsGkAtoms::viewport, viewport);
     if (viewport.IsEmpty()) {
       // If the docType specifies that we are on a site optimized for mobile,
       // then we want to return specially crafted defaults for the viewport info.
       RefPtr<DocumentType> docType = GetDoctype();
@@ -7350,26 +7350,26 @@ nsIDocument::GetViewportInfo(const Scree
         if ((docId.Find("WAP") != -1) ||
             (docId.Find("Mobile") != -1) ||
             (docId.Find("WML") != -1))
         {
           // We're making an assumption that the docType can't change here
           mViewportType = DisplayWidthHeight;
           return nsViewportInfo(aDisplaySize,
                                 defaultScale,
-                                /*allowZoom*/true);
+                                nsViewportInfo::ZoomFlag::AllowZoom);
         }
       }
 
       nsAutoString handheldFriendly;
       GetHeaderData(nsGkAtoms::handheldFriendly, handheldFriendly);
       if (handheldFriendly.EqualsLiteral("true")) {
         mViewportType = DisplayWidthHeight;
         return nsViewportInfo(aDisplaySize, defaultScale,
-                              /*allowZoom*/true);
+                              nsViewportInfo::ZoomFlag::AllowZoom);
       }
     }
 
     nsAutoString minScaleStr;
     GetHeaderData(nsGkAtoms::viewport_minimum_scale, minScaleStr);
 
     nsresult scaleMinErrorCode;
     mScaleMinFloat = LayoutDeviceToScreenScale(minScaleStr.ToFloat(&scaleMinErrorCode));
@@ -7436,29 +7436,32 @@ nsIDocument::GetViewportInfo(const Scree
     mViewportOverflowType = ViewportOverflowType::NoOverflow;
     MOZ_FALLTHROUGH;
   }
   case Specified:
   default:
     LayoutDeviceToScreenScale effectiveMinScale = mScaleMinFloat;
     LayoutDeviceToScreenScale effectiveMaxScale = mScaleMaxFloat;
     bool effectiveValidMaxScale = mValidMaxScale;
-    bool effectiveAllowZoom = mAllowZoom;
+
+    nsViewportInfo::ZoomFlag effectiveZoomFlag =
+      mAllowZoom ? nsViewportInfo::ZoomFlag::AllowZoom
+                 : nsViewportInfo::ZoomFlag::DisallowZoom;
     if (gfxPrefs::ForceUserScalable()) {
       // If the pref to force user-scalable is enabled, we ignore the values
       // from the meta-viewport tag for these properties and just assume they
       // allow the page to be scalable. Note in particular that this code is
       // in the "Specified" branch of the enclosing switch statement, so that
       // calls to GetViewportInfo always use the latest value of the
       // ForceUserScalable pref. Other codepaths that return nsViewportInfo
       // instances are all consistent with ForceUserScalable() already.
       effectiveMinScale = kViewportMinScale;
       effectiveMaxScale = kViewportMaxScale;
       effectiveValidMaxScale = true;
-      effectiveAllowZoom = true;
+      effectiveZoomFlag = nsViewportInfo::ZoomFlag::AllowZoom;
     }
 
     // Returns extend-zoom value which is MIN(mScaleFloat, mScaleMaxFloat).
     auto ComputeExtendZoom = [&]() -> float {
       if (mValidScaleFloat && effectiveValidMaxScale) {
         return std::min(mScaleFloat.scale, effectiveMaxScale.scale);
       }
       if (mValidScaleFloat) {
@@ -7561,26 +7564,31 @@ 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;
 
-    const bool autoSize =
-      mMaxWidth == nsViewportInfo::DeviceSize ||
-      (mWidthStrEmpty &&
-       (mMaxHeight == nsViewportInfo::DeviceSize ||
-        mScaleFloat.scale == 1.0f)) ||
-      (!mWidthStrEmpty && mMaxWidth == nsViewportInfo::Auto && mMaxHeight < 0);
+    nsViewportInfo::AutoSizeFlag sizeFlag =
+      nsViewportInfo::AutoSizeFlag::FixedSize;
+    if (mMaxWidth == nsViewportInfo::DeviceSize ||
+        (mWidthStrEmpty &&
+         (mMaxHeight == nsViewportInfo::DeviceSize ||
+          mScaleFloat.scale == 1.0f)) ||
+         (!mWidthStrEmpty &&
+          mMaxWidth == nsViewportInfo::Auto &&
+          mMaxHeight < 0)) {
+      sizeFlag = nsViewportInfo::AutoSizeFlag::AutoSize;
+    }
 
     // FIXME: Resolving width and height should be done above 'Resolve width
     // value' and 'Resolve height value'.
-    if (autoSize) {
+    if (sizeFlag == nsViewportInfo::AutoSizeFlag::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) {
@@ -7598,17 +7606,18 @@ 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,
-                          autoSize, effectiveAllowZoom);
+                          sizeFlag,
+                          effectiveZoomFlag);
   }
 }
 
 void
 nsIDocument::UpdateViewportOverflowType(nscoord aScrolledWidth,
                                         nscoord aScrollportWidth)
 {
 #ifdef DEBUG
--- a/dom/base/nsViewportInfo.h
+++ b/dom/base/nsViewportInfo.h
@@ -19,44 +19,52 @@ static const mozilla::CSSIntSize kViewpo
 
 /**
  * Information retrieved from the <meta name="viewport"> tag. See
  * nsIDocument::GetViewportInfo for more information on this functionality.
  */
 class MOZ_STACK_CLASS nsViewportInfo
 {
   public:
+    enum class AutoSizeFlag {
+      AutoSize,
+      FixedSize,
+    };
+    enum class ZoomFlag {
+      AllowZoom,
+      DisallowZoom,
+    };
     nsViewportInfo(const mozilla::ScreenIntSize& aDisplaySize,
                    const mozilla::CSSToScreenScale& aDefaultZoom,
-                   bool aAllowZoom) :
+                   ZoomFlag aZoomFlag) :
       mDefaultZoom(aDefaultZoom),
       mDefaultZoomValid(true),
       mAutoSize(true),
-      mAllowZoom(aAllowZoom)
+      mAllowZoom(aZoomFlag == ZoomFlag::AllowZoom)
     {
         mSize = mozilla::ScreenSize(aDisplaySize) / mDefaultZoom;
         mozilla::CSSToLayoutDeviceScale pixelRatio(1.0f);
         mMinZoom = pixelRatio * kViewportMinScale;
         mMaxZoom = pixelRatio * kViewportMaxScale;
         ConstrainViewportValues();
     }
 
     nsViewportInfo(const mozilla::CSSToScreenScale& aDefaultZoom,
                    const mozilla::CSSToScreenScale& aMinZoom,
                    const mozilla::CSSToScreenScale& aMaxZoom,
                    const mozilla::CSSSize& aSize,
-                   bool aAutoSize,
-                   bool aAllowZoom) :
+                   AutoSizeFlag aAutoSizeFlag,
+                   ZoomFlag aZoomFlag) :
                      mDefaultZoom(aDefaultZoom),
                      mMinZoom(aMinZoom),
                      mMaxZoom(aMaxZoom),
                      mSize(aSize),
                      mDefaultZoomValid(true),
-                     mAutoSize(aAutoSize),
-                     mAllowZoom(aAllowZoom)
+                     mAutoSize(aAutoSizeFlag == AutoSizeFlag::AutoSize),
+                     mAllowZoom(aZoomFlag == ZoomFlag::AllowZoom)
     {
       ConstrainViewportValues();
     }
 
     bool IsDefaultZoomValid() const { return mDefaultZoomValid; }
     mozilla::CSSToScreenScale GetDefaultZoom() const { return mDefaultZoom; }
     mozilla::CSSToScreenScale GetMinZoom() const { return mMinZoom; }
     mozilla::CSSToScreenScale GetMaxZoom() const { return mMaxZoom; }