1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 // vim:cindent:ts=2:et:sw=2:
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 * rendering object for CSS display:block, inline-block, and list-item
9 * boxes, also used for various anonymous boxes
12 #ifndef nsBlockFrame_h___
13 #define nsBlockFrame_h___
15 #include "nsContainerFrame.h"
16 #include "nsHTMLParts.h"
17 #include "nsLineBox.h"
18 #include "nsCSSPseudoElements.h"
19 #include "nsStyleSet.h"
20 #include "nsFloatManager.h"
22 enum LineReflowStatus
{
23 // The line was completely reflowed and fit in available width, and we should
24 // try to pull up content from the next line if possible.
26 // The line was completely reflowed and fit in available width, but we should
27 // not try to pull up content from the next line.
29 // We need to reflow the line again at its current vertical position. The
30 // new reflow should not try to pull up any frames from the next line.
31 LINE_REFLOW_REDO_NO_PULL
,
32 // We need to reflow the line again using the floats from its height
33 // this reflow, since its height made it hit floats that were not
34 // adjacent to its top.
35 LINE_REFLOW_REDO_MORE_FLOATS
,
36 // We need to reflow the line again at a lower vertical postion where there
37 // may be more horizontal space due to different float configuration.
38 LINE_REFLOW_REDO_NEXT_BAND
,
39 // The line did not fit in the available vertical space. Try pushing it to
40 // the next page or column if it's not the first line on the current page/column.
44 class nsBlockReflowState
;
45 class nsBlockInFlowLineIterator
;
47 class nsFirstLineFrame
;
51 * -- The overflow out-of-flows list contains the out-of-
52 * flow frames whose placeholders are in the overflow list.
53 * -- A given piece of content has at most one placeholder
54 * frame in a block's normal child list.
55 * -- While a block is being reflowed, and from then until
56 * its next-in-flow is reflowed it may have a
57 * PushedFloatProperty frame property that points to
58 * an nsFrameList. This list contains continuations for
59 * floats whose prev-in-flow is in the block's regular float
60 * list and first-in-flows of floats that did not fit, but
61 * whose placeholders are in the block or one of its
63 * -- In all these frame lists, if there are two frames for
64 * the same content appearing in the list, then the frames
65 * appear with the prev-in-flow before the next-in-flow.
66 * -- While reflowing a block, its overflow line list
67 * will usually be empty but in some cases will have lines
68 * (while we reflow the block at its shrink-wrap width).
69 * In this case any new overflowing content must be
70 * prepended to the overflow lines.
73 typedef nsContainerFrame nsBlockFrameSuper
;
76 * Base class for block and inline frames.
77 * The block frame has an additional child list, kAbsoluteList, which
78 * contains the absolutely positioned frames.
80 class nsBlockFrame
: public nsBlockFrameSuper
83 NS_DECL_QUERYFRAME_TARGET(nsBlockFrame
)
84 NS_DECL_FRAMEARENA_HELPERS
86 typedef nsLineList::iterator line_iterator
;
87 typedef nsLineList::const_iterator const_line_iterator
;
88 typedef nsLineList::reverse_iterator reverse_line_iterator
;
89 typedef nsLineList::const_reverse_iterator const_reverse_line_iterator
;
91 line_iterator
begin_lines() { return mLines
.begin(); }
92 line_iterator
end_lines() { return mLines
.end(); }
93 const_line_iterator
begin_lines() const { return mLines
.begin(); }
94 const_line_iterator
end_lines() const { return mLines
.end(); }
95 reverse_line_iterator
rbegin_lines() { return mLines
.rbegin(); }
96 reverse_line_iterator
rend_lines() { return mLines
.rend(); }
97 const_reverse_line_iterator
rbegin_lines() const { return mLines
.rbegin(); }
98 const_reverse_line_iterator
rend_lines() const { return mLines
.rend(); }
99 line_iterator
line(nsLineBox
* aList
) { return mLines
.begin(aList
); }
100 reverse_line_iterator
rline(nsLineBox
* aList
) { return mLines
.rbegin(aList
); }
102 friend nsBlockFrame
* NS_NewBlockFrame(nsIPresShell
* aPresShell
,
103 nsStyleContext
* aContext
,
104 nsFrameState aFlags
);
110 virtual void Init(nsIContent
* aContent
,
111 nsContainerFrame
* aParent
,
112 nsIFrame
* aPrevInFlow
) MOZ_OVERRIDE
;
113 virtual void SetInitialChildList(ChildListID aListID
,
114 nsFrameList
& aChildList
) MOZ_OVERRIDE
;
115 virtual void AppendFrames(ChildListID aListID
,
116 nsFrameList
& aFrameList
) MOZ_OVERRIDE
;
117 virtual void InsertFrames(ChildListID aListID
,
118 nsIFrame
* aPrevFrame
,
119 nsFrameList
& aFrameList
) MOZ_OVERRIDE
;
120 virtual void RemoveFrame(ChildListID aListID
,
121 nsIFrame
* aOldFrame
) MOZ_OVERRIDE
;
122 virtual const nsFrameList
& GetChildList(ChildListID aListID
) const MOZ_OVERRIDE
;
123 virtual void GetChildLists(nsTArray
<ChildList
>* aLists
) const MOZ_OVERRIDE
;
124 virtual nscoord
GetLogicalBaseline(mozilla::WritingMode aWritingMode
) const MOZ_OVERRIDE
;
125 virtual nscoord
GetCaretBaseline() const MOZ_OVERRIDE
;
126 virtual void DestroyFrom(nsIFrame
* aDestructRoot
) MOZ_OVERRIDE
;
127 virtual nsSplittableType
GetSplittableType() const MOZ_OVERRIDE
;
128 virtual bool IsFloatContainingBlock() const MOZ_OVERRIDE
;
129 virtual void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
130 const nsRect
& aDirtyRect
,
131 const nsDisplayListSet
& aLists
) MOZ_OVERRIDE
;
132 virtual nsIAtom
* GetType() const MOZ_OVERRIDE
;
133 virtual bool IsFrameOfType(uint32_t aFlags
) const MOZ_OVERRIDE
135 return nsContainerFrame::IsFrameOfType(aFlags
&
136 ~(nsIFrame::eCanContainOverflowContainers
|
137 nsIFrame::eBlockFrame
));
140 virtual void InvalidateFrame(uint32_t aDisplayItemKey
= 0) MOZ_OVERRIDE
;
141 virtual void InvalidateFrameWithRect(const nsRect
& aRect
, uint32_t aDisplayItemKey
= 0) MOZ_OVERRIDE
;
143 #ifdef DEBUG_FRAME_DUMP
144 void List(FILE* out
= stderr
, const char* aPrefix
= "", uint32_t aFlags
= 0) const MOZ_OVERRIDE
;
145 virtual nsresult
GetFrameName(nsAString
& aResult
) const MOZ_OVERRIDE
;
149 virtual nsFrameState
GetDebugStateBits() const MOZ_OVERRIDE
;
153 virtual mozilla::a11y::AccType
AccessibleType() MOZ_OVERRIDE
;
156 // line cursor methods to speed up searching for the line(s)
157 // containing a point. The basic idea is that we set the cursor
158 // property if the lines' overflowArea.VisualOverflow().ys and
159 // overflowArea.VisualOverflow().yMosts are non-decreasing
160 // (considering only non-empty overflowArea.VisualOverflow()s; empty
161 // overflowArea.VisualOverflow()s never participate in event handling
162 // or painting), and the block has sufficient number of lines. The
163 // cursor property points to a "recently used" line. If we get a
164 // series of requests that work on lines
165 // "near" the cursor, then we can find those nearby lines quickly by
166 // starting our search at the cursor.
168 // Clear out line cursor because we're disturbing the lines (i.e., Reflow)
169 void ClearLineCursor();
170 // Get the first line that might contain y-coord 'y', or nullptr if you must search
171 // all lines. If nonnull is returned then we guarantee that the lines'
172 // combinedArea.ys and combinedArea.yMosts are non-decreasing.
173 // The actual line returned might not contain 'y', but if not, it is guaranteed
174 // to be before any line which does contain 'y'.
175 nsLineBox
* GetFirstLineContaining(nscoord y
);
176 // Set the line cursor to our first line. Only call this if you
177 // guarantee that the lines' combinedArea.ys and combinedArea.yMosts
178 // are non-decreasing.
179 void SetupLineCursor();
181 virtual void ChildIsDirty(nsIFrame
* aChild
) MOZ_OVERRIDE
;
182 virtual bool IsVisibleInSelection(nsISelection
* aSelection
) MOZ_OVERRIDE
;
184 virtual bool IsEmpty() MOZ_OVERRIDE
;
185 virtual bool CachedIsEmpty() MOZ_OVERRIDE
;
186 virtual bool IsSelfEmpty() MOZ_OVERRIDE
;
188 // Given that we have a bullet, does it actually draw something, i.e.,
189 // do we have either a 'list-style-type' or 'list-style-image' that is
191 bool BulletIsEmpty() const;
194 * Return the bullet text equivalent.
196 void GetSpokenBulletText(nsAString
& aText
) const;
199 * Return true if there's a bullet.
201 bool HasBullet() const {
202 return HasOutsideBullet() || HasInsideBullet();
206 * @return true if this frame has an inside bullet frame.
208 bool HasInsideBullet() const {
209 return 0 != (mState
& NS_BLOCK_FRAME_HAS_INSIDE_BULLET
);
213 * @return true if this frame has an outside bullet frame.
215 bool HasOutsideBullet() const {
216 return 0 != (mState
& NS_BLOCK_FRAME_HAS_OUTSIDE_BULLET
);
220 * @return the bullet frame or nullptr if we don't have one.
222 nsBulletFrame
* GetBullet() const {
223 nsBulletFrame
* outside
= GetOutsideBullet();
224 return outside
? outside
: GetInsideBullet();
227 virtual void MarkIntrinsicISizesDirty() MOZ_OVERRIDE
;
229 void CheckIntrinsicCacheAgainstShrinkWrapState();
231 virtual nscoord
GetMinISize(nsRenderingContext
*aRenderingContext
) MOZ_OVERRIDE
;
232 virtual nscoord
GetPrefISize(nsRenderingContext
*aRenderingContext
) MOZ_OVERRIDE
;
234 virtual nsRect
ComputeTightBounds(gfxContext
* aContext
) const MOZ_OVERRIDE
;
236 virtual nsresult
GetPrefWidthTightBounds(nsRenderingContext
* aContext
,
238 nscoord
* aXMost
) MOZ_OVERRIDE
;
241 * Compute the final block size of this frame.
243 * @param aReflowState Data structure passed from parent during reflow.
244 * @param aReflowStatus A pointer to the reflow status for when we're finished
245 * doing reflow. this will get set appropriately if the block-size
246 * causes us to exceed the current available (page) block-size.
247 * @param aContentBSize The block-size of content, precomputed outside of this
248 * function. The final block-size that is used in aMetrics will be set
249 * to either this or the available block-size, whichever is larger, in
250 * the case where our available block-size is constrained, and we
251 * overflow that available block-size.
252 * @param aBorderPadding The margins representing the border padding for block
254 * @param aFinalSize Out parameter for final block-size.
255 * @param aConsumed The block-size already consumed by our previous-in-flows.
257 void ComputeFinalBSize(const nsHTMLReflowState
& aReflowState
,
258 nsReflowStatus
* aStatus
,
259 nscoord aContentBSize
,
260 const mozilla::LogicalMargin
& aBorderPadding
,
261 mozilla::LogicalSize
& aFinalSize
,
264 virtual void Reflow(nsPresContext
* aPresContext
,
265 nsHTMLReflowMetrics
& aDesiredSize
,
266 const nsHTMLReflowState
& aReflowState
,
267 nsReflowStatus
& aStatus
) MOZ_OVERRIDE
;
269 virtual nsresult
AttributeChanged(int32_t aNameSpaceID
,
271 int32_t aModType
) MOZ_OVERRIDE
;
274 * Move any frames on our overflow list to the end of our principal list.
275 * @return true if there were any overflow frames
277 virtual bool DrainSelfOverflowList() MOZ_OVERRIDE
;
279 virtual nsresult
StealFrame(nsIFrame
* aChild
,
280 bool aForceNormal
= false) MOZ_OVERRIDE
;
282 virtual void DeleteNextInFlowChild(nsIFrame
* aNextInFlow
,
283 bool aDeletingEmptyFrames
) MOZ_OVERRIDE
;
286 * This is a special method that allows a child class of nsBlockFrame to
287 * return a special, customized nsStyleText object to the nsLineLayout
288 * constructor. It is used when the nsBlockFrame child needs to specify its
289 * custom rendering style.
291 virtual const nsStyleText
* StyleTextForLineLayout();
294 * Determines whether the collapsed margin carried out of the last
295 * line includes the margin-top of a line with clearance (in which
296 * case we must avoid collapsing that margin with our bottom margin)
298 bool CheckForCollapsedBEndMarginFromClearanceLine();
300 static nsresult
GetCurrentLine(nsBlockReflowState
*aState
, nsLineBox
**aOutCurrentLine
);
303 * Determine if this block is a margin root at the top/bottom edges.
305 void IsMarginRoot(bool* aBStartMarginRoot
, bool* aBEndMarginRoot
);
307 static bool BlockNeedsFloatManager(nsIFrame
* aBlock
);
310 * Returns whether aFrame is a block frame that will wrap its contents
311 * around floats intruding on it from the outside. (aFrame need not
312 * be a block frame, but if it's not, the result will be false.)
314 static bool BlockCanIntersectFloats(nsIFrame
* aFrame
);
317 * Returns the width that needs to be cleared past floats for blocks
318 * that cannot intersect floats. aState must already have
319 * GetAvailableSpace called on it for the vertical position that we
320 * care about (which need not be its current mY)
322 struct ReplacedElementWidthToClear
{
323 nscoord marginLeft
, borderBoxWidth
, marginRight
;
324 nscoord
MarginBoxWidth() const
325 { return marginLeft
+ borderBoxWidth
+ marginRight
; }
327 static ReplacedElementWidthToClear
328 WidthToClearPastFloats(nsBlockReflowState
& aState
,
329 const nsRect
& aFloatAvailableSpace
,
333 * Creates a contination for aFloat and adds it to the list of overflow floats.
334 * Also updates aState.mReflowStatus to include the float's incompleteness.
335 * Must only be called while this block frame is in reflow.
336 * aFloatStatus must be the float's true, unmodified reflow status.
339 nsresult
SplitFloat(nsBlockReflowState
& aState
,
341 nsReflowStatus aFloatStatus
);
344 * Walks up the frame tree, starting with aCandidate, and returns the first
345 * block frame that it encounters.
347 static nsBlockFrame
* GetNearestAncestorBlock(nsIFrame
* aCandidate
);
355 explicit nsBlockFrame(nsStyleContext
* aContext
)
356 : nsContainerFrame(aContext
)
357 , mMinWidth(NS_INTRINSIC_WIDTH_UNKNOWN
)
358 , mPrefWidth(NS_INTRINSIC_WIDTH_UNKNOWN
)
364 virtual ~nsBlockFrame();
367 already_AddRefed
<nsStyleContext
> GetFirstLetterStyle(nsPresContext
* aPresContext
)
369 return aPresContext
->StyleSet()->
370 ProbePseudoElementStyle(mContent
->AsElement(),
371 nsCSSPseudoElements::ePseudo_firstLetter
,
376 NS_DECLARE_FRAME_PROPERTY(LineCursorProperty
, nullptr)
377 nsLineBox
* GetLineCursor() {
378 return (GetStateBits() & NS_BLOCK_HAS_LINE_CURSOR
) ?
379 static_cast<nsLineBox
*>(Properties().Get(LineCursorProperty())) : nullptr;
382 nsLineBox
* NewLineBox(nsIFrame
* aFrame
, bool aIsBlock
) {
383 return NS_NewLineBox(PresContext()->PresShell(), aFrame
, aIsBlock
);
385 nsLineBox
* NewLineBox(nsLineBox
* aFromLine
, nsIFrame
* aFrame
, int32_t aCount
) {
386 return NS_NewLineBox(PresContext()->PresShell(), aFromLine
, aFrame
, aCount
);
388 void FreeLineBox(nsLineBox
* aLine
) {
389 if (aLine
== GetLineCursor()) {
392 aLine
->Destroy(PresContext()->PresShell());
395 * Helper method for StealFrame.
397 void RemoveFrameFromLine(nsIFrame
* aChild
, nsLineList::iterator aLine
,
398 nsFrameList
& aFrameList
, nsLineList
& aLineList
);
400 void TryAllLines(nsLineList::iterator
* aIterator
,
401 nsLineList::iterator
* aStartIterator
,
402 nsLineList::iterator
* aEndIterator
,
403 bool* aInOverflowLines
,
404 FrameLines
** aOverflowLines
);
406 void SetFlags(nsFrameState aFlags
) {
407 mState
&= ~NS_BLOCK_FLAGS_MASK
;
411 /** move the frames contained by aLine by aDY
412 * if aLine is a block, its child floats are added to the state manager
414 void SlideLine(nsBlockReflowState
& aState
,
415 nsLineBox
* aLine
, nscoord aDY
);
417 void ComputeFinalSize(const nsHTMLReflowState
& aReflowState
,
418 nsBlockReflowState
& aState
,
419 nsHTMLReflowMetrics
& aMetrics
,
420 nscoord
* aBottomEdgeOfChildren
);
422 void ComputeOverflowAreas(const nsRect
& aBounds
,
423 const nsStyleDisplay
* aDisplay
,
424 nscoord aBottomEdgeOfChildren
,
425 nsOverflowAreas
& aOverflowAreas
);
428 * Add the frames in aFrameList to this block after aPrevSibling.
429 * This block thinks in terms of lines, but the frame construction code
430 * knows nothing about lines at all so we need to find the line that
431 * contains aPrevSibling and add aFrameList after aPrevSibling on that line.
432 * New lines are created as necessary to handle block data in aFrameList.
433 * This function will clear aFrameList.
435 void AddFrames(nsFrameList
& aFrameList
, nsIFrame
* aPrevSibling
);
438 * Perform Bidi resolution on this frame
440 nsresult
ResolveBidi();
443 * Test whether the frame is a form control in a visual Bidi page.
444 * This is necessary for backwards-compatibility, because most visual
445 * pages use logical order for form controls so that they will
446 * display correctly on native widgets in OSs with Bidi support
447 * @param aPresContext the pres context
448 * @return whether the frame is a BIDI form control
450 bool IsVisualFormControl(nsPresContext
* aPresContext
);
454 * Does all the real work for removing aDeletedFrame
455 * -- finds the line containing aDeletedFrame
456 * -- removes all aDeletedFrame next-in-flows (or all continuations,
457 * if REMOVE_FIXED_CONTINUATIONS is given)
458 * -- marks lines dirty as needed
459 * -- marks textruns dirty (unless FRAMES_ARE_EMPTY is given, in which
460 * case textruns do not need to be dirtied)
461 * -- destroys all removed frames
464 REMOVE_FIXED_CONTINUATIONS
= 0x02,
465 FRAMES_ARE_EMPTY
= 0x04
467 void DoRemoveFrame(nsIFrame
* aDeletedFrame
, uint32_t aFlags
);
469 void ReparentFloats(nsIFrame
* aFirstFrame
, nsBlockFrame
* aOldParent
,
470 bool aReparentSiblings
);
472 virtual bool UpdateOverflow() MOZ_OVERRIDE
;
474 /** Load all of aFrame's floats into the float manager iff aFrame is not a
475 * block formatting context. Handles all necessary float manager translations;
476 * assumes float manager is in aFrame's parent's coord system.
477 * Safe to call on non-blocks (does nothing).
479 static void RecoverFloatsFor(nsIFrame
* aFrame
,
480 nsFloatManager
& aFloatManager
);
483 * Determine if we have any pushed floats from a previous continuation.
485 * @returns true, if any of the floats at the beginning of our mFloats list
486 * have the NS_FRAME_IS_PUSHED_FLOAT bit set; false otherwise.
488 bool HasPushedFloatsFromPrevContinuation() const {
489 if (!mFloats
.IsEmpty()) {
490 // If we have pushed floats, then they should be at the beginning of our
492 if (mFloats
.FirstChild()->GetStateBits() & NS_FRAME_IS_PUSHED_FLOAT
) {
498 // Double-check the above assertion that pushed floats should be at the
499 // beginning of our floats list.
500 for (nsFrameList::Enumerator
e(mFloats
); !e
.AtEnd(); e
.Next()) {
501 nsIFrame
* f
= e
.get();
502 NS_ASSERTION(!(f
->GetStateBits() & NS_FRAME_IS_PUSHED_FLOAT
),
503 "pushed floats must be at the beginning of the float list");
511 /** grab overflow lines from this block's prevInFlow, and make them
512 * part of this block's mLines list.
513 * @return true if any lines were drained.
515 bool DrainOverflowLines();
518 * @return false iff this block does not have a float on any child list.
519 * This function is O(1).
521 bool MaybeHasFloats() const {
522 if (!mFloats
.IsEmpty()) {
525 // XXX this could be replaced with HasPushedFloats() if we enforced
526 // removing the property when the frame list becomes empty.
527 nsFrameList
* list
= GetPushedFloats();
528 if (list
&& !list
->IsEmpty()) {
531 // For the OverflowOutOfFlowsProperty I think we do enforce that, but it's
532 // a mix of out-of-flow frames, so that's why the method name has "Maybe".
533 return GetStateBits() & NS_BLOCK_HAS_OVERFLOW_OUT_OF_FLOWS
;
536 /** grab pushed floats from this block's prevInFlow, and splice
537 * them into this block's mFloats list.
539 void DrainPushedFloats(nsBlockReflowState
& aState
);
541 /** Load all our floats into the float manager (without reflowing them).
542 * Assumes float manager is in our own coordinate system.
544 void RecoverFloats(nsFloatManager
& aFloatManager
);
546 /** Reflow pushed floats
548 void ReflowPushedFloats(nsBlockReflowState
& aState
,
549 nsOverflowAreas
& aOverflowAreas
,
550 nsReflowStatus
& aStatus
);
552 /** Find any trailing BR clear from the last line of the block (or its PIFs)
554 uint8_t FindTrailingClear();
557 * Remove a float from our float list.
559 void RemoveFloat(nsIFrame
* aFloat
);
561 * Remove a float from the float cache for the line its placeholder is on.
563 void RemoveFloatFromFloatCache(nsIFrame
* aFloat
);
565 void CollectFloats(nsIFrame
* aFrame
, nsFrameList
& aList
,
566 bool aCollectFromSiblings
) {
567 if (MaybeHasFloats()) {
568 DoCollectFloats(aFrame
, aList
, aCollectFromSiblings
);
571 void DoCollectFloats(nsIFrame
* aFrame
, nsFrameList
& aList
,
572 bool aCollectFromSiblings
);
574 // Remove a float, abs, rel positioned frame from the appropriate block's list
575 static void DoRemoveOutOfFlowFrame(nsIFrame
* aFrame
);
577 /** set up the conditions necessary for an resize reflow
578 * the primary task is to mark the minimumly sufficient lines dirty.
580 void PrepareResizeReflow(nsBlockReflowState
& aState
);
582 /** reflow all lines that have been marked dirty */
583 void ReflowDirtyLines(nsBlockReflowState
& aState
);
585 /** Mark a given line dirty due to reflow being interrupted on or before it */
586 void MarkLineDirtyForInterrupt(nsLineBox
* aLine
);
588 //----------------------------------------
589 // Methods for line reflow
592 * @param aState the current reflow state
593 * @param aLine the line to reflow. can contain a single block frame
594 * or contain 1 or more inline frames.
595 * @param aKeepReflowGoing [OUT] indicates whether the caller should continue to reflow more lines
597 void ReflowLine(nsBlockReflowState
& aState
,
599 bool* aKeepReflowGoing
);
601 // Return false if it needs another reflow because of reduced space
602 // between floats that are next to it (but not next to its top), and
603 // return true otherwise.
604 bool PlaceLine(nsBlockReflowState
& aState
,
605 nsLineLayout
& aLineLayout
,
607 nsFloatManager::SavedState
* aFloatStateBeforeLine
,
608 nsRect
& aFloatAvailableSpace
, /* in-out */
609 nscoord
& aAvailableSpaceHeight
, /* in-out */
610 bool* aKeepReflowGoing
);
613 * If NS_BLOCK_LOOK_FOR_DIRTY_FRAMES is set, call MarkLineDirty
614 * on any line with a child frame that is dirty.
616 void LazyMarkLinesDirty();
619 * Mark |aLine| dirty, and, if necessary because of possible
620 * pull-up, mark the previous line dirty as well. Also invalidates textruns
621 * on those lines because the text in the lines might have changed due to
622 * addition/removal of frames.
623 * @param aLine the line to mark dirty
624 * @param aLineList the line list containing that line
626 void MarkLineDirty(line_iterator aLine
, const nsLineList
* aLineList
);
629 bool IsLastLine(nsBlockReflowState
& aState
,
630 line_iterator aLine
);
632 void DeleteLine(nsBlockReflowState
& aState
,
633 nsLineList::iterator aLine
,
634 nsLineList::iterator aLineEnd
);
636 //----------------------------------------
637 // Methods for individual frame reflow
639 bool ShouldApplyBStartMargin(nsBlockReflowState
& aState
,
641 nsIFrame
* aChildFrame
);
643 void ReflowBlockFrame(nsBlockReflowState
& aState
,
647 void ReflowInlineFrames(nsBlockReflowState
& aState
,
649 bool* aKeepLineGoing
);
651 void DoReflowInlineFrames(nsBlockReflowState
& aState
,
652 nsLineLayout
& aLineLayout
,
654 nsFlowAreaRect
& aFloatAvailableSpace
,
655 nscoord
& aAvailableSpaceHeight
,
656 nsFloatManager::SavedState
*
657 aFloatStateBeforeLine
,
658 bool* aKeepReflowGoing
,
659 LineReflowStatus
* aLineReflowStatus
,
662 void ReflowInlineFrame(nsBlockReflowState
& aState
,
663 nsLineLayout
& aLineLayout
,
666 LineReflowStatus
* aLineReflowStatus
);
668 // Compute the available width for a float.
669 nsRect
AdjustFloatAvailableSpace(nsBlockReflowState
& aState
,
670 const nsRect
& aFloatAvailableSpace
,
671 nsIFrame
* aFloatFrame
);
672 // Computes the border-box width of the float
673 nscoord
ComputeFloatWidth(nsBlockReflowState
& aState
,
674 const nsRect
& aFloatAvailableSpace
,
676 // An incomplete aReflowStatus indicates the float should be split
677 // but only if the available height is constrained.
678 // aAdjustedAvailableSpace is the result of calling
679 // nsBlockFrame::AdjustFloatAvailableSpace.
680 void ReflowFloat(nsBlockReflowState
& aState
,
681 const nsRect
& aAdjustedAvailableSpace
,
683 nsMargin
& aFloatMargin
,
684 nsMargin
& aFloatOffsets
,
685 // Whether the float's position
686 // (aAdjustedAvailableSpace) has been pushed down
687 // due to the presence of other floats.
688 bool aFloatPushedDown
,
689 nsReflowStatus
& aReflowStatus
);
691 //----------------------------------------
692 // Methods for pushing/pulling lines/frames
695 * Create a next-in-flow, if necessary, for aFrame. If a new frame is
696 * created, place it in aLine if aLine is not null.
697 * @param aState the block reflow state
698 * @param aLine where to put a new frame
699 * @param aFrame the frame
700 * @return true if a new frame was created, false if not
702 bool CreateContinuationFor(nsBlockReflowState
& aState
,
707 * Push aLine (and any after it), since it cannot be placed on this
708 * page/column. Set aKeepReflowGoing to false and set
709 * flag aState.mReflowStatus as incomplete.
711 void PushTruncatedLine(nsBlockReflowState
& aState
,
713 bool* aKeepReflowGoing
);
715 void SplitLine(nsBlockReflowState
& aState
,
716 nsLineLayout
& aLineLayout
,
719 LineReflowStatus
* aLineReflowStatus
);
722 * Pull a frame from the next available location (one of our lines or
723 * one of our next-in-flows lines).
724 * @return the pulled frame or nullptr
726 nsIFrame
* PullFrame(nsBlockReflowState
& aState
,
727 line_iterator aLine
);
730 * Try to pull a frame out of a line pointed at by aFromLine.
732 * Note: pulling a frame from a line that is a place-holder frame
733 * doesn't automatically remove the corresponding float from the
734 * line's float array. This happens indirectly: either the line gets
735 * emptied (and destroyed) or the line gets reflowed (because we mark
736 * it dirty) and the code at the top of ReflowLine empties the
737 * array. So eventually, it will be removed, just not right away.
739 * @return the pulled frame or nullptr
741 nsIFrame
* PullFrameFrom(nsLineBox
* aLine
,
742 nsBlockFrame
* aFromContainer
,
743 nsLineList::iterator aFromLine
);
746 * Push the line after aLineBefore to the overflow line list.
747 * @param aLineBefore a line in 'mLines' (or begin_lines() when
748 * pushing the first line)
750 void PushLines(nsBlockReflowState
& aState
,
751 nsLineList::iterator aLineBefore
);
753 void PropagateFloatDamage(nsBlockReflowState
& aState
,
757 void CheckFloats(nsBlockReflowState
& aState
);
759 //----------------------------------------
760 // List handling kludge
762 // If this returns true, the block it's called on should get the
763 // NS_FRAME_HAS_DIRTY_CHILDREN bit set on it by the caller; either directly
764 // if it's already in reflow, or via calling FrameNeedsReflow() to schedule a
766 bool RenumberLists(nsPresContext
* aPresContext
);
768 static bool RenumberListsInBlock(nsPresContext
* aPresContext
,
769 nsBlockFrame
* aBlockFrame
,
774 static bool RenumberListsFor(nsPresContext
* aPresContext
, nsIFrame
* aKid
,
775 int32_t* aOrdinal
, int32_t aDepth
,
778 static bool FrameStartsCounterScope(nsIFrame
* aFrame
);
780 void ReflowBullet(nsIFrame
* aBulletFrame
,
781 nsBlockReflowState
& aState
,
782 nsHTMLReflowMetrics
& aMetrics
,
785 //----------------------------------------
787 virtual nsILineIterator
* GetLineIterator() MOZ_OVERRIDE
;
790 bool HasOverflowLines() const {
791 return 0 != (GetStateBits() & NS_BLOCK_HAS_OVERFLOW_LINES
);
793 FrameLines
* GetOverflowLines() const;
795 FrameLines
* RemoveOverflowLines();
796 void SetOverflowLines(FrameLines
* aOverflowLines
);
797 void DestroyOverflowLines();
800 * This class is useful for efficiently modifying the out of flow
801 * overflow list. It gives the client direct writable access to
802 * the frame list temporarily but ensures that property is only
803 * written back if absolutely necessary.
805 struct nsAutoOOFFrameList
{
808 explicit nsAutoOOFFrameList(nsBlockFrame
* aBlock
)
809 : mPropValue(aBlock
->GetOverflowOutOfFlows())
815 ~nsAutoOOFFrameList() {
816 mBlock
->SetOverflowOutOfFlows(mList
, mPropValue
);
819 nsFrameList
* const mPropValue
;
820 nsBlockFrame
* const mBlock
;
822 friend struct nsAutoOOFFrameList
;
824 nsFrameList
* GetOverflowOutOfFlows() const;
825 void SetOverflowOutOfFlows(const nsFrameList
& aList
, nsFrameList
* aPropValue
);
828 * @return the inside bullet frame or nullptr if we don't have one.
830 nsBulletFrame
* GetInsideBullet() const;
833 * @return the outside bullet frame or nullptr if we don't have one.
835 nsBulletFrame
* GetOutsideBullet() const;
838 * @return the outside bullet frame list frame property.
840 nsFrameList
* GetOutsideBulletList() const;
843 * @return true if this frame has pushed floats.
845 bool HasPushedFloats() const {
846 return 0 != (GetStateBits() & NS_BLOCK_HAS_PUSHED_FLOATS
);
849 // Get the pushed floats list, which is used for *temporary* storage
850 // of floats during reflow, between when we decide they don't fit in
851 // this block until our next continuation takes them.
852 nsFrameList
* GetPushedFloats() const;
853 // Get the pushed floats list, or if there is not currently one,
854 // make a new empty one.
855 nsFrameList
* EnsurePushedFloats();
856 // Remove and return the pushed floats list.
857 nsFrameList
* RemovePushedFloats();
860 void VerifyLines(bool aFinalCheckOK
);
861 void VerifyOverflowSituation();
862 int32_t GetDepth() const;
865 nscoord mMinWidth
, mPrefWidth
;
869 // List of all floats in this block
870 // XXXmats blocks rarely have floats, make it a frame property
873 friend class nsBlockReflowState
;
874 friend class nsBlockInFlowLineIterator
;
878 static bool gLamePaintMetrics
;
879 static bool gLameReflowMetrics
;
881 static bool gNoisyDamageRepair
;
882 static bool gNoisyIntrinsic
;
883 static bool gNoisyReflow
;
884 static bool gReallyNoisyReflow
;
885 static bool gNoisyFloatManager
;
886 static bool gVerifyLines
;
887 static bool gDisableResizeOpt
;
889 static int32_t gNoiseIndent
;
891 static const char* kReflowCommandType
[];
894 static void InitDebugFlags();
899 class AutoNoisyIndenter
{
901 explicit AutoNoisyIndenter(bool aDoIndent
) : mIndented(aDoIndent
) {
903 nsBlockFrame::gNoiseIndent
++;
906 ~AutoNoisyIndenter() {
908 nsBlockFrame::gNoiseIndent
--;
917 * Iterates over all lines in the prev-in-flows/next-in-flows of this block.
919 class nsBlockInFlowLineIterator
{
921 typedef nsBlockFrame::line_iterator line_iterator
;
923 * Set up the iterator to point to aLine which must be a normal line
924 * in aFrame (not an overflow line).
926 nsBlockInFlowLineIterator(nsBlockFrame
* aFrame
, line_iterator aLine
);
928 * Set up the iterator to point to the first line found starting from
929 * aFrame. Sets aFoundValidLine to false if there is no such line.
930 * After aFoundValidLine has returned false, don't call any methods on this
933 nsBlockInFlowLineIterator(nsBlockFrame
* aFrame
, bool* aFoundValidLine
);
935 * Set up the iterator to point to the line that contains aFindFrame (either
936 * directly or indirectly). If aFrame is out of flow, or contained in an
937 * out-of-flow, finds the line containing the out-of-flow's placeholder. If
938 * the frame is not found, sets aFoundValidLine to false. After
939 * aFoundValidLine has returned false, don't call any methods on this
942 nsBlockInFlowLineIterator(nsBlockFrame
* aFrame
, nsIFrame
* aFindFrame
,
943 bool* aFoundValidLine
);
945 line_iterator
GetLine() { return mLine
; }
946 bool IsLastLineInList();
947 nsBlockFrame
* GetContainer() { return mFrame
; }
948 bool GetInOverflow() { return mLineList
!= &mFrame
->mLines
; }
951 * Returns the current line list we're iterating, null means
952 * we're iterating |mLines| of the container.
954 nsLineList
* GetLineList() { return mLineList
; }
957 * Returns the end-iterator of whatever line list we're in.
962 * Returns false if there are no more lines. After this has returned false,
963 * don't call any methods on this object again.
967 * Returns false if there are no more lines. After this has returned false,
968 * don't call any methods on this object again.
973 friend class nsBlockFrame
;
974 // XXX nsBlockFrame uses this internally in one place. Try to remove it.
975 nsBlockInFlowLineIterator(nsBlockFrame
* aFrame
, line_iterator aLine
, bool aInOverflow
);
977 nsBlockFrame
* mFrame
;
979 nsLineList
* mLineList
; // the line list mLine is in
982 * Moves iterator to next valid line reachable from the current block.
983 * Returns false if there are no valid lines.
985 bool FindValidLine();
988 #endif /* nsBlockFrame_h___ */