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