Source code

Revision control

Other Tools

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/. */
6
7
/* struct containing the input to nsIFrame::Reflow */
8
9
#include "mozilla/ReflowInput.h"
10
11
#include "LayoutLogging.h"
12
#include "nsStyleConsts.h"
13
#include "nsCSSAnonBoxes.h"
14
#include "nsFrame.h"
15
#include "nsIContent.h"
16
#include "nsGkAtoms.h"
17
#include "nsPresContext.h"
18
#include "nsFontMetrics.h"
19
#include "nsBlockFrame.h"
20
#include "nsLineBox.h"
21
#include "nsImageFrame.h"
22
#include "nsTableFrame.h"
23
#include "nsTableCellFrame.h"
24
#include "nsIPercentBSizeObserver.h"
25
#include "nsLayoutUtils.h"
26
#include "mozilla/Preferences.h"
27
#include "nsFontInflationData.h"
28
#include "StickyScrollContainer.h"
29
#include "nsIFrameInlines.h"
30
#include "CounterStyleManager.h"
31
#include <algorithm>
32
#include "mozilla/dom/HTMLInputElement.h"
33
#include "nsGridContainerFrame.h"
34
35
using namespace mozilla;
36
using namespace mozilla::css;
37
using namespace mozilla::dom;
38
using namespace mozilla::layout;
39
40
enum eNormalLineHeightControl {
41
eUninitialized = -1,
42
eNoExternalLeading = 0, // does not include external leading
43
eIncludeExternalLeading, // use whatever value font vendor provides
44
eCompensateLeading // compensate leading if leading provided by font vendor
45
// is not enough
46
};
47
48
static eNormalLineHeightControl sNormalLineHeightControl = eUninitialized;
49
50
// Initialize a <b>root</b> reflow input with a rendering context to
51
// use for measuring things.
52
ReflowInput::ReflowInput(nsPresContext* aPresContext, nsIFrame* aFrame,
53
gfxContext* aRenderingContext,
54
const LogicalSize& aAvailableSpace, uint32_t aFlags)
55
: SizeComputationInput(aFrame, aRenderingContext) {
56
MOZ_ASSERT(aRenderingContext, "no rendering context");
57
MOZ_ASSERT(aPresContext, "no pres context");
58
MOZ_ASSERT(aFrame, "no frame");
59
MOZ_ASSERT(aPresContext == aFrame->PresContext(), "wrong pres context");
60
AvailableISize() = aAvailableSpace.ISize(mWritingMode);
61
AvailableBSize() = aAvailableSpace.BSize(mWritingMode);
62
63
if (aFlags & DUMMY_PARENT_REFLOW_INPUT) {
64
mFlags.mDummyParentReflowInput = true;
65
}
66
if (aFlags & COMPUTE_SIZE_SHRINK_WRAP) {
67
mFlags.mShrinkWrap = true;
68
}
69
if (aFlags & COMPUTE_SIZE_USE_AUTO_BSIZE) {
70
mFlags.mUseAutoBSize = true;
71
}
72
if (aFlags & STATIC_POS_IS_CB_ORIGIN) {
73
mFlags.mStaticPosIsCBOrigin = true;
74
}
75
if (aFlags & I_CLAMP_MARGIN_BOX_MIN_SIZE) {
76
mFlags.mIClampMarginBoxMinSize = true;
77
}
78
if (aFlags & B_CLAMP_MARGIN_BOX_MIN_SIZE) {
79
mFlags.mBClampMarginBoxMinSize = true;
80
}
81
if (aFlags & I_APPLY_AUTO_MIN_SIZE) {
82
mFlags.mApplyAutoMinSize = true;
83
}
84
85
if (!(aFlags & CALLER_WILL_INIT)) {
86
Init(aPresContext);
87
}
88
}
89
90
static bool CheckNextInFlowParenthood(nsIFrame* aFrame, nsIFrame* aParent) {
91
nsIFrame* frameNext = aFrame->GetNextInFlow();
92
nsIFrame* parentNext = aParent->GetNextInFlow();
93
return frameNext && parentNext && frameNext->GetParent() == parentNext;
94
}
95
96
/**
97
* Adjusts the margin for a list (ol, ul), if necessary, depending on
98
* font inflation settings. Unfortunately, because bullets from a list are
99
* placed in the margin area, we only have ~40px in which to place the
100
* bullets. When they are inflated, however, this causes problems, since
101
* the text takes up more space than is available in the margin.
102
*
103
* This method will return a small amount (in app units) by which the
104
* margin can be adjusted, so that the space is available for list
105
* bullets to be rendered with font inflation enabled.
106
*/
107
static nscoord FontSizeInflationListMarginAdjustment(const nsIFrame* aFrame) {
108
if (!aFrame->IsBlockFrameOrSubclass()) {
109
return 0;
110
}
111
112
// We only want to adjust the margins if we're dealing with an ordered list.
113
const nsBlockFrame* blockFrame = static_cast<const nsBlockFrame*>(aFrame);
114
if (!blockFrame->HasMarker()) {
115
return 0;
116
}
117
118
float inflation = nsLayoutUtils::FontSizeInflationFor(aFrame);
119
if (inflation <= 1.0f) {
120
return 0;
121
}
122
123
// The HTML spec states that the default padding for ordered lists
124
// begins at 40px, indicating that we have 40px of space to place a
125
// bullet. When performing font inflation calculations, we add space
126
// equivalent to this, but simply inflated at the same amount as the
127
// text, in app units.
128
auto margin = nsPresContext::CSSPixelsToAppUnits(40) * (inflation - 1);
129
130
auto* list = aFrame->StyleList();
131
if (!list->mCounterStyle.IsAtom()) {
132
return margin;
133
}
134
135
// NOTE(emilio): @counter-style can override some of the styles from this
136
// list, and we won't add margin to the counter.
137
//
139
nsAtom* type = list->mCounterStyle.AsAtom();
140
if (type != nsGkAtoms::none && type != nsGkAtoms::disc &&
141
type != nsGkAtoms::circle && type != nsGkAtoms::square &&
142
type != nsGkAtoms::disclosure_closed &&
143
type != nsGkAtoms::disclosure_open) {
144
return margin;
145
}
146
147
return 0;
148
}
149
150
SizeComputationInput::SizeComputationInput(
151
nsIFrame* aFrame, gfxContext* aRenderingContext,
152
WritingMode aContainingBlockWritingMode, nscoord aContainingBlockISize)
153
: mFrame(aFrame),
154
mRenderingContext(aRenderingContext),
155
mWritingMode(aFrame->GetWritingMode()) {
156
ReflowInputFlags flags;
157
InitOffsets(aContainingBlockWritingMode, aContainingBlockISize,
158
mFrame->Type(), flags);
159
}
160
161
// Initialize a reflow input for a child frame's reflow. Some state
162
// is copied from the parent reflow input; the remaining state is
163
// computed.
164
ReflowInput::ReflowInput(nsPresContext* aPresContext,
165
const ReflowInput& aParentReflowInput,
166
nsIFrame* aFrame, const LogicalSize& aAvailableSpace,
167
const Maybe<LogicalSize>& aContainingBlockSize,
168
uint32_t aFlags)
169
: SizeComputationInput(aFrame, aParentReflowInput.mRenderingContext),
170
mParentReflowInput(&aParentReflowInput),
171
mFloatManager(aParentReflowInput.mFloatManager),
172
mLineLayout(mFrame->IsFrameOfType(nsIFrame::eLineParticipant)
173
? aParentReflowInput.mLineLayout
174
: nullptr),
175
mPercentBSizeObserver(
176
(aParentReflowInput.mPercentBSizeObserver &&
177
aParentReflowInput.mPercentBSizeObserver->NeedsToObserve(*this))
178
? aParentReflowInput.mPercentBSizeObserver
179
: nullptr),
180
mFlags(aParentReflowInput.mFlags),
181
mReflowDepth(aParentReflowInput.mReflowDepth + 1) {
182
MOZ_ASSERT(aPresContext, "no pres context");
183
MOZ_ASSERT(aFrame, "no frame");
184
MOZ_ASSERT(aPresContext == aFrame->PresContext(), "wrong pres context");
185
MOZ_ASSERT(!mFlags.mSpecialBSizeReflow || !NS_SUBTREE_DIRTY(aFrame),
186
"frame should be clean when getting special bsize reflow");
187
188
AvailableISize() = aAvailableSpace.ISize(mWritingMode);
189
AvailableBSize() = aAvailableSpace.BSize(mWritingMode);
190
191
if (mWritingMode.IsOrthogonalTo(aParentReflowInput.GetWritingMode())) {
192
// If we're setting up for an orthogonal flow, and the parent reflow input
193
// had a constrained ComputedBSize, we can use that as our AvailableISize
194
// in preference to leaving it unconstrained.
195
if (AvailableISize() == NS_UNCONSTRAINEDSIZE &&
196
aParentReflowInput.ComputedBSize() != NS_UNCONSTRAINEDSIZE) {
197
AvailableISize() = aParentReflowInput.ComputedBSize();
198
}
199
}
200
201
// Note: mFlags was initialized as a copy of aParentReflowInput.mFlags up in
202
// this constructor's init list, so the only flags that we need to explicitly
203
// initialize here are those that may need a value other than our parent's.
204
mFlags.mNextInFlowUntouched =
205
aParentReflowInput.mFlags.mNextInFlowUntouched &&
206
CheckNextInFlowParenthood(aFrame, aParentReflowInput.mFrame);
207
mFlags.mAssumingHScrollbar = mFlags.mAssumingVScrollbar = false;
208
mFlags.mIsColumnBalancing = false;
209
mFlags.mColumnSetWrapperHasNoBSizeLeft = false;
210
mFlags.mIsFlexContainerMeasuringBSize = false;
211
mFlags.mTreatBSizeAsIndefinite = false;
212
mFlags.mDummyParentReflowInput = false;
213
mFlags.mShrinkWrap = !!(aFlags & COMPUTE_SIZE_SHRINK_WRAP);
214
mFlags.mUseAutoBSize = !!(aFlags & COMPUTE_SIZE_USE_AUTO_BSIZE);
215
mFlags.mStaticPosIsCBOrigin = !!(aFlags & STATIC_POS_IS_CB_ORIGIN);
216
mFlags.mIOffsetsNeedCSSAlign = mFlags.mBOffsetsNeedCSSAlign = false;
217
mFlags.mIClampMarginBoxMinSize = !!(aFlags & I_CLAMP_MARGIN_BOX_MIN_SIZE);
218
mFlags.mBClampMarginBoxMinSize = !!(aFlags & B_CLAMP_MARGIN_BOX_MIN_SIZE);
219
mFlags.mApplyAutoMinSize = !!(aFlags & I_APPLY_AUTO_MIN_SIZE);
220
mFlags.mApplyLineClamp = false;
221
222
if ((aFlags & DUMMY_PARENT_REFLOW_INPUT) ||
223
(mParentReflowInput->mFlags.mDummyParentReflowInput &&
224
mFrame->IsTableFrame())) {
225
mFlags.mDummyParentReflowInput = true;
226
}
227
228
if (!(aFlags & CALLER_WILL_INIT)) {
229
Init(aPresContext, aContainingBlockSize);
230
}
231
}
232
233
template <typename SizeOrMaxSize>
234
inline nscoord SizeComputationInput::ComputeISizeValue(
235
nscoord aContainingBlockISize, nscoord aContentEdgeToBoxSizing,
236
nscoord aBoxSizingToMarginEdge, const SizeOrMaxSize& aSize) const {
237
return mFrame->ComputeISizeValue(mRenderingContext, aContainingBlockISize,
238
aContentEdgeToBoxSizing,
239
aBoxSizingToMarginEdge, aSize);
240
}
241
242
template <typename SizeOrMaxSize>
243
nscoord SizeComputationInput::ComputeISizeValue(
244
nscoord aContainingBlockISize, StyleBoxSizing aBoxSizing,
245
const SizeOrMaxSize& aSize) const {
246
WritingMode wm = GetWritingMode();
247
nscoord inside = 0, outside = ComputedLogicalBorderPadding().IStartEnd(wm) +
248
ComputedLogicalMargin().IStartEnd(wm);
249
if (aBoxSizing == StyleBoxSizing::Border) {
250
inside = ComputedLogicalBorderPadding().IStartEnd(wm);
251
}
252
outside -= inside;
253
254
return ComputeISizeValue(aContainingBlockISize, inside, outside, aSize);
255
}
256
257
nscoord SizeComputationInput::ComputeBSizeValue(
258
nscoord aContainingBlockBSize, StyleBoxSizing aBoxSizing,
259
const LengthPercentage& aSize) const {
260
WritingMode wm = GetWritingMode();
261
nscoord inside = 0;
262
if (aBoxSizing == StyleBoxSizing::Border) {
263
inside = ComputedLogicalBorderPadding().BStartEnd(wm);
264
}
265
return nsLayoutUtils::ComputeBSizeValue(aContainingBlockBSize, inside, aSize);
266
}
267
268
void ReflowInput::SetComputedWidth(nscoord aComputedWidth) {
269
NS_ASSERTION(mFrame, "Must have a frame!");
270
// It'd be nice to assert that |frame| is not in reflow, but this fails for
271
// two reasons:
272
//
273
// 1) Viewport frames reset the computed width on a copy of their reflow
274
// input when reflowing fixed-pos kids. In that case we actually don't
275
// want to mess with the resize flags, because comparing the frame's rect
276
// to the munged computed width is pointless.
277
// 2) nsFrame::BoxReflow creates a reflow input for its parent. This reflow
278
// input is not used to reflow the parent, but just as a parent for the
279
// frame's own reflow input. So given a nsBoxFrame inside some non-XUL
280
// (like a text control, for example), we'll end up creating a reflow
281
// input for the parent while the parent is reflowing.
282
283
MOZ_ASSERT(aComputedWidth >= 0, "Invalid computed width");
284
if (ComputedWidth() != aComputedWidth) {
285
ComputedWidth() = aComputedWidth;
286
LayoutFrameType frameType = mFrame->Type();
287
if (frameType != LayoutFrameType::Viewport || // Or check GetParent()?
288
mWritingMode.IsVertical()) {
289
InitResizeFlags(mFrame->PresContext(), frameType);
290
}
291
}
292
}
293
294
void ReflowInput::SetComputedHeight(nscoord aComputedHeight) {
295
NS_ASSERTION(mFrame, "Must have a frame!");
296
// It'd be nice to assert that |frame| is not in reflow, but this fails
297
// because:
298
//
299
// nsFrame::BoxReflow creates a reflow input for its parent. This reflow
300
// input is not used to reflow the parent, but just as a parent for the
301
// frame's own reflow input. So given a nsBoxFrame inside some non-XUL
302
// (like a text control, for example), we'll end up creating a reflow
303
// input for the parent while the parent is reflowing.
304
305
MOZ_ASSERT(aComputedHeight >= 0, "Invalid computed height");
306
if (ComputedHeight() != aComputedHeight) {
307
ComputedHeight() = aComputedHeight;
308
LayoutFrameType frameType = mFrame->Type();
309
if (frameType != LayoutFrameType::Viewport || !mWritingMode.IsVertical()) {
310
InitResizeFlags(mFrame->PresContext(), frameType);
311
}
312
}
313
}
314
315
void ReflowInput::Init(nsPresContext* aPresContext,
316
const Maybe<LogicalSize>& aContainingBlockSize,
317
const nsMargin* aBorder, const nsMargin* aPadding) {
318
if (AvailableISize() == NS_UNCONSTRAINEDSIZE) {
319
// Look up the parent chain for an orthogonal inline limit,
320
// and reset AvailableISize() if found.
321
for (const ReflowInput* parent = mParentReflowInput; parent != nullptr;
322
parent = parent->mParentReflowInput) {
323
if (parent->GetWritingMode().IsOrthogonalTo(mWritingMode) &&
324
parent->mOrthogonalLimit != NS_UNCONSTRAINEDSIZE) {
325
AvailableISize() = parent->mOrthogonalLimit;
326
break;
327
}
328
}
329
}
330
331
LAYOUT_WARN_IF_FALSE(AvailableISize() != NS_UNCONSTRAINEDSIZE,
332
"have unconstrained inline-size; this should only "
333
"result from very large sizes, not attempts at "
334
"intrinsic inline-size calculation");
335
336
mStylePosition = mFrame->StylePosition();
337
mStyleDisplay = mFrame->StyleDisplay();
338
mStyleVisibility = mFrame->StyleVisibility();
339
mStyleBorder = mFrame->StyleBorder();
340
mStyleMargin = mFrame->StyleMargin();
341
mStylePadding = mFrame->StylePadding();
342
mStyleText = mFrame->StyleText();
343
344
InitCBReflowInput();
345
346
LayoutFrameType type = mFrame->Type();
347
if (type == mozilla::LayoutFrameType::Placeholder) {
348
// Placeholders have a no-op Reflow method that doesn't need the rest of
349
// this initialization, so we bail out early.
350
ComputedBSize() = ComputedISize() = 0;
351
return;
352
}
353
354
InitFrameType(type);
355
InitConstraints(aPresContext, aContainingBlockSize, aBorder, aPadding, type);
356
357
InitResizeFlags(aPresContext, type);
358
InitDynamicReflowRoot();
359
360
nsIFrame* parent = mFrame->GetParent();
361
if (parent && (parent->GetStateBits() & NS_FRAME_IN_CONSTRAINED_BSIZE) &&
362
!(parent->IsScrollFrame() &&
363
parent->StyleDisplay()->mOverflowY != StyleOverflow::Hidden)) {
364
mFrame->AddStateBits(NS_FRAME_IN_CONSTRAINED_BSIZE);
365
} else if (type == LayoutFrameType::SVGForeignObject) {
366
// An SVG foreignObject frame is inherently constrained block-size.
367
mFrame->AddStateBits(NS_FRAME_IN_CONSTRAINED_BSIZE);
368
} else {
369
const auto& bSizeCoord = mStylePosition->BSize(mWritingMode);
370
const auto& maxBSizeCoord = mStylePosition->MaxBSize(mWritingMode);
371
if ((!bSizeCoord.BehavesLikeInitialValueOnBlockAxis() ||
372
!maxBSizeCoord.BehavesLikeInitialValueOnBlockAxis()) &&
373
// Don't set NS_FRAME_IN_CONSTRAINED_BSIZE on body or html elements.
374
(mFrame->GetContent() && !(mFrame->GetContent()->IsAnyOfHTMLElements(
375
nsGkAtoms::body, nsGkAtoms::html)))) {
376
// If our block-size was specified as a percentage, then this could
377
// actually resolve to 'auto', based on:
379
nsIFrame* containingBlk = mFrame;
380
while (containingBlk) {
381
const nsStylePosition* stylePos = containingBlk->StylePosition();
382
const auto& bSizeCoord = stylePos->BSize(mWritingMode);
383
const auto& maxBSizeCoord = stylePos->MaxBSize(mWritingMode);
384
if ((bSizeCoord.IsLengthPercentage() && !bSizeCoord.HasPercent()) ||
385
(maxBSizeCoord.IsLengthPercentage() &&
386
!maxBSizeCoord.HasPercent())) {
387
mFrame->AddStateBits(NS_FRAME_IN_CONSTRAINED_BSIZE);
388
break;
389
} else if (bSizeCoord.HasPercent() || maxBSizeCoord.HasPercent()) {
390
if (!(containingBlk = containingBlk->GetContainingBlock())) {
391
// If we've reached the top of the tree, then we don't have
392
// a constrained block-size.
393
mFrame->RemoveStateBits(NS_FRAME_IN_CONSTRAINED_BSIZE);
394
break;
395
}
396
397
continue;
398
} else {
399
mFrame->RemoveStateBits(NS_FRAME_IN_CONSTRAINED_BSIZE);
400
break;
401
}
402
}
403
} else {
404
mFrame->RemoveStateBits(NS_FRAME_IN_CONSTRAINED_BSIZE);
405
}
406
}
407
408
if (mParentReflowInput &&
409
mParentReflowInput->GetWritingMode().IsOrthogonalTo(mWritingMode)) {
410
// Orthogonal frames are always reflowed with an unconstrained
411
// dimension to avoid incomplete reflow across an orthogonal
412
// boundary. Normally this is the block-size, but for column sets
413
// with auto-height it's the inline-size, so that they can add
414
// columns in the container's block direction
415
if (type == LayoutFrameType::ColumnSet &&
416
mStylePosition->ISize(mWritingMode).IsAuto()) {
417
ComputedISize() = NS_UNCONSTRAINEDSIZE;
418
} else {
419
AvailableBSize() = NS_UNCONSTRAINEDSIZE;
420
}
421
}
422
423
if (mStyleDisplay->IsContainSize()) {
424
// In the case that a box is size contained, we want to ensure
425
// that it is also monolithic. We do this by unsetting
426
// AvailableBSize() to avoid fragmentaiton.
427
AvailableBSize() = NS_UNCONSTRAINEDSIZE;
428
}
429
430
LAYOUT_WARN_IF_FALSE((mFrameType == NS_CSS_FRAME_TYPE_INLINE &&
431
!mFrame->IsFrameOfType(nsIFrame::eReplaced)) ||
432
type == LayoutFrameType::Text ||
433
ComputedISize() != NS_UNCONSTRAINEDSIZE,
434
"have unconstrained inline-size; this should only "
435
"result from very large sizes, not attempts at "
436
"intrinsic inline-size calculation");
437
}
438
439
void ReflowInput::InitCBReflowInput() {
440
if (!mParentReflowInput) {
441
mCBReflowInput = nullptr;
442
return;
443
}
444
if (mParentReflowInput->mFlags.mDummyParentReflowInput) {
445
mCBReflowInput = mParentReflowInput;
446
return;
447
}
448
449
if (mParentReflowInput->mFrame ==
450
mFrame->GetContainingBlock(0, mStyleDisplay)) {
451
// Inner table frames need to use the containing block of the outer
452
// table frame.
453
if (mFrame->IsTableFrame()) {
454
mCBReflowInput = mParentReflowInput->mCBReflowInput;
455
} else {
456
mCBReflowInput = mParentReflowInput;
457
}
458
} else {
459
mCBReflowInput = mParentReflowInput->mCBReflowInput;
460
}
461
}
462
463
/* Check whether CalcQuirkContainingBlockHeight would stop on the
464
* given reflow input, using its block as a height. (essentially
465
* returns false for any case in which CalcQuirkContainingBlockHeight
466
* has a "continue" in its main loop.)
467
*
468
* XXX Maybe refactor CalcQuirkContainingBlockHeight so it uses
469
* this function as well
470
*/
471
static bool IsQuirkContainingBlockHeight(const ReflowInput* rs,
472
LayoutFrameType aFrameType) {
473
if (LayoutFrameType::Block == aFrameType ||
474
#ifdef MOZ_XUL
475
LayoutFrameType::XULLabel == aFrameType ||
476
#endif
477
LayoutFrameType::Scroll == aFrameType) {
478
// Note: This next condition could change due to a style change,
479
// but that would cause a style reflow anyway, which means we're ok.
480
if (NS_UNCONSTRAINEDSIZE == rs->ComputedHeight()) {
481
if (!rs->mFrame->IsAbsolutelyPositioned(rs->mStyleDisplay)) {
482
return false;
483
}
484
}
485
}
486
return true;
487
}
488
489
void ReflowInput::InitResizeFlags(nsPresContext* aPresContext,
490
LayoutFrameType aFrameType) {
491
SetBResize(false);
492
SetIResize(false);
493
mFlags.mIsBResizeForPercentages = false;
494
495
const WritingMode wm = mWritingMode; // just a shorthand
496
// We should report that we have a resize in the inline dimension if
497
// *either* the border-box size or the content-box size in that
498
// dimension has changed. It might not actually be necessary to do
499
// this if the border-box size has changed and the content-box size
500
// has not changed, but since we've historically used the flag to mean
501
// border-box size change, continue to do that. (It's possible for
502
// the content-box size to change without a border-box size change or
503
// a style change given (1) a fixed width (possibly fixed by max-width
504
// or min-width), (2) box-sizing:border-box or padding-box, and
505
// (3) percentage padding.)
506
//
507
// However, we don't actually have the information at this point to
508
// tell whether the content-box size has changed, since both style
509
// data and the UsedPaddingProperty() have already been updated. So,
510
// instead, we explicitly check for the case where it's possible for
511
// the content-box size to have changed without either (a) a change in
512
// the border-box size or (b) an nsChangeHint_NeedDirtyReflow change
513
// hint due to change in border or padding. Thus we test using the
514
// conditions from the previous paragraph, except without testing (1)
515
// since it's complicated to test properly and less likely to help
516
// with optimizing cases away.
517
bool isIResize =
518
// is the border-box resizing?
519
mFrame->ISize(wm) !=
520
ComputedISize() + ComputedLogicalBorderPadding().IStartEnd(wm) ||
521
// or is the content-box resizing? (see comment above)
522
(mStylePosition->mBoxSizing != StyleBoxSizing::Content &&
523
mStylePadding->IsWidthDependent());
524
525
if ((mFrame->GetStateBits() & NS_FRAME_FONT_INFLATION_FLOW_ROOT) &&
526
nsLayoutUtils::FontSizeInflationEnabled(aPresContext)) {
527
// Create our font inflation data if we don't have it already, and
528
// give it our current width information.
529
bool dirty = nsFontInflationData::UpdateFontInflationDataISizeFor(*this) &&
530
// Avoid running this at the box-to-block interface
531
// (where we shouldn't be inflating anyway, and where
532
// reflow input construction is probably to construct a
533
// dummy parent reflow input anyway).
534
!mFlags.mDummyParentReflowInput;
535
536
if (dirty || (!mFrame->GetParent() && isIResize)) {
537
// When font size inflation is enabled, a change in either:
538
// * the effective width of a font inflation flow root
539
// * the width of the frame
540
// needs to cause a dirty reflow since they change the font size
541
// inflation calculations, which in turn change the size of text,
542
// line-heights, etc. This is relatively similar to a classic
543
// case of style change reflow, except that because inflation
544
// doesn't affect the intrinsic sizing codepath, there's no need
545
// to invalidate intrinsic sizes.
546
//
547
// Note that this makes horizontal resizing a good bit more
548
// expensive. However, font size inflation is targeted at a set of
549
// devices (zoom-and-pan devices) where the main use case for
550
// horizontal resizing needing to be efficient (window resizing) is
551
// not present. It does still increase the cost of dynamic changes
552
// caused by script where a style or content change in one place
553
// causes a resize in another (e.g., rebalancing a table).
554
555
// FIXME: This isn't so great for the cases where
556
// ReflowInput::SetComputedWidth is called, if the first time
557
// we go through InitResizeFlags we set IsHResize() to true, and then
558
// the second time we'd set it to false even without the
559
// NS_FRAME_IS_DIRTY bit already set.
560
if (mFrame->IsSVGForeignObjectFrame()) {
561
// Foreign object frames use dirty bits in a special way.
562
mFrame->AddStateBits(NS_FRAME_HAS_DIRTY_CHILDREN);
563
nsIFrame* kid = mFrame->PrincipalChildList().FirstChild();
564
if (kid) {
565
kid->MarkSubtreeDirty();
566
}
567
} else {
568
mFrame->MarkSubtreeDirty();
569
}
570
571
// Mark intrinsic widths on all descendants dirty. We need to do
572
// this (1) since we're changing the size of text and need to
573
// clear text runs on text frames and (2) since we actually are
574
// changing some intrinsic widths, but only those that live inside
575
// of containers.
576
577
// It makes sense to do this for descendants but not ancestors
578
// (which is unusual) because we're only changing the unusual
579
// inflation-dependent intrinsic widths (i.e., ones computed with
580
// nsPresContext::mInflationDisabledForShrinkWrap set to false),
581
// which should never affect anything outside of their inflation
582
// flow root (or, for that matter, even their inflation
583
// container).
584
585
// This is also different from what PresShell::FrameNeedsReflow
586
// does because it doesn't go through placeholders. It doesn't
587
// need to because we're actually doing something that cares about
588
// frame tree geometry (the width on an ancestor) rather than
589
// style.
590
591
AutoTArray<nsIFrame*, 32> stack;
592
stack.AppendElement(mFrame);
593
594
do {
595
nsIFrame* f = stack.PopLastElement();
596
597
nsIFrame::ChildListIterator lists(f);
598
for (; !lists.IsDone(); lists.Next()) {
599
nsFrameList::Enumerator childFrames(lists.CurrentList());
600
for (; !childFrames.AtEnd(); childFrames.Next()) {
601
nsIFrame* kid = childFrames.get();
602
kid->MarkIntrinsicISizesDirty();
603
stack.AppendElement(kid);
604
}
605
}
606
} while (stack.Length() != 0);
607
}
608
}
609
610
SetIResize(!(mFrame->GetStateBits() & NS_FRAME_IS_DIRTY) && isIResize);
611
612
// XXX Should we really need to null check mCBReflowInput? (We do for
613
// at least nsBoxFrame).
614
if (mFrame->HasBSizeChange()) {
615
// When we have an nsChangeHint_UpdateComputedBSize, we'll set a bit
616
// on the frame to indicate we're resizing. This might catch cases,
617
// such as a change between auto and a length, where the box doesn't
618
// actually resize but children with percentages resize (since those
619
// percentages become auto if their containing block is auto).
620
SetBResize(true);
621
mFlags.mIsBResizeForPercentages = true;
622
// We don't clear the HasBSizeChange state here, since sometimes we
623
// construct reflow states (e.g., in
624
// nsBlockReflowContext::ComputeCollapsedBStartMargin) without
625
// reflowing the frame. Instead, we clear it in nsFrame::DidReflow.
626
} else if (mCBReflowInput &&
627
mCBReflowInput->IsBResizeForPercentagesForWM(wm) &&
628
(mStylePosition->BSize(wm).HasPercent() ||
629
mStylePosition->MinBSize(wm).HasPercent() ||
630
mStylePosition->MaxBSize(wm).HasPercent())) {
631
// We have a percentage (or calc-with-percentage) block-size, and the
632
// value it's relative to has changed.
633
SetBResize(true);
634
mFlags.mIsBResizeForPercentages = true;
635
} else if (aFrameType == LayoutFrameType::TableCell &&
636
(mFlags.mSpecialBSizeReflow ||
637
(mFrame->FirstInFlow()->GetStateBits() &
638
NS_TABLE_CELL_HAD_SPECIAL_REFLOW)) &&
639
(mFrame->GetStateBits() & NS_FRAME_CONTAINS_RELATIVE_BSIZE)) {
640
// Need to set the bit on the cell so that
641
// mCBReflowInput->IsBResize() is set correctly below when
642
// reflowing descendant.
643
SetBResize(true);
644
mFlags.mIsBResizeForPercentages = true;
645
} else if (mCBReflowInput && mFrame->IsBlockWrapper()) {
646
// XXX Is this problematic for relatively positioned inlines acting
647
// as containing block for absolutely positioned elements?
648
// Possibly; in that case we should at least be checking
649
// NS_SUBTREE_DIRTY, I'd think.
650
SetBResize(mCBReflowInput->IsBResizeForWM(wm));
651
mFlags.mIsBResizeForPercentages =
652
mCBReflowInput->IsBResizeForPercentagesForWM(wm);
653
} else if (ComputedBSize() == NS_UNCONSTRAINEDSIZE) {
654
// We have an 'auto' block-size.
655
if (eCompatibility_NavQuirks == aPresContext->CompatibilityMode() &&
656
mCBReflowInput) {
657
// FIXME: This should probably also check IsIResize().
658
SetBResize(mCBReflowInput->IsBResizeForWM(wm));
659
} else {
660
SetBResize(IsIResize());
661
}
662
SetBResize(IsBResize() || NS_SUBTREE_DIRTY(mFrame));
663
} else {
664
// We have a non-'auto' block-size, i.e., a length. Set the BResize
665
// flag to whether the size is actually different.
666
SetBResize(mFrame->BSize(wm) !=
667
ComputedBSize() + ComputedLogicalBorderPadding().BStartEnd(wm));
668
}
669
670
bool dependsOnCBBSize =
671
(mStylePosition->BSizeDependsOnContainer(wm) &&
672
// FIXME: condition this on not-abspos?
673
!mStylePosition->BSize(wm).IsAuto()) ||
674
mStylePosition->MinBSizeDependsOnContainer(wm) ||
675
mStylePosition->MaxBSizeDependsOnContainer(wm) ||
676
mStylePosition->OffsetHasPercent(wm.PhysicalSide(eLogicalSideBStart)) ||
677
!mStylePosition->mOffset.GetBEnd(wm).IsAuto() || mFrame->IsXULBoxFrame();
678
679
if (mStyleText->mLineHeight.IsMozBlockHeight()) {
680
// line-height depends on block bsize
681
mFrame->AddStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE);
682
// but only on containing blocks if this frame is not a suitable block
683
dependsOnCBBSize |= !nsLayoutUtils::IsNonWrapperBlock(mFrame);
684
}
685
686
// If we're the descendant of a table cell that performs special bsize
687
// reflows and we could be the child that requires them, always set
688
// the block-axis resize in case this is the first pass before the
689
// special bsize reflow. However, don't do this if it actually is
690
// the special bsize reflow, since in that case it will already be
691
// set correctly above if we need it set.
692
if (!IsBResize() && mCBReflowInput &&
693
(mCBReflowInput->mFrame->IsTableCellFrame() ||
694
mCBReflowInput->mFlags.mHeightDependsOnAncestorCell) &&
695
!mCBReflowInput->mFlags.mSpecialBSizeReflow && dependsOnCBBSize) {
696
SetBResize(true);
697
mFlags.mHeightDependsOnAncestorCell = true;
698
}
699
700
// Set NS_FRAME_CONTAINS_RELATIVE_BSIZE if it's needed.
701
702
// It would be nice to check that |ComputedBSize != NS_UNCONSTRAINEDSIZE|
703
// &&ed with the percentage bsize check. However, this doesn't get
704
// along with table special bsize reflows, since a special bsize
705
// reflow (a quirk that makes such percentage height work on children
706
// of table cells) can cause not just a single percentage height to
707
// become fixed, but an entire descendant chain of percentage height
708
// to become fixed.
709
if (dependsOnCBBSize && mCBReflowInput) {
710
const ReflowInput* rs = this;
711
bool hitCBReflowInput = false;
712
do {
713
rs = rs->mParentReflowInput;
714
if (!rs) {
715
break;
716
}
717
718
if (rs->mFrame->GetStateBits() & NS_FRAME_CONTAINS_RELATIVE_BSIZE) {
719
break; // no need to go further
720
}
721
rs->mFrame->AddStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE);
722
723
// Keep track of whether we've hit the containing block, because
724
// we need to go at least that far.
725
if (rs == mCBReflowInput) {
726
hitCBReflowInput = true;
727
}
728
729
// XXX What about orthogonal flows? It doesn't make sense to
730
// keep propagating this bit across an orthogonal boundary,
731
// where the meaning of BSize changes. Bug 1175517.
732
} while (!hitCBReflowInput ||
733
(eCompatibility_NavQuirks == aPresContext->CompatibilityMode() &&
734
!IsQuirkContainingBlockHeight(rs, rs->mFrame->Type())));
735
// Note: We actually don't need to set the
736
// NS_FRAME_CONTAINS_RELATIVE_BSIZE bit for the cases
737
// where we hit the early break statements in
738
// CalcQuirkContainingBlockHeight. But it doesn't hurt
739
// us to set the bit in these cases.
740
}
741
if (mFrame->GetStateBits() & NS_FRAME_IS_DIRTY) {
742
// If we're reflowing everything, then we'll find out if we need
743
// to re-set this.
744
mFrame->RemoveStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE);
745
}
746
}
747
748
template <typename SizeOrMaxSize>
749
static inline bool IsIntrinsicKeyword(const SizeOrMaxSize& aSize) {
750
if (!aSize.IsExtremumLength()) {
751
return false;
752
}
753
754
// All of the keywords except for '-moz-available' depend on intrinsic sizes.
755
return aSize.AsExtremumLength() != StyleExtremumLength::MozAvailable;
756
}
757
758
static bool AreDynamicReflowRootsEnabled() {
759
static bool sAreDynamicReflowRootsEnabled;
760
static bool sIsPrefCached = false;
761
762
if (!sIsPrefCached) {
763
sIsPrefCached = true;
764
Preferences::AddBoolVarCache(&sAreDynamicReflowRootsEnabled,
765
"layout.dynamic-reflow-roots.enabled");
766
}
767
return sAreDynamicReflowRootsEnabled;
768
}
769
770
void ReflowInput::InitDynamicReflowRoot() {
771
auto display = mStyleDisplay->mDisplay;
772
if (mFrame->IsFrameOfType(nsIFrame::eLineParticipant) ||
773
nsStyleDisplay::IsRubyDisplayType(display) ||
774
mFrameType == NS_CSS_FRAME_TYPE_INTERNAL_TABLE ||
775
nsStyleDisplay::DisplayInside(display) == StyleDisplayInside::Table ||
776
(mFrame->GetParent() && mFrame->GetParent()->IsXULBoxFrame())) {
777
// We have a display type where 'width' and 'height' don't actually
778
// set the width or height (i.e., the size depends on content).
779
NS_ASSERTION(!(mFrame->GetStateBits() & NS_FRAME_DYNAMIC_REFLOW_ROOT),
780
"should not have dynamic reflow root bit");
781
return;
782
}
783
784
bool canBeDynamicReflowRoot = AreDynamicReflowRootsEnabled();
785
786
// We can't do this if our used 'width' and 'height' might be influenced by
787
// content.
788
// FIXME: For display:block, we should probably optimize inline-size
789
// being auto.
790
// FIXME: Other flex and grid cases?
791
const auto& width = mStylePosition->mWidth;
792
const auto& height = mStylePosition->mHeight;
793
if (canBeDynamicReflowRoot &&
794
(!width.IsLengthPercentage() || width.HasPercent() ||
795
!height.IsLengthPercentage() || height.HasPercent() ||
796
IsIntrinsicKeyword(mStylePosition->mMinWidth) ||
797
IsIntrinsicKeyword(mStylePosition->mMaxWidth) ||
798
IsIntrinsicKeyword(mStylePosition->mMinHeight) ||
799
IsIntrinsicKeyword(mStylePosition->mMaxHeight) ||
800
((mStylePosition->mMinWidth.IsAuto() ||
801
mStylePosition->mMinHeight.IsAuto()) &&
802
mFrame->IsFlexOrGridItem()))) {
803
canBeDynamicReflowRoot = false;
804
}
805
806
if (canBeDynamicReflowRoot && mFrame->IsFlexItem()) {
807
// If our flex-basis is 'auto', it'll defer to 'width' (or 'height') which
808
// we've already checked. Otherwise, it preempts them, so we need to
809
// perform the same "could-this-value-be-influenced-by-content" checks that
810
// we performed for 'width' and 'height' above.
811
const auto& flexBasis = mStylePosition->mFlexBasis;
812
if (!flexBasis.IsAuto()) {
813
if (!flexBasis.IsSize() || !flexBasis.AsSize().IsLengthPercentage() ||
814
flexBasis.AsSize().HasPercent()) {
815
canBeDynamicReflowRoot = false;
816
}
817
}
818
}
819
820
if (canBeDynamicReflowRoot && !mFrame->IsFixedPosContainingBlock()) {
821
// We can't treat this frame as a reflow root, since dynamic changes
822
// to absolutely-positioned frames inside of it require that we
823
// reflow the placeholder before we reflow the absolutely positioned
824
// frame.
825
// FIXME: Alternatively, we could sort the reflow roots in
826
// PresShell::ProcessReflowCommands by depth in the tree, from
827
// deepest to least deep. However, for performance (FIXME) we
828
// should really be sorting them in the opposite order!
829
canBeDynamicReflowRoot = false;
830
}
831
832
// If we participate in a container's block reflow context, or margins
833
// can collapse through us, we can't be a dynamic reflow root.
834
if (canBeDynamicReflowRoot && mFrame->IsBlockFrameOrSubclass() &&
835
!mFrame->HasAllStateBits(NS_BLOCK_FLOAT_MGR | NS_BLOCK_MARGIN_ROOT)) {
836
canBeDynamicReflowRoot = false;
837
}
838
839
// Subgrids are never reflow roots, but 'contain:layout/paint' prevents
840
// creating a subgrid in the first place.
841
if (canBeDynamicReflowRoot &&
842
(mStylePosition->mGridTemplateColumns.IsSubgrid() ||
843
mStylePosition->mGridTemplateRows.IsSubgrid()) &&
844
!(mStyleDisplay->IsContainLayout() || mStyleDisplay->IsContainPaint())) {
845
// NOTE: we could check that 'display' of our content's primary frame is
846
// '[inline-]grid' here but that's probably not worth it in practice.
847
canBeDynamicReflowRoot = false;
848
}
849
850
if (canBeDynamicReflowRoot) {
851
mFrame->AddStateBits(NS_FRAME_DYNAMIC_REFLOW_ROOT);
852
} else {
853
mFrame->RemoveStateBits(NS_FRAME_DYNAMIC_REFLOW_ROOT);
854
}
855
}
856
857
nscoord ReflowInput::GetContainingBlockContentISize(
858
WritingMode aWritingMode) const {
859
if (!mCBReflowInput) {
860
return 0;
861
}
862
return mCBReflowInput->GetWritingMode().IsOrthogonalTo(aWritingMode)
863
? mCBReflowInput->ComputedBSize()
864
: mCBReflowInput->ComputedISize();
865
}
866
867
void ReflowInput::InitFrameType(LayoutFrameType aFrameType) {
868
const nsStyleDisplay* disp = mStyleDisplay;
869
nsCSSFrameType frameType;
870
871
DISPLAY_INIT_TYPE(mFrame, this);
872
873
if (aFrameType == LayoutFrameType::Table) {
874
mFrameType = NS_CSS_FRAME_TYPE_BLOCK;
875
return;
876
}
877
878
NS_ASSERTION(mFrame->StyleDisplay()->IsAbsolutelyPositionedStyle() ==
879
disp->IsAbsolutelyPositionedStyle(),
880
"Unexpected position style");
881
NS_ASSERTION(
882
mFrame->StyleDisplay()->IsFloatingStyle() == disp->IsFloatingStyle(),
883
"Unexpected float style");
884
if (mFrame->GetStateBits() & NS_FRAME_OUT_OF_FLOW) {
885
if (disp->IsAbsolutelyPositioned(mFrame)) {
886
frameType = NS_CSS_FRAME_TYPE_ABSOLUTE;
887
// XXXfr hack for making frames behave properly when in overflow container
888
// lists
889
// see bug 154892; need to revisit later
890
if (mFrame->GetPrevInFlow()) frameType = NS_CSS_FRAME_TYPE_BLOCK;
891
} else if (disp->IsFloating(mFrame)) {
892
frameType = NS_CSS_FRAME_TYPE_FLOATING;
893
} else {
894
NS_ASSERTION(disp->mDisplay == StyleDisplay::MozPopup,
895
"unknown out of flow frame type");
896
frameType = NS_CSS_FRAME_TYPE_UNKNOWN;
897
}
898
} else {
899
switch (disp->DisplayOutside()) {
900
case StyleDisplayOutside::Block:
901
case StyleDisplayOutside::TableCaption:
902
frameType = NS_CSS_FRAME_TYPE_BLOCK;
903
break;
904
905
case StyleDisplayOutside::Inline:
906
frameType = NS_CSS_FRAME_TYPE_INLINE;
907
break;
908
909
case StyleDisplayOutside::InternalTable:
910
frameType = NS_CSS_FRAME_TYPE_INTERNAL_TABLE;
911
break;
912
913
case StyleDisplayOutside::InternalRuby:
914
switch (disp->DisplayInside()) {
915
case StyleDisplayInside::RubyTextContainer:
916
frameType = NS_CSS_FRAME_TYPE_BLOCK;
917
break;
918
case StyleDisplayInside::RubyBase:
919
case StyleDisplayInside::RubyText:
920
case StyleDisplayInside::RubyBaseContainer:
921
frameType = NS_CSS_FRAME_TYPE_INLINE;
922
break;
923
default:
924
MOZ_ASSERT_UNREACHABLE("unexpected inside for InternalRuby");
925
}
926
break;
927
928
default:
929
frameType = NS_CSS_FRAME_TYPE_UNKNOWN;
930
break;
931
}
932
}
933
934
// See if the frame is replaced
935
if (mFrame->IsFrameOfType(nsIFrame::eReplacedContainsBlock)) {
936
frameType = NS_FRAME_REPLACED_CONTAINS_BLOCK(frameType);
937
} else if (mFrame->IsFrameOfType(nsIFrame::eReplaced)) {
938
frameType = NS_FRAME_REPLACED(frameType);
939
}
940
941
mFrameType = frameType;
942
}
943
944
/* static */
945
void ReflowInput::ComputeRelativeOffsets(WritingMode aWM, nsIFrame* aFrame,
946
const LogicalSize& aCBSize,
947
nsMargin& aComputedOffsets) {
948
LogicalMargin offsets(aWM);
949
mozilla::Side inlineStart = aWM.PhysicalSide(eLogicalSideIStart);
950
mozilla::Side inlineEnd = aWM.PhysicalSide(eLogicalSideIEnd);
951
mozilla::Side blockStart = aWM.PhysicalSide(eLogicalSideBStart);
952
mozilla::Side blockEnd = aWM.PhysicalSide(eLogicalSideBEnd);
953
954
const nsStylePosition* position = aFrame->StylePosition();
955
956
// Compute the 'inlineStart' and 'inlineEnd' values. 'inlineStart'
957
// moves the boxes to the end of the line, and 'inlineEnd' moves the
958
// boxes to the start of the line. The computed values are always:
959
// inlineStart=-inlineEnd
960
bool inlineStartIsAuto = position->mOffset.Get(inlineStart).IsAuto();
961
bool inlineEndIsAuto = position->mOffset.Get(inlineEnd).IsAuto();
962
963
// If neither 'inlineStart' nor 'inlineEnd' is auto, then we're
964
// over-constrained and we ignore one of them
965
if (!inlineStartIsAuto && !inlineEndIsAuto) {
966
inlineEndIsAuto = true;
967
}
968
969
if (inlineStartIsAuto) {
970
if (inlineEndIsAuto) {
971
// If both are 'auto' (their initial values), the computed values are 0
972
offsets.IStart(aWM) = offsets.IEnd(aWM) = 0;
973
} else {
974
// 'inlineEnd' isn't 'auto' so compute its value
975
offsets.IEnd(aWM) = nsLayoutUtils::ComputeCBDependentValue(
976
aCBSize.ISize(aWM), position->mOffset.Get(inlineEnd));
977
978
// Computed value for 'inlineStart' is minus the value of 'inlineEnd'
979
offsets.IStart(aWM) = -offsets.IEnd(aWM);
980
}
981
982
} else {
983
NS_ASSERTION(inlineEndIsAuto, "unexpected specified constraint");
984
985
// 'InlineStart' isn't 'auto' so compute its value
986
offsets.IStart(aWM) = nsLayoutUtils::ComputeCBDependentValue(
987
aCBSize.ISize(aWM), position->mOffset.Get(inlineStart));
988
989
// Computed value for 'inlineEnd' is minus the value of 'inlineStart'
990
offsets.IEnd(aWM) = -offsets.IStart(aWM);
991
}
992
993
// Compute the 'blockStart' and 'blockEnd' values. The 'blockStart'
994
// and 'blockEnd' properties move relatively positioned elements in
995
// the block progression direction. They also must be each other's
996
// negative
997
bool blockStartIsAuto = position->mOffset.Get(blockStart).IsAuto();
998
bool blockEndIsAuto = position->mOffset.Get(blockEnd).IsAuto();
999
1000
// Check for percentage based values and a containing block block-size
1001
// that depends on the content block-size. Treat them like 'auto'
1002
if (NS_UNCONSTRAINEDSIZE == aCBSize.BSize(aWM)) {
1003
if (position->OffsetHasPercent(blockStart)) {
1004
blockStartIsAuto = true;
1005
}
1006
if (position->OffsetHasPercent(blockEnd)) {
1007
blockEndIsAuto = true;
1008
}
1009
}
1010
1011
// If neither is 'auto', 'block-end' is ignored
1012
if (!blockStartIsAuto && !blockEndIsAuto) {
1013
blockEndIsAuto = true;
1014
}
1015
1016
if (blockStartIsAuto) {
1017
if (blockEndIsAuto) {
1018
// If both are 'auto' (their initial values), the computed values are 0
1019
offsets.BStart(aWM) = offsets.BEnd(aWM) = 0;
1020
} else {
1021
// 'blockEnd' isn't 'auto' so compute its value
1022
offsets.BEnd(aWM) = nsLayoutUtils::ComputeBSizeDependentValue(
1023
aCBSize.BSize(aWM), position->mOffset.Get(blockEnd));
1024
1025
// Computed value for 'blockStart' is minus the value of 'blockEnd'
1026
offsets.BStart(aWM) = -offsets.BEnd(aWM);
1027
}
1028
1029
} else {
1030
NS_ASSERTION(blockEndIsAuto, "unexpected specified constraint");
1031
1032
// 'blockStart' isn't 'auto' so compute its value
1033
offsets.BStart(aWM) = nsLayoutUtils::ComputeBSizeDependentValue(
1034
aCBSize.BSize(aWM), position->mOffset.Get(blockStart));
1035
1036
// Computed value for 'blockEnd' is minus the value of 'blockStart'
1037
offsets.BEnd(aWM) = -offsets.BStart(aWM);
1038
}
1039
1040
// Convert the offsets to physical coordinates and store them on the frame
1041
aComputedOffsets = offsets.GetPhysicalMargin(aWM);
1042
nsMargin* physicalOffsets =
1043
aFrame->GetProperty(nsIFrame::ComputedOffsetProperty());
1044
if (physicalOffsets) {
1045
*physicalOffsets = aComputedOffsets;
1046
} else {
1047
aFrame->AddProperty(nsIFrame::ComputedOffsetProperty(),
1048
new nsMargin(aComputedOffsets));
1049
}
1050
}
1051
1052
/* static */
1053
void ReflowInput::ApplyRelativePositioning(nsIFrame* aFrame,
1054
const nsMargin& aComputedOffsets,
1055
nsPoint* aPosition) {
1056
if (!aFrame->IsRelativelyPositioned()) {
1057
NS_ASSERTION(!aFrame->GetProperty(nsIFrame::NormalPositionProperty()),
1058
"We assume that changing the 'position' property causes "
1059
"frame reconstruction. If that ever changes, this code "
1060
"should call "
1061
"aFrame->DeleteProperty(nsIFrame::NormalPositionProperty())");
1062
return;
1063
}
1064
1065
// Store the normal position
1066
nsPoint* normalPosition =
1067
aFrame->GetProperty(nsIFrame::NormalPositionProperty());
1068
if (normalPosition) {
1069
*normalPosition = *aPosition;
1070
} else {
1071
aFrame->AddProperty(nsIFrame::NormalPositionProperty(),
1072
new nsPoint(*aPosition));
1073
}
1074
1075
const nsStyleDisplay* display = aFrame->StyleDisplay();
1076
if (NS_STYLE_POSITION_RELATIVE == display->mPosition) {
1077
*aPosition += nsPoint(aComputedOffsets.left, aComputedOffsets.top);
1078
} else if (NS_STYLE_POSITION_STICKY == display->mPosition &&
1079
!aFrame->GetNextContinuation() && !aFrame->GetPrevContinuation() &&
1080
!(aFrame->GetStateBits() & NS_FRAME_PART_OF_IBSPLIT)) {
1081
// Sticky positioning for elements with multiple frames needs to be
1082
// computed all at once. We can't safely do that here because we might be
1083
// partway through (re)positioning the frames, so leave it until the scroll
1084
// container reflows and calls StickyScrollContainer::UpdatePositions.
1085
// For single-frame sticky positioned elements, though, go ahead and apply
1086
// it now to avoid unnecessary overflow updates later.
1087
StickyScrollContainer* ssc =
1088
StickyScrollContainer::GetStickyScrollContainerForFrame(aFrame);
1089
if (ssc) {
1090
*aPosition = ssc->ComputePosition(aFrame);
1091
}
1092
}
1093
}
1094
1095
// Returns true if aFrame is non-null, a XUL frame, and "XUL-collapsed" (which
1096
// only becomes a valid question to ask if we know it's a XUL frame).
1097
static bool IsXULCollapsedXULFrame(nsIFrame* aFrame) {
1098
return aFrame && aFrame->IsXULBoxFrame() && aFrame->IsXULCollapsed();
1099
}
1100
1101
nsIFrame* ReflowInput::GetHypotheticalBoxContainer(nsIFrame* aFrame,
1102
nscoord& aCBIStartEdge,
1103
LogicalSize& aCBSize) const {
1104
aFrame = aFrame->GetContainingBlock();
1105
NS_ASSERTION(aFrame != mFrame, "How did that happen?");
1106
1107
/* Now aFrame is the containing block we want */
1108
1109
/* Check whether the containing block is currently being reflowed.
1110
If so, use the info from the reflow input. */
1111
const ReflowInput* reflowInput;
1112
if (aFrame->GetStateBits() & NS_FRAME_IN_REFLOW) {
1113
for (reflowInput = mParentReflowInput;
1114
reflowInput && reflowInput->mFrame != aFrame;
1115
reflowInput = reflowInput->mParentReflowInput) {
1116
/* do nothing */
1117
}
1118
} else {
1119
reflowInput = nullptr;
1120
}
1121
1122
if (reflowInput) {
1123
WritingMode wm = reflowInput->GetWritingMode();
1124
NS_ASSERTION(wm == aFrame->GetWritingMode(), "unexpected writing mode");
1125
aCBIStartEdge = reflowInput->ComputedLogicalBorderPadding().IStart(wm);
1126
aCBSize = reflowInput->ComputedSize(wm);
1127
} else {
1128
/* Didn't find a reflow reflowInput for aFrame. Just compute the
1129
information we want, on the assumption that aFrame already knows its
1130
size. This really ought to be true by now. */
1131
NS_ASSERTION(!(aFrame->GetStateBits() & NS_FRAME_IN_REFLOW),
1132
"aFrame shouldn't be in reflow; we'll lie if it is");
1133
WritingMode wm = aFrame->GetWritingMode();
1134
// Compute CB's offset & content-box size by subtracting borderpadding from
1135
// frame size. Exception: if the CB is 0-sized, it *might* be a child of a
1136
// XUL-collapsed frame and might have nonzero borderpadding that was simply
1137
// discarded during its layout. (See the child-zero-sizing in
1138
// nsSprocketLayout::XULLayout()). In that case, we ignore the
1139
// borderpadding here (just like we did when laying it out), or else we'd
1140
// produce a bogus negative content-box size.
1141
aCBIStartEdge = 0;
1142
aCBSize = aFrame->GetLogicalSize(wm);
1143
if (!aCBSize.IsAllZero() ||
1144
(!IsXULCollapsedXULFrame(aFrame->GetParent()))) {
1145
// aFrame is not XUL-collapsed (nor is it a child of a XUL-collapsed
1146
// frame), so we can go ahead and subtract out border padding.
1147
LogicalMargin borderPadding = aFrame->GetLogicalUsedBorderAndPadding(wm);
1148
aCBIStartEdge += borderPadding.IStart(wm);
1149
aCBSize -= borderPadding.Size(wm);
1150
}
1151
}
1152
1153
return aFrame;
1154
}
1155
1156
struct nsHypotheticalPosition {
1157
// offset from inline-start edge of containing block (which is a padding edge)
1158
nscoord mIStart;
1159
// offset from block-start edge of containing block (which is a padding edge)
1160
nscoord mBStart;
1161
WritingMode mWritingMode;
1162
};
1163
1164
static bool GetIntrinsicSizeFor(nsIFrame* aFrame, nsSize& aIntrinsicSize,
1165
LayoutFrameType aFrameType) {
1166
// See if it is an image frame
1167
bool success = false;
1168
1169
// Currently the only type of replaced frame that we can get the intrinsic
1170
// size for is an image frame
1171
// XXX We should add back the GetReflowOutput() function and one of the
1172
// things should be the intrinsic size...
1173
if (aFrameType == LayoutFrameType::Image) {
1174
nsImageFrame* imageFrame = (nsImageFrame*)aFrame;
1175
1176
if (NS_SUCCEEDED(imageFrame->GetIntrinsicImageSize(aIntrinsicSize))) {
1177
success = (aIntrinsicSize != nsSize(0, 0));
1178
}
1179
}
1180
return success;
1181
}
1182
1183
/**
1184
* aInsideBoxSizing returns the part of the padding, border, and margin
1185
* in the aAxis dimension that goes inside the edge given by box-sizing;
1186
* aOutsideBoxSizing returns the rest.
1187
*/
1188
void ReflowInput::CalculateBorderPaddingMargin(
1189
LogicalAxis aAxis, nscoord aContainingBlockSize, nscoord* aInsideBoxSizing,
1190
nscoord* aOutsideBoxSizing) const {
1191
WritingMode wm = GetWritingMode();
1192
mozilla::Side startSide =
1193
wm.PhysicalSide(MakeLogicalSide(aAxis, eLogicalEdgeStart));
1194
mozilla::Side endSide =
1195
wm.PhysicalSide(MakeLogicalSide(aAxis, eLogicalEdgeEnd));
1196
1197
nsMargin styleBorder = mStyleBorder->GetComputedBorder();
1198
nscoord borderStartEnd =
1199
styleBorder.Side(startSide) + styleBorder.Side(endSide);
1200
1201
nscoord paddingStartEnd, marginStartEnd;
1202
1203
// See if the style system can provide us the padding directly
1204
nsMargin stylePadding;
1205
if (mStylePadding->GetPadding(stylePadding)) {
1206
paddingStartEnd = stylePadding.Side(startSide) + stylePadding.Side(endSide);
1207
} else {
1208
// We have to compute the start and end values
1209
nscoord start, end;
1210
start = nsLayoutUtils::ComputeCBDependentValue(
1211
aContainingBlockSize, mStylePadding->mPadding.Get(startSide));
1212
end = nsLayoutUtils::ComputeCBDependentValue(
1213
aContainingBlockSize, mStylePadding->mPadding.Get(endSide));
1214
paddingStartEnd = start + end;
1215
}
1216
1217
// See if the style system can provide us the margin directly
1218
nsMargin styleMargin;
1219
if (mStyleMargin->GetMargin(styleMargin)) {
1220
marginStartEnd = styleMargin.Side(startSide) + styleMargin.Side(endSide);
1221
} else {
1222
nscoord start, end;
1223
// We have to compute the start and end values
1224
if (mStyleMargin->mMargin.Get(startSide).IsAuto()) {
1225
// We set this to 0 for now, and fix it up later in
1226
// InitAbsoluteConstraints (which is caller of this function, via
1227
// CalculateHypotheticalPosition).
1228
start = 0;
1229
} else {
1230
start = nsLayoutUtils::ComputeCBDependentValue(
1231
aContainingBlockSize, mStyleMargin->mMargin.Get(startSide));
1232
}
1233
if (mStyleMargin->mMargin.Get(endSide).IsAuto()) {
1234
// We set this to 0 for now, and fix it up later in
1235
// InitAbsoluteConstraints (which is caller of this function, via
1236
// CalculateHypotheticalPosition).
1237
end = 0;
1238
} else {
1239
end = nsLayoutUtils::ComputeCBDependentValue(
1240
aContainingBlockSize, mStyleMargin->mMargin.Get(endSide));
1241
}
1242
marginStartEnd = start + end;
1243
}
1244
1245
nscoord outside = paddingStartEnd + borderStartEnd + marginStartEnd;
1246
nscoord inside = 0;
1247
if (mStylePosition->mBoxSizing == StyleBoxSizing::Border) {
1248
inside = borderStartEnd + paddingStartEnd;
1249
}
1250
outside -= inside;
1251
*aInsideBoxSizing = inside;
1252
*aOutsideBoxSizing = outside;
1253
}
1254
1255
/**
1256
* Returns true iff a pre-order traversal of the normal child
1257
* frames rooted at aFrame finds no non-empty frame before aDescendant.
1258
*/
1259
static bool AreAllEarlierInFlowFramesEmpty(nsIFrame* aFrame,
1260
nsIFrame* aDescendant,
1261
bool* aFound) {
1262
if (aFrame == aDescendant) {
1263
*aFound = true;
1264
return true;
1265
}
1266
if (aFrame->IsPlaceholderFrame()) {
1267
auto ph = static_cast<nsPlaceholderFrame*>(aFrame);
1268
MOZ_ASSERT(ph->IsSelfEmpty() && ph->PrincipalChildList().IsEmpty());
1269
ph->SetLineIsEmptySoFar(true);
1270
} else {
1271
if (!aFrame->IsSelfEmpty()) {
1272
*aFound = false;
1273
return false;
1274
}
1275
for (nsIFrame* f : aFrame->PrincipalChildList()) {
1276
bool allEmpty = AreAllEarlierInFlowFramesEmpty(f, aDescendant, aFound);
1277
if (*aFound || !allEmpty) {
1278
return allEmpty;
1279
}
1280
}
1281
}
1282
*aFound = false;
1283
return true;
1284
}
1285
1286
// Calculate the position of the hypothetical box that the element would have
1287
// if it were in the flow.
1288
// The values returned are relative to the padding edge of the absolute
1289
// containing block. The writing-mode of the hypothetical box position will
1290
// have the same block direction as the absolute containing block, but may
1291
// differ in inline-bidi direction.
1292
// In the code below, |aCBReflowInput->frame| is the absolute containing block,
1293
// while |containingBlock| is the nearest block container of the placeholder
1294
// frame, which may be different from the absolute containing block.
1295
void ReflowInput::CalculateHypotheticalPosition(
1296
nsPresContext* aPresContext, nsPlaceholderFrame* aPlaceholderFrame,
1297
const ReflowInput* aCBReflowInput, nsHypotheticalPosition& aHypotheticalPos,
1298
LayoutFrameType aFrameType) const {
1299
NS_ASSERTION(mStyleDisplay->mOriginalDisplay != StyleDisplay::None,
1300
"mOriginalDisplay has not been properly initialized");
1301
1302
// Find the nearest containing block frame to the placeholder frame,
1303
// and its inline-start edge and width.
1304
nscoord blockIStartContentEdge;
1305
// Dummy writing mode for blockContentSize, will be changed as needed by
1306
// GetHypotheticalBoxContainer.
1307
WritingMode cbwm = aCBReflowInput->GetWritingMode();
1308
LogicalSize blockContentSize(cbwm);
1309
nsIFrame* containingBlock = GetHypotheticalBoxContainer(
1310
aPlaceholderFrame, blockIStartContentEdge, blockContentSize);
1311
// Now blockContentSize is in containingBlock's writing mode.
1312
1313
// If it's a replaced element and it has a 'auto' value for
1314
//'inline size', see if we can get the intrinsic size. This will allow
1315
// us to exactly determine both the inline edges
1316
WritingMode wm = containingBlock->GetWritingMode();
1317
1318
const auto& styleISize = mStylePosition->ISize(wm);
1319
bool isAutoISize = styleISize.IsAuto();
1320
nsSize intrinsicSize;
1321
bool knowIntrinsicSize = false;
1322
if (NS_FRAME_IS_REPLACED(mFrameType) && isAutoISize) {
1323
// See if we can get the intrinsic size of the element
1324
knowIntrinsicSize = GetIntrinsicSizeFor(mFrame, intrinsicSize, aFrameType);
1325
}
1326
1327
// See if we can calculate what the box inline size would have been if
1328
// the element had been in the flow
1329
nscoord boxISize;
1330
bool knowBoxISize = false;
1331
if (mStyleDisplay->IsOriginalDisplayInlineOutside() &&
1332
!NS_FRAME_IS_REPLACED(mFrameType)) {
1333
// For non-replaced inline-level elements the 'inline size' property
1334
// doesn't apply, so we don't know what the inline size would have
1335
// been without reflowing it
1336
1337
} else {
1338
// It's either a replaced inline-level element or a block-level element
1339
1340
// Determine the total amount of inline direction
1341
// border/padding/margin that the element would have had if it had
1342
// been in the flow. Note that we ignore any 'auto' and 'inherit'
1343
// values
1344
nscoord insideBoxSizing, outsideBoxSizing;
1345
CalculateBorderPaddingMargin(eLogicalAxisInline, blockContentSize.ISize(wm),
1346
&insideBoxSizing, &outsideBoxSizing);
1347
1348
if (NS_FRAME_IS_REPLACED(mFrameType) && isAutoISize) {
1349
// It's a replaced element with an 'auto' inline size so the box
1350
// inline size is its intrinsic size plus any border/padding/margin
1351
if (knowIntrinsicSize) {
1352
boxISize = LogicalSize(wm, intrinsicSize).ISize(wm) + outsideBoxSizing +
1353
insideBoxSizing;
1354
knowBoxISize = true;
1355
}
1356
1357
} else if (isAutoISize) {
1358
// The box inline size is the containing block inline size
1359
boxISize = blockContentSize.ISize(wm);
1360
knowBoxISize = true;
1361
1362
} else {
1363
// We need to compute it. It's important we do this, because if it's
1364
// percentage based this computed value may be different from the computed
1365
// value calculated using the absolute containing block width
1366
boxISize = ComputeISizeValue(blockContentSize.ISize(wm), insideBoxSizing,
1367
outsideBoxSizing, styleISize) +
1368
insideBoxSizing + outsideBoxSizing;
1369
knowBoxISize = true;
1370
}
1371
}
1372
1373
// Get the placeholder x-offset and y-offset in the coordinate
1374
// space of its containing block
1375
// XXXbz the placeholder is not fully reflowed yet if our containing block is
1376
// relatively positioned...
1377
nsSize containerSize =
1378
containingBlock->GetStateBits() & NS_FRAME_IN_REFLOW
1379
? aCBReflowInput->ComputedSizeAsContainerIfConstrained()
1380
: containingBlock->GetSize();
1381
LogicalPoint placeholderOffset(
1382
wm, aPlaceholderFrame->GetOffsetToIgnoringScrolling(containingBlock),
1383
containerSize);
1384
1385
// First, determine the hypothetical box's mBStart. We want to check the
1386
// content insertion frame of containingBlock for block-ness, but make
1387
// sure to compute all coordinates in the coordinate system of
1388
// containingBlock.
1389
nsBlockFrame* blockFrame =
1390
do_QueryFrame(containingBlock->GetContentInsertionFrame());
1391
if (blockFrame) {
1392
// Use a null containerSize to convert a LogicalPoint functioning as a
1393
// vector into a physical nsPoint vector.
1394
const nsSize nullContainerSize;
1395
LogicalPoint blockOffset(
1396
wm, blockFrame->GetOffsetToIgnoringScrolling(containingBlock),
1397
nullContainerSize);
1398
bool isValid;
1399
nsBlockInFlowLineIterator iter(blockFrame, aPlaceholderFrame, &isValid);
1400
if (!isValid) {
1401
// Give up. We're probably dealing with somebody using
1402
// position:absolute inside native-anonymous content anyway.
1403
aHypotheticalPos.mBStart = placeholderOffset.B(wm);
1404
} else {
1405
NS_ASSERTION(iter.GetContainer() == blockFrame,
1406
"Found placeholder in wrong block!");
1407
nsBlockFrame::LineIterator lineBox = iter.GetLine();
1408
1409
// How we determine the hypothetical box depends on whether the element
1410
// would have been inline-level or block-level
1411
LogicalRect lineBounds = lineBox->GetBounds().ConvertTo(
1412
wm, lineBox->mWritingMode, lineBox->mContainerSize);
1413
if (mStyleDisplay->IsOriginalDisplayInlineOutside()) {
1414
// Use the block-start of the inline box which the placeholder lives in
1415
// as the hypothetical box's block-start.
1416
aHypotheticalPos.mBStart = lineBounds.BStart(wm) + blockOffset.B(wm);
1417
} else {
1418
// The element would have been block-level which means it would
1419
// be below the line containing the placeholder frame, unless
1420
// all the frames before it are empty. In that case, it would
1421
// have been just before this line.
1422
// XXXbz the line box is not fully reflowed yet if our
1423
// containing block is relatively positioned...
1424
if (lineBox != iter.End()) {
1425
nsIFrame* firstFrame = lineBox->mFirstChild;
1426
bool allEmpty = false;
1427
if (firstFrame == aPlaceholderFrame) {
1428
aPlaceholderFrame->SetLineIsEmptySoFar(true);
1429
allEmpty = true;
1430
} else {
1431
auto prev = aPlaceholderFrame->GetPrevSibling();
1432
if (prev && prev->IsPlaceholderFrame()) {
1433
auto ph = static_cast<nsPlaceholderFrame*>(prev);
1434
if (ph->GetLineIsEmptySoFar(&allEmpty)) {
1435
aPlaceholderFrame->SetLineIsEmptySoFar(allEmpty);
1436
}
1437
}
1438
}
1439
if (!allEmpty) {
1440
bool found = false;
1441
while (firstFrame) { // See bug 223064
1442
allEmpty = AreAllEarlierInFlowFramesEmpty(
1443
firstFrame, aPlaceholderFrame, &found);
1444
if (found || !allEmpty) {
1445
break;
1446
}
1447
firstFrame = firstFrame->GetNextSibling();
1448
}
1449
aPlaceholderFrame->SetLineIsEmptySoFar(allEmpty);
1450
}
1451
NS_ASSERTION(firstFrame, "Couldn't find placeholder!");
1452
1453
if (allEmpty) {
1454
// The top of the hypothetical box is the top of the line
1455
// containing the placeholder, since there is nothing in the
1456
// line before our placeholder except empty frames.
1457
aHypotheticalPos.mBStart =
1458
lineBounds.BStart(wm) + blockOffset.B(wm);
1459
} else {
1460
// The top of the hypothetical box is just below the line
1461
// containing the placeholder.
1462
aHypotheticalPos.mBStart = lineBounds.BEnd(wm) + blockOffset.B(wm);
1463
}
1464
} else {
1465
// Just use the placeholder's block-offset wrt the containing block
1466
aHypotheticalPos.mBStart = placeholderOffset.B(wm);
1467
}
1468
}
1469
}
1470
} else {
1471
// The containing block is not a block, so it's probably something
1472
// like a XUL box, etc.
1473
// Just use the placeholder's block-offset
1474
aHypotheticalPos.mBStart = placeholderOffset.B(wm);
1475
}
1476
1477
// Second, determine the hypothetical box's mIStart.
1478
// How we determine the hypothetical box depends on whether the element
1479
// would have been inline-level or block-level
1480
if (mStyleDisplay->IsOriginalDisplayInlineOutside() ||
1481
mFlags.mIOffsetsNeedCSSAlign) {
1482
// The placeholder represents the IStart edge of the hypothetical box.
1483
// (Or if mFlags.mIOffsetsNeedCSSAlign is set, it represents the IStart
1484
// edge of the Alignment Container.)
1485
aHypotheticalPos.mIStart = placeholderOffset.I(wm);
1486
} else {
1487
aHypotheticalPos.mIStart = blockIStartContentEdge;
1488
}
1489
1490
// The current coordinate space is that of the nearest block to the
1491
// placeholder. Convert to the coordinate space of the absolute containing
1492
// block.
1493
nsPoint cbOffset =
1494
containingBlock->GetOffsetToIgnoringScrolling(aCBReflowInput->mFrame);
1495
1496
nsSize reflowSize = aCBReflowInput->ComputedSizeAsContainerIfConstrained();
1497
LogicalPoint logCBOffs(wm, cbOffset, reflowSize - containerSize);
1498
aHypotheticalPos.mIStart += logCBOffs.I(wm);
1499
aHypotheticalPos.mBStart += logCBOffs.B(wm);
1500
1501
// The specified offsets are relative to the absolute containing block's
1502
// padding edge and our current values are relative to the border edge, so
1503
// translate.
1504
LogicalMargin border = aCBReflowInput->ComputedLogicalBorderPadding() -
1505
aCBReflowInput->ComputedLogicalPadding();
1506
border = border.ConvertTo(wm, aCBReflowInput->GetWritingMode());
1507
aHypotheticalPos.mIStart -= border.IStart(wm);
1508
aHypotheticalPos.mBStart -= border.BStart(wm);
1509
1510
// At this point, we have computed aHypotheticalPos using the writing mode
1511
// of the placeholder's containing block.
1512
1513
if (cbwm.GetBlockDir() != wm.GetBlockDir()) {
1514
// If the block direction we used in calculating aHypotheticalPos does not
1515
// match the absolute containing block's, we need to convert here so that
1516
// aHypotheticalPos is usable in relation to the absolute containing block.
1517
// This requires computing or measuring the abspos frame's block-size,
1518
// which is not otherwise required/used here (as aHypotheticalPos
1519
// records only the block-start coordinate).
1520
1521
// This is similar to the inline-size calculation for a replaced
1522
// inline-level element or a block-level element (above), except that
1523
// 'auto' sizing is handled differently in the block direction for non-
1524
// replaced elements and replaced elements lacking an intrinsic size.
1525
1526
// Determine the total amount of block direction
1527
// border/padding/margin that the element would have had if it had
1528
// been in the flow. Note that we ignore any 'auto' and 'inherit'
1529
// values.
1530
nscoord insideBoxSizing, outsideBoxSizing;
1531
CalculateBorderPaddingMargin(eLogicalAxisBlock, blockContentSize.BSize(wm),
1532
&insideBoxSizing, &outsideBoxSizing);
1533
1534
nscoord boxBSize;
1535
const auto& styleBSize = mStylePosition->BSize(wm);
1536
if (styleBSize.BehavesLikeInitialValueOnBlockAxis()) {
1537
if (NS_FRAME_IS_REPLACED(mFrameType) && knowIntrinsicSize) {
1538
// It's a replaced element with an 'auto' block size so the box
1539
// block size is its intrinsic size plus any border/padding/margin
1540
boxBSize = LogicalSize(wm, intrinsicSize).BSize(wm) + outsideBoxSizing +
1541
insideBoxSizing;
1542
} else {
1543
// XXX Bug 1191801
1544
// Figure out how to get the correct boxBSize here (need to reflow the
1545
// positioned frame?)
1546
boxBSize = 0;
1547
}
1548
} else {
1549
// We need to compute it. It's important we do this, because if it's
1550
// percentage-based this computed value may be different from the
1551
// computed value calculated using the absolute containing block height.
1552
boxBSize = nsLayoutUtils::ComputeBSizeValue(
1553
blockContentSize.BSize(wm), insideBoxSizing,
1554
styleBSize.AsLengthPercentage()) +
1555
insideBoxSizing + outsideBoxSizing;
1556
}
1557
1558
LogicalSize boxSize(wm, knowBoxISize ? boxISize : 0, boxBSize);
1559
1560
LogicalPoint origin(wm, aHypotheticalPos.mIStart, aHypotheticalPos.mBStart);
1561
origin =
1562
origin.ConvertTo(cbwm, wm, reflowSize - boxSize.GetPhysicalSize(wm));
1563
1564
aHypotheticalPos.mIStart = origin.I(cbwm);
1565
aHypotheticalPos.mBStart = origin.B(cbwm);
1566
aHypotheticalPos.mWritingMode = cbwm;
1567
} else {
1568
aHypotheticalPos.mWritingMode = wm;
1569
}
1570
}
1571
1572
void ReflowInput::InitAbsoluteConstraints(nsPresContext* aPresContext,
1573
const ReflowInput* aCBReflowInput,
1574
const LogicalSize& aCBSize,
1575
LayoutFrameType aFrameType) {
1576
WritingMode wm = GetWritingMode();
1577
WritingMode cbwm = aCBReflowInput->GetWritingMode();
1578
NS_WARNING_ASSERTION(aCBSize.BSize(cbwm) != NS_UNCONSTRAINEDSIZE,
1579
"containing block bsize must be constrained");
1580
1581
NS_ASSERTION(aFrameType != LayoutFrameType::Table,
1582
"InitAbsoluteConstraints should not be called on table frames");
1583
NS_ASSERTION(mFrame->GetStateBits() & NS_FRAME_OUT_OF_FLOW,
1584
"Why are we here?");
1585
1586
const auto& styleOffset = mStylePosition->mOffset;
1587
bool iStartIsAuto = styleOffset.GetIStart(cbwm).IsAuto();
1588
bool iEndIsAuto = styleOffset.GetIEnd(cbwm).IsAuto();
1589
bool bStartIsAuto = styleOffset.GetBStart(cbwm).IsAuto();
1590
bool bEndIsAuto = styleOffset.GetBEnd(cbwm).IsAuto();
1591
1592
// If both 'left' and 'right' are 'auto' or both 'top' and 'bottom' are
1593
// 'auto', then compute the hypothetical box position where the element would
1594
// have been if it had been in the flow
1595
nsHypotheticalPosition hypotheticalPos;
1596
if ((iStartIsAuto && iEndIsAuto) || (bStartIsAuto && bEndIsAuto)) {
1597
nsPlaceholderFrame* placeholderFrame = mFrame->GetPlaceholderFrame();
1598
MOZ_ASSERT(placeholderFrame, "no placeholder frame");
1599
1600
if (placeholderFrame->HasAnyStateBits(
1601
PLACEHOLDER_STATICPOS_NEEDS_CSSALIGN)) {
1602
DebugOnly<nsIFrame*> placeholderParent = placeholderFrame->GetParent();
1603
MOZ_ASSERT(placeholderParent, "shouldn't have unparented placeholders");
1604
MOZ_ASSERT(placeholderParent->IsFlexOrGridContainer(),
1605
"This flag should only be set on grid/flex children");
1606
1607
// If the (as-yet unknown) static position will determine the inline
1608
// and/or block offsets, set flags to note those offsets aren't valid
1609
// until we can do CSS Box Alignment on the OOF frame.
1610
mFlags.mIOffsetsNeedCSSAlign = (iStartIsAuto && iEndIsAuto);
1611
mFlags.mBOffsetsNeedCSSAlign = (bStartIsAuto && bEndIsAuto);
1612
}
1613
1614
if (mFlags.mStaticPosIsCBOrigin) {
1615
hypotheticalPos.mWritingMode = cbwm;
1616
hypotheticalPos.mIStart = nscoord(0);
1617
hypotheticalPos.mBStart = nscoord(0);
1618
} else {
1619
// XXXmats all this is broken for orthogonal writing-modes: bug 1521988.
1620
CalculateHypotheticalPosition(aPresContext, placeholderFrame,
1621
aCBReflowInput, hypotheticalPos,
1622
aFrameType);
1623
if (aCBReflowInput->mFrame->IsGridContainerFrame()) {
1624
// 'hypotheticalPos' is relative to the padding rect of the CB *frame*.
1625
// In grid layout the CB is the grid area rectangle, so we translate
1626
// 'hypotheticalPos' to be relative that rectangle here.
1627
nsRect cb = nsGridContainerFrame::GridItemCB(mFrame);
1628
nscoord left(0);
1629
nscoord right(0);
1630
if (cbwm.IsBidiLTR()) {
1631
left = cb.X();
1632
} else {
1633
right = aCBReflowInput->ComputedWidth() +
1634
aCBReflowInput->ComputedPhysicalPadding().LeftRight() -
1635
cb.XMost();
1636
}
1637
LogicalMargin offsets(cbwm, nsMargin(cb.Y(), right, nscoord(0), left));
1638
hypotheticalPos.mIStart -= offsets.IStart(cbwm);
1639
hypotheticalPos.mBStart -= offsets.BStart(cbwm);
1640
}
1641
}
1642
}
1643
1644
// Initialize the 'left' and 'right' computed offsets
1645
// XXX Handle new 'static-position' value...
1646
1647
// Size of the containing block in its writing mode
1648
LogicalSize cbSize = aCBSize;
1649
LogicalMargin offsets = ComputedLogicalOffsets().ConvertTo(cbwm, wm);
1650
1651
if (iStartIsAuto) {
1652
offsets.IStart(cbwm) = 0;
1653
} else {
1654
offsets.IStart(cbwm) = nsLayoutUtils::ComputeCBDependentValue(
1655
cbSize.ISize(cbwm), styleOffset.GetIStart(cbwm));
1656
}
1657
if (iEndIsAuto) {
1658
offsets.IEnd(cbwm) = 0;
1659
} else {
1660
offsets.IEnd(cbwm) = nsLayoutUtils::ComputeCBDependentValue(
1661
cbSize.ISize(cbwm), styleOffset.GetIEnd(cbwm));
1662
}
1663
1664
if (iStartIsAuto && iEndIsAuto) {
1665
if (cbwm.IsBidiLTR() != hypotheticalPos.mWritingMode.IsBidiLTR()) {
1666
offsets.IEnd(cbwm) = hypotheticalPos.mIStart;
1667
iEndIsAuto = false;
1668
} else {
1669
offsets.IStart(cbwm) = hypotheticalPos.mIStart;
1670
iStartIsAuto = false;
1671
}
1672
}
1673
1674
if (bStartIsAuto) {
1675
offsets.BStart(cbwm) = 0;
1676
} else {
1677
offsets.BStart(cbwm) = nsLayoutUtils::ComputeBSizeDependentValue(
1678
cbSize.BSize(cbwm), styleOffset.GetBStart(cbwm));
1679
}
1680
if (bEndIsAuto) {
1681
offsets.BEnd(cbwm) = 0;
1682
} else {
1683
offsets.BEnd(cbwm) = nsLayoutUtils::ComputeBSizeDependentValue(
1684
cbSize.BSize(cbwm), styleOffset.GetBEnd(cbwm));
1685
}
1686
1687
if (bStartIsAuto && bEndIsAuto) {
1688
// Treat 'top' like 'static-position'
1689
offsets.BStart(cbwm) = hypotheticalPos.mBStart;
1690
bStartIsAuto = false;
1691
}
1692
1693
SetComputedLogicalOffsets(offsets.ConvertTo(wm, cbwm));
1694
1695
typedef nsIFrame::ComputeSizeFlags ComputeSizeFlags;
1696
ComputeSizeFlags computeSizeFlags = ComputeSizeFlags::eDefault;
1697
if (mFlags.mIClampMarginBoxMinSize) {
1698
computeSizeFlags = ComputeSizeFlags(
1699
computeSizeFlags | ComputeSizeFlags::eIClampMarginBoxMinSize);
1700
}
1701
if (mFlags.mBClampMarginBoxMinSize) {
1702
computeSizeFlags = ComputeSizeFlags(
1703
computeSizeFlags | ComputeSizeFlags::eBClampMarginBoxMinSize);
1704
}
1705
if (mFlags.mApplyAutoMinSize) {
1706
computeSizeFlags = ComputeSizeFlags(computeSizeFlags |
1707
ComputeSizeFlags::eIApplyAutoMinSize);
1708
}
1709
if (mFlags.mShrinkWrap) {
1710
computeSizeFlags =
1711
ComputeSizeFlags(computeSizeFlags | ComputeSizeFlags::eShrinkWrap);
1712
}
1713
if (mFlags.mUseAutoBSize) {
1714
computeSizeFlags =
1715
ComputeSizeFlags(computeSizeFlags | ComputeSizeFlags::eUseAutoBSize);
1716
}
1717
if (wm.IsOrthogonalTo(cbwm)) {
1718
if (bStartIsAuto || bEndIsAuto) {
1719
computeSizeFlags =
1720
ComputeSizeFlags(computeSizeFlags | ComputeSizeFlags::eShrinkWrap);
1721
}
1722
} else {
1723
if (iStartIsAuto || iEndIsAuto) {
1724
computeSizeFlags =
1725
ComputeSizeFlags(computeSizeFlags | ComputeSizeFlags::eShrinkWrap);
1726
}
1727
}
1728
1729
LogicalSize computedSize(wm);
1730
{
1731
AutoMaybeDisableFontInflation an(mFrame);
1732
1733
computedSize = mFrame->ComputeSize(
1734
mRenderingContext, wm, cbSize.ConvertTo(wm, cbwm),
1735
cbSize.ConvertTo(wm, cbwm).ISize(wm), // XXX or AvailableISize()?
1736
ComputedLogicalMargin().Size(wm) + ComputedLogicalOffsets().Size(wm),
1737
ComputedLogicalBorderPadding().Size(wm) -
1738
ComputedLogicalPadding().Size(wm),
1739
ComputedLogicalPadding().Size(wm), computeSizeFlags);
1740
ComputedISize() = computedSize.ISize(wm);
1741
ComputedBSize() = computedSize.BSize(wm);
1742
NS_ASSERTION(ComputedISize() >= 0, "Bogus inline-size");
1743
NS_ASSERTION(
1744
ComputedBSize() == NS_UNCONSTRAINEDSIZE || ComputedBSize() >= 0,
1745
"Bogus block-size");
1746
}
1747
computedSize = computedSize.ConvertTo(cbwm, wm);
1748
1749
// XXX Now that we have ComputeSize, can we condense many of the
1750
// branches off of widthIsAuto?
1751
1752
LogicalMargin margin = ComputedLogicalMargin().ConvertTo(cbwm, wm);
1753
const LogicalMargin borderPadding =
1754
ComputedLogicalBorderPadding().ConvertTo(cbwm, wm);
1755
1756
bool iSizeIsAuto = mStyle