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 "ColumnInfo.h"
27 #include "FloatingObjects.h"
29 #include "PODIntervalTree.h"
30 #include "RenderBox.h"
31 #include "RenderLineBoxList.h"
32 #include "RootInlineBox.h"
33 #include "TextBreakIterator.h"
35 #include <wtf/OwnPtr.h>
36 #include <wtf/ListHashSet.h>
38 #if ENABLE(CSS_SHAPES)
39 #include "ShapeInsideInfo.h"
40 #include "ShapeValue.h"
47 class LayoutStateMaintainer;
48 class LineLayoutState;
50 class LogicalSelectionOffsetCaches;
58 #if ENABLE(CSS_SHAPES)
62 class WordMeasurement;
64 template <class Iterator, class Run> class BidiResolver;
65 template <class Run> class BidiRunList;
66 template <class Iterator> struct MidpointState;
67 typedef BidiResolver<InlineIterator, BidiRun> InlineBidiResolver;
68 typedef MidpointState<InlineIterator> LineMidpointState;
69 typedef WTF::ListHashSet<RenderBox*, 16> TrackedRendererListHashSet;
70 typedef WTF::HashMap<const RenderBlock*, OwnPtr<TrackedRendererListHashSet> > TrackedDescendantsMap;
71 typedef WTF::HashMap<const RenderBox*, OwnPtr<HashSet<RenderBlock*> > > TrackedContainerMap;
72 typedef Vector<WordMeasurement, 64> WordMeasurements;
74 enum CaretType { CursorCaret, DragCaret };
75 enum ContainingBlockState { NewContainingBlock, SameContainingBlock };
77 #if ENABLE(IOS_TEXT_AUTOSIZING)
79 NOT_SET = 0, NO_LINE = 1, ONE_LINE = 2, MULTI_LINE = 3
84 DefaultTextRunFlags = 0,
85 RespectDirection = 1 << 0,
86 RespectDirectionOverride = 1 << 1
89 typedef unsigned TextRunFlags;
91 class RenderBlock : public RenderBox {
93 friend class LineLayoutState;
95 // Used by the PODIntervalTree for debugging the FloatingObject.
96 template <class> friend struct ValueToString;
100 explicit RenderBlock(Element*, unsigned baseTypeFlags);
101 virtual ~RenderBlock();
104 static RenderBlock* createAnonymous(Document&);
106 bool beingDestroyed() const { return m_beingDestroyed; }
108 // These two functions are overridden for inline-block.
109 virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE FINAL;
110 virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
112 LayoutUnit minLineHeightForReplacedRenderer(bool isFirstLine, LayoutUnit replacedHeight) const;
114 RenderLineBoxList& lineBoxes() { return m_lineBoxes; }
115 const RenderLineBoxList& lineBoxes() const { return m_lineBoxes; }
117 InlineFlowBox* firstLineBox() const { return m_lineBoxes.firstLineBox(); }
118 InlineFlowBox* lastLineBox() const { return m_lineBoxes.lastLineBox(); }
120 // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
121 virtual void deleteLineBoxTree();
123 virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0) OVERRIDE;
124 virtual void removeChild(RenderObject*) OVERRIDE;
126 virtual void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0);
128 void insertPositionedObject(RenderBox*);
129 static void removePositionedObject(RenderBox*);
130 void removePositionedObjects(RenderBlock*, ContainingBlockState = SameContainingBlock);
132 TrackedRendererListHashSet* positionedObjects() const;
133 bool hasPositionedObjects() const
135 TrackedRendererListHashSet* objects = positionedObjects();
136 return objects && !objects->isEmpty();
139 void addPercentHeightDescendant(RenderBox*);
140 static void removePercentHeightDescendant(RenderBox*);
141 TrackedRendererListHashSet* percentHeightDescendants() const;
142 static bool hasPercentHeightContainerMap();
143 static bool hasPercentHeightDescendant(RenderBox*);
144 static void clearPercentHeightDescendantsFrom(RenderBox*);
145 static void removePercentHeightDescendantIfNeeded(RenderBox*);
147 void setHasMarkupTruncation(bool b) { m_hasMarkupTruncation = b; }
148 bool hasMarkupTruncation() const { return m_hasMarkupTruncation; }
150 void setHasMarginBeforeQuirk(bool b) { m_hasMarginBeforeQuirk = b; }
151 void setHasMarginAfterQuirk(bool b) { m_hasMarginAfterQuirk = b; }
153 bool hasMarginBeforeQuirk() const { return m_hasMarginBeforeQuirk; }
154 bool hasMarginAfterQuirk() const { return m_hasMarginAfterQuirk; }
156 bool hasMarginBeforeQuirk(const RenderBox* child) const;
157 bool hasMarginAfterQuirk(const RenderBox* child) const;
159 RootInlineBox* createAndAppendRootInlineBox();
161 bool generatesLineBoxesForInlineChild(RenderObject*);
163 void markPositionedObjectsForLayout();
164 virtual void markForPaginationRelayoutIfNeeded() OVERRIDE FINAL;
166 // FIXME-BLOCKFLOW: Remove virtualizaion when all of the line layout code has been moved out of RenderBlock
167 virtual bool containsFloats() const { return false; }
169 // Versions that can compute line offsets with the region and page offset passed in. Used for speed to avoid having to
170 // compute the region all over again when you already know it.
171 LayoutUnit availableLogicalWidthForLine(LayoutUnit position, bool shouldIndentText, RenderRegion* region, LayoutUnit logicalHeight = 0) const
173 return max<LayoutUnit>(0, logicalRightOffsetForLine(position, shouldIndentText, region, logicalHeight)
174 - logicalLeftOffsetForLine(position, shouldIndentText, region, logicalHeight));
176 LayoutUnit logicalRightOffsetForLine(LayoutUnit position, bool shouldIndentText, RenderRegion* region, LayoutUnit logicalHeight = 0) const
178 return logicalRightOffsetForLine(position, logicalRightOffsetForContent(region), shouldIndentText, 0, logicalHeight);
180 LayoutUnit logicalLeftOffsetForLine(LayoutUnit position, bool shouldIndentText, RenderRegion* region, LayoutUnit logicalHeight = 0) const
182 return logicalLeftOffsetForLine(position, logicalLeftOffsetForContent(region), shouldIndentText, 0, logicalHeight);
184 LayoutUnit startOffsetForLine(LayoutUnit position, bool shouldIndentText, RenderRegion* region, LayoutUnit logicalHeight = 0) const
186 return style()->isLeftToRightDirection() ? logicalLeftOffsetForLine(position, shouldIndentText, region, logicalHeight)
187 : logicalWidth() - logicalRightOffsetForLine(position, shouldIndentText, region, logicalHeight);
189 LayoutUnit endOffsetForLine(LayoutUnit position, bool shouldIndentText, RenderRegion* region, LayoutUnit logicalHeight = 0) const
191 return !style()->isLeftToRightDirection() ? logicalLeftOffsetForLine(position, shouldIndentText, region, logicalHeight)
192 : logicalWidth() - logicalRightOffsetForLine(position, shouldIndentText, region, logicalHeight);
195 LayoutUnit availableLogicalWidthForLine(LayoutUnit position, bool shouldIndentText, LayoutUnit logicalHeight = 0) const
197 return availableLogicalWidthForLine(position, shouldIndentText, regionAtBlockOffset(position), logicalHeight);
199 LayoutUnit logicalRightOffsetForLine(LayoutUnit position, bool shouldIndentText, LayoutUnit logicalHeight = 0) const
201 return logicalRightOffsetForLine(position, logicalRightOffsetForContent(position), shouldIndentText, 0, logicalHeight);
203 LayoutUnit logicalLeftOffsetForLine(LayoutUnit position, bool shouldIndentText, LayoutUnit logicalHeight = 0) const
205 return logicalLeftOffsetForLine(position, logicalLeftOffsetForContent(position), shouldIndentText, 0, logicalHeight);
207 LayoutUnit pixelSnappedLogicalLeftOffsetForLine(LayoutUnit position, bool shouldIndentText, LayoutUnit logicalHeight = 0) const
209 return roundToInt(logicalLeftOffsetForLine(position, shouldIndentText, logicalHeight));
211 LayoutUnit pixelSnappedLogicalRightOffsetForLine(LayoutUnit position, bool shouldIndentText, LayoutUnit logicalHeight = 0) const
213 // FIXME: Multicolumn layouts break carrying over subpixel values to the logical right offset because the lines may be shifted
214 // by a subpixel value for all but the first column. This can lead to the actual pixel snapped width of the column being off
215 // by one pixel when rendered versus layed out, which can result in the line being clipped. For now, we have to floor.
216 // https://bugs.webkit.org/show_bug.cgi?id=105461
217 return floorToInt(logicalRightOffsetForLine(position, shouldIndentText, logicalHeight));
219 LayoutUnit startOffsetForLine(LayoutUnit position, bool shouldIndentText, LayoutUnit logicalHeight = 0) const
221 return style()->isLeftToRightDirection() ? logicalLeftOffsetForLine(position, shouldIndentText, logicalHeight)
222 : logicalWidth() - logicalRightOffsetForLine(position, shouldIndentText, logicalHeight);
224 LayoutUnit endOffsetForLine(LayoutUnit position, bool shouldIndentText, LayoutUnit logicalHeight = 0) const
226 return !style()->isLeftToRightDirection() ? logicalLeftOffsetForLine(position, shouldIndentText, logicalHeight)
227 : logicalWidth() - logicalRightOffsetForLine(position, shouldIndentText, logicalHeight);
230 LayoutUnit startAlignedOffsetForLine(LayoutUnit position, bool shouldIndentText);
231 LayoutUnit textIndentOffset() const;
233 virtual VisiblePosition positionForPoint(const LayoutPoint&) OVERRIDE;
235 // Block flows subclass availableWidth to handle multi column layout (shrinking the width available to children when laying out.)
236 virtual LayoutUnit availableLogicalWidth() const OVERRIDE FINAL;
238 LayoutPoint flipForWritingModeIncludingColumns(const LayoutPoint&) const;
239 void adjustStartEdgeForWritingModeIncludingColumns(LayoutRect&) const;
241 RootInlineBox* firstRootBox() const { return static_cast<RootInlineBox*>(firstLineBox()); }
242 RootInlineBox* lastRootBox() const { return static_cast<RootInlineBox*>(lastLineBox()); }
244 bool containsNonZeroBidiLevel() const;
246 GapRects selectionGapRectsForRepaint(const RenderLayerModelObject* repaintContainer);
247 LayoutRect logicalLeftSelectionGap(RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
248 RenderObject* selObj, LayoutUnit logicalLeft, LayoutUnit logicalTop, LayoutUnit logicalHeight, const LogicalSelectionOffsetCaches&, const PaintInfo*);
249 LayoutRect logicalRightSelectionGap(RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
250 RenderObject* selObj, LayoutUnit logicalRight, LayoutUnit logicalTop, LayoutUnit logicalHeight, const LogicalSelectionOffsetCaches&, const PaintInfo*);
251 void getSelectionGapInfo(SelectionState, bool& leftGap, bool& rightGap);
252 RenderBlock* blockBeforeWithinSelectionRoot(LayoutSize& offset) const;
254 LayoutRect logicalRectToPhysicalRect(const LayoutPoint& physicalPosition, const LayoutRect& logicalRect);
256 // Helper methods for computing line counts and heights for line counts.
257 RootInlineBox* lineAtIndex(int) const;
258 int lineCount(const RootInlineBox* = 0, bool* = 0) const;
259 int heightForLineCount(int);
260 void clearTruncation();
262 void adjustRectForColumns(LayoutRect&) const;
263 virtual void adjustForColumns(LayoutSize&, const LayoutPoint&) const OVERRIDE FINAL;
264 void adjustForColumnRect(LayoutSize& offset, const LayoutPoint& locationInContainer) const;
266 void addContinuationWithOutline(RenderInline*);
267 bool paintsContinuationOutline(RenderInline*);
269 virtual RenderBoxModelObject* virtualContinuation() const OVERRIDE FINAL { return continuation(); }
270 bool isAnonymousBlockContinuation() const { return isAnonymousBlock() && continuation(); }
271 RenderInline* inlineElementContinuation() const;
272 RenderBlock* blockElementContinuation() const;
274 using RenderBoxModelObject::continuation;
275 using RenderBoxModelObject::setContinuation;
277 static RenderBlock* createAnonymousWithParentRendererAndDisplay(const RenderObject*, EDisplay = BLOCK);
278 static RenderBlock* createAnonymousColumnsWithParentRenderer(const RenderObject*);
279 static RenderBlock* createAnonymousColumnSpanWithParentRenderer(const RenderObject*);
280 RenderBlock* createAnonymousBlock(EDisplay display = BLOCK) const { return createAnonymousWithParentRendererAndDisplay(this, display); }
281 RenderBlock* createAnonymousColumnsBlock() const { return createAnonymousColumnsWithParentRenderer(this); }
282 RenderBlock* createAnonymousColumnSpanBlock() const { return createAnonymousColumnSpanWithParentRenderer(this); }
283 static void collapseAnonymousBoxChild(RenderBlock* parent, RenderBlock* child);
285 virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject* parent) const OVERRIDE;
287 static bool shouldSkipCreatingRunsForObject(RenderObject* obj)
289 return obj->isFloating() || (obj->isOutOfFlowPositioned() && !obj->style()->isOriginalDisplayInlineType() && !obj->container()->isRenderInline());
292 static TextRun constructTextRun(RenderObject* context, const Font&, const String&, const RenderStyle&,
293 TextRun::ExpansionBehavior = TextRun::AllowTrailingExpansion | TextRun::ForbidLeadingExpansion, TextRunFlags = DefaultTextRunFlags);
295 static TextRun constructTextRun(RenderObject* context, const Font&, const RenderText*, const RenderStyle&,
296 TextRun::ExpansionBehavior = TextRun::AllowTrailingExpansion | TextRun::ForbidLeadingExpansion);
298 static TextRun constructTextRun(RenderObject* context, const Font&, const RenderText*, unsigned offset, unsigned length, const RenderStyle&,
299 TextRun::ExpansionBehavior = TextRun::AllowTrailingExpansion | TextRun::ForbidLeadingExpansion);
301 static TextRun constructTextRun(RenderObject* context, const Font&, const RenderText*, unsigned offset, const RenderStyle&,
302 TextRun::ExpansionBehavior = TextRun::AllowTrailingExpansion | TextRun::ForbidLeadingExpansion);
304 #if ENABLE(8BIT_TEXTRUN)
305 static TextRun constructTextRun(RenderObject* context, const Font&, const LChar* characters, int length, const RenderStyle&,
306 TextRun::ExpansionBehavior = TextRun::AllowTrailingExpansion | TextRun::ForbidLeadingExpansion);
309 static TextRun constructTextRun(RenderObject* context, const Font&, const UChar* characters, int length, const RenderStyle&,
310 TextRun::ExpansionBehavior = TextRun::AllowTrailingExpansion | TextRun::ForbidLeadingExpansion);
312 ColumnInfo* columnInfo() const;
313 int columnGap() const;
315 void updateColumnInfoFromStyle(RenderStyle*);
317 LayoutUnit initialBlockOffsetForPainting() const;
318 LayoutUnit blockDeltaForPaintingNextColumn() const;
320 // These two functions take the ColumnInfo* to avoid repeated lookups of the info in the global HashMap.
321 unsigned columnCount(ColumnInfo*) const;
322 LayoutRect columnRectAt(ColumnInfo*, unsigned) const;
324 LayoutUnit paginationStrut() const { return m_rareData ? m_rareData->m_paginationStrut : LayoutUnit(); }
325 void setPaginationStrut(LayoutUnit);
327 // The page logical offset is the object's offset from the top of the page in the page progression
328 // direction (so an x-offset in vertical text and a y-offset for horizontal text).
329 LayoutUnit pageLogicalOffset() const { return m_rareData ? m_rareData->m_pageLogicalOffset : LayoutUnit(); }
330 void setPageLogicalOffset(LayoutUnit);
332 // Accessors for logical width/height and margins in the containing block's block-flow direction.
333 enum ApplyLayoutDeltaMode { ApplyLayoutDelta, DoNotApplyLayoutDelta };
334 LayoutUnit logicalWidthForChild(const RenderBox* child) const { return isHorizontalWritingMode() ? child->width() : child->height(); }
335 LayoutUnit logicalHeightForChild(const RenderBox* child) const { return isHorizontalWritingMode() ? child->height() : child->width(); }
336 LayoutUnit logicalTopForChild(const RenderBox* child) const { return isHorizontalWritingMode() ? child->y() : child->x(); }
337 void setLogicalLeftForChild(RenderBox* child, LayoutUnit logicalLeft, ApplyLayoutDeltaMode = DoNotApplyLayoutDelta);
338 void setLogicalTopForChild(RenderBox* child, LayoutUnit logicalTop, ApplyLayoutDeltaMode = DoNotApplyLayoutDelta);
339 LayoutUnit marginBeforeForChild(const RenderBoxModelObject* child) const { return child->marginBefore(style()); }
340 LayoutUnit marginAfterForChild(const RenderBoxModelObject* child) const { return child->marginAfter(style()); }
341 LayoutUnit marginStartForChild(const RenderBoxModelObject* child) const { return child->marginStart(style()); }
342 LayoutUnit marginEndForChild(const RenderBoxModelObject* child) const { return child->marginEnd(style()); }
343 void setMarginStartForChild(RenderBox* child, LayoutUnit value) const { child->setMarginStart(value, style()); }
344 void setMarginEndForChild(RenderBox* child, LayoutUnit value) const { child->setMarginEnd(value, style()); }
345 void setMarginBeforeForChild(RenderBox* child, LayoutUnit value) const { child->setMarginBefore(value, style()); }
346 void setMarginAfterForChild(RenderBox* child, LayoutUnit value) const { child->setMarginAfter(value, style()); }
347 LayoutUnit collapsedMarginBeforeForChild(const RenderBox* child) const;
348 LayoutUnit collapsedMarginAfterForChild(const RenderBox* child) const;
350 void updateLogicalWidthForAlignment(const ETextAlign&, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float& availableLogicalWidth, int expansionOpportunityCount);
352 virtual void updateFirstLetter();
354 virtual void scrollbarsChanged(bool /*horizontalScrollbarChanged*/, bool /*verticalScrollbarChanged*/) { };
356 LayoutUnit logicalLeftOffsetForContent(RenderRegion*) const;
357 LayoutUnit logicalRightOffsetForContent(RenderRegion*) const;
358 LayoutUnit availableLogicalWidthForContent(RenderRegion* region) const
360 return max<LayoutUnit>(0, logicalRightOffsetForContent(region) - logicalLeftOffsetForContent(region)); }
361 LayoutUnit startOffsetForContent(RenderRegion* region) const
363 return style()->isLeftToRightDirection() ? logicalLeftOffsetForContent(region) : logicalWidth() - logicalRightOffsetForContent(region);
365 LayoutUnit endOffsetForContent(RenderRegion* region) const
367 return !style()->isLeftToRightDirection() ? logicalLeftOffsetForContent(region) : logicalWidth() - logicalRightOffsetForContent(region);
369 LayoutUnit logicalLeftOffsetForContent(LayoutUnit blockOffset) const
371 return logicalLeftOffsetForContent(regionAtBlockOffset(blockOffset));
373 LayoutUnit logicalRightOffsetForContent(LayoutUnit blockOffset) const
375 return logicalRightOffsetForContent(regionAtBlockOffset(blockOffset));
377 LayoutUnit availableLogicalWidthForContent(LayoutUnit blockOffset) const
379 return availableLogicalWidthForContent(regionAtBlockOffset(blockOffset));
381 LayoutUnit startOffsetForContent(LayoutUnit blockOffset) const
383 return startOffsetForContent(regionAtBlockOffset(blockOffset));
385 LayoutUnit endOffsetForContent(LayoutUnit blockOffset) const
387 return endOffsetForContent(regionAtBlockOffset(blockOffset));
389 LayoutUnit logicalLeftOffsetForContent() const { return isHorizontalWritingMode() ? borderLeft() + paddingLeft() : borderTop() + paddingTop(); }
390 LayoutUnit logicalRightOffsetForContent() const { return logicalLeftOffsetForContent() + availableLogicalWidth(); }
391 LayoutUnit startOffsetForContent() const { return style()->isLeftToRightDirection() ? logicalLeftOffsetForContent() : logicalWidth() - logicalRightOffsetForContent(); }
392 LayoutUnit endOffsetForContent() const { return !style()->isLeftToRightDirection() ? logicalLeftOffsetForContent() : logicalWidth() - logicalRightOffsetForContent(); }
394 void setStaticInlinePositionForChild(RenderBox*, LayoutUnit blockOffset, LayoutUnit inlinePosition);
395 void updateStaticInlinePositionForChild(RenderBox*, LayoutUnit logicalTop);
397 LayoutUnit computeStartPositionDeltaForChildAvoidingFloats(const RenderBox* child, LayoutUnit childMarginStart, RenderRegion* = 0);
399 void placeRunInIfNeeded(RenderObject* newChild);
400 bool runInIsPlacedIntoSiblingBlock(RenderObject* runIn);
403 void checkPositionedObjectsNeedLayout();
404 void showLineTreeAndMark(const InlineBox* = 0, const char* = 0, const InlineBox* = 0, const char* = 0, const RenderObject* = 0) const;
407 #if ENABLE(IOS_TEXT_AUTOSIZING)
408 int immediateLineCount();
409 void adjustComputedFontSizes(float size, float visibleWidth);
410 void resetComputedFontSize()
412 m_widthForTextAutosizing = -1;
413 m_lineCountForTextAutosizing = NOT_SET;
417 #if ENABLE(CSS_SHAPES)
418 ShapeInsideInfo* ensureShapeInsideInfo()
420 if (!m_rareData || !m_rareData->m_shapeInsideInfo)
421 setShapeInsideInfo(ShapeInsideInfo::createInfo(this));
422 return m_rareData->m_shapeInsideInfo.get();
425 ShapeInsideInfo* shapeInsideInfo() const
427 if (!m_rareData || !m_rareData->m_shapeInsideInfo)
429 return ShapeInsideInfo::isEnabledFor(this) ? m_rareData->m_shapeInsideInfo.get() : 0;
431 void setShapeInsideInfo(PassOwnPtr<ShapeInsideInfo> value)
434 m_rareData = adoptPtr(new RenderBlockRareData());
435 m_rareData->m_shapeInsideInfo = value;
437 void markShapeInsideDescendantsForLayout();
438 ShapeInsideInfo* layoutShapeInsideInfo() const;
439 bool allowsShapeInsideInfoSharing() const { return !isInline() && !isFloating(); }
440 LayoutSize logicalOffsetFromShapeAncestorContainer(const RenderBlock* container) const;
441 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) OVERRIDE;
444 virtual void updateHitTestResult(HitTestResult&, const LayoutPoint&) OVERRIDE;
447 virtual void willBeDestroyed() OVERRIDE;
449 virtual void layout() OVERRIDE;
451 void layoutPositionedObjects(bool relayoutChildren, bool fixedPositionObjectsOnly = false);
452 void markFixedPositionObjectForLayoutIfNeeded(RenderObject* child);
454 virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE;
455 virtual void paintObject(PaintInfo&, const LayoutPoint&) OVERRIDE;
456 virtual void paintChildren(PaintInfo& forSelf, const LayoutPoint&, PaintInfo& forChild, bool usePrintRect);
457 bool paintChild(RenderBox*, PaintInfo& forSelf, const LayoutPoint&, PaintInfo& forChild, bool usePrintRect);
459 LayoutUnit logicalRightOffsetForLine(LayoutUnit logicalTop, LayoutUnit fixedOffset, bool applyTextIndent, LayoutUnit* heightRemaining = 0, LayoutUnit logicalHeight = 0) const
461 return adjustLogicalRightOffsetForLine(logicalRightFloatOffsetForLine(logicalTop, fixedOffset, heightRemaining, logicalHeight, ShapeOutsideFloatShapeOffset), applyTextIndent);
463 LayoutUnit logicalLeftOffsetForLine(LayoutUnit logicalTop, LayoutUnit fixedOffset, bool applyTextIndent, LayoutUnit* heightRemaining = 0, LayoutUnit logicalHeight = 0) const
465 return adjustLogicalLeftOffsetForLine(logicalLeftFloatOffsetForLine(logicalTop, fixedOffset, heightRemaining, logicalHeight, ShapeOutsideFloatShapeOffset), applyTextIndent);
467 LayoutUnit logicalRightOffsetForLineIgnoringShapeOutside(LayoutUnit logicalTop, LayoutUnit fixedOffset, bool applyTextIndent, LayoutUnit* heightRemaining = 0, LayoutUnit logicalHeight = 0) const
469 return adjustLogicalRightOffsetForLine(logicalRightFloatOffsetForLine(logicalTop, fixedOffset, heightRemaining, logicalHeight, ShapeOutsideFloatMarginBoxOffset), applyTextIndent);
471 LayoutUnit logicalLeftOffsetForLineIgnoringShapeOutside(LayoutUnit logicalTop, LayoutUnit fixedOffset, bool applyTextIndent, LayoutUnit* heightRemaining = 0, LayoutUnit logicalHeight = 0) const
473 return adjustLogicalLeftOffsetForLine(logicalLeftFloatOffsetForLine(logicalTop, fixedOffset, heightRemaining, logicalHeight, ShapeOutsideFloatMarginBoxOffset), applyTextIndent);
476 virtual ETextAlign textAlignmentForLine(bool endsWithSoftBreak) const;
477 virtual void adjustInlineDirectionLineBounds(int /* expansionOpportunityCount */, float& /* logicalLeft */, float& /* logicalWidth */) const { }
479 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
481 virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const OVERRIDE;
482 virtual void computePreferredLogicalWidths() OVERRIDE;
483 void adjustIntrinsicLogicalWidthsForColumns(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const;
485 virtual int firstLineBoxBaseline() const OVERRIDE;
486 virtual int inlineBlockBaseline(LineDirectionMode) const OVERRIDE;
487 int lastLineBoxBaseline(LineDirectionMode) const;
489 // Delay update scrollbar until finishDelayRepaint() will be
490 // called. This function is used when a flexbox is laying out its
491 // descendant. If multiple calls are made to startDelayRepaint(),
492 // finishDelayRepaint() will do nothing until finishDelayRepaint()
493 // is called the same number of times.
494 static void startDelayUpdateScrollInfo();
495 static void finishDelayUpdateScrollInfo();
497 void updateScrollInfoAfterLayout();
499 virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle) OVERRIDE;
500 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE;
502 virtual bool hasLineIfEmpty() const;
504 bool simplifiedLayout();
505 virtual void simplifiedNormalFlowLayout();
507 void setDesiredColumnCountAndWidth(int, LayoutUnit);
510 virtual void computeOverflow(LayoutUnit oldClientAfterEdge, bool recomputeFloats = false);
511 void clearLayoutOverflow();
513 virtual void addOverflowFromChildren();
514 void addOverflowFromPositionedObjects();
515 void addOverflowFromBlockChildren();
516 void addOverflowFromInlineChildren();
517 void addVisualOverflowFromTheme();
519 virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer = 0) OVERRIDE;
521 bool updateShapesBeforeBlockLayout();
522 void updateShapesAfterBlockLayout(bool heightChanged = false);
523 void computeRegionRangeForBoxChild(const RenderBox*) const;
525 void estimateRegionRangeForBoxChild(const RenderBox*) const;
526 bool updateRegionRangeForBoxChild(const RenderBox*) const;
528 void updateBlockChildDirtyBitsBeforeLayout(bool relayoutChildren, RenderBox*);
530 virtual void checkForPaginationLogicalHeightChange(LayoutUnit& pageLogicalHeight, bool& pageLogicalHeightChanged, bool& hasSpecifiedPageLogicalHeight);
533 // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
534 virtual LayoutUnit logicalRightFloatOffsetForLine(LayoutUnit, LayoutUnit fixedOffset, LayoutUnit*, LayoutUnit, ShapeOutsideFloatOffsetMode) const { return fixedOffset; };
535 // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
536 virtual LayoutUnit logicalLeftFloatOffsetForLine(LayoutUnit, LayoutUnit fixedOffset, LayoutUnit*, LayoutUnit, ShapeOutsideFloatOffsetMode) const { return fixedOffset; }
537 LayoutUnit adjustLogicalRightOffsetForLine(LayoutUnit offsetFromFloats, bool applyTextIndent) const;
538 LayoutUnit adjustLogicalLeftOffsetForLine(LayoutUnit offsetFromFloats, bool applyTextIndent) const;
540 #if ENABLE(CSS_SHAPES)
541 void computeShapeSize();
542 void updateShapeInsideInfoAfterStyleChange(const ShapeValue*, const ShapeValue* oldShape);
543 void relayoutShapeDescendantIfMoved(RenderBlock* child, LayoutSize offset);
546 virtual const char* renderName() const OVERRIDE;
548 virtual bool isInlineBlockOrInlineTable() const OVERRIDE FINAL { return isInline() && isReplaced(); }
549 virtual bool canHaveChildren() const OVERRIDE { return true; }
551 void makeChildrenNonInline(RenderObject* insertionPoint = 0);
552 virtual void removeLeftoverAnonymousBlock(RenderBlock* child);
554 // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
555 virtual void moveAllChildrenIncludingFloatsTo(RenderBlock* toBlock, bool fullRemoveInsert) { moveAllChildrenTo(toBlock, fullRemoveInsert); }
557 void addChildToContinuation(RenderObject* newChild, RenderObject* beforeChild);
558 virtual void addChildIgnoringContinuation(RenderObject* newChild, RenderObject* beforeChild) OVERRIDE;
559 void addChildToAnonymousColumnBlocks(RenderObject* newChild, RenderObject* beforeChild);
561 void addChildIgnoringAnonymousColumnBlocks(RenderObject* newChild, RenderObject* beforeChild = 0);
563 virtual bool isSelfCollapsingBlock() const OVERRIDE FINAL;
565 void insertIntoTrackedRendererMaps(RenderBox* descendant, TrackedDescendantsMap*&, TrackedContainerMap*&);
566 static void removeFromTrackedRendererMaps(RenderBox* descendant, TrackedDescendantsMap*&, TrackedContainerMap*&);
568 virtual RootInlineBox* createRootInlineBox(); // Subclassed by SVG and Ruby.
570 // Called to lay out the legend for a fieldset or the ruby text of a ruby run.
571 virtual RenderObject* layoutSpecialExcludedChild(bool /*relayoutChildren*/) { return 0; }
573 void createFirstLetterRenderer(RenderObject* firstLetterBlock, RenderText* currentTextChild);
574 void updateFirstLetterStyle(RenderObject* firstLetterBlock, RenderObject* firstLetterContainer);
576 Node* nodeForHitTest() const;
578 struct FloatWithRect {
579 FloatWithRect(RenderBox* f)
581 , rect(LayoutRect(f->x() - f->marginLeft(), f->y() - f->marginTop(), f->width() + f->marginWidth(), f->height() + f->marginHeight()))
582 , everHadLayout(f->everHadLayout())
591 LayoutPoint flipFloatForWritingModeForChild(const FloatingObject*, const LayoutPoint&) const;
593 LayoutUnit xPositionForFloatIncludingMargin(const FloatingObject* child) const
595 if (isHorizontalWritingMode())
596 return child->x() + child->renderer().marginLeft();
598 return child->x() + marginBeforeForChild(&child->renderer());
601 LayoutUnit yPositionForFloatIncludingMargin(const FloatingObject* child) const
603 if (isHorizontalWritingMode())
604 return child->y() + marginBeforeForChild(&child->renderer());
606 return child->y() + child->renderer().marginTop();
609 // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
610 virtual void paintFloats(PaintInfo&, const LayoutPoint&, bool) { }
611 void paintContents(PaintInfo&, const LayoutPoint&);
612 void paintColumnContents(PaintInfo&, const LayoutPoint&, bool paintFloats = false);
613 void paintColumnRules(PaintInfo&, const LayoutPoint&);
614 void paintSelection(PaintInfo&, const LayoutPoint&);
615 void paintCaret(PaintInfo&, const LayoutPoint&, CaretType);
617 virtual bool avoidsFloats() const OVERRIDE;
619 bool hitTestColumns(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction);
620 virtual bool hitTestContents(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction);
621 // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
622 virtual bool hitTestFloats(const HitTestRequest&, HitTestResult&, const HitTestLocation&, const LayoutPoint&) { return false; }
624 virtual bool isPointInOverflowControl(HitTestResult&, const LayoutPoint& locationInContainer, const LayoutPoint& accumulatedOffset);
626 // FIXME: Make this method const so we can remove the const_cast in computeIntrinsicLogicalWidths.
627 void computeInlinePreferredLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth);
628 void computeBlockPreferredLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const;
630 // Obtains the nearest enclosing block (including this block) that contributes a first-line style to our inline
632 virtual RenderBlock* firstLineBlock() const OVERRIDE;
634 virtual LayoutRect rectWithOutlineForRepaint(const RenderLayerModelObject* repaintContainer, LayoutUnit outlineWidth) const OVERRIDE FINAL;
635 virtual RenderStyle* outlineStyleForRepaint() const OVERRIDE FINAL;
637 virtual RenderElement* hoverAncestor() const OVERRIDE FINAL;
638 virtual void updateDragState(bool dragOn) OVERRIDE FINAL;
639 virtual void childBecameNonInline(RenderObject* child) OVERRIDE FINAL;
641 virtual LayoutRect selectionRectForRepaint(const RenderLayerModelObject* repaintContainer, bool /*clipToVisibleContent*/) OVERRIDE FINAL
643 return selectionGapRectsForRepaint(repaintContainer);
645 virtual bool shouldPaintSelectionGaps() const OVERRIDE FINAL;
646 bool isSelectionRoot() const;
647 GapRects selectionGaps(RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
648 LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLogicalRight, const LogicalSelectionOffsetCaches&, const PaintInfo* = 0);
649 GapRects inlineSelectionGaps(RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
650 LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLogicalRight, const LogicalSelectionOffsetCaches&, const PaintInfo*);
651 GapRects blockSelectionGaps(RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
652 LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLogicalRight, const LogicalSelectionOffsetCaches&, const PaintInfo*);
653 LayoutRect blockSelectionGap(RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
654 LayoutUnit lastLogicalTop, LayoutUnit lastLogicalLeft, LayoutUnit lastLogicalRight, LayoutUnit logicalBottom, const LogicalSelectionOffsetCaches&, const PaintInfo*);
655 LayoutUnit logicalLeftSelectionOffset(RenderBlock* rootBlock, LayoutUnit position, const LogicalSelectionOffsetCaches&);
656 LayoutUnit logicalRightSelectionOffset(RenderBlock* rootBlock, LayoutUnit position, const LogicalSelectionOffsetCaches&);
658 // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
659 virtual void clipOutFloatingObjects(RenderBlock*, const PaintInfo*, const LayoutPoint&, const LayoutSize&) { };
660 friend class LogicalSelectionOffsetCaches;
662 virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const OVERRIDE;
663 virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const OVERRIDE;
665 LayoutUnit desiredColumnWidth() const;
666 unsigned desiredColumnCount() const;
668 void paintContinuationOutlines(PaintInfo&, const LayoutPoint&);
670 virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) OVERRIDE FINAL;
672 void adjustPointToColumnContents(LayoutPoint&) const;
674 void fitBorderToLinesIfNeeded(); // Shrink the box in which the border paints if border-fit is set.
675 virtual void adjustForBorderFit(LayoutUnit x, LayoutUnit& left, LayoutUnit& right) const; // Helper function for borderFitAdjust
677 void markLinesDirtyInBlockRange(LayoutUnit logicalTop, LayoutUnit logicalBottom, RootInlineBox* highest = 0);
679 Position positionForBox(InlineBox*, bool start = true) const;
680 VisiblePosition positionForPointWithInlineChildren(const LayoutPoint&);
682 virtual void calcColumnWidth();
683 void makeChildrenAnonymousColumnBlocks(RenderObject* beforeChild, RenderBlock* newBlockBox, RenderObject* newChild);
685 bool expandsToEncloseOverhangingFloats() const;
687 void splitBlocks(RenderBlock* fromBlock, RenderBlock* toBlock, RenderBlock* middleBlock,
688 RenderObject* beforeChild, RenderBoxModelObject* oldCont);
689 void splitFlow(RenderObject* beforeChild, RenderBlock* newBlockBox,
690 RenderObject* newChild, RenderBoxModelObject* oldCont);
691 RenderBlock* clone() const;
692 RenderBlock* continuationBefore(RenderObject* beforeChild);
693 RenderBlock* containingColumnsBlock(bool allowAnonymousColumnBlock = true);
694 RenderBlock* columnsBlockForSpanningElement(RenderObject* newChild);
696 RenderBoxModelObject* createReplacementRunIn(RenderBoxModelObject* runIn);
697 void moveRunInUnderSiblingBlockIfNeeded(RenderObject* runIn);
698 void moveRunInToOriginalPosition(RenderObject* runIn);
701 void dirtyForLayoutFromPercentageHeightDescendants();
703 void determineLogicalLeftPositionForChild(RenderBox* child, ApplyLayoutDeltaMode = DoNotApplyLayoutDelta);
705 // Pagination routines.
706 virtual bool relayoutForPagination(bool hasSpecifiedPageLogicalHeight, LayoutUnit pageLogicalHeight, LayoutStateMaintainer&);
708 // Returns the logicalOffset at the top of the next page. If the offset passed in is already at the top of the current page,
709 // then nextPageLogicalTop with ExcludePageBoundary will still move to the top of the next page. nextPageLogicalTop with
710 // IncludePageBoundary set will not.
712 // 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.
713 enum PageBoundaryRule { ExcludePageBoundary, IncludePageBoundary };
714 LayoutUnit nextPageLogicalTop(LayoutUnit logicalOffset, PageBoundaryRule = ExcludePageBoundary) const;
715 bool hasNextPage(LayoutUnit logicalOffset, PageBoundaryRule = ExcludePageBoundary) const;
717 virtual ColumnInfo::PaginationUnit paginationUnit() const;
720 LayoutUnit pageLogicalTopForOffset(LayoutUnit offset) const;
721 LayoutUnit pageLogicalHeightForOffset(LayoutUnit offset) const;
722 LayoutUnit pageRemainingLogicalHeightForOffset(LayoutUnit offset, PageBoundaryRule = IncludePageBoundary) const;
725 bool pushToNextPageWithMinimumLogicalHeight(LayoutUnit& adjustment, LayoutUnit logicalOffset, LayoutUnit minimumLogicalHeight) const;
727 // A page break is required at some offset due to space shortage in the current fragmentainer.
728 void setPageBreak(LayoutUnit offset, LayoutUnit spaceShortage);
730 // Update minimum page height required to avoid fragmentation where it shouldn't occur (inside
731 // unbreakable content, between orphans and widows, etc.). This will be used as a hint to the
732 // column balancer to help set a good minimum column height.
733 void updateMinimumPageHeight(LayoutUnit offset, LayoutUnit minHeight);
735 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.
737 // Adjust from painting offsets to the local coords of this renderer
738 void offsetForContents(LayoutPoint&) const;
740 // 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
741 // region/page/column that has a different available line width than the old one. Used to know when you have to dirty a
742 // line, i.e., that it can't be re-used.
743 bool lineWidthForPaginatedLineChanged(RootInlineBox*, LayoutUnit lineDelta, RenderFlowThread*) const;
745 bool logicalWidthChangedInRegions(RenderFlowThread*) const;
747 virtual bool requiresColumns(int desiredColumnCount) const;
749 virtual bool updateLogicalWidthAndColumnWidth();
751 virtual bool canCollapseAnonymousBlockChild() const { return true; }
754 virtual LayoutUnit offsetFromLogicalTopOfFirstPage() const OVERRIDE;
755 RenderRegion* regionAtBlockOffset(LayoutUnit) const;
757 // FIXME: This is temporary to allow us to move code from RenderBlock into RenderBlockFlow that accesses member variables that we haven't moved out of
759 friend class RenderBlockFlow;
760 // FIXME-BLOCKFLOW: Remove this when the line layout stuff has all moved out of RenderBlock
761 friend class LineBreaker;
764 // Allocated only when some of these fields have non-default values
765 struct RenderBlockRareData {
766 WTF_MAKE_NONCOPYABLE(RenderBlockRareData); WTF_MAKE_FAST_ALLOCATED;
768 RenderBlockRareData()
769 : m_paginationStrut(0)
770 , m_pageLogicalOffset(0)
774 LayoutUnit m_paginationStrut;
775 LayoutUnit m_pageLogicalOffset;
777 #if ENABLE(CSS_SHAPES)
778 OwnPtr<ShapeInsideInfo> m_shapeInsideInfo;
784 OwnPtr<RenderBlockRareData> m_rareData;
786 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>.
788 mutable signed m_lineHeight : 27;
789 unsigned m_hasMarginBeforeQuirk : 1; // Note these quirk values can't be put in RenderBlockRareData since they are set too frequently.
790 unsigned m_hasMarginAfterQuirk : 1;
791 unsigned m_beingDestroyed : 1;
792 unsigned m_hasMarkupTruncation : 1;
793 unsigned m_hasBorderOrPaddingLogicalWidthChanged : 1;
795 #if ENABLE(IOS_TEXT_AUTOSIZING)
796 int m_widthForTextAutosizing;
797 unsigned m_lineCountForTextAutosizing : 2;
800 // RenderRubyBase objects need to be able to split and merge, moving their children around
801 // (calling moveChildTo, moveAllChildrenTo, and makeChildrenNonInline).
802 friend class RenderRubyBase;
805 // Used to store state between styleWillChange and styleDidChange
806 static bool s_canPropagateFloatIntoSibling;
809 inline RenderBlock& toRenderBlock(RenderObject& object)
811 ASSERT_WITH_SECURITY_IMPLICATION(object.isRenderBlock());
812 return static_cast<RenderBlock&>(object);
815 inline const RenderBlock& toRenderBlock(const RenderObject& object)
817 ASSERT_WITH_SECURITY_IMPLICATION(object.isRenderBlock());
818 return static_cast<const RenderBlock&>(object);
821 inline RenderBlock* toRenderBlock(RenderObject* object)
823 ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isRenderBlock());
824 return static_cast<RenderBlock*>(object);
827 inline const RenderBlock* toRenderBlock(const RenderObject* object)
829 ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isRenderBlock());
830 return static_cast<const RenderBlock*>(object);
833 // This will catch anyone doing an unnecessary cast.
834 void toRenderBlock(const RenderBlock*);
835 void toRenderBlock(const RenderBlock&);
837 } // namespace WebCore
839 #endif // RenderBlock_h