Add a mechanism to opt-out of the automatic scaling applied to not-really-responsive...
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 May 2015 20:42:49 +0000 (20:42 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 May 2015 20:42:49 +0000 (20:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=144760

Reviewed by Darin Adler.

Add a new viewport property, shrink-to-fit, which can be used to disable
the automatic scaling introduced in r181400. This provides sites with a
way to tell WebKit that they're really sure they want to be laid out at
window-width/height, even if they fail to fit within that size.

* dom/ViewportArguments.cpp:
(WebCore::ViewportArguments::resolve):
(WebCore::findBooleanValue):
(WebCore::setViewportFeature):
* dom/ViewportArguments.h:
(WebCore::ViewportArguments::ViewportArguments):
(WebCore::ViewportArguments::operator==):
* page/ViewportConfiguration.cpp:
(WebCore::ViewportConfiguration::shouldIgnoreHorizontalScalingConstraints):
(WebCore::ViewportConfiguration::shouldIgnoreVerticalScalingConstraints):
(WebCore::ViewportConfiguration::webpageParameters):
(WebCore::ViewportConfiguration::textDocumentParameters):
(WebCore::ViewportConfiguration::imageDocumentParameters):
(WebCore::ViewportConfiguration::testingParameters):
(WebCore::booleanViewportArgumentIsSet):
(WebCore::ViewportConfiguration::updateConfiguration):
(WebCore::ViewportConfigurationTextStream::operator<<):
(WebCore::viewportArgumentUserZoomIsSet): Deleted.
* page/ViewportConfiguration.h:
(WebCore::ViewportConfiguration::Parameters::Parameters):
Plumb the shrink-to-fit viewport property through.
If shrink-to-fit is set to yes, or not set, we behave as usual; if it is
set to no, we will bail from shouldIgnore[Horizontal|Vertical]ScalingConstraints,
effectively disabling the automatic scaling introduced in r181400.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@184654 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/dom/ViewportArguments.cpp
Source/WebCore/dom/ViewportArguments.h
Source/WebCore/page/ViewportConfiguration.cpp
Source/WebCore/page/ViewportConfiguration.h

index 764c150f411078bcb24b6356d30d4a9d444dc60d..e94728c0686fdb6353fb06a23b6947d87161782f 100644 (file)
@@ -1,3 +1,40 @@
+2015-05-20  Tim Horton  <timothy_horton@apple.com>
+
+        Add a mechanism to opt-out of the automatic scaling applied to not-really-responsive sites
+        https://bugs.webkit.org/show_bug.cgi?id=144760
+
+        Reviewed by Darin Adler.
+
+        Add a new viewport property, shrink-to-fit, which can be used to disable
+        the automatic scaling introduced in r181400. This provides sites with a
+        way to tell WebKit that they're really sure they want to be laid out at
+        window-width/height, even if they fail to fit within that size.
+
+        * dom/ViewportArguments.cpp:
+        (WebCore::ViewportArguments::resolve):
+        (WebCore::findBooleanValue):
+        (WebCore::setViewportFeature):
+        * dom/ViewportArguments.h:
+        (WebCore::ViewportArguments::ViewportArguments):
+        (WebCore::ViewportArguments::operator==):
+        * page/ViewportConfiguration.cpp:
+        (WebCore::ViewportConfiguration::shouldIgnoreHorizontalScalingConstraints):
+        (WebCore::ViewportConfiguration::shouldIgnoreVerticalScalingConstraints):
+        (WebCore::ViewportConfiguration::webpageParameters):
+        (WebCore::ViewportConfiguration::textDocumentParameters):
+        (WebCore::ViewportConfiguration::imageDocumentParameters):
+        (WebCore::ViewportConfiguration::testingParameters):
+        (WebCore::booleanViewportArgumentIsSet):
+        (WebCore::ViewportConfiguration::updateConfiguration):
+        (WebCore::ViewportConfigurationTextStream::operator<<):
+        (WebCore::viewportArgumentUserZoomIsSet): Deleted.
+        * page/ViewportConfiguration.h:
+        (WebCore::ViewportConfiguration::Parameters::Parameters):
+        Plumb the shrink-to-fit viewport property through.
+        If shrink-to-fit is set to yes, or not set, we behave as usual; if it is
+        set to no, we will bail from shouldIgnore[Horizontal|Vertical]ScalingConstraints,
+        effectively disabling the automatic scaling introduced in r181400.
+
 2015-05-20  Antti Koivisto  <antti@apple.com>
 
         Assertion failure in WebCore::BidiRun::BidiRun()
index 0e124b1e1efbe18dc12eb8794cb4e55e78e91914..cc841648bfd0faf54a6e39c56778164fa859e05f 100644 (file)
@@ -86,7 +86,6 @@ ViewportAttributes ViewportArguments::resolve(const FloatSize& initialViewportSi
     float resultZoom = zoom;
     float resultMinZoom = minZoom;
     float resultMaxZoom = maxZoom;
-    float resultUserZoom = userZoom;
 
     switch (int(resultWidth)) {
     case ViewportArguments::ValueDeviceWidth:
@@ -244,8 +243,9 @@ ViewportAttributes ViewportArguments::resolve(const FloatSize& initialViewportSi
     // if (resultZoom == ViewportArguments::ValueAuto)
     //    result.initialScale = ViewportArguments::ValueAuto;
 
-    result.userScalable = resultUserZoom;
+    result.userScalable = userZoom;
     result.orientation = orientation;
+    result.shrinkToFit = shrinkToFit;
 
     return result;
 }
@@ -354,7 +354,7 @@ static float findScaleValue(const String& keyString, const String& valueString,
     return value;
 }
 
-static float findUserScalableValue(const String& keyString, const String& valueString, Document* document)
+static float findBooleanValue(const String& keyString, const String& valueString, Document* document)
 {
     // yes and no are used as keywords.
     // Numbers >= 1, numbers <= -1, device-width and device-height are mapped to yes.
@@ -392,12 +392,14 @@ void setViewportFeature(const String& keyString, const String& valueString, Docu
     else if (keyString == "maximum-scale")
         arguments->maxZoom = findScaleValue(keyString, valueString, document);
     else if (keyString == "user-scalable")
-        arguments->userZoom = findUserScalableValue(keyString, valueString, document);
+        arguments->userZoom = findBooleanValue(keyString, valueString, document);
 #if PLATFORM(IOS)
     else if (keyString == "minimal-ui")
-        // FIXME: Ignore silently for now. This should eventually fallback to the warning.
+        // FIXME: Ignore silently for now. This should eventually fall back to the warning.
         { }
 #endif
+    else if (keyString == "shrink-to-fit")
+        arguments->shrinkToFit = findBooleanValue(keyString, valueString, document);
     else
         reportViewportWarning(document, UnrecognizedViewportArgumentKeyError, keyString, String());
 }
index 9179d91252474297c9708d2c4a0faf054f1a2a8b..1d641d393e49336d50fc2ccb67b8124aad95fdc0 100644 (file)
@@ -51,6 +51,7 @@ struct ViewportAttributes {
 
     float userScalable;
     float orientation;
+    float shrinkToFit;
 };
 
 struct ViewportArguments {
@@ -76,34 +77,24 @@ struct ViewportArguments {
 
     explicit ViewportArguments(Type type = Implicit)
         : type(type)
-        , width(ValueAuto)
-        , minWidth(ValueAuto)
-        , maxWidth(ValueAuto)
-        , height(ValueAuto)
-        , minHeight(ValueAuto)
-        , maxHeight(ValueAuto)
-        , zoom(ValueAuto)
-        , minZoom(ValueAuto)
-        , maxZoom(ValueAuto)
-        , userZoom(ValueAuto)
-        , orientation(ValueAuto)
     {
     }
 
     // All arguments are in CSS units.
     ViewportAttributes resolve(const FloatSize& initialViewportSize, const FloatSize& deviceSize, int defaultWidth) const;
 
-    float width;
-    float minWidth;
-    float maxWidth;
-    float height;
-    float minHeight;
-    float maxHeight;
-    float zoom;
-    float minZoom;
-    float maxZoom;
-    float userZoom;
-    float orientation;
+    float width { ValueAuto };
+    float minWidth { ValueAuto };
+    float maxWidth { ValueAuto };
+    float height { ValueAuto };
+    float minHeight { ValueAuto };
+    float maxHeight { ValueAuto };
+    float zoom { ValueAuto };
+    float minZoom { ValueAuto };
+    float maxZoom { ValueAuto };
+    float userZoom { ValueAuto };
+    float orientation { ValueAuto };
+    float shrinkToFit { ValueAuto };
 
     bool operator==(const ViewportArguments& other) const
     {
@@ -119,7 +110,8 @@ struct ViewportArguments {
             && minZoom == other.minZoom
             && maxZoom == other.maxZoom
             && userZoom == other.userZoom
-            && orientation == other.orientation;
+            && orientation == other.orientation
+            && shrinkToFit == other.shrinkToFit;
     }
 
     bool operator!=(const ViewportArguments& other) const
index 0a33dd8b06b6e02a093d06687f7d14c953d44ea5..48d3d43ba0c7ea93c3f9b1b3a4c1b063459fe9d0 100644 (file)
@@ -103,6 +103,9 @@ bool ViewportConfiguration::shouldIgnoreHorizontalScalingConstraints() const
     if (!m_canIgnoreScalingConstraints)
         return false;
 
+    if (!m_configuration.allowsShrinkToFit)
+        return false;
+
     bool laidOutWiderThanViewport = m_contentSize.width() > layoutWidth();
     if (m_viewportArguments.width == ViewportArguments::ValueDeviceWidth)
         return laidOutWiderThanViewport;
@@ -118,6 +121,9 @@ bool ViewportConfiguration::shouldIgnoreVerticalScalingConstraints() const
     if (!m_canIgnoreScalingConstraints)
         return false;
 
+    if (!m_configuration.allowsShrinkToFit)
+        return false;
+
     bool laidOutTallerThanViewport = m_contentSize.height() > layoutHeight();
     if (m_viewportArguments.height == ViewportArguments::ValueDeviceHeight && m_viewportArguments.width == ViewportArguments::ValueAuto)
         return laidOutTallerThanViewport;
@@ -188,6 +194,7 @@ ViewportConfiguration::Parameters ViewportConfiguration::webpageParameters()
     parameters.width = 980;
     parameters.widthIsSet = true;
     parameters.allowsUserScaling = true;
+    parameters.allowsShrinkToFit = true;
     parameters.minimumScale = 0.25;
     parameters.maximumScale = 5;
     return parameters;
@@ -206,6 +213,7 @@ ViewportConfiguration::Parameters ViewportConfiguration::textDocumentParameters(
 
     parameters.widthIsSet = true;
     parameters.allowsUserScaling = true;
+    parameters.allowsShrinkToFit = false;
     parameters.minimumScale = 0.25;
     parameters.maximumScale = 5;
     return parameters;
@@ -217,6 +225,7 @@ ViewportConfiguration::Parameters ViewportConfiguration::imageDocumentParameters
     parameters.width = 980;
     parameters.widthIsSet = true;
     parameters.allowsUserScaling = true;
+    parameters.allowsShrinkToFit = false;
     parameters.minimumScale = 0.01;
     parameters.maximumScale = 5;
     return parameters;
@@ -234,6 +243,7 @@ ViewportConfiguration::Parameters ViewportConfiguration::testingParameters()
     Parameters parameters;
     parameters.initialScale = 1;
     parameters.initialScaleIsSet = true;
+    parameters.allowsShrinkToFit = true;
     parameters.minimumScale = 1;
     parameters.maximumScale = 5;
     return parameters;
@@ -261,7 +271,7 @@ static inline void applyViewportArgument(ValueType& value, bool& valueIsSet, Vie
         valueIsSet = false;
 }
 
-static inline bool viewportArgumentUserZoomIsSet(float value)
+static inline bool booleanViewportArgumentIsSet(float value)
 {
     return !value || value == 1;
 }
@@ -292,8 +302,11 @@ void ViewportConfiguration::updateConfiguration()
         m_configuration.heightIsSet = viewportArgumentsOverridesHeight;
     }
 
-    if (viewportArgumentUserZoomIsSet(m_viewportArguments.userZoom))
+    if (booleanViewportArgumentIsSet(m_viewportArguments.userZoom))
         m_configuration.allowsUserScaling = m_viewportArguments.userZoom != 0.;
+
+    if (booleanViewportArgumentIsSet(m_viewportArguments.shrinkToFit))
+        m_configuration.allowsShrinkToFit = m_viewportArguments.shrinkToFit != 0.;
 }
 
 double ViewportConfiguration::viewportArgumentsLength(double length) const
@@ -437,6 +450,7 @@ ViewportConfigurationTextStream& ViewportConfigurationTextStream::operator<<(con
     dumpProperty(ts, "minimumScale", parameters.minimumScale);
     dumpProperty(ts, "maximumScale", parameters.maximumScale);
     dumpProperty(ts, "allowsUserScaling", parameters.allowsUserScaling);
+    dumpProperty(ts, "allowsShrinkToFit", parameters.allowsShrinkToFit);
 
     return ts;
 }
index cbd0642456d42e9535612df5c987b0be123c8458..207de267e0a3846e43efa9dd2779939bd689f016 100644 (file)
@@ -45,6 +45,7 @@ public:
             , minimumScale(0)
             , maximumScale(0)
             , allowsUserScaling(false)
+            , allowsShrinkToFit(false)
             , widthIsSet(false)
             , heightIsSet(false)
             , initialScaleIsSet(false)
@@ -57,6 +58,7 @@ public:
         double minimumScale;
         double maximumScale;
         bool allowsUserScaling;
+        bool allowsShrinkToFit;
 
         bool widthIsSet;
         bool heightIsSet;
@@ -85,6 +87,7 @@ public:
     WEBCORE_EXPORT double minimumScale() const;
     double maximumScale() const { return m_configuration.maximumScale; }
     WEBCORE_EXPORT bool allowsUserScaling() const;
+    bool allowsShrinkToFit() const;
 
     WEBCORE_EXPORT static Parameters webpageParameters();
     WEBCORE_EXPORT static Parameters textDocumentParameters();
@@ -96,7 +99,7 @@ public:
     WTF::CString description() const;
     void dump() const;
 #endif
-    
+
 private:
     void updateConfiguration();
     double viewportArgumentsLength(double length) const;