Bumping manifests a=b2g-bump
[gecko.git] / layout / generic / nsBlockFrame.h
blobaca985e99918a36d4bd254d1191b7588504b85f2
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/. */
7 /*
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.
25 LINE_REFLOW_OK,
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.
28 LINE_REFLOW_STOP,
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.
41 LINE_REFLOW_TRUNCATED
44 class nsBlockReflowState;
45 class nsBlockInFlowLineIterator;
46 class nsBulletFrame;
47 class nsFirstLineFrame;
49 /**
50 * Some invariants:
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
62 * prev-in-flows.
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.
79 */
80 class nsBlockFrame : public nsBlockFrameSuper
82 public:
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);
106 // nsQueryFrame
107 NS_DECL_QUERYFRAME
109 // nsIFrame
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;
146 #endif
148 #ifdef DEBUG
149 virtual nsFrameState GetDebugStateBits() const MOZ_OVERRIDE;
150 #endif
152 #ifdef ACCESSIBILITY
153 virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE;
154 #endif
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
190 // not 'none'?
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;
228 private:
229 void CheckIntrinsicCacheAgainstShrinkWrapState();
230 public:
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,
237 nscoord* aX,
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
253 * frames. Can be 0.
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,
262 nscoord aConsumed);
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,
270 nsIAtom* aAttribute,
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,
330 nsIFrame* aFrame);
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,
340 nsIFrame* aFloat,
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);
349 struct FrameLines {
350 nsLineList mLines;
351 nsFrameList mFrames;
354 protected:
355 explicit nsBlockFrame(nsStyleContext* aContext)
356 : nsContainerFrame(aContext)
357 , mMinWidth(NS_INTRINSIC_WIDTH_UNKNOWN)
358 , mPrefWidth(NS_INTRINSIC_WIDTH_UNKNOWN)
360 #ifdef DEBUG
361 InitDebugFlags();
362 #endif
364 virtual ~nsBlockFrame();
366 #ifdef DEBUG
367 already_AddRefed<nsStyleContext> GetFirstLetterStyle(nsPresContext* aPresContext)
369 return aPresContext->StyleSet()->
370 ProbePseudoElementStyle(mContent->AsElement(),
371 nsCSSPseudoElements::ePseudo_firstLetter,
372 mStyleContext);
374 #endif
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()) {
390 ClearLineCursor();
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;
408 mState |= aFlags;
411 /** move the frames contained by aLine by aDeltaBCoord
412 * if aLine is a block, its child floats are added to the state manager
414 void SlideLine(nsBlockReflowState& aState,
415 nsLineBox* aLine, nscoord aDeltaBCoord);
417 void UpdateLineContainerWidth(nsLineBox* aLine,
418 nscoord aNewContainerWidth);
420 // helper for SlideLine and UpdateLineContainerWidth
421 void MoveChildFramesOfLine(nsLineBox* aLine, nscoord aDeltaBCoord);
423 void ComputeFinalSize(const nsHTMLReflowState& aReflowState,
424 nsBlockReflowState& aState,
425 nsHTMLReflowMetrics& aMetrics,
426 nscoord* aBottomEdgeOfChildren);
428 void ComputeOverflowAreas(const nsRect& aBounds,
429 const nsStyleDisplay* aDisplay,
430 nscoord aBottomEdgeOfChildren,
431 nsOverflowAreas& aOverflowAreas);
434 * Add the frames in aFrameList to this block after aPrevSibling.
435 * This block thinks in terms of lines, but the frame construction code
436 * knows nothing about lines at all so we need to find the line that
437 * contains aPrevSibling and add aFrameList after aPrevSibling on that line.
438 * New lines are created as necessary to handle block data in aFrameList.
439 * This function will clear aFrameList.
441 void AddFrames(nsFrameList& aFrameList, nsIFrame* aPrevSibling);
444 * Perform Bidi resolution on this frame
446 nsresult ResolveBidi();
449 * Test whether the frame is a form control in a visual Bidi page.
450 * This is necessary for backwards-compatibility, because most visual
451 * pages use logical order for form controls so that they will
452 * display correctly on native widgets in OSs with Bidi support
453 * @param aPresContext the pres context
454 * @return whether the frame is a BIDI form control
456 bool IsVisualFormControl(nsPresContext* aPresContext);
458 public:
460 * Does all the real work for removing aDeletedFrame
461 * -- finds the line containing aDeletedFrame
462 * -- removes all aDeletedFrame next-in-flows (or all continuations,
463 * if REMOVE_FIXED_CONTINUATIONS is given)
464 * -- marks lines dirty as needed
465 * -- marks textruns dirty (unless FRAMES_ARE_EMPTY is given, in which
466 * case textruns do not need to be dirtied)
467 * -- destroys all removed frames
469 enum {
470 REMOVE_FIXED_CONTINUATIONS = 0x02,
471 FRAMES_ARE_EMPTY = 0x04
473 void DoRemoveFrame(nsIFrame* aDeletedFrame, uint32_t aFlags);
475 void ReparentFloats(nsIFrame* aFirstFrame, nsBlockFrame* aOldParent,
476 bool aReparentSiblings);
478 virtual bool UpdateOverflow() MOZ_OVERRIDE;
480 /** Load all of aFrame's floats into the float manager iff aFrame is not a
481 * block formatting context. Handles all necessary float manager translations;
482 * assumes float manager is in aFrame's parent's coord system.
483 * Safe to call on non-blocks (does nothing).
485 static void RecoverFloatsFor(nsIFrame* aFrame,
486 nsFloatManager& aFloatManager);
489 * Determine if we have any pushed floats from a previous continuation.
491 * @returns true, if any of the floats at the beginning of our mFloats list
492 * have the NS_FRAME_IS_PUSHED_FLOAT bit set; false otherwise.
494 bool HasPushedFloatsFromPrevContinuation() const {
495 if (!mFloats.IsEmpty()) {
496 // If we have pushed floats, then they should be at the beginning of our
497 // float list.
498 if (mFloats.FirstChild()->GetStateBits() & NS_FRAME_IS_PUSHED_FLOAT) {
499 return true;
503 #ifdef DEBUG
504 // Double-check the above assertion that pushed floats should be at the
505 // beginning of our floats list.
506 for (nsFrameList::Enumerator e(mFloats); !e.AtEnd(); e.Next()) {
507 nsIFrame* f = e.get();
508 NS_ASSERTION(!(f->GetStateBits() & NS_FRAME_IS_PUSHED_FLOAT),
509 "pushed floats must be at the beginning of the float list");
511 #endif
512 return false;
515 protected:
517 /** grab overflow lines from this block's prevInFlow, and make them
518 * part of this block's mLines list.
519 * @return true if any lines were drained.
521 bool DrainOverflowLines();
524 * @return false iff this block does not have a float on any child list.
525 * This function is O(1).
527 bool MaybeHasFloats() const {
528 if (!mFloats.IsEmpty()) {
529 return true;
531 // XXX this could be replaced with HasPushedFloats() if we enforced
532 // removing the property when the frame list becomes empty.
533 nsFrameList* list = GetPushedFloats();
534 if (list && !list->IsEmpty()) {
535 return true;
537 // For the OverflowOutOfFlowsProperty I think we do enforce that, but it's
538 // a mix of out-of-flow frames, so that's why the method name has "Maybe".
539 return GetStateBits() & NS_BLOCK_HAS_OVERFLOW_OUT_OF_FLOWS;
543 * Moves frames from our PushedFloats list back into our mFloats list.
545 void DrainSelfPushedFloats();
548 * First calls DrainSelfPushedFloats() then grabs pushed floats from this
549 * block's prev-in-flow, and splice them into this block's mFloats list too.
551 void DrainPushedFloats();
553 /** Load all our floats into the float manager (without reflowing them).
554 * Assumes float manager is in our own coordinate system.
556 void RecoverFloats(nsFloatManager& aFloatManager);
558 /** Reflow pushed floats
560 void ReflowPushedFloats(nsBlockReflowState& aState,
561 nsOverflowAreas& aOverflowAreas,
562 nsReflowStatus& aStatus);
564 /** Find any trailing BR clear from the last line of the block (or its PIFs)
566 uint8_t FindTrailingClear();
569 * Remove a float from our float list.
571 void RemoveFloat(nsIFrame* aFloat);
573 * Remove a float from the float cache for the line its placeholder is on.
575 void RemoveFloatFromFloatCache(nsIFrame* aFloat);
577 void CollectFloats(nsIFrame* aFrame, nsFrameList& aList,
578 bool aCollectFromSiblings) {
579 if (MaybeHasFloats()) {
580 DoCollectFloats(aFrame, aList, aCollectFromSiblings);
583 void DoCollectFloats(nsIFrame* aFrame, nsFrameList& aList,
584 bool aCollectFromSiblings);
586 // Remove a float, abs, rel positioned frame from the appropriate block's list
587 static void DoRemoveOutOfFlowFrame(nsIFrame* aFrame);
589 /** set up the conditions necessary for an resize reflow
590 * the primary task is to mark the minimumly sufficient lines dirty.
592 void PrepareResizeReflow(nsBlockReflowState& aState);
594 /** reflow all lines that have been marked dirty */
595 void ReflowDirtyLines(nsBlockReflowState& aState);
597 /** Mark a given line dirty due to reflow being interrupted on or before it */
598 void MarkLineDirtyForInterrupt(nsLineBox* aLine);
600 //----------------------------------------
601 // Methods for line reflow
603 * Reflow a line.
604 * @param aState the current reflow state
605 * @param aLine the line to reflow. can contain a single block frame
606 * or contain 1 or more inline frames.
607 * @param aKeepReflowGoing [OUT] indicates whether the caller should continue to reflow more lines
609 void ReflowLine(nsBlockReflowState& aState,
610 line_iterator aLine,
611 bool* aKeepReflowGoing);
613 // Return false if it needs another reflow because of reduced space
614 // between floats that are next to it (but not next to its top), and
615 // return true otherwise.
616 bool PlaceLine(nsBlockReflowState& aState,
617 nsLineLayout& aLineLayout,
618 line_iterator aLine,
619 nsFloatManager::SavedState* aFloatStateBeforeLine,
620 nsRect& aFloatAvailableSpace, /* in-out */
621 nscoord& aAvailableSpaceHeight, /* in-out */
622 bool* aKeepReflowGoing);
625 * If NS_BLOCK_LOOK_FOR_DIRTY_FRAMES is set, call MarkLineDirty
626 * on any line with a child frame that is dirty.
628 void LazyMarkLinesDirty();
631 * Mark |aLine| dirty, and, if necessary because of possible
632 * pull-up, mark the previous line dirty as well. Also invalidates textruns
633 * on those lines because the text in the lines might have changed due to
634 * addition/removal of frames.
635 * @param aLine the line to mark dirty
636 * @param aLineList the line list containing that line
638 void MarkLineDirty(line_iterator aLine, const nsLineList* aLineList);
640 // XXX where to go
641 bool IsLastLine(nsBlockReflowState& aState,
642 line_iterator aLine);
644 void DeleteLine(nsBlockReflowState& aState,
645 nsLineList::iterator aLine,
646 nsLineList::iterator aLineEnd);
648 //----------------------------------------
649 // Methods for individual frame reflow
651 bool ShouldApplyBStartMargin(nsBlockReflowState& aState,
652 nsLineBox* aLine,
653 nsIFrame* aChildFrame);
655 void ReflowBlockFrame(nsBlockReflowState& aState,
656 line_iterator aLine,
657 bool* aKeepGoing);
659 void ReflowInlineFrames(nsBlockReflowState& aState,
660 line_iterator aLine,
661 bool* aKeepLineGoing);
663 void DoReflowInlineFrames(nsBlockReflowState& aState,
664 nsLineLayout& aLineLayout,
665 line_iterator aLine,
666 nsFlowAreaRect& aFloatAvailableSpace,
667 nscoord& aAvailableSpaceHeight,
668 nsFloatManager::SavedState*
669 aFloatStateBeforeLine,
670 bool* aKeepReflowGoing,
671 LineReflowStatus* aLineReflowStatus,
672 bool aAllowPullUp);
674 void ReflowInlineFrame(nsBlockReflowState& aState,
675 nsLineLayout& aLineLayout,
676 line_iterator aLine,
677 nsIFrame* aFrame,
678 LineReflowStatus* aLineReflowStatus);
680 // Compute the available width for a float.
681 nsRect AdjustFloatAvailableSpace(nsBlockReflowState& aState,
682 const nsRect& aFloatAvailableSpace,
683 nsIFrame* aFloatFrame);
684 // Computes the border-box width of the float
685 nscoord ComputeFloatWidth(nsBlockReflowState& aState,
686 const nsRect& aFloatAvailableSpace,
687 nsIFrame* aFloat);
688 // An incomplete aReflowStatus indicates the float should be split
689 // but only if the available height is constrained.
690 // aAdjustedAvailableSpace is the result of calling
691 // nsBlockFrame::AdjustFloatAvailableSpace.
692 void ReflowFloat(nsBlockReflowState& aState,
693 const nsRect& aAdjustedAvailableSpace,
694 nsIFrame* aFloat,
695 nsMargin& aFloatMargin,
696 nsMargin& aFloatOffsets,
697 // Whether the float's position
698 // (aAdjustedAvailableSpace) has been pushed down
699 // due to the presence of other floats.
700 bool aFloatPushedDown,
701 nsReflowStatus& aReflowStatus);
703 //----------------------------------------
704 // Methods for pushing/pulling lines/frames
707 * Create a next-in-flow, if necessary, for aFrame. If a new frame is
708 * created, place it in aLine if aLine is not null.
709 * @param aState the block reflow state
710 * @param aLine where to put a new frame
711 * @param aFrame the frame
712 * @return true if a new frame was created, false if not
714 bool CreateContinuationFor(nsBlockReflowState& aState,
715 nsLineBox* aLine,
716 nsIFrame* aFrame);
719 * Push aLine (and any after it), since it cannot be placed on this
720 * page/column. Set aKeepReflowGoing to false and set
721 * flag aState.mReflowStatus as incomplete.
723 void PushTruncatedLine(nsBlockReflowState& aState,
724 line_iterator aLine,
725 bool* aKeepReflowGoing);
727 void SplitLine(nsBlockReflowState& aState,
728 nsLineLayout& aLineLayout,
729 line_iterator aLine,
730 nsIFrame* aFrame,
731 LineReflowStatus* aLineReflowStatus);
734 * Pull a frame from the next available location (one of our lines or
735 * one of our next-in-flows lines).
736 * @return the pulled frame or nullptr
738 nsIFrame* PullFrame(nsBlockReflowState& aState,
739 line_iterator aLine);
742 * Try to pull a frame out of a line pointed at by aFromLine.
744 * Note: pulling a frame from a line that is a place-holder frame
745 * doesn't automatically remove the corresponding float from the
746 * line's float array. This happens indirectly: either the line gets
747 * emptied (and destroyed) or the line gets reflowed (because we mark
748 * it dirty) and the code at the top of ReflowLine empties the
749 * array. So eventually, it will be removed, just not right away.
751 * @return the pulled frame or nullptr
753 nsIFrame* PullFrameFrom(nsLineBox* aLine,
754 nsBlockFrame* aFromContainer,
755 nsLineList::iterator aFromLine);
758 * Push the line after aLineBefore to the overflow line list.
759 * @param aLineBefore a line in 'mLines' (or begin_lines() when
760 * pushing the first line)
762 void PushLines(nsBlockReflowState& aState,
763 nsLineList::iterator aLineBefore);
765 void PropagateFloatDamage(nsBlockReflowState& aState,
766 nsLineBox* aLine,
767 nscoord aDeltaY);
769 void CheckFloats(nsBlockReflowState& aState);
771 //----------------------------------------
772 // List handling kludge
774 // If this returns true, the block it's called on should get the
775 // NS_FRAME_HAS_DIRTY_CHILDREN bit set on it by the caller; either directly
776 // if it's already in reflow, or via calling FrameNeedsReflow() to schedule a
777 // reflow.
778 bool RenumberLists(nsPresContext* aPresContext);
780 static bool RenumberListsInBlock(nsPresContext* aPresContext,
781 nsBlockFrame* aBlockFrame,
782 int32_t* aOrdinal,
783 int32_t aDepth,
784 int32_t aIncrement);
786 static bool RenumberListsFor(nsPresContext* aPresContext, nsIFrame* aKid,
787 int32_t* aOrdinal, int32_t aDepth,
788 int32_t aIncrement);
790 static bool FrameStartsCounterScope(nsIFrame* aFrame);
792 void ReflowBullet(nsIFrame* aBulletFrame,
793 nsBlockReflowState& aState,
794 nsHTMLReflowMetrics& aMetrics,
795 nscoord aLineTop);
797 //----------------------------------------
799 virtual nsILineIterator* GetLineIterator() MOZ_OVERRIDE;
801 public:
802 bool HasOverflowLines() const {
803 return 0 != (GetStateBits() & NS_BLOCK_HAS_OVERFLOW_LINES);
805 FrameLines* GetOverflowLines() const;
806 protected:
807 FrameLines* RemoveOverflowLines();
808 void SetOverflowLines(FrameLines* aOverflowLines);
809 void DestroyOverflowLines();
812 * This class is useful for efficiently modifying the out of flow
813 * overflow list. It gives the client direct writable access to
814 * the frame list temporarily but ensures that property is only
815 * written back if absolutely necessary.
817 struct nsAutoOOFFrameList {
818 nsFrameList mList;
820 explicit nsAutoOOFFrameList(nsBlockFrame* aBlock)
821 : mPropValue(aBlock->GetOverflowOutOfFlows())
822 , mBlock(aBlock) {
823 if (mPropValue) {
824 mList = *mPropValue;
827 ~nsAutoOOFFrameList() {
828 mBlock->SetOverflowOutOfFlows(mList, mPropValue);
830 protected:
831 nsFrameList* const mPropValue;
832 nsBlockFrame* const mBlock;
834 friend struct nsAutoOOFFrameList;
836 nsFrameList* GetOverflowOutOfFlows() const;
837 void SetOverflowOutOfFlows(const nsFrameList& aList, nsFrameList* aPropValue);
840 * @return the inside bullet frame or nullptr if we don't have one.
842 nsBulletFrame* GetInsideBullet() const;
845 * @return the outside bullet frame or nullptr if we don't have one.
847 nsBulletFrame* GetOutsideBullet() const;
850 * @return the outside bullet frame list frame property.
852 nsFrameList* GetOutsideBulletList() const;
855 * @return true if this frame has pushed floats.
857 bool HasPushedFloats() const {
858 return 0 != (GetStateBits() & NS_BLOCK_HAS_PUSHED_FLOATS);
861 // Get the pushed floats list, which is used for *temporary* storage
862 // of floats during reflow, between when we decide they don't fit in
863 // this block until our next continuation takes them.
864 nsFrameList* GetPushedFloats() const;
865 // Get the pushed floats list, or if there is not currently one,
866 // make a new empty one.
867 nsFrameList* EnsurePushedFloats();
868 // Remove and return the pushed floats list.
869 nsFrameList* RemovePushedFloats();
871 #ifdef DEBUG
872 void VerifyLines(bool aFinalCheckOK);
873 void VerifyOverflowSituation();
874 int32_t GetDepth() const;
875 #endif
877 nscoord mMinWidth, mPrefWidth;
879 nsLineList mLines;
881 // List of all floats in this block
882 // XXXmats blocks rarely have floats, make it a frame property
883 nsFrameList mFloats;
885 friend class nsBlockReflowState;
886 friend class nsBlockInFlowLineIterator;
888 #ifdef DEBUG
889 public:
890 static bool gLamePaintMetrics;
891 static bool gLameReflowMetrics;
892 static bool gNoisy;
893 static bool gNoisyDamageRepair;
894 static bool gNoisyIntrinsic;
895 static bool gNoisyReflow;
896 static bool gReallyNoisyReflow;
897 static bool gNoisyFloatManager;
898 static bool gVerifyLines;
899 static bool gDisableResizeOpt;
901 static int32_t gNoiseIndent;
903 static const char* kReflowCommandType[];
905 protected:
906 static void InitDebugFlags();
907 #endif
910 #ifdef DEBUG
911 class AutoNoisyIndenter {
912 public:
913 explicit AutoNoisyIndenter(bool aDoIndent) : mIndented(aDoIndent) {
914 if (mIndented) {
915 nsBlockFrame::gNoiseIndent++;
918 ~AutoNoisyIndenter() {
919 if (mIndented) {
920 nsBlockFrame::gNoiseIndent--;
923 private:
924 bool mIndented;
926 #endif
929 * Iterates over all lines in the prev-in-flows/next-in-flows of this block.
931 class nsBlockInFlowLineIterator {
932 public:
933 typedef nsBlockFrame::line_iterator line_iterator;
935 * Set up the iterator to point to aLine which must be a normal line
936 * in aFrame (not an overflow line).
938 nsBlockInFlowLineIterator(nsBlockFrame* aFrame, line_iterator aLine);
940 * Set up the iterator to point to the first line found starting from
941 * aFrame. Sets aFoundValidLine to false if there is no such line.
942 * After aFoundValidLine has returned false, don't call any methods on this
943 * object again.
945 nsBlockInFlowLineIterator(nsBlockFrame* aFrame, bool* aFoundValidLine);
947 * Set up the iterator to point to the line that contains aFindFrame (either
948 * directly or indirectly). If aFrame is out of flow, or contained in an
949 * out-of-flow, finds the line containing the out-of-flow's placeholder. If
950 * the frame is not found, sets aFoundValidLine to false. After
951 * aFoundValidLine has returned false, don't call any methods on this
952 * object again.
954 nsBlockInFlowLineIterator(nsBlockFrame* aFrame, nsIFrame* aFindFrame,
955 bool* aFoundValidLine);
957 line_iterator GetLine() { return mLine; }
958 bool IsLastLineInList();
959 nsBlockFrame* GetContainer() { return mFrame; }
960 bool GetInOverflow() { return mLineList != &mFrame->mLines; }
963 * Returns the current line list we're iterating, null means
964 * we're iterating |mLines| of the container.
966 nsLineList* GetLineList() { return mLineList; }
969 * Returns the end-iterator of whatever line list we're in.
971 line_iterator End();
974 * Returns false if there are no more lines. After this has returned false,
975 * don't call any methods on this object again.
977 bool Next();
979 * Returns false if there are no more lines. After this has returned false,
980 * don't call any methods on this object again.
982 bool Prev();
984 private:
985 friend class nsBlockFrame;
986 // XXX nsBlockFrame uses this internally in one place. Try to remove it.
987 nsBlockInFlowLineIterator(nsBlockFrame* aFrame, line_iterator aLine, bool aInOverflow);
989 nsBlockFrame* mFrame;
990 line_iterator mLine;
991 nsLineList* mLineList; // the line list mLine is in
994 * Moves iterator to next valid line reachable from the current block.
995 * Returns false if there are no valid lines.
997 bool FindValidLine();
1000 #endif /* nsBlockFrame_h___ */