This source file includes following definitions.
- maximumScale
- maximumScale
- overrideWith
- clampToConstraints
- clampAll
- fitToContentsWidth
#include "config.h"
#include "core/page/PageScaleConstraints.h"
#include <algorithm>
namespace WebCore {
PageScaleConstraints::PageScaleConstraints()
: initialScale(-1), minimumScale(-1), maximumScale(-1) { }
PageScaleConstraints::PageScaleConstraints(float initial, float minimum, float maximum)
: initialScale(initial), minimumScale(minimum), maximumScale(maximum) { }
void PageScaleConstraints::overrideWith(const PageScaleConstraints& other)
{
if (other.initialScale != -1) {
initialScale = other.initialScale;
if (minimumScale != -1)
minimumScale = std::min(minimumScale, other.initialScale);
}
if (other.minimumScale != -1)
minimumScale = other.minimumScale;
if (other.maximumScale != -1)
maximumScale = other.maximumScale;
if (!other.layoutSize.isEmpty())
layoutSize = other.layoutSize;
clampAll();
}
float PageScaleConstraints::clampToConstraints(float pageScaleFactor) const
{
if (pageScaleFactor == -1)
return pageScaleFactor;
if (minimumScale != -1)
pageScaleFactor = std::max(pageScaleFactor, minimumScale);
if (maximumScale != -1)
pageScaleFactor = std::min(pageScaleFactor, maximumScale);
return pageScaleFactor;
}
void PageScaleConstraints::clampAll()
{
if (minimumScale != -1 && maximumScale != -1)
maximumScale = std::max(minimumScale, maximumScale);
initialScale = clampToConstraints(initialScale);
}
void PageScaleConstraints::fitToContentsWidth(float contentsWidth, int viewWidthNotIncludingScrollbars)
{
if (!contentsWidth || !viewWidthNotIncludingScrollbars)
return;
minimumScale = std::max(minimumScale, viewWidthNotIncludingScrollbars / contentsWidth);
if (initialScale == -1)
initialScale = minimumScale;
clampAll();
}
bool PageScaleConstraints::operator==(const PageScaleConstraints& other) const
{
return layoutSize == other.layoutSize
&& initialScale == other.initialScale
&& minimumScale == other.minimumScale
&& maximumScale == other.maximumScale;
}
}