Prefer distributing the width of a column-spanning cell to columns without specified widths, and make a specified width on a column-spanning cell not cause the column to be considered to have a specified width. b=379361 Patch by Daniel Holbert <dholbert@mozilla.com>. r+sr=dbaron

This commit is contained in:
dbaron@dbaron.org 2007-08-02 17:07:29 -07:00
Родитель 425eadbafc
Коммит c5c9d3cb46
9 изменённых файлов: 343 добавлений и 29 удалений

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

@ -0,0 +1,16 @@
<html>
<body>
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px; background: yellow">Cell A</td>
<td style="width: 300px; background: lightgreen">This text should be on one line</td>
</tr>
<tr>
<td style="width: 100px; background: lightblue" colspan="2">Cell B</td>
</tr>
</table>
</body>
</html>

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

@ -0,0 +1,16 @@
<html>
<body>
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px; background: yellow">Cell A</td>
<td style="background: lightgreen">This text should be on one line</td>
</tr>
<tr>
<td style="width: 100px; background: lightblue" colspan="2">Cell B</td>
</tr>
</table>
</body>
</html>

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

@ -0,0 +1,16 @@
<html>
<body>
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 300px; background: lightgreen">This text should be on one line</td>
<td style="width: 200px; background: yellow">Cell A</td>
</tr>
<tr>
<td style="width: 100px; background: lightblue" colspan="2">Cell B</td>
</tr>
</table>
</body>
</html>

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

@ -0,0 +1,16 @@
<html>
<body>
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="background: lightgreen">This text should be on one line</td>
<td style="width: 200px; background: yellow">Cell A</td>
</tr>
<tr>
<td style="width: 100px; background: lightblue" colspan="2">Cell B</td>
</tr>
</table>
</body>
</html>

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

@ -0,0 +1,123 @@
<html>
<body>
<li>Tables have width 500px.
<li>Yellow cells have width 200px.
<li>Green cells are auto-width.
<li>Blue cells have colspan = 2 and, in test case, have various specified widths.
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px; background: yellow"></td>
<td style="background: lightgreen">Here are some words.</td>
</tr>
<tr>
<td style="background: lightblue" colspan="2">10 px</td>
</tr>
</table>
<br/>
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px; background: yellow"></td>
<td style="background: lightgreen">Here are some words.</td>
</tr>
<tr>
<td style="background: lightblue" colspan="2">50 px</td>
</tr>
</table>
<br/>
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px; background: yellow"></td>
<td style="background: lightgreen">Here are some words.</td>
</tr>
<tr>
<td style="background: lightblue" colspan="2">100 px</td>
</tr>
</table>
<br/>
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px; background: yellow"></td>
<td style="background: lightgreen">Here are some words.</td>
</tr>
<tr>
<td style="background: lightblue" colspan="2">384 px</td>
</tr>
</table>
<br/>
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px; background: yellow"></td>
<td style="background: lightgreen">Here are some words.</td>
</tr>
<tr>
<td style="background: lightblue" colspan="2">385 px</td>
</tr>
</table>
<br/>
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px; background: yellow"></td>
<td style="background: lightgreen">Here are some words.</td>
</tr>
<tr>
<td style="background: lightblue" colspan="2">390 px</td>
</tr>
</table>
<br/>
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px; background: yellow"></td>
<td style="background: lightgreen">Here are some words.</td>
</tr>
<tr>
<td style="background: lightblue" colspan="2">500 px</td>
</tr>
</table>
<br/>
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px; background: yellow"></td>
<td style="background: lightgreen">Here are some words.</td>
</tr>
<tr>
<td style="background: lightblue" colspan="2">600 px</td>
</tr>
</table>
<br/>
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px; background: yellow"></td>
<td style="background: lightgreen">Here are some words.</td>
</tr>
<tr>
<td style="background: lightblue" colspan="2">900 px</td>
</tr>
</table>
<br/>
</table>
<br/>
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px; background: yellow"></td>
<td style="background: lightgreen">Here are some words.</td>
</tr>
<tr>
<td style="background: lightblue" colspan="2">1500 px</td>
</tr>
</table>
<br/>
</body>
</html>

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

@ -0,0 +1,123 @@
<html>
<body>
<li>Tables have width 500px.
<li>Yellow cells have width 200px.
<li>Green cells are auto-width.
<li>Blue cells have colspan = 2 and, in test case, have various specified widths.
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px; background: yellow"></td>
<td style="background: lightgreen">Here are some words.</td>
</tr>
<tr>
<td style="width: 10px; background: lightblue" colspan="2">10 px</td>
</tr>
</table>
<br/>
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px; background: yellow"></td>
<td style="background: lightgreen">Here are some words.</td>
</tr>
<tr>
<td style="width: 50px; background: lightblue" colspan="2">50 px</td>
</tr>
</table>
<br/>
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px; background: yellow"></td>
<td style="background: lightgreen">Here are some words.</td>
</tr>
<tr>
<td style="width: 100px; background: lightblue" colspan="2">100 px</td>
</tr>
</table>
<br/>
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px; background: yellow"></td>
<td style="background: lightgreen">Here are some words.</td>
</tr>
<tr>
<td style="width: 384px; background: lightblue" colspan="2">384 px</td>
</tr>
</table>
<br/>
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px; background: yellow"></td>
<td style="background: lightgreen">Here are some words.</td>
</tr>
<tr>
<td style="width: 385px; background: lightblue" colspan="2">385 px</td>
</tr>
</table>
<br/>
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px; background: yellow"></td>
<td style="background: lightgreen">Here are some words.</td>
</tr>
<tr>
<td style="width: 390px; background: lightblue" colspan="2">390 px</td>
</tr>
</table>
<br/>
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px; background: yellow"></td>
<td style="background: lightgreen">Here are some words.</td>
</tr>
<tr>
<td style="width: 500px; background: lightblue" colspan="2">500 px</td>
</tr>
</table>
<br/>
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px; background: yellow"></td>
<td style="background: lightgreen">Here are some words.</td>
</tr>
<tr>
<td style="width: 600px; background: lightblue" colspan="2">600 px</td>
</tr>
</table>
<br/>
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px; background: yellow"></td>
<td style="background: lightgreen">Here are some words.</td>
</tr>
<tr>
<td style="width: 900px; background: lightblue" colspan="2">900 px</td>
</tr>
</table>
<br/>
</table>
<br/>
<table width="500px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px; background: yellow"></td>
<td style="background: lightgreen">Here are some words.</td>
</tr>
<tr>
<td style="width: 1500px; background: lightblue" colspan="2">1500 px</td>
</tr>
</table>
<br/>
</body>
</html>

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

@ -302,6 +302,8 @@ fails-if(MOZ_WIDGET_TOOLKIT=="cocoa") == 372037-1.html 372037-1-ref.html # bug 3
== 377918.html 377918-ref.html
== 378535-1.html 378535-1-ref.html
== 379316-1.html 379316-1-ref.html
random-if(MOZ_WIDGET_TOOLKIT=="cocoa") == 379316-2.html 379316-2-ref.html # bug 379786
== 379328-1.html 379328-1-ref.html
== 379349-1a.xhtml 379349-1-ref.xhtml
== 379349-1b.xhtml 379349-1-ref.xhtml
== 379349-1c.xhtml 379349-1-ref.xhtml
@ -309,8 +311,9 @@ fails-if(MOZ_WIDGET_TOOLKIT=="cocoa") == 372037-1.html 372037-1-ref.html # bug 3
== 379349-2b.xhtml 379349-2-ref.xhtml
== 379349-3a.xhtml 379349-3-ref.xhtml
== 379349-3b.xhtml 379349-3-ref.xhtml
random-if(MOZ_WIDGET_TOOLKIT=="cocoa") == 379316-2.html 379316-2-ref.html # bug 379786
== 379328-1.html 379328-1-ref.html
== 379361-1.html 379361-1-ref.html
== 379361-2.html 379361-2-ref.html
== 379361-3.html 379361-3-ref.html
== 380004-1.html 380004-1-ref.html
== 380227-1.html 380227-1-ref.html
== 380842-1.html 380842-1-ref.html

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

@ -361,6 +361,7 @@ BasicTableLayoutStrategy::ComputeColumnIntrinsicWidths(nsIRenderingContext* aRen
nscoord totalSPref = 0, totalSMin = 0; // total existing widths
nscoord totalSNonPctPref = 0; // total pref width of columns
// without percentage widths
nscoord totalSAutoPref = 0; // total pref width of auto-width cols
PRInt32 nonPctCount = 0; // # of columns without percentage widths
PRInt32 scol, scol_end;
for (scol = col, scol_end = col + colSpan;
@ -377,25 +378,20 @@ BasicTableLayoutStrategy::ComputeColumnIntrinsicWidths(nsIRenderingContext* aRen
info.prefCoord -= spacing;
}
nscoord curPref;
if (info.hasSpecifiedWidth &&
!scolFrame->GetHasSpecifiedCoord()) {
curPref = scolFrame->GetMinCoord();
} else {
curPref = scolFrame->GetPrefCoord();
}
totalSPref += curPref;
totalSPref += scolFrame->GetPrefCoord();
totalSMin += scolFrame->GetMinCoord();
if (!scolFrame->GetHasSpecifiedCoord()) {
totalSAutoPref += scolFrame->GetPrefCoord();
}
float scolPct = scolFrame->GetPrefPercent();
if (scolPct == 0.0f) {
totalSNonPctPref += curPref;
totalSNonPctPref += scolFrame->GetPrefCoord();
++nonPctCount;
} else {
info.prefPercent -= scolPct;
}
info.minCoord -= scolFrame->GetMinCoord();
info.prefCoord -= curPref;
info.prefCoord -= scolFrame->GetPrefCoord();
}
if (info.minCoord < 0)
@ -430,14 +426,6 @@ BasicTableLayoutStrategy::ComputeColumnIntrinsicWidths(nsIRenderingContext* aRen
continue;
}
nscoord curPref;
if (info.hasSpecifiedWidth &&
!scolFrame->GetHasSpecifiedCoord()) {
curPref = scolFrame->GetMinCoord();
} else {
curPref = scolFrame->GetPrefCoord();
}
// the percentage width (only to columns that don't
// already have percentage widths, in proportion to
// the existing pref widths)
@ -453,7 +441,7 @@ BasicTableLayoutStrategy::ComputeColumnIntrinsicWidths(nsIRenderingContext* aRen
// Group so we're multiplying by 1.0f when we need
// to use up info.prefPercent.
allocatedPct = info.prefPercent *
(float(curPref) /
(float(scolFrame->GetPrefCoord()) /
float(totalSNonPctPref));
} else {
// distribute equally when all pref widths are 0
@ -466,7 +454,8 @@ BasicTableLayoutStrategy::ComputeColumnIntrinsicWidths(nsIRenderingContext* aRen
// existing pref width
float minRatio = 0.0f;
if (minWithinPref > 0) {
minRatio = float(curPref - scolFrame->GetMinCoord()) /
minRatio = float(scolFrame->GetPrefCoord() -
scolFrame->GetMinCoord()) /
float(totalSPref - totalSMin);
}
@ -474,12 +463,21 @@ BasicTableLayoutStrategy::ComputeColumnIntrinsicWidths(nsIRenderingContext* aRen
// proportion to the existing pref widths)
float coordRatio; // for both min and pref
if (spanHasPref) {
if (curPref == 0) {
if (scolFrame->GetPrefCoord() == 0) {
// We might have already subtracted all of
// totalSPref.
coordRatio = 0.0f;
} else if (totalSAutoPref == 0) {
// No auto-width cols left -- dividing up totalSPref
coordRatio = float(scolFrame->GetPrefCoord()) /
float(totalSPref);
} else if (!scolFrame->GetHasSpecifiedCoord()) {
// There are auto-width cols left, and this is one
coordRatio = float(scolFrame->GetPrefCoord()) /
float(totalSAutoPref);
} else {
coordRatio = float(curPref) / float(totalSPref);
// There are auto-width cols left, and this isn't one
coordRatio = 0.0f;
}
} else {
// distribute equally when all pref widths are 0
@ -496,7 +494,7 @@ BasicTableLayoutStrategy::ComputeColumnIntrinsicWidths(nsIRenderingContext* aRen
NSToCoordRound(float(info.prefCoord) * coordRatio);
nscoord spanMin = scolFrame->GetMinCoord() +
allocatedMinWithinPref + allocatedMinOutsidePref;
nscoord spanPref = curPref + allocatedPref;
nscoord spanPref = scolFrame->GetPrefCoord() + allocatedPref;
scolFrame->AddSpanCoords(spanMin, spanPref,
info.hasSpecifiedWidth);
@ -507,10 +505,13 @@ BasicTableLayoutStrategy::ComputeColumnIntrinsicWidths(nsIRenderingContext* aRen
minOutsidePref -= allocatedMinOutsidePref;
info.prefCoord -= allocatedPref;
info.prefPercent -= allocatedPct;
totalSPref -= curPref;
totalSPref -= scolFrame->GetPrefCoord();
totalSMin -= scolFrame->GetMinCoord();
if (!scolFrame->GetHasSpecifiedCoord()) {
totalSAutoPref -= scolFrame->GetPrefCoord();
}
if (scolFrame->GetPrefPercent() == 0.0f) {
totalSNonPctPref -= curPref;
totalSNonPctPref -= scolFrame->GetPrefCoord();
--nonPctCount;
}
}

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

@ -276,7 +276,7 @@ public:
* the primary variables.
*/
void AccumulateSpanIntrinsics() {
AddCoords(mSpanMinCoord, mSpanPrefCoord, mSpanHasSpecifiedCoord);
AddCoords(mSpanMinCoord, mSpanPrefCoord, mHasSpecifiedCoord && mSpanHasSpecifiedCoord);
AddPrefPercent(mSpanPrefPercent);
}