2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2007 David Smith (catfish.man@gmail.com)
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
26 #include "DeprecatedPtrList.h"
28 #include "RenderBox.h"
29 #include "RenderLineBoxList.h"
30 #include "RootInlineBox.h"
31 #include <wtf/ListHashSet.h>
37 class LayoutStateMaintainer;
42 template <class Iterator, class Run> class BidiResolver;
43 template <class Iterator> struct MidpointState;
44 typedef BidiResolver<InlineIterator, BidiRun> InlineBidiResolver;
45 typedef MidpointState<InlineIterator> LineMidpointState;
47 enum CaretType { CursorCaret, DragCaret };
49 class RenderBlock : public RenderBox {
52 virtual ~RenderBlock();
54 const RenderObjectChildList* children() const { return &m_children; }
55 RenderObjectChildList* children() { return &m_children; }
57 virtual void destroy();
59 // These two functions are overridden for inline-block.
60 virtual int lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const;
61 virtual int baselinePosition(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const;
63 RenderLineBoxList* lineBoxes() { return &m_lineBoxes; }
64 const RenderLineBoxList* lineBoxes() const { return &m_lineBoxes; }
66 InlineFlowBox* firstLineBox() const { return m_lineBoxes.firstLineBox(); }
67 InlineFlowBox* lastLineBox() const { return m_lineBoxes.lastLineBox(); }
69 void deleteLineBoxTree();
71 virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0);
72 virtual void removeChild(RenderObject*);
74 virtual void layoutBlock(bool relayoutChildren, int pageHeight = 0);
76 void insertPositionedObject(RenderBox*);
77 void removePositionedObject(RenderBox*);
78 void removePositionedObjects(RenderBlock*);
80 typedef ListHashSet<RenderBox*, 4> PositionedObjectsListHashSet;
81 PositionedObjectsListHashSet* positionedObjects() const { return m_positionedObjects; }
83 void addPercentHeightDescendant(RenderBox*);
84 static void removePercentHeightDescendant(RenderBox*);
85 HashSet<RenderBox*>* percentHeightDescendants() const;
87 RootInlineBox* createAndAppendRootInlineBox();
89 bool generatesLineBoxesForInlineChild(RenderObject*, bool isLineEmpty = true, bool previousLineBrokeCleanly = true);
91 void markAllDescendantsWithFloatsForLayout(RenderBox* floatToRemove = 0, bool inLayout = true);
92 void markPositionedObjectsForLayout();
93 virtual void markForPaginationRelayoutIfNeeded();
95 bool containsFloats() { return m_floatingObjects && !m_floatingObjects->isEmpty(); }
96 bool containsFloat(RenderObject*);
98 int availableLogicalWidthForLine(int position, bool firstLine) const;
99 int logicalRightOffsetForLine(int position, bool firstLine) const { return logicalRightOffsetForLine(position, logicalRightOffsetForContent(), firstLine); }
100 int logicalLeftOffsetForLine(int position, bool firstLine) const { return logicalLeftOffsetForLine(position, logicalLeftOffsetForContent(), firstLine); }
102 virtual int topmostPosition(bool includeOverflowInterior = true, bool includeSelf = true, ApplyTransform = IncludeTransform) const;
103 virtual int lowestPosition(bool includeOverflowInterior = true, bool includeSelf = true, ApplyTransform = IncludeTransform) const;
104 virtual int rightmostPosition(bool includeOverflowInterior = true, bool includeSelf = true, ApplyTransform = IncludeTransform) const;
105 virtual int leftmostPosition(bool includeOverflowInterior = true, bool includeSelf = true, ApplyTransform = IncludeTransform) const;
107 virtual VisiblePosition positionForPoint(const IntPoint&);
109 // Block flows subclass availableWidth to handle multi column layout (shrinking the width available to children when laying out.)
110 virtual int availableLogicalWidth() const;
112 RootInlineBox* firstRootBox() const { return static_cast<RootInlineBox*>(firstLineBox()); }
113 RootInlineBox* lastRootBox() const { return static_cast<RootInlineBox*>(lastLineBox()); }
115 bool containsNonZeroBidiLevel() const;
117 GapRects selectionGapRectsForRepaint(RenderBoxModelObject* repaintContainer);
118 IntRect logicalLeftSelectionGap(RenderBlock* rootBlock, const IntPoint& rootBlockPhysicalPosition, const IntSize& offsetFromRootBlock,
119 RenderObject* selObj, int logicalLeft, int logicalTop, int logicalHeight, const PaintInfo*);
120 IntRect logicalRightSelectionGap(RenderBlock* rootBlock, const IntPoint& rootBlockPhysicalPosition, const IntSize& offsetFromRootBlock,
121 RenderObject* selObj, int logicalRight, int logicalTop, int logicalHeight, const PaintInfo*);
122 void getSelectionGapInfo(SelectionState, bool& leftGap, bool& rightGap);
123 IntRect logicalRectToPhysicalRect(const IntPoint& physicalPosition, const IntRect& logicalRect);
125 // Helper methods for computing line counts and heights for line counts.
126 RootInlineBox* lineAtIndex(int);
128 int heightForLineCount(int);
129 void clearTruncation();
131 void adjustRectForColumns(IntRect&) const;
132 virtual void adjustForColumns(IntSize&, const IntPoint&) const;
134 void addContinuationWithOutline(RenderInline*);
136 RenderBoxModelObject* continuation() const { return m_continuation; }
137 void setContinuation(RenderBoxModelObject* c) { m_continuation = c; }
138 virtual RenderBoxModelObject* virtualContinuation() const { return continuation(); }
139 bool isAnonymousBlockContinuation() const { return continuation() && isAnonymousBlock(); }
140 RenderInline* inlineElementContinuation() const;
141 RenderBlock* blockElementContinuation() const;
143 // This function is a convenience helper for creating an anonymous block that inherits its
144 // style from this RenderBlock.
145 RenderBlock* createAnonymousBlock(bool isFlexibleBox = false) const;
146 RenderBlock* createAnonymousColumnsBlock() const;
147 RenderBlock* createAnonymousColumnSpanBlock() const;
148 RenderBlock* createAnonymousBlockWithSameTypeAs(RenderBlock* otherAnonymousBlock) const;
150 static void appendRunsForObject(int start, int end, RenderObject*, InlineBidiResolver&);
151 static bool requiresLineBox(const InlineIterator&, bool isLineEmpty = true, bool previousLineBrokeCleanly = true);
153 ColumnInfo* columnInfo() const;
154 int columnGap() const;
156 // These two functions take the ColumnInfo* to avoid repeated lookups of the info in the global HashMap.
157 unsigned columnCount(ColumnInfo*) const;
158 IntRect columnRectAt(ColumnInfo*, unsigned) const;
160 int paginationStrut() const { return m_rareData ? m_rareData->m_paginationStrut : 0; }
161 int pageY() const { return m_rareData ? m_rareData->m_pageY : 0; }
162 void setPaginationStrut(int strut);
163 void setPageY(int y);
165 // Accessors for logical width/height and margins in the containing block's block-flow direction.
166 enum ApplyLayoutDeltaMode { ApplyLayoutDelta, DoNotApplyLayoutDelta };
167 int logicalWidthForChild(RenderBox* child) { return style()->isHorizontalWritingMode() ? child->width() : child->height(); }
168 int logicalHeightForChild(RenderBox* child) { return style()->isHorizontalWritingMode() ? child->height() : child->width(); }
169 int logicalTopForChild(RenderBox* child) { return style()->isHorizontalWritingMode() ? child->y() : child->x(); }
170 void setLogicalLeftForChild(RenderBox* child, int logicalLeft, ApplyLayoutDeltaMode = DoNotApplyLayoutDelta);
171 void setLogicalTopForChild(RenderBox* child, int logicalTop, ApplyLayoutDeltaMode = DoNotApplyLayoutDelta);
172 int marginBeforeForChild(RenderBoxModelObject* child) const;
173 int marginAfterForChild(RenderBoxModelObject* child) const;
174 int marginStartForChild(RenderBoxModelObject* child) const;
175 int marginEndForChild(RenderBoxModelObject* child) const;
176 void setMarginStartForChild(RenderBox* child, int);
177 void setMarginEndForChild(RenderBox* child, int);
178 void setMarginBeforeForChild(RenderBox* child, int);
179 void setMarginAfterForChild(RenderBox* child, int);
180 int collapsedMarginBeforeForChild(RenderBox* child) const;
181 int collapsedMarginAfterForChild(RenderBox* child) const;
183 virtual void updateFirstLetter();
187 MarginValues(int beforePos, int beforeNeg, int afterPos, int afterNeg)
188 : m_positiveMarginBefore(beforePos)
189 , m_negativeMarginBefore(beforeNeg)
190 , m_positiveMarginAfter(afterPos)
191 , m_negativeMarginAfter(afterNeg)
194 int positiveMarginBefore() const { return m_positiveMarginBefore; }
195 int negativeMarginBefore() const { return m_negativeMarginBefore; }
196 int positiveMarginAfter() const { return m_positiveMarginAfter; }
197 int negativeMarginAfter() const { return m_negativeMarginAfter; }
199 void setPositiveMarginBefore(int pos) { m_positiveMarginBefore = pos; }
200 void setNegativeMarginBefore(int neg) { m_negativeMarginBefore = neg; }
201 void setPositiveMarginAfter(int pos) { m_positiveMarginAfter = pos; }
202 void setNegativeMarginAfter(int neg) { m_negativeMarginAfter = neg; }
205 int m_positiveMarginBefore;
206 int m_negativeMarginBefore;
207 int m_positiveMarginAfter;
208 int m_negativeMarginAfter;
210 MarginValues marginValuesForChild(RenderBox* child);
213 // These functions are only used internally to manipulate the render tree structure via remove/insert/appendChildNode.
214 // Since they are typically called only to move objects around within anonymous blocks (which only have layers in
215 // the case of column spans), the default for fullRemoveInsert is false rather than true.
216 void moveChildTo(RenderBlock* to, RenderObject* child, bool fullRemoveInsert = false)
218 return moveChildTo(to, child, 0, fullRemoveInsert);
220 void moveChildTo(RenderBlock* to, RenderObject* child, RenderObject* beforeChild, bool fullRemoveInsert = false);
221 void moveAllChildrenTo(RenderBlock* to, bool fullRemoveInsert = false)
223 return moveAllChildrenTo(to, 0, fullRemoveInsert);
225 void moveAllChildrenTo(RenderBlock* to, RenderObject* beforeChild, bool fullRemoveInsert = false)
227 return moveChildrenTo(to, firstChild(), 0, beforeChild, fullRemoveInsert);
229 // Move all of the kids from |startChild| up to but excluding |endChild|. 0 can be passed as the endChild to denote
230 // that all the kids from |startChild| onwards should be added.
231 void moveChildrenTo(RenderBlock* to, RenderObject* startChild, RenderObject* endChild, bool fullRemoveInsert = false)
233 return moveChildrenTo(to, startChild, endChild, 0, fullRemoveInsert);
235 void moveChildrenTo(RenderBlock* to, RenderObject* startChild, RenderObject* endChild, RenderObject* beforeChild, bool fullRemoveInsert = false);
237 int maxPositiveMarginBefore() const { return m_rareData ? m_rareData->m_margins.positiveMarginBefore() : RenderBlockRareData::positiveMarginBeforeDefault(this); }
238 int maxNegativeMarginBefore() const { return m_rareData ? m_rareData->m_margins.negativeMarginBefore() : RenderBlockRareData::negativeMarginBeforeDefault(this); }
239 int maxPositiveMarginAfter() const { return m_rareData ? m_rareData->m_margins.positiveMarginAfter() : RenderBlockRareData::positiveMarginAfterDefault(this); }
240 int maxNegativeMarginAfter() const { return m_rareData ? m_rareData->m_margins.negativeMarginAfter() : RenderBlockRareData::negativeMarginAfterDefault(this); }
242 void setMaxMarginBeforeValues(int pos, int neg);
243 void setMaxMarginAfterValues(int pos, int neg);
245 void initMaxMarginValues()
248 m_rareData->m_margins = MarginValues(RenderBlockRareData::positiveMarginBeforeDefault(this) , RenderBlockRareData::negativeMarginBeforeDefault(this),
249 RenderBlockRareData::positiveMarginAfterDefault(this), RenderBlockRareData::negativeMarginAfterDefault(this));
250 m_rareData->m_paginationStrut = 0;
254 virtual void layout();
256 void layoutPositionedObjects(bool relayoutChildren);
258 virtual void paint(PaintInfo&, int tx, int ty);
259 virtual void paintObject(PaintInfo&, int tx, int ty);
261 int logicalRightOffsetForContent() const { return style()->isHorizontalWritingMode() ? borderLeft() + paddingLeft() + availableLogicalWidth() : borderTop() + paddingTop() + availableLogicalWidth(); }
262 int logicalLeftOffsetForContent() const { return style()->isHorizontalWritingMode() ? borderLeft() + paddingLeft() : borderTop() + paddingTop(); }
263 int logicalRightOffsetForLine(int position, int fixedOffset, bool applyTextIndent = true, int* logicalHeightRemaining = 0) const;
264 int logicalLeftOffsetForLine(int position, int fixedOffset, bool applyTextIndent = true, int* logicalHeightRemaining = 0) const;
266 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction);
268 virtual void computePreferredLogicalWidths();
270 virtual int firstLineBoxBaseline() const;
271 virtual int lastLineBoxBaseline() const;
273 virtual void updateHitTestResult(HitTestResult&, const IntPoint&);
275 // Delay update scrollbar until finishDelayRepaint() will be
276 // called. This function is used when a flexbox is laying out its
277 // descendant. If multiple calls are made to startDelayRepaint(),
278 // finishDelayRepaint() will do nothing until finishDelayRepaint()
279 // is called the same number of times.
280 static void startDelayUpdateScrollInfo();
281 static void finishDelayUpdateScrollInfo();
283 virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle);
284 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
286 virtual bool hasLineIfEmpty() const;
287 bool layoutOnlyPositionedObjects();
292 // Only used by RenderSVGText, which explicitely overrides RenderBlock::layoutBlock(), do NOT use for anything else.
293 void forceLayoutInlineChildren()
295 int repaintLogicalTop = 0;
296 int repaintLogicalBottom = 0;
297 layoutInlineChildren(true, repaintLogicalTop, repaintLogicalBottom);
302 virtual RenderObjectChildList* virtualChildren() { return children(); }
303 virtual const RenderObjectChildList* virtualChildren() const { return children(); }
305 virtual const char* renderName() const;
307 virtual bool isRenderBlock() const { return true; }
308 virtual bool isBlockFlow() const { return (!isInline() || isReplaced()) && !isTable(); }
309 virtual bool isInlineBlockOrInlineTable() const { return isInline() && isReplaced(); }
311 void makeChildrenNonInline(RenderObject* insertionPoint = 0);
312 virtual void removeLeftoverAnonymousBlock(RenderBlock* child);
314 virtual void dirtyLinesFromChangedChild(RenderObject* child) { m_lineBoxes.dirtyLinesFromChangedChild(this, child); }
316 void addChildToContinuation(RenderObject* newChild, RenderObject* beforeChild);
317 void addChildIgnoringContinuation(RenderObject* newChild, RenderObject* beforeChild);
318 void addChildToAnonymousColumnBlocks(RenderObject* newChild, RenderObject* beforeChild);
319 virtual void addChildIgnoringAnonymousColumnBlocks(RenderObject* newChild, RenderObject* beforeChild = 0);
321 virtual bool isSelfCollapsingBlock() const;
323 virtual int collapsedMarginBefore() const { return maxPositiveMarginBefore() - maxNegativeMarginBefore(); }
324 virtual int collapsedMarginAfter() const { return maxPositiveMarginAfter() - maxNegativeMarginAfter(); }
326 virtual void repaintOverhangingFloats(bool paintAllDescendants);
328 void layoutBlockChildren(bool relayoutChildren, int& maxFloatLogicalBottom);
329 void layoutInlineChildren(bool relayoutChildren, int& repaintLogicalTop, int& repaintLogicalBottom);
331 virtual void positionListMarker() { }
333 virtual void borderFitAdjust(int& x, int& w) const; // Shrink the box in which the border paints if border-fit is set.
335 virtual void updateBeforeAfterContent(PseudoId);
337 virtual RootInlineBox* createRootInlineBox(); // Subclassed by SVG and Ruby.
339 // Called to lay out the legend for a fieldset.
340 virtual RenderObject* layoutLegend(bool /*relayoutChildren*/) { return 0; }
342 struct FloatWithRect {
343 FloatWithRect(RenderBox* f)
345 , rect(IntRect(f->x() - f->marginLeft(), f->y() - f->marginTop(), f->width() + f->marginLeft() + f->marginRight(), f->height() + f->marginTop() + f->marginBottom()))
346 , everHadLayout(f->m_everHadLayout)
355 struct FloatingObject : Noncopyable {
356 // Note that Type uses bits so you can use FloatBoth as a mask to query for both left and right.
357 enum Type { FloatLeft = 1, FloatRight = 2, FloatBoth = 3 };
359 FloatingObject(Type type)
361 , m_paginationStrut(0)
363 , m_shouldPaint(true)
364 , m_isDescendant(false)
369 FloatingObject(Type type, const IntRect& frameRect)
371 , m_frameRect(frameRect)
372 , m_paginationStrut(0)
374 , m_shouldPaint(true)
375 , m_isDescendant(false)
380 Type type() const { return static_cast<Type>(m_type); }
381 RenderBox* renderer() const { return m_renderer; }
383 bool isPlaced() const { return m_isPlaced; }
384 void setIsPlaced(bool placed = true) { m_isPlaced = placed; }
386 int left() const { ASSERT(isPlaced()); return m_frameRect.x(); }
387 int right() const { ASSERT(isPlaced()); return m_frameRect.right(); }
388 int top() const { ASSERT(isPlaced()); return m_frameRect.y(); }
389 int bottom() const { ASSERT(isPlaced()); return m_frameRect.bottom(); }
390 int width() const { return m_frameRect.width(); }
391 int height() const { return m_frameRect.height(); }
393 void setLeft(int left) { m_frameRect.setX(left); }
394 void setTop(int top) { m_frameRect.setY(top); }
395 void setWidth(int width) { m_frameRect.setWidth(width); }
396 void setHeight(int height) { m_frameRect.setHeight(height); }
398 const IntRect& frameRect() const { ASSERT(isPlaced()); return m_frameRect; }
399 void setFrameRect(const IntRect& frameRect) { m_frameRect = frameRect; }
401 RenderBox* m_renderer;
403 int m_paginationStrut;
404 unsigned m_type : 2; // Type (left or right aligned)
405 bool m_shouldPaint : 1;
406 bool m_isDescendant : 1;
410 int logicalTopForFloat(FloatingObject* child) const { return style()->isHorizontalWritingMode() ? child->top() : child->left(); }
411 int logicalBottomForFloat(FloatingObject* child) const { return style()->isHorizontalWritingMode() ? child->bottom() : child->right(); }
412 int logicalLeftForFloat(FloatingObject* child) const { return style()->isHorizontalWritingMode() ? child->left() : child->top(); }
413 int logicalRightForFloat(FloatingObject* child) const { return style()->isHorizontalWritingMode() ? child->right() : child->bottom(); }
414 int logicalWidthForFloat(FloatingObject* child) const { return style()->isHorizontalWritingMode() ? child->width() : child->height(); }
415 void setLogicalTopForFloat(FloatingObject* child, int logicalTop)
417 if (style()->isHorizontalWritingMode())
418 child->setTop(logicalTop);
420 child->setLeft(logicalTop);
422 void setLogicalLeftForFloat(FloatingObject* child, int logicalLeft)
424 if (style()->isHorizontalWritingMode())
425 child->setLeft(logicalLeft);
427 child->setTop(logicalLeft);
429 void setLogicalHeightForFloat(FloatingObject* child, int logicalHeight)
431 if (style()->isHorizontalWritingMode())
432 child->setHeight(logicalHeight);
434 child->setWidth(logicalHeight);
436 void setLogicalWidthForFloat(FloatingObject* child, int logicalWidth)
438 if (style()->isHorizontalWritingMode())
439 child->setWidth(logicalWidth);
441 child->setHeight(logicalWidth);
444 // The following functions' implementations are in RenderBlockLineLayout.cpp.
445 RootInlineBox* determineStartPosition(bool& firstLine, bool& fullLayout, bool& previousLineBrokeCleanly,
446 InlineBidiResolver&, Vector<FloatWithRect>& floats, unsigned& numCleanFloats,
447 bool& useRepaintBounds, int& repaintTop, int& repaintBottom);
448 RootInlineBox* determineEndPosition(RootInlineBox* startBox, InlineIterator& cleanLineStart,
449 BidiStatus& cleanLineBidiStatus,
451 bool matchedEndLine(const InlineBidiResolver&, const InlineIterator& endLineStart, const BidiStatus& endLineStatus,
452 RootInlineBox*& endLine, int& endYPos, int& repaintBottom, int& repaintTop);
454 void skipTrailingWhitespace(InlineIterator&, bool isLineEmpty, bool previousLineBrokeCleanly);
455 int skipLeadingWhitespace(InlineBidiResolver&, bool firstLine, bool isLineEmpty, bool previousLineBrokeCleanly, FloatingObject* lastFloatFromPreviousLine);
456 void fitBelowFloats(int widthToFit, bool firstLine, int& availableWidth);
457 InlineIterator findNextLineBreak(InlineBidiResolver&, bool firstLine, bool& isLineEmpty, bool& previousLineBrokeCleanly, bool& hyphenated, EClear*, FloatingObject* lastFloatFromPreviousLine);
458 RootInlineBox* constructLine(unsigned runCount, BidiRun* firstRun, BidiRun* lastRun, bool firstLine, bool lastLine, RenderObject* endObject);
459 InlineFlowBox* createLineBoxes(RenderObject*, bool firstLine);
460 void computeInlineDirectionPositionsForLine(RootInlineBox*, bool firstLine, BidiRun* firstRun, BidiRun* trailingSpaceRun, bool reachedEnd, GlyphOverflowAndFallbackFontsMap&);
461 void computeBlockDirectionPositionsForLine(RootInlineBox*, BidiRun*, GlyphOverflowAndFallbackFontsMap&);
462 void deleteEllipsisLineBoxes();
463 void checkLinesForTextOverflow();
464 void addOverflowFromInlineChildren();
465 int beforeSideVisibleOverflowForLine(RootInlineBox*) const;
466 int afterSideVisibleOverflowForLine(RootInlineBox*) const;
467 int beforeSideLayoutOverflowForLine(RootInlineBox*) const;
468 int afterSideLayoutOverflowForLine(RootInlineBox*) const;
469 // End of functions defined in RenderBlockLineLayout.cpp.
471 void addOverflowFromBlockChildren();
472 void addOverflowFromFloats();
474 void paintFloats(PaintInfo&, int tx, int ty, bool preservePhase = false);
475 void paintContents(PaintInfo&, int tx, int ty);
476 void paintColumnContents(PaintInfo&, int tx, int ty, bool paintFloats = false);
477 void paintColumnRules(PaintInfo&, int tx, int ty);
478 void paintChildren(PaintInfo&, int tx, int ty);
479 void paintEllipsisBoxes(PaintInfo&, int tx, int ty);
480 void paintSelection(PaintInfo&, int tx, int ty);
481 void paintCaret(PaintInfo&, int tx, int ty, CaretType);
483 FloatingObject* insertFloatingObject(RenderBox*);
484 void removeFloatingObject(RenderBox*);
485 void removeFloatingObjectsBelow(FloatingObject*, int y);
487 // Called from lineWidth, to position the floats added in the last line.
488 // Returns true if and only if it has positioned any floats.
489 bool positionNewFloats();
491 // Positions new floats and also adjust all floats encountered on the line if any of them
492 // have to move to the next page/column.
493 bool positionNewFloatOnLine(FloatingObject* newFloat, FloatingObject* lastFloatFromPreviousLine);
496 int getClearDelta(RenderBox* child, int yPos);
498 virtual bool avoidsFloats() const;
500 bool hasOverhangingFloats() { return parent() && !hasColumns() && lowestFloatLogicalBottom() > logicalHeight(); }
501 void addIntrudingFloats(RenderBlock* prev, int xoffset, int yoffset);
502 int addOverhangingFloats(RenderBlock* child, int xoffset, int yoffset, bool makeChildPaintOtherFloats);
504 int lowestFloatLogicalBottom(FloatingObject::Type = FloatingObject::FloatBoth) const;
505 int nextFloatLogicalBottomBelow(int) const;
507 virtual bool hitTestColumns(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction);
508 virtual bool hitTestContents(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction);
509 bool hitTestFloats(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty);
511 virtual bool isPointInOverflowControl(HitTestResult&, int x, int y, int tx, int ty);
513 void computeInlinePreferredLogicalWidths();
514 void computeBlockPreferredLogicalWidths();
516 // Obtains the nearest enclosing block (including this block) that contributes a first-line style to our inline
518 virtual RenderBlock* firstLineBlock() const;
520 virtual IntRect rectWithOutlineForRepaint(RenderBoxModelObject* repaintContainer, int outlineWidth);
521 virtual RenderStyle* outlineStyleForRepaint() const;
523 virtual RenderObject* hoverAncestor() const;
524 virtual void updateDragState(bool dragOn);
525 virtual void childBecameNonInline(RenderObject* child);
527 virtual IntRect selectionRectForRepaint(RenderBoxModelObject* repaintContainer, bool /*clipToVisibleContent*/)
529 return selectionGapRectsForRepaint(repaintContainer);
531 virtual bool shouldPaintSelectionGaps() const;
532 bool isSelectionRoot() const;
533 GapRects selectionGaps(RenderBlock* rootBlock, const IntPoint& rootBlockPhysicalPosition, const IntSize& offsetFromRootBlock,
534 int& lastLogicalTop, int& lastLogicalLeft, int& lastLogicalRight, const PaintInfo* = 0);
535 GapRects inlineSelectionGaps(RenderBlock* rootBlock, const IntPoint& rootBlockPhysicalPosition, const IntSize& offsetFromRootBlock,
536 int& lastLogicalTop, int& lastLogicalLeft, int& lastLogicalRight, const PaintInfo*);
537 GapRects blockSelectionGaps(RenderBlock* rootBlock, const IntPoint& rootBlockPhysicalPosition, const IntSize& offsetFromRootBlock,
538 int& lastLogicalTop, int& lastLogicalLeft, int& lastLogicalRight, const PaintInfo*);
539 IntRect blockSelectionGap(RenderBlock* rootBlock, const IntPoint& rootBlockPhysicalPosition, const IntSize& offsetFromRootBlock,
540 int lastLogicalTop, int lastLogicalLeft, int lastLogicalRight, int logicalBottom, const PaintInfo*);
541 int logicalLeftSelectionOffset(RenderBlock* rootBlock, int position);
542 int logicalRightSelectionOffset(RenderBlock* rootBlock, int position);
544 virtual void absoluteRects(Vector<IntRect>&, int tx, int ty);
545 virtual void absoluteQuads(Vector<FloatQuad>&);
547 int desiredColumnWidth() const;
548 unsigned desiredColumnCount() const;
549 void setDesiredColumnCountAndWidth(int count, int width);
551 void paintContinuationOutlines(PaintInfo&, int tx, int ty);
553 virtual IntRect localCaretRect(InlineBox*, int caretOffset, int* extraWidthToEndOfLine = 0);
555 virtual void addFocusRingRects(Vector<IntRect>&, int tx, int ty);
557 void adjustPointToColumnContents(IntPoint&) const;
558 void adjustForBorderFit(int x, int& left, int& right) const; // Helper function for borderFitAdjust
560 void markLinesDirtyInBlockRange(int logicalTop, int logicalBottom, RootInlineBox* highest = 0);
562 void newLine(EClear);
564 Position positionForBox(InlineBox*, bool start = true) const;
565 Position positionForRenderer(RenderObject*, bool start = true) const;
566 VisiblePosition positionForPointWithInlineChildren(const IntPoint&);
568 // Adjust tx and ty from painting offsets to the local coords of this renderer
569 void offsetForContents(int& tx, int& ty) const;
571 void calcColumnWidth();
572 bool layoutColumns(bool hasSpecifiedPageHeight, int pageHeight, LayoutStateMaintainer&);
573 void makeChildrenAnonymousColumnBlocks(RenderObject* beforeChild, RenderBlock* newBlockBox, RenderObject* newChild);
575 bool expandsToEncloseOverhangingFloats() const;
577 void updateScrollInfoAfterLayout();
579 RenderObject* splitAnonymousBlocksAroundChild(RenderObject* beforeChild);
580 void splitBlocks(RenderBlock* fromBlock, RenderBlock* toBlock, RenderBlock* middleBlock,
581 RenderObject* beforeChild, RenderBoxModelObject* oldCont);
582 void splitFlow(RenderObject* beforeChild, RenderBlock* newBlockBox,
583 RenderObject* newChild, RenderBoxModelObject* oldCont);
584 RenderBlock* clone() const;
585 RenderBlock* continuationBefore(RenderObject* beforeChild);
586 RenderBlock* containingColumnsBlock(bool allowAnonymousColumnBlock = true);
587 RenderBlock* columnsBlockForSpanningElement(RenderObject* newChild);
590 // Collapsing flags for whether we can collapse our margins with our children's margins.
591 bool m_canCollapseWithChildren : 1;
592 bool m_canCollapseMarginBeforeWithChildren : 1;
593 bool m_canCollapseMarginAfterWithChildren : 1;
595 // Whether or not we are a quirky container, i.e., do we collapse away top and bottom
596 // margins in our container. Table cells and the body are the common examples. We
597 // also have a custom style property for Safari RSS to deal with TypePad blog articles.
598 bool m_quirkContainer : 1;
600 // This flag tracks whether we are still looking at child margins that can all collapse together at the beginning of a block.
601 // They may or may not collapse with the top margin of the block (|m_canCollapseTopWithChildren| tells us that), but they will
602 // always be collapsing with one another. This variable can remain set to true through multiple iterations
603 // as long as we keep encountering self-collapsing blocks.
604 bool m_atBeforeSideOfBlock : 1;
606 // This flag is set when we know we're examining bottom margins and we know we're at the bottom of the block.
607 bool m_atAfterSideOfBlock : 1;
609 // These variables are used to detect quirky margins that we need to collapse away (in table cells
610 // and in the body element).
611 bool m_marginBeforeQuirk : 1;
612 bool m_marginAfterQuirk : 1;
613 bool m_determinedMarginBeforeQuirk : 1;
615 // These flags track the previous maximal positive and negative margins.
616 int m_positiveMargin;
617 int m_negativeMargin;
620 MarginInfo(RenderBlock* b, int beforeBorderPadding, int afterBorderPadding);
622 void setAtBeforeSideOfBlock(bool b) { m_atBeforeSideOfBlock = b; }
623 void setAtAfterSideOfBlock(bool b) { m_atAfterSideOfBlock = b; }
624 void clearMargin() { m_positiveMargin = m_negativeMargin = 0; }
625 void setMarginBeforeQuirk(bool b) { m_marginBeforeQuirk = b; }
626 void setMarginAfterQuirk(bool b) { m_marginAfterQuirk = b; }
627 void setDeterminedMarginBeforeQuirk(bool b) { m_determinedMarginBeforeQuirk = b; }
628 void setPositiveMargin(int p) { m_positiveMargin = p; }
629 void setNegativeMargin(int n) { m_negativeMargin = n; }
630 void setPositiveMarginIfLarger(int p) { if (p > m_positiveMargin) m_positiveMargin = p; }
631 void setNegativeMarginIfLarger(int n) { if (n > m_negativeMargin) m_negativeMargin = n; }
633 void setMargin(int p, int n) { m_positiveMargin = p; m_negativeMargin = n; }
635 bool atBeforeSideOfBlock() const { return m_atBeforeSideOfBlock; }
636 bool canCollapseWithMarginBefore() const { return m_atBeforeSideOfBlock && m_canCollapseMarginBeforeWithChildren; }
637 bool canCollapseWithMarginAfter() const { return m_atAfterSideOfBlock && m_canCollapseMarginAfterWithChildren; }
638 bool canCollapseMarginBeforeWithChildren() const { return m_canCollapseMarginBeforeWithChildren; }
639 bool canCollapseMarginAfterWithChildren() const { return m_canCollapseMarginAfterWithChildren; }
640 bool quirkContainer() const { return m_quirkContainer; }
641 bool determinedMarginBeforeQuirk() const { return m_determinedMarginBeforeQuirk; }
642 bool marginBeforeQuirk() const { return m_marginBeforeQuirk; }
643 bool marginAfterQuirk() const { return m_marginAfterQuirk; }
644 int positiveMargin() const { return m_positiveMargin; }
645 int negativeMargin() const { return m_negativeMargin; }
646 int margin() const { return m_positiveMargin - m_negativeMargin; }
649 void layoutBlockChild(RenderBox* child, MarginInfo&, int& previousFloatLogicalBottom, int& maxFloatLogicalBottom);
650 void adjustPositionedBlock(RenderBox* child, const MarginInfo&);
651 void adjustFloatingBlock(const MarginInfo&);
652 bool handleSpecialChild(RenderBox* child, const MarginInfo&);
653 bool handleFloatingChild(RenderBox* child, const MarginInfo&);
654 bool handlePositionedChild(RenderBox* child, const MarginInfo&);
655 bool handleRunInChild(RenderBox* child);
656 int collapseMargins(RenderBox* child, MarginInfo&);
657 int clearFloatsIfNeeded(RenderBox* child, MarginInfo&, int oldTopPosMargin, int oldTopNegMargin, int yPos);
658 int estimateLogicalTopPosition(RenderBox* child, const MarginInfo&);
659 void determineLogicalLeftPositionForChild(RenderBox* child);
660 void handleAfterSideOfBlock(int top, int bottom, MarginInfo&);
661 void setCollapsedBottomMargin(const MarginInfo&);
662 // End helper functions and structs used by layoutBlockChildren.
664 // Pagination routines.
665 int nextPageTop(int yPos) const; // Returns the top of the next page following yPos.
666 int applyBeforeBreak(RenderBox* child, int yPos); // If the child has a before break, then return a new yPos that shifts to the top of the next page/column.
667 int applyAfterBreak(RenderBox* child, int yPos, MarginInfo& marginInfo); // If the child has an after break, then return a new yPos that shifts to the top of the next page/column.
668 int adjustForUnsplittableChild(RenderBox* child, int yPos, bool includeMargins = false); // If the child is unsplittable and can't fit on the current page, return the top of the next page/column.
669 void adjustLinePositionForPagination(RootInlineBox*, int& deltaY); // Computes a deltaY value that put a line at the top of the next page if it doesn't fit on the current page.
671 typedef PositionedObjectsListHashSet::const_iterator Iterator;
672 DeprecatedPtrList<FloatingObject>* m_floatingObjects;
674 PositionedObjectsListHashSet* m_positionedObjects;
676 // An inline can be split with blocks occurring in between the inline content.
677 // When this occurs we need a pointer to our next object. We can basically be
678 // split into a sequence of inlines and blocks. The continuation will either be
679 // an anonymous block (that houses other blocks) or it will be an inline flow.
680 RenderBoxModelObject* m_continuation;
682 // Allocated only when some of these fields have non-default values
683 struct RenderBlockRareData : Noncopyable {
684 RenderBlockRareData(const RenderBlock* block)
685 : m_margins(positiveMarginBeforeDefault(block), negativeMarginBeforeDefault(block), positiveMarginAfterDefault(block), negativeMarginAfterDefault(block))
686 , m_paginationStrut(0)
691 static int positiveMarginBeforeDefault(const RenderBlock* block)
693 return std::max(block->marginBefore(), 0);
696 static int negativeMarginBeforeDefault(const RenderBlock* block)
698 return std::max(-block->marginBefore(), 0);
700 static int positiveMarginAfterDefault(const RenderBlock* block)
702 return std::max(block->marginAfter(), 0);
704 static int negativeMarginAfterDefault(const RenderBlock* block)
706 return std::max(-block->marginAfter(), 0);
709 MarginValues m_margins;
710 int m_paginationStrut;
714 OwnPtr<RenderBlockRareData> m_rareData;
716 RenderObjectChildList m_children;
717 RenderLineBoxList m_lineBoxes; // All of the root line boxes created for this block flow. For example, <div>Hello<br>world.</div> will have two total lines for the <div>.
719 mutable int m_lineHeight;
721 // RenderRubyBase objects need to be able to split and merge, moving their children around
722 // (calling moveChildTo, moveAllChildrenTo, and makeChildrenNonInline).
723 friend class RenderRubyBase;
726 inline RenderBlock* toRenderBlock(RenderObject* object)
728 ASSERT(!object || object->isRenderBlock());
729 return static_cast<RenderBlock*>(object);
732 inline const RenderBlock* toRenderBlock(const RenderObject* object)
734 ASSERT(!object || object->isRenderBlock());
735 return static_cast<const RenderBlock*>(object);
738 // This will catch anyone doing an unnecessary cast.
739 void toRenderBlock(const RenderBlock*);
741 } // namespace WebCore
743 #endif // RenderBlock_h