Bug 1839315: part 4) Link from `SheetLoadData::mWasAlternate` to spec. r=emilio DONTBUILD
[gecko.git] / layout / generic / nsBlockFrame.h
blob79f7064ac2fec91f27bd57c836da390c9ca70e3a
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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 "nsFloatManager.h"
21 enum class LineReflowStatus {
22 // The line was completely reflowed and fit in available width, and we should
23 // try to pull up content from the next line if possible.
24 OK,
25 // The line was completely reflowed and fit in available width, but we should
26 // not try to pull up content from the next line.
27 Stop,
28 // We need to reflow the line again at its current vertical position. The
29 // new reflow should not try to pull up any frames from the next line.
30 RedoNoPull,
31 // We need to reflow the line again using the floats from its height
32 // this reflow, since its height made it hit floats that were not
33 // adjacent to its top.
34 RedoMoreFloats,
35 // We need to reflow the line again at a lower vertical postion where there
36 // may be more horizontal space due to different float configuration.
37 RedoNextBand,
38 // The line did not fit in the available vertical space. Try pushing it to
39 // the next page or column if it's not the first line on the current
40 // page/column.
41 Truncated
44 class nsBlockInFlowLineIterator;
45 namespace mozilla {
46 class BlockReflowState;
47 class PresShell;
48 class ServoRestyleState;
49 class ServoStyleSet;
50 } // namespace mozilla
52 /**
53 * Some invariants:
54 * -- The overflow out-of-flows list contains the out-of-
55 * flow frames whose placeholders are in the overflow list.
56 * -- A given piece of content has at most one placeholder
57 * frame in a block's normal child list.
58 * -- While a block is being reflowed, and from then until
59 * its next-in-flow is reflowed it may have a
60 * PushedFloatProperty frame property that points to
61 * an nsFrameList. This list contains continuations for
62 * floats whose prev-in-flow is in the block's regular float
63 * list and first-in-flows of floats that did not fit, but
64 * whose placeholders are in the block or one of its
65 * prev-in-flows.
66 * -- In all these frame lists, if there are two frames for
67 * the same content appearing in the list, then the frames
68 * appear with the prev-in-flow before the next-in-flow.
69 * -- While reflowing a block, its overflow line list
70 * will usually be empty but in some cases will have lines
71 * (while we reflow the block at its shrink-wrap width).
72 * In this case any new overflowing content must be
73 * prepended to the overflow lines.
77 * Base class for block and inline frames.
78 * The block frame has an additional child list, FrameChildListID::Absolute,
79 * which contains the absolutely positioned frames.
81 class nsBlockFrame : public nsContainerFrame {
82 using BlockReflowState = mozilla::BlockReflowState;
84 public:
85 NS_DECL_FRAMEARENA_HELPERS(nsBlockFrame)
87 typedef nsLineList::iterator LineIterator;
88 typedef nsLineList::const_iterator ConstLineIterator;
89 typedef nsLineList::reverse_iterator ReverseLineIterator;
90 typedef nsLineList::const_reverse_iterator ConstReverseLineIterator;
92 LineIterator LinesBegin() { return mLines.begin(); }
93 LineIterator LinesEnd() { return mLines.end(); }
94 ConstLineIterator LinesBegin() const { return mLines.begin(); }
95 ConstLineIterator LinesEnd() const { return mLines.end(); }
96 ReverseLineIterator LinesRBegin() { return mLines.rbegin(); }
97 ReverseLineIterator LinesREnd() { return mLines.rend(); }
98 ConstReverseLineIterator LinesRBegin() const { return mLines.rbegin(); }
99 ConstReverseLineIterator LinesREnd() const { return mLines.rend(); }
100 LineIterator LinesBeginFrom(nsLineBox* aList) { return mLines.begin(aList); }
101 ReverseLineIterator LinesRBeginFrom(nsLineBox* aList) {
102 return mLines.rbegin(aList);
105 // Methods declared to be used in 'range-based-for-loop'
106 nsLineList& Lines() { return mLines; }
107 const nsLineList& Lines() const { return mLines; }
109 friend nsBlockFrame* NS_NewBlockFrame(mozilla::PresShell* aPresShell,
110 ComputedStyle* aStyle);
112 // nsQueryFrame
113 NS_DECL_QUERYFRAME
115 // nsIFrame
116 void Init(nsIContent* aContent, nsContainerFrame* aParent,
117 nsIFrame* aPrevInFlow) override;
118 void SetInitialChildList(ChildListID aListID,
119 nsFrameList&& aChildList) override;
120 void AppendFrames(ChildListID aListID, nsFrameList&& aFrameList) override;
121 void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
122 const nsLineList::iterator* aPrevFrameLine,
123 nsFrameList&& aFrameList) override;
124 void RemoveFrame(DestroyContext&, ChildListID, nsIFrame* aOldFrame) override;
125 nsContainerFrame* GetContentInsertionFrame() override;
126 void AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) override;
127 const nsFrameList& GetChildList(ChildListID aListID) const override;
128 void GetChildLists(nsTArray<ChildList>* aLists) const override;
129 nscoord SynthesizeFallbackBaseline(
130 mozilla::WritingMode aWM,
131 BaselineSharingGroup aBaselineGroup) const override;
132 BaselineSharingGroup GetDefaultBaselineSharingGroup() const override {
133 return BaselineSharingGroup::Last;
135 Maybe<nscoord> GetNaturalBaselineBOffset(
136 mozilla::WritingMode aWM, BaselineSharingGroup aBaselineGroup,
137 BaselineExportContext aExportContext) const override;
138 nscoord GetCaretBaseline() const override;
139 void Destroy(DestroyContext&) override;
141 bool IsFloatContainingBlock() const override;
142 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
143 const nsDisplayListSet& aLists) override;
144 bool IsFrameOfType(uint32_t aFlags) const override {
145 return nsContainerFrame::IsFrameOfType(
146 aFlags & ~(nsIFrame::eCanContainOverflowContainers));
149 void InvalidateFrame(uint32_t aDisplayItemKey = 0,
150 bool aRebuildDisplayItems = true) override;
151 void InvalidateFrameWithRect(const nsRect& aRect,
152 uint32_t aDisplayItemKey = 0,
153 bool aRebuildDisplayItems = true) override;
155 #ifdef DEBUG_FRAME_DUMP
156 void List(FILE* out = stderr, const char* aPrefix = "",
157 ListFlags aFlags = ListFlags()) const override;
158 nsresult GetFrameName(nsAString& aResult) const override;
159 #endif
161 #ifdef DEBUG
162 const char* LineReflowStatusToString(
163 LineReflowStatus aLineReflowStatus) const;
164 #endif
166 #ifdef ACCESSIBILITY
167 mozilla::a11y::AccType AccessibleType() override;
168 #endif
170 // Line cursor methods to speed up line searching in which one query result
171 // is expected to be close to the next in general. This is mainly for
172 // searching line(s) containing a point. It is also used as a cache for local
173 // computation. The basic idea for the former is that we set the cursor
174 // property if the lines' overflowArea.InkOverflow().ys and
175 // overflowArea.InkOverflow().yMosts are non-decreasing
176 // (considering only non-empty overflowArea.InkOverflow()s; empty
177 // overflowArea.InkOverflow()s never participate in event handling
178 // or painting), and the block has sufficient number of lines. The
179 // cursor property points to a "recently used" line. If we get a
180 // series of requests that work on lines
181 // "near" the cursor, then we can find those nearby lines quickly by
182 // starting our search at the cursor.
184 // We have two independent line cursors, one used for display-list building
185 // and the other for a11y or other frame queries. Either or both may be
186 // present at any given time. When we reflow or otherwise munge the lines,
187 // both cursors will be cleared.
188 // The display cursor is only created and used if the lines satisfy the non-
189 // decreasing y-coordinate condition (see SetupLineCursorForDisplay comment
190 // below), whereas the query cursor may be created for any block. The two
191 // are separated so creating a cursor for a11y queries (eg GetRenderedText)
192 // does not risk confusing the display-list building code.
194 // Clear out line cursors because we're disturbing the lines (i.e., Reflow)
195 void ClearLineCursors() {
196 if (MaybeHasLineCursor()) {
197 ClearLineCursorForDisplay();
198 ClearLineCursorForQuery();
199 RemoveStateBits(NS_BLOCK_HAS_LINE_CURSOR);
201 RemoveProperty(LineIteratorProperty());
203 void ClearLineCursorForDisplay() {
204 RemoveProperty(LineCursorPropertyDisplay());
206 void ClearLineCursorForQuery() { RemoveProperty(LineCursorPropertyQuery()); }
208 // Get the first line that might contain y-coord 'y', or nullptr if you must
209 // search all lines. If nonnull is returned then we guarantee that the lines'
210 // combinedArea.ys and combinedArea.yMosts are non-decreasing.
211 // The actual line returned might not contain 'y', but if not, it is
212 // guaranteed to be before any line which does contain 'y'.
213 nsLineBox* GetFirstLineContaining(nscoord y);
215 // Ensure the frame has a display-list line cursor, initializing it to the
216 // first line if it is not already present. (If there's an existing cursor,
217 // it is left untouched.) Only call this if you guarantee that the lines'
218 // combinedArea.ys and combinedArea.yMosts are non-decreasing.
219 void SetupLineCursorForDisplay();
221 // Ensure the frame has a query line cursor, initializing it to the first
222 // line if it is not already present. (If there's an existing cursor, it is
223 // left untouched.)
224 void SetupLineCursorForQuery();
226 void ChildIsDirty(nsIFrame* aChild) override;
228 bool IsEmpty() override;
229 bool CachedIsEmpty() override;
230 bool IsSelfEmpty() override;
232 // Given that we have a ::marker frame, does it actually draw something, i.e.,
233 // do we have either a 'list-style-type' or 'list-style-image' that is
234 // not 'none', and no 'content'?
235 bool MarkerIsEmpty() const;
238 * Return true if this frame has a ::marker frame.
240 bool HasMarker() const { return HasOutsideMarker() || HasInsideMarker(); }
243 * @return true if this frame has an inside ::marker frame.
245 bool HasInsideMarker() const {
246 return HasAnyStateBits(NS_BLOCK_FRAME_HAS_INSIDE_MARKER);
250 * @return true if this frame has an outside ::marker frame.
252 bool HasOutsideMarker() const {
253 return HasAnyStateBits(NS_BLOCK_FRAME_HAS_OUTSIDE_MARKER);
257 * @return the ::marker frame or nullptr if we don't have one.
259 nsIFrame* GetMarker() const {
260 nsIFrame* outside = GetOutsideMarker();
261 return outside ? outside : GetInsideMarker();
265 * @return the first-letter frame or nullptr if we don't have one.
267 nsIFrame* GetFirstLetter() const;
270 * @return the ::first-line frame or nullptr if we don't have one.
272 nsIFrame* GetFirstLineFrame() const;
274 void MarkIntrinsicISizesDirty() override;
276 private:
277 void CheckIntrinsicCacheAgainstShrinkWrapState();
279 template <typename LineIteratorType>
280 Maybe<nscoord> GetBaselineBOffset(LineIteratorType aStart,
281 LineIteratorType aEnd,
282 mozilla::WritingMode aWM,
283 BaselineSharingGroup aBaselineGroup,
284 BaselineExportContext aExportContext) const;
286 public:
287 nscoord GetMinISize(gfxContext* aRenderingContext) override;
288 nscoord GetPrefISize(gfxContext* aRenderingContext) override;
290 nsRect ComputeTightBounds(DrawTarget* aDrawTarget) const override;
292 nsresult GetPrefWidthTightBounds(gfxContext* aContext, nscoord* aX,
293 nscoord* aXMost) override;
296 * Compute the final block size of this frame.
298 * @param aState BlockReflowState passed from parent during reflow.
299 * Note: aState.mReflowStatus is mostly an "input" parameter. When this
300 * method is called, it should represent what our status would be as if
301 * we were shrinkwrapping our children's block-size. This method will
302 * then adjust it before returning if our status is different in light
303 * of our actual final block-size and current page/column's available
304 * block-size.
305 * @param aBEndEdgeOfChildren The distance between this frame's block-start
306 * border-edge and the block-end edge of our last child's border-box.
307 * This is effectively our block-start border-padding plus the
308 * block-size of our children, precomputed outside of this function.
309 * @return our final block-size with respect to aReflowInput's writing-mode.
311 nscoord ComputeFinalBSize(BlockReflowState& aState,
312 nscoord aBEndEdgeOfChildren);
314 void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
315 const ReflowInput& aReflowInput,
316 nsReflowStatus& aStatus) override;
319 * Move any frames on our overflow list to the end of our principal list.
320 * @return true if there were any overflow frames
322 bool DrainSelfOverflowList() override;
324 void StealFrame(nsIFrame* aChild) override;
326 void DeleteNextInFlowChild(DestroyContext&, nsIFrame* aNextInFlow,
327 bool aDeletingEmptyFrames) override;
330 * This is a special method that allows a child class of nsBlockFrame to
331 * return a special, customized nsStyleText object to the nsLineLayout
332 * constructor. It is used when the nsBlockFrame child needs to specify its
333 * custom rendering style.
335 virtual const nsStyleText* StyleTextForLineLayout();
338 * Determines whether the collapsed margin carried out of the last
339 * line includes the margin-top of a line with clearance (in which
340 * case we must avoid collapsing that margin with our bottom margin)
342 bool CheckForCollapsedBEndMarginFromClearanceLine();
344 static nsresult GetCurrentLine(BlockReflowState* aState,
345 nsLineBox** aOutCurrentLine);
348 * Determine if this block is a margin root at the top/bottom edges.
350 void IsMarginRoot(bool* aBStartMarginRoot, bool* aBEndMarginRoot);
352 static bool BlockNeedsFloatManager(nsIFrame* aBlock);
355 * Returns whether aFrame is a block frame that will wrap its contents
356 * around floats intruding on it from the outside. (aFrame need not
357 * be a block frame, but if it's not, the result will be false.)
359 * Note: We often use the term "float-avoiding block" to refer to
360 * block-level frames for whom this function returns false.
362 static bool BlockCanIntersectFloats(nsIFrame* aFrame);
365 * Returns the inline size that needs to be cleared past floats for
366 * blocks that avoid (i.e. cannot intersect) floats. aState must already
367 * have GetFloatAvailableSpace called on it for the block-dir position that
368 * we care about (which need not be its current mBCoord)
370 struct FloatAvoidingISizeToClear {
371 // Note that we care about the inline-start margin but can ignore
372 // the inline-end margin.
373 nscoord marginIStart, borderBoxISize;
375 static FloatAvoidingISizeToClear ISizeToClearPastFloats(
376 const BlockReflowState& aState,
377 const mozilla::LogicalRect& aFloatAvailableSpace,
378 nsIFrame* aFloatAvoidingBlock);
381 * Creates a contination for aFloat and adds it to the list of overflow
382 * floats. Also updates aState.mReflowStatus to include the float's
383 * incompleteness. Must only be called while this block frame is in reflow.
384 * aFloatStatus must be the float's true, unmodified reflow status.
386 void SplitFloat(BlockReflowState& aState, nsIFrame* aFloat,
387 const nsReflowStatus& aFloatStatus);
390 * Walks up the frame tree, starting with aCandidate, and returns the first
391 * block frame that it encounters.
393 static nsBlockFrame* GetNearestAncestorBlock(nsIFrame* aCandidate);
395 struct FrameLines {
396 nsLineList mLines;
397 nsFrameList mFrames;
401 * Update the styles of our various pseudo-elements (marker, first-line,
402 * etc, but _not_ first-letter).
404 void UpdatePseudoElementStyles(mozilla::ServoRestyleState& aRestyleState);
406 // Update our first-letter styles during stylo post-traversal. This needs to
407 // be done at a slightly different time than our other pseudo-elements.
408 void UpdateFirstLetterStyle(mozilla::ServoRestyleState& aRestyleState);
410 protected:
411 explicit nsBlockFrame(ComputedStyle* aStyle, nsPresContext* aPresContext,
412 ClassID aID = kClassID)
413 : nsContainerFrame(aStyle, aPresContext, aID) {
414 #ifdef DEBUG
415 InitDebugFlags();
416 #endif
419 virtual ~nsBlockFrame();
421 #ifdef DEBUG
422 already_AddRefed<ComputedStyle> GetFirstLetterStyle(
423 nsPresContext* aPresContext);
424 #endif
426 NS_DECLARE_FRAME_PROPERTY_WITHOUT_DTOR(LineCursorPropertyDisplay, nsLineBox)
427 NS_DECLARE_FRAME_PROPERTY_WITHOUT_DTOR(LineCursorPropertyQuery, nsLineBox)
428 // Note that the NS_BLOCK_HAS_LINE_CURSOR flag does not necessarily mean the
429 // cursor is present, as it covers both the "display" and "query" cursors,
430 // but may remain set if they have been separately deleted. In such a case,
431 // the Get* accessors will be slightly more expensive, but will still safely
432 // return null if the cursor is absent.
433 bool MaybeHasLineCursor() {
434 return HasAnyStateBits(NS_BLOCK_HAS_LINE_CURSOR);
436 nsLineBox* GetLineCursorForDisplay() {
437 return MaybeHasLineCursor() ? GetProperty(LineCursorPropertyDisplay())
438 : nullptr;
440 nsLineBox* GetLineCursorForQuery() {
441 return MaybeHasLineCursor() ? GetProperty(LineCursorPropertyQuery())
442 : nullptr;
445 nsLineBox* NewLineBox(nsIFrame* aFrame, bool aIsBlock) {
446 return NS_NewLineBox(PresShell(), aFrame, aIsBlock);
448 nsLineBox* NewLineBox(nsLineBox* aFromLine, nsIFrame* aFrame,
449 int32_t aCount) {
450 return NS_NewLineBox(PresShell(), aFromLine, aFrame, aCount);
452 void FreeLineBox(nsLineBox* aLine) {
453 if (aLine == GetLineCursorForDisplay()) {
454 ClearLineCursorForDisplay();
456 if (aLine == GetLineCursorForQuery()) {
457 ClearLineCursorForQuery();
459 aLine->Destroy(PresShell());
462 * Helper method for StealFrame.
464 void RemoveFrameFromLine(nsIFrame* aChild, nsLineList::iterator aLine,
465 nsFrameList& aFrameList, nsLineList& aLineList);
467 void TryAllLines(nsLineList::iterator* aIterator,
468 nsLineList::iterator* aStartIterator,
469 nsLineList::iterator* aEndIterator, bool* aInOverflowLines,
470 FrameLines** aOverflowLines);
472 /** move the frames contained by aLine by aDeltaBCoord
473 * if aLine is a block, its child floats are added to the state manager
475 void SlideLine(BlockReflowState& aState, nsLineBox* aLine,
476 nscoord aDeltaBCoord);
478 void UpdateLineContainerSize(nsLineBox* aLine,
479 const nsSize& aNewContainerSize);
481 // helper for SlideLine and UpdateLineContainerSize
482 void MoveChildFramesOfLine(nsLineBox* aLine, nscoord aDeltaBCoord);
484 // Returns block-end edge of children.
485 nscoord ComputeFinalSize(const ReflowInput& aReflowInput,
486 BlockReflowState& aState, ReflowOutput& aMetrics);
489 * Helper method for Reflow(). Computes the overflow areas created by our
490 * children, and includes them into aOverflowAreas.
492 void ComputeOverflowAreas(mozilla::OverflowAreas& aOverflowAreas,
493 nscoord aBEndEdgeOfChildren,
494 const nsStyleDisplay* aDisplay) const;
497 * Helper method for ComputeOverflowAreas(). Incorporates aBEndEdgeOfChildren
498 * into the aOverflowAreas.
500 void ConsiderBlockEndEdgeOfChildren(mozilla::OverflowAreas& aOverflowAreas,
501 nscoord aBEndEdgeOfChildren,
502 const nsStyleDisplay* aDisplay) const;
505 * Add the frames in aFrameList to this block after aPrevSibling.
506 * This block thinks in terms of lines, but the frame construction code
507 * knows nothing about lines at all so we need to find the line that
508 * contains aPrevSibling and add aFrameList after aPrevSibling on that line.
509 * New lines are created as necessary to handle block data in aFrameList.
510 * This function will clear aFrameList.
512 * aPrevSiblingLine, if present, must be the line containing aPrevSibling.
513 * Providing it will make this function faster.
515 void AddFrames(nsFrameList&& aFrameList, nsIFrame* aPrevSibling,
516 const nsLineList::iterator* aPrevSiblingLine);
518 // Return the :-moz-block-ruby-content child frame, if any.
519 // (It's non-null only if this block frame is for 'display:block ruby'.)
520 nsContainerFrame* GetRubyContentPseudoFrame();
523 * Perform Bidi resolution on this frame
525 nsresult ResolveBidi();
528 * Test whether the frame is a form control in a visual Bidi page.
529 * This is necessary for backwards-compatibility, because most visual
530 * pages use logical order for form controls so that they will
531 * display correctly on native widgets in OSs with Bidi support
532 * @param aPresContext the pres context
533 * @return whether the frame is a BIDI form control
535 bool IsVisualFormControl(nsPresContext* aPresContext);
538 * For text-wrap:balance, we iteratively try reflowing with adjusted inline
539 * size to find the "best" result (the tightest size that can be applied
540 * without increasing the total line count of the block).
541 * This record is used to manage the state of these "trial reflows", and
542 * return results from the final trial.
544 struct TrialReflowState {
545 // Values pre-computed at start of Reflow(), constant across trials.
546 const nscoord mConsumedBSize;
547 const nscoord mEffectiveContentBoxBSize;
548 bool mNeedFloatManager;
549 // Settings for the current trial.
550 bool mBalancing = false;
551 nscoord mInset = 0;
552 // Results computed during the trial reflow. Values from the final trial
553 // will be used by the remainder of Reflow().
554 mozilla::OverflowAreas mOcBounds;
555 mozilla::OverflowAreas mFcBounds;
556 nscoord mBlockEndEdgeOfChildren = 0;
557 nscoord mContainerWidth = 0;
559 // Initialize for the initial trial reflow, with zero inset.
560 TrialReflowState(nscoord aConsumedBSize, nscoord aEffectiveContentBoxBSize,
561 bool aNeedFloatManager)
562 : mConsumedBSize(aConsumedBSize),
563 mEffectiveContentBoxBSize(aEffectiveContentBoxBSize),
564 mNeedFloatManager(aNeedFloatManager) {}
566 // Adjust the inset amount, and reset state for a new trial.
567 void ResetForBalance(nscoord aInsetDelta) {
568 // Tells the reflow-lines loop we must consider all lines "dirty" (as we
569 // are modifying the effective inline-size to be used).
570 mBalancing = true;
571 // Adjust inset to apply.
572 mInset += aInsetDelta;
573 // Re-initialize state that the reflow loop will compute.
574 mOcBounds.Clear();
575 mFcBounds.Clear();
576 mBlockEndEdgeOfChildren = 0;
577 mContainerWidth = 0;
582 * Internal helper for Reflow(); may be called repeatedly during a single
583 * Reflow() in order to implement text-wrap:balance.
584 * This method applies aTrialState.mInset during line-breaking to reduce
585 * the effective available inline-size (without affecting alignment).
587 nsReflowStatus TrialReflow(nsPresContext* aPresContext,
588 ReflowOutput& aMetrics,
589 const ReflowInput& aReflowInput,
590 TrialReflowState& aTrialState);
592 public:
594 * Helper function for the frame ctor to register a ::marker frame.
596 void SetMarkerFrameForListItem(nsIFrame* aMarkerFrame);
599 * Does all the real work for removing aDeletedFrame
600 * -- finds the line containing aDeletedFrame
601 * -- removes all aDeletedFrame next-in-flows (or all continuations,
602 * if REMOVE_FIXED_CONTINUATIONS is given)
603 * -- marks lines dirty as needed
604 * -- marks textruns dirty (unless FRAMES_ARE_EMPTY is given, in which
605 * case textruns do not need to be dirtied)
606 * -- destroys all removed frames
608 enum { REMOVE_FIXED_CONTINUATIONS = 0x02, FRAMES_ARE_EMPTY = 0x04 };
609 void DoRemoveFrame(DestroyContext&, nsIFrame* aDeletedFrame, uint32_t aFlags);
611 void ReparentFloats(nsIFrame* aFirstFrame, nsBlockFrame* aOldParent,
612 bool aReparentSiblings);
614 bool ComputeCustomOverflow(mozilla::OverflowAreas&) override;
616 void UnionChildOverflow(mozilla::OverflowAreas&) override;
619 * Load all of aFrame's floats into the float manager iff aFrame is not a
620 * block formatting context. Handles all necessary float manager translations;
621 * assumes float manager is in aFrame's parent's coord system.
623 * Safe to call on non-blocks (does nothing).
625 static void RecoverFloatsFor(nsIFrame* aFrame, nsFloatManager& aFloatManager,
626 mozilla::WritingMode aWM,
627 const nsSize& aContainerSize);
630 * Determine if we have any pushed floats from a previous continuation.
632 * @returns true, if any of the floats at the beginning of our mFloats list
633 * have the NS_FRAME_IS_PUSHED_FLOAT bit set; false otherwise.
635 bool HasPushedFloatsFromPrevContinuation() const;
637 // @see nsIFrame::AddSizeOfExcludingThisForTree
638 void AddSizeOfExcludingThisForTree(nsWindowSizes&) const override;
641 * Clears any -webkit-line-clamp ellipsis on a line in this block or one
642 * of its descendants.
644 void ClearLineClampEllipsis();
647 * Returns whether this block is in a -webkit-line-clamp context. That is,
648 * whether this block is in a block formatting-context whose root block has
649 * -webkit-line-clamp: <n>.
651 bool IsInLineClampContext() const;
653 protected:
654 /** grab overflow lines from this block's prevInFlow, and make them
655 * part of this block's mLines list.
656 * @return true if any lines were drained.
658 bool DrainOverflowLines();
661 * @return false iff this block does not have a float on any child list.
662 * This function is O(1).
664 bool MaybeHasFloats() const {
665 if (!mFloats.IsEmpty()) {
666 return true;
668 // XXX this could be replaced with HasPushedFloats() if we enforced
669 // removing the property when the frame list becomes empty.
670 nsFrameList* list = GetPushedFloats();
671 if (list && !list->IsEmpty()) {
672 return true;
674 // For the OverflowOutOfFlowsProperty I think we do enforce that, but it's
675 // a mix of out-of-flow frames, so that's why the method name has "Maybe".
676 return HasAnyStateBits(NS_BLOCK_HAS_OVERFLOW_OUT_OF_FLOWS);
680 * Moves frames from our PushedFloats list back into our mFloats list.
682 void DrainSelfPushedFloats();
685 * First calls DrainSelfPushedFloats() then grabs pushed floats from this
686 * block's prev-in-flow, and splice them into this block's mFloats list too.
688 void DrainPushedFloats();
690 /** Load all our floats into the float manager (without reflowing them).
691 * Assumes float manager is in our own coordinate system.
693 void RecoverFloats(nsFloatManager& aFloatManager, mozilla::WritingMode aWM,
694 const nsSize& aContainerSize);
696 /** Reflow pushed floats
698 void ReflowPushedFloats(BlockReflowState& aState,
699 mozilla::OverflowAreas& aOverflowAreas);
702 * Find any trailing BR clear from the last line of this block (or from its
703 * prev-in-flows).
705 mozilla::StyleClear FindTrailingClear();
708 * Remove a float from our float list.
710 void RemoveFloat(nsIFrame* aFloat);
712 * Remove a float from the float cache for the line its placeholder is on.
714 void RemoveFloatFromFloatCache(nsIFrame* aFloat);
716 void CollectFloats(nsIFrame* aFrame, nsFrameList& aList,
717 bool aCollectFromSiblings) {
718 if (MaybeHasFloats()) {
719 DoCollectFloats(aFrame, aList, aCollectFromSiblings);
722 void DoCollectFloats(nsIFrame* aFrame, nsFrameList& aList,
723 bool aCollectFromSiblings);
725 // Remove a float, abs, rel positioned frame from the appropriate block's list
726 static void DoRemoveOutOfFlowFrame(DestroyContext&, nsIFrame*);
728 /** set up the conditions necessary for an resize reflow
729 * the primary task is to mark the minimumly sufficient lines dirty.
731 void PrepareResizeReflow(BlockReflowState& aState);
733 /** reflow all lines that have been marked dirty */
734 void ReflowDirtyLines(BlockReflowState& aState);
736 /** Mark a given line dirty due to reflow being interrupted on or before it */
737 void MarkLineDirtyForInterrupt(nsLineBox* aLine);
739 //----------------------------------------
740 // Methods for line reflow
742 * Reflow a line.
744 * @param aState
745 * the current reflow input
746 * @param aLine
747 * the line to reflow. can contain a single block frame or contain 1 or
748 * more inline frames.
749 * @param aKeepReflowGoing [OUT]
750 * indicates whether the caller should continue to reflow more lines
752 void ReflowLine(BlockReflowState& aState, LineIterator aLine,
753 bool* aKeepReflowGoing);
755 // Return false if it needs another reflow because of reduced space
756 // between floats that are next to it (but not next to its top), and
757 // return true otherwise.
758 bool PlaceLine(BlockReflowState& aState, nsLineLayout& aLineLayout,
759 LineIterator aLine,
760 nsFloatManager::SavedState* aFloatStateBeforeLine,
761 nsFlowAreaRect& aFlowArea, // in-out
762 nscoord& aAvailableSpaceBSize, // in-out
763 bool* aKeepReflowGoing);
766 * If NS_BLOCK_LOOK_FOR_DIRTY_FRAMES is set, call MarkLineDirty
767 * on any line with a child frame that is dirty.
769 void LazyMarkLinesDirty();
772 * Mark |aLine| dirty, and, if necessary because of possible
773 * pull-up, mark the previous line dirty as well. Also invalidates textruns
774 * on those lines because the text in the lines might have changed due to
775 * addition/removal of frames.
776 * @param aLine the line to mark dirty
777 * @param aLineList the line list containing that line
779 void MarkLineDirty(LineIterator aLine, const nsLineList* aLineList);
781 // XXX where to go
782 bool IsLastLine(BlockReflowState& aState, LineIterator aLine);
784 void DeleteLine(BlockReflowState& aState, nsLineList::iterator aLine,
785 nsLineList::iterator aLineEnd);
787 //----------------------------------------
788 // Methods for individual frame reflow
790 bool ShouldApplyBStartMargin(BlockReflowState& aState, nsLineBox* aLine);
792 void ReflowBlockFrame(BlockReflowState& aState, LineIterator aLine,
793 bool* aKeepGoing);
795 void ReflowInlineFrames(BlockReflowState& aState, LineIterator aLine,
796 bool* aKeepLineGoing);
798 void DoReflowInlineFrames(
799 BlockReflowState& aState, nsLineLayout& aLineLayout, LineIterator aLine,
800 nsFlowAreaRect& aFloatAvailableSpace, nscoord& aAvailableSpaceBSize,
801 nsFloatManager::SavedState* aFloatStateBeforeLine, bool* aKeepReflowGoing,
802 LineReflowStatus* aLineReflowStatus, bool aAllowPullUp);
804 void ReflowInlineFrame(BlockReflowState& aState, nsLineLayout& aLineLayout,
805 LineIterator aLine, nsIFrame* aFrame,
806 LineReflowStatus* aLineReflowStatus);
808 // @param aReflowStatus an incomplete status indicates the float should be
809 // split but only if the available block-size is constrained.
810 void ReflowFloat(BlockReflowState& aState, ReflowInput& aFloatRI,
811 nsIFrame* aFloat, nsReflowStatus& aReflowStatus);
813 //----------------------------------------
814 // Methods for pushing/pulling lines/frames
817 * Create a next-in-flow, if necessary, for aFrame. If a new frame is
818 * created, place it in aLine if aLine is not null.
819 * @param aState the block reflow state
820 * @param aLine where to put a new frame
821 * @param aFrame the frame
822 * @return true if a new frame was created, false if not
824 bool CreateContinuationFor(BlockReflowState& aState, nsLineBox* aLine,
825 nsIFrame* aFrame);
828 * Set line-break-before status in aState.mReflowStatus because aLine cannot
829 * be placed on this page/column and we don't want to break within ourselves.
830 * Also, mark the aLine dirty, and set aKeepReflowGoing to false;
832 void SetBreakBeforeStatusBeforeLine(BlockReflowState& aState,
833 LineIterator aLine,
834 bool* aKeepReflowGoing);
837 * Push aLine (and any after it), since it cannot be placed on this
838 * page/column. Set aKeepReflowGoing to false and set
839 * flag aState.mReflowStatus as incomplete.
841 void PushTruncatedLine(BlockReflowState& aState, LineIterator aLine,
842 bool* aKeepReflowGoing);
844 void SplitLine(BlockReflowState& aState, nsLineLayout& aLineLayout,
845 LineIterator aLine, nsIFrame* aFrame,
846 LineReflowStatus* aLineReflowStatus);
849 * Pull a frame from the next available location (one of our lines or
850 * one of our next-in-flows lines).
851 * @return the pulled frame or nullptr
853 nsIFrame* PullFrame(BlockReflowState& aState, LineIterator aLine);
856 * Try to pull a frame out of a line pointed at by aFromLine.
858 * Note: pulling a frame from a line that is a place-holder frame
859 * doesn't automatically remove the corresponding float from the
860 * line's float array. This happens indirectly: either the line gets
861 * emptied (and destroyed) or the line gets reflowed (because we mark
862 * it dirty) and the code at the top of ReflowLine empties the
863 * array. So eventually, it will be removed, just not right away.
865 * @return the pulled frame or nullptr
867 nsIFrame* PullFrameFrom(nsLineBox* aLine, nsBlockFrame* aFromContainer,
868 nsLineList::iterator aFromLine);
871 * Push the line after aLineBefore to the overflow line list.
872 * @param aLineBefore a line in 'mLines' (or LinesBegin() when
873 * pushing the first line)
875 void PushLines(BlockReflowState& aState, nsLineList::iterator aLineBefore);
877 void PropagateFloatDamage(BlockReflowState& aState, nsLineBox* aLine,
878 nscoord aDeltaBCoord);
880 void CheckFloats(BlockReflowState& aState);
882 //----------------------------------------
883 // List handling kludge
885 void ReflowOutsideMarker(nsIFrame* aMarkerFrame, BlockReflowState& aState,
886 ReflowOutput& aMetrics, nscoord aLineTop);
888 //----------------------------------------
890 NS_DECLARE_FRAME_PROPERTY_DELETABLE(LineIteratorProperty, nsLineIterator);
892 bool CanProvideLineIterator() const final { return true; }
893 nsILineIterator* GetLineIterator() final;
895 public:
896 bool HasOverflowLines() const {
897 return HasAnyStateBits(NS_BLOCK_HAS_OVERFLOW_LINES);
899 FrameLines* GetOverflowLines() const;
901 protected:
902 FrameLines* RemoveOverflowLines();
903 void SetOverflowLines(FrameLines* aOverflowLines);
904 void DestroyOverflowLines();
907 * This class is useful for efficiently modifying the out of flow
908 * overflow list. It gives the client direct writable access to
909 * the frame list temporarily but ensures that property is only
910 * written back if absolutely necessary.
912 struct nsAutoOOFFrameList {
913 nsFrameList mList;
915 explicit nsAutoOOFFrameList(nsBlockFrame* aBlock)
916 : mPropValue(aBlock->GetOverflowOutOfFlows()), mBlock(aBlock) {
917 if (mPropValue) {
918 mList = std::move(*mPropValue);
921 ~nsAutoOOFFrameList() {
922 mBlock->SetOverflowOutOfFlows(std::move(mList), mPropValue);
925 protected:
926 nsFrameList* const mPropValue;
927 nsBlockFrame* const mBlock;
929 friend struct nsAutoOOFFrameList;
931 nsFrameList* GetOverflowOutOfFlows() const;
933 // This takes ownership of the frames in aList.
934 void SetOverflowOutOfFlows(nsFrameList&& aList, nsFrameList* aPropValue);
937 * @return the inside ::marker frame or nullptr if we don't have one.
939 nsIFrame* GetInsideMarker() const;
942 * @return the outside ::marker frame or nullptr if we don't have one.
944 nsIFrame* GetOutsideMarker() const;
947 * @return the outside ::marker frame list frame property.
949 nsFrameList* GetOutsideMarkerList() const;
952 * @return true if this frame has pushed floats.
954 bool HasPushedFloats() const {
955 return HasAnyStateBits(NS_BLOCK_HAS_PUSHED_FLOATS);
958 // Get the pushed floats list, which is used for *temporary* storage
959 // of floats during reflow, between when we decide they don't fit in
960 // this block until our next continuation takes them.
961 nsFrameList* GetPushedFloats() const;
962 // Get the pushed floats list, or if there is not currently one,
963 // make a new empty one.
964 nsFrameList* EnsurePushedFloats();
965 // Remove and return the pushed floats list.
966 nsFrameList* RemovePushedFloats();
968 #ifdef DEBUG
969 void VerifyLines(bool aFinalCheckOK);
970 void VerifyOverflowSituation();
971 int32_t GetDepth() const;
972 #endif
974 nscoord mCachedMinISize = NS_INTRINSIC_ISIZE_UNKNOWN;
975 nscoord mCachedPrefISize = NS_INTRINSIC_ISIZE_UNKNOWN;
977 nsLineList mLines;
979 // List of all floats in this block
980 // XXXmats blocks rarely have floats, make it a frame property
981 nsFrameList mFloats;
983 friend class mozilla::BlockReflowState;
984 friend class nsBlockInFlowLineIterator;
986 #ifdef DEBUG
987 public:
988 static bool gLamePaintMetrics;
989 static bool gLameReflowMetrics;
990 static bool gNoisy;
991 static bool gNoisyDamageRepair;
992 static bool gNoisyIntrinsic;
993 static bool gNoisyReflow;
994 static bool gReallyNoisyReflow;
995 static bool gNoisyFloatManager;
996 static bool gVerifyLines;
997 static bool gDisableResizeOpt;
999 static int32_t gNoiseIndent;
1001 static const char* kReflowCommandType[];
1003 protected:
1004 static void InitDebugFlags();
1005 #endif
1008 #ifdef DEBUG
1009 class AutoNoisyIndenter {
1010 public:
1011 explicit AutoNoisyIndenter(bool aDoIndent) : mIndented(aDoIndent) {
1012 if (mIndented) {
1013 nsBlockFrame::gNoiseIndent++;
1016 ~AutoNoisyIndenter() {
1017 if (mIndented) {
1018 nsBlockFrame::gNoiseIndent--;
1022 private:
1023 bool mIndented;
1025 #endif
1028 * Iterates over all lines in the prev-in-flows/next-in-flows of this block.
1030 class nsBlockInFlowLineIterator {
1031 public:
1032 typedef nsBlockFrame::LineIterator LineIterator;
1034 * Set up the iterator to point to aLine which must be a normal line
1035 * in aFrame (not an overflow line).
1037 nsBlockInFlowLineIterator(nsBlockFrame* aFrame, LineIterator aLine);
1039 * Set up the iterator to point to the first line found starting from
1040 * aFrame. Sets aFoundValidLine to false if there is no such line.
1041 * After aFoundValidLine has returned false, don't call any methods on this
1042 * object again.
1044 nsBlockInFlowLineIterator(nsBlockFrame* aFrame, bool* aFoundValidLine);
1046 * Set up the iterator to point to the line that contains aFindFrame (either
1047 * directly or indirectly). If aFrame is out of flow, or contained in an
1048 * out-of-flow, finds the line containing the out-of-flow's placeholder. If
1049 * the frame is not found, sets aFoundValidLine to false. After
1050 * aFoundValidLine has returned false, don't call any methods on this
1051 * object again.
1053 nsBlockInFlowLineIterator(nsBlockFrame* aFrame, nsIFrame* aFindFrame,
1054 bool* aFoundValidLine);
1056 // Allow to be uninitialized (and then assigned from another object).
1057 nsBlockInFlowLineIterator() : mFrame(nullptr) {}
1059 LineIterator GetLine() { return mLine; }
1060 bool IsLastLineInList();
1061 nsBlockFrame* GetContainer() { return mFrame; }
1062 bool GetInOverflow() { return mLineList != &mFrame->mLines; }
1065 * Returns the current line list we're iterating, null means
1066 * we're iterating |mLines| of the container.
1068 nsLineList* GetLineList() { return mLineList; }
1071 * Returns the end-iterator of whatever line list we're in.
1073 LineIterator End();
1076 * Returns false if there are no more lines. After this has returned false,
1077 * don't call any methods on this object again.
1079 bool Next();
1081 * Returns false if there are no more lines. After this has returned false,
1082 * don't call any methods on this object again.
1084 bool Prev();
1086 // XXX nsBlockFrame uses this internally in one place. Try to remove it.
1087 // XXX uhm, and nsBidiPresUtils::Resolve too.
1088 nsBlockInFlowLineIterator(nsBlockFrame* aFrame, LineIterator aLine,
1089 bool aInOverflow);
1091 private:
1092 nsBlockFrame* mFrame;
1093 LineIterator mLine;
1094 nsLineList* mLineList; // the line list mLine is in
1097 * Moves iterator to next valid line reachable from the current block.
1098 * Returns false if there are no valid lines.
1100 bool FindValidLine();
1103 #endif /* nsBlockFrame_h___ */