Bug 776265 - changing the way ComputeHeightValue works to make it work just

like ComputeWidthValue already does. this fixes {min,max}-height + adding
  reftests for {min,max}-{height,width} r=mats
This commit is contained in:
Charly Molter 2012-08-08 17:58:26 +02:00
Родитель a7aaa7a89e
Коммит 0ca4358d6c
18 изменённых файлов: 273 добавлений и 65 удалений

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

@ -2734,12 +2734,14 @@ nsLayoutUtils::ComputeWidthValue(
nscoord result;
if (aCoord.IsCoordPercentCalcUnit()) {
result = nsRuleNode::ComputeCoordPercentCalc(aCoord, aContainingBlockWidth);
result = nsRuleNode::ComputeCoordPercentCalc(aCoord,
aContainingBlockWidth);
// The result of a calc() expression might be less than 0; we
// should clamp at runtime (below). (Percentages and coords that
// are less than 0 have already been dropped by the parser.)
result -= aContentEdgeToBoxSizing;
} else if (eStyleUnit_Enumerated == aCoord.GetUnit()) {
} else {
MOZ_ASSERT(eStyleUnit_Enumerated == aCoord.GetUnit());
// If aFrame is a container for font size inflation, then shrink
// wrapping inside of it should not apply font size inflation.
AutoMaybeDisableFontInflation an(aFrame);
@ -2768,15 +2770,10 @@ nsLayoutUtils::ComputeWidthValue(
result = aContainingBlockWidth -
(aBoxSizingToMarginEdge + aContentEdgeToBoxSizing);
}
} else {
NS_NOTREACHED("unexpected width value");
result = 0;
}
if (result < 0)
result = 0;
return result;
}
return NS_MAX(0, result);
}
/* static */ nscoord
nsLayoutUtils::ComputeHeightDependentValue(
@ -2842,14 +2839,12 @@ nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(
width = nsLayoutUtils::ComputeWidthValue(aRenderingContext,
aFrame, aCBSize.width, boxSizingAdjust.width,
boxSizingToMarginEdgeWidth, stylePos->mWidth);
NS_ASSERTION(width >= 0, "negative result from ComputeWidthValue");
}
if (stylePos->mMaxWidth.GetUnit() != eStyleUnit_None) {
maxWidth = nsLayoutUtils::ComputeWidthValue(aRenderingContext,
aFrame, aCBSize.width, boxSizingAdjust.width,
boxSizingToMarginEdgeWidth, stylePos->mMaxWidth);
NS_ASSERTION(maxWidth >= 0, "negative result from ComputeWidthValue");
} else {
maxWidth = nscoord_MAX;
}
@ -2857,32 +2852,25 @@ nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(
minWidth = nsLayoutUtils::ComputeWidthValue(aRenderingContext,
aFrame, aCBSize.width, boxSizingAdjust.width,
boxSizingToMarginEdgeWidth, stylePos->mMinWidth);
NS_ASSERTION(minWidth >= 0, "negative result from ComputeWidthValue");
if (!isAutoHeight) {
height = nsLayoutUtils::
ComputeHeightValue(aCBSize.height, stylePos->mHeight) -
boxSizingAdjust.height;
if (height < 0)
height = 0;
height = nsLayoutUtils::ComputeHeightValue(aCBSize.height,
boxSizingAdjust.height,
stylePos->mHeight);
}
if (!IsAutoHeight(stylePos->mMaxHeight, aCBSize.height)) {
maxHeight = nsLayoutUtils::
ComputeHeightValue(aCBSize.height, stylePos->mMaxHeight) -
boxSizingAdjust.height;
if (maxHeight < 0)
maxHeight = 0;
maxHeight = nsLayoutUtils::ComputeHeightValue(aCBSize.height,
boxSizingAdjust.height,
stylePos->mMaxHeight);
} else {
maxHeight = nscoord_MAX;
}
if (!IsAutoHeight(stylePos->mMinHeight, aCBSize.height)) {
minHeight = nsLayoutUtils::
ComputeHeightValue(aCBSize.height, stylePos->mMinHeight) -
boxSizingAdjust.height;
if (minHeight < 0)
minHeight = 0;
minHeight = nsLayoutUtils::ComputeHeightValue(aCBSize.height,
boxSizingAdjust.height,
stylePos->mMinHeight);
} else {
minHeight = 0;
}

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

@ -913,13 +913,17 @@ public:
* Likewise, but for 'height', 'min-height', or 'max-height'.
*/
static nscoord ComputeHeightValue(nscoord aContainingBlockHeight,
nscoord aContentEdgeToBoxSizingBoxEdge,
const nsStyleCoord& aCoord)
{
MOZ_ASSERT(aContainingBlockHeight != NS_AUTOHEIGHT || !aCoord.HasPercent(),
"caller must deal with %% of unconstrained height");
MOZ_ASSERT(aCoord.IsCoordPercentCalcUnit());
nscoord result =
ComputeHeightDependentValue(aContainingBlockHeight, aCoord);
if (result < 0)
result = 0; // clamp calc()
return result;
nsRuleNode::ComputeCoordPercentCalc(aCoord, aContainingBlockHeight);
// Clamp calc(), and the subtraction for box-sizing.
return NS_MAX(0, result - aContentEdgeToBoxSizingBoxEdge);
}
static bool IsAutoHeight(const nsStyleCoord &aCoord, nscoord aCBHeight)

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

@ -514,14 +514,12 @@ nsTextControlFrame::Reflow(nsPresContext* aPresContext,
// set values of reflow's out parameters
aDesiredSize.width = aReflowState.ComputedWidth() +
aReflowState.mComputedBorderPadding.LeftRight();
aDesiredSize.height = NS_CSS_MINMAX(aReflowState.ComputedHeight(),
aReflowState.mComputedMinHeight,
aReflowState.mComputedMaxHeight);
nscoord lineHeight = aDesiredSize.height;
aDesiredSize.height += aReflowState.mComputedBorderPadding.TopBottom();
aReflowState.mComputedBorderPadding.LeftRight();
aDesiredSize.height = aReflowState.ComputedHeight() +
aReflowState.mComputedBorderPadding.TopBottom();
// computation of the ascent wrt the input height
nscoord lineHeight = aReflowState.ComputedHeight();
float inflation = nsLayoutUtils::FontSizeInflationFor(this);
if (!IsSingleLineTextControl()) {
lineHeight = nsHTMLReflowState::CalcLineHeight(GetStyleContext(),

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

@ -3872,7 +3872,6 @@ nsFrame::ComputeSize(nsRenderingContext *aRenderingContext,
}
nscoord boxSizingToMarginEdgeWidth =
aMargin.width + aBorder.width + aPadding.width - boxSizingAdjust.width;
// Compute width
if (stylePos->mWidth.GetUnit() != eStyleUnit_Auto) {
@ -3887,40 +3886,38 @@ nsFrame::ComputeSize(nsRenderingContext *aRenderingContext,
nsLayoutUtils::ComputeWidthValue(aRenderingContext, this,
aCBSize.width, boxSizingAdjust.width, boxSizingToMarginEdgeWidth,
stylePos->mMaxWidth);
if (maxWidth < result.width)
result.width = maxWidth;
result.width = NS_MIN(maxWidth, result.width);
}
nscoord minWidth =
nsLayoutUtils::ComputeWidthValue(aRenderingContext, this,
aCBSize.width, boxSizingAdjust.width, boxSizingToMarginEdgeWidth,
stylePos->mMinWidth);
if (minWidth > result.width)
result.width = minWidth;
result.width = NS_MAX(minWidth, result.width);
// Compute height
if (!nsLayoutUtils::IsAutoHeight(stylePos->mHeight, aCBSize.height)) {
result.height =
nsLayoutUtils::ComputeHeightValue(aCBSize.height, stylePos->mHeight) -
boxSizingAdjust.height;
nsLayoutUtils::ComputeHeightValue(aCBSize.height,
boxSizingAdjust.height,
stylePos->mHeight);
}
if (result.height != NS_UNCONSTRAINEDSIZE) {
if (!nsLayoutUtils::IsAutoHeight(stylePos->mMaxHeight, aCBSize.height)) {
nscoord maxHeight =
nsLayoutUtils::ComputeHeightValue(aCBSize.height, stylePos->mMaxHeight) -
boxSizingAdjust.height;
if (maxHeight < result.height)
result.height = maxHeight;
nsLayoutUtils::ComputeHeightValue(aCBSize.height,
boxSizingAdjust.height,
stylePos->mMaxHeight);
result.height = NS_MIN(maxHeight, result.height);
}
if (!nsLayoutUtils::IsAutoHeight(stylePos->mMinHeight, aCBSize.height)) {
nscoord minHeight =
nsLayoutUtils::ComputeHeightValue(aCBSize.height, stylePos->mMinHeight) -
boxSizingAdjust.height;
if (minHeight > result.height)
result.height = minHeight;
nsLayoutUtils::ComputeHeightValue(aCBSize.height,
boxSizingAdjust.height,
stylePos->mMinHeight);
result.height = NS_MAX(minHeight, result.height);
}
}
@ -3947,11 +3944,8 @@ nsFrame::ComputeSize(nsRenderingContext *aRenderingContext,
result.width = size.width;
}
if (result.width < 0)
result.width = 0;
if (result.height < 0)
result.height = 0;
result.width = NS_MAX(0, result.width);
result.height = NS_MAX(0, result.height);
return result;
}

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

@ -220,6 +220,24 @@ nsCSSOffsetState::ComputeWidthValue(nscoord aContainingBlockWidth,
outside, aCoord);
}
nscoord
nsCSSOffsetState::ComputeHeightValue(nscoord aContainingBlockHeight,
PRUint8 aBoxSizing,
const nsStyleCoord& aCoord)
{
nscoord inside = 0;
switch (aBoxSizing) {
case NS_STYLE_BOX_SIZING_BORDER:
inside = mComputedBorderPadding.TopBottom();
break;
case NS_STYLE_BOX_SIZING_PADDING:
inside = mComputedPadding.TopBottom();
break;
}
return nsLayoutUtils::ComputeHeightValue(aContainingBlockHeight,
inside, aCoord);
}
void
nsHTMLReflowState::SetComputedWidth(nscoord aComputedWidth)
{
@ -1962,8 +1980,9 @@ nsHTMLReflowState::InitConstraints(nsPresContext* aPresContext,
} else {
NS_ASSERTION(heightUnit == mStylePosition->mHeight.GetUnit(),
"unexpected height unit change");
mComputedHeight = nsLayoutUtils::
ComputeHeightValue(aContainingBlockHeight, mStylePosition->mHeight);
mComputedHeight = ComputeHeightValue(aContainingBlockHeight,
mStylePosition->mBoxSizing,
mStylePosition->mHeight);
}
// Doesn't apply to table elements
@ -2468,8 +2487,9 @@ nsHTMLReflowState::ComputeMinMaxValues(nscoord aContainingBlockWidth,
minHeight.IsCalcUnit())) {
mComputedMinHeight = 0;
} else {
mComputedMinHeight = nsLayoutUtils::
ComputeHeightValue(aContainingBlockHeight, minHeight);
mComputedMinHeight = ComputeHeightValue(aContainingBlockHeight,
mStylePosition->mBoxSizing,
minHeight);
}
const nsStyleCoord &maxHeight = mStylePosition->mMaxHeight;
nsStyleUnit maxHeightUnit = maxHeight.GetUnit();
@ -2487,8 +2507,9 @@ nsHTMLReflowState::ComputeMinMaxValues(nscoord aContainingBlockWidth,
maxHeight.IsCalcUnit())) {
mComputedMaxHeight = NS_UNCONSTRAINEDSIZE;
} else {
mComputedMaxHeight = nsLayoutUtils::
ComputeHeightValue(aContainingBlockHeight, maxHeight);
mComputedMaxHeight = ComputeHeightValue(aContainingBlockHeight,
mStylePosition->mBoxSizing,
maxHeight);
}
}

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

@ -192,6 +192,10 @@ protected:
nscoord ComputeWidthValue(nscoord aContainingBlockWidth,
PRUint8 aBoxSizing,
const nsStyleCoord& aCoord);
nscoord ComputeHeightValue(nscoord aContainingBlockHeight,
PRUint8 aBoxSizing,
const nsStyleCoord& aCoord);
};
/**

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

@ -0,0 +1,18 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Testcase for bug 776265</title>
<style type="text/css">
textarea {
float: left;
height: 40px;
width: 40px;
border: 1px solid #aaa;
padding: 4px;
}
</style>
</head>
<body><textarea></textarea>
</body>
</html>

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

@ -0,0 +1,21 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Testcase for bug 776265 - checks min-height with box-sizing: border-box</title>
<style type="text/css">
textarea {
float: left;
height: 40px;
width: 50px;
min-height: 50px;
border: 1px solid #aaa;
padding: 4px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
</style>
</head>
<body><textarea></textarea>
</body>
</html>

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

@ -0,0 +1,21 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Testcase for bug 776265 checks max-height with box-sizing: border-box</title>
<style type="text/css">
textarea {
float: left;
height: 70px;
width: 50px;
max-height: 50px;
border: 1px solid #aaa;
padding: 4px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
</style>
</head>
<body><textarea></textarea>
</body>
</html>

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

@ -0,0 +1,21 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Testcase for bug 776265 - checks min-width with box-sizing: border-box</title>
<style type="text/css">
textarea {
float: left;
width: 40px;
height: 50px;
min-width: 50px;
border: 1px solid #aaa;
padding: 4px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
</style>
</head>
<body><textarea></textarea>
</body>
</html>

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

@ -0,0 +1,21 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Testcase for bug 776265 - checks max-width with box-sizing: border-box</title>
<style type="text/css">
textarea {
float: left;
width: 70px;
height: 50px;
max-width: 50px;
border: 1px solid #aaa;
padding: 4px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
</style>
</head>
<body><textarea></textarea>
</body>
</html>

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

@ -0,0 +1,17 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Testcase for bug 776265</title>
<style type="text/css">
textarea {
float: left;
height: 50px;
width: 50px;
border: 1px solid #aaa;
padding: 4px;
}
</style>
</head>
<body><textarea></textarea>
</body>
</html>

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

@ -0,0 +1,18 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Testcase for bug 776265 - checks min-height</title>
<style type="text/css">
textarea {
float: left;
height: 30px;
width: 50px;
min-height: 50px;
border: 1px solid #aaa;
padding: 4px;
}
</style>
</head>
<body><textarea></textarea>
</body>
</html>

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

@ -0,0 +1,18 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Testcase for bug 776265 - checks max-height</title>
<style type="text/css">
textarea {
float: left;
height: 70px;
width: 50px;
max-height: 50px;
border: 1px solid #aaa;
padding: 4px;
}
</style>
</head>
<body><textarea></textarea>
</body>
</html>

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

@ -0,0 +1,18 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Testcase for bug 776265 - checks min-width</title>
<style type="text/css">
textarea {
float: left;
height: 50px;
width: 30px;
min-width: 50px;
border: 1px solid #aaa;
padding: 4px;
}
</style>
</head>
<body><textarea></textarea>
</body>
</html>

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

@ -0,0 +1,18 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Testcase for bug 776265 - checks max-width</title>
<style type="text/css">
textarea {
float: left;
height: 50px;
width: 70px;
max-width: 50px;
border: 1px solid #aaa;
padding: 4px;
}
</style>
</head>
<body><textarea></textarea>
</body>
</html>

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

@ -1711,3 +1711,11 @@ needs-focus == 731726-1.html 731726-1-ref.html
== 758561-1.html 758561-1-ref.html
fuzzy-if(true,1,19) == 759036-1.html 759036-1-ref.html
fuzzy-if(true,17,5859) == 759036-2.html 759036-2-ref.html
== 776265-1a.html 776265-1-ref.html
== 776265-1b.html 776265-1-ref.html
== 776265-1c.html 776265-1-ref.html
== 776265-1d.html 776265-1-ref.html
== 776265-2a.html 776265-2-ref.html
== 776265-2b.html 776265-2-ref.html
== 776265-2c.html 776265-2-ref.html
== 776265-2d.html 776265-2-ref.html

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

@ -60,7 +60,7 @@ load 433296-1.xul
load 434458-1.xul
load 460900-1.xul
load 464149-1.xul
load 464407-1.xhtml
asserts-if(winWidget,1) load 464407-1.xhtml # Bug 450974
load 467481-1.xul
load 470063-1.html
load 472189.xul