Add support for calc() to ComputeWidthDependentValue and ComputeHeightDependentValue. Also change calc() handling of percents from using round to using floor, which changes our handling of percents on 'width' back to using floor, reverting an earlier change in this bug. (Bug 585715) r=bzbarsky a2.0=blocking+

This commit is contained in:
L. David Baron 2010-08-25 12:17:55 +02:00
parent 3fc44d5786
commit 698bb0f927
2 changed files with 18 additions and 25 deletions

View File

@ -2147,12 +2147,8 @@ nsLayoutUtils::ComputeWidthDependentValue(
"very large sizes, not attempts at intrinsic width " "very large sizes, not attempts at intrinsic width "
"calculation"); "calculation");
if (eStyleUnit_Coord == aCoord.GetUnit()) { if (aCoord.IsCoordPercentCalcUnit()) {
return aCoord.GetCoordValue(); return nsRuleNode::ComputeCoordPercentCalc(aCoord, aContainingBlockWidth);
}
if (eStyleUnit_Percent == aCoord.GetUnit()) {
return NSToCoordFloorClamped(aContainingBlockWidth *
aCoord.GetPercentValue());
} }
NS_ASSERTION(aCoord.GetUnit() == eStyleUnit_None || NS_ASSERTION(aCoord.GetUnit() == eStyleUnit_None ||
aCoord.GetUnit() == eStyleUnit_Auto, aCoord.GetUnit() == eStyleUnit_Auto,
@ -2225,25 +2221,22 @@ nsLayoutUtils::ComputeHeightDependentValue(
nscoord aContainingBlockHeight, nscoord aContainingBlockHeight,
const nsStyleCoord& aCoord) const nsStyleCoord& aCoord)
{ {
if (eStyleUnit_Coord == aCoord.GetUnit()) { // XXXldb Some callers explicitly check aContainingBlockHeight
return aCoord.GetCoordValue(); // against NS_AUTOHEIGHT *and* unit against eStyleUnit_Percent or
} // calc()s containing percents before calling this function.
if (eStyleUnit_Percent == aCoord.GetUnit()) { // However, it would be much more likely to catch problems without
// XXXldb Some callers explicitly check aContainingBlockHeight // the unit conditions.
// against NS_AUTOHEIGHT *and* unit against eStyleUnit_Percent // XXXldb Many callers pass a non-'auto' containing block height when
// before calling this function, so this assertion probably needs to // according to CSS2.1 they should be passing 'auto'.
// be inside the percentage case. However, it would be much more NS_PRECONDITION(NS_AUTOHEIGHT != aContainingBlockHeight ||
// likely to catch problems if it were at the start of the function. (aCoord.GetUnit() != eStyleUnit_Percent &&
// XXXldb Many callers pass a non-'auto' containing block height when !(aCoord.IsCalcUnit() && aCoord.CalcHasPercent())),
// according to CSS2.1 they should be passing 'auto'. "unexpected containing block height");
NS_PRECONDITION(NS_AUTOHEIGHT != aContainingBlockHeight,
"unexpected 'containing block height'");
if (NS_AUTOHEIGHT != aContainingBlockHeight) { if (aCoord.IsCoordPercentCalcUnit()) {
return NSToCoordFloorClamped(aContainingBlockHeight * return nsRuleNode::ComputeCoordPercentCalc(aCoord, aContainingBlockHeight);
aCoord.GetPercentValue());
}
} }
NS_ASSERTION(aCoord.GetUnit() == eStyleUnit_None || NS_ASSERTION(aCoord.GetUnit() == eStyleUnit_None ||
aCoord.GetUnit() == eStyleUnit_Auto, aCoord.GetUnit() == eStyleUnit_Auto,
"unexpected height value"); "unexpected height value");

View File

@ -535,8 +535,8 @@ struct ComputeComputedCalcCalcOps : public css::StyleCoordInputCalcOps,
{ {
nscoord result; nscoord result;
if (aValue.GetUnit() == eStyleUnit_Percent) { if (aValue.GetUnit() == eStyleUnit_Percent) {
result = NSCoordSaturatingMultiply(mPercentageBasis, result =
aValue.GetPercentValue()); NSToCoordFloorClamped(mPercentageBasis * aValue.GetPercentValue());
} else { } else {
result = aValue.GetCoordValue(); result = aValue.GetCoordValue();
} }