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"
15 #include "mozilla/Assertions.h"
16 #include "mozilla/Maybe.h"
21 struct nsHypotheticalPosition
;
22 class nsIPercentBSizeObserver
;
24 class nsPlaceholderFrame
;
28 * @return aValue clamped to [aMinValue, aMaxValue].
30 * @note This function needs to handle aMinValue > aMaxValue. In that case,
31 * aMinValue is returned.
32 * @see http://www.w3.org/TR/CSS21/visudet.html#min-max-widths
33 * @see http://www.w3.org/TR/CSS21/visudet.html#min-max-heights
35 template <class NumericType
>
36 NumericType
NS_CSS_MINMAX(NumericType aValue
, NumericType aMinValue
,
37 NumericType aMaxValue
) {
38 NumericType result
= aValue
;
39 if (aMaxValue
< result
) result
= aMaxValue
;
40 if (aMinValue
> result
) result
= aMinValue
;
45 * CSS Frame type. Included as part of the reflow input.
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 \
55 5 /* row group frame, row frame, cell frame, ... */
58 * Bit-flag that indicates whether the element is replaced. Applies to inline,
59 * block-level, floating, and absolutely positioned elements
61 #define NS_CSS_FRAME_TYPE_REPLACED 0x08000
64 * Bit-flag that indicates that the element is replaced and contains a block
65 * (eg some form controls). Applies to inline, block-level, floating, and
66 * absolutely positioned elements. Mutually exclusive with
67 * NS_CSS_FRAME_TYPE_REPLACED.
69 #define NS_CSS_FRAME_TYPE_REPLACED_CONTAINS_BLOCK 0x10000
72 * Helper macros for telling whether items are replaced
74 #define NS_FRAME_IS_REPLACED_NOBLOCK(_ft) \
75 (NS_CSS_FRAME_TYPE_REPLACED == ((_ft)&NS_CSS_FRAME_TYPE_REPLACED))
77 #define NS_FRAME_IS_REPLACED(_ft) \
78 (NS_FRAME_IS_REPLACED_NOBLOCK(_ft) || \
79 NS_FRAME_IS_REPLACED_CONTAINS_BLOCK(_ft))
81 #define NS_FRAME_REPLACED(_ft) (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) \
95 ~(NS_CSS_FRAME_TYPE_REPLACED | NS_CSS_FRAME_TYPE_REPLACED_CONTAINS_BLOCK))
99 // A base class of ReflowInput that computes only the padding,
100 // border, and margin, since those values are needed more often.
101 struct SizeComputationInput
{
103 typedef mozilla::WritingMode WritingMode
;
104 typedef mozilla::LogicalMargin LogicalMargin
;
106 // The frame being reflowed.
109 // Rendering context to use for measurement.
110 gfxContext
* mRenderingContext
;
112 const nsMargin
& ComputedPhysicalMargin() const { return mComputedMargin
; }
113 const nsMargin
& ComputedPhysicalBorderPadding() const {
114 return mComputedBorderPadding
;
116 const nsMargin
& ComputedPhysicalPadding() const { return mComputedPadding
; }
118 // We may need to eliminate the (few) users of these writable-reference
119 // accessors 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
);
127 const LogicalMargin
ComputedLogicalBorderPadding() const {
128 return LogicalMargin(mWritingMode
, mComputedBorderPadding
);
130 const LogicalMargin
ComputedLogicalPadding() const {
131 return LogicalMargin(mWritingMode
, mComputedPadding
);
134 void SetComputedLogicalMargin(mozilla::WritingMode aWM
,
135 const LogicalMargin
& aMargin
) {
136 mComputedMargin
= aMargin
.GetPhysicalMargin(aWM
);
138 void SetComputedLogicalMargin(const LogicalMargin
& aMargin
) {
139 SetComputedLogicalMargin(mWritingMode
, aMargin
);
142 void SetComputedLogicalBorderPadding(mozilla::WritingMode aWM
,
143 const LogicalMargin
& aMargin
) {
144 mComputedBorderPadding
= aMargin
.GetPhysicalMargin(aWM
);
146 void SetComputedLogicalBorderPadding(const LogicalMargin
& aMargin
) {
147 SetComputedLogicalBorderPadding(mWritingMode
, aMargin
);
150 void SetComputedLogicalPadding(mozilla::WritingMode aWM
,
151 const LogicalMargin
& aMargin
) {
152 mComputedPadding
= aMargin
.GetPhysicalMargin(aWM
);
154 void SetComputedLogicalPadding(const LogicalMargin
& aMargin
) {
155 SetComputedLogicalPadding(mWritingMode
, aMargin
);
158 WritingMode
GetWritingMode() const { return mWritingMode
; }
161 // cached copy of the frame's writing-mode, for logical coordinates
162 WritingMode mWritingMode
;
164 // These are PHYSICAL coordinates (for now).
165 // Will probably become logical in due course.
167 // Computed margin values
168 nsMargin mComputedMargin
;
170 // Cached copy of the border + padding values
171 nsMargin mComputedBorderPadding
;
173 // Computed padding values
174 nsMargin mComputedPadding
;
177 // Callers using this constructor must call InitOffsets on their own.
178 SizeComputationInput(nsIFrame
* aFrame
, gfxContext
* aRenderingContext
)
180 mRenderingContext(aRenderingContext
),
181 mWritingMode(aFrame
->GetWritingMode()) {}
183 SizeComputationInput(nsIFrame
* aFrame
, gfxContext
* aRenderingContext
,
184 mozilla::WritingMode aContainingBlockWritingMode
,
185 nscoord aContainingBlockISize
);
187 struct ReflowInputFlags
{
188 ReflowInputFlags() { memset(this, 0, sizeof(*this)); }
190 // used by tables to communicate special reflow (in process) to handle
191 // percent bsize frames inside cells which may not have computed bsizes
192 bool mSpecialBSizeReflow
: 1;
194 // nothing in the frame's next-in-flow (or its descendants) is changing
195 bool mNextInFlowUntouched
: 1;
197 // Is the current context at the top of a page? When true, we force
198 // something that's too tall for a page/column to fit anyway to avoid
200 bool mIsTopOfPage
: 1;
202 // parent frame is an nsIScrollableFrame and it is assuming a horizontal
204 bool mAssumingHScrollbar
: 1;
206 // parent frame is an nsIScrollableFrame and it is assuming a vertical
208 bool mAssumingVScrollbar
: 1;
210 // Is frame a different inline-size than before?
213 // Is frame (potentially) a different block-size than before?
214 // This includes cases where the block-size is 'auto' and the
215 // contents or width have changed.
218 // Has this frame changed block-size in a way that affects
219 // block-size percentages on frames for which it is the containing
220 // block? This includes a change between 'auto' and a length that
221 // doesn't actually change the frame's block-size. It does not
222 // include cases where the block-size is 'auto' and the frame's
223 // contents have changed.
225 // In the current code, this is only true when mIsBResize is also
226 // true, although it doesn't necessarily need to be that way (e.g.,
227 // in the case of a frame changing from 'auto' to a length that
228 // produces the same height).
229 bool mIsBResizeForPercentages
: 1;
231 // tables are splittable, this should happen only inside a page and never
232 // insider a column frame
233 bool mTableIsSplittable
: 1;
235 // Does frame height depend on an ancestor table-cell?
236 bool mHeightDependsOnAncestorCell
: 1;
238 // nsColumnSetFrame is balancing columns
239 bool mIsColumnBalancing
: 1;
241 // True if ColumnSetWrapperFrame has a constrained block-size, and is going
242 // to consume all of its block-size in this fragment. This bit is passed to
243 // nsColumnSetFrame to determine whether to give up balancing and create
245 bool mColumnSetWrapperHasNoBSizeLeft
: 1;
247 // nsFlexContainerFrame is reflowing this child to measure its intrinsic
249 bool mIsFlexContainerMeasuringBSize
: 1;
251 // a "fake" reflow input made in order to be the parent of a real one
252 bool mDummyParentReflowInput
: 1;
254 // Should this frame reflow its place-holder children? If the available
255 // height of this frame didn't change, but its in a paginated environment
256 // (e.g. columns), it should always reflow its placeholder children.
257 bool mMustReflowPlaceholders
: 1;
259 // stores the COMPUTE_SIZE_SHRINK_WRAP ctor flag
260 bool mShrinkWrap
: 1;
262 // stores the COMPUTE_SIZE_USE_AUTO_BSIZE ctor flag
263 bool mUseAutoBSize
: 1;
265 // the STATIC_POS_IS_CB_ORIGIN ctor flag
266 bool mStaticPosIsCBOrigin
: 1;
268 // the I_CLAMP_MARGIN_BOX_MIN_SIZE ctor flag
269 bool mIClampMarginBoxMinSize
: 1;
271 // the B_CLAMP_MARGIN_BOX_MIN_SIZE ctor flag
272 bool mBClampMarginBoxMinSize
: 1;
274 // the I_APPLY_AUTO_MIN_SIZE ctor flag
275 bool mApplyAutoMinSize
: 1;
277 // If set, the following two flags indicate that:
278 // (1) this frame is absolutely-positioned (or fixed-positioned).
279 // (2) this frame's static position depends on the CSS Box Alignment.
280 // (3) we do need to compute the static position, because the frame's
281 // {Inline and/or Block} offsets actually depend on it.
282 // When these bits are set, the offset values (IStart/IEnd, BStart/BEnd)
283 // represent the "start" edge of the frame's CSS Box Alignment container
284 // area, in that axis -- and these offsets need to be further-resolved
285 // (with CSS Box Alignment) after we know the OOF frame's size.
286 // NOTE: The "I" and "B" (for "Inline" and "Block") refer the axes of the
287 // *containing block's writing-mode*, NOT mFrame's own writing-mode. This
288 // is purely for convenience, since that's the writing-mode we're dealing
289 // with when we set & react to these bits.
290 bool mIOffsetsNeedCSSAlign
: 1;
291 bool mBOffsetsNeedCSSAlign
: 1;
293 // Are we somewhere inside an element with -webkit-line-clamp set?
294 // This flag is inherited into descendant ReflowInputs, but we don't bother
295 // resetting it to false when crossing over into a block descendant that
296 // -webkit-line-clamp skips over (such as a BFC).
297 bool mInsideLineClamp
: 1;
299 // Is this a flex item, and should we add or remove a -webkit-line-clamp
300 // ellipsis on a descendant line? It's possible for this flag to be true
301 // when mInsideLineClamp is false if we previously had a numeric
302 // -webkit-line-clamp value, but now have 'none' and we need to find the
303 // line with the ellipsis flag and clear it.
304 // This flag is not inherited into descendant ReflowInputs.
305 bool mApplyLineClamp
: 1;
307 // Is this frame or one of its ancestors being reflowed in a different
308 // continuation than the one in which it was previously reflowed? In
309 // other words, has it moved to a different column or page than it was in
310 // the previous reflow?
312 // FIXME: For now, we only ensure that this is set correctly for blocks.
313 // This is okay because the only thing that uses it only cares about
314 // whether there's been a fragment change within the same block formatting
316 bool mMovedBlockFragments
: 1;
320 // Reflow trace methods. Defined in nsFrame.cpp so they have access
321 // to the display-reflow infrastructure.
322 static void* DisplayInitOffsetsEnter(nsIFrame
* aFrame
,
323 SizeComputationInput
* aState
,
324 nscoord aPercentBasis
,
325 WritingMode aCBWritingMode
,
326 const nsMargin
* aBorder
,
327 const nsMargin
* aPadding
);
328 static void DisplayInitOffsetsExit(nsIFrame
* aFrame
,
329 SizeComputationInput
* aState
,
335 * Computes margin values from the specified margin style information, and
336 * fills in the mComputedMargin member.
338 * @param aWM Writing mode of the containing block
339 * @param aPercentBasis
340 * Inline size of the containing block (in its own writing mode), to use
341 * for resolving percentage margin values in the inline and block axes.
342 * @return true if the margin is dependent on the containing block size.
344 bool ComputeMargin(mozilla::WritingMode aWM
, nscoord aPercentBasis
);
347 * Computes padding values from the specified padding style information, and
348 * fills in the mComputedPadding member.
350 * @param aWM Writing mode of the containing block
351 * @param aPercentBasis
352 * Inline size of the containing block (in its own writing mode), to use
353 * for resolving percentage padding values in the inline and block axes.
354 * @return true if the padding is dependent on the containing block size.
356 bool ComputePadding(mozilla::WritingMode aWM
, nscoord aPercentBasis
,
357 mozilla::LayoutFrameType aFrameType
);
360 void InitOffsets(mozilla::WritingMode aWM
, nscoord aPercentBasis
,
361 mozilla::LayoutFrameType aFrameType
, ReflowInputFlags aFlags
,
362 const nsMargin
* aBorder
= nullptr,
363 const nsMargin
* aPadding
= nullptr,
364 const nsStyleDisplay
* aDisplay
= nullptr);
367 * Convert StyleSize or StyleMaxSize to nscoord when percentages depend on the
368 * inline size of the containing block, and enumerated values are for inline
369 * size, min-inline-size, or max-inline-size. Does not handle auto inline
372 template <typename SizeOrMaxSize
>
373 inline nscoord
ComputeISizeValue(nscoord aContainingBlockISize
,
374 nscoord aContentEdgeToBoxSizing
,
375 nscoord aBoxSizingToMarginEdge
,
376 const SizeOrMaxSize
&) const;
377 // same as previous, but using mComputedBorderPadding, mComputedPadding,
378 // and mComputedMargin
379 template <typename SizeOrMaxSize
>
380 inline nscoord
ComputeISizeValue(nscoord aContainingBlockISize
,
381 mozilla::StyleBoxSizing aBoxSizing
,
382 const SizeOrMaxSize
&) const;
384 nscoord
ComputeBSizeValue(nscoord aContainingBlockBSize
,
385 mozilla::StyleBoxSizing aBoxSizing
,
386 const mozilla::LengthPercentage
& aCoord
) const;
390 * State passed to a frame during reflow or intrinsic size calculation.
392 * XXX Refactor so only a base class (nsSizingState?) is used for intrinsic
395 * @see nsIFrame#Reflow()
397 struct ReflowInput
: public SizeComputationInput
{
398 // the reflow inputs are linked together. this is the pointer to the
399 // parent's reflow input
400 const ReflowInput
* mParentReflowInput
= nullptr;
402 // A non-owning pointer to the float manager associated with this area,
403 // which points to the object owned by nsAutoFloatManager::mNew.
404 nsFloatManager
* mFloatManager
= nullptr;
406 // LineLayout object (only for inline reflow; set to nullptr otherwise)
407 nsLineLayout
* mLineLayout
= nullptr;
409 // The appropriate reflow input for the containing block (for
410 // percentage widths, etc.) of this reflow input's frame. It will be setup
411 // properly in InitCBReflowInput().
412 const ReflowInput
* mCBReflowInput
= nullptr;
414 // The type of frame, from css's perspective. This value is
415 // initialized by the Init method below.
416 nsCSSFrameType mFrameType
= NS_CSS_FRAME_TYPE_UNKNOWN
;
418 // The amount the in-flow position of the block is moving vertically relative
419 // to its previous in-flow position (i.e. the amount the line containing the
421 // This should be zero for anything which is not a block outside, and it
422 // should be zero for anything which has a non-block parent.
423 // The intended use of this value is to allow the accurate determination
424 // of the potential impact of a float
425 // This takes on an arbitrary value the first time a block is reflowed
426 nscoord mBlockDelta
= 0;
428 // If a ReflowInput finds itself initialized with an unconstrained
429 // inline-size, it will look up its parentReflowInput chain for a reflow input
430 // with an orthogonal writing mode and a non-NS_UNCONSTRAINEDSIZE value for
431 // orthogonal limit; when it finds such a reflow input, it will use its
432 // orthogonal-limit value to constrain inline-size.
433 // This is initialized to NS_UNCONSTRAINEDSIZE (so it will be ignored),
434 // but reset to a suitable value for the reflow root by PresShell.
435 nscoord mOrthogonalLimit
= NS_UNCONSTRAINEDSIZE
;
437 // Accessors for the private fields below. Forcing all callers to use these
438 // will allow us to introduce logical-coordinate versions and gradually
439 // change clients from physical to logical as needed; and potentially switch
440 // the internal fields from physical to logical coordinates in due course,
441 // while maintaining compatibility with not-yet-updated code.
442 nscoord
AvailableWidth() const { return mAvailableWidth
; }
443 nscoord
AvailableHeight() const { return mAvailableHeight
; }
444 nscoord
ComputedWidth() const { return mComputedWidth
; }
445 nscoord
ComputedHeight() const { return mComputedHeight
; }
446 nscoord
ComputedMinWidth() const { return mComputedMinWidth
; }
447 nscoord
ComputedMaxWidth() const { return mComputedMaxWidth
; }
448 nscoord
ComputedMinHeight() const { return mComputedMinHeight
; }
449 nscoord
ComputedMaxHeight() const { return mComputedMaxHeight
; }
451 nscoord
& AvailableWidth() { return mAvailableWidth
; }
452 nscoord
& AvailableHeight() { return mAvailableHeight
; }
453 nscoord
& ComputedWidth() { return mComputedWidth
; }
454 nscoord
& ComputedHeight() { return mComputedHeight
; }
455 nscoord
& ComputedMinWidth() { return mComputedMinWidth
; }
456 nscoord
& ComputedMaxWidth() { return mComputedMaxWidth
; }
457 nscoord
& ComputedMinHeight() { return mComputedMinHeight
; }
458 nscoord
& ComputedMaxHeight() { return mComputedMaxHeight
; }
460 // ISize and BSize are logical-coordinate dimensions:
461 // ISize is the size in the writing mode's inline direction (which equates to
462 // width in horizontal writing modes, height in vertical ones), and BSize is
463 // the size in the block-progression direction.
464 nscoord
AvailableISize() const {
465 return mWritingMode
.IsVertical() ? mAvailableHeight
: mAvailableWidth
;
467 nscoord
AvailableBSize() const {
468 return mWritingMode
.IsVertical() ? mAvailableWidth
: mAvailableHeight
;
470 nscoord
ComputedISize() const {
471 return mWritingMode
.IsVertical() ? mComputedHeight
: mComputedWidth
;
473 nscoord
ComputedBSize() const {
474 return mWritingMode
.IsVertical() ? mComputedWidth
: mComputedHeight
;
476 nscoord
ComputedMinISize() const {
477 return mWritingMode
.IsVertical() ? mComputedMinHeight
: mComputedMinWidth
;
479 nscoord
ComputedMaxISize() const {
480 return mWritingMode
.IsVertical() ? mComputedMaxHeight
: mComputedMaxWidth
;
482 nscoord
ComputedMinBSize() const {
483 return mWritingMode
.IsVertical() ? mComputedMinWidth
: mComputedMinHeight
;
485 nscoord
ComputedMaxBSize() const {
486 return mWritingMode
.IsVertical() ? mComputedMaxWidth
: mComputedMaxHeight
;
489 nscoord
& AvailableISize() {
490 return mWritingMode
.IsVertical() ? mAvailableHeight
: mAvailableWidth
;
492 nscoord
& AvailableBSize() {
493 return mWritingMode
.IsVertical() ? mAvailableWidth
: mAvailableHeight
;
495 nscoord
& ComputedISize() {
496 return mWritingMode
.IsVertical() ? mComputedHeight
: mComputedWidth
;
498 nscoord
& ComputedBSize() {
499 return mWritingMode
.IsVertical() ? mComputedWidth
: mComputedHeight
;
501 nscoord
& ComputedMinISize() {
502 return mWritingMode
.IsVertical() ? mComputedMinHeight
: mComputedMinWidth
;
504 nscoord
& ComputedMaxISize() {
505 return mWritingMode
.IsVertical() ? mComputedMaxHeight
: mComputedMaxWidth
;
507 nscoord
& ComputedMinBSize() {
508 return mWritingMode
.IsVertical() ? mComputedMinWidth
: mComputedMinHeight
;
510 nscoord
& ComputedMaxBSize() {
511 return mWritingMode
.IsVertical() ? mComputedMaxWidth
: mComputedMaxHeight
;
514 mozilla::LogicalSize
AvailableSize() const {
515 return mozilla::LogicalSize(mWritingMode
, AvailableISize(),
518 mozilla::LogicalSize
ComputedSize() const {
519 return mozilla::LogicalSize(mWritingMode
, ComputedISize(), ComputedBSize());
521 mozilla::LogicalSize
ComputedMinSize() const {
522 return mozilla::LogicalSize(mWritingMode
, ComputedMinISize(),
525 mozilla::LogicalSize
ComputedMaxSize() const {
526 return mozilla::LogicalSize(mWritingMode
, ComputedMaxISize(),
530 mozilla::LogicalSize
AvailableSize(mozilla::WritingMode aWM
) const {
531 return AvailableSize().ConvertTo(aWM
, mWritingMode
);
533 mozilla::LogicalSize
ComputedSize(mozilla::WritingMode aWM
) const {
534 return ComputedSize().ConvertTo(aWM
, mWritingMode
);
536 mozilla::LogicalSize
ComputedMinSize(mozilla::WritingMode aWM
) const {
537 return ComputedMinSize().ConvertTo(aWM
, mWritingMode
);
539 mozilla::LogicalSize
ComputedMaxSize(mozilla::WritingMode aWM
) const {
540 return ComputedMaxSize().ConvertTo(aWM
, mWritingMode
);
543 mozilla::LogicalSize
ComputedSizeWithPadding() const {
544 mozilla::WritingMode wm
= GetWritingMode();
545 return mozilla::LogicalSize(
546 wm
, ComputedISize() + ComputedLogicalPadding().IStartEnd(wm
),
547 ComputedBSize() + ComputedLogicalPadding().BStartEnd(wm
));
550 mozilla::LogicalSize
ComputedSizeWithPadding(mozilla::WritingMode aWM
) const {
551 return ComputedSizeWithPadding().ConvertTo(aWM
, GetWritingMode());
554 mozilla::LogicalSize
ComputedSizeWithBorderPadding() const {
555 mozilla::WritingMode wm
= GetWritingMode();
556 return mozilla::LogicalSize(
557 wm
, ComputedISize() + ComputedLogicalBorderPadding().IStartEnd(wm
),
558 ComputedBSize() + ComputedLogicalBorderPadding().BStartEnd(wm
));
561 mozilla::LogicalSize
ComputedSizeWithBorderPadding(
562 mozilla::WritingMode aWM
) const {
563 return ComputedSizeWithBorderPadding().ConvertTo(aWM
, GetWritingMode());
566 mozilla::LogicalSize
ComputedSizeWithMarginBorderPadding() const {
567 mozilla::WritingMode wm
= GetWritingMode();
568 return mozilla::LogicalSize(
570 ComputedISize() + ComputedLogicalMargin().IStartEnd(wm
) +
571 ComputedLogicalBorderPadding().IStartEnd(wm
),
572 ComputedBSize() + ComputedLogicalMargin().BStartEnd(wm
) +
573 ComputedLogicalBorderPadding().BStartEnd(wm
));
576 mozilla::LogicalSize
ComputedSizeWithMarginBorderPadding(
577 mozilla::WritingMode aWM
) const {
578 return ComputedSizeWithMarginBorderPadding().ConvertTo(aWM
,
582 nsSize
ComputedPhysicalSize() const {
583 return nsSize(ComputedWidth(), ComputedHeight());
586 // XXX this will need to change when we make mComputedOffsets logical;
587 // we won't be able to return a reference for the physical offsets
588 const nsMargin
& ComputedPhysicalOffsets() const { return mComputedOffsets
; }
589 nsMargin
& ComputedPhysicalOffsets() { return mComputedOffsets
; }
591 const LogicalMargin
ComputedLogicalOffsets() const {
592 return LogicalMargin(mWritingMode
, mComputedOffsets
);
595 void SetComputedLogicalOffsets(const LogicalMargin
& aOffsets
) {
596 mComputedOffsets
= aOffsets
.GetPhysicalMargin(mWritingMode
);
599 // Return the state's computed size including border-padding, with
600 // unconstrained dimensions replaced by zero.
601 nsSize
ComputedSizeAsContainerIfConstrained() const {
602 const nscoord wd
= ComputedWidth();
603 const nscoord ht
= ComputedHeight();
604 return nsSize(wd
== NS_UNCONSTRAINEDSIZE
606 : wd
+ ComputedPhysicalBorderPadding().LeftRight(),
607 ht
== NS_UNCONSTRAINEDSIZE
609 : ht
+ ComputedPhysicalBorderPadding().TopBottom());
613 // the available width in which to reflow the frame. The space
614 // represents the amount of room for the frame's margin, border,
615 // padding, and content area. The frame size you choose should fit
616 // within the available width.
617 nscoord mAvailableWidth
= 0;
619 // A value of NS_UNCONSTRAINEDSIZE for the available height means
620 // you can choose whatever size you want. In galley mode the
621 // available height is always NS_UNCONSTRAINEDSIZE, and only page
622 // mode or multi-column layout involves a constrained height. The
623 // element's the top border and padding, and content, must fit. If the
624 // element is complete after reflow then its bottom border, padding
625 // and margin (and similar for its complete ancestors) will need to
626 // fit in this height.
627 nscoord mAvailableHeight
= 0;
629 // The computed width specifies the frame's content area width, and it does
630 // not apply to inline non-replaced elements
632 // For replaced inline frames, a value of NS_UNCONSTRAINEDSIZE means you
633 // should use your intrinsic width as the computed width
635 // For block-level frames, the computed width is based on the width of the
636 // containing block, the margin/border/padding areas, and the min/max width.
637 MOZ_INIT_OUTSIDE_CTOR
638 nscoord mComputedWidth
;
640 // The computed height specifies the frame's content height, and it does
641 // not apply to inline non-replaced elements
643 // For replaced inline frames, a value of NS_UNCONSTRAINEDSIZE means you
644 // should use your intrinsic height as the computed height
646 // For non-replaced block-level frames in the flow and floated, a value of
647 // NS_UNCONSTRAINEDSIZE means you choose a height to shrink wrap around the
648 // normal flow child frames. The height must be within the limit of the
649 // min/max height if there is such a limit
651 // For replaced block-level frames, a value of NS_UNCONSTRAINEDSIZE
652 // means you use your intrinsic height as the computed height
653 MOZ_INIT_OUTSIDE_CTOR
654 nscoord mComputedHeight
;
656 // Computed values for 'left/top/right/bottom' offsets. Only applies to
657 // 'positioned' elements. These are PHYSICAL coordinates (for now).
658 nsMargin mComputedOffsets
;
660 // Computed values for 'min-width/max-width' and 'min-height/max-height'
661 // XXXldb The width ones here should go; they should be needed only
662 // internally, except for nsComboboxDisplayFrame, which still wants to honor
663 // min-inline-size even though it wants to trump inline-size.
664 MOZ_INIT_OUTSIDE_CTOR
665 nscoord mComputedMinWidth
, mComputedMaxWidth
;
666 MOZ_INIT_OUTSIDE_CTOR
667 nscoord mComputedMinHeight
, mComputedMaxHeight
;
670 // Our saved containing block dimensions.
671 LogicalSize mContainingBlockSize
= LogicalSize(mWritingMode
);
673 // Cached pointers to the various style structs used during initialization.
674 const nsStyleDisplay
* mStyleDisplay
= nullptr;
675 const nsStyleVisibility
* mStyleVisibility
= nullptr;
676 const nsStylePosition
* mStylePosition
= nullptr;
677 const nsStyleBorder
* mStyleBorder
= nullptr;
678 const nsStyleMargin
* mStyleMargin
= nullptr;
679 const nsStylePadding
* mStylePadding
= nullptr;
680 const nsStyleText
* mStyleText
= nullptr;
682 bool IsFloating() const;
684 mozilla::StyleDisplay
GetDisplay() const;
686 // a frame (e.g. nsTableCellFrame) which may need to generate a special
687 // reflow for percent bsize calculations
688 nsIPercentBSizeObserver
* mPercentBSizeObserver
= nullptr;
690 // CSS margin collapsing sometimes requires us to reflow
691 // optimistically assuming that margins collapse to see if clearance
692 // is required. When we discover that clearance is required, we
693 // store the frame in which clearance was discovered to the location
695 nsIFrame
** mDiscoveredClearance
= nullptr;
697 ReflowInputFlags mFlags
;
699 // This value keeps track of how deeply nested a given reflow input
700 // is from the top of the frame tree.
701 int16_t mReflowDepth
= 0;
703 // Logical and physical accessors for the resize flags. All users should go
704 // via these accessors, so that in due course we can change the storage from
705 // physical to logical.
706 bool IsHResize() const {
707 return mWritingMode
.IsVertical() ? mFlags
.mIsBResize
: mFlags
.mIsIResize
;
709 bool IsVResize() const {
710 return mWritingMode
.IsVertical() ? mFlags
.mIsIResize
: mFlags
.mIsBResize
;
712 bool IsIResize() const { return mFlags
.mIsIResize
; }
713 bool IsBResize() const { return mFlags
.mIsBResize
; }
714 bool IsBResizeForWM(mozilla::WritingMode aWM
) const {
715 return aWM
.IsOrthogonalTo(mWritingMode
) ? mFlags
.mIsIResize
718 bool IsBResizeForPercentagesForWM(mozilla::WritingMode aWM
) const {
719 // This uses the relatively-accurate mIsBResizeForPercentages flag
720 // when the writing modes are parallel, and is a bit more
721 // pessimistic when orthogonal.
722 return !aWM
.IsOrthogonalTo(mWritingMode
) ? mFlags
.mIsBResizeForPercentages
725 void SetHResize(bool aValue
) {
726 if (mWritingMode
.IsVertical()) {
727 mFlags
.mIsBResize
= aValue
;
729 mFlags
.mIsIResize
= aValue
;
732 void SetVResize(bool aValue
) {
733 if (mWritingMode
.IsVertical()) {
734 mFlags
.mIsIResize
= aValue
;
736 mFlags
.mIsBResize
= aValue
;
739 void SetIResize(bool aValue
) { mFlags
.mIsIResize
= aValue
; }
740 void SetBResize(bool aValue
) { mFlags
.mIsBResize
= aValue
; }
742 // Note: The copy constructor is written by the compiler automatically. You
743 // can use that and then override specific values if you want, or you can
744 // call Init as desired...
747 * Initialize a ROOT reflow input.
749 * @param aPresContext Must be equal to aFrame->PresContext().
750 * @param aFrame The frame for whose reflow input is being constructed.
751 * @param aRenderingContext The rendering context to be used for measurements.
752 * @param aAvailableSpace See comments for availableHeight and availableWidth
754 * @param aFlags A set of flags used for additional boolean parameters (see
757 ReflowInput(nsPresContext
* aPresContext
, nsIFrame
* aFrame
,
758 gfxContext
* aRenderingContext
,
759 const mozilla::LogicalSize
& aAvailableSpace
, uint32_t aFlags
= 0);
762 * Initialize a reflow input for a child frame's reflow. Some parts of the
763 * state are copied from the parent's reflow input. The remainder is computed.
765 * @param aPresContext Must be equal to aFrame->PresContext().
766 * @param aParentReflowInput A reference to an ReflowInput object that
767 * is to be the parent of this object.
768 * @param aFrame The frame for whose reflow input is being constructed.
769 * @param aAvailableSpace See comments for availableHeight and availableWidth
771 * @param aContainingBlockSize An optional size, in app units, specifying
772 * the containing block size to use instead of the default which is
773 * computed by ComputeContainingBlockRectangle().
774 * @param aFlags A set of flags used for additional boolean parameters (see
777 ReflowInput(nsPresContext
* aPresContext
,
778 const ReflowInput
& aParentReflowInput
, nsIFrame
* aFrame
,
779 const mozilla::LogicalSize
& aAvailableSpace
,
780 const mozilla::Maybe
<mozilla::LogicalSize
>& aContainingBlockSize
=
782 uint32_t aFlags
= 0);
784 // Values for |aFlags| passed to constructor
786 // Indicates that the parent of this reflow input is "fake" (see
787 // mDummyParentReflowInput in mFlags).
788 DUMMY_PARENT_REFLOW_INPUT
= (1 << 0),
790 // Indicates that the calling function will initialize the reflow input, and
791 // that the constructor should not call Init().
792 CALLER_WILL_INIT
= (1 << 1),
794 // The caller wants shrink-wrap behavior (i.e. ComputeSizeFlags::eShrinkWrap
795 // will be passed to ComputeSize()).
796 COMPUTE_SIZE_SHRINK_WRAP
= (1 << 2),
798 // The caller wants 'auto' bsize behavior (ComputeSizeFlags::eUseAutoBSize
799 // will be be passed to ComputeSize()).
800 COMPUTE_SIZE_USE_AUTO_BSIZE
= (1 << 3),
802 // The caller wants the abs.pos. static-position resolved at the origin of
803 // the containing block, i.e. at LogicalPoint(0, 0). (Note that this
804 // doesn't necessarily mean that (0, 0) is the *correct* static position
805 // for the frame in question.)
806 STATIC_POS_IS_CB_ORIGIN
= (1 << 4),
808 // Pass ComputeSizeFlags::eIClampMarginBoxMinSize to ComputeSize().
809 I_CLAMP_MARGIN_BOX_MIN_SIZE
= (1 << 5),
811 // Pass ComputeSizeFlags::eBClampMarginBoxMinSize to ComputeSize().
812 B_CLAMP_MARGIN_BOX_MIN_SIZE
= (1 << 6),
814 // Pass ComputeSizeFlags::eIApplyAutoMinSize to ComputeSize().
815 I_APPLY_AUTO_MIN_SIZE
= (1 << 7),
818 // This method initializes various data members. It is automatically
819 // called by the various constructors
820 void Init(nsPresContext
* aPresContext
,
821 const mozilla::Maybe
<mozilla::LogicalSize
>& aContainingBlockSize
=
823 const nsMargin
* aBorder
= nullptr,
824 const nsMargin
* aPadding
= nullptr);
827 * Find the content isize of our containing block for the given writing mode,
828 * which need not be the same as the reflow input's mode.
830 nscoord
GetContainingBlockContentISize(
831 mozilla::WritingMode aWritingMode
) const;
834 * Calculate the used line-height property. The return value will be >= 0.
836 nscoord
CalcLineHeight() const;
839 * Same as CalcLineHeight() above, but doesn't need a reflow input.
841 * @param aBlockBSize The computed block size of the content rect of the block
842 * that the line should fill.
843 * Only used with line-height:-moz-block-height.
844 * NS_UNCONSTRAINEDSIZE results in a normal line-height
845 * for line-height:-moz-block-height.
846 * @param aFontSizeInflation The result of the appropriate
847 * nsLayoutUtils::FontSizeInflationFor call,
848 * or 1.0 if during intrinsic size
851 static nscoord
CalcLineHeight(nsIContent
* aContent
,
852 ComputedStyle
* aComputedStyle
,
853 nsPresContext
* aPresContext
,
854 nscoord aBlockBSize
, float aFontSizeInflation
);
856 mozilla::LogicalSize
ComputeContainingBlockRectangle(
857 nsPresContext
* aPresContext
, const ReflowInput
* aContainingBlockRI
) const;
860 * Apply the mComputed(Min/Max)Width constraints to the content
861 * size computed so far.
863 nscoord
ApplyMinMaxWidth(nscoord aWidth
) const {
864 if (NS_UNCONSTRAINEDSIZE
!= ComputedMaxWidth()) {
865 aWidth
= std::min(aWidth
, ComputedMaxWidth());
867 return std::max(aWidth
, ComputedMinWidth());
871 * Apply the mComputed(Min/Max)ISize constraints to the content
872 * size computed so far.
874 nscoord
ApplyMinMaxISize(nscoord aISize
) const {
875 if (NS_UNCONSTRAINEDSIZE
!= ComputedMaxISize()) {
876 aISize
= std::min(aISize
, ComputedMaxISize());
878 return std::max(aISize
, ComputedMinISize());
882 * Apply the mComputed(Min/Max)Height constraints to the content
883 * size computed so far.
885 * @param aHeight The height that we've computed an to which we want to apply
886 * min/max constraints.
887 * @param aConsumed The amount of the computed height that was consumed by
890 nscoord
ApplyMinMaxHeight(nscoord aHeight
, nscoord aConsumed
= 0) const {
891 aHeight
+= aConsumed
;
893 if (NS_UNCONSTRAINEDSIZE
!= ComputedMaxHeight()) {
894 aHeight
= std::min(aHeight
, ComputedMaxHeight());
897 if (NS_UNCONSTRAINEDSIZE
!= ComputedMinHeight()) {
898 aHeight
= std::max(aHeight
, ComputedMinHeight());
901 return aHeight
- aConsumed
;
905 * Apply the mComputed(Min/Max)BSize constraints to the content
906 * size computed so far.
908 * @param aBSize The block-size that we've computed an to which we want to
909 * apply min/max constraints.
910 * @param aConsumed The amount of the computed block-size that was consumed by
913 nscoord
ApplyMinMaxBSize(nscoord aBSize
, nscoord aConsumed
= 0) const {
916 if (NS_UNCONSTRAINEDSIZE
!= ComputedMaxBSize()) {
917 aBSize
= std::min(aBSize
, ComputedMaxBSize());
920 if (NS_UNCONSTRAINEDSIZE
!= ComputedMinBSize()) {
921 aBSize
= std::max(aBSize
, ComputedMinBSize());
924 return aBSize
- aConsumed
;
927 bool ShouldReflowAllKids() const {
928 // Note that we could make a stronger optimization for IsBResize if
929 // we use it in a ShouldReflowChild test that replaces the current
930 // checks of NS_FRAME_IS_DIRTY | NS_FRAME_HAS_DIRTY_CHILDREN, if it
931 // were tested there along with NS_FRAME_CONTAINS_RELATIVE_BSIZE.
932 // This would need to be combined with a slight change in which
933 // frames NS_FRAME_CONTAINS_RELATIVE_BSIZE is marked on.
934 return (mFrame
->GetStateBits() & NS_FRAME_IS_DIRTY
) || IsIResize() ||
936 (mFrame
->GetStateBits() & NS_FRAME_CONTAINS_RELATIVE_BSIZE
));
939 // This method doesn't apply min/max computed widths to the value passed in.
940 void SetComputedWidth(nscoord aComputedWidth
);
942 // This method doesn't apply min/max computed heights to the value passed in.
943 void SetComputedHeight(nscoord aComputedHeight
);
945 void SetComputedISize(nscoord aComputedISize
) {
946 if (mWritingMode
.IsVertical()) {
947 SetComputedHeight(aComputedISize
);
949 SetComputedWidth(aComputedISize
);
953 void SetComputedBSize(nscoord aComputedBSize
) {
954 if (mWritingMode
.IsVertical()) {
955 SetComputedWidth(aComputedBSize
);
957 SetComputedHeight(aComputedBSize
);
961 void SetComputedBSizeWithoutResettingResizeFlags(nscoord aComputedBSize
) {
962 // Viewport frames reset the computed block size on a copy of their reflow
963 // input when reflowing fixed-pos kids. In that case we actually don't
964 // want to mess with the resize flags, because comparing the frame's rect
965 // to the munged computed isize is pointless.
966 ComputedBSize() = aComputedBSize
;
969 void SetTruncated(const ReflowOutput
& aMetrics
,
970 nsReflowStatus
* aStatus
) const;
972 bool WillReflowAgainForClearance() const {
973 return mDiscoveredClearance
&& *mDiscoveredClearance
;
976 // Compute the offsets for a relative position element
977 static void ComputeRelativeOffsets(mozilla::WritingMode aWM
, nsIFrame
* aFrame
,
978 const mozilla::LogicalSize
& aCBSize
,
979 nsMargin
& aComputedOffsets
);
981 // If a relatively positioned element, adjust the position appropriately.
982 static void ApplyRelativePositioning(nsIFrame
* aFrame
,
983 const nsMargin
& aComputedOffsets
,
986 void ApplyRelativePositioning(nsPoint
* aPosition
) const {
987 ApplyRelativePositioning(mFrame
, ComputedPhysicalOffsets(), aPosition
);
990 static void ApplyRelativePositioning(
991 nsIFrame
* aFrame
, mozilla::WritingMode aWritingMode
,
992 const mozilla::LogicalMargin
& aComputedOffsets
,
993 mozilla::LogicalPoint
* aPosition
, const nsSize
& aContainerSize
) {
994 // Subtract the size of the frame from the container size that we
995 // use for converting between the logical and physical origins of
996 // the frame. This accounts for the fact that logical origins in RTL
997 // coordinate systems are at the top right of the frame instead of
999 nsSize frameSize
= aFrame
->GetSize();
1001 aPosition
->GetPhysicalPoint(aWritingMode
, aContainerSize
- frameSize
);
1002 ApplyRelativePositioning(
1003 aFrame
, aComputedOffsets
.GetPhysicalMargin(aWritingMode
), &pos
);
1005 mozilla::LogicalPoint(aWritingMode
, pos
, aContainerSize
- frameSize
);
1008 void ApplyRelativePositioning(mozilla::LogicalPoint
* aPosition
,
1009 const nsSize
& aContainerSize
) const {
1010 ApplyRelativePositioning(mFrame
, mWritingMode
, ComputedLogicalOffsets(),
1011 aPosition
, aContainerSize
);
1015 // Reflow trace methods. Defined in nsFrame.cpp so they have access
1016 // to the display-reflow infrastructure.
1017 static void* DisplayInitConstraintsEnter(nsIFrame
* aFrame
,
1018 ReflowInput
* aState
,
1019 nscoord aCBISize
, nscoord aCBBSize
,
1020 const nsMargin
* aBorder
,
1021 const nsMargin
* aPadding
);
1022 static void DisplayInitConstraintsExit(nsIFrame
* aFrame
, ReflowInput
* aState
,
1024 static void* DisplayInitFrameTypeEnter(nsIFrame
* aFrame
, ReflowInput
* aState
);
1025 static void DisplayInitFrameTypeExit(nsIFrame
* aFrame
, ReflowInput
* aState
,
1030 void InitFrameType(LayoutFrameType aFrameType
);
1031 void InitCBReflowInput();
1032 void InitResizeFlags(nsPresContext
* aPresContext
,
1033 mozilla::LayoutFrameType aFrameType
);
1034 void InitDynamicReflowRoot();
1036 void InitConstraints(
1037 nsPresContext
* aPresContext
,
1038 const mozilla::Maybe
<mozilla::LogicalSize
>& aContainingBlockSize
,
1039 const nsMargin
* aBorder
, const nsMargin
* aPadding
,
1040 mozilla::LayoutFrameType aFrameType
);
1042 // Returns the nearest containing block or block frame (whether or not
1043 // it is a containing block) for the specified frame. Also returns
1044 // the inline-start edge and logical size of the containing block's
1046 // These are returned in the coordinate space of the containing block.
1047 nsIFrame
* GetHypotheticalBoxContainer(nsIFrame
* aFrame
,
1048 nscoord
& aCBIStartEdge
,
1049 mozilla::LogicalSize
& aCBSize
) const;
1051 // Calculate a "hypothetical box" position where the placeholder frame
1052 // (for a position:fixed/absolute element) would have been placed if it were
1053 // positioned statically. The hypothetical box position will have a writing
1054 // mode with the same block direction as the absolute containing block
1055 // (aCBReflowInput->frame), though it may differ in inline direction.
1056 void CalculateHypotheticalPosition(nsPresContext
* aPresContext
,
1057 nsPlaceholderFrame
* aPlaceholderFrame
,
1058 const ReflowInput
* aCBReflowInput
,
1059 nsHypotheticalPosition
& aHypotheticalPos
,
1060 mozilla::LayoutFrameType aFrameType
) const;
1062 void InitAbsoluteConstraints(nsPresContext
* aPresContext
,
1063 const ReflowInput
* aCBReflowInput
,
1064 const mozilla::LogicalSize
& aContainingBlockSize
,
1065 mozilla::LayoutFrameType aFrameType
);
1067 // Calculates the computed values for the 'min-Width', 'max-Width',
1068 // 'min-Height', and 'max-Height' properties, and stores them in the assorted
1070 void ComputeMinMaxValues(const mozilla::LogicalSize
& aContainingBlockSize
);
1072 // aInsideBoxSizing returns the part of the padding, border, and margin
1073 // in the aAxis dimension that goes inside the edge given by box-sizing;
1074 // aOutsideBoxSizing returns the rest.
1075 void CalculateBorderPaddingMargin(mozilla::LogicalAxis aAxis
,
1076 nscoord aContainingBlockSize
,
1077 nscoord
* aInsideBoxSizing
,
1078 nscoord
* aOutsideBoxSizing
) const;
1080 void CalculateBlockSideMargins(LayoutFrameType aFrameType
);
1083 } // namespace mozilla
1085 #endif // mozilla_ReflowInput_h