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