• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/shapes/ShapeInsideInfo.h"
33 #include "core/rendering/style/ShapeValue.h"
34 #include "platform/text/TextBreakIterator.h"
35 #include "platform/text/TextRun.h"
36 #include "wtf/ListHashSet.h"
37 #include "wtf/OwnPtr.h"
38 
39 namespace WebCore {
40 
41 class BasicShape;
42 class BidiContext;
43 class InlineIterator;
44 class LayoutStateMaintainer;
45 class LineLayoutState;
46 class RenderInline;
47 class RenderText;
48 
49 struct BidiRun;
50 struct PaintInfo;
51 class LineInfo;
52 class RenderRubyRun;
53 class TextLayout;
54 class WordMeasurement;
55 
56 template <class Iterator, class Run> class BidiResolver;
57 template <class Run> class BidiRunList;
58 template <class Iterator> struct MidpointState;
59 typedef BidiResolver<InlineIterator, BidiRun> InlineBidiResolver;
60 typedef MidpointState<InlineIterator> LineMidpointState;
61 typedef WTF::ListHashSet<RenderBox*, 16> TrackedRendererListHashSet;
62 typedef WTF::HashMap<const RenderBlock*, OwnPtr<TrackedRendererListHashSet> > TrackedDescendantsMap;
63 typedef WTF::HashMap<const RenderBox*, OwnPtr<HashSet<RenderBlock*> > > TrackedContainerMap;
64 typedef Vector<WordMeasurement, 64> WordMeasurements;
65 
66 enum CaretType { CursorCaret, DragCaret };
67 enum ContainingBlockState { NewContainingBlock, SameContainingBlock };
68 
69 enum TextRunFlag {
70     DefaultTextRunFlags = 0,
71     RespectDirection = 1 << 0,
72     RespectDirectionOverride = 1 << 1
73 };
74 
75 typedef unsigned TextRunFlags;
76 
77 class RenderBlock : public RenderBox {
78 public:
79     friend class LineLayoutState;
80 
81 protected:
82     explicit RenderBlock(ContainerNode*);
83     virtual ~RenderBlock();
84 
85 public:
firstChild()86     RenderObject* firstChild() const { ASSERT(children() == virtualChildren()); return children()->firstChild(); }
lastChild()87     RenderObject* lastChild() const { ASSERT(children() == virtualChildren()); return children()->lastChild(); }
88 
children()89     const RenderObjectChildList* children() const { return &m_children; }
children()90     RenderObjectChildList* children() { return &m_children; }
91 
beingDestroyed()92     bool beingDestroyed() const { return m_beingDestroyed; }
93 
94     // These two functions are overridden for inline-block.
95     virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE FINAL;
96     virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const;
97 
98     LayoutUnit minLineHeightForReplacedRenderer(bool isFirstLine, LayoutUnit replacedHeight) const;
99 
lineBoxes()100     RenderLineBoxList* lineBoxes() { return &m_lineBoxes; }
101 
firstLineBox()102     InlineFlowBox* firstLineBox() const { return m_lineBoxes.firstLineBox(); }
lastLineBox()103     InlineFlowBox* lastLineBox() const { return m_lineBoxes.lastLineBox(); }
104 
105     // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
106     virtual void deleteLineBoxTree();
107 
108     virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0);
109     virtual void removeChild(RenderObject*);
110 
111     virtual void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0);
112 
113     void insertPositionedObject(RenderBox*);
114     static void removePositionedObject(RenderBox*);
115     void removePositionedObjects(RenderBlock*, ContainingBlockState = SameContainingBlock);
116 
117     TrackedRendererListHashSet* positionedObjects() const;
hasPositionedObjects()118     bool hasPositionedObjects() const
119     {
120         TrackedRendererListHashSet* objects = positionedObjects();
121         return objects && !objects->isEmpty();
122     }
123 
124     void addPercentHeightDescendant(RenderBox*);
125     static void removePercentHeightDescendant(RenderBox*);
126     TrackedRendererListHashSet* percentHeightDescendants() const;
127     static bool hasPercentHeightContainerMap();
128     static bool hasPercentHeightDescendant(RenderBox*);
129     static void clearPercentHeightDescendantsFrom(RenderBox*);
130     static void removePercentHeightDescendantIfNeeded(RenderBox*);
131 
setHasMarkupTruncation(bool b)132     void setHasMarkupTruncation(bool b) { m_hasMarkupTruncation = b; }
hasMarkupTruncation()133     bool hasMarkupTruncation() const { return m_hasMarkupTruncation; }
134 
setHasMarginBeforeQuirk(bool b)135     void setHasMarginBeforeQuirk(bool b) { m_hasMarginBeforeQuirk = b; }
setHasMarginAfterQuirk(bool b)136     void setHasMarginAfterQuirk(bool b) { m_hasMarginAfterQuirk = b; }
137 
hasMarginBeforeQuirk()138     bool hasMarginBeforeQuirk() const { return m_hasMarginBeforeQuirk; }
hasMarginAfterQuirk()139     bool hasMarginAfterQuirk() const { return m_hasMarginAfterQuirk; }
140 
141     bool hasMarginBeforeQuirk(const RenderBox* child) const;
142     bool hasMarginAfterQuirk(const RenderBox* child) const;
143 
144     RootInlineBox* createAndAppendRootInlineBox();
145 
146     void markShapeInsideDescendantsForLayout();
147     void markPositionedObjectsForLayout();
148     // FIXME: Do we really need this to be virtual? It's just so we can call this on
149     // RenderBoxes without needed to check whether they're RenderBlocks first.
150     virtual void markForPaginationRelayoutIfNeeded(SubtreeLayoutScope&) OVERRIDE FINAL;
151 
152     // FIXME-BLOCKFLOW: Remove virtualizaion when all of the line layout code has been moved out of RenderBlock
containsFloats()153     virtual bool containsFloats() const { return false; }
154 
155     // Versions that can compute line offsets with the region and page offset passed in. Used for speed to avoid having to
156     // compute the region all over again when you already know it.
157     LayoutUnit availableLogicalWidthForLineInRegion(LayoutUnit position, bool shouldIndentText, RenderRegion* region, LayoutUnit logicalHeight = 0) const
158     {
159         return max<LayoutUnit>(0, logicalRightOffsetForLineInRegion(position, shouldIndentText, region, logicalHeight)
160             - logicalLeftOffsetForLineInRegion(position, shouldIndentText, region, logicalHeight));
161     }
162     LayoutUnit logicalRightOffsetForLineInRegion(LayoutUnit position, bool shouldIndentText, RenderRegion* region, LayoutUnit logicalHeight = 0) const
163     {
164         return logicalRightOffsetForLine(position, logicalRightOffsetForContent(region), shouldIndentText, logicalHeight);
165     }
166     LayoutUnit logicalLeftOffsetForLineInRegion(LayoutUnit position, bool shouldIndentText, RenderRegion* region, LayoutUnit logicalHeight = 0) const
167     {
168         return logicalLeftOffsetForLine(position, logicalLeftOffsetForContent(region), shouldIndentText, logicalHeight);
169     }
170     LayoutUnit startOffsetForLineInRegion(LayoutUnit position, bool shouldIndentText, RenderRegion* region, LayoutUnit logicalHeight = 0) const
171     {
172         return style()->isLeftToRightDirection() ? logicalLeftOffsetForLineInRegion(position, shouldIndentText, region, logicalHeight)
173             : logicalWidth() - logicalRightOffsetForLineInRegion(position, shouldIndentText, region, logicalHeight);
174     }
175     LayoutUnit endOffsetForLineInRegion(LayoutUnit position, bool shouldIndentText, RenderRegion* region, LayoutUnit logicalHeight = 0) const
176     {
177         return !style()->isLeftToRightDirection() ? logicalLeftOffsetForLineInRegion(position, shouldIndentText, region, logicalHeight)
178             : logicalWidth() - logicalRightOffsetForLineInRegion(position, shouldIndentText, region, logicalHeight);
179     }
180 
181     LayoutUnit availableLogicalWidthForLine(LayoutUnit position, bool shouldIndentText, LayoutUnit logicalHeight = 0) const
182     {
183         return availableLogicalWidthForLineInRegion(position, shouldIndentText, regionAtBlockOffset(position), logicalHeight);
184     }
185     LayoutUnit logicalRightOffsetForLine(LayoutUnit position, bool shouldIndentText, LayoutUnit logicalHeight = 0) const
186     {
187         return logicalRightOffsetForLine(position, logicalRightOffsetForContent(position), shouldIndentText, logicalHeight);
188     }
189     LayoutUnit logicalLeftOffsetForLine(LayoutUnit position, bool shouldIndentText, LayoutUnit logicalHeight = 0) const
190     {
191         return logicalLeftOffsetForLine(position, logicalLeftOffsetForContent(position), shouldIndentText, logicalHeight);
192     }
193     LayoutUnit pixelSnappedLogicalLeftOffsetForLine(LayoutUnit position, bool shouldIndentText, LayoutUnit logicalHeight = 0) const
194     {
195         return roundToInt(logicalLeftOffsetForLine(position, shouldIndentText, logicalHeight));
196     }
197     LayoutUnit pixelSnappedLogicalRightOffsetForLine(LayoutUnit position, bool shouldIndentText, LayoutUnit logicalHeight = 0) const
198     {
199         // FIXME: Multicolumn layouts break carrying over subpixel values to the logical right offset because the lines may be shifted
200         // by a subpixel value for all but the first column. This can lead to the actual pixel snapped width of the column being off
201         // by one pixel when rendered versus layed out, which can result in the line being clipped. For now, we have to floor.
202         // https://bugs.webkit.org/show_bug.cgi?id=105461
203         return floorToInt(logicalRightOffsetForLine(position, shouldIndentText, logicalHeight));
204     }
205     LayoutUnit startOffsetForLine(LayoutUnit position, bool shouldIndentText, LayoutUnit logicalHeight = 0) const
206     {
207         return style()->isLeftToRightDirection() ? logicalLeftOffsetForLine(position, shouldIndentText, logicalHeight)
208             : logicalWidth() - logicalRightOffsetForLine(position, shouldIndentText, logicalHeight);
209     }
210     LayoutUnit endOffsetForLine(LayoutUnit position, bool shouldIndentText, LayoutUnit logicalHeight = 0) const
211     {
212         return !style()->isLeftToRightDirection() ? logicalLeftOffsetForLine(position, shouldIndentText, logicalHeight)
213             : logicalWidth() - logicalRightOffsetForLine(position, shouldIndentText, logicalHeight);
214     }
215 
216     LayoutUnit textIndentOffset() const;
217 
218     virtual PositionWithAffinity positionForPoint(const LayoutPoint&) OVERRIDE;
219 
220     // Block flows subclass availableWidth to handle multi column layout (shrinking the width available to children when laying out.)
221     virtual LayoutUnit availableLogicalWidth() const OVERRIDE FINAL;
222 
223     LayoutPoint flipForWritingModeIncludingColumns(const LayoutPoint&) const;
224     void adjustStartEdgeForWritingModeIncludingColumns(LayoutRect&) const;
225 
226     LayoutUnit blockDirectionOffset(const LayoutSize& offsetFromBlock) const;
227     LayoutUnit inlineDirectionOffset(const LayoutSize& offsetFromBlock) const;
228 
firstRootBox()229     RootInlineBox* firstRootBox() const { return static_cast<RootInlineBox*>(firstLineBox()); }
lastRootBox()230     RootInlineBox* lastRootBox() const { return static_cast<RootInlineBox*>(lastLineBox()); }
231 
232     GapRects selectionGapRectsForRepaint(const RenderLayerModelObject* repaintContainer);
233     LayoutRect logicalLeftSelectionGap(RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
234                                        RenderObject* selObj, LayoutUnit logicalLeft, LayoutUnit logicalTop, LayoutUnit logicalHeight, const PaintInfo*);
235     LayoutRect logicalRightSelectionGap(RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
236                                         RenderObject* selObj, LayoutUnit logicalRight, LayoutUnit logicalTop, LayoutUnit logicalHeight, const PaintInfo*);
237     void getSelectionGapInfo(SelectionState, bool& leftGap, bool& rightGap);
238     RenderBlock* blockBeforeWithinSelectionRoot(LayoutSize& offset) const;
239 
240     LayoutRect logicalRectToPhysicalRect(const LayoutPoint& physicalPosition, const LayoutRect& logicalRect);
241 
242     // Helper methods for computing line counts and heights for line counts.
243     RootInlineBox* lineAtIndex(int) const;
244     int lineCount(const RootInlineBox* = 0, bool* = 0) const;
245     int heightForLineCount(int);
246     void clearTruncation();
247 
248     void adjustRectForColumns(LayoutRect&) const;
249     virtual void adjustForColumns(LayoutSize&, const LayoutPoint&) const OVERRIDE FINAL;
250     void adjustForColumnRect(LayoutSize& offset, const LayoutPoint& locationInContainer) const;
251 
252     void addContinuationWithOutline(RenderInline*);
253     bool paintsContinuationOutline(RenderInline*);
254 
virtualContinuation()255     virtual RenderBoxModelObject* virtualContinuation() const OVERRIDE FINAL { return continuation(); }
isAnonymousBlockContinuation()256     bool isAnonymousBlockContinuation() const { return continuation() && isAnonymousBlock(); }
257     RenderInline* inlineElementContinuation() const;
258     RenderBlock* blockElementContinuation() const;
259 
260     using RenderBoxModelObject::continuation;
261     using RenderBoxModelObject::setContinuation;
262 
263     static RenderBlock* createAnonymousWithParentRendererAndDisplay(const RenderObject*, EDisplay = BLOCK);
264     static RenderBlockFlow* createAnonymousColumnsWithParentRenderer(const RenderObject*);
265     static RenderBlockFlow* createAnonymousColumnSpanWithParentRenderer(const RenderObject*);
266     RenderBlock* createAnonymousBlock(EDisplay display = BLOCK) const { return createAnonymousWithParentRendererAndDisplay(this, display); }
createAnonymousColumnsBlock()267     RenderBlockFlow* createAnonymousColumnsBlock() const { return createAnonymousColumnsWithParentRenderer(this); }
createAnonymousColumnSpanBlock()268     RenderBlockFlow* createAnonymousColumnSpanBlock() const { return createAnonymousColumnSpanWithParentRenderer(this); }
269 
270     virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject* parent) const OVERRIDE;
271 
272     ColumnInfo* columnInfo() const;
273     int columnGap() const;
274 
275     void updateColumnInfoFromStyle(RenderStyle*);
276 
277     // These two functions take the ColumnInfo* to avoid repeated lookups of the info in the global HashMap.
278     unsigned columnCount(ColumnInfo*) const;
279     LayoutRect columnRectAt(ColumnInfo*, unsigned) const;
280 
paginationStrut()281     LayoutUnit paginationStrut() const { return m_rareData ? m_rareData->m_paginationStrut : LayoutUnit(); }
282     void setPaginationStrut(LayoutUnit);
283 
shouldBreakAtLineToAvoidWidow()284     bool shouldBreakAtLineToAvoidWidow() const { return m_rareData && m_rareData->m_lineBreakToAvoidWidow >= 0; }
285     void clearShouldBreakAtLineToAvoidWidow() const;
lineBreakToAvoidWidow()286     int lineBreakToAvoidWidow() const { return m_rareData ? m_rareData->m_lineBreakToAvoidWidow : -1; }
287     void setBreakAtLineToAvoidWidow(int);
288     void clearDidBreakAtLineToAvoidWidow();
289     void setDidBreakAtLineToAvoidWidow();
didBreakAtLineToAvoidWidow()290     bool didBreakAtLineToAvoidWidow() const { return m_rareData && m_rareData->m_didBreakAtLineToAvoidWidow; }
291 
292     // The page logical offset is the object's offset from the top of the page in the page progression
293     // direction (so an x-offset in vertical text and a y-offset for horizontal text).
pageLogicalOffset()294     LayoutUnit pageLogicalOffset() const { return m_rareData ? m_rareData->m_pageLogicalOffset : LayoutUnit(); }
295     void setPageLogicalOffset(LayoutUnit);
296 
297     // Accessors for logical width/height and margins in the containing block's block-flow direction.
298     enum ApplyLayoutDeltaMode { ApplyLayoutDelta, DoNotApplyLayoutDelta };
logicalWidthForChild(const RenderBox * child)299     LayoutUnit logicalWidthForChild(const RenderBox* child) const { return isHorizontalWritingMode() ? child->width() : child->height(); }
logicalHeightForChild(const RenderBox * child)300     LayoutUnit logicalHeightForChild(const RenderBox* child) const { return isHorizontalWritingMode() ? child->height() : child->width(); }
logicalTopForChild(const RenderBox * child)301     LayoutUnit logicalTopForChild(const RenderBox* child) const { return isHorizontalWritingMode() ? child->y() : child->x(); }
302     void setLogicalLeftForChild(RenderBox* child, LayoutUnit logicalLeft, ApplyLayoutDeltaMode = DoNotApplyLayoutDelta);
303     void setLogicalTopForChild(RenderBox* child, LayoutUnit logicalTop, ApplyLayoutDeltaMode = DoNotApplyLayoutDelta);
marginBeforeForChild(const RenderBoxModelObject * child)304     LayoutUnit marginBeforeForChild(const RenderBoxModelObject* child) const { return child->marginBefore(style()); }
marginAfterForChild(const RenderBoxModelObject * child)305     LayoutUnit marginAfterForChild(const RenderBoxModelObject* child) const { return child->marginAfter(style()); }
marginStartForChild(const RenderBoxModelObject * child)306     LayoutUnit marginStartForChild(const RenderBoxModelObject* child) const { return child->marginStart(style()); }
marginEndForChild(const RenderBoxModelObject * child)307     LayoutUnit marginEndForChild(const RenderBoxModelObject* child) const { return child->marginEnd(style()); }
setMarginStartForChild(RenderBox * child,LayoutUnit value)308     void setMarginStartForChild(RenderBox* child, LayoutUnit value) const { child->setMarginStart(value, style()); }
setMarginEndForChild(RenderBox * child,LayoutUnit value)309     void setMarginEndForChild(RenderBox* child, LayoutUnit value) const { child->setMarginEnd(value, style()); }
setMarginBeforeForChild(RenderBox * child,LayoutUnit value)310     void setMarginBeforeForChild(RenderBox* child, LayoutUnit value) const { child->setMarginBefore(value, style()); }
setMarginAfterForChild(RenderBox * child,LayoutUnit value)311     void setMarginAfterForChild(RenderBox* child, LayoutUnit value) const { child->setMarginAfter(value, style()); }
312     LayoutUnit collapsedMarginBeforeForChild(const RenderBox* child) const;
313     LayoutUnit collapsedMarginAfterForChild(const RenderBox* child) const;
314 
315     virtual void updateFirstLetter();
316 
scrollbarsChanged(bool,bool)317     virtual void scrollbarsChanged(bool /*horizontalScrollbarChanged*/, bool /*verticalScrollbarChanged*/) { };
318 
319     LayoutUnit logicalLeftOffsetForContent(RenderRegion*) const;
320     LayoutUnit logicalRightOffsetForContent(RenderRegion*) const;
availableLogicalWidthForContent(RenderRegion * region)321     LayoutUnit availableLogicalWidthForContent(RenderRegion* region) const
322     {
323         return max<LayoutUnit>(0, logicalRightOffsetForContent(region) - logicalLeftOffsetForContent(region));
324     }
startOffsetForContent(RenderRegion * region)325     LayoutUnit startOffsetForContent(RenderRegion* region) const
326     {
327         return style()->isLeftToRightDirection() ? logicalLeftOffsetForContent(region) : logicalWidth() - logicalRightOffsetForContent(region);
328     }
endOffsetForContent(RenderRegion * region)329     LayoutUnit endOffsetForContent(RenderRegion* region) const
330     {
331         return !style()->isLeftToRightDirection() ? logicalLeftOffsetForContent(region) : logicalWidth() - logicalRightOffsetForContent(region);
332     }
logicalLeftOffsetForContent(LayoutUnit blockOffset)333     LayoutUnit logicalLeftOffsetForContent(LayoutUnit blockOffset) const
334     {
335         return logicalLeftOffsetForContent(regionAtBlockOffset(blockOffset));
336     }
logicalRightOffsetForContent(LayoutUnit blockOffset)337     LayoutUnit logicalRightOffsetForContent(LayoutUnit blockOffset) const
338     {
339         return logicalRightOffsetForContent(regionAtBlockOffset(blockOffset));
340     }
availableLogicalWidthForContent(LayoutUnit blockOffset)341     LayoutUnit availableLogicalWidthForContent(LayoutUnit blockOffset) const
342     {
343         return availableLogicalWidthForContent(regionAtBlockOffset(blockOffset));
344     }
startOffsetForContent(LayoutUnit blockOffset)345     LayoutUnit startOffsetForContent(LayoutUnit blockOffset) const
346     {
347         return startOffsetForContent(regionAtBlockOffset(blockOffset));
348     }
endOffsetForContent(LayoutUnit blockOffset)349     LayoutUnit endOffsetForContent(LayoutUnit blockOffset) const
350     {
351         return endOffsetForContent(regionAtBlockOffset(blockOffset));
352     }
logicalLeftOffsetForContent()353     LayoutUnit logicalLeftOffsetForContent() const { return isHorizontalWritingMode() ? borderLeft() + paddingLeft() : borderTop() + paddingTop(); }
logicalRightOffsetForContent()354     LayoutUnit logicalRightOffsetForContent() const { return logicalLeftOffsetForContent() + availableLogicalWidth(); }
startOffsetForContent()355     LayoutUnit startOffsetForContent() const { return style()->isLeftToRightDirection() ? logicalLeftOffsetForContent() : logicalWidth() - logicalRightOffsetForContent(); }
endOffsetForContent()356     LayoutUnit endOffsetForContent() const { return !style()->isLeftToRightDirection() ? logicalLeftOffsetForContent() : logicalWidth() - logicalRightOffsetForContent(); }
357 
358     LayoutUnit computeStartPositionDeltaForChildAvoidingFloats(const RenderBox* child, LayoutUnit childMarginStart, RenderRegion* = 0);
359 
360 #ifndef NDEBUG
361     void checkPositionedObjectsNeedLayout();
362     void showLineTreeAndMark(const InlineBox* = 0, const char* = 0, const InlineBox* = 0, const char* = 0, const RenderObject* = 0) const;
363 #endif
364 
ensureShapeInsideInfo()365     ShapeInsideInfo* ensureShapeInsideInfo()
366     {
367         if (!m_rareData || !m_rareData->m_shapeInsideInfo)
368             setShapeInsideInfo(ShapeInsideInfo::createInfo(this));
369         return m_rareData->m_shapeInsideInfo.get();
370     }
shapeInsideInfo()371     ShapeInsideInfo* shapeInsideInfo() const
372     {
373         return m_rareData && m_rareData->m_shapeInsideInfo && ShapeInsideInfo::isEnabledFor(this) ? m_rareData->m_shapeInsideInfo.get() : 0;
374     }
setShapeInsideInfo(PassOwnPtr<ShapeInsideInfo> value)375     void setShapeInsideInfo(PassOwnPtr<ShapeInsideInfo> value)
376     {
377         if (!m_rareData)
378             m_rareData = adoptPtr(new RenderBlockRareData());
379         m_rareData->m_shapeInsideInfo = value;
380     }
381     ShapeInsideInfo* layoutShapeInsideInfo() const;
382     bool allowsShapeInsideInfoSharing(const RenderBlock* other) const;
383     LayoutSize logicalOffsetFromShapeAncestorContainer(const RenderBlock* container) const;
384     virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) OVERRIDE;
385 
386     // inline-block elements paint all phases atomically. This function ensures that. Certain other elements
387     // (grid items, flex items) require this behavior as well, and this function exists as a helper for them.
388     // It is expected that the caller will call this function independent of the value of paintInfo.phase.
389     static void paintAsInlineBlock(RenderObject*, PaintInfo&, const LayoutPoint&);
390 protected:
391     virtual void willBeDestroyed();
392 
393     void dirtyForLayoutFromPercentageHeightDescendants(SubtreeLayoutScope&);
394 
395     virtual void layout();
396     virtual void didLayout(ResourceLoadPriorityOptimizer&);
397     virtual void didScroll(ResourceLoadPriorityOptimizer&);
398     void updateStyleImageLoadingPriorities(ResourceLoadPriorityOptimizer&);
399 
400     void layoutPositionedObjects(bool relayoutChildren, bool fixedPositionObjectsOnly = false);
401     void markFixedPositionObjectForLayoutIfNeeded(RenderObject* child, SubtreeLayoutScope&);
402 
403     LayoutUnit marginIntrinsicLogicalWidthForChild(RenderBox* child) const;
404 
supportsPartialLayout()405     virtual bool supportsPartialLayout() const OVERRIDE { return true; };
406 
407     virtual void paint(PaintInfo&, const LayoutPoint&);
408     virtual void paintObject(PaintInfo&, const LayoutPoint&);
409     virtual void paintChildren(PaintInfo&, const LayoutPoint&);
410     void paintChild(RenderBox*, PaintInfo&, const LayoutPoint&);
411     void paintChildAsInlineBlock(RenderBox*, PaintInfo&, const LayoutPoint&);
412 
413     LayoutUnit logicalRightOffsetForLine(LayoutUnit logicalTop, LayoutUnit fixedOffset, bool applyTextIndent, LayoutUnit logicalHeight = 0) const
414     {
415         return adjustLogicalRightOffsetForLine(logicalRightFloatOffsetForLine(logicalTop, fixedOffset, logicalHeight), applyTextIndent);
416     }
417     LayoutUnit logicalLeftOffsetForLine(LayoutUnit logicalTop, LayoutUnit fixedOffset, bool applyTextIndent, LayoutUnit logicalHeight = 0) const
418     {
419         return adjustLogicalLeftOffsetForLine(logicalLeftFloatOffsetForLine(logicalTop, fixedOffset, logicalHeight), applyTextIndent);
420     }
421 
adjustInlineDirectionLineBounds(int,float &,float &)422     virtual void adjustInlineDirectionLineBounds(int /* expansionOpportunityCount */, float& /* logicalLeft */, float& /* logicalWidth */) const { }
423 
424     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
425 
426     virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const OVERRIDE;
427     virtual void computePreferredLogicalWidths() OVERRIDE;
428     void adjustIntrinsicLogicalWidthsForColumns(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const;
429 
430     virtual int firstLineBoxBaseline() const;
431     virtual int inlineBlockBaseline(LineDirectionMode) const OVERRIDE;
432     int lastLineBoxBaseline(LineDirectionMode) const;
433 
434     virtual void updateHitTestResult(HitTestResult&, const LayoutPoint&);
435 
436     // Delay update scrollbar until finishDelayRepaint() will be
437     // called. This function is used when a flexbox is laying out its
438     // descendant. If multiple calls are made to startDelayRepaint(),
439     // finishDelayRepaint() will do nothing until finishDelayRepaint()
440     // is called the same number of times.
441     static void startDelayUpdateScrollInfo();
442     static void finishDelayUpdateScrollInfo();
443 
444     void updateScrollInfoAfterLayout();
445 
446     virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle);
447     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
448 
449     virtual bool hasLineIfEmpty() const;
450 
451     bool simplifiedLayout();
452     virtual void simplifiedNormalFlowLayout();
453 
454     void setDesiredColumnCountAndWidth(int, LayoutUnit);
455 
456 public:
457     virtual void computeOverflow(LayoutUnit oldClientAfterEdge, bool = false);
458 protected:
459     virtual void addOverflowFromChildren();
460     void addOverflowFromPositionedObjects();
461     void addOverflowFromBlockChildren();
462     void addVisualOverflowFromTheme();
463 
464     virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer = 0) OVERRIDE;
465 
466     virtual void computeSelfHitTestRects(Vector<LayoutRect>&, const LayoutPoint& layerOffset) const OVERRIDE;
467 
468     bool updateRegionsAndShapesLogicalSize(RenderFlowThread*);
469     void computeRegionRangeForBlock(RenderFlowThread*);
470 
471     void updateBlockChildDirtyBitsBeforeLayout(bool relayoutChildren, RenderBox*);
472 
473     virtual void checkForPaginationLogicalHeightChange(LayoutUnit& pageLogicalHeight, bool& pageLogicalHeightChanged, bool& hasSpecifiedPageLogicalHeight);
474 
isInlineBlockOrInlineTable()475     virtual bool isInlineBlockOrInlineTable() const OVERRIDE FINAL { return isInline() && isReplaced(); }
476 
477 private:
478     // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
logicalRightFloatOffsetForLine(LayoutUnit,LayoutUnit fixedOffset,LayoutUnit)479     virtual LayoutUnit logicalRightFloatOffsetForLine(LayoutUnit, LayoutUnit fixedOffset, LayoutUnit) const { return fixedOffset; }
480     // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
logicalLeftFloatOffsetForLine(LayoutUnit,LayoutUnit fixedOffset,LayoutUnit)481     virtual LayoutUnit logicalLeftFloatOffsetForLine(LayoutUnit, LayoutUnit fixedOffset, LayoutUnit) const { return fixedOffset; }
482     LayoutUnit adjustLogicalRightOffsetForLine(LayoutUnit offsetFromFloats, bool applyTextIndent) const;
483     LayoutUnit adjustLogicalLeftOffsetForLine(LayoutUnit offsetFromFloats, bool applyTextIndent) const;
484 
485     void computeShapeSize();
486     void updateRegionsAndShapesAfterChildLayout(RenderFlowThread*, bool);
487     void updateShapeInsideInfoAfterStyleChange(const ShapeValue*, const ShapeValue* oldShape);
488     void relayoutShapeDescendantIfMoved(RenderBlock* child, LayoutSize offset);
489 
virtualChildren()490     virtual RenderObjectChildList* virtualChildren() OVERRIDE FINAL { return children(); }
virtualChildren()491     virtual const RenderObjectChildList* virtualChildren() const OVERRIDE FINAL { return children(); }
492 
493     virtual const char* renderName() const;
494 
isRenderBlock()495     virtual bool isRenderBlock() const OVERRIDE FINAL { return true; }
496 
497     void makeChildrenNonInline(RenderObject* insertionPoint = 0);
498     virtual void removeLeftoverAnonymousBlock(RenderBlock* child);
499 
500     static void collapseAnonymousBlockChild(RenderBlock* parent, RenderBlock* child);
501     // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
moveAllChildrenIncludingFloatsTo(RenderBlock * toBlock,bool fullRemoveInsert)502     virtual void moveAllChildrenIncludingFloatsTo(RenderBlock* toBlock, bool fullRemoveInsert) { moveAllChildrenTo(toBlock, fullRemoveInsert); }
503 
dirtyLinesFromChangedChild(RenderObject * child)504     virtual void dirtyLinesFromChangedChild(RenderObject* child) OVERRIDE FINAL { m_lineBoxes.dirtyLinesFromChangedChild(this, child); }
505 
506     void addChildToContinuation(RenderObject* newChild, RenderObject* beforeChild);
507     void addChildIgnoringContinuation(RenderObject* newChild, RenderObject* beforeChild);
508     void addChildToAnonymousColumnBlocks(RenderObject* newChild, RenderObject* beforeChild);
509 
510     void addChildIgnoringAnonymousColumnBlocks(RenderObject* newChild, RenderObject* beforeChild = 0);
511 
512     virtual bool isSelfCollapsingBlock() const OVERRIDE FINAL;
513 
514     void insertIntoTrackedRendererMaps(RenderBox* descendant, TrackedDescendantsMap*&, TrackedContainerMap*&);
515     static void removeFromTrackedRendererMaps(RenderBox* descendant, TrackedDescendantsMap*&, TrackedContainerMap*&);
516 
createRootInlineBox()517     virtual RootInlineBox* createRootInlineBox() { return 0; } // Subclassed by RenderBlockFlow, SVG and Ruby.
518 
519     // Called to lay out the legend for a fieldset or the ruby text of a ruby run.
layoutSpecialExcludedChild(bool,SubtreeLayoutScope &)520     virtual RenderObject* layoutSpecialExcludedChild(bool /*relayoutChildren*/, SubtreeLayoutScope&) { return 0; }
521 
522     void createFirstLetterRenderer(RenderObject* firstLetterBlock, RenderObject* currentChild, unsigned length);
523     void updateFirstLetterStyle(RenderObject* firstLetterBlock, RenderObject* firstLetterContainer);
524 
525     Node* nodeForHitTest() const;
526 
527     // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
paintFloats(PaintInfo &,const LayoutPoint &,bool)528     virtual void paintFloats(PaintInfo&, const LayoutPoint&, bool) { }
529     void paintContents(PaintInfo&, const LayoutPoint&);
530     void paintColumnContents(PaintInfo&, const LayoutPoint&, bool paintFloats = false);
531     void paintColumnRules(PaintInfo&, const LayoutPoint&);
532     void paintSelection(PaintInfo&, const LayoutPoint&);
533     void paintCaret(PaintInfo&, const LayoutPoint&, CaretType);
534 
hasCaret()535     bool hasCaret() const { return hasCaret(CursorCaret) || hasCaret(DragCaret); }
536     bool hasCaret(CaretType) const;
537 
538     virtual bool avoidsFloats() const;
539 
540     bool hitTestColumns(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction);
541     bool hitTestContents(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction);
542     // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
hitTestFloats(const HitTestRequest &,HitTestResult &,const HitTestLocation &,const LayoutPoint &)543     virtual bool hitTestFloats(const HitTestRequest&, HitTestResult&, const HitTestLocation&, const LayoutPoint&) { return false; }
544 
545     virtual bool isPointInOverflowControl(HitTestResult&, const LayoutPoint& locationInContainer, const LayoutPoint& accumulatedOffset);
546 
547     // FIXME: Make this method const so we can remove the const_cast in computeIntrinsicLogicalWidths.
548     void computeInlinePreferredLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth);
549     void computeBlockPreferredLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const;
550 
551     // Obtains the nearest enclosing block (including this block) that contributes a first-line style to our inline
552     // children.
553     virtual RenderBlock* firstLineBlock() const;
554 
555     virtual LayoutRect rectWithOutlineForRepaint(const RenderLayerModelObject* repaintContainer, LayoutUnit outlineWidth) const OVERRIDE FINAL;
556     virtual RenderStyle* outlineStyleForRepaint() const OVERRIDE FINAL;
557 
558     virtual RenderObject* hoverAncestor() const OVERRIDE FINAL;
559     virtual void updateDragState(bool dragOn) OVERRIDE FINAL;
560     virtual void childBecameNonInline(RenderObject* child) OVERRIDE FINAL;
561 
selectionRectForRepaint(const RenderLayerModelObject * repaintContainer,bool)562     virtual LayoutRect selectionRectForRepaint(const RenderLayerModelObject* repaintContainer, bool /*clipToVisibleContent*/) OVERRIDE FINAL
563     {
564         return selectionGapRectsForRepaint(repaintContainer);
565     }
566     virtual bool shouldPaintSelectionGaps() const OVERRIDE FINAL;
567     bool isSelectionRoot() const;
568     GapRects selectionGaps(RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
569                            LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLogicalRight, const PaintInfo* = 0);
570     GapRects blockSelectionGaps(RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
571                                 LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLogicalRight, const PaintInfo*);
572     LayoutRect blockSelectionGap(RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
573                                  LayoutUnit lastLogicalTop, LayoutUnit lastLogicalLeft, LayoutUnit lastLogicalRight, LayoutUnit logicalBottom, const PaintInfo*);
574     LayoutUnit logicalLeftSelectionOffset(RenderBlock* rootBlock, LayoutUnit position);
575     LayoutUnit logicalRightSelectionOffset(RenderBlock* rootBlock, LayoutUnit position);
576 
577     // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
clipOutFloatingObjects(RenderBlock *,const PaintInfo *,const LayoutPoint &,const LayoutSize &)578     virtual void clipOutFloatingObjects(RenderBlock*, const PaintInfo*, const LayoutPoint&, const LayoutSize&) { };
579 
580     virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const;
581     virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const;
582 
583     LayoutUnit desiredColumnWidth() const;
584 
585     void paintContinuationOutlines(PaintInfo&, const LayoutPoint&);
586 
587     virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) OVERRIDE FINAL;
588 
589     void adjustPointToColumnContents(LayoutPoint&) const;
590 
591     void fitBorderToLinesIfNeeded(); // Shrink the box in which the border paints if border-fit is set.
592     virtual void adjustForBorderFit(LayoutUnit x, LayoutUnit& left, LayoutUnit& right) const; // Helper function for borderFitAdjust
593 
594     void markLinesDirtyInBlockRange(LayoutUnit logicalTop, LayoutUnit logicalBottom, RootInlineBox* highest = 0);
595 
596     Position positionForBox(InlineBox*, bool start = true) const;
597     PositionWithAffinity positionForPointWithInlineChildren(const LayoutPoint&);
598 
599     virtual void calcColumnWidth();
600     void makeChildrenAnonymousColumnBlocks(RenderObject* beforeChild, RenderBlockFlow* newBlockBox, RenderObject* newChild);
601 
602     bool expandsToEncloseOverhangingFloats() const;
603 
604     void splitBlocks(RenderBlock* fromBlock, RenderBlock* toBlock, RenderBlock* middleBlock,
605                      RenderObject* beforeChild, RenderBoxModelObject* oldCont);
606     void splitFlow(RenderObject* beforeChild, RenderBlock* newBlockBox,
607                    RenderObject* newChild, RenderBoxModelObject* oldCont);
608     RenderBlock* clone() const;
609     RenderBlock* continuationBefore(RenderObject* beforeChild);
610     RenderBlockFlow* containingColumnsBlock(bool allowAnonymousColumnBlock = true);
611     RenderBlockFlow* columnsBlockForSpanningElement(RenderObject* newChild);
612 
613     // End helper functions and structs used by layoutBlockChildren.
614 
615 protected:
616     void determineLogicalLeftPositionForChild(RenderBox* child, ApplyLayoutDeltaMode = DoNotApplyLayoutDelta);
617 
618     // Pagination routines.
619     bool relayoutToAvoidWidows(LayoutStateMaintainer&);
620 
621     // Returns the logicalOffset at the top of the next page. If the offset passed in is already at the top of the current page,
622     // then nextPageLogicalTop with ExcludePageBoundary will still move to the top of the next page. nextPageLogicalTop with
623     // IncludePageBoundary set will not.
624     //
625     // 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.
626     enum PageBoundaryRule { ExcludePageBoundary, IncludePageBoundary };
627     LayoutUnit nextPageLogicalTop(LayoutUnit logicalOffset, PageBoundaryRule = ExcludePageBoundary) const;
628     bool hasNextPage(LayoutUnit logicalOffset, PageBoundaryRule = ExcludePageBoundary) const;
629 
630     virtual ColumnInfo::PaginationUnit paginationUnit() const;
631 
632 public:
633     LayoutUnit pageLogicalTopForOffset(LayoutUnit offset) const;
634     LayoutUnit pageLogicalHeightForOffset(LayoutUnit offset) const;
635     LayoutUnit pageRemainingLogicalHeightForOffset(LayoutUnit offset, PageBoundaryRule = IncludePageBoundary) const;
636 
637 protected:
638     bool pushToNextPageWithMinimumLogicalHeight(LayoutUnit& adjustment, LayoutUnit logicalOffset, LayoutUnit minimumLogicalHeight) const;
639 
640     // A page break is required at some offset due to space shortage in the current fragmentainer.
641     void setPageBreak(LayoutUnit offset, LayoutUnit spaceShortage);
642 
643     // Update minimum page height required to avoid fragmentation where it shouldn't occur (inside
644     // unbreakable content, between orphans and widows, etc.). This will be used as a hint to the
645     // column balancer to help set a good minimum column height.
646     void updateMinimumPageHeight(LayoutUnit offset, LayoutUnit minHeight);
647 
648     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.
649     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.
650     void updateRegionForLine(RootInlineBox*) const;
651 
652     // Adjust from painting offsets to the local coords of this renderer
653     void offsetForContents(LayoutPoint&) const;
654 
655     // This function is called to test a line box that has moved in the block direction to see if it has ended up in a new
656     // region/page/column that has a different available line width than the old one. Used to know when you have to dirty a
657     // line, i.e., that it can't be re-used.
658     bool lineWidthForPaginatedLineChanged(RootInlineBox*, LayoutUnit lineDelta, RenderFlowThread*) const;
659 
660     bool logicalWidthChangedInRegions(RenderFlowThread*) const;
661 
662     virtual bool requiresColumns(int desiredColumnCount) const;
663 
664     virtual bool updateLogicalWidthAndColumnWidth();
665 
canCollapseAnonymousBlockChild()666     virtual bool canCollapseAnonymousBlockChild() const { return true; }
667 
668 public:
669     virtual LayoutUnit offsetFromLogicalTopOfFirstPage() const OVERRIDE FINAL;
670     RenderRegion* regionAtBlockOffset(LayoutUnit) const;
671     RenderRegion* clampToStartAndEndRegions(RenderRegion*) const;
672 
673 public:
674 
675     // Allocated only when some of these fields have non-default values
676     struct RenderBlockRareData {
677         WTF_MAKE_NONCOPYABLE(RenderBlockRareData); WTF_MAKE_FAST_ALLOCATED;
678     public:
RenderBlockRareDataRenderBlockRareData679         RenderBlockRareData()
680             : m_paginationStrut(0)
681             , m_pageLogicalOffset(0)
682             , m_lineBreakToAvoidWidow(-1)
683             , m_didBreakAtLineToAvoidWidow(false)
684         {
685         }
686 
687         LayoutUnit m_paginationStrut;
688         LayoutUnit m_pageLogicalOffset;
689 
690         int m_lineBreakToAvoidWidow;
691         OwnPtr<ShapeInsideInfo> m_shapeInsideInfo;
692         bool m_didBreakAtLineToAvoidWidow : 1;
693      };
694 
695 protected:
696     OwnPtr<RenderBlockRareData> m_rareData;
697 
698     RenderObjectChildList m_children;
699     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>.
700 
701     mutable signed m_lineHeight : 27;
702     unsigned m_hasMarginBeforeQuirk : 1; // Note these quirk values can't be put in RenderBlockRareData since they are set too frequently.
703     unsigned m_hasMarginAfterQuirk : 1;
704     unsigned m_beingDestroyed : 1;
705     unsigned m_hasMarkupTruncation : 1;
706     unsigned m_hasBorderOrPaddingLogicalWidthChanged : 1;
707 
708     // RenderRubyBase objects need to be able to split and merge, moving their children around
709     // (calling moveChildTo, moveAllChildrenTo, and makeChildrenNonInline).
710     friend class RenderRubyBase;
711     // FIXME-BLOCKFLOW: Remove this when the line layout stuff has all moved out of RenderBlock
712     friend class LineBreaker;
713 
714     // FIXME: This is temporary as we move code that accesses block flow
715     // member variables out of RenderBlock and into RenderBlockFlow.
716     friend class RenderBlockFlow;
717 };
718 
719 
allowsShapeInsideInfoSharing(const RenderBlock * other)720 inline bool RenderBlock::allowsShapeInsideInfoSharing(const RenderBlock* other) const
721 {
722     if (!other)
723         return false;
724     for (const RenderBlock* current = this; current && current != other && !current->isRenderFlowThread(); current = current->containingBlock()) {
725         if (current->isInline() || current->isFloating())
726             return false;
727         if (current->parent() != current->containingBlock())
728             return false;
729     }
730     return true;
731 }
732 
733 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderBlock, isRenderBlock());
734 
735 } // namespace WebCore
736 
737 #endif // RenderBlock_h
738