Bug 1470462 - contain:size for nsGridContainerFrame - r=dholbert

When contain:size is set for a grid container, ignore sizes from children when
computing own size during layout.

Differential Revision: https://phabricator.services.mozilla.com/D4429

--HG--
rename : layout/reftests/w3c-css/submitted/contain/contain-size-flex-001-ref.html => layout/reftests/w3c-css/submitted/contain/contain-size-grid-001-ref.html
rename : layout/reftests/w3c-css/submitted/contain/contain-size-flex-001.html => layout/reftests/w3c-css/submitted/contain/contain-size-grid-001.html
extra : moz-landing-system : lando
This commit is contained in:
Gerald Squelart 2018-09-11 00:00:05 +00:00
parent e88a043618
commit 7927ab927e
4 changed files with 147 additions and 11 deletions

View File

@ -5988,7 +5988,7 @@ nsGridContainerFrame::Reflow(nsPresContext* aPresContext,
const nscoord computedBSize = aReflowInput.ComputedBSize();
const nscoord computedISize = aReflowInput.ComputedISize();
const WritingMode& wm = gridReflowInput.mWM;
LogicalSize computedSize(wm, computedISize, computedBSize);
const LogicalSize computedSize(wm, computedISize, computedBSize);
nscoord consumedBSize = 0;
nscoord bSize = 0;
@ -5999,18 +5999,28 @@ nsGridContainerFrame::Reflow(nsPresContext* aPresContext,
gridReflowInput.CalculateTrackSizes(grid, computedSize,
SizingConstraint::eNoConstraint);
// Note: we can't use GridLineEdge here since we haven't calculated
// the rows' mPosition yet (happens in AlignJustifyContent below).
for (const auto& sz : gridReflowInput.mRows.mSizes) {
bSize += sz.mBase;
// XXX Technically incorrect: We're ignoring our row sizes, when really
// we should use them but *they* should be computed as if we had no
// children. To be fixed in bug 1488878.
if (!aReflowInput.mStyleDisplay->IsContainSize()) {
// Note: we can't use GridLineEdge here since we haven't calculated
// the rows' mPosition yet (happens in AlignJustifyContent below).
for (const auto& sz : gridReflowInput.mRows.mSizes) {
bSize += sz.mBase;
}
bSize += gridReflowInput.mRows.SumOfGridGaps();
}
bSize += gridReflowInput.mRows.SumOfGridGaps();
} else {
consumedBSize = ConsumedBSize(wm);
gridReflowInput.InitializeForContinuation(this, consumedBSize);
const uint32_t numRows = gridReflowInput.mRows.mSizes.Length();
bSize = gridReflowInput.mRows.GridLineEdge(numRows,
GridLineSide::eAfterGridGap);
// XXX Technically incorrect: We're ignoring our row sizes, when really
// we should use them but *they* should be computed as if we had no
// children. To be fixed in bug 1488878.
if (!aReflowInput.mStyleDisplay->IsContainSize()) {
const uint32_t numRows = gridReflowInput.mRows.mSizes.Length();
bSize = gridReflowInput.mRows.GridLineEdge(numRows,
GridLineSide::eAfterGridGap);
}
}
if (computedBSize == NS_AUTOHEIGHT) {
bSize = NS_CSS_MINMAX(bSize,
@ -6476,7 +6486,9 @@ nsGridContainerFrame::GetMinISize(gfxContext* aRC)
{
DISPLAY_MIN_WIDTH(this, mCachedMinISize);
if (mCachedMinISize == NS_INTRINSIC_WIDTH_UNKNOWN) {
mCachedMinISize = IntrinsicISize(aRC, nsLayoutUtils::MIN_ISIZE);
mCachedMinISize = StyleDisplay()->IsContainSize()
? 0
: IntrinsicISize(aRC, nsLayoutUtils::MIN_ISIZE);
}
return mCachedMinISize;
}
@ -6486,7 +6498,9 @@ nsGridContainerFrame::GetPrefISize(gfxContext* aRC)
{
DISPLAY_PREF_WIDTH(this, mCachedPrefISize);
if (mCachedPrefISize == NS_INTRINSIC_WIDTH_UNKNOWN) {
mCachedPrefISize = IntrinsicISize(aRC, nsLayoutUtils::PREF_ISIZE);
mCachedPrefISize = StyleDisplay()->IsContainSize()
? 0
: IntrinsicISize(aRC, nsLayoutUtils::PREF_ISIZE);
}
return mCachedPrefISize;
}

View File

@ -0,0 +1,49 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>CSS Reftest Reference</title>
<link rel="author" title="Gerald Squelart" href="mailto:gsquelart@mozilla.com">
<style>
.basic {
display: grid;
border: 1em solid green;
}
.height-ref {
height: 40px;
background: lightblue;
}
.width-ref {
width: 40px;
}
.floatLBasic-ref {
float: left;
}
.floatLWidth-ref {
float: left;
width: 40px;
}
</style>
</head>
<body>
<div class="basic"></div>
<br>
<div class="basic height-ref"></div>
<br>
<div class="basic height-ref"></div>
<br>
<div class="basic width-ref"></div>
<br>
<div class="basic width-ref"></div>
<br>
<div class="basic floatLBasic-ref"></div>
<br>
<div class="basic floatLWidth-ref"></div>
</body>
</html>

View File

@ -0,0 +1,72 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>CSS Test: 'contain: size' on grid elements should cause them to be sized and baseline-aligned as if they had no contents.</title>
<link rel="author" title="Gerald Squelart" href="mailto:gsquelart@mozilla.com">
<link rel="help" href="https://drafts.csswg.org/css-contain/#containment-size">
<link rel="match" href="contain-size-grid-001-ref.html">
<style>
.contain {
display: grid;
contain:size;
border: 1em solid green;
background: red;
}
.innerContents {
color: transparent;
height: 100px;
width: 100px;
}
.minHeight {
min-height: 40px;
background: lightblue;
}
.height {
height: 40px;
background: lightblue;
}
.maxWidth {
max-width: 40px;
}
.width {
width: 40px;
}
.floatLBasic {
float: left;
}
.floatLWidth {
float: left;
width: 40px;
}
</style>
</head>
<body>
<!--CSS Test: A size-contained grid element with no specified size should render at 0 height regardless of content.-->
<div class="contain"><div class="innerContents">inner</div></div>
<br>
<!--CSS Test: A size-contained grid element with specified min-height should render at given min-height regardless of content.-->
<div class="contain minHeight"><div class="innerContents">inner</div></div>
<br>
<!--CSS Test: A size-contained grid element with specified height should render at given height regardless of content.-->
<div class="contain height"><div class="innerContents">inner</div></div>
<br>
<!--CSS Test: A size-contained grid element with specified max-width should render at given max-width and zero height regardless of content.-->
<div class="contain maxWidth"><div class="innerContents">inner</div></div>
<br>
<!--CSS Test: A size-contained grid element with specified width should render at given width and zero height regardless of content.-->
<div class="contain width"><div class="innerContents">inner</div></div>
<br>
<!--CSS Test: A size-contained floated grid element with no specified size should render at 0px by 0px regardless of content.-->
<div class="contain floatLBasic"><div class="innerContents">inner</div></div>
<br>
<!--CSS Test: A size-contained floated grid element with specified width and no specified height should render at given width and 0 height regardless of content.-->
<div class="contain floatLWidth"><div class="innerContents">inner</div></div>
</body>
</html>

View File

@ -22,6 +22,7 @@ pref(layout.css.overflow-clip-box.enabled,true) == contain-paint-clip-006.html c
== contain-size-inline-block-001.html contain-size-inline-block-001-ref.html
== contain-size-flex-001.html contain-size-flex-001-ref.html
fuzzy-if(webrender&&winWidget,0-3,0-2) == contain-size-inline-flex-001.html contain-size-inline-flex-001-ref.html # bug 1474093
== contain-size-grid-001.html contain-size-grid-001-ref.html
== contain-size-multicol-001.html contain-size-multicol-001-ref.html
== contain-size-fieldset-001.html contain-size-fieldset-001-ref.html
== contain-size-fieldset-002.html contain-size-fieldset-002-ref.html