This source file includes following definitions.
- compareIgnoringAuto
- resolveViewportLength
- resolve
#include "config.h"
#include "core/dom/ViewportDescription.h"
using namespace std;
namespace WebCore {
static const float& compareIgnoringAuto(const float& value1, const float& value2, const float& (*compare) (const float&, const float&))
{
if (value1 == ViewportDescription::ValueAuto)
return value2;
if (value2 == ViewportDescription::ValueAuto)
return value1;
return compare(value1, value2);
}
float ViewportDescription::resolveViewportLength(const Length& length, const FloatSize& initialViewportSize, Direction direction)
{
if (length.isAuto())
return ViewportDescription::ValueAuto;
if (length.isFixed())
return length.getFloatValue();
if (length.type() == ExtendToZoom)
return ViewportDescription::ValueExtendToZoom;
if (length.type() == Percent && direction == Horizontal)
return initialViewportSize.width() * length.getFloatValue() / 100.0f;
if (length.type() == Percent && direction == Vertical)
return initialViewportSize.height() * length.getFloatValue() / 100.0f;
if (length.type() == DeviceWidth)
return initialViewportSize.width();
if (length.type() == DeviceHeight)
return initialViewportSize.height();
ASSERT_NOT_REACHED();
return ViewportDescription::ValueAuto;
}
PageScaleConstraints ViewportDescription::resolve(const FloatSize& initialViewportSize, Length legacyFallbackWidth) const
{
float resultWidth = ValueAuto;
Length copyMaxWidth = maxWidth;
Length copyMinWidth = minWidth;
if (isLegacyViewportType() && maxWidth.isAuto()) {
if (zoom == ViewportDescription::ValueAuto) {
copyMinWidth = Length(ExtendToZoom);
copyMaxWidth = legacyFallbackWidth;
} else if (maxHeight.isAuto()) {
copyMinWidth = Length(ExtendToZoom);
copyMaxWidth = Length(ExtendToZoom);
}
}
float resultMaxWidth = resolveViewportLength(copyMaxWidth, initialViewportSize, Horizontal);
float resultMinWidth = resolveViewportLength(copyMinWidth, initialViewportSize, Horizontal);
float resultHeight = ValueAuto;
float resultMaxHeight = resolveViewportLength(maxHeight, initialViewportSize, Vertical);
float resultMinHeight = resolveViewportLength(minHeight, initialViewportSize, Vertical);
float resultZoom = zoom;
float resultMinZoom = minZoom;
float resultMaxZoom = maxZoom;
float resultUserZoom = userZoom;
if (resultMinZoom != ViewportDescription::ValueAuto && resultMaxZoom != ViewportDescription::ValueAuto)
resultMaxZoom = max(resultMinZoom, resultMaxZoom);
if (resultZoom != ViewportDescription::ValueAuto)
resultZoom = compareIgnoringAuto(resultMinZoom, compareIgnoringAuto(resultMaxZoom, resultZoom, min), max);
float extendZoom = compareIgnoringAuto(resultZoom, resultMaxZoom, min);
if (extendZoom == ViewportDescription::ValueAuto) {
if (resultMaxWidth == ViewportDescription::ValueExtendToZoom)
resultMaxWidth = ViewportDescription::ValueAuto;
if (resultMaxHeight == ViewportDescription::ValueExtendToZoom)
resultMaxHeight = ViewportDescription::ValueAuto;
if (resultMinWidth == ViewportDescription::ValueExtendToZoom)
resultMinWidth = resultMaxWidth;
if (resultMinHeight == ViewportDescription::ValueExtendToZoom)
resultMinHeight = resultMaxHeight;
} else {
float extendWidth = initialViewportSize.width() / extendZoom;
float extendHeight = initialViewportSize.height() / extendZoom;
if (resultMaxWidth == ViewportDescription::ValueExtendToZoom)
resultMaxWidth = extendWidth;
if (resultMaxHeight == ViewportDescription::ValueExtendToZoom)
resultMaxHeight = extendHeight;
if (resultMinWidth == ViewportDescription::ValueExtendToZoom)
resultMinWidth = compareIgnoringAuto(extendWidth, resultMaxWidth, max);
if (resultMinHeight == ViewportDescription::ValueExtendToZoom)
resultMinHeight = compareIgnoringAuto(extendHeight, resultMaxHeight, max);
}
if (resultMinWidth != ViewportDescription::ValueAuto || resultMaxWidth != ViewportDescription::ValueAuto)
resultWidth = compareIgnoringAuto(resultMinWidth, compareIgnoringAuto(resultMaxWidth, initialViewportSize.width(), min), max);
if (resultMinHeight != ViewportDescription::ValueAuto || resultMaxHeight != ViewportDescription::ValueAuto)
resultHeight = compareIgnoringAuto(resultMinHeight, compareIgnoringAuto(resultMaxHeight, initialViewportSize.height(), min), max);
if (resultWidth == ViewportDescription::ValueAuto) {
if (resultHeight == ViewportDescription::ValueAuto || !initialViewportSize.height())
resultWidth = initialViewportSize.width();
else
resultWidth = resultHeight * (initialViewportSize.width() / initialViewportSize.height());
}
if (resultHeight == ViewportDescription::ValueAuto) {
if (!initialViewportSize.width())
resultHeight = initialViewportSize.height();
else
resultHeight = resultWidth * initialViewportSize.height() / initialViewportSize.width();
}
if (resultZoom == ViewportDescription::ValueAuto) {
if (resultWidth != ViewportDescription::ValueAuto && resultWidth > 0)
resultZoom = initialViewportSize.width() / resultWidth;
if (resultHeight != ViewportDescription::ValueAuto && resultHeight > 0) {
resultZoom = max<float>(resultZoom, initialViewportSize.height() / resultHeight);
}
}
if (!resultUserZoom)
resultMinZoom = resultMaxZoom = resultZoom;
if (zoom == ViewportDescription::ValueAuto)
resultZoom = ViewportDescription::ValueAuto;
PageScaleConstraints result;
result.minimumScale = resultMinZoom;
result.maximumScale = resultMaxZoom;
result.initialScale = resultZoom;
result.layoutSize.setWidth(resultWidth);
result.layoutSize.setHeight(resultHeight);
return result;
}
}