Пример #1
0
LayoutState::LayoutState(LayoutBox& layoutObject, const LayoutSize& offset, LayoutUnit pageLogicalHeight, bool pageLogicalHeightChanged, bool containingBlockLogicalWidthChanged)
    : m_containingBlockLogicalWidthChanged(containingBlockLogicalWidthChanged)
    , m_next(layoutObject.view()->layoutState())
    , m_layoutObject(layoutObject)
{
    if (layoutObject.isLayoutFlowThread())
        m_flowThread = toLayoutFlowThread(&layoutObject);
    else if (!layoutObject.isOutOfFlowPositioned())
        m_flowThread = m_next->flowThread();
    else
        m_flowThread = nullptr;
    layoutObject.view()->pushLayoutState(*this);
    bool fixed = layoutObject.isOutOfFlowPositioned() && layoutObject.style()->position() == FixedPosition;
    if (fixed) {
        // FIXME: This doesn't work correctly with transforms.
        FloatPoint fixedOffset = layoutObject.view()->localToAbsolute(FloatPoint(), IsFixed);
        m_layoutOffset = LayoutSize(fixedOffset.x(), fixedOffset.y()) + offset;
    } else {
        m_layoutOffset = m_next->m_layoutOffset + offset;
    }
    m_heightOffsetForTableHeaders = m_next->heightOffsetForTableHeaders();

    if (layoutObject.isOutOfFlowPositioned() && !fixed) {
        if (LayoutObject* container = layoutObject.container()) {
            if (container->style()->hasInFlowPosition() && container->isLayoutInline())
                m_layoutOffset += toLayoutInline(container)->offsetForInFlowPositionedInline(layoutObject);
        }
    }
    // If we establish a new page height, then cache the offset to the top of the first page.
    // We can compare this later on to figure out what part of the page we're actually on,
    if (pageLogicalHeight || layoutObject.isLayoutFlowThread()) {
        m_pageLogicalHeight = pageLogicalHeight;
        bool isFlipped = layoutObject.style()->isFlippedBlocksWritingMode();
        m_pageOffset = LayoutSize(m_layoutOffset.width() + (!isFlipped ? layoutObject.borderLeft() + layoutObject.paddingLeft() : layoutObject.borderRight() + layoutObject.paddingRight()),
            m_layoutOffset.height() + (!isFlipped ? layoutObject.borderTop() + layoutObject.paddingTop() : layoutObject.borderBottom() + layoutObject.paddingBottom()));
        m_pageLogicalHeightChanged = pageLogicalHeightChanged;
        m_isPaginated = true;
    } else if (m_layoutObject.isSVG() && !m_layoutObject.isSVGRoot()) {
        // Pagination inside SVG is not allowed.
        m_flowThread = nullptr;
        m_pageLogicalHeightChanged = false;
        m_isPaginated = false;
    } else {
        // If we don't establish a new page height, then propagate the old page height and offset down.
        m_pageLogicalHeight = m_next->m_pageLogicalHeight;
        m_pageLogicalHeightChanged = m_next->m_pageLogicalHeightChanged;
        m_pageOffset = m_next->m_pageOffset;

        // Disable pagination for objects we don't support. For now this includes overflow:scroll/auto, inline blocks and
        // writing mode roots.
        if (layoutObject.getPaginationBreakability() == LayoutBox::ForbidBreaks) {
            m_flowThread = nullptr;
            m_pageLogicalHeight = LayoutUnit();
            m_isPaginated = false;
        } else {
            m_isPaginated = m_pageLogicalHeight || m_flowThread;
        }
    }

    // FIXME: <http://bugs.webkit.org/show_bug.cgi?id=13443> Apply control clip if present.
}