Chromium Code Reviews| Index: Source/core/dom/ViewportArguments.cpp |
| diff --git a/Source/core/dom/ViewportArguments.cpp b/Source/core/dom/ViewportArguments.cpp |
| index 92ae2cf0ae0dc57aecb8c5f2da81ca7e8984a384..c603ec5315d2dc9508af00855b0031683fe3cfc8 100644 |
| --- a/Source/core/dom/ViewportArguments.cpp |
| +++ b/Source/core/dom/ViewportArguments.cpp |
| @@ -68,15 +68,37 @@ static inline float clampScaleValue(float value) |
| return value; |
| } |
| +static float resolveViewportLength(const Length& length, const FloatSize& initialViewportSize, bool horizontal) |
|
apavlov
2013/08/07 09:25:54
optionally, you could have an enum instead of the
rune
2013/08/07 10:06:15
I'll fix.
rune
2013/08/07 11:30:04
Done.
|
| +{ |
| + if (length.isAuto()) |
| + return ViewportArguments::ValueAuto; |
| + |
| + if (length.isFixed()) |
| + return length.getFloatValue(); |
| + |
| + if (length.type() == ExtendToZoom) |
| + return ViewportArguments::ValueExtendToZoom; |
| + |
| + if (length.type() == Percent && horizontal || length.type() == ViewportPercentageWidth) |
| + return initialViewportSize.width() * length.getFloatValue() / 100.0f; |
| + |
| + if (length.type() == Percent && !horizontal || length.type() == ViewportPercentageHeight) |
| + return initialViewportSize.height() * length.getFloatValue() / 100.0f; |
| + |
| + if (length.type() == ViewportPercentageMin) |
| + return min(initialViewportSize.width(), initialViewportSize.height()) * length.viewportPercentageLength() / 100.0f; |
| + |
| + if (length.type() == ViewportPercentageMax) |
| + return max(initialViewportSize.width(), initialViewportSize.height()) * length.viewportPercentageLength() / 100.0f; |
| + |
| + ASSERT_NOT_REACHED(); |
| + return ViewportArguments::ValueAuto; |
| +} |
| + |
| PageScaleConstraints ViewportArguments::resolve(const FloatSize& initialViewportSize, const FloatSize& deviceSize, int defaultWidth) const |
| { |
| float resultWidth = width; |
| - float resultMaxWidth = maxWidth; |
| - float resultMinWidth = minWidth; |
| float resultHeight = height; |
| - float resultMinHeight = minHeight; |
| - float resultMaxHeight = maxHeight; |
| - |
| float resultZoom = zoom; |
| float resultMinZoom = minZoom; |
| float resultMaxZoom = maxZoom; |
| @@ -84,15 +106,10 @@ PageScaleConstraints ViewportArguments::resolve(const FloatSize& initialViewport |
| 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); |
| + float resultMaxWidth = resolveViewportLength(maxWidth, initialViewportSize, true); |
| + float resultMinWidth = resolveViewportLength(minWidth, initialViewportSize, true); |
| + float resultMaxHeight = resolveViewportLength(maxHeight, initialViewportSize, false); |
| + float resultMinHeight = resolveViewportLength(minHeight, initialViewportSize, false); |
| // 1. Resolve min-zoom and max-zoom values. |
| if (resultMinZoom != ViewportArguments::ValueAuto && resultMaxZoom != ViewportArguments::ValueAuto) |
| @@ -143,7 +160,7 @@ PageScaleConstraints ViewportArguments::resolve(const FloatSize& initialViewport |
| // 6-7. Resolve width value. |
| if (resultWidth == ViewportArguments::ValueAuto) { |
| - if (resultHeight == ViewportArguments::ValueAuto || !initialViewportSize .height()) |
| + if (resultHeight == ViewportArguments::ValueAuto || !initialViewportSize.height()) |
| resultWidth = initialViewportSize.width(); |
| else |
| resultWidth = resultHeight * (initialViewportSize.width() / initialViewportSize.height()); |