ViewportConfiguration.h [plain text]
#pragma once
#include "DisabledAdaptations.h"
#include "FloatSize.h"
#include "IntSize.h"
#include "ViewportArguments.h"
#include <wtf/Noncopyable.h>
#include <wtf/OptionSet.h>
namespace WTF {
class TextStream;
}
namespace WebCore {
static const double forceAlwaysUserScalableMaximumScale = 5.0;
static const double forceAlwaysUserScalableMinimumScale = 1.0;
class ViewportConfiguration {
WTF_MAKE_NONCOPYABLE(ViewportConfiguration); WTF_MAKE_FAST_ALLOCATED;
public:
struct Parameters {
double width { 0 };
double height { 0 };
double initialScale { 0 };
double minimumScale { 0 };
double maximumScale { 0 };
bool allowsUserScaling { false };
bool allowsShrinkToFit { false };
bool avoidsUnsafeArea { true };
bool widthIsSet { false };
bool heightIsSet { false };
bool initialScaleIsSet { false };
bool operator==(const Parameters& other) const
{
return width == other.width && height == other.height
&& initialScale == other.initialScale && minimumScale == other.minimumScale && maximumScale == other.maximumScale
&& allowsUserScaling == other.allowsUserScaling && allowsShrinkToFit == other.allowsShrinkToFit && avoidsUnsafeArea == other.avoidsUnsafeArea
&& widthIsSet == other.widthIsSet && heightIsSet == other.heightIsSet && initialScaleIsSet == other.initialScaleIsSet;
}
};
WEBCORE_EXPORT ViewportConfiguration();
const Parameters& defaultConfiguration() const { return m_defaultConfiguration; }
WEBCORE_EXPORT void setDefaultConfiguration(const Parameters&);
const IntSize& contentsSize() const { return m_contentSize; }
WEBCORE_EXPORT bool setContentsSize(const IntSize&);
const FloatSize& viewLayoutSize() const { return m_viewLayoutSize; }
const FloatSize& minimumLayoutSize() const { return m_minimumLayoutSize; }
WEBCORE_EXPORT bool setViewLayoutSize(const FloatSize&);
const OptionSet<DisabledAdaptations>& disabledAdaptations() const { return m_disabledAdaptations; }
WEBCORE_EXPORT bool setDisabledAdaptations(const OptionSet<DisabledAdaptations>&);
const ViewportArguments& viewportArguments() const { return m_viewportArguments; }
WEBCORE_EXPORT bool setViewportArguments(const ViewportArguments&);
WEBCORE_EXPORT bool setCanIgnoreScalingConstraints(bool);
void setForceAlwaysUserScalable(bool forceAlwaysUserScalable) { m_forceAlwaysUserScalable = forceAlwaysUserScalable; }
WEBCORE_EXPORT IntSize layoutSize() const;
WEBCORE_EXPORT double initialScale() const;
WEBCORE_EXPORT double initialScaleIgnoringContentSize() const;
WEBCORE_EXPORT double minimumScale() const;
double maximumScale() const { return m_forceAlwaysUserScalable ? forceAlwaysUserScalableMaximumScale : m_configuration.maximumScale; }
double maximumScaleIgnoringAlwaysScalable() const { return m_configuration.maximumScale; }
WEBCORE_EXPORT bool allowsUserScaling() const;
WEBCORE_EXPORT bool allowsUserScalingIgnoringAlwaysScalable() const;
bool allowsShrinkToFit() const;
bool avoidsUnsafeArea() const { return m_configuration.avoidsUnsafeArea; }
WEBCORE_EXPORT static Parameters webpageParameters();
WEBCORE_EXPORT static Parameters textDocumentParameters();
WEBCORE_EXPORT static Parameters imageDocumentParameters();
WEBCORE_EXPORT static Parameters xhtmlMobileParameters();
WEBCORE_EXPORT static Parameters testingParameters();
#ifndef NDEBUG
String description() const;
WEBCORE_EXPORT void dump() const;
#endif
private:
void updateConfiguration();
double viewportArgumentsLength(double length) const;
double initialScaleFromSize(double width, double height, bool shouldIgnoreScalingConstraints) const;
int layoutWidth() const;
int layoutHeight() const;
bool shouldOverrideDeviceWidthAndShrinkToFit() const;
bool shouldIgnoreScalingConstraintsRegardlessOfContentSize() const;
bool shouldIgnoreScalingConstraints() const;
bool shouldIgnoreVerticalScalingConstraints() const;
bool shouldIgnoreHorizontalScalingConstraints() const;
void updateMinimumLayoutSize();
Parameters m_configuration;
Parameters m_defaultConfiguration;
IntSize m_contentSize;
FloatSize m_minimumLayoutSize;
FloatSize m_viewLayoutSize;
ViewportArguments m_viewportArguments;
OptionSet<DisabledAdaptations> m_disabledAdaptations;
bool m_canIgnoreScalingConstraints;
bool m_forceAlwaysUserScalable;
};
WTF::TextStream& operator<<(WTF::TextStream&, const ViewportConfiguration::Parameters&);
WTF::TextStream& operator<<(WTF::TextStream&, const ViewportConfiguration&);
}