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

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

Issue 22549002: Recompute percentage based @viewport on resize. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed Mac compile issues. 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 0a2708dd1f07b1b02f760d61f5acb4d501683393..846ed2eed5cb136321f2c9174a64f11c744c7de7 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;
}
+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;
@@ -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, 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)
@@ -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());
« 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