IntSize PageScaleConstraintsSet::mainFrameSize(int contentWidthIncludingScrollbar) const
{
    // If there's no explicit minimum scale factor set, size the frame so that its width == content width
    // so there's no horizontal scrolling at the minimum scale.
    if (m_pageDefinedConstraints.minimumScale < finalConstraints().minimumScale
        && m_userAgentConstraints.minimumScale < finalConstraints().minimumScale
        && contentWidthIncludingScrollbar
        && m_viewSize.width()) {

        // Special case where the contents are exactly as wide as the viewport to prevent an off-by-one due
        // to floating point imprecision in the aspect ratio height calculation.
        if (contentWidthIncludingScrollbar == m_viewSize.width())
            return m_viewSize;

        return expandedIntSize(FloatSize(
            contentWidthIncludingScrollbar,
            computeHeightByAspectRatio(contentWidthIncludingScrollbar, m_viewSize)));
    }

    // If there is a minimum scale (or there's no content size yet), the frame size should match the viewport
    // size at minimum scale, since the viewport must always be contained by the frame.
    FloatSize frameSize(m_viewSize);
    frameSize.scale(1 / finalConstraints().minimumScale);
    return expandedIntSize(frameSize);
}
void PageScaleConstraintsSet::didChangeContentsSize(IntSize contentsSize, float pageScaleFactor)
{
    // If a large fixed-width element expanded the size of the document late in
    // loading and our initial scale is not set (or set to be less than the last
    // minimum scale), reset the page scale factor to the new initial scale.
    if (contentsSize.width() > m_lastContentsWidth
        && pageScaleFactor == finalConstraints().minimumScale
        && computeConstraintsStack().initialScale < finalConstraints().minimumScale)
        setNeedsReset(true);

    m_constraintsDirty = true;
    m_lastContentsWidth = contentsSize.width();
}
IntSize PageScaleConstraintsSet::mainFrameSize(const IntSize& contentsSize) const
{
    // If there's no explicit minimum scale factor set, size the frame so that its width == content width
    // so there's no horizontal scrolling at the minimum scale.
    if (m_pageDefinedConstraints.minimumScale < finalConstraints().minimumScale
        && m_userAgentConstraints.minimumScale < finalConstraints().minimumScale
        && contentsSize.width()
        && m_viewSize.width())
        return IntSize(contentsSize.width(), computeHeightByAspectRatio(contentsSize.width(), m_viewSize));

    // If there is a minimum scale (or there's no content size yet), the frame size should match the viewport
    // size at minimum scale, since the viewport must always be contained by the frame.
    IntSize frameSize(m_viewSize);
    frameSize.scale(1 / finalConstraints().minimumScale);
    return frameSize;
}
IntSize PageScaleConstraintsSet::mainFrameSize() const
{
    // The frame size should match the viewport size at minimum scale, since the
    // viewport must always be contained by the frame.
    FloatSize frameSize(m_viewSize);
    frameSize.scale(1 / finalConstraints().minimumScale);
    return expandedIntSize(frameSize);
}