Upstream version 7.35.139.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / RenderBlock.h
1 /*
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.
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 #ifndef RenderBlock_h
24 #define RenderBlock_h
25
26 #include "core/rendering/ColumnInfo.h"
27 #include "core/rendering/FloatingObjects.h"
28 #include "core/rendering/GapRects.h"
29 #include "core/rendering/RenderBox.h"
30 #include "core/rendering/RenderLineBoxList.h"
31 #include "core/rendering/RootInlineBox.h"
32 #include "core/rendering/style/ShapeValue.h"
33 #include "platform/text/TextBreakIterator.h"
34 #include "platform/text/TextRun.h"
35 #include "wtf/ListHashSet.h"
36 #include "wtf/OwnPtr.h"
37
38 namespace WebCore {
39
40 class BasicShape;
41 class BidiContext;
42 class LayoutStateMaintainer;
43 class LineLayoutState;
44 class RenderInline;
45 class RenderRegion;
46 class RenderText;
47
48 struct BidiRun;
49 struct PaintInfo;
50 class LineInfo;
51 class RenderRubyRun;
52 class WordMeasurement;
53
54 template <class Run> class BidiRunList;
55 typedef WTF::ListHashSet<RenderBox*, 16> TrackedRendererListHashSet;
56 typedef WTF::HashMap<const RenderBlock*, OwnPtr<TrackedRendererListHashSet> > TrackedDescendantsMap;
57 typedef WTF::HashMap<const RenderBox*, OwnPtr<HashSet<RenderBlock*> > > TrackedContainerMap;
58 typedef Vector<WordMeasurement, 64> WordMeasurements;
59
60 enum CaretType { CursorCaret, DragCaret };
61 enum ContainingBlockState { NewContainingBlock, SameContainingBlock };
62
63 enum TextRunFlag {
64     DefaultTextRunFlags = 0,
65     RespectDirection = 1 << 0,
66     RespectDirectionOverride = 1 << 1
67 };
68
69 typedef unsigned TextRunFlags;
70
71 class RenderBlock : public RenderBox {
72 public:
73     friend class LineLayoutState;
74
75 protected:
76     explicit RenderBlock(ContainerNode*);
77     virtual ~RenderBlock();
78
79 public:
80     RenderObject* firstChild() const { ASSERT(children() == virtualChildren()); return children()->firstChild(); }
81     RenderObject* lastChild() const { ASSERT(children() == virtualChildren()); return children()->lastChild(); }
82
83     const RenderObjectChildList* children() const { return &m_children; }
84     RenderObjectChildList* children() { return &m_children; }
85
86     bool beingDestroyed() const { return m_beingDestroyed; }
87
88     // These two functions are overridden for inline-block.
89     virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE FINAL;
90     virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
91
92     LayoutUnit minLineHeightForReplacedRenderer(bool isFirstLine, LayoutUnit replacedHeight) const;
93
94     RenderLineBoxList* lineBoxes() { return &m_lineBoxes; }
95
96     InlineFlowBox* firstLineBox() const { return m_lineBoxes.firstLineBox(); }
97     InlineFlowBox* lastLineBox() const { return m_lineBoxes.lastLineBox(); }
98
99     // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
100     virtual void deleteLineBoxTree();
101
102     virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0) OVERRIDE;
103     virtual void removeChild(RenderObject*) OVERRIDE;
104
105     virtual void layoutBlock(bool relayoutChildren);
106
107     void insertPositionedObject(RenderBox*);
108     static void removePositionedObject(RenderBox*);
109     void removePositionedObjects(RenderBlock*, ContainingBlockState = SameContainingBlock);
110
111     TrackedRendererListHashSet* positionedObjects() const;
112     bool hasPositionedObjects() const
113     {
114         TrackedRendererListHashSet* objects = positionedObjects();
115         return objects && !objects->isEmpty();
116     }
117
118     virtual bool visibleForTouchAction() const OVERRIDE FINAL { return true; }
119
120     void addPercentHeightDescendant(RenderBox*);
121     static void removePercentHeightDescendant(RenderBox*);
122     static bool hasPercentHeightContainerMap();
123     static bool hasPercentHeightDescendant(RenderBox*);
124     static void clearPercentHeightDescendantsFrom(RenderBox*);
125     static void removePercentHeightDescendantIfNeeded(RenderBox*);
126
127     TrackedRendererListHashSet* percentHeightDescendants() const;
128     bool hasPercentHeightDescendants() const
129     {
130         TrackedRendererListHashSet* descendants = percentHeightDescendants();
131         return descendants && !descendants->isEmpty();
132     }
133
134     void setHasMarkupTruncation(bool b) { m_hasMarkupTruncation = b; }
135     bool hasMarkupTruncation() const { return m_hasMarkupTruncation; }
136
137     void setHasMarginBeforeQuirk(bool b) { m_hasMarginBeforeQuirk = b; }
138     void setHasMarginAfterQuirk(bool b) { m_hasMarginAfterQuirk = b; }
139
140     bool hasMarginBeforeQuirk() const { return m_hasMarginBeforeQuirk; }
141     bool hasMarginAfterQuirk() const { return m_hasMarginAfterQuirk; }
142
143     bool hasMarginBeforeQuirk(const RenderBox* child) const;
144     bool hasMarginAfterQuirk(const RenderBox* child) const;
145
146     void markPositionedObjectsForLayout();
147     // FIXME: Do we really need this to be virtual? It's just so we can call this on
148     // RenderBoxes without needed to check whether they're RenderBlocks first.
149     virtual void markForPaginationRelayoutIfNeeded(SubtreeLayoutScope&) OVERRIDE FINAL;
150
151     // FIXME-BLOCKFLOW: Remove virtualizaion when all of the line layout code has been moved out of RenderBlock
152     virtual bool containsFloats() const { return false; }
153
154     LayoutUnit textIndentOffset() const;
155
156     virtual PositionWithAffinity positionForPoint(const LayoutPoint&) OVERRIDE;
157
158     // Block flows subclass availableWidth to handle multi column layout (shrinking the width available to children when laying out.)
159     virtual LayoutUnit availableLogicalWidth() const OVERRIDE FINAL;
160
161     LayoutPoint flipForWritingModeIncludingColumns(const LayoutPoint&) const;
162     void adjustStartEdgeForWritingModeIncludingColumns(LayoutRect&) const;
163
164     LayoutUnit blockDirectionOffset(const LayoutSize& offsetFromBlock) const;
165     LayoutUnit inlineDirectionOffset(const LayoutSize& offsetFromBlock) const;
166
167     RootInlineBox* firstRootBox() const { return static_cast<RootInlineBox*>(firstLineBox()); }
168     RootInlineBox* lastRootBox() const { return static_cast<RootInlineBox*>(lastLineBox()); }
169
170     GapRects selectionGapRectsForRepaint(const RenderLayerModelObject* repaintContainer);
171     LayoutRect logicalLeftSelectionGap(RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
172                                        RenderObject* selObj, LayoutUnit logicalLeft, LayoutUnit logicalTop, LayoutUnit logicalHeight, const PaintInfo*);
173     LayoutRect logicalRightSelectionGap(RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
174                                         RenderObject* selObj, LayoutUnit logicalRight, LayoutUnit logicalTop, LayoutUnit logicalHeight, const PaintInfo*);
175     void getSelectionGapInfo(SelectionState, bool& leftGap, bool& rightGap);
176     RenderBlock* blockBeforeWithinSelectionRoot(LayoutSize& offset) const;
177
178     LayoutRect logicalRectToPhysicalRect(const LayoutPoint& physicalPosition, const LayoutRect& logicalRect);
179
180     // Helper methods for computing line counts and heights for line counts.
181     RootInlineBox* lineAtIndex(int) const;
182     int lineCount(const RootInlineBox* = 0, bool* = 0) const;
183     int heightForLineCount(int);
184     void clearTruncation();
185
186     void adjustRectForColumns(LayoutRect&) const;
187     virtual void adjustForColumns(LayoutSize&, const LayoutPoint&) const OVERRIDE FINAL;
188     void adjustForColumnRect(LayoutSize& offset, const LayoutPoint& locationInContainer) const;
189
190     void addContinuationWithOutline(RenderInline*);
191     bool paintsContinuationOutline(RenderInline*);
192
193     virtual RenderBoxModelObject* virtualContinuation() const OVERRIDE FINAL { return continuation(); }
194     bool isAnonymousBlockContinuation() const { return continuation() && isAnonymousBlock(); }
195     RenderInline* inlineElementContinuation() const;
196     RenderBlock* blockElementContinuation() const;
197
198     using RenderBoxModelObject::continuation;
199     using RenderBoxModelObject::setContinuation;
200
201     static RenderBlock* createAnonymousWithParentRendererAndDisplay(const RenderObject*, EDisplay = BLOCK);
202     static RenderBlockFlow* createAnonymousColumnsWithParentRenderer(const RenderObject*);
203     static RenderBlockFlow* createAnonymousColumnSpanWithParentRenderer(const RenderObject*);
204     RenderBlock* createAnonymousBlock(EDisplay display = BLOCK) const { return createAnonymousWithParentRendererAndDisplay(this, display); }
205     RenderBlockFlow* createAnonymousColumnsBlock() const { return createAnonymousColumnsWithParentRenderer(this); }
206     RenderBlockFlow* createAnonymousColumnSpanBlock() const { return createAnonymousColumnSpanWithParentRenderer(this); }
207
208     virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject* parent) const OVERRIDE;
209
210     ColumnInfo* columnInfo() const;
211     int columnGap() const;
212
213     // These two functions take the ColumnInfo* to avoid repeated lookups of the info in the global HashMap.
214     unsigned columnCount(ColumnInfo*) const;
215     LayoutRect columnRectAt(ColumnInfo*, unsigned) const;
216
217     LayoutUnit paginationStrut() const { return m_rareData ? m_rareData->m_paginationStrut : LayoutUnit(); }
218     void setPaginationStrut(LayoutUnit);
219
220     bool shouldBreakAtLineToAvoidWidow() const { return m_rareData && m_rareData->m_lineBreakToAvoidWidow >= 0; }
221     void clearShouldBreakAtLineToAvoidWidow() const;
222     int lineBreakToAvoidWidow() const { return m_rareData ? m_rareData->m_lineBreakToAvoidWidow : -1; }
223     void setBreakAtLineToAvoidWidow(int);
224     void clearDidBreakAtLineToAvoidWidow();
225     void setDidBreakAtLineToAvoidWidow();
226     bool didBreakAtLineToAvoidWidow() const { return m_rareData && m_rareData->m_didBreakAtLineToAvoidWidow; }
227
228     // The page logical offset is the object's offset from the top of the page in the page progression
229     // direction (so an x-offset in vertical text and a y-offset for horizontal text).
230     LayoutUnit pageLogicalOffset() const { return m_rareData ? m_rareData->m_pageLogicalOffset : LayoutUnit(); }
231     void setPageLogicalOffset(LayoutUnit);
232
233     // Accessors for logical width/height and margins in the containing block's block-flow direction.
234     LayoutUnit logicalWidthForChild(const RenderBox* child) const { return isHorizontalWritingMode() ? child->width() : child->height(); }
235     LayoutUnit logicalHeightForChild(const RenderBox* child) const { return isHorizontalWritingMode() ? child->height() : child->width(); }
236     LayoutSize logicalSizeForChild(const RenderBox* child) const { return isHorizontalWritingMode() ? child->size() : child->size().transposedSize(); }
237     LayoutUnit logicalTopForChild(const RenderBox* child) const { return isHorizontalWritingMode() ? child->y() : child->x(); }
238     LayoutUnit marginBeforeForChild(const RenderBoxModelObject* child) const { return child->marginBefore(style()); }
239     LayoutUnit marginAfterForChild(const RenderBoxModelObject* child) const { return child->marginAfter(style()); }
240     LayoutUnit marginStartForChild(const RenderBoxModelObject* child) const { return child->marginStart(style()); }
241     LayoutUnit marginEndForChild(const RenderBoxModelObject* child) const { return child->marginEnd(style()); }
242     void setMarginStartForChild(RenderBox* child, LayoutUnit value) const { child->setMarginStart(value, style()); }
243     void setMarginEndForChild(RenderBox* child, LayoutUnit value) const { child->setMarginEnd(value, style()); }
244     void setMarginBeforeForChild(RenderBox* child, LayoutUnit value) const { child->setMarginBefore(value, style()); }
245     void setMarginAfterForChild(RenderBox* child, LayoutUnit value) const { child->setMarginAfter(value, style()); }
246     LayoutUnit collapsedMarginBeforeForChild(const RenderBox* child) const;
247     LayoutUnit collapsedMarginAfterForChild(const RenderBox* child) const;
248
249     virtual void updateFirstLetter();
250
251     virtual void scrollbarsChanged(bool /*horizontalScrollbarChanged*/, bool /*verticalScrollbarChanged*/) { };
252
253     LayoutUnit availableLogicalWidthForContent() const { return max<LayoutUnit>(0, logicalRightOffsetForContent() - logicalLeftOffsetForContent()); }
254     LayoutUnit logicalLeftOffsetForContent() const { return isHorizontalWritingMode() ? borderLeft() + paddingLeft() : borderTop() + paddingTop(); }
255     LayoutUnit logicalRightOffsetForContent() const { return logicalLeftOffsetForContent() + availableLogicalWidth(); }
256     LayoutUnit startOffsetForContent() const { return style()->isLeftToRightDirection() ? logicalLeftOffsetForContent() : logicalWidth() - logicalRightOffsetForContent(); }
257     LayoutUnit endOffsetForContent() const { return !style()->isLeftToRightDirection() ? logicalLeftOffsetForContent() : logicalWidth() - logicalRightOffsetForContent(); }
258
259 #ifndef NDEBUG
260     void checkPositionedObjectsNeedLayout();
261     void showLineTreeAndMark(const InlineBox* = 0, const char* = 0, const InlineBox* = 0, const char* = 0, const RenderObject* = 0) const;
262 #endif
263
264     LayoutSize logicalOffsetFromShapeAncestorContainer(const RenderBlock* container) const;
265
266     // inline-block elements paint all phases atomically. This function ensures that. Certain other elements
267     // (grid items, flex items) require this behavior as well, and this function exists as a helper for them.
268     // It is expected that the caller will call this function independent of the value of paintInfo.phase.
269     static void paintAsInlineBlock(RenderObject*, PaintInfo&, const LayoutPoint&);
270 protected:
271     virtual void willBeDestroyed() OVERRIDE;
272
273     void dirtyForLayoutFromPercentageHeightDescendants(SubtreeLayoutScope&);
274
275     virtual void layout() OVERRIDE;
276     virtual bool updateImageLoadingPriorities() OVERRIDE FINAL;
277
278     void layoutPositionedObjects(bool relayoutChildren, bool fixedPositionObjectsOnly = false);
279     void markFixedPositionObjectForLayoutIfNeeded(RenderObject* child, SubtreeLayoutScope&);
280
281     LayoutUnit marginIntrinsicLogicalWidthForChild(RenderBox* child) const;
282
283     int beforeMarginInLineDirection(LineDirectionMode) const;
284
285     virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE;
286     virtual void paintObject(PaintInfo&, const LayoutPoint&) OVERRIDE;
287     virtual void paintChildren(PaintInfo&, const LayoutPoint&);
288     void paintChild(RenderBox*, PaintInfo&, const LayoutPoint&);
289     void paintChildAsInlineBlock(RenderBox*, PaintInfo&, const LayoutPoint&);
290
291     virtual void adjustInlineDirectionLineBounds(int /* expansionOpportunityCount */, float& /* logicalLeft */, float& /* logicalWidth */) const { }
292
293     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
294
295     virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const OVERRIDE;
296     virtual void computePreferredLogicalWidths() OVERRIDE;
297     void adjustIntrinsicLogicalWidthsForColumns(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const;
298
299     virtual int firstLineBoxBaseline() const OVERRIDE;
300     virtual int inlineBlockBaseline(LineDirectionMode) const OVERRIDE;
301     int lastLineBoxBaseline(LineDirectionMode) const;
302
303     virtual void updateHitTestResult(HitTestResult&, const LayoutPoint&) OVERRIDE;
304
305     // Delay update scrollbar until finishDelayRepaint() will be
306     // called. This function is used when a flexbox is laying out its
307     // descendant. If multiple calls are made to startDelayRepaint(),
308     // finishDelayRepaint() will do nothing until finishDelayRepaint()
309     // is called the same number of times.
310     static void startDelayUpdateScrollInfo();
311     static void finishDelayUpdateScrollInfo();
312
313     void updateScrollInfoAfterLayout();
314
315     virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle) OVERRIDE;
316     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE;
317
318     virtual bool hasLineIfEmpty() const;
319
320     bool simplifiedLayout();
321     virtual void simplifiedNormalFlowLayout();
322
323     void setDesiredColumnCountAndWidth(int, LayoutUnit);
324
325 public:
326     virtual void computeOverflow(LayoutUnit oldClientAfterEdge, bool = false);
327 protected:
328     virtual void addOverflowFromChildren();
329     void addOverflowFromPositionedObjects();
330     void addOverflowFromBlockChildren();
331     void addVisualOverflowFromTheme();
332
333     virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer = 0) OVERRIDE;
334
335     virtual void computeSelfHitTestRects(Vector<LayoutRect>&, const LayoutPoint& layerOffset) const OVERRIDE;
336
337     void computeRegionRangeForBlock(RenderFlowThread*);
338
339     void updateBlockChildDirtyBitsBeforeLayout(bool relayoutChildren, RenderBox*);
340
341     virtual bool isInlineBlockOrInlineTable() const OVERRIDE FINAL { return isInline() && isReplaced(); }
342
343 private:
344     virtual RenderObjectChildList* virtualChildren() OVERRIDE FINAL { return children(); }
345     virtual const RenderObjectChildList* virtualChildren() const OVERRIDE FINAL { return children(); }
346
347     virtual const char* renderName() const OVERRIDE;
348
349     virtual bool isRenderBlock() const OVERRIDE FINAL { return true; }
350
351     void makeChildrenNonInline(RenderObject* insertionPoint = 0);
352     virtual void removeLeftoverAnonymousBlock(RenderBlock* child);
353
354     static void collapseAnonymousBlockChild(RenderBlock* parent, RenderBlock* child);
355
356     virtual void dirtyLinesFromChangedChild(RenderObject* child) OVERRIDE FINAL { m_lineBoxes.dirtyLinesFromChangedChild(this, child); }
357
358     void addChildToContinuation(RenderObject* newChild, RenderObject* beforeChild);
359     virtual void addChildIgnoringContinuation(RenderObject* newChild, RenderObject* beforeChild) OVERRIDE;
360     void addChildToAnonymousColumnBlocks(RenderObject* newChild, RenderObject* beforeChild);
361
362     void addChildIgnoringAnonymousColumnBlocks(RenderObject* newChild, RenderObject* beforeChild = 0);
363
364     virtual bool isSelfCollapsingBlock() const OVERRIDE;
365
366     void insertIntoTrackedRendererMaps(RenderBox* descendant, TrackedDescendantsMap*&, TrackedContainerMap*&);
367     static void removeFromTrackedRendererMaps(RenderBox* descendant, TrackedDescendantsMap*&, TrackedContainerMap*&);
368
369     void createFirstLetterRenderer(RenderObject* firstLetterBlock, RenderObject* currentChild, unsigned length);
370     void updateFirstLetterStyle(RenderObject* firstLetterBlock, RenderObject* firstLetterContainer);
371
372     Node* nodeForHitTest() const;
373
374     // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
375     virtual void paintFloats(PaintInfo&, const LayoutPoint&, bool) { }
376     void paintContents(PaintInfo&, const LayoutPoint&);
377     void paintColumnContents(PaintInfo&, const LayoutPoint&, bool paintFloats = false);
378     void paintColumnRules(PaintInfo&, const LayoutPoint&);
379     void paintSelection(PaintInfo&, const LayoutPoint&);
380     void paintCaret(PaintInfo&, const LayoutPoint&, CaretType);
381
382     bool hasCaret() const { return hasCaret(CursorCaret) || hasCaret(DragCaret); }
383     bool hasCaret(CaretType) const;
384
385     virtual bool avoidsFloats() const OVERRIDE;
386
387     bool hitTestColumns(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction);
388     bool hitTestContents(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction);
389     // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
390     virtual bool hitTestFloats(const HitTestRequest&, HitTestResult&, const HitTestLocation&, const LayoutPoint&) { return false; }
391
392     virtual bool isPointInOverflowControl(HitTestResult&, const LayoutPoint& locationInContainer, const LayoutPoint& accumulatedOffset);
393
394     void computeBlockPreferredLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const;
395
396     // Obtains the nearest enclosing block (including this block) that contributes a first-line style to our inline
397     // children.
398     virtual RenderBlock* firstLineBlock() const OVERRIDE;
399
400     virtual LayoutRect rectWithOutlineForRepaint(const RenderLayerModelObject* repaintContainer, LayoutUnit outlineWidth) const OVERRIDE FINAL;
401     virtual RenderStyle* outlineStyleForRepaint() const OVERRIDE FINAL;
402
403     virtual RenderObject* hoverAncestor() const OVERRIDE FINAL;
404     virtual void updateDragState(bool dragOn) OVERRIDE FINAL;
405     virtual void childBecameNonInline(RenderObject* child) OVERRIDE FINAL;
406
407     virtual LayoutRect selectionRectForRepaint(const RenderLayerModelObject* repaintContainer, bool /*clipToVisibleContent*/) OVERRIDE FINAL
408     {
409         return selectionGapRectsForRepaint(repaintContainer);
410     }
411     virtual bool shouldPaintSelectionGaps() const OVERRIDE FINAL;
412     bool isSelectionRoot() const;
413     GapRects selectionGaps(RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
414                            LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLogicalRight, const PaintInfo* = 0);
415     GapRects blockSelectionGaps(RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
416                                 LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLogicalRight, const PaintInfo*);
417     LayoutRect blockSelectionGap(RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
418                                  LayoutUnit lastLogicalTop, LayoutUnit lastLogicalLeft, LayoutUnit lastLogicalRight, LayoutUnit logicalBottom, const PaintInfo*);
419     virtual LayoutUnit logicalLeftSelectionOffset(RenderBlock* rootBlock, LayoutUnit position);
420     virtual LayoutUnit logicalRightSelectionOffset(RenderBlock* rootBlock, LayoutUnit position);
421
422     // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
423     virtual void clipOutFloatingObjects(RenderBlock*, const PaintInfo*, const LayoutPoint&, const LayoutSize&) { };
424
425     virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const OVERRIDE;
426     virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const OVERRIDE;
427
428     LayoutUnit desiredColumnWidth() const;
429
430     void paintContinuationOutlines(PaintInfo&, const LayoutPoint&);
431
432     virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) OVERRIDE FINAL;
433
434     void adjustPointToColumnContents(LayoutPoint&) const;
435
436     void fitBorderToLinesIfNeeded(); // Shrink the box in which the border paints if border-fit is set.
437     virtual void adjustForBorderFit(LayoutUnit x, LayoutUnit& left, LayoutUnit& right) const; // Helper function for borderFitAdjust
438
439     void markLinesDirtyInBlockRange(LayoutUnit logicalTop, LayoutUnit logicalBottom, RootInlineBox* highest = 0);
440
441     Position positionForBox(InlineBox*, bool start = true) const;
442     PositionWithAffinity positionForPointWithInlineChildren(const LayoutPoint&);
443
444     void calcColumnWidth();
445     void makeChildrenAnonymousColumnBlocks(RenderObject* beforeChild, RenderBlockFlow* newBlockBox, RenderObject* newChild);
446
447     void splitBlocks(RenderBlock* fromBlock, RenderBlock* toBlock, RenderBlock* middleBlock,
448                      RenderObject* beforeChild, RenderBoxModelObject* oldCont);
449     void splitFlow(RenderObject* beforeChild, RenderBlock* newBlockBox,
450                    RenderObject* newChild, RenderBoxModelObject* oldCont);
451     RenderBlock* clone() const;
452     RenderBlock* continuationBefore(RenderObject* beforeChild);
453     RenderBlockFlow* containingColumnsBlock(bool allowAnonymousColumnBlock = true);
454     RenderBlockFlow* columnsBlockForSpanningElement(RenderObject* newChild);
455
456     // End helper functions and structs used by layoutBlockChildren.
457
458 protected:
459     // Returns the logicalOffset at the top of the next page. If the offset passed in is already at the top of the current page,
460     // then nextPageLogicalTop with ExcludePageBoundary will still move to the top of the next page. nextPageLogicalTop with
461     // IncludePageBoundary set will not.
462     //
463     // For a page height of 800px, the first rule will return 800 if the value passed in is 0. The second rule will simply return 0.
464     enum PageBoundaryRule { ExcludePageBoundary, IncludePageBoundary };
465     LayoutUnit nextPageLogicalTop(LayoutUnit logicalOffset, PageBoundaryRule = ExcludePageBoundary) const;
466
467     bool createsBlockFormattingContext() const;
468
469 public:
470     LayoutUnit pageLogicalTopForOffset(LayoutUnit offset) const;
471     LayoutUnit pageLogicalHeightForOffset(LayoutUnit offset) const;
472     LayoutUnit pageRemainingLogicalHeightForOffset(LayoutUnit offset, PageBoundaryRule = IncludePageBoundary) const;
473
474 protected:
475     bool pushToNextPageWithMinimumLogicalHeight(LayoutUnit& adjustment, LayoutUnit logicalOffset, LayoutUnit minimumLogicalHeight) const;
476
477     // A page break is required at some offset due to space shortage in the current fragmentainer.
478     void setPageBreak(LayoutUnit offset, LayoutUnit spaceShortage);
479
480     // Update minimum page height required to avoid fragmentation where it shouldn't occur (inside
481     // unbreakable content, between orphans and widows, etc.). This will be used as a hint to the
482     // column balancer to help set a good minimum column height.
483     void updateMinimumPageHeight(LayoutUnit offset, LayoutUnit minHeight);
484
485     LayoutUnit adjustForUnsplittableChild(RenderBox* child, LayoutUnit logicalOffset, bool includeMargins = false); // If the child is unsplittable and can't fit on the current page, return the top of the next page/column.
486     void adjustLinePositionForPagination(RootInlineBox*, LayoutUnit& deltaOffset, RenderFlowThread*); // Computes a deltaOffset value that put a line at the top of the next page if it doesn't fit on the current page.
487
488     // Adjust from painting offsets to the local coords of this renderer
489     void offsetForContents(LayoutPoint&) const;
490
491     bool requiresColumns(int desiredColumnCount) const;
492
493     virtual bool updateLogicalWidthAndColumnWidth();
494
495     virtual bool canCollapseAnonymousBlockChild() const { return true; }
496
497 public:
498     virtual LayoutUnit offsetFromLogicalTopOfFirstPage() const OVERRIDE FINAL;
499     RenderRegion* regionAtBlockOffset(LayoutUnit) const;
500
501 public:
502
503     // Allocated only when some of these fields have non-default values
504     struct RenderBlockRareData {
505         WTF_MAKE_NONCOPYABLE(RenderBlockRareData); WTF_MAKE_FAST_ALLOCATED;
506     public:
507         RenderBlockRareData()
508             : m_paginationStrut(0)
509             , m_pageLogicalOffset(0)
510             , m_lineBreakToAvoidWidow(-1)
511             , m_didBreakAtLineToAvoidWidow(false)
512         {
513         }
514
515         LayoutUnit m_paginationStrut;
516         LayoutUnit m_pageLogicalOffset;
517
518         int m_lineBreakToAvoidWidow : 31;
519         unsigned m_didBreakAtLineToAvoidWidow : 1;
520      };
521
522 protected:
523     OwnPtr<RenderBlockRareData> m_rareData;
524
525     RenderObjectChildList m_children;
526     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>.
527
528     mutable signed m_lineHeight : 26;
529     unsigned m_hasMarginBeforeQuirk : 1; // Note these quirk values can't be put in RenderBlockRareData since they are set too frequently.
530     unsigned m_hasMarginAfterQuirk : 1;
531     unsigned m_beingDestroyed : 1;
532     unsigned m_hasMarkupTruncation : 1;
533     unsigned m_hasBorderOrPaddingLogicalWidthChanged : 1;
534     mutable unsigned m_hasOnlySelfCollapsingChildren : 1;
535
536     // RenderRubyBase objects need to be able to split and merge, moving their children around
537     // (calling moveChildTo, moveAllChildrenTo, and makeChildrenNonInline).
538     friend class RenderRubyBase;
539     // FIXME-BLOCKFLOW: Remove this when the line layout stuff has all moved out of RenderBlock
540     friend class LineBreaker;
541
542     // FIXME: This is temporary as we move code that accesses block flow
543     // member variables out of RenderBlock and into RenderBlockFlow.
544     friend class RenderBlockFlow;
545 };
546
547 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderBlock, isRenderBlock());
548
549 } // namespace WebCore
550
551 #endif // RenderBlock_h