#ifndef RenderBlock_H
#define RenderBlock_H
#include "GapRects.h"
#include "RenderFlow.h"
#include "RootInlineBox.h"
namespace WebCore {
class Position;
class RootInlineBox;
enum CaretType {
CursorCaret,
DragCaret,
};
class RenderBlock : public RenderFlow {
public:
RenderBlock(Node*);
virtual ~RenderBlock();
virtual const char *renderName() const;
virtual short lineHeight(bool b, bool isRootLineBox=false) const;
virtual short baselinePosition(bool b, bool isRootLineBox=false) const;
virtual bool isRenderBlock() const { return true; }
virtual bool isBlockFlow() const { return (!isInline() || isReplaced()) && !isTable(); }
virtual bool isInlineFlow() const { return isInline() && !isReplaced(); }
virtual bool isInlineBlockOrInlineTable() const { return isInline() && isReplaced(); }
virtual bool childrenInline() const { return m_childrenInline; }
virtual void setChildrenInline(bool b) { m_childrenInline = b; }
void makeChildrenNonInline(RenderObject* insertionPoint = 0);
void deleteLineBoxTree();
virtual int overflowHeight(bool includeInterior=true) const;
virtual int overflowWidth(bool includeInterior=true) const;
virtual int overflowLeft(bool includeInterior=true) const;
virtual int overflowTop(bool includeInterior=true) const;
virtual IntRect overflowRect(bool includeInterior=true) const;
virtual void setOverflowHeight(int h) { m_overflowHeight = h; }
virtual void setOverflowWidth(int w) { m_overflowWidth = w; }
virtual bool isSelfCollapsingBlock() const;
virtual bool isTopMarginQuirk() const { return m_topMarginQuirk; }
virtual bool isBottomMarginQuirk() const { return m_bottomMarginQuirk; }
virtual int maxTopMargin(bool positive) const {
if (positive)
return m_maxTopPosMargin;
else
return m_maxTopNegMargin;
}
virtual int maxBottomMargin(bool positive) const {
if (positive)
return m_maxBottomPosMargin;
else
return m_maxBottomNegMargin;
}
void initMaxMarginValues() {
if (m_marginTop >= 0) {
m_maxTopPosMargin = m_marginTop;
m_maxTopNegMargin = 0;
} else {
m_maxTopNegMargin = -m_marginTop;
m_maxTopPosMargin = 0;
}
if (m_marginBottom >= 0) {
m_maxBottomPosMargin = m_marginBottom;
m_maxBottomNegMargin = 0;
} else {
m_maxBottomNegMargin = -m_marginBottom;
m_maxBottomPosMargin = 0;
}
}
virtual void addChildToFlow(RenderObject* newChild, RenderObject* beforeChild);
virtual void removeChild(RenderObject*);
virtual void repaintObjectsBeforeLayout();
virtual void repaintOverhangingFloats(bool paintAllDescendants);
virtual void getAbsoluteRepaintRectIncludingFloats(IntRect& bounds, IntRect& fullBounds);
virtual void setStyle(RenderStyle*);
virtual void layout();
virtual void layoutBlock(bool relayoutChildren);
void layoutBlockChildren(bool relayoutChildren);
IntRect layoutInlineChildren(bool relayoutChildren);
void layoutPositionedObjects( bool relayoutChildren );
void insertPositionedObject(RenderObject *o);
void removePositionedObject(RenderObject *o);
virtual void removePositionedObjects(RenderBlock*);
virtual void positionListMarker() { }
virtual RenderObject* layoutLegend(bool relayoutChildren) { return 0; };
void bidiReorderLine(const BidiIterator& start, const BidiIterator& end, BidiState &bidi );
RootInlineBox* determineStartPosition(bool fullLayout, BidiIterator& start, BidiState &bidi);
RootInlineBox* determineEndPosition(RootInlineBox* startBox, BidiIterator& cleanLineStart,
BidiStatus& cleanLineBidiStatus, BidiContext*& cleanLineBidiContext,
int& yPos);
bool matchedEndLine(const BidiIterator& start, const BidiStatus& status, BidiContext* context,
const BidiIterator& endLineStart, const BidiStatus& endLineStatus,
BidiContext* endLineContext, RootInlineBox*& endLine, int& endYPos);
int skipWhitespace(BidiIterator& , BidiState &);
BidiIterator findNextLineBreak(BidiIterator& start, BidiState &info );
RootInlineBox* constructLine(const BidiIterator& start, const BidiIterator& end);
InlineFlowBox* createLineBoxes(RenderObject* obj);
int tabWidth(bool isWhitespacePre);
void computeHorizontalPositionsForLine(RootInlineBox* lineBox, BidiState &bidi);
void computeVerticalPositionsForLine(RootInlineBox* lineBox);
void checkLinesForOverflow();
void deleteEllipsisLineBoxes();
void checkLinesForTextOverflow();
virtual void paint(PaintInfo& i, int tx, int ty);
virtual void paintObject(PaintInfo& i, int tx, int ty);
void paintFloats(PaintInfo& i, int _tx, int _ty, bool paintSelection = false);
void paintChildren(PaintInfo& i, int _tx, int _ty);
void paintEllipsisBoxes(PaintInfo& i, int _tx, int _ty);
void paintSelection(PaintInfo& i, int _tx, int _ty);
void paintCaret(PaintInfo& i, CaretType);
void insertFloatingObject(RenderObject *o);
void removeFloatingObject(RenderObject *o);
void setPaintsFloatingObject(RenderObject*, bool);
void positionNewFloats();
void clearFloats();
int getClearDelta(RenderObject *child);
virtual void markAllDescendantsWithFloatsForLayout(RenderObject* floatToRemove = 0);
void markPositionedObjectsForLayout();
virtual bool containsFloats() { return m_floatingObjects!=0; }
virtual bool containsFloat(RenderObject* o);
virtual bool hasOverhangingFloats() { return floatBottom() > m_height; }
void addIntrudingFloats(RenderBlock* prev, int xoffset, int yoffset);
void addOverhangingFloats(RenderBlock* child, int xoffset, int yoffset);
int nearestFloatBottom(int height) const;
int floatBottom() const;
inline int leftBottom();
inline int rightBottom();
virtual IntRect floatRect() const;
virtual int lineWidth(int y) 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() const;
int rightRelOffset(int y, int fixedOffset, bool applyTextIndent = true,
int *heightRemaining = 0) const;
int rightOffset(int y) const { return rightRelOffset(y, rightOffset(), true); }
int leftOffset() const;
int leftRelOffset(int y, int fixedOffset, bool applyTextIndent = true,
int *heightRemaining = 0) const;
int leftOffset(int y) const { return leftRelOffset(y, leftOffset(), true); }
virtual bool nodeAtPoint(NodeInfo& info, int x, int y, int tx, int ty,
HitTestAction hitTestAction);
bool isPointInScrollbar(int x, int y, int tx, int ty);
virtual VisiblePosition positionForCoordinates(int x, int y);
virtual void calcMinMaxWidth();
void calcInlineMinMaxWidth();
void calcBlocminMaxWidth();
virtual int getBaselineOfFirstLineBox() const;
virtual int getBaselineOfLastLineBox() const;
RootInlineBox* firstRootBox() const { return static_cast<RootInlineBox*>(m_firstLineBox); }
RootInlineBox* lastRootBox() const { return static_cast<RootInlineBox*>(m_lastLineBox); }
virtual RenderBlock* firstLineBlock() const;
virtual void updateFirstLetter();
bool inRootBlockContext() const;
void setHasMarkupTruncation(bool b=true) { m_hasMarkupTruncation = b; }
bool hasMarkupTruncation() const { return m_hasMarkupTruncation; }
virtual bool hasSelectedChildren() const { return m_selectionState != SelectionNone; }
virtual SelectionState selectionState() const { return static_cast<SelectionState>(m_selectionState); }
virtual void setSelectionState(SelectionState s);
struct BlockSelectionInfo {
RenderBlock* m_block;
GapRects m_rects;
SelectionState m_state;
BlockSelectionInfo() { m_block = 0; m_state = SelectionNone; }
BlockSelectionInfo(RenderBlock* b) {
m_block = b;
m_state = m_block->selectionState();
m_rects = m_block->selectionGapRects();
}
GapRects rects() const { return m_rects; }
SelectionState state() const { return m_state; }
RenderBlock* block() const { return m_block; }
};
virtual IntRect selectionRect() { return selectionGapRects(); }
GapRects selectionGapRects();
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* i = 0);
GapRects fillInlineSelectionGaps(RenderBlock* rootBlock, int blockX, int blockY, int tx, int ty,
int& lastTop, int& lastLeft, int& lastRight, const PaintInfo* i);
GapRects fillBlockSelectionGaps(RenderBlock* rootBlock, int blockX, int blockY, int tx, int ty,
int& lastTop, int& lastLeft, int& lastRight, const PaintInfo* i);
IntRect fillVerticalSelectionGap(int lastTop, int lastLeft, int lastRight,
int bottomY, RenderBlock* rootBlock, int blockX, int blockY, const PaintInfo* i);
IntRect fillLeftSelectionGap(RenderObject* selObj, int xPos, int yPos, int height, RenderBlock* rootBlock, int blockX, int blockY, int tx, int ty, const PaintInfo* i);
IntRect fillRightSelectionGap(RenderObject* selObj, int xPos, int yPos, int height, RenderBlock* rootBlock, int blockX, int blockY, int tx, int ty, const PaintInfo* i);
IntRect fillHorizontalSelectionGap(RenderObject* selObj, int xPos, int yPos, int width, int height, const PaintInfo* i);
void getHorizontalSelectionGapInfo(SelectionState state, bool& leftGap, bool& rightGap);
int leftSelectionOffset(RenderBlock* rootBlock, int y);
int rightSelectionOffset(RenderBlock* rootBlock, int y);
#if !NDEBUG
virtual void dump(TextStream *stream, DeprecatedString ind = "") const;
#endif
RootInlineBox* lineAtIndex(int i);
int lineCount();
int heightForLineCount(int l);
void clearTruncation();
int immediateLineCount();
void adjustComputedFontSizes(float size, float visibleWidth);
protected:
void newLine();
private:
Position positionForBox(InlineBox *box, bool start=true) const;
Position positionForRenderer(RenderObject *renderer, bool start=true) const;
bool hasLineIfEmpty() const;
protected:
struct FloatingObject {
enum Type {
FloatLeft,
FloatRight
};
FloatingObject(Type type) {
node = 0;
startY = 0;
endY = 0;
m_type = type;
left = 0;
width = 0;
noPaint = false;
}
Type type() { return static_cast<Type>(m_type); }
RenderObject* node;
int startY;
int endY;
int left;
int width;
unsigned m_type : 1; bool noPaint : 1;
};
class CompactInfo {
RenderObject* m_compact;
RenderObject* m_block;
public:
RenderObject* compact() const { return m_compact; }
RenderObject* block() const { return m_block; }
bool matches(RenderObject* child) const { return m_compact && m_block == child; }
void clear() { set(0, 0); }
void set(RenderObject* c, RenderObject* b) { m_compact = c; m_block = b; }
CompactInfo() { clear(); }
};
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_selfCollapsingBlockClearedFloat : 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 setSelfCollapsingBlockClearedFloat(bool b) { m_selfCollapsingBlockClearedFloat = b; }
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 selfCollapsingBlockClearedFloat() const { return m_selfCollapsingBlockClearedFloat; }
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 adjustPositionedBlock(RenderObject* child, const MarginInfo& marginInfo);
void adjustFloatingBlock(const MarginInfo& marginInfo);
RenderObject* handleSpecialChild(RenderObject* child, const MarginInfo& marginInfo, CompactInfo& compactInfo, bool& handled);
RenderObject* handleFloatingChild(RenderObject* child, const MarginInfo& marginInfo, bool& handled);
RenderObject* handlePositionedChild(RenderObject* child, const MarginInfo& marginInfo, bool& handled);
RenderObject* handleCompactChild(RenderObject* child, CompactInfo& compactInfo, bool& handled);
RenderObject* handleRunInChild(RenderObject* child, bool& handled);
void collapseMargins(RenderObject* child, MarginInfo& marginInfo, int yPosEstimate);
void clearFloatsIfNeeded(RenderObject* child, MarginInfo& marginInfo, int oldTopPosMargin, int oldTopNegMargin);
void insertCompactIfNeeded(RenderObject* child, CompactInfo& compactInfo);
int estimateVerticalPosition(RenderObject* child, const MarginInfo& info);
void determineHorizontalPosition(RenderObject* child);
void handleBottomOfBlock(int top, int bottom, MarginInfo& marginInfo);
void setCollapsedBottomMargin(const MarginInfo& marginInfo);
protected:
DeprecatedPtrList<FloatingObject>* m_floatingObjects;
DeprecatedPtrList<RenderObject>* m_positionedObjects;
bool m_childrenInline : 1;
bool m_firstLine : 1;
unsigned m_clearStatus : 2; bool m_topMarginQuirk : 1;
bool m_bottomMarginQuirk : 1;
bool m_hasMarkupTruncation : 1;
unsigned m_selectionState : 3; unsigned m_lineCountForTextAutosizing : 2;
int m_maxTopPosMargin;
int m_maxTopNegMargin;
int m_maxBottomPosMargin;
int m_maxBottomNegMargin;
int m_overflowHeight;
int m_overflowWidth;
int m_overflowLeft;
int m_overflowTop;
int m_tabWidth;
int m_widthForTextAutosizing;
};
}
#endif // RENDER_BLOCK_H