| 1 | /* |
|---|
| 2 | * This file is part of the render object implementation for KHTML. |
|---|
| 3 | * |
|---|
| 4 | * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
|---|
| 5 | * (C) 1999 Antti Koivisto (koivisto@kde.org) |
|---|
| 6 | * (C) 2007 David Smith (catfish.man@gmail.com) |
|---|
| 7 | * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
|---|
| 8 | * |
|---|
| 9 | * This library is free software; you can redistribute it and/or |
|---|
| 10 | * modify it under the terms of the GNU Library General Public |
|---|
| 11 | * License as published by the Free Software Foundation; either |
|---|
| 12 | * version 2 of the License, or (at your option) any later version. |
|---|
| 13 | * |
|---|
| 14 | * This library is distributed in the hope that it will be useful, |
|---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 17 | * Library General Public License for more details. |
|---|
| 18 | * |
|---|
| 19 | * You should have received a copy of the GNU Library General Public License |
|---|
| 20 | * along with this library; see the file COPYING.LIB. If not, write to |
|---|
| 21 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|---|
| 22 | * Boston, MA 02110-1301, USA. |
|---|
| 23 | */ |
|---|
| 24 | |
|---|
| 25 | #ifndef RenderBlock_h |
|---|
| 26 | #define RenderBlock_h |
|---|
| 27 | |
|---|
| 28 | #include "DeprecatedPtrList.h" |
|---|
| 29 | #include "GapRects.h" |
|---|
| 30 | #include "RenderFlow.h" |
|---|
| 31 | #include "RootInlineBox.h" |
|---|
| 32 | #include <wtf/ListHashSet.h> |
|---|
| 33 | |
|---|
| 34 | namespace WebCore { |
|---|
| 35 | |
|---|
| 36 | class InlineIterator; |
|---|
| 37 | class BidiRun; |
|---|
| 38 | class Position; |
|---|
| 39 | class RootInlineBox; |
|---|
| 40 | |
|---|
| 41 | template <class Iterator, class Run> class BidiResolver; |
|---|
| 42 | typedef BidiResolver<InlineIterator, BidiRun> InlineBidiResolver; |
|---|
| 43 | |
|---|
| 44 | enum CaretType { CursorCaret, DragCaret }; |
|---|
| 45 | |
|---|
| 46 | class RenderBlock : public RenderFlow { |
|---|
| 47 | public: |
|---|
| 48 | RenderBlock(Node*); |
|---|
| 49 | virtual ~RenderBlock(); |
|---|
| 50 | |
|---|
| 51 | virtual const char* renderName() const; |
|---|
| 52 | |
|---|
| 53 | // These two functions are overridden for inline-block. |
|---|
| 54 | virtual int lineHeight(bool firstLine, bool isRootLineBox = false) const; |
|---|
| 55 | virtual int baselinePosition(bool firstLine, bool isRootLineBox = false) const; |
|---|
| 56 | |
|---|
| 57 | virtual bool isRenderBlock() const { return true; } |
|---|
| 58 | virtual bool isBlockFlow() const { return (!isInline() || isReplaced()) && !isTable(); } |
|---|
| 59 | virtual bool isInlineFlow() const { return isInline() && !isReplaced(); } |
|---|
| 60 | virtual bool isInlineBlockOrInlineTable() const { return isInline() && isReplaced(); } |
|---|
| 61 | |
|---|
| 62 | virtual bool childrenInline() const { return m_childrenInline; } |
|---|
| 63 | virtual void setChildrenInline(bool b) { m_childrenInline = b; } |
|---|
| 64 | void makeChildrenNonInline(RenderObject* insertionPoint = 0); |
|---|
| 65 | void deleteLineBoxTree(); |
|---|
| 66 | |
|---|
| 67 | // The height (and width) of a block when you include overflow spillage out of the bottom |
|---|
| 68 | // of the block (e.g., a <div style="height:25px"> that has a 100px tall image inside |
|---|
| 69 | // it would have an overflow height of borderTop() + paddingTop() + 100px. |
|---|
| 70 | virtual int overflowHeight(bool includeInterior = true) const; |
|---|
| 71 | virtual int overflowWidth(bool includeInterior = true) const; |
|---|
| 72 | virtual int overflowLeft(bool includeInterior = true) const; |
|---|
| 73 | virtual int overflowTop(bool includeInterior = true) const; |
|---|
| 74 | virtual IntRect overflowRect(bool includeInterior = true) const; |
|---|
| 75 | virtual void setOverflowHeight(int h) { m_overflowHeight = h; } |
|---|
| 76 | virtual void setOverflowWidth(int w) { m_overflowWidth = w; } |
|---|
| 77 | |
|---|
| 78 | void addVisualOverflow(const IntRect&); |
|---|
| 79 | |
|---|
| 80 | virtual bool isSelfCollapsingBlock() const; |
|---|
| 81 | virtual bool isTopMarginQuirk() const { return m_topMarginQuirk; } |
|---|
| 82 | virtual bool isBottomMarginQuirk() const { return m_bottomMarginQuirk; } |
|---|
| 83 | |
|---|
| 84 | virtual int maxTopMargin(bool positive) const { return positive ? maxTopPosMargin() : maxTopNegMargin(); } |
|---|
| 85 | virtual int maxBottomMargin(bool positive) const { return positive ? maxBottomPosMargin() : maxBottomNegMargin(); } |
|---|
| 86 | |
|---|
| 87 | int maxTopPosMargin() const { return m_maxMargin ? m_maxMargin->m_topPos : MaxMargin::topPosDefault(this); } |
|---|
| 88 | int maxTopNegMargin() const { return m_maxMargin ? m_maxMargin->m_topNeg : MaxMargin::topNegDefault(this); } |
|---|
| 89 | int maxBottomPosMargin() const { return m_maxMargin ? m_maxMargin->m_bottomPos : MaxMargin::bottomPosDefault(this); } |
|---|
| 90 | int maxBottomNegMargin() const { return m_maxMargin ? m_maxMargin->m_bottomNeg : MaxMargin::bottomNegDefault(this); } |
|---|
| 91 | void setMaxTopMargins(int pos, int neg); |
|---|
| 92 | void setMaxBottomMargins(int pos, int neg); |
|---|
| 93 | |
|---|
| 94 | void initMaxMarginValues() |
|---|
| 95 | { |
|---|
| 96 | if (m_maxMargin) { |
|---|
| 97 | m_maxMargin->m_topPos = MaxMargin::topPosDefault(this); |
|---|
| 98 | m_maxMargin->m_topNeg = MaxMargin::topNegDefault(this); |
|---|
| 99 | m_maxMargin->m_bottomPos = MaxMargin::bottomPosDefault(this); |
|---|
| 100 | m_maxMargin->m_bottomNeg = MaxMargin::bottomNegDefault(this); |
|---|
| 101 | } |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | virtual void addChildToFlow(RenderObject* newChild, RenderObject* beforeChild); |
|---|
| 105 | virtual void removeChild(RenderObject*); |
|---|
| 106 | |
|---|
| 107 | virtual void repaintOverhangingFloats(bool paintAllDescendants); |
|---|
| 108 | |
|---|
| 109 | virtual void setStyle(const RenderStyle*); |
|---|
| 110 | |
|---|
| 111 | virtual void layout(); |
|---|
| 112 | virtual void layoutBlock(bool relayoutChildren); |
|---|
| 113 | void layoutBlockChildren(bool relayoutChildren, int& maxFloatBottom); |
|---|
| 114 | void layoutInlineChildren(bool relayoutChildren, int& repaintTop, int& repaintBottom); |
|---|
| 115 | |
|---|
| 116 | void layoutPositionedObjects(bool relayoutChildren); |
|---|
| 117 | void insertPositionedObject(RenderObject*); |
|---|
| 118 | void removePositionedObject(RenderObject*); |
|---|
| 119 | virtual void removePositionedObjects(RenderBlock*); |
|---|
| 120 | |
|---|
| 121 | void addPercentHeightDescendant(RenderBox*); |
|---|
| 122 | static void removePercentHeightDescendant(RenderBox*); |
|---|
| 123 | |
|---|
| 124 | virtual void positionListMarker() { } |
|---|
| 125 | |
|---|
| 126 | virtual void borderFitAdjust(int& x, int& w) const; // Shrink the box in which the border paints if border-fit is set. |
|---|
| 127 | |
|---|
| 128 | // Called to lay out the legend for a fieldset. |
|---|
| 129 | virtual RenderObject* layoutLegend(bool relayoutChildren) { return 0; }; |
|---|
| 130 | |
|---|
| 131 | // the implementation of the following functions is in bidi.cpp |
|---|
| 132 | struct FloatWithRect { |
|---|
| 133 | FloatWithRect(RenderObject* f) |
|---|
| 134 | : object(f) |
|---|
| 135 | , rect(IntRect(f->xPos() - f->marginLeft(), f->yPos() - f->marginTop(), f->width() + f->marginLeft() + f->marginRight(), f->height() + f->marginTop() + f->marginBottom())) |
|---|
| 136 | { |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | RenderObject* object; |
|---|
| 140 | IntRect rect; |
|---|
| 141 | }; |
|---|
| 142 | |
|---|
| 143 | void bidiReorderLine(InlineBidiResolver&, const InlineIterator& end); |
|---|
| 144 | RootInlineBox* determineStartPosition(bool& fullLayout, InlineBidiResolver&, Vector<FloatWithRect>& floats, unsigned& numCleanFloats); |
|---|
| 145 | RootInlineBox* determineEndPosition(RootInlineBox* startBox, InlineIterator& cleanLineStart, |
|---|
| 146 | BidiStatus& cleanLineBidiStatus, |
|---|
| 147 | int& yPos); |
|---|
| 148 | bool matchedEndLine(const InlineBidiResolver&, const InlineIterator& endLineStart, const BidiStatus& endLineStatus, |
|---|
| 149 | RootInlineBox*& endLine, int& endYPos, int& repaintBottom, int& repaintTop); |
|---|
| 150 | bool generatesLineBoxesForInlineChild(RenderObject*); |
|---|
| 151 | void skipTrailingWhitespace(InlineIterator&); |
|---|
| 152 | int skipLeadingWhitespace(InlineBidiResolver&); |
|---|
| 153 | void fitBelowFloats(int widthToFit, int& availableWidth); |
|---|
| 154 | InlineIterator findNextLineBreak(InlineBidiResolver&, EClear* clear = 0); |
|---|
| 155 | RootInlineBox* constructLine(unsigned runCount, BidiRun* firstRun, BidiRun* lastRun, bool lastLine, RenderObject* endObject); |
|---|
| 156 | InlineFlowBox* createLineBoxes(RenderObject*); |
|---|
| 157 | void computeHorizontalPositionsForLine(RootInlineBox*, BidiRun* firstRun, BidiRun* trailingSpaceRun, bool reachedEnd); |
|---|
| 158 | void computeVerticalPositionsForLine(RootInlineBox*, BidiRun*); |
|---|
| 159 | void checkLinesForOverflow(); |
|---|
| 160 | void deleteEllipsisLineBoxes(); |
|---|
| 161 | void checkLinesForTextOverflow(); |
|---|
| 162 | // end bidi.cpp functions |
|---|
| 163 | |
|---|
| 164 | virtual void paint(PaintInfo&, int tx, int ty); |
|---|
| 165 | virtual void paintObject(PaintInfo&, int tx, int ty); |
|---|
| 166 | void paintFloats(PaintInfo&, int tx, int ty, bool preservePhase = false); |
|---|
| 167 | void paintContents(PaintInfo&, int tx, int ty); |
|---|
| 168 | void paintColumns(PaintInfo&, int tx, int ty, bool paintFloats = false); |
|---|
| 169 | void paintChildren(PaintInfo&, int tx, int ty); |
|---|
| 170 | void paintEllipsisBoxes(PaintInfo&, int tx, int ty); |
|---|
| 171 | void paintSelection(PaintInfo&, int tx, int ty); |
|---|
| 172 | void paintCaret(PaintInfo&, CaretType); |
|---|
| 173 | |
|---|
| 174 | void insertFloatingObject(RenderObject*); |
|---|
| 175 | void removeFloatingObject(RenderObject*); |
|---|
| 176 | |
|---|
| 177 | // Called from lineWidth, to position the floats added in the last line. |
|---|
| 178 | // Returns ture if and only if it has positioned any floats. |
|---|
| 179 | bool positionNewFloats(); |
|---|
| 180 | void clearFloats(); |
|---|
| 181 | int getClearDelta(RenderObject* child); |
|---|
| 182 | virtual void markAllDescendantsWithFloatsForLayout(RenderObject* floatToRemove = 0); |
|---|
| 183 | void markPositionedObjectsForLayout(); |
|---|
| 184 | |
|---|
| 185 | virtual bool containsFloats() { return m_floatingObjects && !m_floatingObjects->isEmpty(); } |
|---|
| 186 | virtual bool containsFloat(RenderObject*); |
|---|
| 187 | |
|---|
| 188 | virtual bool avoidsFloats() const; |
|---|
| 189 | |
|---|
| 190 | virtual bool hasOverhangingFloats() { return !hasColumns() && floatBottom() > m_height; } |
|---|
| 191 | void addIntrudingFloats(RenderBlock* prev, int xoffset, int yoffset); |
|---|
| 192 | int addOverhangingFloats(RenderBlock* child, int xoffset, int yoffset, bool makeChildPaintOtherFloats); |
|---|
| 193 | |
|---|
| 194 | int nextFloatBottomBelow(int) const; |
|---|
| 195 | int floatBottom() const; |
|---|
| 196 | inline int leftBottom(); |
|---|
| 197 | inline int rightBottom(); |
|---|
| 198 | IntRect floatRect() const; |
|---|
| 199 | |
|---|
| 200 | virtual int lineWidth(int) const; |
|---|
| 201 | virtual int lowestPosition(bool includeOverflowInterior = true, bool includeSelf = true) const; |
|---|
| 202 | virtual int rightmostPosition(bool includeOverflowInterior = true, bool includeSelf = true) const; |
|---|
| 203 | virtual int leftmostPosition(bool includeOverflowInterior = true, bool includeSelf = true) const; |
|---|
| 204 | |
|---|
| 205 | int rightOffset() const; |
|---|
| 206 | int rightRelOffset(int y, int fixedOffset, bool applyTextIndent = true, int* heightRemaining = 0) const; |
|---|
| 207 | int rightOffset(int y) const { return rightRelOffset(y, rightOffset(), true); } |
|---|
| 208 | |
|---|
| 209 | int leftOffset() const; |
|---|
| 210 | int leftRelOffset(int y, int fixedOffset, bool applyTextIndent = true, int* heightRemaining = 0) const; |
|---|
| 211 | int leftOffset(int y) const { return leftRelOffset(y, leftOffset(), true); } |
|---|
| 212 | |
|---|
| 213 | virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction); |
|---|
| 214 | virtual bool hitTestColumns(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction); |
|---|
| 215 | virtual bool hitTestContents(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction); |
|---|
| 216 | |
|---|
| 217 | virtual bool isPointInOverflowControl(HitTestResult&, int x, int y, int tx, int ty); |
|---|
| 218 | |
|---|
| 219 | virtual VisiblePosition positionForCoordinates(int x, int y); |
|---|
| 220 | |
|---|
| 221 | // Block flows subclass availableWidth to handle multi column layout (shrinking the width available to children when laying out.) |
|---|
| 222 | virtual int availableWidth() const; |
|---|
| 223 | |
|---|
| 224 | virtual void calcPrefWidths(); |
|---|
| 225 | void calcInlinePrefWidths(); |
|---|
| 226 | void calcBlockPrefWidths(); |
|---|
| 227 | |
|---|
| 228 | virtual int getBaselineOfFirstLineBox() const; |
|---|
| 229 | virtual int getBaselineOfLastLineBox() const; |
|---|
| 230 | |
|---|
| 231 | RootInlineBox* firstRootBox() const { return static_cast<RootInlineBox*>(firstLineBox()); } |
|---|
| 232 | RootInlineBox* lastRootBox() const { return static_cast<RootInlineBox*>(lastLineBox()); } |
|---|
| 233 | |
|---|
| 234 | // Obtains the nearest enclosing block (including this block) that contributes a first-line style to our inline |
|---|
| 235 | // children. |
|---|
| 236 | virtual RenderBlock* firstLineBlock() const; |
|---|
| 237 | virtual void updateFirstLetter(); |
|---|
| 238 | |
|---|
| 239 | bool inRootBlockContext() const; |
|---|
| 240 | |
|---|
| 241 | void setHasMarkupTruncation(bool b = true) { m_hasMarkupTruncation = b; } |
|---|
| 242 | bool hasMarkupTruncation() const { return m_hasMarkupTruncation; } |
|---|
| 243 | |
|---|
| 244 | virtual bool hasSelectedChildren() const { return m_selectionState != SelectionNone; } |
|---|
| 245 | virtual SelectionState selectionState() const { return static_cast<SelectionState>(m_selectionState); } |
|---|
| 246 | virtual void setSelectionState(SelectionState s); |
|---|
| 247 | |
|---|
| 248 | struct BlockSelectionInfo { |
|---|
| 249 | RenderBlock* m_block; |
|---|
| 250 | GapRects m_rects; |
|---|
| 251 | SelectionState m_state; |
|---|
| 252 | |
|---|
| 253 | BlockSelectionInfo() |
|---|
| 254 | : m_block(0) |
|---|
| 255 | , m_state(SelectionNone) |
|---|
| 256 | { |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | BlockSelectionInfo(RenderBlock* b) |
|---|
| 260 | : m_block(b) |
|---|
| 261 | , m_rects(b->needsLayout() ? GapRects() : b->selectionGapRects()) |
|---|
| 262 | , m_state(b->selectionState()) |
|---|
| 263 | { |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | RenderBlock* block() const { return m_block; } |
|---|
| 267 | GapRects rects() const { return m_rects; } |
|---|
| 268 | SelectionState state() const { return m_state; } |
|---|
| 269 | }; |
|---|
| 270 | |
|---|
| 271 | virtual IntRect selectionRect(bool) { return selectionGapRects(); } |
|---|
| 272 | GapRects selectionGapRects(); |
|---|
| 273 | virtual bool shouldPaintSelectionGaps() const; |
|---|
| 274 | bool isSelectionRoot() const; |
|---|
| 275 | GapRects fillSelectionGaps(RenderBlock* rootBlock, int blockX, int blockY, int tx, int ty, |
|---|
| 276 | int& lastTop, int& lastLeft, int& lastRight, const PaintInfo* = 0); |
|---|
| 277 | GapRects fillInlineSelectionGaps(RenderBlock* rootBlock, int blockX, int blockY, int tx, int ty, |
|---|
| 278 | int& lastTop, int& lastLeft, int& lastRight, const PaintInfo*); |
|---|
| 279 | GapRects fillBlockSelectionGaps(RenderBlock* rootBlock, int blockX, int blockY, int tx, int ty, |
|---|
| 280 | int& lastTop, int& lastLeft, int& lastRight, const PaintInfo*); |
|---|
| 281 | IntRect fillVerticalSelectionGap(int lastTop, int lastLeft, int lastRight, int bottomY, RenderBlock* rootBlock, |
|---|
| 282 | int blockX, int blockY, const PaintInfo*); |
|---|
| 283 | IntRect fillLeftSelectionGap(RenderObject* selObj, int xPos, int yPos, int height, RenderBlock* rootBlock, |
|---|
| 284 | int blockX, int blockY, int tx, int ty, const PaintInfo*); |
|---|
| 285 | IntRect fillRightSelectionGap(RenderObject* selObj, int xPos, int yPos, int height, RenderBlock* rootBlock, |
|---|
| 286 | int blockX, int blockY, int tx, int ty, const PaintInfo*); |
|---|
| 287 | IntRect fillHorizontalSelectionGap(RenderObject* selObj, int xPos, int yPos, int width, int height, const PaintInfo*); |
|---|
| 288 | |
|---|
| 289 | void getHorizontalSelectionGapInfo(SelectionState, bool& leftGap, bool& rightGap); |
|---|
| 290 | int leftSelectionOffset(RenderBlock* rootBlock, int y); |
|---|
| 291 | int rightSelectionOffset(RenderBlock* rootBlock, int y); |
|---|
| 292 | |
|---|
| 293 | // Helper methods for computing line counts and heights for line counts. |
|---|
| 294 | RootInlineBox* lineAtIndex(int); |
|---|
| 295 | int lineCount(); |
|---|
| 296 | int heightForLineCount(int); |
|---|
| 297 | void clearTruncation(); |
|---|
| 298 | |
|---|
| 299 | int desiredColumnWidth() const; |
|---|
| 300 | unsigned desiredColumnCount() const; |
|---|
| 301 | Vector<IntRect>* columnRects() const; |
|---|
| 302 | void setDesiredColumnCountAndWidth(int count, int width); |
|---|
| 303 | |
|---|
| 304 | void adjustRectForColumns(IntRect&) const; |
|---|
| 305 | |
|---|
| 306 | void addContinuationWithOutline(RenderFlow*); |
|---|
| 307 | void paintContinuationOutlines(PaintInfo&, int tx, int ty); |
|---|
| 308 | |
|---|
| 309 | private: |
|---|
| 310 | void adjustPointToColumnContents(IntPoint&) const; |
|---|
| 311 | void adjustForBorderFit(int x, int& left, int& right) const; // Helper function for borderFitAdjust |
|---|
| 312 | |
|---|
| 313 | void markLinesDirtyInVerticalRange(int top, int bottom); |
|---|
| 314 | |
|---|
| 315 | protected: |
|---|
| 316 | void newLine(EClear); |
|---|
| 317 | virtual bool hasLineIfEmpty() const; |
|---|
| 318 | bool layoutOnlyPositionedObjects(); |
|---|
| 319 | |
|---|
| 320 | private: |
|---|
| 321 | Position positionForBox(InlineBox*, bool start = true) const; |
|---|
| 322 | Position positionForRenderer(RenderObject*, bool start = true) const; |
|---|
| 323 | |
|---|
| 324 | int columnGap() const; |
|---|
| 325 | void calcColumnWidth(); |
|---|
| 326 | int layoutColumns(int endOfContent = -1); |
|---|
| 327 | |
|---|
| 328 | protected: |
|---|
| 329 | struct FloatingObject { |
|---|
| 330 | enum Type { |
|---|
| 331 | FloatLeft, |
|---|
| 332 | FloatRight |
|---|
| 333 | }; |
|---|
| 334 | |
|---|
| 335 | FloatingObject(Type type) |
|---|
| 336 | : m_renderer(0) |
|---|
| 337 | , m_top(0) |
|---|
| 338 | , m_bottom(0) |
|---|
| 339 | , m_left(0) |
|---|
| 340 | , m_width(0) |
|---|
| 341 | , m_type(type) |
|---|
| 342 | , m_shouldPaint(true) |
|---|
| 343 | , m_isDescendant(false) |
|---|
| 344 | { |
|---|
| 345 | } |
|---|
| 346 | |
|---|
| 347 | Type type() { return static_cast<Type>(m_type); } |
|---|
| 348 | |
|---|
| 349 | RenderObject* m_renderer; |
|---|
| 350 | int m_top; |
|---|
| 351 | int m_bottom; |
|---|
| 352 | int m_left; |
|---|
| 353 | int m_width; |
|---|
| 354 | unsigned m_type : 1; // Type (left or right aligned) |
|---|
| 355 | bool m_shouldPaint : 1; |
|---|
| 356 | bool m_isDescendant : 1; |
|---|
| 357 | }; |
|---|
| 358 | |
|---|
| 359 | // The following helper functions and structs are used by layoutBlockChildren. |
|---|
| 360 | class CompactInfo { |
|---|
| 361 | // A compact child that needs to be collapsed into the margin of the following block. |
|---|
| 362 | RenderObject* m_compact; |
|---|
| 363 | |
|---|
| 364 | // The block with the open margin that the compact child is going to place itself within. |
|---|
| 365 | RenderObject* m_block; |
|---|
| 366 | |
|---|
| 367 | public: |
|---|
| 368 | RenderObject* compact() const { return m_compact; } |
|---|
| 369 | RenderObject* block() const { return m_block; } |
|---|
| 370 | bool matches(RenderObject* child) const { return m_compact && m_block == child; } |
|---|
| 371 | |
|---|
| 372 | void clear() { set(0, 0); } |
|---|
| 373 | void set(RenderObject* c, RenderObject* b) { m_compact = c; m_block = b; } |
|---|
| 374 | |
|---|
| 375 | CompactInfo() { clear(); } |
|---|
| 376 | }; |
|---|
| 377 | |
|---|
| 378 | class MarginInfo { |
|---|
| 379 | // Collapsing flags for whether we can collapse our margins with our children's margins. |
|---|
| 380 | bool m_canCollapseWithChildren : 1; |
|---|
| 381 | bool m_canCollapseTopWithChildren : 1; |
|---|
| 382 | bool m_canCollapseBottomWithChildren : 1; |
|---|
| 383 | |
|---|
| 384 | // Whether or not we are a quirky container, i.e., do we collapse away top and bottom |
|---|
| 385 | // margins in our container. Table cells and the body are the common examples. We |
|---|
| 386 | // also have a custom style property for Safari RSS to deal with TypePad blog articles. |
|---|
| 387 | bool m_quirkContainer : 1; |
|---|
| 388 | |
|---|
| 389 | // This flag tracks whether we are still looking at child margins that can all collapse together at the beginning of a block. |
|---|
| 390 | // They may or may not collapse with the top margin of the block (|m_canCollapseTopWithChildren| tells us that), but they will |
|---|
| 391 | // always be collapsing with one another. This variable can remain set to true through multiple iterations |
|---|
| 392 | // as long as we keep encountering self-collapsing blocks. |
|---|
| 393 | bool m_atTopOfBlock : 1; |
|---|
| 394 | |
|---|
| 395 | // This flag is set when we know we're examining bottom margins and we know we're at the bottom of the block. |
|---|
| 396 | bool m_atBottomOfBlock : 1; |
|---|
| 397 | |
|---|
| 398 | // If our last normal flow child was a self-collapsing block that cleared a float, |
|---|
| 399 | // we track it in this variable. |
|---|
| 400 | bool m_selfCollapsingBlockClearedFloat : 1; |
|---|
| 401 | |
|---|
| 402 | // These variables are used to detect quirky margins that we need to collapse away (in table cells |
|---|
| 403 | // and in the body element). |
|---|
| 404 | bool m_topQuirk : 1; |
|---|
| 405 | bool m_bottomQuirk : 1; |
|---|
| 406 | bool m_determinedTopQuirk : 1; |
|---|
| 407 | |
|---|
| 408 | // These flags track the previous maximal positive and negative margins. |
|---|
| 409 | int m_posMargin; |
|---|
| 410 | int m_negMargin; |
|---|
| 411 | |
|---|
| 412 | public: |
|---|
| 413 | MarginInfo(RenderBlock* b, int top, int bottom); |
|---|
| 414 | |
|---|
| 415 | void setAtTopOfBlock(bool b) { m_atTopOfBlock = b; } |
|---|
| 416 | void setAtBottomOfBlock(bool b) { m_atBottomOfBlock = b; } |
|---|
| 417 | void clearMargin() { m_posMargin = m_negMargin = 0; } |
|---|
| 418 | void setSelfCollapsingBlockClearedFloat(bool b) { m_selfCollapsingBlockClearedFloat = b; } |
|---|
| 419 | void setTopQuirk(bool b) { m_topQuirk = b; } |
|---|
| 420 | void setBottomQuirk(bool b) { m_bottomQuirk = b; } |
|---|
| 421 | void setDeterminedTopQuirk(bool b) { m_determinedTopQuirk = b; } |
|---|
| 422 | void setPosMargin(int p) { m_posMargin = p; } |
|---|
| 423 | void setNegMargin(int n) { m_negMargin = n; } |
|---|
| 424 | void setPosMarginIfLarger(int p) { if (p > m_posMargin) m_posMargin = p; } |
|---|
| 425 | void setNegMarginIfLarger(int n) { if (n > m_negMargin) m_negMargin = n; } |
|---|
| 426 | |
|---|
| 427 | void setMargin(int p, int n) { m_posMargin = p; m_negMargin = n; } |
|---|
| 428 | |
|---|
| 429 | bool atTopOfBlock() const { return m_atTopOfBlock; } |
|---|
| 430 | bool canCollapseWithTop() const { return m_atTopOfBlock && m_canCollapseTopWithChildren; } |
|---|
| 431 | bool canCollapseWithBottom() const { return m_atBottomOfBlock && m_canCollapseBottomWithChildren; } |
|---|
| 432 | bool canCollapseTopWithChildren() const { return m_canCollapseTopWithChildren; } |
|---|
| 433 | bool canCollapseBottomWithChildren() const { return m_canCollapseBottomWithChildren; } |
|---|
| 434 | bool selfCollapsingBlockClearedFloat() const { return m_selfCollapsingBlockClearedFloat; } |
|---|
| 435 | bool quirkContainer() const { return m_quirkContainer; } |
|---|
| 436 | bool determinedTopQuirk() const { return m_determinedTopQuirk; } |
|---|
| 437 | bool topQuirk() const { return m_topQuirk; } |
|---|
| 438 | bool bottomQuirk() const { return m_bottomQuirk; } |
|---|
| 439 | int posMargin() const { return m_posMargin; } |
|---|
| 440 | int negMargin() const { return m_negMargin; } |
|---|
| 441 | int margin() const { return m_posMargin - m_negMargin; } |
|---|
| 442 | }; |
|---|
| 443 | |
|---|
| 444 | void adjustPositionedBlock(RenderObject* child, const MarginInfo&); |
|---|
| 445 | void adjustFloatingBlock(const MarginInfo&); |
|---|
| 446 | RenderObject* handleSpecialChild(RenderObject* child, const MarginInfo&, CompactInfo&, bool& handled); |
|---|
| 447 | RenderObject* handleFloatingChild(RenderObject* child, const MarginInfo&, bool& handled); |
|---|
| 448 | RenderObject* handlePositionedChild(RenderObject* child, const MarginInfo&, bool& handled); |
|---|
| 449 | RenderObject* handleCompactChild(RenderObject* child, CompactInfo&, bool& handled); |
|---|
| 450 | RenderObject* handleRunInChild(RenderObject* child, bool& handled); |
|---|
| 451 | void collapseMargins(RenderObject* child, MarginInfo&, int yPosEstimate); |
|---|
| 452 | void clearFloatsIfNeeded(RenderObject* child, MarginInfo&, int oldTopPosMargin, int oldTopNegMargin); |
|---|
| 453 | void insertCompactIfNeeded(RenderObject* child, CompactInfo&); |
|---|
| 454 | int estimateVerticalPosition(RenderObject* child, const MarginInfo&); |
|---|
| 455 | void determineHorizontalPosition(RenderObject* child); |
|---|
| 456 | void handleBottomOfBlock(int top, int bottom, MarginInfo&); |
|---|
| 457 | void setCollapsedBottomMargin(const MarginInfo&); |
|---|
| 458 | // End helper functions and structs used by layoutBlockChildren. |
|---|
| 459 | |
|---|
| 460 | private: |
|---|
| 461 | typedef ListHashSet<RenderObject*>::const_iterator Iterator; |
|---|
| 462 | DeprecatedPtrList<FloatingObject>* m_floatingObjects; |
|---|
| 463 | ListHashSet<RenderObject*>* m_positionedObjects; |
|---|
| 464 | |
|---|
| 465 | // Allocated only when some of these fields have non-default values |
|---|
| 466 | struct MaxMargin { |
|---|
| 467 | MaxMargin(const RenderBlock* o) |
|---|
| 468 | : m_topPos(topPosDefault(o)) |
|---|
| 469 | , m_topNeg(topNegDefault(o)) |
|---|
| 470 | , m_bottomPos(bottomPosDefault(o)) |
|---|
| 471 | , m_bottomNeg(bottomNegDefault(o)) |
|---|
| 472 | { |
|---|
| 473 | } |
|---|
| 474 | |
|---|
| 475 | static int topPosDefault(const RenderBlock* o) { return o->marginTop() > 0 ? o->marginTop() : 0; } |
|---|
| 476 | static int topNegDefault(const RenderBlock* o) { return o->marginTop() < 0 ? -o->marginTop() : 0; } |
|---|
| 477 | static int bottomPosDefault(const RenderBlock* o) { return o->marginBottom() > 0 ? o->marginBottom() : 0; } |
|---|
| 478 | static int bottomNegDefault(const RenderBlock* o) { return o->marginBottom() < 0 ? -o->marginBottom() : 0; } |
|---|
| 479 | |
|---|
| 480 | int m_topPos; |
|---|
| 481 | int m_topNeg; |
|---|
| 482 | int m_bottomPos; |
|---|
| 483 | int m_bottomNeg; |
|---|
| 484 | }; |
|---|
| 485 | |
|---|
| 486 | MaxMargin* m_maxMargin; |
|---|
| 487 | |
|---|
| 488 | protected: |
|---|
| 489 | // How much content overflows out of our block vertically or horizontally. |
|---|
| 490 | int m_overflowHeight; |
|---|
| 491 | int m_overflowWidth; |
|---|
| 492 | int m_overflowLeft; |
|---|
| 493 | int m_overflowTop; |
|---|
| 494 | }; |
|---|
| 495 | |
|---|
| 496 | } // namespace WebCore |
|---|
| 497 | |
|---|
| 498 | #endif // RenderBlock_h |
|---|