#ifndef RenderView_h
#define RenderView_h
#include "FrameView.h"
#include "LayoutState.h"
#include "PODFreeListArena.h"
#include "RenderBlock.h"
#include <wtf/OwnPtr.h>
namespace WebCore {
class FlowThreadController;
class RenderWidget;
#if USE(ACCELERATED_COMPOSITING)
class RenderLayerCompositor;
#endif
class RenderView : public RenderBlock {
public:
RenderView(Node*, FrameView*);
virtual ~RenderView();
bool hitTest(const HitTestRequest&, HitTestResult&);
virtual const char* renderName() const OVERRIDE { return "RenderView"; }
virtual bool isRenderView() const OVERRIDE { return true; }
virtual bool requiresLayer() const OVERRIDE { return true; }
virtual bool isChildAllowed(RenderObject*, RenderStyle*) const OVERRIDE;
virtual void layout() OVERRIDE;
virtual void computeLogicalWidth() OVERRIDE;
virtual void computeLogicalHeight() OVERRIDE;
virtual void computePreferredLogicalWidths() OVERRIDE;
virtual LayoutUnit availableLogicalHeight() const OVERRIDE;
int viewHeight() const;
int viewWidth() const;
int viewLogicalWidth() const { return style()->isHorizontalWritingMode() ? viewWidth() : viewHeight(); }
int viewLogicalHeight() const;
float zoomFactor() const;
FrameView* frameView() const { return m_frameView; }
virtual void computeRectForRepaint(RenderBoxModelObject* repaintContainer, LayoutRect&, bool fixed = false) const;
virtual void repaintViewRectangle(const LayoutRect&, bool immediate = false);
virtual void repaintRectangleInViewAndCompositedLayers(const LayoutRect&, bool immediate = false);
virtual void paint(PaintInfo&, const LayoutPoint&);
virtual void paintBoxDecorations(PaintInfo&, const LayoutPoint&) OVERRIDE;
enum SelectionRepaintMode { RepaintNewXOROld, RepaintNewMinusOld, RepaintNothing };
void setSelection(RenderObject* start, int startPos, RenderObject* end, int endPos, SelectionRepaintMode = RepaintNewXOROld);
void getSelection(RenderObject*& startRenderer, int& startOffset, RenderObject*& endRenderer, int& endOffset) const;
void clearSelection();
RenderObject* selectionStart() const { return m_selectionStart; }
RenderObject* selectionEnd() const { return m_selectionEnd; }
IntRect selectionBounds(bool clipToVisibleContent = true) const;
void selectionStartEnd(int& startPos, int& endPos) const;
bool printing() const;
virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const;
virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const;
#if USE(ACCELERATED_COMPOSITING)
void setMaximalOutlineSize(int o);
#else
void setMaximalOutlineSize(int o) { m_maximalOutlineSize = o; }
#endif
int maximalOutlineSize() const { return m_maximalOutlineSize; }
virtual LayoutRect viewRect() const OVERRIDE;
void updateWidgetPositions();
void addWidget(RenderWidget*);
void removeWidget(RenderWidget*);
void notifyWidgets(WidgetNotification);
LayoutSize layoutDelta() const
{
return m_layoutState ? m_layoutState->m_layoutDelta : LayoutSize();
}
void addLayoutDelta(const LayoutSize& delta)
{
if (m_layoutState)
m_layoutState->m_layoutDelta += delta;
}
bool doingFullRepaint() const { return m_frameView->needsFullRepaint(); }
void pushLayoutState(RenderObject*);
void popLayoutState(RenderObject*) { return popLayoutState(); }
bool shouldDisableLayoutStateForSubtree(RenderObject*) const;
bool layoutStateEnabled() const { return m_layoutStateDisableCount == 0 && m_layoutState; }
LayoutState* layoutState() const { return m_layoutState; }
virtual void updateHitTestResult(HitTestResult&, const LayoutPoint&);
unsigned pageLogicalHeight() const { return m_pageLogicalHeight; }
void setPageLogicalHeight(unsigned height)
{
if (m_pageLogicalHeight != height) {
m_pageLogicalHeight = height;
m_pageLogicalHeightChanged = true;
}
}
int bestTruncatedAt() const { return m_legacyPrinting.m_bestTruncatedAt; }
void setBestTruncatedAt(int y, RenderBoxModelObject* forRenderer, bool forcedBreak = false);
int truncatedAt() const { return m_legacyPrinting.m_truncatedAt; }
void setTruncatedAt(int y)
{
m_legacyPrinting.m_truncatedAt = y;
m_legacyPrinting.m_bestTruncatedAt = 0;
m_legacyPrinting.m_truncatorWidth = 0;
m_legacyPrinting.m_forcedPageBreak = false;
}
const IntRect& printRect() const { return m_legacyPrinting.m_printRect; }
void setPrintRect(const IntRect& r) { m_legacyPrinting.m_printRect = r; }
void didMoveOnscreen();
void willMoveOffscreen();
#if USE(ACCELERATED_COMPOSITING)
RenderLayerCompositor* compositor();
bool usesCompositing() const;
#endif
IntRect unscaledDocumentRect() const;
LayoutRect backgroundRect(RenderBox* backgroundRenderer) const;
IntRect documentRect() const;
bool hasRenderNamedFlowThreads() const;
FlowThreadController* flowThreadController();
void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
enum ContainingBlockCheck { CheckContainingBlock, DontCheckContainingBlock };
bool hasCustomFixedPosition(const RenderObject*, ContainingBlockCheck = CheckContainingBlock) const;
bool setCustomFixedPositionedObjectsNeedLayout();
IntervalArena* intervalArena();
IntSize viewportSize() const { return document()->viewportSize(); }
void setFixedPositionedObjectsNeedLayout();
void insertFixedPositionedObject(RenderBox*);
void removeFixedPositionedObject(RenderBox*);
protected:
virtual void mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool useTransforms, bool fixed, TransformState&, ApplyContainerFlipOrNot = ApplyContainerFlip, bool* wasFixed = 0) const;
virtual const RenderObject* pushMappingToContainer(const RenderBoxModelObject* ancestorToStopAt, RenderGeometryMap&) const;
virtual void mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState&) const;
virtual bool requiresColumns(int desiredColumnCount) const OVERRIDE;
private:
virtual void calcColumnWidth() OVERRIDE;
virtual ColumnInfo::PaginationUnit paginationUnit() const OVERRIDE;
bool shouldRepaint(const LayoutRect&) const;
void pushLayoutState(RenderFlowThread*, bool regionsChanged);
bool pushLayoutState(RenderBox* renderer, const LayoutSize& offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
{
if (!doingFullRepaint() || m_layoutState->isPaginated() || renderer->hasColumns() || renderer->inRenderFlowThread()
|| m_layoutState->lineGrid() || (renderer->style()->lineGrid() != RenderStyle::initialLineGrid() && renderer->isBlockFlow())) {
m_layoutState = new (renderArena()) LayoutState(m_layoutState, renderer, offset, pageHeight, pageHeightChanged, colInfo);
return true;
}
return false;
}
void popLayoutState()
{
LayoutState* state = m_layoutState;
m_layoutState = state->m_next;
state->destroy(renderArena());
}
void disableLayoutState() { m_layoutStateDisableCount++; }
void enableLayoutState() { ASSERT(m_layoutStateDisableCount > 0); m_layoutStateDisableCount--; }
size_t getRetainedWidgets(Vector<RenderWidget*>&);
void releaseWidgets(Vector<RenderWidget*>&);
friend class LayoutStateMaintainer;
friend class LayoutStateDisabler;
protected:
FrameView* m_frameView;
RenderObject* m_selectionStart;
RenderObject* m_selectionEnd;
int m_selectionStartPos;
int m_selectionEndPos;
struct LegacyPrinting {
LegacyPrinting()
: m_bestTruncatedAt(0)
, m_truncatedAt(0)
, m_truncatorWidth(0)
, m_forcedPageBreak(false)
{ }
int m_bestTruncatedAt;
int m_truncatedAt;
int m_truncatorWidth;
IntRect m_printRect;
bool m_forcedPageBreak;
};
LegacyPrinting m_legacyPrinting;
int m_maximalOutlineSize;
typedef HashSet<RenderWidget*> RenderWidgetSet;
RenderWidgetSet m_widgets;
typedef HashSet<RenderBox*> RenderBoxSet;
OwnPtr<RenderBoxSet> m_fixedPositionedElements;
private:
bool shouldUsePrintingLayout() const;
unsigned m_pageLogicalHeight;
bool m_pageLogicalHeightChanged;
LayoutState* m_layoutState;
unsigned m_layoutStateDisableCount;
#if USE(ACCELERATED_COMPOSITING)
OwnPtr<RenderLayerCompositor> m_compositor;
#endif
OwnPtr<FlowThreadController> m_flowThreadController;
RefPtr<IntervalArena> m_intervalArena;
};
inline RenderView* toRenderView(RenderObject* object)
{
ASSERT(!object || object->isRenderView());
return static_cast<RenderView*>(object);
}
inline const RenderView* toRenderView(const RenderObject* object)
{
ASSERT(!object || object->isRenderView());
return static_cast<const RenderView*>(object);
}
void toRenderView(const RenderView*);
ALWAYS_INLINE RenderView* RenderObject::view() const
{
return toRenderView(document()->renderer());
}
class LayoutStateMaintainer {
WTF_MAKE_NONCOPYABLE(LayoutStateMaintainer);
public:
LayoutStateMaintainer(RenderView* view, RenderBox* root, LayoutSize offset, bool disableState = false, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
: m_view(view)
, m_disabled(disableState)
, m_didStart(false)
, m_didEnd(false)
, m_didCreateLayoutState(false)
{
push(root, offset, pageHeight, pageHeightChanged, colInfo);
}
LayoutStateMaintainer(RenderView* view)
: m_view(view)
, m_disabled(false)
, m_didStart(false)
, m_didEnd(false)
, m_didCreateLayoutState(false)
{
}
LayoutStateMaintainer(RenderView* view, RenderFlowThread* flowThread, bool regionsChanged)
: m_view(view)
, m_disabled(false)
, m_didStart(false)
, m_didEnd(false)
, m_didCreateLayoutState(false)
{
push(flowThread, regionsChanged);
}
~LayoutStateMaintainer()
{
ASSERT(m_didStart == m_didEnd); }
void push(RenderBox* root, LayoutSize offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
{
ASSERT(!m_didStart);
m_didCreateLayoutState = m_view->pushLayoutState(root, offset, pageHeight, pageHeightChanged, colInfo);
if (m_disabled && m_didCreateLayoutState)
m_view->disableLayoutState();
m_didStart = true;
}
void push(RenderFlowThread* flowThread, bool regionsChanged)
{
ASSERT(!m_didStart);
m_view->pushLayoutState(flowThread, regionsChanged);
m_didCreateLayoutState = true;
m_didStart = true;
}
void pop()
{
if (m_didStart) {
ASSERT(!m_didEnd);
if (m_didCreateLayoutState) {
m_view->popLayoutState();
if (m_disabled)
m_view->enableLayoutState();
}
m_didEnd = true;
}
}
bool didPush() const { return m_didStart; }
private:
RenderView* m_view;
bool m_disabled : 1; bool m_didStart : 1; bool m_didEnd : 1; bool m_didCreateLayoutState : 1; };
class LayoutStateDisabler {
WTF_MAKE_NONCOPYABLE(LayoutStateDisabler);
public:
LayoutStateDisabler(RenderView* view)
: m_view(view)
{
if (m_view)
m_view->disableLayoutState();
}
~LayoutStateDisabler()
{
if (m_view)
m_view->enableLayoutState();
}
private:
RenderView* m_view;
};
}
#endif // RenderView_h