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 class RubyReflowState
;
29 * @return aValue clamped to [aMinValue, aMaxValue].
31 * @note This function needs to handle aMinValue > aMaxValue. In that case,
32 * aMinValue is returned.
33 * @see http://www.w3.org/TR/CSS21/visudet.html#min-max-widths
34 * @see http://www.w3.org/TR/CSS21/visudet.html#min-max-heights
36 template <class NumericType
>
38 NS_CSS_MINMAX(NumericType aValue
, NumericType aMinValue
, NumericType aMaxValue
)
40 NumericType result
= aValue
;
41 if (aMaxValue
< result
)
43 if (aMinValue
> result
)
49 * CSS Frame type. Included as part of the reflow state.
51 typedef uint32_t nsCSSFrameType
;
53 #define NS_CSS_FRAME_TYPE_UNKNOWN 0
54 #define NS_CSS_FRAME_TYPE_INLINE 1
55 #define NS_CSS_FRAME_TYPE_BLOCK 2 /* block-level in normal flow */
56 #define NS_CSS_FRAME_TYPE_FLOATING 3
57 #define NS_CSS_FRAME_TYPE_ABSOLUTE 4
58 #define NS_CSS_FRAME_TYPE_INTERNAL_TABLE 5 /* row group frame, row frame, cell frame, ... */
61 * Bit-flag that indicates whether the element is replaced. Applies to inline,
62 * block-level, floating, and absolutely positioned elements
64 #define NS_CSS_FRAME_TYPE_REPLACED 0x08000
67 * Bit-flag that indicates that the element is replaced and contains a block
68 * (eg some form controls). Applies to inline, block-level, floating, and
69 * absolutely positioned elements. Mutually exclusive with
70 * NS_CSS_FRAME_TYPE_REPLACED.
72 #define NS_CSS_FRAME_TYPE_REPLACED_CONTAINS_BLOCK 0x10000
75 * Helper macros for telling whether items are replaced
77 #define NS_FRAME_IS_REPLACED_NOBLOCK(_ft) \
78 (NS_CSS_FRAME_TYPE_REPLACED == ((_ft) & NS_CSS_FRAME_TYPE_REPLACED))
80 #define NS_FRAME_IS_REPLACED(_ft) \
81 (NS_FRAME_IS_REPLACED_NOBLOCK(_ft) || \
82 NS_FRAME_IS_REPLACED_CONTAINS_BLOCK(_ft))
84 #define NS_FRAME_REPLACED(_ft) \
85 (NS_CSS_FRAME_TYPE_REPLACED | (_ft))
87 #define NS_FRAME_IS_REPLACED_CONTAINS_BLOCK(_ft) \
88 (NS_CSS_FRAME_TYPE_REPLACED_CONTAINS_BLOCK == \
89 ((_ft) & NS_CSS_FRAME_TYPE_REPLACED_CONTAINS_BLOCK))
91 #define NS_FRAME_REPLACED_CONTAINS_BLOCK(_ft) \
92 (NS_CSS_FRAME_TYPE_REPLACED_CONTAINS_BLOCK | (_ft))
95 * A macro to extract the type. Masks off the 'replaced' bit-flag
97 #define NS_FRAME_GET_TYPE(_ft) \
98 ((_ft) & ~(NS_CSS_FRAME_TYPE_REPLACED | \
99 NS_CSS_FRAME_TYPE_REPLACED_CONTAINS_BLOCK))
101 // A base class of nsHTMLReflowState that computes only the padding,
102 // border, and margin, since those values are needed more often.
103 struct nsCSSOffsetState
{
105 typedef mozilla::WritingMode WritingMode
;
106 typedef mozilla::LogicalMargin LogicalMargin
;
108 // the frame being reflowed
111 // rendering context to use for measurement
112 nsRenderingContext
* rendContext
;
114 const nsMargin
& ComputedPhysicalMargin() const { return mComputedMargin
; }
115 const nsMargin
& ComputedPhysicalBorderPadding() const { return mComputedBorderPadding
; }
116 const nsMargin
& ComputedPhysicalPadding() const { return mComputedPadding
; }
118 // We may need to eliminate the (few) users of these writable-reference accessors
119 // as part of migrating to logical coordinates.
120 nsMargin
& ComputedPhysicalMargin() { return mComputedMargin
; }
121 nsMargin
& ComputedPhysicalBorderPadding() { return mComputedBorderPadding
; }
122 nsMargin
& ComputedPhysicalPadding() { return mComputedPadding
; }
124 const LogicalMargin
ComputedLogicalMargin() const
125 { return LogicalMargin(mWritingMode
, mComputedMargin
); }
126 const LogicalMargin
ComputedLogicalBorderPadding() const
127 { return LogicalMargin(mWritingMode
, mComputedBorderPadding
); }
128 const LogicalMargin
ComputedLogicalPadding() const
129 { return LogicalMargin(mWritingMode
, mComputedPadding
); }
131 void SetComputedLogicalMargin(const LogicalMargin
& aMargin
)
132 { mComputedMargin
= aMargin
.GetPhysicalMargin(mWritingMode
); }
133 void SetComputedLogicalBorderPadding(const LogicalMargin
& aMargin
)
134 { mComputedBorderPadding
= aMargin
.GetPhysicalMargin(mWritingMode
); }
135 void SetComputedLogicalPadding(const LogicalMargin
& aMargin
)
136 { mComputedPadding
= aMargin
.GetPhysicalMargin(mWritingMode
); }
138 WritingMode
GetWritingMode() const { return mWritingMode
; }
141 // cached copy of the frame's writing-mode, for logical coordinates
142 WritingMode mWritingMode
;
144 // These are PHYSICAL coordinates (for now).
145 // Will probably become logical in due course.
147 // Computed margin values
148 nsMargin mComputedMargin
;
150 // Cached copy of the border + padding values
151 nsMargin mComputedBorderPadding
;
153 // Computed padding values
154 nsMargin mComputedPadding
;
157 // Callers using this constructor must call InitOffsets on their own.
158 nsCSSOffsetState(nsIFrame
*aFrame
, nsRenderingContext
*aRenderingContext
)
160 , rendContext(aRenderingContext
)
161 , mWritingMode(aFrame
->GetWritingMode())
165 nsCSSOffsetState(nsIFrame
*aFrame
, nsRenderingContext
*aRenderingContext
,
166 nscoord aContainingBlockWidth
);
169 // Reflow trace methods. Defined in nsFrame.cpp so they have access
170 // to the display-reflow infrastructure.
171 static void* DisplayInitOffsetsEnter(nsIFrame
* aFrame
,
172 nsCSSOffsetState
* aState
,
173 nscoord aInlineDirPercentBasis
,
174 nscoord aBlockDirPercentBasis
,
175 const nsMargin
* aBorder
,
176 const nsMargin
* aPadding
);
177 static void DisplayInitOffsetsExit(nsIFrame
* aFrame
,
178 nsCSSOffsetState
* aState
,
184 * Computes margin values from the specified margin style information, and
185 * fills in the mComputedMargin member.
187 * @param aInlineDirPercentBasis
188 * Length to use for resolving percentage margin values in the inline
189 * axis. Usually the containing block inline-size (width if writing mode
190 * is horizontal, and height if vertical).
191 * @param aBlockDirPercentBasis
192 * Length to use for resolving percentage margin values in the block
193 * axis. Usually the containing block inline-size, per CSS21 sec 8.3
194 * (read in conjunction with CSS Writing Modes sec 7.2), but may
195 * be the containing block block-size, e.g. in CSS3 Flexbox and Grid.
196 * @return true if the margin is dependent on the containing block size.
198 bool ComputeMargin(nscoord aInlineDirPercentBasis
,
199 nscoord aBlockDirPercentBasis
);
202 * Computes padding values from the specified padding style information, and
203 * fills in the mComputedPadding member.
205 * @param aInlineDirPercentBasis
206 * Length to use for resolving percentage padding values in the inline
207 * axis. Usually the containing block inline-size.
208 * @param aBlockDirPercentBasis
209 * Length to use for resolving percentage padding values in the block
210 * axis. Usually the containing block inline-size, per CSS21 sec 8.4,
211 * but may be the containing block block-size in e.g. CSS3 Flexbox and
213 * @return true if the padding is dependent on the containing block size.
215 bool ComputePadding(nscoord aInlineDirPercentBasis
,
216 nscoord aBlockDirPercentBasis
, nsIAtom
* aFrameType
);
220 void InitOffsets(nscoord aInlineDirPercentBasis
,
221 nscoord aBlockDirPercentBasis
,
223 const nsMargin
*aBorder
= nullptr,
224 const nsMargin
*aPadding
= nullptr);
227 * Convert nsStyleCoord to nscoord when percentages depend on the
228 * containing block width, and enumerated values are for width,
229 * min-width, or max-width. Does not handle auto widths.
231 inline nscoord
ComputeWidthValue(nscoord aContainingBlockWidth
,
232 nscoord aContentEdgeToBoxSizing
,
233 nscoord aBoxSizingToMarginEdge
,
234 const nsStyleCoord
& aCoord
);
235 // same as previous, but using mComputedBorderPadding, mComputedPadding,
236 // and mComputedMargin
237 nscoord
ComputeWidthValue(nscoord aContainingBlockWidth
,
239 const nsStyleCoord
& aCoord
);
241 nscoord
ComputeHeightValue(nscoord aContainingBlockHeight
,
243 const nsStyleCoord
& aCoord
);
247 * State passed to a frame during reflow or intrinsic size calculation.
249 * XXX Refactor so only a base class (nsSizingState?) is used for intrinsic
252 * @see nsIFrame#Reflow()
254 struct nsHTMLReflowState
: public nsCSSOffsetState
{
255 // the reflow states are linked together. this is the pointer to the
256 // parent's reflow state
257 const nsHTMLReflowState
* parentReflowState
;
259 // pointer to the float manager associated with this area
260 nsFloatManager
* mFloatManager
;
262 // LineLayout object (only for inline reflow; set to nullptr otherwise)
263 nsLineLayout
* mLineLayout
;
265 // RubyReflowState object (only for ruby reflow; set to nullptr otherwise)
266 mozilla::RubyReflowState
* mRubyReflowState
;
268 // The appropriate reflow state for the containing block (for
269 // percentage widths, etc.) of this reflow state's frame.
270 const nsHTMLReflowState
*mCBReflowState
;
272 // The type of frame, from css's perspective. This value is
273 // initialized by the Init method below.
274 nsCSSFrameType mFrameType
;
276 // The amount the in-flow position of the block is moving vertically relative
277 // to its previous in-flow position (i.e. the amount the line containing the
279 // This should be zero for anything which is not a block outside, and it
280 // should be zero for anything which has a non-block parent.
281 // The intended use of this value is to allow the accurate determination
282 // of the potential impact of a float
283 // This takes on an arbitrary value the first time a block is reflowed
286 // If an nsHTMLReflowState finds itself initialized with an unconstrained
287 // inline-size, it will look up its parentReflowState chain for a state
288 // with an orthogonal writing mode and a non-NS_UNCONSTRAINEDSIZE value for
289 // orthogonal limit; when it finds such a reflow-state, it will use its
290 // orthogonal-limit value to constrain inline-size.
291 // This is initialized to NS_UNCONSTRAINEDSIZE (so it will be ignored),
292 // but reset to a suitable value for the reflow root by nsPresShell.
293 nscoord mOrthogonalLimit
;
295 // Accessors for the private fields below. Forcing all callers to use these
296 // will allow us to introduce logical-coordinate versions and gradually
297 // change clients from physical to logical as needed; and potentially switch
298 // the internal fields from physical to logical coordinates in due course,
299 // while maintaining compatibility with not-yet-updated code.
300 nscoord
AvailableWidth() const { return mAvailableWidth
; }
301 nscoord
AvailableHeight() const { return mAvailableHeight
; }
302 nscoord
ComputedWidth() const { return mComputedWidth
; }
303 nscoord
ComputedHeight() const { return mComputedHeight
; }
304 nscoord
ComputedMinWidth() const { return mComputedMinWidth
; }
305 nscoord
ComputedMaxWidth() const { return mComputedMaxWidth
; }
306 nscoord
ComputedMinHeight() const { return mComputedMinHeight
; }
307 nscoord
ComputedMaxHeight() const { return mComputedMaxHeight
; }
309 nscoord
& AvailableWidth() { return mAvailableWidth
; }
310 nscoord
& AvailableHeight() { return mAvailableHeight
; }
311 nscoord
& ComputedWidth() { return mComputedWidth
; }
312 nscoord
& ComputedHeight() { return mComputedHeight
; }
313 nscoord
& ComputedMinWidth() { return mComputedMinWidth
; }
314 nscoord
& ComputedMaxWidth() { return mComputedMaxWidth
; }
315 nscoord
& ComputedMinHeight() { return mComputedMinHeight
; }
316 nscoord
& ComputedMaxHeight() { return mComputedMaxHeight
; }
318 // ISize and BSize are logical-coordinate dimensions:
319 // ISize is the size in the writing mode's inline direction (which equates to
320 // width in horizontal writing modes, height in vertical ones), and BSize is
321 // the size in the block-progression direction.
322 nscoord
AvailableISize() const
323 { return mWritingMode
.IsVertical() ? mAvailableHeight
: mAvailableWidth
; }
324 nscoord
AvailableBSize() const
325 { return mWritingMode
.IsVertical() ? mAvailableWidth
: mAvailableHeight
; }
326 nscoord
ComputedISize() const
327 { return mWritingMode
.IsVertical() ? mComputedHeight
: mComputedWidth
; }
328 nscoord
ComputedBSize() const
329 { return mWritingMode
.IsVertical() ? mComputedWidth
: mComputedHeight
; }
330 nscoord
ComputedMinISize() const
331 { return mWritingMode
.IsVertical() ? mComputedMinHeight
: mComputedMinWidth
; }
332 nscoord
ComputedMaxISize() const
333 { return mWritingMode
.IsVertical() ? mComputedMaxHeight
: mComputedMaxWidth
; }
334 nscoord
ComputedMinBSize() const
335 { return mWritingMode
.IsVertical() ? mComputedMinWidth
: mComputedMinHeight
; }
336 nscoord
ComputedMaxBSize() const
337 { return mWritingMode
.IsVertical() ? mComputedMaxWidth
: mComputedMaxHeight
; }
339 nscoord
& AvailableISize()
340 { return mWritingMode
.IsVertical() ? mAvailableHeight
: mAvailableWidth
; }
341 nscoord
& AvailableBSize()
342 { return mWritingMode
.IsVertical() ? mAvailableWidth
: mAvailableHeight
; }
343 nscoord
& ComputedISize()
344 { return mWritingMode
.IsVertical() ? mComputedHeight
: mComputedWidth
; }
345 nscoord
& ComputedBSize()
346 { return mWritingMode
.IsVertical() ? mComputedWidth
: mComputedHeight
; }
347 nscoord
& ComputedMinISize()
348 { return mWritingMode
.IsVertical() ? mComputedMinHeight
: mComputedMinWidth
; }
349 nscoord
& ComputedMaxISize()
350 { return mWritingMode
.IsVertical() ? mComputedMaxHeight
: mComputedMaxWidth
; }
351 nscoord
& ComputedMinBSize()
352 { return mWritingMode
.IsVertical() ? mComputedMinWidth
: mComputedMinHeight
; }
353 nscoord
& ComputedMaxBSize()
354 { return mWritingMode
.IsVertical() ? mComputedMaxWidth
: mComputedMaxHeight
; }
356 mozilla::LogicalSize
AvailableSize() const {
357 return mozilla::LogicalSize(mWritingMode
,
358 AvailableISize(), AvailableBSize());
360 mozilla::LogicalSize
ComputedSize() const {
361 return mozilla::LogicalSize(mWritingMode
,
362 ComputedISize(), ComputedBSize());
364 mozilla::LogicalSize
ComputedMinSize() const {
365 return mozilla::LogicalSize(mWritingMode
,
366 ComputedMinISize(), ComputedMinBSize());
368 mozilla::LogicalSize
ComputedMaxSize() const {
369 return mozilla::LogicalSize(mWritingMode
,
370 ComputedMaxISize(), ComputedMaxBSize());
373 mozilla::LogicalSize
AvailableSize(mozilla::WritingMode aWM
) const
374 { return AvailableSize().ConvertTo(aWM
, mWritingMode
); }
375 mozilla::LogicalSize
ComputedSize(mozilla::WritingMode aWM
) const
376 { return ComputedSize().ConvertTo(aWM
, mWritingMode
); }
377 mozilla::LogicalSize
ComputedMinSize(mozilla::WritingMode aWM
) const
378 { return ComputedMinSize().ConvertTo(aWM
, mWritingMode
); }
379 mozilla::LogicalSize
ComputedMaxSize(mozilla::WritingMode aWM
) const
380 { return ComputedMaxSize().ConvertTo(aWM
, mWritingMode
); }
382 mozilla::LogicalSize
ComputedSizeWithPadding() const {
383 mozilla::WritingMode wm
= GetWritingMode();
384 return mozilla::LogicalSize(wm
,
386 ComputedLogicalPadding().IStartEnd(wm
),
388 ComputedLogicalPadding().BStartEnd(wm
));
391 mozilla::LogicalSize
ComputedSizeWithPadding(mozilla::WritingMode aWM
) const {
392 return ComputedSizeWithPadding().ConvertTo(aWM
, GetWritingMode());
395 mozilla::LogicalSize
ComputedSizeWithBorderPadding() const {
396 mozilla::WritingMode wm
= GetWritingMode();
397 return mozilla::LogicalSize(wm
,
399 ComputedLogicalBorderPadding().IStartEnd(wm
),
401 ComputedLogicalBorderPadding().BStartEnd(wm
));
405 ComputedSizeWithBorderPadding(mozilla::WritingMode aWM
) const {
406 return ComputedSizeWithBorderPadding().ConvertTo(aWM
, GetWritingMode());
410 ComputedSizeWithMarginBorderPadding() const {
411 mozilla::WritingMode wm
= GetWritingMode();
412 return mozilla::LogicalSize(wm
,
414 ComputedLogicalMargin().IStartEnd(wm
) +
415 ComputedLogicalBorderPadding().IStartEnd(wm
),
417 ComputedLogicalMargin().BStartEnd(wm
) +
418 ComputedLogicalBorderPadding().BStartEnd(wm
));
422 ComputedSizeWithMarginBorderPadding(mozilla::WritingMode aWM
) const {
423 return ComputedSizeWithMarginBorderPadding().ConvertTo(aWM
,
427 // XXX this will need to change when we make mComputedOffsets logical;
428 // we won't be able to return a reference for the physical offsets
429 const nsMargin
& ComputedPhysicalOffsets() const { return mComputedOffsets
; }
430 nsMargin
& ComputedPhysicalOffsets() { return mComputedOffsets
; }
432 LogicalMargin
ComputedLogicalOffsets() const
433 { return LogicalMargin(mWritingMode
, mComputedOffsets
); }
436 // the available width in which to reflow the frame. The space
437 // represents the amount of room for the frame's margin, border,
438 // padding, and content area. The frame size you choose should fit
439 // within the available width.
440 nscoord mAvailableWidth
;
442 // A value of NS_UNCONSTRAINEDSIZE for the available height means
443 // you can choose whatever size you want. In galley mode the
444 // available height is always NS_UNCONSTRAINEDSIZE, and only page
445 // mode or multi-column layout involves a constrained height. The
446 // element's the top border and padding, and content, must fit. If the
447 // element is complete after reflow then its bottom border, padding
448 // and margin (and similar for its complete ancestors) will need to
449 // fit in this height.
450 nscoord mAvailableHeight
;
452 // The computed width specifies the frame's content area width, and it does
453 // not apply to inline non-replaced elements
455 // For replaced inline frames, a value of NS_INTRINSICSIZE means you should
456 // use your intrinsic width as the computed width
458 // For block-level frames, the computed width is based on the width of the
459 // containing block, the margin/border/padding areas, and the min/max width.
460 nscoord mComputedWidth
;
462 // The computed height specifies the frame's content height, and it does
463 // not apply to inline non-replaced elements
465 // For replaced inline frames, a value of NS_INTRINSICSIZE means you should
466 // use your intrinsic height as the computed height
468 // For non-replaced block-level frames in the flow and floated, a value of
469 // NS_AUTOHEIGHT means you choose a height to shrink wrap around the normal
470 // flow child frames. The height must be within the limit of the min/max
471 // height if there is such a limit
473 // For replaced block-level frames, a value of NS_INTRINSICSIZE
474 // means you use your intrinsic height as the computed height
475 nscoord mComputedHeight
;
477 // Computed values for 'left/top/right/bottom' offsets. Only applies to
478 // 'positioned' elements. These are PHYSICAL coordinates (for now).
479 nsMargin mComputedOffsets
;
481 // Computed values for 'min-width/max-width' and 'min-height/max-height'
482 // XXXldb The width ones here should go; they should be needed only
484 nscoord mComputedMinWidth
, mComputedMaxWidth
;
485 nscoord mComputedMinHeight
, mComputedMaxHeight
;
488 // Cached pointers to the various style structs used during intialization
489 const nsStyleDisplay
* mStyleDisplay
;
490 const nsStyleVisibility
* mStyleVisibility
;
491 const nsStylePosition
* mStylePosition
;
492 const nsStyleBorder
* mStyleBorder
;
493 const nsStyleMargin
* mStyleMargin
;
494 const nsStylePadding
* mStylePadding
;
495 const nsStyleText
* mStyleText
;
497 bool IsFloating() const;
499 uint8_t GetDisplay() const;
501 // a frame (e.g. nsTableCellFrame) which may need to generate a special
502 // reflow for percent height calculations
503 nsIPercentHeightObserver
* mPercentHeightObserver
;
505 // CSS margin collapsing sometimes requires us to reflow
506 // optimistically assuming that margins collapse to see if clearance
507 // is required. When we discover that clearance is required, we
508 // store the frame in which clearance was discovered to the location
510 nsIFrame
** mDiscoveredClearance
;
512 // This value keeps track of how deeply nested a given reflow state
513 // is from the top of the frame tree.
514 int16_t mReflowDepth
;
516 struct ReflowStateFlags
{
517 uint16_t mSpecialHeightReflow
:1; // used by tables to communicate special reflow (in process) to handle
518 // percent height frames inside cells which may not have computed heights
519 uint16_t mNextInFlowUntouched
:1; // nothing in the frame's next-in-flow (or its descendants)
521 uint16_t mIsTopOfPage
:1; // Is the current context at the top of a
522 // page? When true, we force something
523 // that's too tall for a page/column to
524 // fit anyway to avoid infinite loops.
525 uint16_t mHasClearance
:1; // Block has clearance
526 uint16_t mAssumingHScrollbar
:1; // parent frame is an nsIScrollableFrame and it
527 // is assuming a horizontal scrollbar
528 uint16_t mAssumingVScrollbar
:1; // parent frame is an nsIScrollableFrame and it
529 // is assuming a vertical scrollbar
531 uint16_t mIsHResize
:1; // Is frame (a) not dirty and (b) a
532 // different width than before?
534 uint16_t mIsVResize
:1; // Is frame (a) not dirty and (b) a
535 // different height than before or
536 // (potentially) in a context where
537 // percent heights have a different
539 uint16_t mTableIsSplittable
:1; // tables are splittable, this should happen only inside a page
540 // and never insider a column frame
541 uint16_t mHeightDependsOnAncestorCell
:1; // Does frame height depend on
542 // an ancestor table-cell?
543 uint16_t mIsColumnBalancing
:1; // nsColumnSetFrame is balancing columns
544 uint16_t mIsFlexContainerMeasuringHeight
:1; // nsFlexContainerFrame is
545 // reflowing this child to
546 // measure its intrinsic height.
547 uint16_t mDummyParentReflowState
:1; // a "fake" reflow state made
548 // in order to be the parent
550 uint16_t mMustReflowPlaceholders
:1; // Should this frame reflow its place-
551 // holder children? If the available
552 // height of this frame didn't change,
553 // but its in a paginated environment
554 // (e.g. columns), it should always
555 // reflow its placeholder children.
558 // Logical and physical accessors for the resize flags. All users should go
559 // via these accessors, so that in due course we can change the storage from
560 // physical to logical.
561 bool IsHResize() const {
562 return mFlags
.mIsHResize
;
564 bool IsVResize() const {
565 return mFlags
.mIsVResize
;
567 bool IsIResize() const {
568 return mWritingMode
.IsVertical() ? mFlags
.mIsVResize
: mFlags
.mIsHResize
;
570 bool IsBResize() const {
571 return mWritingMode
.IsVertical() ? mFlags
.mIsHResize
: mFlags
.mIsVResize
;
573 void SetHResize(bool aValue
) {
574 mFlags
.mIsHResize
= aValue
;
576 void SetVResize(bool aValue
) {
577 mFlags
.mIsVResize
= aValue
;
579 void SetIResize(bool aValue
) {
580 if (mWritingMode
.IsVertical()) {
581 mFlags
.mIsVResize
= aValue
;
583 mFlags
.mIsHResize
= aValue
;
586 void SetBResize(bool aValue
) {
587 if (mWritingMode
.IsVertical()) {
588 mFlags
.mIsHResize
= aValue
;
590 mFlags
.mIsVResize
= aValue
;
594 // Note: The copy constructor is written by the compiler automatically. You
595 // can use that and then override specific values if you want, or you can
596 // call Init as desired...
599 * Initialize a ROOT reflow state.
601 * @param aPresContext Must be equal to aFrame->PresContext().
602 * @param aFrame The frame for whose reflow state is being constructed.
603 * @param aRenderingContext The rendering context to be used for measurements.
604 * @param aAvailableSpace See comments for availableHeight and availableWidth
606 * @param aFlags A set of flags used for additional boolean parameters (see
609 nsHTMLReflowState(nsPresContext
* aPresContext
,
611 nsRenderingContext
* aRenderingContext
,
612 const mozilla::LogicalSize
& aAvailableSpace
,
613 uint32_t aFlags
= 0);
616 * Initialize a reflow state for a child frame's reflow. Some parts of the
617 * state are copied from the parent's reflow state. The remainder is computed.
619 * @param aPresContext Must be equal to aFrame->PresContext().
620 * @param aParentReflowState A reference to an nsHTMLReflowState object that
621 * is to be the parent of this object.
622 * @param aFrame The frame for whose reflow state is being constructed.
623 * @param aAvailableSpace See comments for availableHeight and availableWidth
625 * @param aContainingBlockWidth An optional width, in app units, that is used
626 * by absolute positioning code to override default containing block
628 * @param aContainingBlockHeight An optional height, in app units, that is
629 * used by absolute positioning code to override default containing
631 * @param aFlags A set of flags used for additional boolean parameters (see
634 nsHTMLReflowState(nsPresContext
* aPresContext
,
635 const nsHTMLReflowState
& aParentReflowState
,
637 const mozilla::LogicalSize
& aAvailableSpace
,
638 nscoord aContainingBlockWidth
= -1,
639 nscoord aContainingBlockHeight
= -1,
640 uint32_t aFlags
= 0);
642 // Values for |aFlags| passed to constructor
644 // Indicates that the parent of this reflow state is "fake" (see
645 // mDummyParentReflowState in mFlags).
646 DUMMY_PARENT_REFLOW_STATE
= (1<<0),
648 // Indicates that the calling function will initialize the reflow state, and
649 // that the constructor should not call Init().
650 CALLER_WILL_INIT
= (1<<1)
653 // This method initializes various data members. It is automatically
654 // called by the various constructors
655 void Init(nsPresContext
* aPresContext
,
656 nscoord aContainingBlockISize
= -1,
657 nscoord aContainingBlockBSize
= -1,
658 const nsMargin
* aBorder
= nullptr,
659 const nsMargin
* aPadding
= nullptr);
661 * Find the content width of the containing block of aReflowState
664 GetContainingBlockContentWidth(const nsHTMLReflowState
* aReflowState
);
667 * Calculate the used line-height property. The return value will be >= 0.
669 nscoord
CalcLineHeight() const;
672 * Same as CalcLineHeight() above, but doesn't need a reflow state.
674 * @param aBlockHeight The computed height of the content rect of the block
675 * that the line should fill.
676 * Only used with line-height:-moz-block-height.
677 * NS_AUTOHEIGHT results in a normal line-height for
678 * line-height:-moz-block-height.
679 * @param aFontSizeInflation The result of the appropriate
680 * nsLayoutUtils::FontSizeInflationFor call,
681 * or 1.0 if during intrinsic size
684 static nscoord
CalcLineHeight(nsIContent
* aContent
,
685 nsStyleContext
* aStyleContext
,
687 float aFontSizeInflation
);
690 void ComputeContainingBlockRectangle(nsPresContext
* aPresContext
,
691 const nsHTMLReflowState
* aContainingBlockRS
,
692 nscoord
& aContainingBlockWidth
,
693 nscoord
& aContainingBlockHeight
);
696 * Apply the mComputed(Min/Max)Width constraints to the content
697 * size computed so far.
699 nscoord
ApplyMinMaxWidth(nscoord aWidth
) const {
700 if (NS_UNCONSTRAINEDSIZE
!= ComputedMaxWidth()) {
701 aWidth
= std::min(aWidth
, ComputedMaxWidth());
703 return std::max(aWidth
, ComputedMinWidth());
707 * Apply the mComputed(Min/Max)ISize constraints to the content
708 * size computed so far.
710 nscoord
ApplyMinMaxISize(nscoord aISize
) const {
711 if (NS_UNCONSTRAINEDSIZE
!= ComputedMaxISize()) {
712 aISize
= std::min(aISize
, ComputedMaxISize());
714 return std::max(aISize
, ComputedMinISize());
718 * Apply the mComputed(Min/Max)Height constraints to the content
719 * size computed so far.
721 * @param aHeight The height that we've computed an to which we want to apply
722 * min/max constraints.
723 * @param aConsumed The amount of the computed height that was consumed by
726 nscoord
ApplyMinMaxHeight(nscoord aHeight
, nscoord aConsumed
= 0) const {
727 aHeight
+= aConsumed
;
729 if (NS_UNCONSTRAINEDSIZE
!= ComputedMaxHeight()) {
730 aHeight
= std::min(aHeight
, ComputedMaxHeight());
733 if (NS_UNCONSTRAINEDSIZE
!= ComputedMinHeight()) {
734 aHeight
= std::max(aHeight
, ComputedMinHeight());
737 return aHeight
- aConsumed
;
741 * Apply the mComputed(Min/Max)BSize constraints to the content
742 * size computed so far.
744 * @param aBSize The block-size that we've computed an to which we want to apply
745 * min/max constraints.
746 * @param aConsumed The amount of the computed block-size that was consumed by
749 nscoord
ApplyMinMaxBSize(nscoord aBSize
, nscoord aConsumed
= 0) const {
752 if (NS_UNCONSTRAINEDSIZE
!= ComputedMaxBSize()) {
753 aBSize
= std::min(aBSize
, ComputedMaxBSize());
756 if (NS_UNCONSTRAINEDSIZE
!= ComputedMinBSize()) {
757 aBSize
= std::max(aBSize
, ComputedMinBSize());
760 return aBSize
- aConsumed
;
763 bool ShouldReflowAllKids() const {
764 // Note that we could make a stronger optimization for mVResize if
765 // we use it in a ShouldReflowChild test that replaces the current
766 // checks of NS_FRAME_IS_DIRTY | NS_FRAME_HAS_DIRTY_CHILDREN, if it
767 // were tested there along with NS_FRAME_CONTAINS_RELATIVE_HEIGHT.
768 // This would need to be combined with a slight change in which
769 // frames NS_FRAME_CONTAINS_RELATIVE_HEIGHT is marked on.
770 return (frame
->GetStateBits() & NS_FRAME_IS_DIRTY
) ||
773 (frame
->GetStateBits() & NS_FRAME_CONTAINS_RELATIVE_HEIGHT
));
776 // This method doesn't apply min/max computed widths to the value passed in.
777 void SetComputedWidth(nscoord aComputedWidth
);
779 // This method doesn't apply min/max computed heights to the value passed in.
780 void SetComputedHeight(nscoord aComputedHeight
);
782 void SetComputedISize(nscoord aComputedISize
) {
783 if (mWritingMode
.IsVertical()) {
784 SetComputedHeight(aComputedISize
);
786 SetComputedWidth(aComputedISize
);
790 void SetComputedBSize(nscoord aComputedBSize
) {
791 if (mWritingMode
.IsVertical()) {
792 SetComputedWidth(aComputedBSize
);
794 SetComputedHeight(aComputedBSize
);
798 void SetComputedHeightWithoutResettingResizeFlags(nscoord aComputedHeight
) {
799 // Viewport frames reset the computed height on a copy of their reflow
800 // state when reflowing fixed-pos kids. In that case we actually don't
801 // want to mess with the resize flags, because comparing the frame's rect
802 // to the munged computed width is pointless.
803 ComputedHeight() = aComputedHeight
;
806 void SetTruncated(const nsHTMLReflowMetrics
& aMetrics
, nsReflowStatus
* aStatus
) const;
808 bool WillReflowAgainForClearance() const {
809 return mDiscoveredClearance
&& *mDiscoveredClearance
;
812 // Compute the offsets for a relative position element
813 static void ComputeRelativeOffsets(uint8_t aCBDirection
,
815 nscoord aContainingBlockWidth
,
816 nscoord aContainingBlockHeight
,
817 nsMargin
& aComputedOffsets
);
819 // If a relatively positioned element, adjust the position appropriately.
820 static void ApplyRelativePositioning(nsIFrame
* aFrame
,
821 const nsMargin
& aComputedOffsets
,
824 void ApplyRelativePositioning(nsPoint
* aPosition
) const {
825 ApplyRelativePositioning(frame
, ComputedPhysicalOffsets(), aPosition
);
829 // Reflow trace methods. Defined in nsFrame.cpp so they have access
830 // to the display-reflow infrastructure.
831 static void* DisplayInitConstraintsEnter(nsIFrame
* aFrame
,
832 nsHTMLReflowState
* aState
,
835 const nsMargin
* aBorder
,
836 const nsMargin
* aPadding
);
837 static void DisplayInitConstraintsExit(nsIFrame
* aFrame
,
838 nsHTMLReflowState
* aState
,
840 static void* DisplayInitFrameTypeEnter(nsIFrame
* aFrame
,
841 nsHTMLReflowState
* aState
);
842 static void DisplayInitFrameTypeExit(nsIFrame
* aFrame
,
843 nsHTMLReflowState
* aState
,
848 void InitFrameType(nsIAtom
* aFrameType
);
849 void InitCBReflowState();
850 void InitResizeFlags(nsPresContext
* aPresContext
, nsIAtom
* aFrameType
);
852 void InitConstraints(nsPresContext
* aPresContext
,
853 nscoord aContainingBlockWidth
,
854 nscoord aContainingBlockHeight
,
855 const nsMargin
* aBorder
,
856 const nsMargin
* aPadding
,
857 nsIAtom
* aFrameType
);
859 // Returns the nearest containing block or block frame (whether or not
860 // it is a containing block) for the specified frame. Also returns
861 // the left edge and width of the containing block's content area.
862 // These are returned in the coordinate space of the containing block.
863 nsIFrame
* GetHypotheticalBoxContainer(nsIFrame
* aFrame
,
864 nscoord
& aCBLeftEdge
,
867 void CalculateHypotheticalBox(nsPresContext
* aPresContext
,
868 nsIFrame
* aPlaceholderFrame
,
869 nsIFrame
* aContainingBlock
,
870 nscoord aBlockLeftContentEdge
,
871 nscoord aBlockContentWidth
,
872 const nsHTMLReflowState
* cbrs
,
873 nsHypotheticalBox
& aHypotheticalBox
,
874 nsIAtom
* aFrameType
);
876 void InitAbsoluteConstraints(nsPresContext
* aPresContext
,
877 const nsHTMLReflowState
* cbrs
,
878 nscoord aContainingBlockWidth
,
879 nscoord aContainingBlockHeight
,
880 nsIAtom
* aFrameType
);
882 // Calculates the computed values for the 'min-Width', 'max-Width',
883 // 'min-Height', and 'max-Height' properties, and stores them in the assorted
885 void ComputeMinMaxValues(nscoord aContainingBlockWidth
,
886 nscoord aContainingBlockHeight
,
887 const nsHTMLReflowState
* aContainingBlockRS
);
889 void CalculateHorizBorderPaddingMargin(nscoord aContainingBlockWidth
,
890 nscoord
* aInsideBoxSizing
,
891 nscoord
* aOutsideBoxSizing
);
893 void CalculateBlockSideMargins(nsIAtom
* aFrameType
);
896 #endif /* nsHTMLReflowState_h___ */