Bug 1525662 - Part 3: Provide a hook for treating missing viewport specification as an explicit "width=device-width". r=botond
authorJan Henning <jh+bugzilla@buttercookie.de>
Sun, 24 Feb 2019 14:55:02 +0100
changeset 522003 7b61f5d7f7d2
parent 522002 dc422efc3103
child 522004 60e8006f70d2
push id10870
push usernbeleuzu@mozilla.com
push dateFri, 15 Mar 2019 20:00:07 +0000
treeherdermozilla-beta@c594aee5b7a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1525662
milestone67.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 1525662 - Part 3: Provide a hook for treating missing viewport specification as an explicit "width=device-width". r=botond Ordinarily, when a page doesn't explicitly specify its viewport dimensions using a <meta> viewport tag, we treat is as a non-mobile-friendly desktop page and do some special viewport handling. For some document types however we might want to override that behaviour and treat the page as if "<meta name="viewport" content="width=device-width>" had explicitly been specified anyway. Differential Revision: https://phabricator.services.mozilla.com/D20953
dom/base/Document.cpp
dom/base/Document.h
--- a/dom/base/Document.cpp
+++ b/dom/base/Document.cpp
@@ -6509,16 +6509,18 @@ nsINode* Document::AdoptNode(nsINode& aA
   }
 
   NS_ASSERTION(adoptedNode->OwnerDoc() == this,
                "Should still be in the document we just got adopted into");
 
   return adoptedNode;
 }
 
+bool Document::UseWidthDeviceWidthFallbackViewport() const { return false; }
+
 void Document::ParseWidthAndHeightInMetaViewport(
     const nsAString& aWidthString, const nsAString& aHeightString,
     const nsAString& aScaleString) {
   // The width and height properties
   // https://drafts.csswg.org/css-device-adapt/#width-and-height-properties
   //
   // The width and height viewport <META> properties are translated into width
   // and height descriptors, setting the min-width/min-height value to
@@ -6548,16 +6550,19 @@ void Document::ParseWidthAndHeightInMeta
       }
     }
     // FIXME: Check the scale is not 'auto' once we support auto value for it.
   } else if (!aScaleString.IsEmpty()) {
     if (aHeightString.IsEmpty()) {
       mMinWidth = nsViewportInfo::ExtendToZoom;
       mMaxWidth = nsViewportInfo::ExtendToZoom;
     }
+  } else if (aHeightString.IsEmpty() && UseWidthDeviceWidthFallbackViewport()) {
+    mMinWidth = nsViewportInfo::ExtendToZoom;
+    mMaxWidth = nsViewportInfo::DeviceSize;
   }
 
   mMinHeight = nsViewportInfo::Auto;
   mMaxHeight = nsViewportInfo::Auto;
   if (!aHeightString.IsEmpty()) {
     mMinHeight = nsViewportInfo::ExtendToZoom;
     if (aHeightString.EqualsLiteral("device-height")) {
       mMaxHeight = nsViewportInfo::DeviceSize;
--- a/dom/base/Document.h
+++ b/dom/base/Document.h
@@ -3600,16 +3600,23 @@ class Document : public nsINode,
    * This method is virtual so that XULDocument can
    * override it.
    */
   virtual void InitialDocumentTranslationCompleted();
 
  protected:
   RefPtr<mozilla::dom::DocumentL10n> mDocumentL10n;
 
+  /**
+   * Return true when you want a document without explicitly specified viewport
+   * dimensions/scale to be treated as if "width=device-width" had in fact been
+   * specified.
+   */
+  virtual bool UseWidthDeviceWidthFallbackViewport() const;
+
  private:
   void InitializeLocalization(nsTArray<nsString>& aResourceIds);
 
   void ParseWidthAndHeightInMetaViewport(const nsAString& aWidthString,
                                          const nsAString& aHeightString,
                                          const nsAString& aScaleString);
 
   mozilla::dom::FlashClassification DocumentFlashClassificationInternal();