Bug 1917144 Part 2 - Add IntrinsicSizeInput::mContainingBlockSize. r=dholbert

Currently, only the grid container needs the containing block size to resolve
the transferred min and max sizes for `repeat()` function in
`nsGridContainerFrame::ComputeIntrinsicISize()`.

This patch is a preparation for Bug 1865438. `mContainingBlockSize` will be used
there, so it does not change any behavior yet.

Differential Revision: https://phabricator.services.mozilla.com/D221333
This commit is contained in:
Ting-Yu Lin 2024-09-11 18:01:40 +00:00
Родитель 00de44c0c3
Коммит f32549a8c7
13 изменённых файлов: 49 добавлений и 24 удалений

Просмотреть файл

@ -2622,7 +2622,7 @@ MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHODIMP nsDocumentViewer::GetContentSize(
const nscoord minISize = wm.IsVertical() ? constraints.mMinSize.height
: constraints.mMinSize.width;
const nscoord maxISize = wm.IsVertical() ? aMaxHeight : aMaxWidth;
const IntrinsicSizeInput input(rcx.get(), Nothing());
const IntrinsicSizeInput input(rcx.get(), Nothing(), Nothing());
if (aPrefWidth) {
prefISize = std::max(root->GetMinISize(input), aPrefWidth);
} else {

Просмотреть файл

@ -4298,7 +4298,7 @@ static Maybe<nscoord> GetIntrinsicSize(nsIFrame::ExtremumLength aLength,
} else {
// Bug 1363918: We need to refactor this function to compute a percentage
// basis when computing intrinsic sizes.
const IntrinsicSizeInput input(aRenderingContext, Nothing());
const IntrinsicSizeInput input(aRenderingContext, Nothing(), Nothing());
auto type = aLength == nsIFrame::ExtremumLength::MaxContent
? IntrinsicISizeType::PrefISize
: IntrinsicISizeType::MinISize;
@ -4415,7 +4415,7 @@ static nscoord AddIntrinsicSizeOffset(
} else {
// Bug 1363918: We need to refactor this function to compute a percentage
// basis when computing intrinsic sizes.
const IntrinsicSizeInput input(aRenderingContext, Nothing());
const IntrinsicSizeInput input(aRenderingContext, Nothing(), Nothing());
minContent = aFrame->GetMinISize(input);
maxContent = aFrame->GetPrefISize(input);
}
@ -4747,7 +4747,7 @@ nscoord nsLayoutUtils::IntrinsicForAxis(
percentageBasisBSizeForChildren = percentageBasisBSizeForFrame;
}
const IntrinsicSizeInput input(
aRenderingContext,
aRenderingContext, aPercentageBasis,
Some(LogicalSize(childWM, NS_UNCONSTRAINEDSIZE,
percentageBasisBSizeForChildren)));
result = aFrame->IntrinsicISize(input, aType);

Просмотреть файл

@ -249,7 +249,7 @@ LogicalSize nsTextControlFrame::CalcIntrinsicSize(gfxContext* aRenderingContext,
// Add the inline size of the button if our char size is explicit, so as to
// make sure to make enough space for it.
if (maybeCols.isSome() && mButton && mButton->GetPrimaryFrame()) {
const IntrinsicSizeInput input(aRenderingContext, Nothing());
const IntrinsicSizeInput input(aRenderingContext, Nothing(), Nothing());
intrinsicSize.ISize(aWM) += mButton->GetPrimaryFrame()->GetMinISize(input);
}

Просмотреть файл

@ -1039,7 +1039,8 @@ nsresult nsBlockFrame::GetPrefWidthTightBounds(gfxContext* aRenderingContext,
// determine the intrinsic inline sizes of MathML token elements. These
// elements shouldn't have percentage block sizes that require a
// percentage basis for resolution.
const IntrinsicSizeInput kidInput(aRenderingContext, Nothing());
const IntrinsicSizeInput kidInput(aRenderingContext, Nothing(),
Nothing());
for (int32_t i = 0, i_end = line->GetChildCount(); i != i_end;
++i, kid = kid->GetNextSibling()) {
rv = kid->GetPrefWidthTightBounds(aRenderingContext, &childX,

Просмотреть файл

@ -837,7 +837,9 @@ LogicalSize nsContainerFrame::ComputeAutoSize(
AutoMaybeDisableFontInflation an(this);
WritingMode tableWM = GetParent()->GetWritingMode();
const IntrinsicSizeInput input(aRenderingContext, Nothing());
const IntrinsicSizeInput input(
aRenderingContext, Some(aCBSize.ConvertTo(GetWritingMode(), aWM)),
Nothing());
if (aWM.IsOrthogonalTo(tableWM)) {
// For an orthogonal caption on a block-dir side of the table, shrink-wrap
// to min-isize.

Просмотреть файл

@ -6525,7 +6525,9 @@ nsIFrame::SizeComputationResult nsIFrame::ComputeSize(
result.ISize(aWM) = std::min(maxISize, result.ISize(aWM));
}
const IntrinsicSizeInput input(aRenderingContext, Nothing());
const IntrinsicSizeInput input(aRenderingContext,
Some(aCBSize.ConvertTo(GetWritingMode(), aWM)),
Nothing());
const auto& minISizeCoord = stylePos->MinISize(aWM);
nscoord minISize;
if (!minISizeCoord.IsAuto() && !shouldIgnoreMinMaxISize) {
@ -6757,8 +6759,9 @@ LogicalSize nsIFrame::ComputeAutoSize(
styleBSize, stylePos->MinBSize(aWM), stylePos->MaxBSize(aWM),
aCBSize.BSize(aWM), contentEdgeToBoxSizing.BSize(aWM));
const IntrinsicSizeInput input(
aRenderingContext, Some(LogicalSize(aWM, NS_UNCONSTRAINEDSIZE, bSize)
.ConvertTo(GetWritingMode(), aWM)));
aRenderingContext, Some(aCBSize.ConvertTo(GetWritingMode(), aWM)),
Some(LogicalSize(aWM, NS_UNCONSTRAINEDSIZE, bSize)
.ConvertTo(GetWritingMode(), aWM)));
result.ISize(aWM) = ShrinkISizeToFit(input, availBased, aFlags);
}
return result;
@ -6854,8 +6857,9 @@ nsIFrame::ISizeComputationResult nsIFrame::ComputeISizeValue(
aStyleBSize, stylePos->MinBSize(aWM), stylePos->MaxBSize(aWM),
aCBSize.BSize(aWM), aContentEdgeToBoxSizing.BSize(aWM));
const IntrinsicSizeInput input(
aRenderingContext, Some(LogicalSize(aWM, NS_UNCONSTRAINEDSIZE, bSize)
.ConvertTo(GetWritingMode(), aWM)));
aRenderingContext, Some(aCBSize.ConvertTo(GetWritingMode(), aWM)),
Some(LogicalSize(aWM, NS_UNCONSTRAINEDSIZE, bSize)
.ConvertTo(GetWritingMode(), aWM)));
nscoord result;
switch (aSize) {
case ExtremumLength::MaxContent:

Просмотреть файл

@ -423,6 +423,18 @@ struct FrameBidiData {
struct MOZ_STACK_CLASS IntrinsicSizeInput final {
gfxContext* const mContext;
// The content-box size of a frame's containing block (in the frame's own
// writing mode), used as a percentage basis for percentage-based sizes on the
// frame itself that contribute to its intrinsic size. For example, in grid
// layout, a percentage value of min-height be can transferred through the
// aspect-ratio to determine auto repeat columns specified in
// grid-template-columns.
//
// Note: it is acceptable for mContainingBlockSize to be Nothing() as long as
// the frame doesn't have percentage-based value for properties that need to
// be resolved in order to compute its intrinsic size.
Maybe<LogicalSize> mContainingBlockSize;
// The content-box size of a frame (in the frame's own writing mode), served
// as a percentage basis when computing the children's intrinsic
// contributions. If the basis is indefinite in a given axis, use
@ -435,22 +447,28 @@ struct MOZ_STACK_CLASS IntrinsicSizeInput final {
Maybe<LogicalSize> mPercentageBasisForChildren;
IntrinsicSizeInput(gfxContext* aContext,
const Maybe<LogicalSize>& aContainingBlockSize,
const Maybe<LogicalSize>& aPercentageBasisForChildren)
: mContext(aContext),
mContainingBlockSize(aContainingBlockSize),
mPercentageBasisForChildren(aPercentageBasisForChildren) {
MOZ_ASSERT(mContext);
}
// Construct a new IntrinsicSizeInput by copying from aSource.
// Construct a new IntrinsicSizeInput for children by copying from
// aParentInput.
//
// Note: since this constructor creates an IntrinsicSizeInput for the
// children, it does not copy mContainingBlockSize from aParentInput.
//
// This constructor converts mPercentageBasisForChildren's writing mode, if it
// exists. The original mPercentageBasis in aSource is expected to be in the
// writing mode aFromWM, and it will be converted to the writing mode aToWM.
IntrinsicSizeInput(const IntrinsicSizeInput& aSource,
IntrinsicSizeInput(const IntrinsicSizeInput& aParentInput,
mozilla::WritingMode aToWM, mozilla::WritingMode aFromWM)
: IntrinsicSizeInput(
aSource.mContext,
aSource.mPercentageBasisForChildren.map([&](const auto& aPB) {
aParentInput.mContext, Nothing(),
aParentInput.mPercentageBasisForChildren.map([&](const auto& aPB) {
return aPB.ConvertTo(aToWM, aFromWM);
})) {}
};

Просмотреть файл

@ -214,7 +214,7 @@ void nsRubyBaseContainerFrame::AddInlineMinISize(
void nsRubyBaseContainerFrame::AddInlinePrefISize(
const IntrinsicSizeInput& aInput, InlinePrefISizeData* aData) {
AutoRubyTextContainerArray textContainers(this);
const IntrinsicSizeInput input(aInput.mContext, Nothing());
const IntrinsicSizeInput input(aInput.mContext, Nothing(), Nothing());
nscoord sum = 0;
for (nsIFrame* frame = this; frame; frame = frame->GetNextInFlow()) {

Просмотреть файл

@ -56,7 +56,7 @@ void nsRubyFrame::AddInlineMinISize(const IntrinsicSizeInput& aInput,
auto handleChildren = [&](auto frame, auto data) {
// Ruby frames shouldn't have percentage block sizes that require a
// percentage basis for resolution.
const IntrinsicSizeInput input(aInput.mContext, Nothing());
const IntrinsicSizeInput input(aInput.mContext, Nothing(), Nothing());
for (RubySegmentEnumerator e(static_cast<nsRubyFrame*>(frame)); !e.AtEnd();
e.Next()) {
e.GetBaseContainer()->AddInlineMinISize(input, data);
@ -71,7 +71,7 @@ void nsRubyFrame::AddInlinePrefISize(const IntrinsicSizeInput& aInput,
auto handleChildren = [&](auto frame, auto data) {
// Ruby frames shouldn't have percentage block sizes that require a
// percentage basis for resolution.
const IntrinsicSizeInput input(aInput.mContext, Nothing());
const IntrinsicSizeInput input(aInput.mContext, Nothing(), Nothing());
for (RubySegmentEnumerator e(static_cast<nsRubyFrame*>(frame)); !e.AtEnd();
e.Next()) {
e.GetBaseContainer()->AddInlinePrefISize(input, data);

Просмотреть файл

@ -5105,7 +5105,7 @@ void SVGTextFrame::DoReflow() {
kid->MarkIntrinsicISizesDirty();
}
const IntrinsicSizeInput input(renderingContext.get(), Nothing());
const IntrinsicSizeInput input(renderingContext.get(), Nothing(), Nothing());
nscoord inlineSize = kid->GetPrefISize(input);
WritingMode wm = kid->GetWritingMode();
ReflowInput reflowInput(presContext, kid, renderingContext.get(),

Просмотреть файл

@ -107,7 +107,7 @@ static CellISizeInfo GetISizeInfo(gfxContext* aRenderingContext,
cbBSize, contentEdgeToBoxSizingBSize);
const IntrinsicSizeInput input(
aRenderingContext,
aRenderingContext, Nothing(),
Some(LogicalSize(aWM, NS_UNCONSTRAINEDSIZE, cellBSize)));
minCoord = aFrame->GetMinISize(input);
prefCoord = aFrame->GetPrefISize(input);

Просмотреть файл

@ -1403,7 +1403,7 @@ nsIFrame::SizeComputationResult nsTableFrame::ComputeSize(
AutoMaybeDisableFontInflation an(this);
// Tables never shrink below their min inline-size.
const IntrinsicSizeInput input(aRenderingContext, Nothing());
const IntrinsicSizeInput input(aRenderingContext, Some(aCBSize), Nothing());
nscoord minISize = GetMinISize(input);
if (minISize > result.mLogicalSize.ISize(aWM)) {
result.mLogicalSize.ISize(aWM) = minISize;
@ -1419,7 +1419,7 @@ nscoord nsTableFrame::TableShrinkISizeToFit(gfxContext* aRenderingContext,
AutoMaybeDisableFontInflation an(this);
nscoord result;
const IntrinsicSizeInput input(aRenderingContext, Nothing());
const IntrinsicSizeInput input(aRenderingContext, Nothing(), Nothing());
nscoord minISize = GetMinISize(input);
if (minISize > aISizeInCB) {
result = minISize;

Просмотреть файл

@ -250,7 +250,7 @@ nscoord nsTableWrapperFrame::IntrinsicISize(const IntrinsicSizeInput& aInput,
// Tables can't shrink smaller than their intrinsic minimum inline size,
// no matter what.
const IntrinsicSizeInput input(aInput.mContext, Nothing());
const IntrinsicSizeInput input(aInput.mContext, Nothing(), Nothing());
// GetMinISize() returns a content-box inline size, but we need the
// margin-box inline size as the contribution in the inline axis.