Bug 1500314 Part 1: Only apply mobile viewport stretching for documents with no meta viewport tag. r=botond
☠☠ backed out by 62b9000a17c1 ☠ ☠
authorBrad Werth <bwerth@mozilla.com>
Fri, 22 Mar 2019 16:46:23 +0000
changeset 465748 77cafd05c85c01998b90fac9d87e924040de1a90
parent 465747 cc78d8cad2cedab669fddcc804d6282a2af900a2
child 465749 38349ca764d764d99930bd94ae088072a4d93d1d
push id35746
push usershindli@mozilla.com
push dateSat, 23 Mar 2019 09:46:24 +0000
treeherdermozilla-central@02b7484f316b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1500314
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 1500314 Part 1: Only apply mobile viewport stretching for documents with no meta viewport tag. r=botond Differential Revision: https://phabricator.services.mozilla.com/D23531
dom/base/Document.cpp
dom/base/Document.h
--- a/dom/base/Document.cpp
+++ b/dom/base/Document.cpp
@@ -6622,17 +6622,21 @@ nsViewportInfo Document::GetViewportInfo
 
   switch (mViewportType) {
     case DisplayWidthHeight:
       return nsViewportInfo(aDisplaySize, defaultScale,
                             nsViewportInfo::ZoomFlag::AllowZoom);
     case Unknown: {
       nsAutoString viewport;
       GetHeaderData(nsGkAtoms::viewport, viewport);
-      if (viewport.IsEmpty()) {
+      // We might early exit if the viewport is empty. Even if we don't,
+      // at the end of this case we'll note that it was empty. Later, when
+      // we're using the cached values, this will trigger alternate code paths.
+      bool viewportIsEmpty = viewport.IsEmpty();
+      if (viewportIsEmpty) {
         // 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();
         if (docType) {
           nsAutoString docId;
           docType->GetPublicId(docId);
           if ((docId.Find("WAP") != -1) || (docId.Find("Mobile") != -1) ||
@@ -6716,21 +6720,22 @@ nsViewportInfo Document::GetViewportInfo
       }
 
       mScaleStrEmpty = scaleStr.IsEmpty();
       mWidthStrEmpty = widthStr.IsEmpty();
       mValidScaleFloat = !scaleStr.IsEmpty() && NS_SUCCEEDED(scaleErrorCode);
       mValidMaxScale =
           !maxScaleStr.IsEmpty() && NS_SUCCEEDED(scaleMaxErrorCode);
 
-      mViewportType = Specified;
+      mViewportType = viewportIsEmpty ? Empty : Specified;
       mViewportOverflowType = ViewportOverflowType::NoOverflow;
       MOZ_FALLTHROUGH;
     }
     case Specified:
+    case Empty:
     default:
       LayoutDeviceToScreenScale effectiveMinScale = mScaleMinFloat;
       LayoutDeviceToScreenScale effectiveMaxScale = mScaleMaxFloat;
       bool effectiveValidMaxScale = mValidMaxScale;
 
       nsViewportInfo::ZoomFlag effectiveZoomFlag =
           mAllowZoom ? nsViewportInfo::ZoomFlag::AllowZoom
                      : nsViewportInfo::ZoomFlag::DisallowZoom;
@@ -6825,28 +6830,38 @@ nsViewportInfo Document::GetViewportInfo
         height = nsViewportInfo::Max(
             minHeight, nsViewportInfo::Min(maxHeight, displaySize.height));
       }
 
       // Resolve width value
       // https://drafts.csswg.org/css-device-adapt/#resolve-width
       if (width == nsViewportInfo::Auto) {
         if (height == nsViewportInfo::Auto || aDisplaySize.height == 0) {
-          // If we don't have any applicable viewport width constraints, this is
-          // most likely a desktop page written without mobile devices in mind.
-          // We use the desktop mode viewport for those pages by default,
-          // because a narrow viewport based on typical mobile device screen
-          // sizes (especially in portrait mode) will frequently break the
-          // layout of such pages. To keep text readable in that case, we rely
-          // on font inflation instead.
-
-          // Divide by fullZoom to stretch CSS pixel size of viewport in order
-          // to keep device pixel size unchanged after full zoom applied.
-          // See bug 974242.
-          width = gfxPrefs::DesktopViewportWidth() / fullZoom;
+          // What we do in this situation deviates somewhat from the spec. We
+          // want to consider the case where no viewport information has been
+          // provided, in which case we want to assume that the document is not
+          // optimized for aDisplaySize, and we should instead force a useful
+          // size.
+          if (mViewportType == Empty) {
+            // If we don't have any applicable viewport width constraints, this
+            // is most likely a desktop page written without mobile devices in
+            // mind. We use the desktop mode viewport for those pages by
+            // default, because a narrow viewport based on typical mobile device
+            // screen sizes (especially in portrait mode) will frequently break
+            // the layout of such pages. To keep text readable in that case, we
+            // rely on font inflation instead.
+
+            // Divide by fullZoom to stretch CSS pixel size of viewport in order
+            // to keep device pixel size unchanged after full zoom applied.
+            // See bug 974242.
+            width = gfxPrefs::DesktopViewportWidth() / fullZoom;
+          } else {
+            // Some viewport information was provided; follow the spec.
+            width = displaySize.width;
+          }
         } else {
           width = height * aDisplaySize.width / aDisplaySize.height;
         }
       }
 
       // Resolve height value
       // https://drafts.csswg.org/css-device-adapt/#resolve-height
       if (height == nsViewportInfo::Auto) {
--- a/dom/base/Document.h
+++ b/dom/base/Document.h
@@ -4475,17 +4475,17 @@ class Document : public nsINode,
   // Weak reference to our sink for in case we no longer have a parser.  This
   // will allow us to flush out any pending stuff from the sink even if
   // EndLoad() has already happened.
   nsWeakPtr mWeakSink;
 
   // Our update nesting level
   uint32_t mUpdateNestLevel;
 
-  enum ViewportType : uint8_t { DisplayWidthHeight, Specified, Unknown };
+  enum ViewportType : uint8_t { DisplayWidthHeight, Specified, Unknown, Empty };
 
   ViewportType mViewportType;
 
   // Enum for how content in this document overflows viewport causing
   // out-of-reach issue. Currently it only takes horizontal overflow
   // into consideration. This enum and the corresponding field is only
   // set and read on a top level content document.
   enum class ViewportOverflowType : uint8_t {