+2007-01-11 Mitz Pettel <mitz@webkit.org>
+
+ Reviewed by Hyatt.
+
+ - updated results for http://bugs.webkit.org/show_bug.cgi?id=12115
+ RTL text is jumbled on display
+ (fixing fixed table layout)
+
+ * tables/mozilla/bugs/bug157890-expected.checksum:
+ * tables/mozilla/bugs/bug157890-expected.png:
+ * tables/mozilla/bugs/bug157890-expected.txt:
+ * tables/mozilla/bugs/bug44505-expected.checksum:
+ * tables/mozilla/bugs/bug44505-expected.png:
+ * tables/mozilla/bugs/bug44505-expected.txt:
+ * tables/mozilla_expected_failures/bugs/bug7243-expected.checksum:
+ * tables/mozilla_expected_failures/bugs/bug7243-expected.png:
+ * tables/mozilla_expected_failures/bugs/bug7243-expected.txt:
+
2007-01-11 Mitz Pettel <mitz@webkit.org>
Reviewed by Hyatt.
-94c3e0cdcbd44a143545d5d7131902c1
\ No newline at end of file
+7dd09a4474aae5290b806f3d85feb26f
\ No newline at end of file
RenderTable {TABLE} at (0,0) size 24x0
RenderTableSection {TBODY} at (0,0) size 24x0
RenderTableRow {TR} at (0,0) size 24x0
- RenderTableCell {TD} at (0,0) size 4x0 [r=0 c=0 rs=1 cs=1]
- RenderTableCell {TD} at (4,0) size 4x0 [r=0 c=1 rs=1 cs=1]
- RenderTableCell {TD} at (8,0) size 3x0 [r=0 c=2 rs=1 cs=1]
- RenderTableCell {TD} at (11,0) size 3x0 [r=0 c=3 rs=1 cs=1]
- RenderTableCell {TD} at (14,0) size 10x0 [r=0 c=4 rs=1 cs=1]
+ RenderTableCell {TD} at (0,0) size 2x0 [r=0 c=0 rs=1 cs=1]
+ RenderTableCell {TD} at (2,0) size 2x0 [r=0 c=1 rs=1 cs=1]
+ RenderTableCell {TD} at (4,0) size 2x0 [r=0 c=2 rs=1 cs=1]
+ RenderTableCell {TD} at (6,0) size 2x0 [r=0 c=3 rs=1 cs=1]
+ RenderTableCell {TD} at (8,0) size 16x0 [r=0 c=4 rs=1 cs=1]
RenderTable {TABLE} at (0,0) size 25x0
RenderTableSection {TBODY} at (0,0) size 25x0
RenderTableRow {TR} at (0,0) size 25x0
- RenderTableCell {TD} at (0,0) size 4x0 [r=0 c=0 rs=1 cs=1]
- RenderTableCell {TD} at (4,0) size 4x0 [r=0 c=1 rs=1 cs=1]
- RenderTableCell {TD} at (8,0) size 4x0 [r=0 c=2 rs=1 cs=1]
- RenderTableCell {TD} at (12,0) size 3x0 [r=0 c=3 rs=1 cs=1]
- RenderTableCell {TD} at (15,0) size 10x0 [r=0 c=4 rs=1 cs=1]
- RenderTable {TABLE} at (0,0) size 100x0
- RenderTableSection {TBODY} at (0,0) size 100x0
- RenderTableRow {TR} at (0,0) size 100x0
- RenderTableCell {TD} at (0,0) size 10x0 [r=0 c=0 rs=1 cs=1]
- RenderTableCell {TD} at (10,0) size 10x0 [r=0 c=1 rs=1 cs=1]
- RenderTableCell {TD} at (20,0) size 10x0 [r=0 c=2 rs=1 cs=1]
- RenderTableCell {TD} at (30,0) size 10x0 [r=0 c=3 rs=1 cs=1]
- RenderTableCell {TD} at (40,0) size 10x0 [r=0 c=4 rs=1 cs=1]
- RenderTableCell {TD} at (50,0) size 10x0 [r=0 c=5 rs=1 cs=1]
- RenderTableCell {TD} at (60,0) size 10x0 [r=0 c=6 rs=1 cs=1]
- RenderTableCell {TD} at (70,0) size 10x0 [r=0 c=7 rs=1 cs=1]
- RenderTableCell {TD} at (80,0) size 10x0 [r=0 c=8 rs=1 cs=1]
- RenderTableCell {TD} at (90,0) size 10x0 [r=0 c=9 rs=1 cs=1]
+ RenderTableCell {TD} at (0,0) size 3x0 [r=0 c=0 rs=1 cs=1]
+ RenderTableCell {TD} at (3,0) size 2x0 [r=0 c=1 rs=1 cs=1]
+ RenderTableCell {TD} at (5,0) size 2x0 [r=0 c=2 rs=1 cs=1]
+ RenderTableCell {TD} at (7,0) size 2x0 [r=0 c=3 rs=1 cs=1]
+ RenderTableCell {TD} at (9,0) size 16x0 [r=0 c=4 rs=1 cs=1]
+ RenderTable {TABLE} at (0,0) size 17x0
+ RenderTableSection {TBODY} at (0,0) size 17x0
+ RenderTableRow {TR} at (0,0) size 17x0
+ RenderTableCell {TD} at (0,0) size 2x0 [r=0 c=0 rs=1 cs=1]
+ RenderTableCell {TD} at (2,0) size 2x0 [r=0 c=1 rs=1 cs=1]
+ RenderTableCell {TD} at (4,0) size 2x0 [r=0 c=2 rs=1 cs=1]
+ RenderTableCell {TD} at (6,0) size 2x0 [r=0 c=3 rs=1 cs=1]
+ RenderTableCell {TD} at (8,0) size 2x0 [r=0 c=4 rs=1 cs=1]
+ RenderTableCell {TD} at (10,0) size 2x0 [r=0 c=5 rs=1 cs=1]
+ RenderTableCell {TD} at (12,0) size 2x0 [r=0 c=6 rs=1 cs=1]
+ RenderTableCell {TD} at (14,0) size 1x0 [r=0 c=7 rs=1 cs=1]
+ RenderTableCell {TD} at (15,0) size 1x0 [r=0 c=8 rs=1 cs=1]
+ RenderTableCell {TD} at (16,0) size 1x0 [r=0 c=9 rs=1 cs=1]
RenderBlock {PRE} at (0,13) size 784x450
RenderText {#text} at (0,0) size 216x15
text run at (0,0) width 216: "Specified table width: 25px"
RenderText {#text} at (0,270) size 168x15
text run at (0,270) width 168: "Actual TD widths: "
RenderText {#text} at (168,270) size 32x15
- text run at (168,270) width 32: "4px "
+ text run at (168,270) width 32: "2px "
RenderText {#text} at (200,270) size 32x15
- text run at (200,270) width 32: "4px "
+ text run at (200,270) width 32: "2px "
RenderText {#text} at (232,270) size 32x15
- text run at (232,270) width 32: "3px "
+ text run at (232,270) width 32: "2px "
RenderText {#text} at (264,270) size 32x15
- text run at (264,270) width 32: "3px "
+ text run at (264,270) width 32: "2px "
RenderText {#text} at (296,270) size 40x15
- text run at (296,270) width 40: "10px "
+ text run at (296,270) width 40: "16px "
RenderText {#text} at (336,270) size 336x30
text run at (336,270) width 0: " "
text run at (0,285) width 0: " "
RenderText {#text} at (0,345) size 168x15
text run at (0,345) width 168: "Actual TD widths: "
RenderText {#text} at (168,345) size 32x15
- text run at (168,345) width 32: "4px "
+ text run at (168,345) width 32: "3px "
RenderText {#text} at (200,345) size 32x15
- text run at (200,345) width 32: "4px "
+ text run at (200,345) width 32: "2px "
RenderText {#text} at (232,345) size 32x15
- text run at (232,345) width 32: "4px "
+ text run at (232,345) width 32: "2px "
RenderText {#text} at (264,345) size 32x15
- text run at (264,345) width 32: "3px "
+ text run at (264,345) width 32: "2px "
RenderText {#text} at (296,345) size 40x15
- text run at (296,345) width 40: "10px "
+ text run at (296,345) width 40: "16px "
RenderText {#text} at (336,345) size 336x30
text run at (336,345) width 0: " "
text run at (0,360) width 0: " "
RenderText {#text} at (0,375) size 216x15
text run at (0,375) width 216: "Specified table width: 17px"
text run at (216,375) width 0: " "
- RenderText {#text} at (0,390) size 224x15
- text run at (0,390) width 224: "Actual table width: 100px"
- text run at (224,390) width 0: " "
+ RenderText {#text} at (0,390) size 216x15
+ text run at (0,390) width 216: "Actual table width: 17px"
+ text run at (216,390) width 0: " "
RenderText {#text} at (0,405) size 168x15
text run at (0,405) width 168: "Specified TD widths: "
RenderText {#text} at (168,405) size 32x15
text run at (488,405) width 0: " "
RenderText {#text} at (0,420) size 168x15
text run at (0,420) width 168: "Actual TD widths: "
- RenderText {#text} at (168,420) size 40x15
- text run at (168,420) width 40: "10px "
- RenderText {#text} at (208,420) size 40x15
- text run at (208,420) width 40: "10px "
- RenderText {#text} at (248,420) size 40x15
- text run at (248,420) width 40: "10px "
- RenderText {#text} at (288,420) size 40x15
- text run at (288,420) width 40: "10px "
- RenderText {#text} at (328,420) size 40x15
- text run at (328,420) width 40: "10px "
- RenderText {#text} at (368,420) size 40x15
- text run at (368,420) width 40: "10px "
- RenderText {#text} at (408,420) size 40x15
- text run at (408,420) width 40: "10px "
- RenderText {#text} at (448,420) size 40x15
- text run at (448,420) width 40: "10px "
- RenderText {#text} at (488,420) size 40x15
- text run at (488,420) width 40: "10px "
- RenderText {#text} at (528,420) size 40x15
- text run at (528,420) width 40: "10px "
- RenderText {#text} at (568,420) size 568x30
- text run at (568,420) width 0: " "
+ RenderText {#text} at (168,420) size 32x15
+ text run at (168,420) width 32: "2px "
+ RenderText {#text} at (200,420) size 32x15
+ text run at (200,420) width 32: "2px "
+ RenderText {#text} at (232,420) size 32x15
+ text run at (232,420) width 32: "2px "
+ RenderText {#text} at (264,420) size 32x15
+ text run at (264,420) width 32: "2px "
+ RenderText {#text} at (296,420) size 32x15
+ text run at (296,420) width 32: "2px "
+ RenderText {#text} at (328,420) size 32x15
+ text run at (328,420) width 32: "2px "
+ RenderText {#text} at (360,420) size 32x15
+ text run at (360,420) width 32: "2px "
+ RenderText {#text} at (392,420) size 32x15
+ text run at (392,420) width 32: "1px "
+ RenderText {#text} at (424,420) size 32x15
+ text run at (424,420) width 32: "1px "
+ RenderText {#text} at (456,420) size 32x15
+ text run at (456,420) width 32: "1px "
+ RenderText {#text} at (488,420) size 488x30
+ text run at (488,420) width 0: " "
text run at (0,435) width 0: " "
-3dc0ee2d6ae1cea2c88defc9405414a2
\ No newline at end of file
+2dddf239d6fc289d8e025d9b6b2a0a50
\ No newline at end of file
RenderTableCell {TD} at (204,26) size 100x22 [bgcolor=#0000FF] [border: (1px inset #808080)] [r=1 c=1 rs=1 cs=1]
RenderText {#text} at (2,2) size 4x18
text run at (2,2) width 4: " "
-layer at (11,115) size 186x22 clip at (12,116) size 184x20
- RenderTableCell {TD} at (2,2) size 186x22 [bgcolor=#0000FF] [border: (1px inset #808080)] [r=0 c=0 rs=1 cs=1]
+layer at (11,115) size 233x22 clip at (12,116) size 231x20
+ RenderTableCell {TD} at (2,2) size 233x22 [bgcolor=#0000FF] [border: (1px inset #808080)] [r=0 c=0 rs=1 cs=1]
RenderText {#text} at (2,2) size 4x18
text run at (2,2) width 4: " "
-layer at (199,115) size 106x22 clip at (200,116) size 104x20
- RenderTableCell {TD} at (190,2) size 106x22 [bgcolor=#0000FF] [border: (1px inset #808080)] [r=0 c=1 rs=1 cs=1]
+layer at (246,115) size 59x22 clip at (247,116) size 57x20
+ RenderTableCell {TD} at (237,2) size 59x22 [bgcolor=#0000FF] [border: (1px inset #808080)] [r=0 c=1 rs=1 cs=1]
RenderText {#text} at (2,2) size 4x18
text run at (2,2) width 4: " "
-layer at (11,139) size 186x22 clip at (12,140) size 184x20
- RenderTableCell {TD} at (2,26) size 186x22 [bgcolor=#0000FF] [border: (1px inset #808080)] [r=1 c=0 rs=1 cs=1]
+layer at (11,139) size 233x22 clip at (12,140) size 231x20
+ RenderTableCell {TD} at (2,26) size 233x22 [bgcolor=#0000FF] [border: (1px inset #808080)] [r=1 c=0 rs=1 cs=1]
RenderText {#text} at (2,2) size 4x18
text run at (2,2) width 4: " "
-layer at (199,139) size 106x22 clip at (200,140) size 104x20
- RenderTableCell {TD} at (190,26) size 106x22 [bgcolor=#0000FF] [border: (1px inset #808080)] [r=1 c=1 rs=1 cs=1]
+layer at (246,139) size 59x22 clip at (247,140) size 57x20
+ RenderTableCell {TD} at (237,26) size 59x22 [bgcolor=#0000FF] [border: (1px inset #808080)] [r=1 c=1 rs=1 cs=1]
RenderText {#text} at (2,2) size 4x18
text run at (2,2) width 4: " "
layer at (11,167) size 150x22 clip at (12,168) size 148x20
-cea4667d98e0d80f994bddcf9cc10b3e
\ No newline at end of file
+7be8b6d1e975ddade007fb9f4cb9f53f
\ No newline at end of file
RenderTableCol {COL} at (0,0) size 0x0
RenderTableSection {TBODY} at (1,1) size 398x22
RenderTableRow {TR} at (0,0) size 398x22
- RenderTableCell {TD} at (0,0) size 149x22 [border: (1px inset #808080)] [r=0 c=0 rs=1 cs=1]
+ RenderTableCell {TD} at (0,0) size 133x22 [border: (1px inset #808080)] [r=0 c=0 rs=1 cs=1]
RenderText {#text} at (2,2) size 21x18
text run at (2,2) width 21: "foo"
- RenderTableCell {TD} at (149,0) size 249x22 [border: (1px inset #808080)] [r=0 c=1 rs=1 cs=1]
+ RenderTableCell {TD} at (133,0) size 265x22 [border: (1px inset #808080)] [r=0 c=1 rs=1 cs=1]
RenderText {#text} at (2,2) size 20x18
text run at (2,2) width 20: "bar"
RenderBlock (anonymous) at (0,86) size 784x18
RenderTable {TABLE} at (0,252) size 784x106 [border: (1px outset #808080)]
RenderTableSection {TBODY} at (1,1) size 782x104
RenderTableRow {TR} at (0,20) size 782x22
- RenderTableCell {TD} at (20,20) size 422x22 [border: (1px inset #808080)] [r=0 c=0 rs=1 cs=2]
+ RenderTableCell {TD} at (20,20) size 301x22 [border: (1px inset #808080)] [r=0 c=0 rs=1 cs=2]
RenderText {#text} at (2,2) size 21x18
text run at (2,2) width 21: "foo"
- RenderTableCell {TD} at (462,20) size 300x22 [border: (1px inset #808080)] [r=0 c=2 rs=1 cs=1]
+ RenderTableCell {TD} at (341,20) size 421x22 [border: (1px inset #808080)] [r=0 c=2 rs=1 cs=1]
RenderText {#text} at (2,2) size 20x18
text run at (2,2) width 20: "bar"
RenderTableRow {TR} at (0,62) size 782x22
- RenderTableCell {TD} at (20,62) size 201x22 [border: (1px inset #808080)] [r=1 c=0 rs=1 cs=1]
+ RenderTableCell {TD} at (20,62) size 141x22 [border: (1px inset #808080)] [r=1 c=0 rs=1 cs=1]
RenderText {#text} at (2,2) size 21x18
text run at (2,2) width 21: "foo"
- RenderTableCell {TD} at (241,62) size 201x22 [border: (1px inset #808080)] [r=1 c=1 rs=1 cs=1]
+ RenderTableCell {TD} at (181,62) size 140x22 [border: (1px inset #808080)] [r=1 c=1 rs=1 cs=1]
RenderText {#text} at (2,2) size 20x18
text run at (2,2) width 20: "bar"
- RenderTableCell {TD} at (462,62) size 300x22 [border: (1px inset #808080)] [r=1 c=2 rs=1 cs=1]
+ RenderTableCell {TD} at (341,62) size 421x22 [border: (1px inset #808080)] [r=1 c=2 rs=1 cs=1]
RenderText {#text} at (2,2) size 20x18
text run at (2,2) width 20: "bar"
RenderBlock (anonymous) at (0,358) size 784x18
RenderTableCol {COL} at (0,0) size 0x0
RenderTableSection {TBODY} at (1,1) size 98x42
RenderTableRow {TR} at (0,10) size 98x22
- RenderTableCell {TD} at (10,10) size 23x22 [border: (1px inset #808080)] [r=0 c=0 rs=1 cs=1]
+ RenderTableCell {TD} at (10,10) size 16x22 [border: (1px inset #808080)] [r=0 c=0 rs=1 cs=1]
RenderText {#text} at (2,2) size 21x18
text run at (2,2) width 21: "foo"
- RenderTableCell {TD} at (43,10) size 34x22 [border: (1px inset #808080)] [r=0 c=1 rs=1 cs=1]
+ RenderTableCell {TD} at (36,10) size 22x22 [border: (1px inset #808080)] [r=0 c=1 rs=1 cs=1]
RenderText {#text} at (2,2) size 21x18
text run at (2,2) width 21: "foo"
- RenderTableCell {TD} at (87,10) size 20x22 [border: (1px inset #808080)] [r=0 c=2 rs=1 cs=1]
+ RenderTableCell {TD} at (68,10) size 20x22 [border: (1px inset #808080)] [r=0 c=2 rs=1 cs=1]
RenderText {#text} at (2,2) size 21x18
text run at (2,2) width 21: "foo"
RenderBlock (anonymous) at (0,538) size 784x18
+2007-01-11 Mitz Pettel <mitz@webkit.org>
+
+ Reviewed by Hyatt.
+
+ - fix http://bugs.webkit.org/show_bug.cgi?id=12115
+ RTL text is jumbled on display
+
+ Fixed fixed table layout. Implemented an algorithm that matches the behavior
+ of Firefox, up to rounding errors.
+
+ Fixes three existing table tests.
+
+ * rendering/FixedTableLayout.cpp:
+ Undid accidental search-and-replace of "width" to "m_width" in the comments.
+ Removed an outdated comment, since WebKit no longer honors table-layout:fixed
+ for variable-width tables.
+ (WebCore::FixedTableLayout::calcWidthArray): Fixed the logic that finds the
+ first row. Changed to divide the width specified for a cell that spans multiple
+ columns between the columns rather than assign its entire width to each column.
+ (WebCore::FixedTableLayout::calcMinMaxWidth):
+ (WebCore::FixedTableLayout::layout): Implemented the behavior observed in
+ Firefox.
+ * rendering/FixedTableLayout.h:
+
2007-01-11 Mitz Pettel <mitz@webkit.org>
Reviewed by Hyatt.
With this (fast) algorithm, the horizontal layout of the table does
not depend on the contents of the cells; it only depends on the
- table's m_width, the m_width of the columns, and borders or cell
+ table's width, the width of the columns, and borders or cell
spacing.
- The table's m_width may be specified explicitly with the 'm_width'
+ The table's width may be specified explicitly with the 'width'
property. A value of 'auto' (for both 'display: table' and 'display:
inline-table') means use the automatic table layout algorithm.
- In the fixed table layout algorithm, the m_width of each column is
+ In the fixed table layout algorithm, the width of each column is
determined as follows:
- 1. A column element with a value other than 'auto' for the 'm_width'
- property sets the m_width for that column.
+ 1. A column element with a value other than 'auto' for the 'width'
+ property sets the width for that column.
2. Otherwise, a cell in the first row with a value other than
- 'auto' for the 'm_width' property sets the m_width for that column. If
- the cell spans more than one column, the m_width is divided over the
+ 'auto' for the 'width' property sets the width for that column. If
+ the cell spans more than one column, the width is divided over the
columns.
3. Any remaining columns equally divide the remaining horizontal
table space (minus borders or cell spacing).
- The m_width of the table is then the greater of the value of the
- 'm_width' property for the table element and the sum of the column
+ The width of the table is then the greater of the value of the
+ 'width' property for the table element and the sum of the column
widths (plus cell spacing or borders). If the table is wider than
the columns, the extra space should be distributed over the columns.
not affect column widths. Any cell that has content that overflows
uses the 'overflow' property to determine whether to clip the
overflow content.
-
-_____________________________________________________
-
- This is not quite true when comparing to IE. IE always honours
- table-layout:fixed and treats a variable table m_width as 100%. Makes
- a lot of sense, and is implemented here the same way.
-
*/
using namespace std;
{
}
-FixedTableLayout::~FixedTableLayout()
-{
-}
-
int FixedTableLayout::calcWidthArray(int tableWidth)
{
int usedWidth = 0;
}
int eSpan = m_table->spanOfEffCol(cCol+i);
if ((w.isFixed() || w.isPercent()) && w.isPositive()) {
- m_width[cCol+i].setRawValue(w.type(), w.rawValue() * eSpan);
+ m_width[cCol + i].setRawValue(w.type(), w.rawValue() * eSpan);
usedWidth += effWidth * eSpan;
}
usedSpan += eSpan;
child = next;
}
- // iterate over the first row in case some are unspecified.
+ // Iterate over the first row in case some are unspecified.
RenderTableSection* section = m_table->header();
if (!section)
section = m_table->firstBody();
if (!section)
section = m_table->footer();
+ if (!section->numRows())
+ section = m_table->sectionBelow(section, true);
if (section) {
cCol = 0;
- // FIXME: Technically the first row could be in an arbitrary section (e.g., an nth section
- // if the previous n-1 sections have no rows), so this check isn't good enough.
- // get the first cell in the first row
RenderObject* firstRow = section->firstChild();
- child = firstRow ? firstRow->firstChild() : 0;
+ child = firstRow->firstChild();
while (child) {
if (child->isTableCell()) {
- RenderTableCell *cell = static_cast<RenderTableCell *>(child);
+ RenderTableCell* cell = static_cast<RenderTableCell*>(child);
Length w = cell->styleOrColWidth();
int span = cell->colSpan();
int effWidth = 0;
- // FIXME: This does not make sense (mixing percentages with absolute length)
- if ((w.isFixed() || w.isPercent()) && w.isPositive())
- effWidth = w.isPercent() ? w.rawValue() / percentScaleFactor : w.value();
+ if (w.isFixed() && w.isPositive())
+ effWidth = w.value();
int usedSpan = 0;
int i = 0;
while (usedSpan < span) {
ASSERT(cCol + i < nEffCols);
- int eSpan = m_table->spanOfEffCol(cCol+i);
- // only set if no col element has already set it.
- if (m_width[cCol+i].isAuto() && w.type() != Auto) {
- m_width[cCol+i].setRawValue(w.type(), w.rawValue() * eSpan);
- usedWidth += effWidth*eSpan;
+ int eSpan = m_table->spanOfEffCol(cCol + i);
+ // Only set if no col element has already set it.
+ if (m_width[cCol + i].isAuto() && w.type() != Auto) {
+ m_width[cCol + i].setRawValue(w.type(), w.rawValue() * eSpan / span);
+ usedWidth += effWidth * eSpan / span;
}
usedSpan += eSpan;
i++;
}
return usedWidth;
-
}
void FixedTableLayout::calcMinMaxWidth(int& minWidth, int& maxWidth)
// we might want to wait until we have all of the first row before
// layouting for the first time.
- // only need to calculate the minimum m_width as the sum of the
- // cols/cells with a fixed m_width.
+ // only need to calculate the minimum width as the sum of the
+ // cols/cells with a fixed width.
//
- // The maximum m_width is max(minWidth, tableWidth).
+ // The maximum width is max(minWidth, tableWidth).
int bs = m_table->bordersPaddingAndSpacing();
int tableWidth = m_table->style()->width().isFixed() ? m_table->style()->width().value() - bs : 0;
void FixedTableLayout::layout()
{
int tableWidth = m_table->width() - m_table->bordersPaddingAndSpacing();
- int available = tableWidth;
int nEffCols = m_table->numEffCols();
- int totalPercent = 0;
-
- Vector<int> calcWidth(nEffCols, -1);
+ Vector<int> calcWidth(nEffCols, 0);
- // assign percent m_width
- if (available > 0) {
- for (int i = 0; i < nEffCols; i++)
- if (m_width[i].isPercent())
- totalPercent += m_width[i].rawValue();
+ int numAuto = 0;
+ int totalFixedWidth = 0;
+ int totalPercentWidth = 0;
+ int totalRawPercent = 0;
- // calculate how much to distribute to percent cells.
- int base = tableWidth * totalPercent / (100 * percentScaleFactor);
- if (base > available)
- base = available;
- else
- totalPercent = 100 * percentScaleFactor;
-
- for (int i = 0; available > 0 && i < nEffCols; i++) {
- if (m_width[i].isPercent()) {
- int w = base * m_width[i].rawValue() / totalPercent;
- available -= w;
- calcWidth[i] = w;
- }
- }
- }
-
- // next assign fixed m_width
+ // Compute requirements and try to satisfy fixed and percent widths.
+ // Percentages are of the table's width, so for example
+ // for a table width of 100px with columns (40px, 10%), the 10% compute
+ // to 10px here, and will scale up to 20px in the final (80px, 20px).
for (int i = 0; i < nEffCols; i++) {
if (m_width[i].isFixed()) {
calcWidth[i] = m_width[i].value();
- available -= m_width[i].value();
- }
+ totalFixedWidth += calcWidth[i];
+ } else if (m_width[i].isPercent()) {
+ calcWidth[i] = m_width[i].calcValue(tableWidth);
+ totalPercentWidth += calcWidth[i];
+ totalRawPercent += m_width[i].rawValue();
+ } else if (m_width[i].isAuto())
+ numAuto++;
}
- // assign variable m_width
- if (available > 0) {
- int totalAuto = 0;
- for (int i = 0; i < nEffCols; i++)
- if (m_width[i].isAuto())
- totalAuto++;
-
- for (int i = 0; available > 0 && i < nEffCols; i++) {
+ int totalWidth = totalFixedWidth + totalPercentWidth;
+ if (!numAuto || totalWidth > tableWidth) {
+ // If there are no auto columns, or if the total is too wide, take
+ // what we have and scale it to fit as necessary.
+ if (totalWidth != tableWidth) {
+ // Fixed widths only scale up
+ if (totalFixedWidth && totalWidth < tableWidth) {
+ totalFixedWidth = 0;
+ for (int i = 0; i < nEffCols; i++) {
+ if (m_width[i].isFixed()) {
+ calcWidth[i] = calcWidth[i] * tableWidth / totalWidth;
+ totalFixedWidth += calcWidth[i];
+ }
+ }
+ }
+ if (totalRawPercent) {
+ totalPercentWidth = 0;
+ for (int i = 0; i < nEffCols; i++) {
+ if (m_width[i].isPercent()) {
+ calcWidth[i] = m_width[i].rawValue() * (tableWidth - totalFixedWidth) / totalRawPercent;
+ totalPercentWidth += calcWidth[i];
+ }
+ }
+ }
+ totalWidth = totalFixedWidth + totalPercentWidth;
+ }
+ } else {
+ // Divide the remaining width among the auto columns.
+ int remainingWidth = tableWidth - totalFixedWidth - totalPercentWidth;
+ int lastAuto = 0;
+ for (int i = 0; i < nEffCols; i++) {
if (m_width[i].isAuto()) {
- int w = available / totalAuto;
- available -= w;
- calcWidth[i] = w;
- totalAuto--;
+ calcWidth[i] = remainingWidth / numAuto;
+ remainingWidth -= calcWidth[i];
+ if (!remainingWidth)
+ break;
+ lastAuto = i;
+ numAuto--;
}
}
+ // Last one gets the remainder.
+ if (remainingWidth)
+ calcWidth[lastAuto] += remainingWidth;
+ totalWidth = tableWidth;
}
- for (int i = 0; i < nEffCols; i++)
- if (calcWidth[i] <= 0)
- calcWidth[i] = 0; // IE gives min 1 px...
-
- // spread extra space over columns
- if (available > 0) {
+ if (totalWidth < tableWidth) {
+ // Spread extra space over columns.
+ int remainingWidth = tableWidth - totalWidth;
int total = nEffCols;
- // still have some m_width to spread
- int i = nEffCols;
- while ( i--) {
- int w = available / total;
- available -= w;
- total--;
- calcWidth[i] += w;
+ while (total) {
+ int w = remainingWidth / total;
+ remainingWidth -= w;
+ calcWidth[--total] += w;
}
+ calcWidth[nEffCols - 1] += remainingWidth;
}
int pos = 0;
m_table->columnPositions()[i] = pos;
pos += calcWidth[i] + hspacing;
}
- m_table->columnPositions()[m_table->columnPositions().size()-1] = pos;
+ m_table->columnPositions()[m_table->columnPositions().size() - 1] = pos;
}
-#undef DEBUG_LAYOUT
-
} // namespace WebCore
* Boston, MA 02111-1307, USA.
*/
-#ifndef FixedTableLayout_H
-#define FixedTableLayout_H
+#ifndef FixedTableLayout_h
+#define FixedTableLayout_h
#include "Length.h"
#include "TableLayout.h"
class FixedTableLayout : public TableLayout {
public:
FixedTableLayout(RenderTable*);
- ~FixedTableLayout();
virtual void calcMinMaxWidth(int& minWidth, int& maxWidth);
virtual void layout();
} // namespace WebCore
-#endif // FixedTableLayout_H
+#endif // FixedTableLayout_h