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 /* struct containing the input to nsIFrame::Reflow */
9 #ifndef mozilla_ReflowInput_h
10 #define mozilla_ReflowInput_h
13 #include "nsStyleConsts.h"
14 #include "mozilla/Assertions.h"
15 #include "mozilla/EnumSet.h"
16 #include "mozilla/Maybe.h"
17 #include "mozilla/WritingModes.h"
18 #include "LayoutConstants.h"
19 #include "ReflowOutput.h"
24 struct nsHypotheticalPosition
;
25 class nsIPercentBSizeObserver
;
27 class nsPlaceholderFrame
;
32 enum class LayoutFrameType
: uint8_t;
35 * A set of StyleSizes used as an input parameter to various functions that
36 * compute sizes like nsIFrame::ComputeSize(). If any of the member fields has a
37 * value, the function may use the value instead of retrieving it from the
40 * The logical sizes are assumed to be in the associated frame's writing-mode.
42 struct StyleSizeOverrides
{
43 Maybe
<StyleSize
> mStyleISize
;
44 Maybe
<StyleSize
> mStyleBSize
;
45 Maybe
<AspectRatio
> mAspectRatio
;
47 bool HasAnyOverrides() const { return mStyleISize
|| mStyleBSize
; }
48 bool HasAnyLengthOverrides() const {
49 return (mStyleISize
&& mStyleISize
->ConvertsToLength()) ||
50 (mStyleBSize
&& mStyleBSize
->ConvertsToLength());
53 // By default, table wrapper frame considers the size overrides applied to
54 // itself, so it creates any length size overrides for inner table frame by
55 // subtracting the area occupied by the caption and border & padding according
58 // When this flag is true, table wrapper frame is required to apply the size
59 // overrides to the inner table frame directly, without any modification,
60 // which is useful for flex container to override the inner table frame's
61 // preferred main size with 'flex-basis'.
63 // Note: if mStyleISize is a LengthPercentage, the inner table frame will
64 // comply with the inline-size override without enforcing its min-content
65 // inline-size in nsTableFrame::ComputeSize(). This is necessary so that small
66 // flex-basis values like 'flex-basis:1%' can be resolved correctly; the
67 // flexbox layout algorithm does still explicitly clamp to min-sizes *at a
68 // later step*, after the flex-basis has been resolved -- so this flag won't
69 // actually produce any user-visible tables whose final inline size is smaller
70 // than their min-content inline size.
71 bool mApplyOverridesVerbatim
= false;
73 } // namespace mozilla
76 * @return aValue clamped to [aMinValue, aMaxValue].
78 * @note This function needs to handle aMinValue > aMaxValue. In that case,
79 * aMinValue is returned. That's why we cannot use std::clamp() and
80 * mozilla::clamped() since they both assert max >= min.
81 * @see http://www.w3.org/TR/CSS21/visudet.html#min-max-widths
82 * @see http://www.w3.org/TR/CSS21/visudet.html#min-max-heights
84 template <class NumericType
>
85 NumericType
NS_CSS_MINMAX(NumericType aValue
, NumericType aMinValue
,
86 NumericType aMaxValue
) {
87 NumericType result
= aValue
;
88 if (aMaxValue
< result
) result
= aMaxValue
;
89 if (aMinValue
> result
) result
= aMinValue
;
95 // A base class of ReflowInput that computes only the padding,
96 // border, and margin, since those values are needed more often.
97 struct SizeComputationInput
{
99 // The frame being reflowed.
100 nsIFrame
* const mFrame
;
102 // Rendering context to use for measurement.
103 gfxContext
* mRenderingContext
;
105 nsMargin
ComputedPhysicalMargin() const {
106 return mComputedMargin
.GetPhysicalMargin(mWritingMode
);
108 nsMargin
ComputedPhysicalBorderPadding() const {
109 return mComputedBorderPadding
.GetPhysicalMargin(mWritingMode
);
111 nsMargin
ComputedPhysicalPadding() const {
112 return mComputedPadding
.GetPhysicalMargin(mWritingMode
);
115 mozilla::LogicalMargin
ComputedLogicalMargin(mozilla::WritingMode aWM
) const {
116 return mComputedMargin
.ConvertTo(aWM
, mWritingMode
);
118 mozilla::LogicalMargin
ComputedLogicalBorderPadding(
119 mozilla::WritingMode aWM
) const {
120 return mComputedBorderPadding
.ConvertTo(aWM
, mWritingMode
);
122 mozilla::LogicalMargin
ComputedLogicalPadding(
123 mozilla::WritingMode aWM
) const {
124 return mComputedPadding
.ConvertTo(aWM
, mWritingMode
);
126 mozilla::LogicalMargin
ComputedLogicalBorder(mozilla::WritingMode aWM
) const {
127 return (mComputedBorderPadding
- mComputedPadding
)
128 .ConvertTo(aWM
, mWritingMode
);
131 void SetComputedLogicalMargin(mozilla::WritingMode aWM
,
132 const mozilla::LogicalMargin
& aMargin
) {
133 mComputedMargin
= aMargin
.ConvertTo(mWritingMode
, aWM
);
135 void SetComputedLogicalBorderPadding(
136 mozilla::WritingMode aWM
, const mozilla::LogicalMargin
& aBorderPadding
) {
137 mComputedBorderPadding
= aBorderPadding
.ConvertTo(mWritingMode
, aWM
);
139 void SetComputedLogicalPadding(mozilla::WritingMode aWM
,
140 const mozilla::LogicalMargin
& aPadding
) {
141 mComputedPadding
= aPadding
.ConvertTo(mWritingMode
, aWM
);
144 mozilla::WritingMode
GetWritingMode() const { return mWritingMode
; }
147 // cached copy of the frame's writing-mode, for logical coordinates
148 const mozilla::WritingMode mWritingMode
;
150 // Cached mFrame->IsThemed().
151 const bool mIsThemed
= false;
153 // Computed margin values
154 mozilla::LogicalMargin mComputedMargin
;
156 // Cached copy of the border + padding values
157 mozilla::LogicalMargin mComputedBorderPadding
;
159 // Computed padding values
160 mozilla::LogicalMargin mComputedPadding
;
163 // Callers using this constructor must call InitOffsets on their own.
164 SizeComputationInput(nsIFrame
* aFrame
, gfxContext
* aRenderingContext
);
166 SizeComputationInput(nsIFrame
* aFrame
, gfxContext
* aRenderingContext
,
167 mozilla::WritingMode aContainingBlockWritingMode
,
168 nscoord aContainingBlockISize
,
169 const mozilla::Maybe
<mozilla::LogicalMargin
>& aBorder
=
171 const mozilla::Maybe
<mozilla::LogicalMargin
>& aPadding
=
175 // Reflow trace methods. Defined in nsFrame.cpp so they have access
176 // to the display-reflow infrastructure.
177 static void* DisplayInitOffsetsEnter(nsIFrame
* aFrame
,
178 SizeComputationInput
* aState
,
179 nscoord aPercentBasis
,
180 mozilla::WritingMode aCBWritingMode
,
181 const nsMargin
* aBorder
,
182 const nsMargin
* aPadding
);
183 static void DisplayInitOffsetsExit(nsIFrame
* aFrame
,
184 SizeComputationInput
* aState
,
190 * Computes margin values from the specified margin style information, and
191 * fills in the mComputedMargin member.
193 * @param aCBWM Writing mode of the containing block
194 * @param aPercentBasis
195 * Inline size of the containing block (in its own writing mode), to use
196 * for resolving percentage margin values in the inline and block axes.
197 * @return true if the margin is dependent on the containing block size.
199 bool ComputeMargin(mozilla::WritingMode aCBWM
, nscoord aPercentBasis
,
200 mozilla::LayoutFrameType aFrameType
);
203 * Computes padding values from the specified padding style information, and
204 * fills in the mComputedPadding member.
206 * @param aCBWM Writing mode of the containing block
207 * @param aPercentBasis
208 * Inline size of the containing block (in its own writing mode), to use
209 * for resolving percentage padding values in the inline and block axes.
210 * @return true if the padding is dependent on the containing block size.
212 bool ComputePadding(mozilla::WritingMode aCBWM
, nscoord aPercentBasis
,
213 mozilla::LayoutFrameType aFrameType
);
216 void InitOffsets(mozilla::WritingMode aCBWM
, nscoord aPercentBasis
,
217 mozilla::LayoutFrameType aFrameType
,
218 mozilla::ComputeSizeFlags aFlags
,
219 const mozilla::Maybe
<mozilla::LogicalMargin
>& aBorder
,
220 const mozilla::Maybe
<mozilla::LogicalMargin
>& aPadding
,
221 const nsStyleDisplay
* aDisplay
= nullptr);
224 * Convert StyleSize or StyleMaxSize to nscoord when percentages depend on the
225 * inline size of the containing block, and enumerated values are for inline
226 * size, min-inline-size, or max-inline-size. Does not handle auto inline
229 template <typename SizeOrMaxSize
>
230 inline nscoord
ComputeISizeValue(const WritingMode aWM
,
231 const LogicalSize
& aContainingBlockSize
,
232 const LogicalSize
& aContentEdgeToBoxSizing
,
233 nscoord aBoxSizingToMarginEdge
,
234 const SizeOrMaxSize
&) const;
235 // same as previous, but using mComputedBorderPadding, mComputedPadding,
236 // and mComputedMargin
237 template <typename SizeOrMaxSize
>
238 inline nscoord
ComputeISizeValue(const LogicalSize
& aContainingBlockSize
,
239 mozilla::StyleBoxSizing aBoxSizing
,
240 const SizeOrMaxSize
&) const;
242 nscoord
ComputeBSizeValue(nscoord aContainingBlockBSize
,
243 mozilla::StyleBoxSizing aBoxSizing
,
244 const mozilla::LengthPercentage
& aCoord
) const;
248 * State passed to a frame during reflow or intrinsic size calculation.
250 * XXX Refactor so only a base class (nsSizingState?) is used for intrinsic
253 * @see nsIFrame#Reflow()
255 struct ReflowInput
: public SizeComputationInput
{
256 // the reflow inputs are linked together. this is the pointer to the
257 // parent's reflow input
258 const ReflowInput
* mParentReflowInput
= nullptr;
260 // A non-owning pointer to the float manager associated with this area,
261 // which points to the object owned by nsAutoFloatManager::mNew.
262 nsFloatManager
* mFloatManager
= nullptr;
264 // LineLayout object (only for inline reflow; set to nullptr otherwise)
265 nsLineLayout
* mLineLayout
= nullptr;
267 // The appropriate reflow input for the containing block (for
268 // percentage widths, etc.) of this reflow input's frame. It will be setup
269 // properly in InitCBReflowInput().
270 const ReflowInput
* mCBReflowInput
= nullptr;
272 // The amount the in-flow position of the block is moving vertically relative
273 // to its previous in-flow position (i.e. the amount the line containing the
275 // This should be zero for anything which is not a block outside, and it
276 // should be zero for anything which has a non-block parent.
277 // The intended use of this value is to allow the accurate determination
278 // of the potential impact of a float
279 // This takes on an arbitrary value the first time a block is reflowed
280 nscoord mBlockDelta
= 0;
282 // If a ReflowInput finds itself initialized with an unconstrained
283 // inline-size, it will look up its parentReflowInput chain for a reflow input
284 // with an orthogonal writing mode and a non-NS_UNCONSTRAINEDSIZE value for
285 // orthogonal limit; when it finds such a reflow input, it will use its
286 // orthogonal-limit value to constrain inline-size.
287 // This is initialized to NS_UNCONSTRAINEDSIZE (so it will be ignored),
288 // but reset to a suitable value for the reflow root by PresShell.
289 nscoord mOrthogonalLimit
= NS_UNCONSTRAINEDSIZE
;
291 // Physical accessors for the private fields. They are needed for
292 // compatibility with not-yet-updated code. New code should use the accessors
293 // for logical coordinates, unless the code really works on physical
295 nscoord
AvailableWidth() const { return mAvailableSize
.Width(mWritingMode
); }
296 nscoord
AvailableHeight() const {
297 return mAvailableSize
.Height(mWritingMode
);
299 nscoord
ComputedWidth() const { return mComputedSize
.Width(mWritingMode
); }
300 nscoord
ComputedHeight() const { return mComputedSize
.Height(mWritingMode
); }
301 nscoord
ComputedMinWidth() const {
302 return mComputedMinSize
.Width(mWritingMode
);
304 nscoord
ComputedMaxWidth() const {
305 return mComputedMaxSize
.Width(mWritingMode
);
307 nscoord
ComputedMinHeight() const {
308 return mComputedMinSize
.Height(mWritingMode
);
310 nscoord
ComputedMaxHeight() const {
311 return mComputedMaxSize
.Height(mWritingMode
);
314 // Logical accessors for private fields in mWritingMode.
315 nscoord
AvailableISize() const { return mAvailableSize
.ISize(mWritingMode
); }
316 nscoord
AvailableBSize() const { return mAvailableSize
.BSize(mWritingMode
); }
317 nscoord
ComputedISize() const { return mComputedSize
.ISize(mWritingMode
); }
318 nscoord
ComputedBSize() const { return mComputedSize
.BSize(mWritingMode
); }
319 nscoord
ComputedMinISize() const {
320 return mComputedMinSize
.ISize(mWritingMode
);
322 nscoord
ComputedMaxISize() const {
323 return mComputedMaxSize
.ISize(mWritingMode
);
325 nscoord
ComputedMinBSize() const {
326 return mComputedMinSize
.BSize(mWritingMode
);
328 nscoord
ComputedMaxBSize() const {
329 return mComputedMaxSize
.BSize(mWritingMode
);
332 // WARNING: In general, adjusting available inline-size or block-size is not
333 // safe because ReflowInput has members whose values depend on the available
334 // size passing through the constructor. For example,
335 // CalculateBlockSideMargins() is called during initialization, and uses
336 // AvailableSize(). Make sure your use case doesn't lead to stale member
337 // values in ReflowInput!
338 void SetAvailableISize(nscoord aAvailableISize
) {
339 mAvailableSize
.ISize(mWritingMode
) = aAvailableISize
;
341 void SetAvailableBSize(nscoord aAvailableBSize
) {
342 mAvailableSize
.BSize(mWritingMode
) = aAvailableBSize
;
345 void SetComputedMinISize(nscoord aMinISize
) {
346 mComputedMinSize
.ISize(mWritingMode
) = aMinISize
;
348 void SetComputedMaxISize(nscoord aMaxISize
) {
349 mComputedMaxSize
.ISize(mWritingMode
) = aMaxISize
;
351 void SetComputedMinBSize(nscoord aMinBSize
) {
352 mComputedMinSize
.BSize(mWritingMode
) = aMinBSize
;
354 void SetComputedMaxBSize(nscoord aMaxBSize
) {
355 mComputedMaxSize
.BSize(mWritingMode
) = aMaxBSize
;
357 void SetPercentageBasisInBlockAxis(nscoord aBSize
) {
358 mPercentageBasisInBlockAxis
= Some(aBSize
);
361 mozilla::LogicalSize
AvailableSize() const { return mAvailableSize
; }
362 mozilla::LogicalSize
ComputedSize() const { return mComputedSize
; }
363 mozilla::LogicalSize
ComputedMinSize() const { return mComputedMinSize
; }
364 mozilla::LogicalSize
ComputedMaxSize() const { return mComputedMaxSize
; }
366 mozilla::LogicalSize
AvailableSize(mozilla::WritingMode aWM
) const {
367 return AvailableSize().ConvertTo(aWM
, mWritingMode
);
369 mozilla::LogicalSize
ComputedSize(mozilla::WritingMode aWM
) const {
370 return ComputedSize().ConvertTo(aWM
, mWritingMode
);
372 mozilla::LogicalSize
ComputedMinSize(mozilla::WritingMode aWM
) const {
373 return ComputedMinSize().ConvertTo(aWM
, mWritingMode
);
375 mozilla::LogicalSize
ComputedMaxSize(mozilla::WritingMode aWM
) const {
376 return ComputedMaxSize().ConvertTo(aWM
, mWritingMode
);
379 mozilla::LogicalSize
ComputedSizeWithPadding(mozilla::WritingMode aWM
) const {
380 return ComputedSize(aWM
) + ComputedLogicalPadding(aWM
).Size(aWM
);
383 mozilla::LogicalSize
ComputedSizeWithBorderPadding(
384 mozilla::WritingMode aWM
) const {
385 return ComputedSize(aWM
) + ComputedLogicalBorderPadding(aWM
).Size(aWM
);
388 mozilla::LogicalSize
ComputedSizeWithMarginBorderPadding(
389 mozilla::WritingMode aWM
) const {
390 return ComputedSizeWithBorderPadding(aWM
) +
391 ComputedLogicalMargin(aWM
).Size(aWM
);
394 nsSize
ComputedPhysicalSize() const {
395 return nsSize(ComputedWidth(), ComputedHeight());
398 nsMargin
ComputedPhysicalOffsets() const {
399 return mComputedOffsets
.GetPhysicalMargin(mWritingMode
);
402 LogicalMargin
ComputedLogicalOffsets(mozilla::WritingMode aWM
) const {
403 return mComputedOffsets
.ConvertTo(aWM
, mWritingMode
);
406 void SetComputedLogicalOffsets(mozilla::WritingMode aWM
,
407 const LogicalMargin
& aOffsets
) {
408 mComputedOffsets
= aOffsets
.ConvertTo(mWritingMode
, aWM
);
411 // Return ReflowInput's computed size including border-padding, with
412 // unconstrained dimensions replaced by zero.
413 nsSize
ComputedSizeAsContainerIfConstrained() const {
414 const nscoord wd
= ComputedWidth();
415 const nscoord ht
= ComputedHeight();
416 return nsSize(wd
== NS_UNCONSTRAINEDSIZE
418 : wd
+ ComputedPhysicalBorderPadding().LeftRight(),
419 ht
== NS_UNCONSTRAINEDSIZE
421 : ht
+ ComputedPhysicalBorderPadding().TopBottom());
424 // Our saved containing block dimensions.
425 LogicalSize mContainingBlockSize
{mWritingMode
};
427 // Cached pointers to the various style structs used during initialization.
428 const nsStyleDisplay
* mStyleDisplay
= nullptr;
429 const nsStylePosition
* mStylePosition
= nullptr;
430 const nsStyleBorder
* mStyleBorder
= nullptr;
431 const nsStyleMargin
* mStyleMargin
= nullptr;
433 enum class BreakType
: uint8_t {
438 BreakType mBreakType
= BreakType::Auto
;
440 // a frame (e.g. nsTableCellFrame) which may need to generate a special
441 // reflow for percent bsize calculations
442 nsIPercentBSizeObserver
* mPercentBSizeObserver
= nullptr;
444 // CSS margin collapsing sometimes requires us to reflow
445 // optimistically assuming that margins collapse to see if clearance
446 // is required. When we discover that clearance is required, we
447 // store the frame in which clearance was discovered to the location
449 nsIFrame
** mDiscoveredClearance
= nullptr;
452 Flags() { memset(this, 0, sizeof(*this)); }
454 // cached mFrame->IsReplaced() || mFrame->IsReplacedWithBlock()
455 bool mIsReplaced
: 1;
457 // used by tables to communicate special reflow (in process) to handle
458 // percent bsize frames inside cells which may not have computed bsizes
459 bool mSpecialBSizeReflow
: 1;
461 // nothing in the frame's next-in-flow (or its descendants) is changing
462 bool mNextInFlowUntouched
: 1;
464 // Is the current context at the top of a page? When true, we force
465 // something that's too tall for a page/column to fit anyway to avoid
467 bool mIsTopOfPage
: 1;
469 // parent frame is an nsIScrollableFrame and it is assuming a horizontal
471 bool mAssumingHScrollbar
: 1;
473 // parent frame is an nsIScrollableFrame and it is assuming a vertical
475 bool mAssumingVScrollbar
: 1;
477 // Is frame a different inline-size than before?
480 // Is frame (potentially) a different block-size than before?
481 // This includes cases where the block-size is 'auto' and the
482 // contents or width have changed.
485 // Has this frame changed block-size in a way that affects
486 // block-size percentages on frames for which it is the containing
487 // block? This includes a change between 'auto' and a length that
488 // doesn't actually change the frame's block-size. It does not
489 // include cases where the block-size is 'auto' and the frame's
490 // contents have changed.
492 // In the current code, this is only true when mIsBResize is also
493 // true, although it doesn't necessarily need to be that way (e.g.,
494 // in the case of a frame changing from 'auto' to a length that
495 // produces the same height).
496 bool mIsBResizeForPercentages
: 1;
498 // tables are splittable, this should happen only inside a page and never
499 // insider a column frame
500 bool mTableIsSplittable
: 1;
502 // Does frame height depend on an ancestor table-cell?
503 bool mHeightDependsOnAncestorCell
: 1;
505 // nsColumnSetFrame is balancing columns
506 bool mIsColumnBalancing
: 1;
508 // We have an ancestor nsColumnSetFrame performing the last column balancing
509 // reflow. The available block-size of the last column might become
511 bool mIsInLastColumnBalancingReflow
: 1;
513 // True if ColumnSetWrapperFrame has a constrained block-size, and is going
514 // to consume all of its block-size in this fragment. This bit is passed to
515 // nsColumnSetFrame to determine whether to give up balancing and create
517 bool mColumnSetWrapperHasNoBSizeLeft
: 1;
519 // If this flag is set, the BSize of this frame should be considered
520 // indefinite for the purposes of percent resolution on child frames (we
521 // should behave as if ComputedBSize() were NS_UNCONSTRAINEDSIZE when doing
522 // percent resolution against this.ComputedBSize()). For example: flex
523 // items may have their ComputedBSize() resolved ahead-of-time by their
524 // flex container, and yet their BSize might have to be considered
525 // indefinite per https://drafts.csswg.org/css-flexbox/#definite-sizes
526 bool mTreatBSizeAsIndefinite
: 1;
528 // a "fake" reflow input made in order to be the parent of a real one
529 bool mDummyParentReflowInput
: 1;
531 // Should this frame reflow its place-holder children? If the available
532 // height of this frame didn't change, but its in a paginated environment
533 // (e.g. columns), it should always reflow its placeholder children.
534 bool mMustReflowPlaceholders
: 1;
536 // the STATIC_POS_IS_CB_ORIGIN ctor flag
537 bool mStaticPosIsCBOrigin
: 1;
539 // If set, the following two flags indicate that:
540 // (1) this frame is absolutely-positioned (or fixed-positioned).
541 // (2) this frame's static position depends on the CSS Box Alignment.
542 // (3) we do need to compute the static position, because the frame's
543 // {Inline and/or Block} offsets actually depend on it.
544 // When these bits are set, the offset values (IStart/IEnd, BStart/BEnd)
545 // represent the "start" edge of the frame's CSS Box Alignment container
546 // area, in that axis -- and these offsets need to be further-resolved
547 // (with CSS Box Alignment) after we know the OOF frame's size.
548 // NOTE: The "I" and "B" (for "Inline" and "Block") refer the axes of the
549 // *containing block's writing-mode*, NOT mFrame's own writing-mode. This
550 // is purely for convenience, since that's the writing-mode we're dealing
551 // with when we set & react to these bits.
552 bool mIOffsetsNeedCSSAlign
: 1;
553 bool mBOffsetsNeedCSSAlign
: 1;
555 // Is this frame or one of its ancestors being reflowed in a different
556 // continuation than the one in which it was previously reflowed? In
557 // other words, has it moved to a different column or page than it was in
558 // the previous reflow?
560 // FIXME: For now, we only ensure that this is set correctly for blocks.
561 // This is okay because the only thing that uses it only cares about
562 // whether there's been a fragment change within the same block formatting
564 bool mMovedBlockFragments
: 1;
566 // Is the block-size computed by aspect-ratio and inline size (i.e. block
567 // axis is the ratio-dependent axis)? We set this flag so that we can check
568 // whether to apply automatic content-based minimum sizes once we know the
569 // children's block-size (after reflowing them).
570 // https://drafts.csswg.org/css-sizing-4/#aspect-ratio-minimum
571 bool mIsBSizeSetByAspectRatio
: 1;
573 // If true, then children of this frame can generate class A breakpoints
574 // for paginated reflow.
575 bool mCanHaveClassABreakpoints
: 1;
579 mozilla::StyleSizeOverrides mStyleSizeOverrides
;
581 mozilla::ComputeSizeFlags mComputeSizeFlags
;
583 // This value keeps track of how deeply nested a given reflow input
584 // is from the top of the frame tree.
585 int16_t mReflowDepth
= 0;
587 // Logical and physical accessors for the resize flags.
588 bool IsHResize() const {
589 return mWritingMode
.IsVertical() ? mFlags
.mIsBResize
: mFlags
.mIsIResize
;
591 bool IsVResize() const {
592 return mWritingMode
.IsVertical() ? mFlags
.mIsIResize
: mFlags
.mIsBResize
;
594 bool IsIResize() const { return mFlags
.mIsIResize
; }
595 bool IsBResize() const { return mFlags
.mIsBResize
; }
596 bool IsBResizeForWM(mozilla::WritingMode aWM
) const {
597 return aWM
.IsOrthogonalTo(mWritingMode
) ? mFlags
.mIsIResize
600 bool IsBResizeForPercentagesForWM(mozilla::WritingMode aWM
) const {
601 // This uses the relatively-accurate mIsBResizeForPercentages flag
602 // when the writing modes are parallel, and is a bit more
603 // pessimistic when orthogonal.
604 return !aWM
.IsOrthogonalTo(mWritingMode
) ? mFlags
.mIsBResizeForPercentages
607 void SetHResize(bool aValue
) {
608 if (mWritingMode
.IsVertical()) {
609 mFlags
.mIsBResize
= aValue
;
611 mFlags
.mIsIResize
= aValue
;
614 void SetVResize(bool aValue
) {
615 if (mWritingMode
.IsVertical()) {
616 mFlags
.mIsIResize
= aValue
;
618 mFlags
.mIsBResize
= aValue
;
621 void SetIResize(bool aValue
) { mFlags
.mIsIResize
= aValue
; }
622 void SetBResize(bool aValue
) { mFlags
.mIsBResize
= aValue
; }
624 // Values for |aFlags| passed to constructor
625 enum class InitFlag
: uint8_t {
626 // Indicates that the parent of this reflow input is "fake" (see
627 // mDummyParentReflowInput in mFlags).
628 DummyParentReflowInput
,
630 // Indicates that the calling function will initialize the reflow input, and
631 // that the constructor should not call Init().
634 // The caller wants the abs.pos. static-position resolved at the origin of
635 // the containing block, i.e. at LogicalPoint(0, 0). (Note that this
636 // doesn't necessarily mean that (0, 0) is the *correct* static position
637 // for the frame in question.)
638 // @note In a Grid container's masonry axis we'll always use
639 // the placeholder's position in that axis regardless of this flag.
642 using InitFlags
= mozilla::EnumSet
<InitFlag
>;
644 // Note: The copy constructor is written by the compiler automatically. You
645 // can use that and then override specific values if you want, or you can
646 // call Init as desired...
649 * Initialize a ROOT reflow input.
651 * @param aPresContext Must be equal to aFrame->PresContext().
652 * @param aFrame The frame for whose reflow input is being constructed.
653 * @param aRenderingContext The rendering context to be used for measurements.
654 * @param aAvailableSpace The available space to reflow aFrame (in aFrame's
655 * writing-mode). See comments for mAvailableSize for more information.
656 * @param aFlags A set of flags used for additional boolean parameters (see
659 ReflowInput(nsPresContext
* aPresContext
, nsIFrame
* aFrame
,
660 gfxContext
* aRenderingContext
,
661 const mozilla::LogicalSize
& aAvailableSpace
,
662 InitFlags aFlags
= {});
665 * Initialize a reflow input for a child frame's reflow. Some parts of the
666 * state are copied from the parent's reflow input. The remainder is computed.
668 * @param aPresContext Must be equal to aFrame->PresContext().
669 * @param aParentReflowInput A reference to an ReflowInput object that
670 * is to be the parent of this object.
671 * @param aFrame The frame for whose reflow input is being constructed.
672 * @param aAvailableSpace The available space to reflow aFrame (in aFrame's
673 * writing-mode). See comments for mAvailableSize for more information.
674 * @param aContainingBlockSize An optional size (in aFrame's writing mode),
675 * specifying the containing block size to use instead of the default
676 * size computed by ComputeContainingBlockRectangle(). If
677 * InitFlag::CallerWillInit is used, this is ignored. Pass it via
679 * @param aFlags A set of flags used for additional boolean parameters (see
681 * @param aStyleSizeOverrides The style data used to override mFrame's when we
682 * call nsIFrame::ComputeSize() internally.
683 * @param aComputeSizeFlags A set of flags used when we call
684 * nsIFrame::ComputeSize() internally.
686 ReflowInput(nsPresContext
* aPresContext
,
687 const ReflowInput
& aParentReflowInput
, nsIFrame
* aFrame
,
688 const mozilla::LogicalSize
& aAvailableSpace
,
689 const mozilla::Maybe
<mozilla::LogicalSize
>& aContainingBlockSize
=
691 InitFlags aFlags
= {},
692 const mozilla::StyleSizeOverrides
& aSizeOverrides
= {},
693 mozilla::ComputeSizeFlags aComputeSizeFlags
= {});
696 * This method initializes various data members. It is automatically called by
697 * the constructors if InitFlags::CallerWillInit is *not* used.
699 * @param aContainingBlockSize An optional size (in mFrame's writing mode),
700 * specifying the containing block size to use instead of the default
701 * size computed by ComputeContainingBlockRectangle().
702 * @param aBorder An optional border (in mFrame's writing mode). If given, use
703 * it instead of the border computed from mFrame's StyleBorder.
704 * @param aPadding An optional padding (in mFrame's writing mode). If given,
705 * use it instead of the padding computing from mFrame's StylePadding.
707 void Init(nsPresContext
* aPresContext
,
708 const mozilla::Maybe
<mozilla::LogicalSize
>& aContainingBlockSize
=
710 const mozilla::Maybe
<mozilla::LogicalMargin
>& aBorder
=
712 const mozilla::Maybe
<mozilla::LogicalMargin
>& aPadding
=
716 * Get the used line-height property. The return value will be >= 0.
718 nscoord
GetLineHeight() const;
721 * Set the used line-height. aLineHeight must be >= 0.
723 void SetLineHeight(nscoord aLineHeight
);
726 * Calculate the used line-height property without a reflow input instance.
727 * The return value will be >= 0.
729 * @param aBlockBSize The computed block size of the content rect of the block
730 * that the line should fill. Only used with
731 * line-height:-moz-block-height. NS_UNCONSTRAINEDSIZE
732 * results in a normal line-height for
733 * line-height:-moz-block-height.
734 * @param aFontSizeInflation The result of the appropriate
735 * nsLayoutUtils::FontSizeInflationFor call,
736 * or 1.0 if during intrinsic size
739 static nscoord
CalcLineHeight(const ComputedStyle
&,
740 nsPresContext
* aPresContext
,
741 const nsIContent
* aContent
, nscoord aBlockBSize
,
742 float aFontSizeInflation
);
744 static nscoord
CalcLineHeight(const StyleLineHeight
&,
745 const nsStyleFont
& aRelativeToFont
,
746 nsPresContext
* aPresContext
, bool aIsVertical
,
747 const nsIContent
* aContent
, nscoord aBlockBSize
,
748 float aFontSizeInflation
);
750 mozilla::LogicalSize
ComputeContainingBlockRectangle(
751 nsPresContext
* aPresContext
, const ReflowInput
* aContainingBlockRI
) const;
754 * Apply the mComputed(Min/Max)Width constraints to the content
755 * size computed so far.
757 nscoord
ApplyMinMaxWidth(nscoord aWidth
) const {
758 if (NS_UNCONSTRAINEDSIZE
!= ComputedMaxWidth()) {
759 aWidth
= std::min(aWidth
, ComputedMaxWidth());
761 return std::max(aWidth
, ComputedMinWidth());
765 * Apply the mComputed(Min/Max)ISize constraints to the content
766 * size computed so far.
768 nscoord
ApplyMinMaxISize(nscoord aISize
) const {
769 if (NS_UNCONSTRAINEDSIZE
!= ComputedMaxISize()) {
770 aISize
= std::min(aISize
, ComputedMaxISize());
772 return std::max(aISize
, ComputedMinISize());
776 * Apply the mComputed(Min/Max)Height constraints to the content
777 * size computed so far.
779 * @param aHeight The height that we've computed an to which we want to apply
780 * min/max constraints.
781 * @param aConsumed The amount of the computed height that was consumed by
784 nscoord
ApplyMinMaxHeight(nscoord aHeight
, nscoord aConsumed
= 0) const {
785 aHeight
+= aConsumed
;
787 if (NS_UNCONSTRAINEDSIZE
!= ComputedMaxHeight()) {
788 aHeight
= std::min(aHeight
, ComputedMaxHeight());
791 if (NS_UNCONSTRAINEDSIZE
!= ComputedMinHeight()) {
792 aHeight
= std::max(aHeight
, ComputedMinHeight());
795 return aHeight
- aConsumed
;
799 * Apply the mComputed(Min/Max)BSize constraints to the content
800 * size computed so far.
802 * @param aBSize The block-size that we've computed an to which we want to
803 * apply min/max constraints.
804 * @param aConsumed The amount of the computed block-size that was consumed by
807 nscoord
ApplyMinMaxBSize(nscoord aBSize
, nscoord aConsumed
= 0) const {
810 if (NS_UNCONSTRAINEDSIZE
!= ComputedMaxBSize()) {
811 aBSize
= std::min(aBSize
, ComputedMaxBSize());
814 if (NS_UNCONSTRAINEDSIZE
!= ComputedMinBSize()) {
815 aBSize
= std::max(aBSize
, ComputedMinBSize());
818 return aBSize
- aConsumed
;
821 bool ShouldReflowAllKids() const;
823 // This method doesn't apply min/max computed widths to the value passed in.
824 void SetComputedWidth(nscoord aComputedWidth
) {
825 if (mWritingMode
.IsVertical()) {
826 SetComputedBSize(aComputedWidth
);
828 SetComputedISize(aComputedWidth
);
832 // This method doesn't apply min/max computed heights to the value passed in.
833 void SetComputedHeight(nscoord aComputedHeight
) {
834 if (mWritingMode
.IsVertical()) {
835 SetComputedISize(aComputedHeight
);
837 SetComputedBSize(aComputedHeight
);
841 // Use "No" to request SetComputedISize/SetComputedBSize not to reset resize
843 enum class ResetResizeFlags
: bool { No
, Yes
};
845 // This method doesn't apply min/max computed inline-sizes to the value passed
847 void SetComputedISize(nscoord aComputedISize
,
848 ResetResizeFlags aFlags
= ResetResizeFlags::Yes
);
850 // These methods don't apply min/max computed block-sizes to the value passed
852 void SetComputedBSize(nscoord aComputedBSize
,
853 ResetResizeFlags aFlags
= ResetResizeFlags::Yes
);
855 bool WillReflowAgainForClearance() const {
856 return mDiscoveredClearance
&& *mDiscoveredClearance
;
859 // Returns true if we should apply automatic minimum on the block axis.
861 // The automatic minimum size in the ratio-dependent axis of a box with a
862 // preferred aspect ratio that is neither a replaced element nor a scroll
863 // container is its min-content size clamped from above by its maximum size.
865 // https://drafts.csswg.org/css-sizing-4/#aspect-ratio-minimum
866 bool ShouldApplyAutomaticMinimumOnBlockAxis() const;
868 // Returns true if mFrame has a constrained available block-size, or if mFrame
869 // is a continuation. When this method returns true, mFrame can be considered
870 // to be in a "fragmented context."
872 // Note: this method usually returns true when mFrame is in a paged
873 // environment (e.g. printing) or has a multi-column container ancestor.
874 // However, this doesn't include several cases when we're intentionally
875 // performing layout in a fragmentation-ignoring way, e.g. 1) mFrame is a flex
876 // or grid item, and this ReflowInput is for a measuring reflow with an
877 // unconstrained available block-size, or 2) mFrame is (or is inside of) an
878 // element that forms an orthogonal writing-mode.
879 bool IsInFragmentedContext() const;
881 // Compute the offsets for a relative position element
883 // @param aWM the writing mode of aCBSize and the returned offsets.
884 static mozilla::LogicalMargin
ComputeRelativeOffsets(
885 mozilla::WritingMode aWM
, nsIFrame
* aFrame
,
886 const mozilla::LogicalSize
& aCBSize
);
888 // If aFrame is a relatively or sticky positioned element, adjust aPosition
891 // @param aComputedOffsets aFrame's relative offset, either from the cached
892 // nsIFrame::ComputedOffsetProperty() or ComputedPhysicalOffsets().
893 // Note: This parameter is used only when aFrame is relatively
894 // positioned, not sticky positioned.
895 // @param aPosition [in/out] Pass aFrame's normal position (pre-relative
896 // positioning), and this method will update it to indicate aFrame's
898 static void ApplyRelativePositioning(nsIFrame
* aFrame
,
899 const nsMargin
& aComputedOffsets
,
902 static void ApplyRelativePositioning(
903 nsIFrame
* aFrame
, mozilla::WritingMode aWritingMode
,
904 const mozilla::LogicalMargin
& aComputedOffsets
,
905 mozilla::LogicalPoint
* aPosition
, const nsSize
& aContainerSize
);
907 // Resolve any block-axis 'auto' margins (if any) for an absolutely positioned
908 // frame. aMargin and aOffsets are both outparams (though we only touch
909 // aOffsets if the position is overconstrained)
910 static void ComputeAbsPosBlockAutoMargin(nscoord aAvailMarginSpace
,
911 WritingMode aContainingBlockWM
,
912 bool aIsMarginBStartAuto
,
913 bool aIsMarginBEndAuto
,
914 LogicalMargin
& aMargin
,
915 LogicalMargin
& aOffsets
);
917 // Resolve any inline-axis 'auto' margins (if any) for an absolutely
918 // positioned frame. aMargin and aOffsets are both outparams (though we only
919 // touch aOffsets if the position is overconstrained)
920 static void ComputeAbsPosInlineAutoMargin(nscoord aAvailMarginSpace
,
921 WritingMode aContainingBlockWM
,
922 bool aIsMarginIStartAuto
,
923 bool aIsMarginIEndAuto
,
924 LogicalMargin
& aMargin
,
925 LogicalMargin
& aOffsets
);
928 // Reflow trace methods. Defined in nsFrame.cpp so they have access
929 // to the display-reflow infrastructure.
930 static void* DisplayInitConstraintsEnter(nsIFrame
* aFrame
,
932 nscoord aCBISize
, nscoord aCBBSize
,
933 const nsMargin
* aBorder
,
934 const nsMargin
* aPadding
);
935 static void DisplayInitConstraintsExit(nsIFrame
* aFrame
, ReflowInput
* aState
,
937 static void* DisplayInitFrameTypeEnter(nsIFrame
* aFrame
, ReflowInput
* aState
);
938 static void DisplayInitFrameTypeExit(nsIFrame
* aFrame
, ReflowInput
* aState
,
943 void InitCBReflowInput();
944 void InitResizeFlags(nsPresContext
* aPresContext
,
945 mozilla::LayoutFrameType aFrameType
);
946 void InitDynamicReflowRoot();
948 void InitConstraints(
949 nsPresContext
* aPresContext
,
950 const mozilla::Maybe
<mozilla::LogicalSize
>& aContainingBlockSize
,
951 const mozilla::Maybe
<mozilla::LogicalMargin
>& aBorder
,
952 const mozilla::Maybe
<mozilla::LogicalMargin
>& aPadding
,
953 mozilla::LayoutFrameType aFrameType
);
955 // Returns the nearest containing block or block frame (whether or not
956 // it is a containing block) for the specified frame. Also returns
957 // the inline-start edge and logical size of the containing block's
959 // These are returned in the coordinate space of the containing block.
960 nsIFrame
* GetHypotheticalBoxContainer(nsIFrame
* aFrame
,
961 nscoord
& aCBIStartEdge
,
962 mozilla::LogicalSize
& aCBSize
) const;
964 // Calculate a "hypothetical box" position where the placeholder frame
965 // (for a position:fixed/absolute element) would have been placed if it were
966 // positioned statically. The hypothetical box position will have a writing
967 // mode with the same block direction as the absolute containing block
968 // (aCBReflowInput->frame), though it may differ in inline direction.
969 void CalculateHypotheticalPosition(nsPresContext
* aPresContext
,
970 nsPlaceholderFrame
* aPlaceholderFrame
,
971 const ReflowInput
* aCBReflowInput
,
972 nsHypotheticalPosition
& aHypotheticalPos
,
973 mozilla::LayoutFrameType aFrameType
) const;
975 // Check if we can use the resolved auto block size (by insets) to compute
976 // the inline size through aspect-ratio on absolute-positioned elements.
977 // This is only needed for non-replaced elements.
978 // https://drafts.csswg.org/css-position/#abspos-auto-size
979 bool IsInlineSizeComputableByBlockSizeAndAspectRatio(
980 nscoord aBlockSize
) const;
982 // This calculates the size by using the resolved auto block size (from
983 // non-auto block insets), according to the writing mode of current block.
984 LogicalSize
CalculateAbsoluteSizeWithResolvedAutoBlockSize(
985 nscoord aAutoBSize
, const LogicalSize
& aTentativeComputedSize
);
987 void InitAbsoluteConstraints(nsPresContext
* aPresContext
,
988 const ReflowInput
* aCBReflowInput
,
989 const mozilla::LogicalSize
& aContainingBlockSize
,
990 mozilla::LayoutFrameType aFrameType
);
992 // Calculates the computed values for the 'min-inline-size',
993 // 'max-inline-size', 'min-block-size', and 'max-block-size' properties, and
994 // stores them in the assorted data members
995 void ComputeMinMaxValues(const mozilla::LogicalSize
& aCBSize
);
997 // aInsideBoxSizing returns the part of the padding, border, and margin
998 // in the aAxis dimension that goes inside the edge given by box-sizing;
999 // aOutsideBoxSizing returns the rest.
1000 void CalculateBorderPaddingMargin(mozilla::LogicalAxis aAxis
,
1001 nscoord aContainingBlockSize
,
1002 nscoord
* aInsideBoxSizing
,
1003 nscoord
* aOutsideBoxSizing
) const;
1005 void CalculateBlockSideMargins();
1008 * @return true if mFrame is an internal table frame, i.e. an
1009 * ns[RowGroup|ColGroup|Row|Cell]Frame. (We exclude nsTableColFrame
1010 * here since we never setup a ReflowInput for those.)
1012 bool IsInternalTableFrame() const;
1015 // The available size in which to reflow the frame. The space represents the
1016 // amount of room for the frame's margin, border, padding, and content area.
1018 // The available inline-size should be constrained. The frame's inline-size
1019 // you choose should fit within it.
1021 // In galley mode, the available block-size is always unconstrained, and only
1022 // page mode or multi-column layout involves a constrained available
1025 // An unconstrained available block-size means you can choose whatever size
1026 // you want. If the value is constrained, the frame's block-start border,
1027 // padding, and content, must fit. If a frame is fully-complete after reflow,
1028 // then its block-end border, padding, and margin (and similar for its
1029 // fully-complete ancestors) will need to fit within this available
1030 // block-size. However, if a frame is monolithic, it may choose a block-size
1031 // larger than the available block-size.
1032 mozilla::LogicalSize mAvailableSize
{mWritingMode
};
1034 // The computed size specifies the frame's content area, and it does not apply
1035 // to inline non-replaced elements.
1037 // For block-level frames, the computed inline-size is based on the
1038 // inline-size of the containing block, the margin/border/padding areas, and
1039 // the min/max inline-size.
1041 // For non-replaced block-level frames in the flow and floated, if the
1042 // computed block-size is NS_UNCONSTRAINEDSIZE, you should choose a block-size
1043 // to shrink wrap around the normal flow child frames. The block-size must be
1044 // within the limit of the min/max block-size if there is such a limit.
1045 mozilla::LogicalSize mComputedSize
{mWritingMode
};
1047 // Computed values for 'inset' properties. Only applies to 'positioned'
1049 mozilla::LogicalMargin mComputedOffsets
{mWritingMode
};
1051 // Computed value for 'min-inline-size'/'min-block-size'.
1052 mozilla::LogicalSize mComputedMinSize
{mWritingMode
};
1054 // Computed value for 'max-inline-size'/'max-block-size'.
1055 mozilla::LogicalSize mComputedMaxSize
{mWritingMode
, NS_UNCONSTRAINEDSIZE
,
1056 NS_UNCONSTRAINEDSIZE
};
1058 // Percentage basis in the block axis for the purpose of percentage resolution
1061 // This will be ignored when mTreatBSizeAsIndefinite flag is true, or when a
1062 // customized containing block size is provided via ReflowInput's constructor
1063 // or Init(). When this percentage basis exists, it will be used to replace
1064 // the containing block's ComputedBSize() in
1065 // ComputeContainingBlockRectangle().
1067 // This is currently used in a special scenario where we treat certain
1068 // sized-to-content flex items as having an 'auto' block-size for their final
1069 // reflow to accomodate fragmentation-imposed block-size growth. This sort of
1070 // flex item does nonetheless have a known block-size (from the flex layout
1071 // algorithm) that it needs to use as a definite percentage-basis for its
1072 // children during its final reflow; and we represent that here.
1073 Maybe
<nscoord
> mPercentageBasisInBlockAxis
;
1075 // Cache the used line-height property.
1076 mutable nscoord mLineHeight
= NS_UNCONSTRAINEDSIZE
;
1079 } // namespace mozilla
1081 #endif // mozilla_ReflowInput_h