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

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

Issue 23604037: Recompute percentage based @viewport on resize. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed review issue 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
« no previous file with comments | « Source/core/dom/ViewportArguments.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/ViewportArguments.cpp
diff --git a/Source/core/dom/ViewportArguments.cpp b/Source/core/dom/ViewportArguments.cpp
index d32836aaa10cd6f8adc73dd426b9d0f7400236f3..24d893d9c6fbb29811c4ee18c7abddfca0ac0c2d 100644
--- a/Source/core/dom/ViewportArguments.cpp
+++ b/Source/core/dom/ViewportArguments.cpp
@@ -70,15 +70,37 @@ static inline float clampScaleValue(float value)
return value;
}
+float ViewportArguments::resolveViewportLength(const Length& length, const FloatSize& initialViewportSize, Direction direction)
+{
+ if (length.isAuto())
+ return ViewportArguments::ValueAuto;
+
+ if (length.isFixed())
+ return length.getFloatValue();
+
+ if (length.type() == ExtendToZoom)
+ return ViewportArguments::ValueExtendToZoom;
+
+ if ((length.type() == Percent && direction == Horizontal) || length.type() == ViewportPercentageWidth)
+ return initialViewportSize.width() * length.getFloatValue() / 100.0f;
+
+ if ((length.type() == Percent && direction == Vertical) || 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, 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;
@@ -86,15 +108,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, Horizontal);
+ float resultMinWidth = resolveViewportLength(minWidth, initialViewportSize, Horizontal);
+ float resultMaxHeight = resolveViewportLength(maxHeight, initialViewportSize, Vertical);
+ float resultMinHeight = resolveViewportLength(minHeight, initialViewportSize, Vertical);
// 1. Resolve min-zoom and max-zoom values.
if (resultMinZoom != ViewportArguments::ValueAuto && resultMaxZoom != ViewportArguments::ValueAuto)
@@ -145,7 +162,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());
« no previous file with comments | « Source/core/dom/ViewportArguments.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698