Bug 930218 part 2. Account for the parent's box-sizing whe figuring out the percentage height of a kid with an intrinsic ratio for purposes of determining the parent's shrink-wrap width. r=dbaron

This commit is contained in:
Boris Zbarsky 2015-12-08 14:56:20 -05:00
parent ffcb398079
commit 668bee9c72
11 changed files with 124 additions and 10 deletions

View File

@ -4205,6 +4205,7 @@ GetBSizeTakenByBoxSizing(StyleBoxSizing aBoxSizing,
static bool
GetPercentBSize(const nsStyleCoord& aStyle,
nsIFrame* aFrame,
bool aHorizontalAxis,
nscoord& aResult)
{
if (eStyleUnit_Percent != aStyle.GetUnit() &&
@ -4231,7 +4232,7 @@ GetPercentBSize(const nsStyleCoord& aStyle,
const nsStyleCoord& bSizeCoord = pos->BSize(wm);
nscoord h;
if (!GetAbsoluteCoord(bSizeCoord, h) &&
!GetPercentBSize(bSizeCoord, f, h)) {
!GetPercentBSize(bSizeCoord, f, aHorizontalAxis, h)) {
NS_ASSERTION(bSizeCoord.GetUnit() == eStyleUnit_Auto ||
bSizeCoord.HasPercent(),
"unknown block-size unit");
@ -4261,7 +4262,7 @@ GetPercentBSize(const nsStyleCoord& aStyle,
nscoord maxh;
if (GetAbsoluteCoord(maxBSizeCoord, maxh) ||
GetPercentBSize(maxBSizeCoord, f, maxh)) {
GetPercentBSize(maxBSizeCoord, f, aHorizontalAxis, maxh)) {
if (maxh < h)
h = maxh;
} else {
@ -4274,7 +4275,7 @@ GetPercentBSize(const nsStyleCoord& aStyle,
nscoord minh;
if (GetAbsoluteCoord(minBSizeCoord, minh) ||
GetPercentBSize(minBSizeCoord, f, minh)) {
GetPercentBSize(minBSizeCoord, f, aHorizontalAxis, minh)) {
if (minh > h)
h = minh;
} else {
@ -4283,6 +4284,14 @@ GetPercentBSize(const nsStyleCoord& aStyle,
"unknown min block-size unit");
}
// Now adjust h for box-sizing styles on the parent. We never ignore padding
// here. That could conceivably cause some problems with fieldsets (which are
// the one place that wants to ignore padding), but solving that here without
// hardcoding a check for f being a fieldset-content frame is a bit of a pain.
nscoord bSizeTakenByBoxSizing =
GetBSizeTakenByBoxSizing(pos->mBoxSizing, f, aHorizontalAxis, false);
h = std::max(0, h - bSizeTakenByBoxSizing);
if (aStyle.IsCalcUnit()) {
aResult = std::max(nsRuleNode::ComputeComputedCalc(aStyle, h), 0);
return true;
@ -4328,11 +4337,11 @@ GetBSizeTakenByBoxSizing(StyleBoxSizing aBoxSizing,
// here as 0 instead, except that in some cases the width may in fact be
// known. See bug 1231059.
if (GetAbsoluteCoord(paddingStart, pad) ||
GetPercentBSize(paddingStart, aFrame, pad)) {
GetPercentBSize(paddingStart, aFrame, aHorizontalAxis, pad)) {
bSizeTakenByBoxSizing += pad;
}
if (GetAbsoluteCoord(paddingEnd, pad) ||
GetPercentBSize(paddingEnd, aFrame, pad)) {
GetPercentBSize(paddingEnd, aFrame, aHorizontalAxis, pad)) {
bSizeTakenByBoxSizing += pad;
}
}
@ -4711,13 +4720,13 @@ nsLayoutUtils::IntrinsicForAxis(PhysicalAxis aAxis,
nscoord h;
if (GetAbsoluteCoord(styleBSize, h) ||
GetPercentBSize(styleBSize, aFrame, h)) {
GetPercentBSize(styleBSize, aFrame, horizontalAxis, h)) {
h = std::max(0, h - bSizeTakenByBoxSizing);
result = NSCoordMulDiv(h, ratioISize, ratioBSize);
}
if (GetAbsoluteCoord(styleMaxBSize, h) ||
GetPercentBSize(styleMaxBSize, aFrame, h)) {
GetPercentBSize(styleMaxBSize, aFrame, horizontalAxis, h)) {
h = std::max(0, h - bSizeTakenByBoxSizing);
nscoord maxISize = NSCoordMulDiv(h, ratioISize, ratioBSize);
if (maxISize < result)
@ -4725,7 +4734,7 @@ nsLayoutUtils::IntrinsicForAxis(PhysicalAxis aAxis,
}
if (GetAbsoluteCoord(styleMinBSize, h) ||
GetPercentBSize(styleMinBSize, aFrame, h)) {
GetPercentBSize(styleMinBSize, aFrame, horizontalAxis, h)) {
h = std::max(0, h - bSizeTakenByBoxSizing);
nscoord minISize = NSCoordMulDiv(h, ratioISize, ratioBSize);
if (minISize > result)

View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<body>
<div style="display: inline-block; background: blue;
box-sizing: border-box; height: 200px;
border: 40px transparent solid">
<img src="lime100x100.png"
style="height: 100%; display: block; visibility: hidden;">
</div>
</body>

View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<body>
<div style="display: inline-block; background: blue;
box-sizing: padding-box; height: 120px;
border: 40px transparent solid">
<img src="lime100x100.png"
style="height: 100%; display: block; visibility: hidden;">
</div>
</body>

View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<body>
<div style="display: inline-block; background: blue;
box-sizing: border-box; height: 200px;
border: 25px transparent solid">
<div style="height: 100%; box-sizing: border-box;
border: 15px transparent solid;">
<img src="lime100x100.png"
style="height: 100%; display: block; visibility: hidden;">
</div>
</div>
</body>

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<body>
<div style="display: inline-block; background: blue;
box-sizing: border-box; height: 200px;
border: 40px transparent solid">
<!-- We need to be taller than intrinsic height, so use a min-height -->
<img src="lime100x100.png"
style="min-height: 100%; display: block; visibility: hidden;">
</div>
</body>

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<body>
<div style="display: inline-block; background: blue;
box-sizing: padding-box; height: 120px;
border: 40px transparent solid">
<!-- We need to be taller than intrinsic height, so use a min-height -->
<img src="lime100x100.png"
style="min-height: 100%; display: block; visibility: hidden;">
</div>
</body>

View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<body>
<div style="display: inline-block; background: blue;
box-sizing: border-box; height: 200px;
border: 25px transparent solid">
<div style="height: 100%; box-sizing: border-box;
border: 15px transparent solid;">
<!-- We need to be taller than intrinsic height, so use a min-height -->
<img src="lime100x100.png"
style="min-height: 100%; display: block; visibility: hidden;">
</div>
</div>
</body>

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<body>
<div style="display: inline-block; background: blue;
box-sizing: border-box; height: 200px;
border: 80px transparent solid">
<!-- We need to be shorter than intrinsic height, so use a max-height -->
<img src="lime100x100.png"
style="max-height: 100%; display: block; visibility: hidden;">
</div>
</body>

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<body>
<div style="display: inline-block; background: blue;
box-sizing: padding-box; height: 40px;
border: 80px transparent solid">
<!-- We need to be shorter than intrinsic height, so use a max-height -->
<img src="lime100x100.png"
style="max-height: 100%; display: block; visibility: hidden;">
</div>
</body>

View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<body>
<div style="display: inline-block; background: blue;
box-sizing: border-box; height: 200px;
border: 50px transparent solid">
<div style="height: 100%; box-sizing: border-box;
border: 30px transparent solid;">
<!-- We need to be shorter than intrinsic height, so use a max-height -->
<img src="lime100x100.png"
style="max-height: 100%; display: block; visibility: hidden;">
</div>
</div>
</body>

View File

@ -4,4 +4,13 @@
== intrinsic-1d.html intrinsic-1-ref.html
== intrinsic-1e.html intrinsic-1-ref.html
== intrinsic-1f.html intrinsic-1-ref.html
== intrinsic-1g.html intrinsic-1-ref.html
== intrinsic-1h.html intrinsic-1-ref.html
== intrinsic-1i.html intrinsic-1-ref.html
== intrinsic-1j.html intrinsic-1-ref.html
== intrinsic-1k.html intrinsic-1-ref.html
== intrinsic-1l.html intrinsic-1-ref.html
== intrinsic-1m.html intrinsic-1-ref.html
== intrinsic-1n.html intrinsic-1-ref.html
== intrinsic-1o.html intrinsic-1-ref.html
== computed-size-reporting.html computed-size-reporting-ref.html