author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 03 May 2010 13:17:34 +0300 | |
changeset 19 | fcece45ef507 |
parent 0 | 1918ee327afb |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
|
3 |
* (C) 1999 Antti Koivisto (koivisto@kde.org) |
|
4 |
* (C) 2007 David Smith (catfish.man@gmail.com) |
|
5 |
* Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 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 "DeprecatedPtrList.h" |
|
27 |
#include "GapRects.h" |
|
28 |
#include "RenderBox.h" |
|
29 |
#include "RenderLineBoxList.h" |
|
30 |
#include "RootInlineBox.h" |
|
31 |
#include <wtf/ListHashSet.h> |
|
32 |
||
33 |
namespace WebCore { |
|
34 |
||
35 |
class InlineIterator; |
|
36 |
class RenderInline; |
|
37 |
class RootInlineBox; |
|
38 |
||
39 |
struct BidiRun; |
|
40 |
||
41 |
template <class Iterator, class Run> class BidiResolver; |
|
42 |
template <class Iterator> class MidpointState; |
|
43 |
typedef BidiResolver<InlineIterator, BidiRun> InlineBidiResolver; |
|
44 |
typedef MidpointState<InlineIterator> LineMidpointState; |
|
45 |
||
46 |
enum CaretType { CursorCaret, DragCaret }; |
|
47 |
||
48 |
class RenderBlock : public RenderBox { |
|
49 |
public: |
|
50 |
RenderBlock(Node*); |
|
51 |
virtual ~RenderBlock(); |
|
52 |
||
53 |
const RenderObjectChildList* children() const { return &m_children; } |
|
54 |
RenderObjectChildList* children() { return &m_children; } |
|
55 |
||
56 |
virtual void destroy(); |
|
57 |
||
58 |
// These two functions are overridden for inline-block. |
|
59 |
virtual int lineHeight(bool firstLine, bool isRootLineBox = false) const; |
|
60 |
virtual int baselinePosition(bool firstLine, bool isRootLineBox = false) const; |
|
61 |
||
62 |
RenderLineBoxList* lineBoxes() { return &m_lineBoxes; } |
|
63 |
const RenderLineBoxList* lineBoxes() const { return &m_lineBoxes; } |
|
64 |
||
65 |
InlineFlowBox* firstLineBox() const { return m_lineBoxes.firstLineBox(); } |
|
66 |
InlineFlowBox* lastLineBox() const { return m_lineBoxes.lastLineBox(); } |
|
67 |
||
68 |
void deleteLineBoxTree(); |
|
69 |
||
70 |
virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0); |
|
71 |
virtual void removeChild(RenderObject*); |
|
72 |
||
73 |
virtual void layoutBlock(bool relayoutChildren); |
|
74 |
||
75 |
void insertPositionedObject(RenderBox*); |
|
76 |
void removePositionedObject(RenderBox*); |
|
77 |
void removePositionedObjects(RenderBlock*); |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
78 |
ListHashSet<RenderBox*>* positionedObjects() const { return m_positionedObjects; } |
0 | 79 |
|
80 |
void addPercentHeightDescendant(RenderBox*); |
|
81 |
static void removePercentHeightDescendant(RenderBox*); |
|
82 |
HashSet<RenderBox*>* percentHeightDescendants() const; |
|
83 |
||
84 |
RootInlineBox* createAndAppendRootInlineBox(); |
|
85 |
||
86 |
bool generatesLineBoxesForInlineChild(RenderObject*, bool isLineEmpty = true, bool previousLineBrokeCleanly = true); |
|
87 |
||
88 |
void markAllDescendantsWithFloatsForLayout(RenderBox* floatToRemove = 0, bool inLayout = true); |
|
89 |
void markPositionedObjectsForLayout(); |
|
90 |
||
91 |
bool containsFloats() { return m_floatingObjects && !m_floatingObjects->isEmpty(); } |
|
92 |
bool containsFloat(RenderObject*); |
|
93 |
||
94 |
IntRect floatRect() const; |
|
95 |
||
96 |
int lineWidth(int y, bool firstLine) const; |
|
97 |
||
98 |
virtual int lowestPosition(bool includeOverflowInterior = true, bool includeSelf = true) const; |
|
99 |
virtual int rightmostPosition(bool includeOverflowInterior = true, bool includeSelf = true) const; |
|
100 |
virtual int leftmostPosition(bool includeOverflowInterior = true, bool includeSelf = true) const; |
|
101 |
||
102 |
int rightOffset(int y, bool firstLine) const { return rightRelOffset(y, rightOffset(), firstLine); } |
|
103 |
int leftOffset(int y, bool firstLine) const { return leftRelOffset(y, leftOffset(), firstLine); } |
|
104 |
||
105 |
virtual VisiblePosition positionForPoint(const IntPoint&); |
|
106 |
||
107 |
// Block flows subclass availableWidth to handle multi column layout (shrinking the width available to children when laying out.) |
|
108 |
virtual int availableWidth() const; |
|
109 |
||
110 |
RootInlineBox* firstRootBox() const { return static_cast<RootInlineBox*>(firstLineBox()); } |
|
111 |
RootInlineBox* lastRootBox() const { return static_cast<RootInlineBox*>(lastLineBox()); } |
|
112 |
||
113 |
bool containsNonZeroBidiLevel() const; |
|
114 |
||
115 |
virtual void setSelectionState(SelectionState s); |
|
116 |
||
117 |
GapRects selectionGapRectsForRepaint(RenderBoxModelObject* repaintContainer); |
|
118 |
IntRect fillLeftSelectionGap(RenderObject* selObj, int xPos, int yPos, int height, RenderBlock* rootBlock, |
|
119 |
int blockX, int blockY, int tx, int ty, const PaintInfo*); |
|
120 |
IntRect fillRightSelectionGap(RenderObject* selObj, int xPos, int yPos, int height, RenderBlock* rootBlock, |
|
121 |
int blockX, int blockY, int tx, int ty, const PaintInfo*); |
|
122 |
IntRect fillHorizontalSelectionGap(RenderObject* selObj, int xPos, int yPos, int width, int height, const PaintInfo*); |
|
123 |
||
124 |
void getHorizontalSelectionGapInfo(SelectionState, bool& leftGap, bool& rightGap); |
|
125 |
||
126 |
// Helper methods for computing line counts and heights for line counts. |
|
127 |
RootInlineBox* lineAtIndex(int); |
|
128 |
int lineCount(); |
|
129 |
int heightForLineCount(int); |
|
130 |
void clearTruncation(); |
|
131 |
||
132 |
void adjustRectForColumns(IntRect&) const; |
|
133 |
||
134 |
void addContinuationWithOutline(RenderInline*); |
|
135 |
||
136 |
RenderInline* inlineContinuation() const { return m_inlineContinuation; } |
|
137 |
void setInlineContinuation(RenderInline* c) { m_inlineContinuation = c; } |
|
138 |
||
139 |
// This function is a convenience helper for creating an anonymous block that inherits its |
|
140 |
// style from this RenderBlock. |
|
141 |
RenderBlock* createAnonymousBlock(bool isFlexibleBox = false) const; |
|
142 |
||
143 |
protected: |
|
144 |
int maxTopPosMargin() const { return m_maxMargin ? m_maxMargin->m_topPos : MaxMargin::topPosDefault(this); } |
|
145 |
int maxTopNegMargin() const { return m_maxMargin ? m_maxMargin->m_topNeg : MaxMargin::topNegDefault(this); } |
|
146 |
int maxBottomPosMargin() const { return m_maxMargin ? m_maxMargin->m_bottomPos : MaxMargin::bottomPosDefault(this); } |
|
147 |
int maxBottomNegMargin() const { return m_maxMargin ? m_maxMargin->m_bottomNeg : MaxMargin::bottomNegDefault(this); } |
|
148 |
void setMaxTopMargins(int pos, int neg); |
|
149 |
void setMaxBottomMargins(int pos, int neg); |
|
150 |
||
151 |
void initMaxMarginValues() |
|
152 |
{ |
|
153 |
if (m_maxMargin) { |
|
154 |
m_maxMargin->m_topPos = MaxMargin::topPosDefault(this); |
|
155 |
m_maxMargin->m_topNeg = MaxMargin::topNegDefault(this); |
|
156 |
m_maxMargin->m_bottomPos = MaxMargin::bottomPosDefault(this); |
|
157 |
m_maxMargin->m_bottomNeg = MaxMargin::bottomNegDefault(this); |
|
158 |
} |
|
159 |
} |
|
160 |
||
161 |
virtual void layout(); |
|
162 |
||
163 |
void layoutPositionedObjects(bool relayoutChildren); |
|
164 |
||
165 |
virtual void paint(PaintInfo&, int tx, int ty); |
|
166 |
virtual void paintObject(PaintInfo&, int tx, int ty); |
|
167 |
||
168 |
int rightRelOffset(int y, int fixedOffset, bool applyTextIndent = true, int* heightRemaining = 0) const; |
|
169 |
int leftRelOffset(int y, int fixedOffset, bool applyTextIndent = true, int* heightRemaining = 0) const; |
|
170 |
||
171 |
virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction); |
|
172 |
||
173 |
virtual void calcPrefWidths(); |
|
174 |
||
175 |
virtual int firstLineBoxBaseline() const; |
|
176 |
virtual int lastLineBoxBaseline() const; |
|
177 |
||
178 |
virtual void updateFirstLetter(); |
|
179 |
||
180 |
virtual void updateHitTestResult(HitTestResult&, const IntPoint&); |
|
181 |
||
182 |
// Delay update scrollbar until finishDelayRepaint() will be |
|
183 |
// called. This function is used when a flexbox is laying out its |
|
184 |
// descendant. If multiple calls are made to startDelayRepaint(), |
|
185 |
// finishDelayRepaint() will do nothing until finishDelayRepaint() |
|
186 |
// is called the same number of times. |
|
187 |
static void startDelayUpdateScrollInfo(); |
|
188 |
static void finishDelayUpdateScrollInfo(); |
|
189 |
||
190 |
virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle); |
|
191 |
virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle); |
|
192 |
||
193 |
virtual bool hasLineIfEmpty() const; |
|
194 |
bool layoutOnlyPositionedObjects(); |
|
195 |
||
196 |
private: |
|
197 |
virtual RenderObjectChildList* virtualChildren() { return children(); } |
|
198 |
virtual const RenderObjectChildList* virtualChildren() const { return children(); } |
|
199 |
||
200 |
virtual const char* renderName() const; |
|
201 |
||
202 |
virtual bool isRenderBlock() const { return true; } |
|
203 |
virtual bool isBlockFlow() const { return (!isInline() || isReplaced()) && !isTable(); } |
|
204 |
virtual bool isInlineBlockOrInlineTable() const { return isInline() && isReplaced(); } |
|
205 |
||
206 |
void makeChildrenNonInline(RenderObject* insertionPoint = 0); |
|
207 |
virtual void removeLeftoverAnonymousBlock(RenderBlock* child); |
|
208 |
||
209 |
virtual void dirtyLinesFromChangedChild(RenderObject* child) { m_lineBoxes.dirtyLinesFromChangedChild(this, child); } |
|
210 |
||
211 |
virtual bool isSelfCollapsingBlock() const; |
|
212 |
||
213 |
virtual int maxTopMargin(bool positive) const { return positive ? maxTopPosMargin() : maxTopNegMargin(); } |
|
214 |
virtual int maxBottomMargin(bool positive) const { return positive ? maxBottomPosMargin() : maxBottomNegMargin(); } |
|
215 |
||
216 |
virtual void repaintOverhangingFloats(bool paintAllDescendants); |
|
217 |
||
218 |
void layoutBlockChildren(bool relayoutChildren, int& maxFloatBottom); |
|
219 |
void layoutInlineChildren(bool relayoutChildren, int& repaintTop, int& repaintBottom); |
|
220 |
||
221 |
virtual void positionListMarker() { } |
|
222 |
||
223 |
virtual void borderFitAdjust(int& x, int& w) const; // Shrink the box in which the border paints if border-fit is set. |
|
224 |
||
225 |
virtual void updateBeforeAfterContent(PseudoId); |
|
226 |
||
227 |
virtual RootInlineBox* createRootInlineBox(); // Subclassed by SVG and Ruby. |
|
228 |
||
229 |
// Called to lay out the legend for a fieldset. |
|
230 |
virtual RenderObject* layoutLegend(bool /*relayoutChildren*/) { return 0; } |
|
231 |
||
232 |
struct FloatWithRect { |
|
233 |
FloatWithRect(RenderBox* f) |
|
234 |
: object(f) |
|
235 |
, rect(IntRect(f->x() - f->marginLeft(), f->y() - f->marginTop(), f->width() + f->marginLeft() + f->marginRight(), f->height() + f->marginTop() + f->marginBottom())) |
|
236 |
, everHadLayout(f->m_everHadLayout) |
|
237 |
{ |
|
238 |
} |
|
239 |
||
240 |
RenderBox* object; |
|
241 |
IntRect rect; |
|
242 |
bool everHadLayout; |
|
243 |
}; |
|
244 |
||
245 |
// The following functions' implementations are in RenderBlockLineLayout.cpp. |
|
246 |
void bidiReorderLine(InlineBidiResolver&, const InlineIterator& end, bool previousLineBrokeCleanly); |
|
247 |
RootInlineBox* determineStartPosition(bool& firstLine, bool& fullLayout, bool& previousLineBrokeCleanly, |
|
248 |
InlineBidiResolver&, Vector<FloatWithRect>& floats, unsigned& numCleanFloats); |
|
249 |
RootInlineBox* determineEndPosition(RootInlineBox* startBox, InlineIterator& cleanLineStart, |
|
250 |
BidiStatus& cleanLineBidiStatus, |
|
251 |
int& yPos); |
|
252 |
bool matchedEndLine(const InlineBidiResolver&, const InlineIterator& endLineStart, const BidiStatus& endLineStatus, |
|
253 |
RootInlineBox*& endLine, int& endYPos, int& repaintBottom, int& repaintTop); |
|
254 |
||
255 |
void skipTrailingWhitespace(InlineIterator&, bool isLineEmpty, bool previousLineBrokeCleanly); |
|
256 |
int skipLeadingWhitespace(InlineBidiResolver&, bool firstLine, bool isLineEmpty, bool previousLineBrokeCleanly); |
|
257 |
void fitBelowFloats(int widthToFit, bool firstLine, int& availableWidth); |
|
258 |
InlineIterator findNextLineBreak(InlineBidiResolver&, bool firstLine, bool& isLineEmpty, bool& previousLineBrokeCleanly, EClear* clear = 0); |
|
259 |
RootInlineBox* constructLine(unsigned runCount, BidiRun* firstRun, BidiRun* lastRun, bool firstLine, bool lastLine, RenderObject* endObject); |
|
260 |
InlineFlowBox* createLineBoxes(RenderObject*, bool firstLine); |
|
261 |
void computeHorizontalPositionsForLine(RootInlineBox*, bool firstLine, BidiRun* firstRun, BidiRun* trailingSpaceRun, bool reachedEnd); |
|
262 |
void computeVerticalPositionsForLine(RootInlineBox*, BidiRun*); |
|
263 |
void deleteEllipsisLineBoxes(); |
|
264 |
void checkLinesForTextOverflow(); |
|
265 |
void addOverflowFromInlineChildren(); |
|
266 |
// End of functions defined in RenderBlockLineLayout.cpp. |
|
267 |
||
268 |
void addOverflowFromBlockChildren(); |
|
269 |
void addOverflowFromFloats(); |
|
270 |
||
271 |
void paintFloats(PaintInfo&, int tx, int ty, bool preservePhase = false); |
|
272 |
void paintContents(PaintInfo&, int tx, int ty); |
|
273 |
void paintColumnContents(PaintInfo&, int tx, int ty, bool paintFloats = false); |
|
274 |
void paintColumnRules(PaintInfo&, int tx, int ty); |
|
275 |
void paintChildren(PaintInfo&, int tx, int ty); |
|
276 |
void paintEllipsisBoxes(PaintInfo&, int tx, int ty); |
|
277 |
void paintSelection(PaintInfo&, int tx, int ty); |
|
278 |
void paintCaret(PaintInfo&, int tx, int ty, CaretType); |
|
279 |
||
280 |
void insertFloatingObject(RenderBox*); |
|
281 |
void removeFloatingObject(RenderBox*); |
|
282 |
||
283 |
// Called from lineWidth, to position the floats added in the last line. |
|
284 |
// Returns ture if and only if it has positioned any floats. |
|
285 |
bool positionNewFloats(); |
|
286 |
void clearFloats(); |
|
287 |
int getClearDelta(RenderBox* child, int yPos); |
|
288 |
||
289 |
virtual bool avoidsFloats() const; |
|
290 |
||
291 |
bool hasOverhangingFloats() { return parent() && !hasColumns() && floatBottom() > height(); } |
|
292 |
void addIntrudingFloats(RenderBlock* prev, int xoffset, int yoffset); |
|
293 |
int addOverhangingFloats(RenderBlock* child, int xoffset, int yoffset, bool makeChildPaintOtherFloats); |
|
294 |
||
295 |
int nextFloatBottomBelow(int) const; |
|
296 |
int floatBottom() const; |
|
297 |
inline int leftBottom(); |
|
298 |
inline int rightBottom(); |
|
299 |
||
300 |
int rightOffset() const; |
|
301 |
int leftOffset() const; |
|
302 |
virtual bool hitTestColumns(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction); |
|
303 |
virtual bool hitTestContents(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction); |
|
304 |
||
305 |
virtual bool isPointInOverflowControl(HitTestResult&, int x, int y, int tx, int ty); |
|
306 |
||
307 |
void calcInlinePrefWidths(); |
|
308 |
void calcBlockPrefWidths(); |
|
309 |
||
310 |
// Obtains the nearest enclosing block (including this block) that contributes a first-line style to our inline |
|
311 |
// children. |
|
312 |
virtual RenderBlock* firstLineBlock() const; |
|
313 |
bool inRootBlockContext() const; |
|
314 |
||
315 |
virtual IntRect rectWithOutlineForRepaint(RenderBoxModelObject* repaintContainer, int outlineWidth); |
|
316 |
virtual RenderStyle* outlineStyleForRepaint() const; |
|
317 |
||
318 |
virtual RenderObject* hoverAncestor() const; |
|
319 |
virtual void updateDragState(bool dragOn); |
|
320 |
virtual void childBecameNonInline(RenderObject* child); |
|
321 |
||
322 |
virtual IntRect selectionRectForRepaint(RenderBoxModelObject* repaintContainer, bool /*clipToVisibleContent*/) |
|
323 |
{ |
|
324 |
return selectionGapRectsForRepaint(repaintContainer); |
|
325 |
} |
|
326 |
virtual bool shouldPaintSelectionGaps() const; |
|
327 |
bool isSelectionRoot() const; |
|
328 |
GapRects fillSelectionGaps(RenderBlock* rootBlock, int blockX, int blockY, int tx, int ty, |
|
329 |
int& lastTop, int& lastLeft, int& lastRight, const PaintInfo* = 0); |
|
330 |
GapRects fillInlineSelectionGaps(RenderBlock* rootBlock, int blockX, int blockY, int tx, int ty, |
|
331 |
int& lastTop, int& lastLeft, int& lastRight, const PaintInfo*); |
|
332 |
GapRects fillBlockSelectionGaps(RenderBlock* rootBlock, int blockX, int blockY, int tx, int ty, |
|
333 |
int& lastTop, int& lastLeft, int& lastRight, const PaintInfo*); |
|
334 |
IntRect fillVerticalSelectionGap(int lastTop, int lastLeft, int lastRight, int bottomY, RenderBlock* rootBlock, |
|
335 |
int blockX, int blockY, const PaintInfo*); |
|
336 |
int leftSelectionOffset(RenderBlock* rootBlock, int y); |
|
337 |
int rightSelectionOffset(RenderBlock* rootBlock, int y); |
|
338 |
||
339 |
virtual void absoluteRects(Vector<IntRect>&, int tx, int ty); |
|
340 |
virtual void absoluteQuads(Vector<FloatQuad>&); |
|
341 |
||
342 |
int desiredColumnWidth() const; |
|
343 |
unsigned desiredColumnCount() const; |
|
344 |
Vector<IntRect>* columnRects() const; |
|
345 |
void setDesiredColumnCountAndWidth(int count, int width); |
|
346 |
int columnGap() const; |
|
347 |
||
348 |
void paintContinuationOutlines(PaintInfo&, int tx, int ty); |
|
349 |
||
350 |
virtual IntRect localCaretRect(InlineBox*, int caretOffset, int* extraWidthToEndOfLine = 0); |
|
351 |
||
352 |
virtual void addFocusRingRects(GraphicsContext*, int tx, int ty); |
|
353 |
||
354 |
void adjustPointToColumnContents(IntPoint&) const; |
|
355 |
void adjustForBorderFit(int x, int& left, int& right) const; // Helper function for borderFitAdjust |
|
356 |
||
357 |
void markLinesDirtyInVerticalRange(int top, int bottom); |
|
358 |
||
359 |
void newLine(EClear); |
|
360 |
||
361 |
Position positionForBox(InlineBox*, bool start = true) const; |
|
362 |
Position positionForRenderer(RenderObject*, bool start = true) const; |
|
363 |
VisiblePosition positionForPointWithInlineChildren(const IntPoint&); |
|
364 |
||
365 |
// Adjust tx and ty from painting offsets to the local coords of this renderer |
|
366 |
void offsetForContents(int& tx, int& ty) const; |
|
367 |
||
368 |
void calcColumnWidth(); |
|
369 |
int layoutColumns(int endOfContent = -1); |
|
370 |
||
371 |
bool expandsToEncloseOverhangingFloats() const; |
|
372 |
||
373 |
void updateScrollInfoAfterLayout(); |
|
374 |
||
375 |
struct FloatingObject { |
|
376 |
enum Type { |
|
377 |
FloatLeft, |
|
378 |
FloatRight |
|
379 |
}; |
|
380 |
||
381 |
FloatingObject(Type type) |
|
382 |
: m_renderer(0) |
|
383 |
, m_top(0) |
|
384 |
, m_bottom(0) |
|
385 |
, m_left(0) |
|
386 |
, m_width(0) |
|
387 |
, m_type(type) |
|
388 |
, m_shouldPaint(true) |
|
389 |
, m_isDescendant(false) |
|
390 |
{ |
|
391 |
} |
|
392 |
||
393 |
Type type() { return static_cast<Type>(m_type); } |
|
394 |
||
395 |
RenderBox* m_renderer; |
|
396 |
int m_top; |
|
397 |
int m_bottom; |
|
398 |
int m_left; |
|
399 |
int m_width; |
|
400 |
unsigned m_type : 1; // Type (left or right aligned) |
|
401 |
bool m_shouldPaint : 1; |
|
402 |
bool m_isDescendant : 1; |
|
403 |
}; |
|
404 |
||
405 |
class MarginInfo { |
|
406 |
// Collapsing flags for whether we can collapse our margins with our children's margins. |
|
407 |
bool m_canCollapseWithChildren : 1; |
|
408 |
bool m_canCollapseTopWithChildren : 1; |
|
409 |
bool m_canCollapseBottomWithChildren : 1; |
|
410 |
||
411 |
// Whether or not we are a quirky container, i.e., do we collapse away top and bottom |
|
412 |
// margins in our container. Table cells and the body are the common examples. We |
|
413 |
// also have a custom style property for Safari RSS to deal with TypePad blog articles. |
|
414 |
bool m_quirkContainer : 1; |
|
415 |
||
416 |
// This flag tracks whether we are still looking at child margins that can all collapse together at the beginning of a block. |
|
417 |
// They may or may not collapse with the top margin of the block (|m_canCollapseTopWithChildren| tells us that), but they will |
|
418 |
// always be collapsing with one another. This variable can remain set to true through multiple iterations |
|
419 |
// as long as we keep encountering self-collapsing blocks. |
|
420 |
bool m_atTopOfBlock : 1; |
|
421 |
||
422 |
// This flag is set when we know we're examining bottom margins and we know we're at the bottom of the block. |
|
423 |
bool m_atBottomOfBlock : 1; |
|
424 |
||
425 |
// These variables are used to detect quirky margins that we need to collapse away (in table cells |
|
426 |
// and in the body element). |
|
427 |
bool m_topQuirk : 1; |
|
428 |
bool m_bottomQuirk : 1; |
|
429 |
bool m_determinedTopQuirk : 1; |
|
430 |
||
431 |
// These flags track the previous maximal positive and negative margins. |
|
432 |
int m_posMargin; |
|
433 |
int m_negMargin; |
|
434 |
||
435 |
public: |
|
436 |
MarginInfo(RenderBlock* b, int top, int bottom); |
|
437 |
||
438 |
void setAtTopOfBlock(bool b) { m_atTopOfBlock = b; } |
|
439 |
void setAtBottomOfBlock(bool b) { m_atBottomOfBlock = b; } |
|
440 |
void clearMargin() { m_posMargin = m_negMargin = 0; } |
|
441 |
void setTopQuirk(bool b) { m_topQuirk = b; } |
|
442 |
void setBottomQuirk(bool b) { m_bottomQuirk = b; } |
|
443 |
void setDeterminedTopQuirk(bool b) { m_determinedTopQuirk = b; } |
|
444 |
void setPosMargin(int p) { m_posMargin = p; } |
|
445 |
void setNegMargin(int n) { m_negMargin = n; } |
|
446 |
void setPosMarginIfLarger(int p) { if (p > m_posMargin) m_posMargin = p; } |
|
447 |
void setNegMarginIfLarger(int n) { if (n > m_negMargin) m_negMargin = n; } |
|
448 |
||
449 |
void setMargin(int p, int n) { m_posMargin = p; m_negMargin = n; } |
|
450 |
||
451 |
bool atTopOfBlock() const { return m_atTopOfBlock; } |
|
452 |
bool canCollapseWithTop() const { return m_atTopOfBlock && m_canCollapseTopWithChildren; } |
|
453 |
bool canCollapseWithBottom() const { return m_atBottomOfBlock && m_canCollapseBottomWithChildren; } |
|
454 |
bool canCollapseTopWithChildren() const { return m_canCollapseTopWithChildren; } |
|
455 |
bool canCollapseBottomWithChildren() const { return m_canCollapseBottomWithChildren; } |
|
456 |
bool quirkContainer() const { return m_quirkContainer; } |
|
457 |
bool determinedTopQuirk() const { return m_determinedTopQuirk; } |
|
458 |
bool topQuirk() const { return m_topQuirk; } |
|
459 |
bool bottomQuirk() const { return m_bottomQuirk; } |
|
460 |
int posMargin() const { return m_posMargin; } |
|
461 |
int negMargin() const { return m_negMargin; } |
|
462 |
int margin() const { return m_posMargin - m_negMargin; } |
|
463 |
}; |
|
464 |
||
465 |
void layoutBlockChild(RenderBox* child, MarginInfo&, int& previousFloatBottom, int& maxFloatBottom); |
|
466 |
void adjustPositionedBlock(RenderBox* child, const MarginInfo&); |
|
467 |
void adjustFloatingBlock(const MarginInfo&); |
|
468 |
bool handleSpecialChild(RenderBox* child, const MarginInfo&); |
|
469 |
bool handleFloatingChild(RenderBox* child, const MarginInfo&); |
|
470 |
bool handlePositionedChild(RenderBox* child, const MarginInfo&); |
|
471 |
bool handleRunInChild(RenderBox* child); |
|
472 |
int collapseMargins(RenderBox* child, MarginInfo&); |
|
473 |
int clearFloatsIfNeeded(RenderBox* child, MarginInfo&, int oldTopPosMargin, int oldTopNegMargin, int yPos); |
|
474 |
int estimateVerticalPosition(RenderBox* child, const MarginInfo&); |
|
475 |
void determineHorizontalPosition(RenderBox* child); |
|
476 |
void handleBottomOfBlock(int top, int bottom, MarginInfo&); |
|
477 |
void setCollapsedBottomMargin(const MarginInfo&); |
|
478 |
// End helper functions and structs used by layoutBlockChildren. |
|
479 |
||
480 |
typedef ListHashSet<RenderBox*>::const_iterator Iterator; |
|
481 |
DeprecatedPtrList<FloatingObject>* m_floatingObjects; |
|
482 |
ListHashSet<RenderBox*>* m_positionedObjects; |
|
483 |
||
484 |
// An inline can be split with blocks occurring in between the inline content. |
|
485 |
// When this occurs we need a pointer to our next object. We can basically be |
|
486 |
// split into a sequence of inlines and blocks. The continuation will either be |
|
487 |
// an anonymous block (that houses other blocks) or it will be an inline flow. |
|
488 |
RenderInline* m_inlineContinuation; |
|
489 |
||
490 |
// Allocated only when some of these fields have non-default values |
|
491 |
struct MaxMargin { |
|
492 |
MaxMargin(const RenderBlock* o) |
|
493 |
: m_topPos(topPosDefault(o)) |
|
494 |
, m_topNeg(topNegDefault(o)) |
|
495 |
, m_bottomPos(bottomPosDefault(o)) |
|
496 |
, m_bottomNeg(bottomNegDefault(o)) |
|
497 |
{ |
|
498 |
} |
|
499 |
||
500 |
static int topPosDefault(const RenderBlock* o) { return o->marginTop() > 0 ? o->marginTop() : 0; } |
|
501 |
static int topNegDefault(const RenderBlock* o) { return o->marginTop() < 0 ? -o->marginTop() : 0; } |
|
502 |
static int bottomPosDefault(const RenderBlock* o) { return o->marginBottom() > 0 ? o->marginBottom() : 0; } |
|
503 |
static int bottomNegDefault(const RenderBlock* o) { return o->marginBottom() < 0 ? -o->marginBottom() : 0; } |
|
504 |
||
505 |
int m_topPos; |
|
506 |
int m_topNeg; |
|
507 |
int m_bottomPos; |
|
508 |
int m_bottomNeg; |
|
509 |
}; |
|
510 |
||
511 |
MaxMargin* m_maxMargin; |
|
512 |
||
513 |
RenderObjectChildList m_children; |
|
514 |
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>. |
|
515 |
||
516 |
mutable int m_lineHeight; |
|
517 |
}; |
|
518 |
||
519 |
inline RenderBlock* toRenderBlock(RenderObject* object) |
|
520 |
{ |
|
521 |
ASSERT(!object || object->isRenderBlock()); |
|
522 |
return static_cast<RenderBlock*>(object); |
|
523 |
} |
|
524 |
||
525 |
inline const RenderBlock* toRenderBlock(const RenderObject* object) |
|
526 |
{ |
|
527 |
ASSERT(!object || object->isRenderBlock()); |
|
528 |
return static_cast<const RenderBlock*>(object); |
|
529 |
} |
|
530 |
||
531 |
// This will catch anyone doing an unnecessary cast. |
|
532 |
void toRenderBlock(const RenderBlock*); |
|
533 |
||
534 |
} // namespace WebCore |
|
535 |
||
536 |
#endif // RenderBlock_h |