#ifndef RenderBlock_h
#define RenderBlock_h
#include "DeprecatedPtrList.h"
#include "GapRects.h"
#include "RenderBox.h"
#include "RenderLineBoxList.h"
#include "RootInlineBox.h"
#include <wtf/ListHashSet.h>
namespace WebCore {
class InlineIterator;
class RenderInline;
struct BidiRun;
template <class Iterator, class Run> class BidiResolver;
template <class Iterator> class MidpointState;
typedef BidiResolver<InlineIterator, BidiRun> InlineBidiResolver;
typedef MidpointState<InlineIterator> LineMidpointState;
enum CaretType { CursorCaret, DragCaret };
enum LineCount {
NOT_SET = 0, NO_LINE = 1, ONE_LINE = 2, MULTI_LINE = 3
};
class RenderBlock : public RenderBox {
public:
RenderBlock(Node*);
virtual ~RenderBlock();
const RenderObjectChildList* children() const { return &m_children; }
RenderObjectChildList* children() { return &m_children; }
virtual void destroy();
virtual int lineHeight(bool firstLine, bool isRootLineBox = false) const;
virtual int baselinePosition(bool firstLine, bool isRootLineBox = false) const;
RenderLineBoxList* lineBoxes() { return &m_lineBoxes; }
const RenderLineBoxList* lineBoxes() const { return &m_lineBoxes; }
InlineFlowBox* firstLineBox() const { return m_lineBoxes.firstLineBox(); }
InlineFlowBox* lastLineBox() const { return m_lineBoxes.lastLineBox(); }
void deleteLineBoxTree();
virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0);
virtual void removeChild(RenderObject*);
virtual void layoutBlock(bool relayoutChildren);
void insertPositionedObject(RenderBox*);
void removePositionedObject(RenderBox*);
void removePositionedObjects(RenderBlock*);
typedef ListHashSet<RenderBox*, 4> PositionedObjectsListHashSet;
PositionedObjectsListHashSet* positionedObjects() const { return m_positionedObjects; }
void addPercentHeightDescendant(RenderBox*);
static void removePercentHeightDescendant(RenderBox*);
HashSet<RenderBox*>* percentHeightDescendants() const;
RootInlineBox* createAndAppendRootInlineBox();
bool generatesLineBoxesForInlineChild(RenderObject*, bool isLineEmpty = true, bool previousLineBrokeCleanly = true);
void markAllDescendantsWithFloatsForLayout(RenderBox* floatToRemove = 0, bool inLayout = true);
void markPositionedObjectsForLayout();
bool containsFloats() { return m_floatingObjects && !m_floatingObjects->isEmpty(); }
bool containsFloat(RenderObject*);
int lineWidth(int y, bool firstLine) const;
virtual int lowestPosition(bool includeOverflowInterior = true, bool includeSelf = true) const;
virtual int rightmostPosition(bool includeOverflowInterior = true, bool includeSelf = true) const;
virtual int leftmostPosition(bool includeOverflowInterior = true, bool includeSelf = true) const;
int rightOffset(int y, bool firstLine) const { return rightRelOffset(y, rightOffset(), firstLine); }
int leftOffset(int y, bool firstLine) const { return leftRelOffset(y, leftOffset(), firstLine); }
virtual VisiblePosition positionForPoint(const IntPoint&);
virtual int availableWidth() const;
RootInlineBox* firstRootBox() const { return static_cast<RootInlineBox*>(firstLineBox()); }
RootInlineBox* lastRootBox() const { return static_cast<RootInlineBox*>(lastLineBox()); }
bool containsNonZeroBidiLevel() const;
virtual void setSelectionState(SelectionState s);
GapRects selectionGapRectsForRepaint(RenderBoxModelObject* repaintContainer);
IntRect fillLeftSelectionGap(RenderObject* selObj, int xPos, int yPos, int height, RenderBlock* rootBlock,
int blockX, int blockY, int tx, int ty, const PaintInfo*);
IntRect fillRightSelectionGap(RenderObject* selObj, int xPos, int yPos, int height, RenderBlock* rootBlock,
int blockX, int blockY, int tx, int ty, const PaintInfo*);
IntRect fillHorizontalSelectionGap(RenderObject* selObj, int xPos, int yPos, int width, int height, const PaintInfo*);
void getHorizontalSelectionGapInfo(SelectionState, bool& leftGap, bool& rightGap);
RootInlineBox* lineAtIndex(int);
int lineCount();
int heightForLineCount(int);
void clearTruncation();
void adjustRectForColumns(IntRect&) const;
virtual void adjustForColumns(IntSize&, const IntPoint&) const;
void addContinuationWithOutline(RenderInline*);
RenderInline* inlineContinuation() const { return m_inlineContinuation; }
void setInlineContinuation(RenderInline* c) { m_inlineContinuation = c; }
RenderBlock* createAnonymousBlock(bool isFlexibleBox = false) const;
static void appendRunsForObject(int start, int end, RenderObject*, InlineBidiResolver&);
static bool requiresLineBox(const InlineIterator&, bool isLineEmpty = true, bool previousLineBrokeCleanly = true);
int immediateLineCount();
void adjustComputedFontSizes(float size, float visibleWidth);
void resetComputedFontSize() {
m_widthForTextAutosizing = -1;
m_lineCountForTextAutosizing = NOT_SET;
}
virtual void updateFirstLetter();
protected:
void moveChildTo(RenderObject* to, RenderObjectChildList* toChildList, RenderObject* child);
void moveChildTo(RenderObject* to, RenderObjectChildList* toChildList, RenderObject* beforeChild, RenderObject* child);
void moveAllChildrenTo(RenderObject* to, RenderObjectChildList* toChildList);
void moveAllChildrenTo(RenderObject* to, RenderObjectChildList* toChildList, RenderObject* beforeChild);
int maxTopPosMargin() const { return m_maxMargin ? m_maxMargin->m_topPos : MaxMargin::topPosDefault(this); }
int maxTopNegMargin() const { return m_maxMargin ? m_maxMargin->m_topNeg : MaxMargin::topNegDefault(this); }
int maxBottomPosMargin() const { return m_maxMargin ? m_maxMargin->m_bottomPos : MaxMargin::bottomPosDefault(this); }
int maxBottomNegMargin() const { return m_maxMargin ? m_maxMargin->m_bottomNeg : MaxMargin::bottomNegDefault(this); }
void setMaxTopMargins(int pos, int neg);
void setMaxBottomMargins(int pos, int neg);
void initMaxMarginValues()
{
if (m_maxMargin) {
m_maxMargin->m_topPos = MaxMargin::topPosDefault(this);
m_maxMargin->m_topNeg = MaxMargin::topNegDefault(this);
m_maxMargin->m_bottomPos = MaxMargin::bottomPosDefault(this);
m_maxMargin->m_bottomNeg = MaxMargin::bottomNegDefault(this);
}
}
virtual void layout();
void layoutPositionedObjects(bool relayoutChildren);
virtual void paint(PaintInfo&, int tx, int ty);
virtual void paintObject(PaintInfo&, int tx, int ty);
int rightRelOffset(int y, int fixedOffset, bool applyTextIndent = true, int* heightRemaining = 0) const;
int leftRelOffset(int y, int fixedOffset, bool applyTextIndent = true, int* heightRemaining = 0) const;
virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction);
virtual void calcPrefWidths();
virtual int firstLineBoxBaseline() const;
virtual int lastLineBoxBaseline() const;
virtual void updateHitTestResult(HitTestResult&, const IntPoint&);
static void startDelayUpdateScrollInfo();
static void finishDelayUpdateScrollInfo();
virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle);
virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
virtual bool hasLineIfEmpty() const;
bool layoutOnlyPositionedObjects();
private:
virtual RenderObjectChildList* virtualChildren() { return children(); }
virtual const RenderObjectChildList* virtualChildren() const { return children(); }
virtual const char* renderName() const;
virtual bool isRenderBlock() const { return true; }
virtual bool isBlockFlow() const { return (!isInline() || isReplaced()) && !isTable(); }
virtual bool isInlineBlockOrInlineTable() const { return isInline() && isReplaced(); }
void makeChildrenNonInline(RenderObject* insertionPoint = 0);
virtual void removeLeftoverAnonymousBlock(RenderBlock* child);
virtual void dirtyLinesFromChangedChild(RenderObject* child) { m_lineBoxes.dirtyLinesFromChangedChild(this, child); }
virtual bool isSelfCollapsingBlock() const;
virtual int maxTopMargin(bool positive) const { return positive ? maxTopPosMargin() : maxTopNegMargin(); }
virtual int maxBottomMargin(bool positive) const { return positive ? maxBottomPosMargin() : maxBottomNegMargin(); }
virtual void repaintOverhangingFloats(bool paintAllDescendants);
void layoutBlockChildren(bool relayoutChildren, int& maxFloatBottom);
void layoutInlineChildren(bool relayoutChildren, int& repaintTop, int& repaintBottom);
virtual void positionListMarker() { }
virtual void borderFitAdjust(int& x, int& w) const;
virtual void updateBeforeAfterContent(PseudoId);
virtual RootInlineBox* createRootInlineBox();
virtual RenderObject* layoutLegend(bool ) { return 0; }
struct FloatWithRect {
FloatWithRect(RenderBox* f)
: object(f)
, rect(IntRect(f->x() - f->marginLeft(), f->y() - f->marginTop(), f->width() + f->marginLeft() + f->marginRight(), f->height() + f->marginTop() + f->marginBottom()))
, everHadLayout(f->m_everHadLayout)
{
}
RenderBox* object;
IntRect rect;
bool everHadLayout;
};
void bidiReorderLine(InlineBidiResolver&, const InlineIterator& end, bool previousLineBrokeCleanly);
RootInlineBox* determineStartPosition(bool& firstLine, bool& fullLayout, bool& previousLineBrokeCleanly,
InlineBidiResolver&, Vector<FloatWithRect>& floats, unsigned& numCleanFloats);
RootInlineBox* determineEndPosition(RootInlineBox* startBox, InlineIterator& cleanLineStart,
BidiStatus& cleanLineBidiStatus,
int& yPos);
bool matchedEndLine(const InlineBidiResolver&, const InlineIterator& endLineStart, const BidiStatus& endLineStatus,
RootInlineBox*& endLine, int& endYPos, int& repaintBottom, int& repaintTop);
void skipTrailingWhitespace(InlineIterator&, bool isLineEmpty, bool previousLineBrokeCleanly);
int skipLeadingWhitespace(InlineBidiResolver&, bool firstLine, bool isLineEmpty, bool previousLineBrokeCleanly);
void fitBelowFloats(int widthToFit, bool firstLine, int& availableWidth);
InlineIterator findNextLineBreak(InlineBidiResolver&, bool firstLine, bool& isLineEmpty, bool& previousLineBrokeCleanly, bool& hyphenated, EClear* = 0);
RootInlineBox* constructLine(unsigned runCount, BidiRun* firstRun, BidiRun* lastRun, bool firstLine, bool lastLine, RenderObject* endObject);
InlineFlowBox* createLineBoxes(RenderObject*, bool firstLine);
void computeHorizontalPositionsForLine(RootInlineBox*, bool firstLine, BidiRun* firstRun, BidiRun* trailingSpaceRun, bool reachedEnd);
void computeVerticalPositionsForLine(RootInlineBox*, BidiRun*);
void deleteEllipsisLineBoxes();
void checkLinesForTextOverflow();
void addOverflowFromInlineChildren();
void addOverflowFromBlockChildren();
void addOverflowFromFloats();
void paintFloats(PaintInfo&, int tx, int ty, bool preservePhase = false);
void paintContents(PaintInfo&, int tx, int ty);
void paintColumnContents(PaintInfo&, int tx, int ty, bool paintFloats = false);
void paintColumnRules(PaintInfo&, int tx, int ty);
void paintChildren(PaintInfo&, int tx, int ty);
void paintEllipsisBoxes(PaintInfo&, int tx, int ty);
void paintSelection(PaintInfo&, int tx, int ty);
void paintCaret(PaintInfo&, int tx, int ty, CaretType);
void insertFloatingObject(RenderBox*);
void removeFloatingObject(RenderBox*);
bool positionNewFloats();
void clearFloats();
int getClearDelta(RenderBox* child, int yPos);
virtual bool avoidsFloats() const;
bool hasOverhangingFloats() { return parent() && !hasColumns() && floatBottom() > height(); }
void addIntrudingFloats(RenderBlock* prev, int xoffset, int yoffset);
int addOverhangingFloats(RenderBlock* child, int xoffset, int yoffset, bool makeChildPaintOtherFloats);
int nextFloatBottomBelow(int) const;
int floatBottom() const;
inline int leftBottom();
inline int rightBottom();
int rightOffset() const;
int leftOffset() const;
virtual bool hitTestColumns(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction);
virtual bool hitTestContents(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction);
bool hitTestFloats(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty);
virtual bool isPointInOverflowControl(HitTestResult&, int x, int y, int tx, int ty);
void calcInlinePrefWidths();
void calcBlockPrefWidths();
virtual RenderBlock* firstLineBlock() const;
virtual IntRect rectWithOutlineForRepaint(RenderBoxModelObject* repaintContainer, int outlineWidth);
virtual RenderStyle* outlineStyleForRepaint() const;
virtual RenderObject* hoverAncestor() const;
virtual void updateDragState(bool dragOn);
virtual void childBecameNonInline(RenderObject* child);
virtual IntRect selectionRectForRepaint(RenderBoxModelObject* repaintContainer, bool )
{
return selectionGapRectsForRepaint(repaintContainer);
}
virtual bool shouldPaintSelectionGaps() const;
bool isSelectionRoot() const;
GapRects fillSelectionGaps(RenderBlock* rootBlock, int blockX, int blockY, int tx, int ty,
int& lastTop, int& lastLeft, int& lastRight, const PaintInfo* = 0);
GapRects fillInlineSelectionGaps(RenderBlock* rootBlock, int blockX, int blockY, int tx, int ty,
int& lastTop, int& lastLeft, int& lastRight, const PaintInfo*);
GapRects fillBlockSelectionGaps(RenderBlock* rootBlock, int blockX, int blockY, int tx, int ty,
int& lastTop, int& lastLeft, int& lastRight, const PaintInfo*);
IntRect fillVerticalSelectionGap(int lastTop, int lastLeft, int lastRight, int bottomY, RenderBlock* rootBlock,
int blockX, int blockY, const PaintInfo*);
public:
int leftSelectionOffset(RenderBlock* rootBlock, int y);
int rightSelectionOffset(RenderBlock* rootBlock, int y);
private:
virtual void absoluteRects(Vector<IntRect>&, int tx, int ty);
virtual void absoluteQuads(Vector<FloatQuad>&);
int desiredColumnWidth() const;
unsigned desiredColumnCount() const;
Vector<IntRect>* columnRects() const;
void setDesiredColumnCountAndWidth(int count, int width);
int columnGap() const;
void paintContinuationOutlines(PaintInfo&, int tx, int ty);
virtual IntRect localCaretRect(InlineBox*, int caretOffset, int* extraWidthToEndOfLine = 0);
virtual void addFocusRingRects(Vector<IntRect>&, int tx, int ty);
void adjustPointToColumnContents(IntPoint&) const;
void adjustForBorderFit(int x, int& left, int& right) const;
void markLinesDirtyInVerticalRange(int top, int bottom, RootInlineBox* highest = 0);
void newLine(EClear);
Position positionForBox(InlineBox*, bool start = true) const;
Position positionForRenderer(RenderObject*, bool start = true) const;
VisiblePosition positionForPointWithInlineChildren(const IntPoint&);
void offsetForContents(int& tx, int& ty) const;
void calcColumnWidth();
int layoutColumns(int endOfContent = -1, int requestedColumnHeight = -1);
int visibleTopOfHighestFloatExtendingBelow(int bottom, int maxHeight) const;
bool expandsToEncloseOverhangingFloats() const;
void updateScrollInfoAfterLayout();
struct FloatingObject : Noncopyable {
enum Type {
FloatLeft,
FloatRight
};
FloatingObject(Type type)
: m_renderer(0)
, m_top(0)
, m_bottom(0)
, m_left(0)
, m_width(0)
, m_type(type)
, m_shouldPaint(true)
, m_isDescendant(false)
{
}
Type type() { return static_cast<Type>(m_type); }
RenderBox* m_renderer;
int m_top;
int m_bottom;
int m_left;
int m_width;
unsigned m_type : 1; bool m_shouldPaint : 1;
bool m_isDescendant : 1;
};
class MarginInfo {
bool m_canCollapseWithChildren : 1;
bool m_canCollapseTopWithChildren : 1;
bool m_canCollapseBottomWithChildren : 1;
bool m_quirkContainer : 1;
bool m_atTopOfBlock : 1;
bool m_atBottomOfBlock : 1;
bool m_topQuirk : 1;
bool m_bottomQuirk : 1;
bool m_determinedTopQuirk : 1;
int m_posMargin;
int m_negMargin;
public:
MarginInfo(RenderBlock* b, int top, int bottom);
void setAtTopOfBlock(bool b) { m_atTopOfBlock = b; }
void setAtBottomOfBlock(bool b) { m_atBottomOfBlock = b; }
void clearMargin() { m_posMargin = m_negMargin = 0; }
void setTopQuirk(bool b) { m_topQuirk = b; }
void setBottomQuirk(bool b) { m_bottomQuirk = b; }
void setDeterminedTopQuirk(bool b) { m_determinedTopQuirk = b; }
void setPosMargin(int p) { m_posMargin = p; }
void setNegMargin(int n) { m_negMargin = n; }
void setPosMarginIfLarger(int p) { if (p > m_posMargin) m_posMargin = p; }
void setNegMarginIfLarger(int n) { if (n > m_negMargin) m_negMargin = n; }
void setMargin(int p, int n) { m_posMargin = p; m_negMargin = n; }
bool atTopOfBlock() const { return m_atTopOfBlock; }
bool canCollapseWithTop() const { return m_atTopOfBlock && m_canCollapseTopWithChildren; }
bool canCollapseWithBottom() const { return m_atBottomOfBlock && m_canCollapseBottomWithChildren; }
bool canCollapseTopWithChildren() const { return m_canCollapseTopWithChildren; }
bool canCollapseBottomWithChildren() const { return m_canCollapseBottomWithChildren; }
bool quirkContainer() const { return m_quirkContainer; }
bool determinedTopQuirk() const { return m_determinedTopQuirk; }
bool topQuirk() const { return m_topQuirk; }
bool bottomQuirk() const { return m_bottomQuirk; }
int posMargin() const { return m_posMargin; }
int negMargin() const { return m_negMargin; }
int margin() const { return m_posMargin - m_negMargin; }
};
void layoutBlockChild(RenderBox* child, MarginInfo&, int& previousFloatBottom, int& maxFloatBottom);
void adjustPositionedBlock(RenderBox* child, const MarginInfo&);
void adjustFloatingBlock(const MarginInfo&);
bool handleSpecialChild(RenderBox* child, const MarginInfo&);
bool handleFloatingChild(RenderBox* child, const MarginInfo&);
bool handlePositionedChild(RenderBox* child, const MarginInfo&);
bool handleRunInChild(RenderBox* child);
int collapseMargins(RenderBox* child, MarginInfo&);
int clearFloatsIfNeeded(RenderBox* child, MarginInfo&, int oldTopPosMargin, int oldTopNegMargin, int yPos);
int estimateVerticalPosition(RenderBox* child, const MarginInfo&);
void determineHorizontalPosition(RenderBox* child);
void handleBottomOfBlock(int top, int bottom, MarginInfo&);
void setCollapsedBottomMargin(const MarginInfo&);
typedef PositionedObjectsListHashSet::const_iterator Iterator;
DeprecatedPtrList<FloatingObject>* m_floatingObjects;
PositionedObjectsListHashSet* m_positionedObjects;
RenderInline* m_inlineContinuation;
struct MaxMargin : Noncopyable {
MaxMargin(const RenderBlock* o)
: m_topPos(topPosDefault(o))
, m_topNeg(topNegDefault(o))
, m_bottomPos(bottomPosDefault(o))
, m_bottomNeg(bottomNegDefault(o))
{
}
static int topPosDefault(const RenderBlock* o) { return o->marginTop() > 0 ? o->marginTop() : 0; }
static int topNegDefault(const RenderBlock* o) { return o->marginTop() < 0 ? -o->marginTop() : 0; }
static int bottomPosDefault(const RenderBlock* o) { return o->marginBottom() > 0 ? o->marginBottom() : 0; }
static int bottomNegDefault(const RenderBlock* o) { return o->marginBottom() < 0 ? -o->marginBottom() : 0; }
int m_topPos;
int m_topNeg;
int m_bottomPos;
int m_bottomNeg;
};
MaxMargin* m_maxMargin;
RenderObjectChildList m_children;
RenderLineBoxList m_lineBoxes;
mutable int m_lineHeight;
int m_widthForTextAutosizing;
unsigned m_lineCountForTextAutosizing : 2;
friend class RenderRubyBase;
};
inline RenderBlock* toRenderBlock(RenderObject* object)
{
ASSERT(!object || object->isRenderBlock());
return static_cast<RenderBlock*>(object);
}
inline const RenderBlock* toRenderBlock(const RenderObject* object)
{
ASSERT(!object || object->isRenderBlock());
return static_cast<const RenderBlock*>(object);
}
void toRenderBlock(const RenderBlock*);
}
#endif // RenderBlock_h