Bug 776443 part 2. Support percent-less calc for internal table element widths. r=dbaron

This commit is contained in:
Boris Zbarsky 2012-11-21 11:19:37 -05:00
parent c882c3bf6c
commit 27793548d6
9 changed files with 39 additions and 22 deletions

View File

@ -2542,7 +2542,9 @@ nsLayoutUtils::IntrinsicForContainer(nsRenderingContext *aRenderingContext,
// If we have a specified width (or a specified 'min-width' greater
// than the specified 'max-width', which works out to the same thing),
// don't even bother getting the frame's intrinsic width.
// don't even bother getting the frame's intrinsic width, because in
// this case GetAbsoluteCoord(styleWidth, w) will always succeed, so
// we'll never need the intrinsic dimensions.
if (styleWidth.GetUnit() == eStyleUnit_Enumerated &&
(styleWidth.GetIntValue() == NS_STYLE_WIDTH_MAX_CONTENT ||
styleWidth.GetIntValue() == NS_STYLE_WIDTH_MIN_CONTENT)) {
@ -2551,7 +2553,7 @@ nsLayoutUtils::IntrinsicForContainer(nsRenderingContext *aRenderingContext,
// For -moz-max-content and -moz-min-content, we handle them like
// specified widths, but ignore -moz-box-sizing.
boxSizing = NS_STYLE_BOX_SIZING_CONTENT;
} else if (styleWidth.GetUnit() != eStyleUnit_Coord &&
} else if (!styleWidth.ConvertsToLength() &&
!(haveFixedMinWidth && haveFixedMaxWidth && maxw <= minw)) {
#ifdef DEBUG_INTRINSIC_WIDTH
++gNoiseIndent;

View File

@ -1968,8 +1968,9 @@ nsHTMLReflowState::InitConstraints(nsPresContext* aPresContext,
rowOrRowGroup = true;
}
// calc() acts like auto on internal table elements
if (eStyleUnit_Auto == widthUnit || width.IsCalcUnit()) {
// calc() with percentages acts like auto on internal table elements
if (eStyleUnit_Auto == widthUnit ||
(width.IsCalcUnit() && width.CalcHasPercent())) {
mComputedWidth = availableWidth;
if ((mComputedWidth != NS_UNCONSTRAINEDSIZE) && !rowOrRowGroup){

View File

@ -0,0 +1,6 @@
<!DOCTYPE html>
<style>
table { background: yellow; }
td { width: 500px; }
</style>
<table><tr><td>Should be 500px wide</td></tr></table>

View File

@ -0,0 +1,6 @@
<!DOCTYPE html>
<style>
table { background: yellow; }
td { width: calc(250px + 250px); }
</style>
<table><tr><td>Should be 500px wide</td></tr></table>

View File

@ -1715,6 +1715,7 @@ needs-focus == 731726-1.html 731726-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
== 776443-1.html 776443-1-ref.html
== 776443-2.html 776443-2-ref.html
== 776265-1a.html 776265-1-ref.html
== 776265-1b.html 776265-1-ref.html
== 776265-1c.html 776265-1-ref.html

View File

@ -2,7 +2,7 @@
<title>width: calc() on table-layout: auto tables</title>
<table border>
<tr>
<td>x</td>
<td style="width: 500px">x</td>
<td style="width: 100px">y</td>
</table>
<table border>

View File

@ -5,7 +5,7 @@ table { table-layout: fixed; width: 500px; border-spacing: 0 }
</style>
<table border>
<tr>
<td>x</td>
<td style="width: 500px">x</td>
<td style="width: 100px">y</td>
</table>
<table border>

View File

@ -137,10 +137,11 @@ GetWidthInfo(nsRenderingContext *aRenderingContext,
const nsStyleCoord &width = stylePos->mWidth;
nsStyleUnit unit = width.GetUnit();
// NOTE: We're ignoring calc() units here, for lack of a sensible
// idea for what to do with them. This means calc() is basically
// handled like 'auto' for table cells and columns.
if (unit == eStyleUnit_Coord) {
// NOTE: We're ignoring calc() units with percentages here, for lack of a
// sensible idea for what to do with them. This means calc() with
// percentages is basically handled like 'auto' for table cells and
// columns.
if (width.ConvertsToLength()) {
hasSpecifiedWidth = true;
// Note: since ComputeWidthValue was designed to return content-box
// width, it will (in some cases) subtract the box-sizing edges.
@ -192,7 +193,7 @@ GetWidthInfo(nsRenderingContext *aRenderingContext,
unit = maxWidth.GetUnit();
// XXX To really implement 'max-width' well, we'd need to store
// it separately on the columns.
if (unit == eStyleUnit_Coord || unit == eStyleUnit_Enumerated) {
if (maxWidth.ConvertsToLength() || unit == eStyleUnit_Enumerated) {
nscoord w =
nsLayoutUtils::ComputeWidthValue(aRenderingContext, aFrame,
0, 0, 0, maxWidth);
@ -205,7 +206,7 @@ GetWidthInfo(nsRenderingContext *aRenderingContext,
if (p < prefPercent)
prefPercent = p;
}
// treat calc() on max-width just like 'none'.
// treat calc() with percentages on max-width just like 'none'.
nsStyleCoord minWidth(stylePos->mMinWidth);
if (minWidth.GetUnit() == eStyleUnit_Enumerated) {
@ -218,7 +219,7 @@ GetWidthInfo(nsRenderingContext *aRenderingContext,
eStyleUnit_Enumerated);
}
unit = minWidth.GetUnit();
if (unit == eStyleUnit_Coord || unit == eStyleUnit_Enumerated) {
if (minWidth.ConvertsToLength() || unit == eStyleUnit_Enumerated) {
nscoord w =
nsLayoutUtils::ComputeWidthValue(aRenderingContext, aFrame,
0, 0, 0, minWidth);
@ -231,7 +232,7 @@ GetWidthInfo(nsRenderingContext *aRenderingContext,
if (p > prefPercent)
prefPercent = p;
}
// treat calc() on min-width just like '0'.
// treat calc() with percentages on min-width just like '0'.
// XXX Should col frame have border/padding considered?
if (aIsCell) {

View File

@ -66,7 +66,7 @@ FixedTableLayoutStrategy::GetMinWidth(nsRenderingContext* aRenderingContext)
}
const nsStyleCoord *styleWidth =
&colFrame->GetStylePosition()->mWidth;
if (styleWidth->GetUnit() == eStyleUnit_Coord) {
if (styleWidth->ConvertsToLength()) {
result += nsLayoutUtils::ComputeWidthValue(aRenderingContext,
colFrame, 0, 0, 0, *styleWidth);
} else if (styleWidth->GetUnit() == eStyleUnit_Percent) {
@ -74,7 +74,7 @@ FixedTableLayoutStrategy::GetMinWidth(nsRenderingContext* aRenderingContext)
} else {
NS_ASSERTION(styleWidth->GetUnit() == eStyleUnit_Auto ||
styleWidth->GetUnit() == eStyleUnit_Enumerated ||
styleWidth->IsCalcUnit(),
(styleWidth->IsCalcUnit() && styleWidth->CalcHasPercent()),
"bad width");
// The 'table-layout: fixed' algorithm considers only cells
@ -85,7 +85,7 @@ FixedTableLayoutStrategy::GetMinWidth(nsRenderingContext* aRenderingContext)
cellMap->GetCellInfoAt(0, col, &originates, &colSpan);
if (cellFrame) {
styleWidth = &cellFrame->GetStylePosition()->mWidth;
if (styleWidth->GetUnit() == eStyleUnit_Coord ||
if (styleWidth->ConvertsToLength() ||
(styleWidth->GetUnit() == eStyleUnit_Enumerated &&
(styleWidth->GetIntValue() == NS_STYLE_WIDTH_MAX_CONTENT ||
styleWidth->GetIntValue() == NS_STYLE_WIDTH_MIN_CONTENT))) {
@ -107,7 +107,7 @@ FixedTableLayoutStrategy::GetMinWidth(nsRenderingContext* aRenderingContext)
}
}
// else, for 'auto', '-moz-available', '-moz-fit-content',
// and 'calc()', do nothing
// and 'calc()' with percentages, do nothing
}
}
}
@ -208,7 +208,7 @@ FixedTableLayoutStrategy::ComputeColumnWidths(const nsHTMLReflowState& aReflowSt
const nsStyleCoord *styleWidth =
&colFrame->GetStylePosition()->mWidth;
nscoord colWidth;
if (styleWidth->GetUnit() == eStyleUnit_Coord) {
if (styleWidth->ConvertsToLength()) {
colWidth = nsLayoutUtils::ComputeWidthValue(
aReflowState.rendContext,
colFrame, 0, 0, 0, *styleWidth);
@ -221,7 +221,7 @@ FixedTableLayoutStrategy::ComputeColumnWidths(const nsHTMLReflowState& aReflowSt
} else {
NS_ASSERTION(styleWidth->GetUnit() == eStyleUnit_Auto ||
styleWidth->GetUnit() == eStyleUnit_Enumerated ||
styleWidth->IsCalcUnit(),
(styleWidth->IsCalcUnit() && styleWidth->CalcHasPercent()),
"bad width");
// The 'table-layout: fixed' algorithm considers only cells
@ -232,7 +232,7 @@ FixedTableLayoutStrategy::ComputeColumnWidths(const nsHTMLReflowState& aReflowSt
cellMap->GetCellInfoAt(0, col, &originates, &colSpan);
if (cellFrame) {
styleWidth = &cellFrame->GetStylePosition()->mWidth;
if (styleWidth->GetUnit() == eStyleUnit_Coord ||
if (styleWidth->ConvertsToLength() ||
(styleWidth->GetUnit() == eStyleUnit_Enumerated &&
(styleWidth->GetIntValue() == NS_STYLE_WIDTH_MAX_CONTENT ||
styleWidth->GetIntValue() == NS_STYLE_WIDTH_MIN_CONTENT))) {
@ -257,7 +257,7 @@ FixedTableLayoutStrategy::ComputeColumnWidths(const nsHTMLReflowState& aReflowSt
pctTotal += pct;
} else {
// 'auto', '-moz-available', '-moz-fit-content', and
// 'calc()'
// 'calc()' with percentages
colWidth = unassignedMarker;
}
if (colWidth != unassignedMarker) {