Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(597)

Unified Diff: Source/core/dom/ViewportArguments.cpp

Issue 23742003: Use css-device-adapt constraining for legacy viewport tags. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/dom/ViewportArguments.cpp
diff --git a/Source/core/dom/ViewportArguments.cpp b/Source/core/dom/ViewportArguments.cpp
index 0a2708dd1f07b1b02f760d61f5acb4d501683393..ba0098d4816bb2f5468e9deb2e5b2b13f2bacda4 100644
--- a/Source/core/dom/ViewportArguments.cpp
+++ b/Source/core/dom/ViewportArguments.cpp
@@ -48,9 +48,6 @@ static const float& compareIgnoringAuto(const float& value1, const float& value2
static inline float clampLengthValue(float value)
{
- ASSERT(value != ViewportArguments::ValueDeviceWidth);
- ASSERT(value != ViewportArguments::ValueDeviceHeight);
-
// Limits as defined in the css-device-adapt spec.
if (value != ViewportArguments::ValueAuto)
return min(float(10000), max(value, float(1)));
@@ -59,21 +56,18 @@ static inline float clampLengthValue(float value)
static inline float clampScaleValue(float value)
{
- ASSERT(value != ViewportArguments::ValueDeviceWidth);
- ASSERT(value != ViewportArguments::ValueDeviceHeight);
-
// Limits as defined in the css-device-adapt spec.
if (value != ViewportArguments::ValueAuto)
return min(float(10), max(value, float(0.1)));
return value;
}
-PageScaleConstraints ViewportArguments::resolve(const FloatSize& initialViewportSize, int defaultWidth) const
+PageScaleConstraints ViewportArguments::resolve(const FloatSize& initialViewportSize) const
{
- float resultWidth = width;
+ float resultWidth = ValueAuto;
float resultMaxWidth = maxWidth;
float resultMinWidth = minWidth;
- float resultHeight = height;
+ float resultHeight = ValueAuto;
float resultMinHeight = minHeight;
float resultMaxHeight = maxHeight;
@@ -82,180 +76,105 @@ PageScaleConstraints ViewportArguments::resolve(const FloatSize& initialViewport
float resultMaxZoom = maxZoom;
float resultUserZoom = userZoom;
- if (type == ViewportArguments::CSSDeviceAdaptation) {
-
- // device-width/device-height not supported for @viewport.
- ASSERT(resultMinWidth != ViewportArguments::ValueDeviceWidth);
- ASSERT(resultMinWidth != ViewportArguments::ValueDeviceHeight);
- ASSERT(resultMaxWidth != ViewportArguments::ValueDeviceWidth);
- ASSERT(resultMaxWidth != ViewportArguments::ValueDeviceHeight);
- ASSERT(resultMinHeight != ViewportArguments::ValueDeviceWidth);
- ASSERT(resultMinHeight != ViewportArguments::ValueDeviceHeight);
- ASSERT(resultMaxHeight != ViewportArguments::ValueDeviceWidth);
- ASSERT(resultMaxHeight != ViewportArguments::ValueDeviceHeight);
+ if (resultMaxWidth == ValueDeviceWidth)
+ resultMaxWidth = initialViewportSize.width();
+ else if (resultMaxWidth == ValueDeviceHeight)
+ resultMaxWidth = initialViewportSize.height();
- // 1. Resolve min-zoom and max-zoom values.
- if (resultMinZoom != ViewportArguments::ValueAuto && resultMaxZoom != ViewportArguments::ValueAuto)
- resultMaxZoom = max(resultMinZoom, resultMaxZoom);
+ if (resultMaxHeight == ValueDeviceWidth)
+ resultMaxHeight = initialViewportSize.width();
+ else if (resultMaxHeight == ValueDeviceHeight)
+ resultMaxHeight = initialViewportSize.height();
- // 2. Constrain zoom value to the [min-zoom, max-zoom] range.
- if (resultZoom != ViewportArguments::ValueAuto)
- resultZoom = compareIgnoringAuto(resultMinZoom, compareIgnoringAuto(resultMaxZoom, resultZoom, min), max);
+ // 1. Resolve min-zoom and max-zoom values.
+ if (resultMinZoom != ViewportArguments::ValueAuto && resultMaxZoom != ViewportArguments::ValueAuto)
+ resultMaxZoom = max(resultMinZoom, resultMaxZoom);
- float extendZoom = compareIgnoringAuto(resultZoom, resultMaxZoom, min);
+ // 2. Constrain zoom value to the [min-zoom, max-zoom] range.
+ if (resultZoom != ViewportArguments::ValueAuto)
+ resultZoom = compareIgnoringAuto(resultMinZoom, compareIgnoringAuto(resultMaxZoom, resultZoom, min), max);
- if (extendZoom == ViewportArguments::ValueAuto) {
- if (resultMaxWidth == ViewportArguments::ValueExtendToZoom)
- resultMaxWidth = ViewportArguments::ValueAuto;
+ float extendZoom = compareIgnoringAuto(resultZoom, resultMaxZoom, min);
- if (resultMaxHeight == ViewportArguments::ValueExtendToZoom)
- resultMaxHeight = ViewportArguments::ValueAuto;
+ // 3. Resolve non-"auto" lengths to pixel lengths.
kenneth.r.christiansen 2013/09/02 09:14:16 So all this is the same as in my patch?
rune 2013/09/02 11:29:30 I have not actually diffed - can do that. I did no
+ if (extendZoom == ViewportArguments::ValueAuto) {
+ if (resultMaxWidth == ViewportArguments::ValueExtendToZoom)
+ resultMaxWidth = ViewportArguments::ValueAuto;
- if (resultMinWidth == ViewportArguments::ValueExtendToZoom)
- resultMinWidth = resultMaxWidth;
+ if (resultMaxHeight == ViewportArguments::ValueExtendToZoom)
+ resultMaxHeight = ViewportArguments::ValueAuto;
- if (resultMinHeight == ViewportArguments::ValueExtendToZoom)
- resultMinHeight = resultMaxHeight;
- } else {
- float extendWidth = initialViewportSize.width() / extendZoom;
- float extendHeight = initialViewportSize.height() / extendZoom;
+ if (resultMinWidth == ViewportArguments::ValueExtendToZoom)
+ resultMinWidth = resultMaxWidth;
- if (resultMaxWidth == ViewportArguments::ValueExtendToZoom)
- resultMaxWidth = extendWidth;
+ if (resultMinHeight == ViewportArguments::ValueExtendToZoom)
+ resultMinHeight = resultMaxHeight;
+ } else {
+ float extendWidth = initialViewportSize.width() / extendZoom;
+ float extendHeight = initialViewportSize.height() / extendZoom;
- if (resultMaxHeight == ViewportArguments::ValueExtendToZoom)
- resultMaxHeight = extendHeight;
-
- if (resultMinWidth == ViewportArguments::ValueExtendToZoom)
- resultMinWidth = compareIgnoringAuto(extendWidth, resultMaxWidth, max);
-
- if (resultMinHeight == ViewportArguments::ValueExtendToZoom)
- resultMinHeight = compareIgnoringAuto(extendHeight, resultMaxHeight, max);
- }
+ if (resultMaxWidth == ViewportArguments::ValueExtendToZoom)
+ resultMaxWidth = extendWidth;
- // 4. Resolve initial width from min/max descriptors.
- if (resultMinWidth != ViewportArguments::ValueAuto || resultMaxWidth != ViewportArguments::ValueAuto)
- resultWidth = compareIgnoringAuto(resultMinWidth, compareIgnoringAuto(resultMaxWidth, initialViewportSize.width(), min), max);
+ if (resultMaxHeight == ViewportArguments::ValueExtendToZoom)
+ resultMaxHeight = extendHeight;
- // 5. Resolve initial height from min/max descriptors.
- if (resultMinHeight != ViewportArguments::ValueAuto || resultMaxHeight != ViewportArguments::ValueAuto)
- resultHeight = compareIgnoringAuto(resultMinHeight, compareIgnoringAuto(resultMaxHeight, initialViewportSize.height(), min), max);
+ if (resultMinWidth == ViewportArguments::ValueExtendToZoom)
+ resultMinWidth = compareIgnoringAuto(extendWidth, resultMaxWidth, max);
- // 6-7. Resolve width value.
- if (resultWidth == ViewportArguments::ValueAuto) {
- if (resultHeight == ViewportArguments::ValueAuto || !initialViewportSize .height())
- resultWidth = initialViewportSize.width();
- else
- resultWidth = resultHeight * (initialViewportSize.width() / initialViewportSize.height());
- }
-
- // 8. Resolve height value.
- if (resultHeight == ViewportArguments::ValueAuto) {
- if (!initialViewportSize.width())
- resultHeight = initialViewportSize.height();
- else
- resultHeight = resultWidth * initialViewportSize.height() / initialViewportSize.width();
- }
-
- PageScaleConstraints result;
- result.minimumScale = resultMinZoom;
- result.maximumScale = resultMaxZoom;
- result.initialScale = resultZoom;
- result.layoutSize.setWidth(resultWidth);
- result.layoutSize.setHeight(resultHeight);
- return result;
+ if (resultMinHeight == ViewportArguments::ValueExtendToZoom)
+ resultMinHeight = compareIgnoringAuto(extendHeight, resultMaxHeight, max);
}
- switch (static_cast<int>(resultWidth)) {
- case ViewportArguments::ValueDeviceWidth:
- resultWidth = initialViewportSize.width();
- break;
- case ViewportArguments::ValueDeviceHeight:
- resultWidth = initialViewportSize.height();
- break;
- }
+ // 4. Resolve initial width from min/max descriptors.
+ if (resultMinWidth != ViewportArguments::ValueAuto || resultMaxWidth != ViewportArguments::ValueAuto)
+ resultWidth = compareIgnoringAuto(resultMinWidth, compareIgnoringAuto(resultMaxWidth, initialViewportSize.width(), min), max);
- switch (static_cast<int>(resultHeight)) {
- case ViewportArguments::ValueDeviceWidth:
- resultHeight = initialViewportSize.width();
- break;
- case ViewportArguments::ValueDeviceHeight:
- resultHeight = initialViewportSize.height();
- break;
- }
+ // 5. Resolve initial height from min/max descriptors.
+ if (resultMinHeight != ViewportArguments::ValueAuto || resultMaxHeight != ViewportArguments::ValueAuto)
+ resultHeight = compareIgnoringAuto(resultMinHeight, compareIgnoringAuto(resultMaxHeight, initialViewportSize.height(), min), max);
- if (type != ViewportArguments::Implicit) {
- // Clamp values to a valid range, but not for @viewport since is
- // not mandated by the specification.
- resultWidth = clampLengthValue(resultWidth);
- resultHeight = clampLengthValue(resultHeight);
- resultZoom = clampScaleValue(resultZoom);
- resultMinZoom = clampScaleValue(resultMinZoom);
- resultMaxZoom = clampScaleValue(resultMaxZoom);
+ // 6-7. Resolve width value.
+ if (resultWidth == ViewportArguments::ValueAuto) {
+ if (resultHeight == ViewportArguments::ValueAuto || !initialViewportSize.height())
+ resultWidth = initialViewportSize.width();
+ else
+ resultWidth = resultHeight * (initialViewportSize.width() / initialViewportSize.height());
}
- PageScaleConstraints result;
-
- // Resolve minimum-scale and maximum-scale values according to spec.
- if (resultMinZoom == ViewportArguments::ValueAuto)
- result.minimumScale = float(0.25);
- else
- result.minimumScale = resultMinZoom;
-
- if (resultMaxZoom == ViewportArguments::ValueAuto) {
- result.maximumScale = float(5.0);
- result.minimumScale = min(float(5.0), result.minimumScale);
- } else
- result.maximumScale = resultMaxZoom;
- result.maximumScale = max(result.minimumScale, result.maximumScale);
+ // 8. Resolve height value.
+ if (resultHeight == ViewportArguments::ValueAuto) {
+ if (!initialViewportSize.width())
+ resultHeight = initialViewportSize.height();
+ else
+ resultHeight = resultWidth * initialViewportSize.height() / initialViewportSize.width();
+ }
// Resolve initial-scale value.
- result.initialScale = resultZoom;
if (resultZoom == ViewportArguments::ValueAuto) {
- result.initialScale = initialViewportSize.width() / defaultWidth;
if (resultWidth != ViewportArguments::ValueAuto && resultWidth > 0)
- result.initialScale = initialViewportSize.width() / resultWidth;
+ resultZoom = initialViewportSize.width() / resultWidth;
if (resultHeight != ViewportArguments::ValueAuto && resultHeight > 0) {
// if 'auto', the initial-scale will be negative here and thus ignored.
- result.initialScale = max<float>(result.initialScale, initialViewportSize.height() / resultHeight);
+ resultZoom = max<float>(resultZoom, initialViewportSize.height() / resultHeight);
}
}
- // Constrain initial-scale value to minimum-scale/maximum-scale range.
- result.initialScale = min(result.maximumScale, max(result.minimumScale, result.initialScale));
-
- // Resolve width value.
- if (resultWidth == ViewportArguments::ValueAuto) {
- if (resultZoom == ViewportArguments::ValueAuto)
- resultWidth = defaultWidth;
- else if (resultHeight != ViewportArguments::ValueAuto)
- resultWidth = resultHeight * (initialViewportSize.width() / initialViewportSize.height());
- else
- resultWidth = initialViewportSize.width() / result.initialScale;
- }
-
- // Resolve height value.
- if (resultHeight == ViewportArguments::ValueAuto)
- resultHeight = resultWidth * (initialViewportSize.height() / initialViewportSize.width());
-
- if (type == ViewportArguments::ViewportMeta) {
- // Extend width and height to fill the visual viewport for the resolved initial-scale.
- resultWidth = max<float>(resultWidth, initialViewportSize.width() / result.initialScale);
- resultHeight = max<float>(resultHeight, initialViewportSize.height() / result.initialScale);
- }
-
- result.layoutSize.setWidth(resultWidth);
- result.layoutSize.setHeight(resultHeight);
-
// If user-scalable = no, lock the min/max scale to the computed initial
// scale.
if (!resultUserZoom)
- result.maximumScale = result.minimumScale = result.initialScale;
+ resultMinZoom = resultMaxZoom = resultZoom;
// Only set initialScale to a value if it was explicitly set.
- if (resultZoom == ViewportArguments::ValueAuto)
- result.initialScale = ViewportArguments::ValueAuto;
+ if (zoom == ViewportArguments::ValueAuto)
+ resultZoom = ViewportArguments::ValueAuto;
+ PageScaleConstraints result;
+ result.minimumScale = resultMinZoom;
+ result.maximumScale = resultMaxZoom;
+ result.initialScale = resultZoom;
+ result.layoutSize.setWidth(resultWidth);
+ result.layoutSize.setHeight(resultHeight);
return result;
}
@@ -297,7 +216,7 @@ static float findSizeValue(const String& keyString, const String& valueString, D
if (value < 0)
return ViewportArguments::ValueAuto;
- return value;
+ return clampLengthValue(value);
}
static float findScaleValue(const String& keyString, const String& valueString, Document* document)
@@ -325,7 +244,7 @@ static float findScaleValue(const String& keyString, const String& valueString,
if (value > 10.0)
reportViewportWarning(document, MaximumScaleTooLargeError, String(), String());
- return value;
+ return clampScaleValue(value);
}
static float findUserScalableValue(const String& keyString, const String& valueString, Document* document)
@@ -374,23 +293,32 @@ void setViewportFeature(const String& keyString, const String& valueString, Docu
{
ViewportArguments* arguments = static_cast<ViewportArguments*>(data);
- if (keyString == "width")
- arguments->width = findSizeValue(keyString, valueString, document);
- else if (keyString == "height")
- arguments->height = findSizeValue(keyString, valueString, document);
- else if (keyString == "initial-scale")
+ if (keyString == "width") {
+ float width = findSizeValue(keyString, valueString, document);
+ if (width != ViewportArguments::ValueAuto) {
+ arguments->minWidth = ViewportArguments::ValueExtendToZoom;
+ arguments->maxWidth = width;
+ }
+ } else if (keyString == "height") {
+ float height = findSizeValue(keyString, valueString, document);
+ if (height != ViewportArguments::ValueAuto) {
+ arguments->minHeight = ViewportArguments::ValueExtendToZoom;
+ arguments->maxHeight = height;
+ }
+ } else if (keyString == "initial-scale") {
arguments->zoom = findScaleValue(keyString, valueString, document);
- else if (keyString == "minimum-scale")
+ } else if (keyString == "minimum-scale") {
arguments->minZoom = findScaleValue(keyString, valueString, document);
- else if (keyString == "maximum-scale")
+ } else if (keyString == "maximum-scale") {
arguments->maxZoom = findScaleValue(keyString, valueString, document);
- else if (keyString == "user-scalable")
+ } else if (keyString == "user-scalable") {
arguments->userZoom = findUserScalableValue(keyString, valueString, document);
- else if (keyString == "target-densitydpi") {
+ } else if (keyString == "target-densitydpi") {
arguments->deprecatedTargetDensityDPI = findTargetDensityDPIValue(keyString, valueString, document);
reportViewportWarning(document, TargetDensityDpiUnsupported, String(), String());
- } else
+ } else {
reportViewportWarning(document, UnrecognizedViewportArgumentKeyError, keyString, String());
+ }
}
static const char* viewportErrorMessageTemplate(ViewportErrorCode errorCode)

Powered by Google App Engine
This is Rietveld 408576698