#pragma once
#include "FrameViewLayoutContext.h"
#include "LayoutRect.h"
#include <wtf/Noncopyable.h>
namespace WebCore {
class RenderBlockFlow;
class RenderBox;
class RenderElement;
class RenderFragmentedFlow;
class RenderMultiColumnFlow;
class RenderObject;
class LayoutState {
WTF_MAKE_NONCOPYABLE(LayoutState); WTF_MAKE_FAST_ALLOCATED;
public:
LayoutState()
: m_clipped(false)
, m_isPaginated(false)
, m_pageLogicalHeightChanged(false)
#if !ASSERT_DISABLED
, m_layoutDeltaXSaturated(false)
, m_layoutDeltaYSaturated(false)
#endif
{
}
LayoutState(const FrameViewLayoutContext::LayoutStateStack&, RenderBox&, const LayoutSize& offset, LayoutUnit pageHeight, bool pageHeightChanged);
enum class IsPaginated { No, Yes };
explicit LayoutState(RenderElement&, IsPaginated = IsPaginated::No);
bool isPaginated() const { return m_isPaginated; }
LayoutUnit pageLogicalOffset(RenderBox*, LayoutUnit childLogicalOffset) const;
LayoutUnit pageLogicalHeight() const { return m_pageLogicalHeight; }
bool pageLogicalHeightChanged() const { return m_pageLogicalHeightChanged; }
RenderBlockFlow* lineGrid() const { return m_lineGrid.get(); }
LayoutSize lineGridOffset() const { return m_lineGridOffset; }
LayoutSize lineGridPaginationOrigin() const { return m_lineGridPaginationOrigin; }
LayoutSize paintOffset() const { return m_paintOffset; }
LayoutSize layoutOffset() const { return m_layoutOffset; }
LayoutSize pageOffset() const { return m_pageOffset; }
bool needsBlockDirectionLocationSetBeforeLayout() const { return m_lineGrid || (m_isPaginated && m_pageLogicalHeight); }
#ifndef NDEBUG
RenderElement* renderer() const { return m_renderer; }
#endif
LayoutRect clipRect() const { return m_clipRect; }
bool isClipped() const { return m_clipped; }
void addLayoutDelta(LayoutSize);
LayoutSize layoutDelta() const { return m_layoutDelta; }
#if !ASSERT_DISABLED
bool layoutDeltaMatches(LayoutSize) const;
#endif
private:
void computeOffsets(const LayoutState& ancestor, RenderBox&, LayoutSize offset);
void computeClipRect(const LayoutState& ancestor, RenderBox&);
void computePaginationInformation(const FrameViewLayoutContext::LayoutStateStack&, RenderBox&, LayoutUnit pageLogicalHeight, bool pageLogicalHeightChanged);
void propagateLineGridInfo(const LayoutState& ancestor, RenderBox&);
void establishLineGrid(const FrameViewLayoutContext::LayoutStateStack&, RenderBlockFlow&);
void computeLineGridPaginationOrigin(const RenderMultiColumnFlow&);
bool m_clipped : 1;
bool m_isPaginated : 1;
bool m_pageLogicalHeightChanged : 1;
#if !ASSERT_DISABLED
bool m_layoutDeltaXSaturated : 1;
bool m_layoutDeltaYSaturated : 1;
#endif
WeakPtr<RenderBlockFlow> m_lineGrid;
LayoutRect m_clipRect;
LayoutSize m_paintOffset;
LayoutSize m_layoutOffset;
LayoutSize m_layoutDelta;
LayoutUnit m_pageLogicalHeight;
LayoutSize m_pageOffset;
LayoutSize m_lineGridOffset;
LayoutSize m_lineGridPaginationOrigin;
#ifndef NDEBUG
RenderElement* m_renderer { nullptr };
#endif
};
class LayoutStateMaintainer {
WTF_MAKE_NONCOPYABLE(LayoutStateMaintainer);
public:
explicit LayoutStateMaintainer(RenderBox&, LayoutSize offset, bool disableState = false, LayoutUnit pageHeight = 0, bool pageHeightChanged = false);
~LayoutStateMaintainer();
private:
FrameViewLayoutContext& m_context;
bool m_paintOffsetCacheIsDisabled { false };
bool m_didPushLayoutState { false };
};
class SubtreeLayoutStateMaintainer {
public:
SubtreeLayoutStateMaintainer(RenderElement* subtreeLayoutRoot);
~SubtreeLayoutStateMaintainer();
private:
FrameViewLayoutContext* m_context { nullptr };
bool m_didDisablePaintOffsetCache { false };
};
class LayoutStateDisabler {
WTF_MAKE_NONCOPYABLE(LayoutStateDisabler);
public:
LayoutStateDisabler(FrameViewLayoutContext&);
~LayoutStateDisabler();
private:
FrameViewLayoutContext& m_context;
};
class PaginatedLayoutStateMaintainer {
public:
PaginatedLayoutStateMaintainer(RenderBlockFlow&);
~PaginatedLayoutStateMaintainer();
private:
FrameViewLayoutContext& m_context;
bool m_pushed { false };
};
}