1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /* struct containing the input to nsIFrame::Reflow */
8 #ifndef nsHTMLReflowState_h___
9 #define nsHTMLReflowState_h___
12 #include "nsStyleCoord.h"
14 #include "mozilla/Assertions.h"
18 class nsRenderingContext
;
21 class nsIPercentHeightObserver
;
22 struct nsHypotheticalBox
;
25 * @return aValue clamped to [aMinValue, aMaxValue].
27 * @note This function needs to handle aMinValue > aMaxValue. In that case,
28 * aMinValue is returned.
29 * @see http://www.w3.org/TR/CSS21/visudet.html#min-max-widths
30 * @see http://www.w3.org/TR/CSS21/visudet.html#min-max-heights
32 template <class NumericType
>
34 NS_CSS_MINMAX(NumericType aValue
, NumericType aMinValue
, NumericType aMaxValue
)
36 NumericType result
= aValue
;
37 if (aMaxValue
< result
)
39 if (aMinValue
> result
)
45 * CSS Frame type. Included as part of the reflow state.
47 typedef uint32_t nsCSSFrameType
;
49 #define NS_CSS_FRAME_TYPE_UNKNOWN 0
50 #define NS_CSS_FRAME_TYPE_INLINE 1
51 #define NS_CSS_FRAME_TYPE_BLOCK 2 /* block-level in normal flow */
52 #define NS_CSS_FRAME_TYPE_FLOATING 3
53 #define NS_CSS_FRAME_TYPE_ABSOLUTE 4
54 #define NS_CSS_FRAME_TYPE_INTERNAL_TABLE 5 /* row group frame, row frame, cell frame, ... */
57 * Bit-flag that indicates whether the element is replaced. Applies to inline,
58 * block-level, floating, and absolutely positioned elements
60 #define NS_CSS_FRAME_TYPE_REPLACED 0x08000
63 * Bit-flag that indicates that the element is replaced and contains a block
64 * (eg some form controls). Applies to inline, block-level, floating, and
65 * absolutely positioned elements. Mutually exclusive with
66 * NS_CSS_FRAME_TYPE_REPLACED.
68 #define NS_CSS_FRAME_TYPE_REPLACED_CONTAINS_BLOCK 0x10000
71 * Helper macros for telling whether items are replaced
73 #define NS_FRAME_IS_REPLACED_NOBLOCK(_ft) \
74 (NS_CSS_FRAME_TYPE_REPLACED == ((_ft) & NS_CSS_FRAME_TYPE_REPLACED))
76 #define NS_FRAME_IS_REPLACED(_ft) \
77 (NS_FRAME_IS_REPLACED_NOBLOCK(_ft) || \
78 NS_FRAME_IS_REPLACED_CONTAINS_BLOCK(_ft))
80 #define NS_FRAME_REPLACED(_ft) \
81 (NS_CSS_FRAME_TYPE_REPLACED | (_ft))
83 #define NS_FRAME_IS_REPLACED_CONTAINS_BLOCK(_ft) \
84 (NS_CSS_FRAME_TYPE_REPLACED_CONTAINS_BLOCK == \
85 ((_ft) & NS_CSS_FRAME_TYPE_REPLACED_CONTAINS_BLOCK))
87 #define NS_FRAME_REPLACED_CONTAINS_BLOCK(_ft) \
88 (NS_CSS_FRAME_TYPE_REPLACED_CONTAINS_BLOCK | (_ft))
91 * A macro to extract the type. Masks off the 'replaced' bit-flag
93 #define NS_FRAME_GET_TYPE(_ft) \
94 ((_ft) & ~(NS_CSS_FRAME_TYPE_REPLACED | \
95 NS_CSS_FRAME_TYPE_REPLACED_CONTAINS_BLOCK))
97 // A base class of nsHTMLReflowState that computes only the padding,
98 // border, and margin, since those values are needed more often.
99 struct nsCSSOffsetState
{
101 typedef mozilla::WritingMode WritingMode
;
102 typedef mozilla::LogicalMargin LogicalMargin
;
104 // the frame being reflowed
107 // rendering context to use for measurement
108 nsRenderingContext
* rendContext
;
110 const nsMargin
& ComputedPhysicalMargin() const { return mComputedMargin
; }
111 const nsMargin
& ComputedPhysicalBorderPadding() const { return mComputedBorderPadding
; }
112 const nsMargin
& ComputedPhysicalPadding() const { return mComputedPadding
; }
114 // We may need to eliminate the (few) users of these writable-reference accessors
115 // as part of migrating to logical coordinates.
116 nsMargin
& ComputedPhysicalMargin() { return mComputedMargin
; }
117 nsMargin
& ComputedPhysicalBorderPadding() { return mComputedBorderPadding
; }
118 nsMargin
& ComputedPhysicalPadding() { return mComputedPadding
; }
120 LogicalMargin
ComputedLogicalMargin() const
121 { return LogicalMargin(mWritingMode
, mComputedMargin
); }
122 LogicalMargin
ComputedLogicalBorderPadding() const
123 { return LogicalMargin(mWritingMode
, mComputedBorderPadding
); }
124 LogicalMargin
ComputedLogicalPadding() const
125 { return LogicalMargin(mWritingMode
, mComputedPadding
); }
127 WritingMode
GetWritingMode() const { return mWritingMode
; }
130 // cached copy of the frame's writing-mode, for logical coordinates
131 WritingMode mWritingMode
;
133 // These are PHYSICAL coordinates (for now).
134 // Will probably become logical in due course.
136 // Computed margin values
137 nsMargin mComputedMargin
;
139 // Cached copy of the border + padding values
140 nsMargin mComputedBorderPadding
;
142 // Computed padding values
143 nsMargin mComputedPadding
;
146 // Callers using this constructor must call InitOffsets on their own.
147 nsCSSOffsetState(nsIFrame
*aFrame
, nsRenderingContext
*aRenderingContext
)
149 , rendContext(aRenderingContext
)
150 , mWritingMode(aFrame
->GetWritingMode())
154 nsCSSOffsetState(nsIFrame
*aFrame
, nsRenderingContext
*aRenderingContext
,
155 nscoord aContainingBlockWidth
);
158 // Reflow trace methods. Defined in nsFrame.cpp so they have access
159 // to the display-reflow infrastructure.
160 static void* DisplayInitOffsetsEnter(nsIFrame
* aFrame
,
161 nsCSSOffsetState
* aState
,
162 nscoord aHorizontalPercentBasis
,
163 nscoord aVerticalPercentBasis
,
164 const nsMargin
* aBorder
,
165 const nsMargin
* aPadding
);
166 static void DisplayInitOffsetsExit(nsIFrame
* aFrame
,
167 nsCSSOffsetState
* aState
,
173 * Computes margin values from the specified margin style information, and
174 * fills in the mComputedMargin member.
176 * @param aHorizontalPercentBasis
177 * Length to use for resolving percentage margin values in the horizontal
178 * axis. Usually the containing block width.
179 * @param aVerticalPercentBasis
180 * Length to use for resolving percentage margin values in the vertical
181 * axis. Usually the containing block width, per CSS21 sec 8.3, but may
182 * be the containing block *height*, e.g. in CSS3 Flexbox and Grid.
183 * @return true if the margin is dependent on the containing block size.
185 bool ComputeMargin(nscoord aHorizontalPercentBasis
,
186 nscoord aVerticalPercentBasis
);
189 * Computes padding values from the specified padding style information, and
190 * fills in the mComputedPadding member.
192 * @param aHorizontalPercentBasis
193 * Length to use for resolving percentage padding values in the horizontal
194 * axis. Usually the containing block width.
195 * @param aVerticalPercentBasis
196 * Length to use for resolving percentage padding values in the vertical
197 * axis. Usually the containing block width, per CSS21 sec 8.4, but may
198 * be the containing block *height* in e.g. CSS3 Flexbox and Grid.
199 * @return true if the padding is dependent on the containing block size.
201 bool ComputePadding(nscoord aHorizontalPercentBasis
,
202 nscoord aVerticalPercentBasis
, nsIAtom
* aFrameType
);
206 void InitOffsets(nscoord aHorizontalPercentBasis
,
207 nscoord aVerticalPercentBasis
,
209 const nsMargin
*aBorder
= nullptr,
210 const nsMargin
*aPadding
= nullptr);
213 * Convert nsStyleCoord to nscoord when percentages depend on the
214 * containing block width, and enumerated values are for width,
215 * min-width, or max-width. Does not handle auto widths.
217 inline nscoord
ComputeWidthValue(nscoord aContainingBlockWidth
,
218 nscoord aContentEdgeToBoxSizing
,
219 nscoord aBoxSizingToMarginEdge
,
220 const nsStyleCoord
& aCoord
);
221 // same as previous, but using mComputedBorderPadding, mComputedPadding,
222 // and mComputedMargin
223 nscoord
ComputeWidthValue(nscoord aContainingBlockWidth
,
225 const nsStyleCoord
& aCoord
);
227 nscoord
ComputeHeightValue(nscoord aContainingBlockHeight
,
229 const nsStyleCoord
& aCoord
);
233 * State passed to a frame during reflow or intrinsic size calculation.
235 * XXX Refactor so only a base class (nsSizingState?) is used for intrinsic
238 * @see nsIFrame#Reflow()
240 struct nsHTMLReflowState
: public nsCSSOffsetState
{
241 // the reflow states are linked together. this is the pointer to the
242 // parent's reflow state
243 const nsHTMLReflowState
* parentReflowState
;
245 // pointer to the float manager associated with this area
246 nsFloatManager
* mFloatManager
;
248 // LineLayout object (only for inline reflow; set to nullptr otherwise)
249 nsLineLayout
* mLineLayout
;
251 // The appropriate reflow state for the containing block (for
252 // percentage widths, etc.) of this reflow state's frame.
253 const nsHTMLReflowState
*mCBReflowState
;
255 // The type of frame, from css's perspective. This value is
256 // initialized by the Init method below.
257 nsCSSFrameType mFrameType
;
259 // The amount the in-flow position of the block is moving vertically relative
260 // to its previous in-flow position (i.e. the amount the line containing the
262 // This should be zero for anything which is not a block outside, and it
263 // should be zero for anything which has a non-block parent.
264 // The intended use of this value is to allow the accurate determination
265 // of the potential impact of a float
266 // This takes on an arbitrary value the first time a block is reflowed
269 // Accessors for the private fields below. Forcing all callers to use these
270 // will allow us to introduce logical-coordinate versions and gradually
271 // change clients from physical to logical as needed; and potentially switch
272 // the internal fields from physical to logical coordinates in due course,
273 // while maintaining compatibility with not-yet-updated code.
274 nscoord
AvailableWidth() const { return mAvailableWidth
; }
275 nscoord
AvailableHeight() const { return mAvailableHeight
; }
276 nscoord
ComputedWidth() const { return mComputedWidth
; }
277 nscoord
ComputedHeight() const { return mComputedHeight
; }
278 nscoord
ComputedMinWidth() const { return mComputedMinWidth
; }
279 nscoord
ComputedMaxWidth() const { return mComputedMaxWidth
; }
280 nscoord
ComputedMinHeight() const { return mComputedMinHeight
; }
281 nscoord
ComputedMaxHeight() const { return mComputedMaxHeight
; }
283 nscoord
& AvailableWidth() { return mAvailableWidth
; }
284 nscoord
& AvailableHeight() { return mAvailableHeight
; }
285 nscoord
& ComputedWidth() { return mComputedWidth
; }
286 nscoord
& ComputedHeight() { return mComputedHeight
; }
287 nscoord
& ComputedMinWidth() { return mComputedMinWidth
; }
288 nscoord
& ComputedMaxWidth() { return mComputedMaxWidth
; }
289 nscoord
& ComputedMinHeight() { return mComputedMinHeight
; }
290 nscoord
& ComputedMaxHeight() { return mComputedMaxHeight
; }
292 // ISize and BSize are logical-coordinate dimensions:
293 // ISize is the size in the writing mode's inline direction (which equates to
294 // width in horizontal writing modes, height in vertical ones), and BSize is
295 // the size in the block-progression direction.
296 nscoord
AvailableISize() const
297 { return mWritingMode
.IsVertical() ? mAvailableHeight
: mAvailableWidth
; }
298 nscoord
AvailableBSize() const
299 { return mWritingMode
.IsVertical() ? mAvailableWidth
: mAvailableHeight
; }
300 nscoord
ComputedISize() const
301 { return mWritingMode
.IsVertical() ? mComputedHeight
: mComputedWidth
; }
302 nscoord
ComputedBSize() const
303 { return mWritingMode
.IsVertical() ? mComputedWidth
: mComputedHeight
; }
304 nscoord
ComputedMinISize() const
305 { return mWritingMode
.IsVertical() ? mComputedMinHeight
: mComputedMinWidth
; }
306 nscoord
ComputedMaxISize() const
307 { return mWritingMode
.IsVertical() ? mComputedMaxHeight
: mComputedMaxWidth
; }
308 nscoord
ComputedMinBSize() const
309 { return mWritingMode
.IsVertical() ? mComputedMinWidth
: mComputedMinHeight
; }
310 nscoord
ComputedMaxBSize() const
311 { return mWritingMode
.IsVertical() ? mComputedMaxWidth
: mComputedMaxHeight
; }
313 nscoord
& AvailableISize()
314 { return mWritingMode
.IsVertical() ? mAvailableHeight
: mAvailableWidth
; }
315 nscoord
& AvailableBSize()
316 { return mWritingMode
.IsVertical() ? mAvailableWidth
: mAvailableHeight
; }
317 nscoord
& ComputedISize()
318 { return mWritingMode
.IsVertical() ? mComputedHeight
: mComputedWidth
; }
319 nscoord
& ComputedBSize()
320 { return mWritingMode
.IsVertical() ? mComputedWidth
: mComputedHeight
; }
321 nscoord
& ComputedMinISize()
322 { return mWritingMode
.IsVertical() ? mComputedMinHeight
: mComputedMinWidth
; }
323 nscoord
& ComputedMaxISize()
324 { return mWritingMode
.IsVertical() ? mComputedMaxHeight
: mComputedMaxWidth
; }
325 nscoord
& ComputedMinBSize()
326 { return mWritingMode
.IsVertical() ? mComputedMinWidth
: mComputedMinHeight
; }
327 nscoord
& ComputedMaxBSize()
328 { return mWritingMode
.IsVertical() ? mComputedMaxWidth
: mComputedMaxHeight
; }
330 mozilla::LogicalSize
AvailableSize() const {
331 return mozilla::LogicalSize(mWritingMode
,
332 AvailableISize(), AvailableBSize());
334 mozilla::LogicalSize
ComputedSize() const {
335 return mozilla::LogicalSize(mWritingMode
,
336 ComputedISize(), ComputedBSize());
338 mozilla::LogicalSize
ComputedMinSize() const {
339 return mozilla::LogicalSize(mWritingMode
,
340 ComputedMinISize(), ComputedMinBSize());
342 mozilla::LogicalSize
ComputedMaxSize() const {
343 return mozilla::LogicalSize(mWritingMode
,
344 ComputedMaxISize(), ComputedMaxBSize());
347 mozilla::LogicalSize
AvailableSize(mozilla::WritingMode aWM
) const
348 { return AvailableSize().ConvertTo(aWM
, mWritingMode
); }
349 mozilla::LogicalSize
ComputedSize(mozilla::WritingMode aWM
) const
350 { return ComputedSize().ConvertTo(aWM
, mWritingMode
); }
351 mozilla::LogicalSize
ComputedMinSize(mozilla::WritingMode aWM
) const
352 { return ComputedMinSize().ConvertTo(aWM
, mWritingMode
); }
353 mozilla::LogicalSize
ComputedMaxSize(mozilla::WritingMode aWM
) const
354 { return ComputedMaxSize().ConvertTo(aWM
, mWritingMode
); }
356 mozilla::LogicalSize
ComputedSizeWithPadding() const {
357 mozilla::WritingMode wm
= GetWritingMode();
358 return mozilla::LogicalSize(wm
,
360 ComputedLogicalPadding().IStartEnd(wm
),
362 ComputedLogicalPadding().BStartEnd(wm
));
365 mozilla::LogicalSize
ComputedSizeWithPadding(mozilla::WritingMode aWM
) const {
366 return ComputedSizeWithPadding().ConvertTo(aWM
, GetWritingMode());
369 mozilla::LogicalSize
ComputedSizeWithBorderPadding() const {
370 mozilla::WritingMode wm
= GetWritingMode();
371 return mozilla::LogicalSize(wm
,
373 ComputedLogicalBorderPadding().IStartEnd(wm
),
375 ComputedLogicalBorderPadding().BStartEnd(wm
));
379 ComputedSizeWithBorderPadding(mozilla::WritingMode aWM
) const {
380 return ComputedSizeWithBorderPadding().ConvertTo(aWM
, GetWritingMode());
384 ComputedSizeWithMarginBorderPadding() const {
385 mozilla::WritingMode wm
= GetWritingMode();
386 return mozilla::LogicalSize(wm
,
388 ComputedLogicalMargin().IStartEnd(wm
) +
389 ComputedLogicalBorderPadding().IStartEnd(wm
),
391 ComputedLogicalMargin().BStartEnd(wm
) +
392 ComputedLogicalBorderPadding().BStartEnd(wm
));
396 ComputedSizeWithMarginBorderPadding(mozilla::WritingMode aWM
) const {
397 return ComputedSizeWithMarginBorderPadding().ConvertTo(aWM
,
401 // XXX this will need to change when we make mComputedOffsets logical;
402 // we won't be able to return a reference for the physical offsets
403 const nsMargin
& ComputedPhysicalOffsets() const { return mComputedOffsets
; }
404 nsMargin
& ComputedPhysicalOffsets() { return mComputedOffsets
; }
406 LogicalMargin
ComputedLogicalOffsets() const
407 { return LogicalMargin(mWritingMode
, mComputedOffsets
); }
410 // the available width in which to reflow the frame. The space
411 // represents the amount of room for the frame's margin, border,
412 // padding, and content area. The frame size you choose should fit
413 // within the available width.
414 nscoord mAvailableWidth
;
416 // A value of NS_UNCONSTRAINEDSIZE for the available height means
417 // you can choose whatever size you want. In galley mode the
418 // available height is always NS_UNCONSTRAINEDSIZE, and only page
419 // mode or multi-column layout involves a constrained height. The
420 // element's the top border and padding, and content, must fit. If the
421 // element is complete after reflow then its bottom border, padding
422 // and margin (and similar for its complete ancestors) will need to
423 // fit in this height.
424 nscoord mAvailableHeight
;
426 // The computed width specifies the frame's content area width, and it does
427 // not apply to inline non-replaced elements
429 // For replaced inline frames, a value of NS_INTRINSICSIZE means you should
430 // use your intrinsic width as the computed width
432 // For block-level frames, the computed width is based on the width of the
433 // containing block, the margin/border/padding areas, and the min/max width.
434 nscoord mComputedWidth
;
436 // The computed height specifies the frame's content height, and it does
437 // not apply to inline non-replaced elements
439 // For replaced inline frames, a value of NS_INTRINSICSIZE means you should
440 // use your intrinsic height as the computed height
442 // For non-replaced block-level frames in the flow and floated, a value of
443 // NS_AUTOHEIGHT means you choose a height to shrink wrap around the normal
444 // flow child frames. The height must be within the limit of the min/max
445 // height if there is such a limit
447 // For replaced block-level frames, a value of NS_INTRINSICSIZE
448 // means you use your intrinsic height as the computed height
449 nscoord mComputedHeight
;
451 // Computed values for 'left/top/right/bottom' offsets. Only applies to
452 // 'positioned' elements. These are PHYSICAL coordinates (for now).
453 nsMargin mComputedOffsets
;
455 // Computed values for 'min-width/max-width' and 'min-height/max-height'
456 // XXXldb The width ones here should go; they should be needed only
458 nscoord mComputedMinWidth
, mComputedMaxWidth
;
459 nscoord mComputedMinHeight
, mComputedMaxHeight
;
462 // Cached pointers to the various style structs used during intialization
463 const nsStyleDisplay
* mStyleDisplay
;
464 const nsStyleVisibility
* mStyleVisibility
;
465 const nsStylePosition
* mStylePosition
;
466 const nsStyleBorder
* mStyleBorder
;
467 const nsStyleMargin
* mStyleMargin
;
468 const nsStylePadding
* mStylePadding
;
469 const nsStyleText
* mStyleText
;
471 bool IsFloating() const;
473 uint8_t GetDisplay() const;
475 // a frame (e.g. nsTableCellFrame) which may need to generate a special
476 // reflow for percent height calculations
477 nsIPercentHeightObserver
* mPercentHeightObserver
;
479 // CSS margin collapsing sometimes requires us to reflow
480 // optimistically assuming that margins collapse to see if clearance
481 // is required. When we discover that clearance is required, we
482 // store the frame in which clearance was discovered to the location
484 nsIFrame
** mDiscoveredClearance
;
486 // This value keeps track of how deeply nested a given reflow state
487 // is from the top of the frame tree.
488 int16_t mReflowDepth
;
490 struct ReflowStateFlags
{
491 uint16_t mSpecialHeightReflow
:1; // used by tables to communicate special reflow (in process) to handle
492 // percent height frames inside cells which may not have computed heights
493 uint16_t mNextInFlowUntouched
:1; // nothing in the frame's next-in-flow (or its descendants)
495 uint16_t mIsTopOfPage
:1; // Is the current context at the top of a
496 // page? When true, we force something
497 // that's too tall for a page/column to
498 // fit anyway to avoid infinite loops.
499 uint16_t mHasClearance
:1; // Block has clearance
500 uint16_t mAssumingHScrollbar
:1; // parent frame is an nsIScrollableFrame and it
501 // is assuming a horizontal scrollbar
502 uint16_t mAssumingVScrollbar
:1; // parent frame is an nsIScrollableFrame and it
503 // is assuming a vertical scrollbar
505 uint16_t mHResize
:1; // Is frame (a) not dirty and (b) a
506 // different width than before?
508 uint16_t mVResize
:1; // Is frame (a) not dirty and (b) a
509 // different height than before or
510 // (potentially) in a context where
511 // percent heights have a different
513 uint16_t mTableIsSplittable
:1; // tables are splittable, this should happen only inside a page
514 // and never insider a column frame
515 uint16_t mHeightDependsOnAncestorCell
:1; // Does frame height depend on
516 // an ancestor table-cell?
517 uint16_t mIsColumnBalancing
:1; // nsColumnSetFrame is balancing columns
518 uint16_t mIsFlexContainerMeasuringHeight
:1; // nsFlexContainerFrame is
519 // reflowing this child to
520 // measure its intrinsic height.
521 uint16_t mDummyParentReflowState
:1; // a "fake" reflow state made
522 // in order to be the parent
524 uint16_t mMustReflowPlaceholders
:1; // Should this frame reflow its place-
525 // holder children? If the available
526 // height of this frame didn't change,
527 // but its in a paginated environment
528 // (e.g. columns), it should always
529 // reflow its placeholder children.
532 // Note: The copy constructor is written by the compiler automatically. You
533 // can use that and then override specific values if you want, or you can
534 // call Init as desired...
537 * Initialize a ROOT reflow state.
539 * @param aPresContext Must be equal to aFrame->PresContext().
540 * @param aFrame The frame for whose reflow state is being constructed.
541 * @param aRenderingContext The rendering context to be used for measurements.
542 * @param aAvailableSpace See comments for availableHeight and availableWidth
544 * @param aFlags A set of flags used for additional boolean parameters (see
547 nsHTMLReflowState(nsPresContext
* aPresContext
,
549 nsRenderingContext
* aRenderingContext
,
550 const mozilla::LogicalSize
& aAvailableSpace
,
551 uint32_t aFlags
= 0);
554 * Initialize a reflow state for a child frame's reflow. Some parts of the
555 * state are copied from the parent's reflow state. The remainder is computed.
557 * @param aPresContext Must be equal to aFrame->PresContext().
558 * @param aParentReflowState A reference to an nsHTMLReflowState object that
559 * is to be the parent of this object.
560 * @param aFrame The frame for whose reflow state is being constructed.
561 * @param aAvailableSpace See comments for availableHeight and availableWidth
563 * @param aContainingBlockWidth An optional width, in app units, that is used
564 * by absolute positioning code to override default containing block
566 * @param aContainingBlockHeight An optional height, in app units, that is
567 * used by absolute positioning code to override default containing
569 * @param aFlags A set of flags used for additional boolean parameters (see
572 nsHTMLReflowState(nsPresContext
* aPresContext
,
573 const nsHTMLReflowState
& aParentReflowState
,
575 const mozilla::LogicalSize
& aAvailableSpace
,
576 nscoord aContainingBlockWidth
= -1,
577 nscoord aContainingBlockHeight
= -1,
578 uint32_t aFlags
= 0);
580 // Values for |aFlags| passed to constructor
582 // Indicates that the parent of this reflow state is "fake" (see
583 // mDummyParentReflowState in mFlags).
584 DUMMY_PARENT_REFLOW_STATE
= (1<<0),
586 // Indicates that the calling function will initialize the reflow state, and
587 // that the constructor should not call Init().
588 CALLER_WILL_INIT
= (1<<1)
591 // This method initializes various data members. It is automatically
592 // called by the various constructors
593 void Init(nsPresContext
* aPresContext
,
594 nscoord aContainingBlockISize
= -1,
595 nscoord aContainingBlockBSize
= -1,
596 const nsMargin
* aBorder
= nullptr,
597 const nsMargin
* aPadding
= nullptr);
599 * Find the content width of the containing block of aReflowState
602 GetContainingBlockContentWidth(const nsHTMLReflowState
* aReflowState
);
605 * Calculate the used line-height property. The return value will be >= 0.
607 nscoord
CalcLineHeight() const;
610 * Same as CalcLineHeight() above, but doesn't need a reflow state.
612 * @param aBlockHeight The computed height of the content rect of the block
613 * that the line should fill.
614 * Only used with line-height:-moz-block-height.
615 * NS_AUTOHEIGHT results in a normal line-height for
616 * line-height:-moz-block-height.
617 * @param aFontSizeInflation The result of the appropriate
618 * nsLayoutUtils::FontSizeInflationFor call,
619 * or 1.0 if during intrinsic size
622 static nscoord
CalcLineHeight(nsIContent
* aContent
,
623 nsStyleContext
* aStyleContext
,
624 nscoord aBlockHeight
,
625 float aFontSizeInflation
);
628 void ComputeContainingBlockRectangle(nsPresContext
* aPresContext
,
629 const nsHTMLReflowState
* aContainingBlockRS
,
630 nscoord
& aContainingBlockWidth
,
631 nscoord
& aContainingBlockHeight
);
634 * Apply the mComputed(Min/Max)Width constraints to the content
635 * size computed so far.
637 nscoord
ApplyMinMaxWidth(nscoord aWidth
) const {
638 if (NS_UNCONSTRAINEDSIZE
!= ComputedMaxWidth()) {
639 aWidth
= std::min(aWidth
, ComputedMaxWidth());
641 return std::max(aWidth
, ComputedMinWidth());
645 * Apply the mComputed(Min/Max)Height constraints to the content
646 * size computed so far.
648 * @param aHeight The height that we've computed an to which we want to apply
649 * min/max constraints.
650 * @param aConsumed The amount of the computed height that was consumed by
653 nscoord
ApplyMinMaxHeight(nscoord aHeight
, nscoord aConsumed
= 0) const {
654 aHeight
+= aConsumed
;
656 if (NS_UNCONSTRAINEDSIZE
!= ComputedMaxHeight()) {
657 aHeight
= std::min(aHeight
, ComputedMaxHeight());
660 if (NS_UNCONSTRAINEDSIZE
!= ComputedMinHeight()) {
661 aHeight
= std::max(aHeight
, ComputedMinHeight());
664 return aHeight
- aConsumed
;
667 bool ShouldReflowAllKids() const {
668 // Note that we could make a stronger optimization for mVResize if
669 // we use it in a ShouldReflowChild test that replaces the current
670 // checks of NS_FRAME_IS_DIRTY | NS_FRAME_HAS_DIRTY_CHILDREN, if it
671 // were tested there along with NS_FRAME_CONTAINS_RELATIVE_HEIGHT.
672 // This would need to be combined with a slight change in which
673 // frames NS_FRAME_CONTAINS_RELATIVE_HEIGHT is marked on.
674 return (frame
->GetStateBits() & NS_FRAME_IS_DIRTY
) ||
677 (frame
->GetStateBits() & NS_FRAME_CONTAINS_RELATIVE_HEIGHT
));
680 // This method doesn't apply min/max computed widths to the value passed in.
681 void SetComputedWidth(nscoord aComputedWidth
);
683 // This method doesn't apply min/max computed heights to the value passed in.
684 void SetComputedHeight(nscoord aComputedHeight
);
686 void SetComputedISize(nscoord aComputedISize
) {
687 if (mWritingMode
.IsVertical()) {
688 SetComputedHeight(aComputedISize
);
690 SetComputedWidth(aComputedISize
);
694 void SetComputedBSize(nscoord aComputedBSize
) {
695 if (mWritingMode
.IsVertical()) {
696 SetComputedWidth(aComputedBSize
);
698 SetComputedHeight(aComputedBSize
);
702 void SetComputedHeightWithoutResettingResizeFlags(nscoord aComputedHeight
) {
703 // Viewport frames reset the computed height on a copy of their reflow
704 // state when reflowing fixed-pos kids. In that case we actually don't
705 // want to mess with the resize flags, because comparing the frame's rect
706 // to the munged computed width is pointless.
707 ComputedHeight() = aComputedHeight
;
710 void SetTruncated(const nsHTMLReflowMetrics
& aMetrics
, nsReflowStatus
* aStatus
) const;
712 bool WillReflowAgainForClearance() const {
713 return mDiscoveredClearance
&& *mDiscoveredClearance
;
716 // Compute the offsets for a relative position element
717 static void ComputeRelativeOffsets(uint8_t aCBDirection
,
719 nscoord aContainingBlockWidth
,
720 nscoord aContainingBlockHeight
,
721 nsMargin
& aComputedOffsets
);
723 // If a relatively positioned element, adjust the position appropriately.
724 static void ApplyRelativePositioning(nsIFrame
* aFrame
,
725 const nsMargin
& aComputedOffsets
,
728 void ApplyRelativePositioning(nsPoint
* aPosition
) const {
729 ApplyRelativePositioning(frame
, ComputedPhysicalOffsets(), aPosition
);
733 // Reflow trace methods. Defined in nsFrame.cpp so they have access
734 // to the display-reflow infrastructure.
735 static void* DisplayInitConstraintsEnter(nsIFrame
* aFrame
,
736 nsHTMLReflowState
* aState
,
739 const nsMargin
* aBorder
,
740 const nsMargin
* aPadding
);
741 static void DisplayInitConstraintsExit(nsIFrame
* aFrame
,
742 nsHTMLReflowState
* aState
,
744 static void* DisplayInitFrameTypeEnter(nsIFrame
* aFrame
,
745 nsHTMLReflowState
* aState
);
746 static void DisplayInitFrameTypeExit(nsIFrame
* aFrame
,
747 nsHTMLReflowState
* aState
,
752 void InitFrameType(nsIAtom
* aFrameType
);
753 void InitCBReflowState();
754 void InitResizeFlags(nsPresContext
* aPresContext
, nsIAtom
* aFrameType
);
756 void InitConstraints(nsPresContext
* aPresContext
,
757 nscoord aContainingBlockWidth
,
758 nscoord aContainingBlockHeight
,
759 const nsMargin
* aBorder
,
760 const nsMargin
* aPadding
,
761 nsIAtom
* aFrameType
);
763 // Returns the nearest containing block or block frame (whether or not
764 // it is a containing block) for the specified frame. Also returns
765 // the left edge and width of the containing block's content area.
766 // These are returned in the coordinate space of the containing block.
767 nsIFrame
* GetHypotheticalBoxContainer(nsIFrame
* aFrame
,
768 nscoord
& aCBLeftEdge
,
771 void CalculateHypotheticalBox(nsPresContext
* aPresContext
,
772 nsIFrame
* aPlaceholderFrame
,
773 nsIFrame
* aContainingBlock
,
774 nscoord aBlockLeftContentEdge
,
775 nscoord aBlockContentWidth
,
776 const nsHTMLReflowState
* cbrs
,
777 nsHypotheticalBox
& aHypotheticalBox
,
778 nsIAtom
* aFrameType
);
780 void InitAbsoluteConstraints(nsPresContext
* aPresContext
,
781 const nsHTMLReflowState
* cbrs
,
782 nscoord aContainingBlockWidth
,
783 nscoord aContainingBlockHeight
,
784 nsIAtom
* aFrameType
);
786 // Calculates the computed values for the 'min-Width', 'max-Width',
787 // 'min-Height', and 'max-Height' properties, and stores them in the assorted
789 void ComputeMinMaxValues(nscoord aContainingBlockWidth
,
790 nscoord aContainingBlockHeight
,
791 const nsHTMLReflowState
* aContainingBlockRS
);
793 void CalculateHorizBorderPaddingMargin(nscoord aContainingBlockWidth
,
794 nscoord
* aInsideBoxSizing
,
795 nscoord
* aOutsideBoxSizing
);
797 void CalculateBlockSideMargins(nscoord aAvailWidth
,
798 nscoord aComputedWidth
,
799 nsIAtom
* aFrameType
);
802 #endif /* nsHTMLReflowState_h___ */