FrameViewLayoutContext.h [plain text]
#pragma once
#include "LayoutUnit.h"
#include "Timer.h"
#include <wtf/WeakPtr.h>
namespace WebCore {
class Document;
class Frame;
class FrameView;
class LayoutScope;
class LayoutSize;
class LayoutState;
class RenderBlockFlow;
class RenderBox;
class RenderObject;
class RenderElement;
class RenderView;
class FrameViewLayoutContext {
public:
FrameViewLayoutContext(FrameView&);
~FrameViewLayoutContext();
void layout();
void setNeedsLayout();
bool needsLayout() const;
void scheduleLayout();
void scheduleSubtreeLayout(RenderElement& layoutRoot);
void unscheduleLayout();
void startDisallowingLayout() { ++m_layoutDisallowedCount; }
void endDisallowingLayout() { ASSERT(m_layoutDisallowedCount > 0); --m_layoutDisallowedCount; }
void disableSetNeedsLayout();
void enableSetNeedsLayout();
enum class LayoutPhase {
OutsideLayout,
InPreLayout,
InRenderTreeLayout,
InViewSizeAdjust,
InPostLayout
};
LayoutPhase layoutPhase() const { return m_layoutPhase; }
bool isLayoutNested() const { return m_layoutNestedState == LayoutNestedState::Nested; }
bool isLayoutPending() const { return m_layoutTimer.isActive(); }
bool isInLayout() const { return layoutPhase() != LayoutPhase::OutsideLayout; }
bool isInRenderTreeLayout() const { return layoutPhase() == LayoutPhase::InRenderTreeLayout; }
bool inPaintableState() const { return layoutPhase() != LayoutPhase::InRenderTreeLayout && layoutPhase() != LayoutPhase::InViewSizeAdjust && (layoutPhase() != LayoutPhase::InPostLayout || inAsynchronousTasks()); }
unsigned layoutCount() const { return m_layoutCount; }
RenderElement* subtreeLayoutRoot() const { return m_subtreeLayoutRoot.get(); }
void clearSubtreeLayoutRoot() { m_subtreeLayoutRoot.clear(); }
void convertSubtreeLayoutToFullLayout();
void reset();
void resetFirstLayoutFlag() { m_firstLayout = true; }
bool didFirstLayout() const { return !m_firstLayout; }
void setNeedsFullRepaint() { m_needsFullRepaint = true; }
bool needsFullRepaint() const { return m_needsFullRepaint; }
void flushAsynchronousTasks();
LayoutState* layoutState() const;
bool isPaintOffsetCacheEnabled() const { return !m_paintOffsetCacheDisableCount && layoutState(); }
#ifndef NDEBUG
void checkLayoutState();
#endif
LayoutSize layoutDelta() const;
void addLayoutDelta(const LayoutSize& delta);
#if !ASSERT_DISABLED
bool layoutDeltaMatches(const LayoutSize& delta);
#endif
using LayoutStateStack = Vector<std::unique_ptr<LayoutState>>;
private:
friend class LayoutScope;
friend class LayoutStateMaintainer;
friend class LayoutStateDisabler;
friend class SubtreeLayoutStateMaintainer;
friend class PaginatedLayoutStateMaintainer;
bool canPerformLayout() const;
bool layoutDisallowed() const { return m_layoutDisallowedCount; }
bool isLayoutSchedulingEnabled() const { return m_layoutSchedulingIsEnabled; }
void layoutTimerFired();
void runAsynchronousTasks();
void runOrScheduleAsynchronousTasks();
bool inAsynchronousTasks() const { return m_inAsynchronousTasks; }
void setSubtreeLayoutRoot(RenderElement&);
#if ENABLE(TEXT_AUTOSIZING)
void applyTextSizingIfNeeded(RenderElement& layoutRoot);
#endif
void updateStyleForLayout();
bool handleLayoutWithFrameFlatteningIfNeeded();
void startLayoutAtMainFrameViewIfNeeded();
void pushLayoutState(RenderElement&);
bool pushLayoutStateForPaginationIfNeeded(RenderBlockFlow&);
bool pushLayoutState(RenderBox& renderer, const LayoutSize& offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false);
void popLayoutState();
void disablePaintOffsetCache() { m_paintOffsetCacheDisableCount++; }
void enablePaintOffsetCache() { ASSERT(m_paintOffsetCacheDisableCount > 0); m_paintOffsetCacheDisableCount--; }
Frame& frame() const;
FrameView& view() const;
RenderView* renderView() const;
Document* document() const;
FrameView& m_frameView;
Timer m_layoutTimer;
Timer m_asynchronousTasksTimer;
bool m_layoutSchedulingIsEnabled { true };
bool m_delayedLayout { false };
bool m_firstLayout { true };
bool m_needsFullRepaint { true };
bool m_inAsynchronousTasks { false };
bool m_setNeedsLayoutWasDeferred { false };
LayoutPhase m_layoutPhase { LayoutPhase::OutsideLayout };
enum class LayoutNestedState { NotInLayout, NotNested, Nested };
LayoutNestedState m_layoutNestedState { LayoutNestedState::NotInLayout };
unsigned m_layoutCount { 0 };
unsigned m_disableSetNeedsLayoutCount { 0 };
int m_layoutDisallowedCount { 0 };
WeakPtr<RenderElement> m_subtreeLayoutRoot;
LayoutStateStack m_layoutStateStack;
unsigned m_paintOffsetCacheDisableCount { 0 };
};
}