Changeset 18790 in webkit


Ignore:
Timestamp:
Jan 11, 2007 8:28:05 PM (17 years ago)
Author:
bdash
Message:

2007-01-11 Mitz Pettel <mitz@webkit.org>

Reviewed by Hyatt.

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.

  • 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:
Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r18788 r18790  
     12007-01-11  Mitz Pettel  <mitz@webkit.org>
     2
     3        Reviewed by Hyatt.
     4
     5        - updated results for http://bugs.webkit.org/show_bug.cgi?id=12115
     6          RTL text is jumbled on display
     7          (fixing fixed table layout)
     8
     9        * tables/mozilla/bugs/bug157890-expected.checksum:
     10        * tables/mozilla/bugs/bug157890-expected.png:
     11        * tables/mozilla/bugs/bug157890-expected.txt:
     12        * tables/mozilla/bugs/bug44505-expected.checksum:
     13        * tables/mozilla/bugs/bug44505-expected.png:
     14        * tables/mozilla/bugs/bug44505-expected.txt:
     15        * tables/mozilla_expected_failures/bugs/bug7243-expected.checksum:
     16        * tables/mozilla_expected_failures/bugs/bug7243-expected.png:
     17        * tables/mozilla_expected_failures/bugs/bug7243-expected.txt:
     18
    1192007-01-11  Mitz Pettel  <mitz@webkit.org>
    220
  • trunk/LayoutTests/tables/mozilla/bugs/bug157890-expected.checksum

    r14222 r18790  
    1 94c3e0cdcbd44a143545d5d7131902c1
     17dd09a4474aae5290b806f3d85feb26f
  • trunk/LayoutTests/tables/mozilla/bugs/bug157890-expected.txt

    r14684 r18790  
    4343        RenderTableSection {TBODY} at (0,0) size 24x0
    4444          RenderTableRow {TR} at (0,0) size 24x0
    45             RenderTableCell {TD} at (0,0) size 4x0 [r=0 c=0 rs=1 cs=1]
    46             RenderTableCell {TD} at (4,0) size 4x0 [r=0 c=1 rs=1 cs=1]
    47             RenderTableCell {TD} at (8,0) size 3x0 [r=0 c=2 rs=1 cs=1]
    48             RenderTableCell {TD} at (11,0) size 3x0 [r=0 c=3 rs=1 cs=1]
    49             RenderTableCell {TD} at (14,0) size 10x0 [r=0 c=4 rs=1 cs=1]
     45            RenderTableCell {TD} at (0,0) size 2x0 [r=0 c=0 rs=1 cs=1]
     46            RenderTableCell {TD} at (2,0) size 2x0 [r=0 c=1 rs=1 cs=1]
     47            RenderTableCell {TD} at (4,0) size 2x0 [r=0 c=2 rs=1 cs=1]
     48            RenderTableCell {TD} at (6,0) size 2x0 [r=0 c=3 rs=1 cs=1]
     49            RenderTableCell {TD} at (8,0) size 16x0 [r=0 c=4 rs=1 cs=1]
    5050      RenderTable {TABLE} at (0,0) size 25x0
    5151        RenderTableSection {TBODY} at (0,0) size 25x0
    5252          RenderTableRow {TR} at (0,0) size 25x0
    53             RenderTableCell {TD} at (0,0) size 4x0 [r=0 c=0 rs=1 cs=1]
    54             RenderTableCell {TD} at (4,0) size 4x0 [r=0 c=1 rs=1 cs=1]
    55             RenderTableCell {TD} at (8,0) size 4x0 [r=0 c=2 rs=1 cs=1]
    56             RenderTableCell {TD} at (12,0) size 3x0 [r=0 c=3 rs=1 cs=1]
    57             RenderTableCell {TD} at (15,0) size 10x0 [r=0 c=4 rs=1 cs=1]
    58       RenderTable {TABLE} at (0,0) size 100x0
    59         RenderTableSection {TBODY} at (0,0) size 100x0
    60           RenderTableRow {TR} at (0,0) size 100x0
    61             RenderTableCell {TD} at (0,0) size 10x0 [r=0 c=0 rs=1 cs=1]
    62             RenderTableCell {TD} at (10,0) size 10x0 [r=0 c=1 rs=1 cs=1]
    63             RenderTableCell {TD} at (20,0) size 10x0 [r=0 c=2 rs=1 cs=1]
    64             RenderTableCell {TD} at (30,0) size 10x0 [r=0 c=3 rs=1 cs=1]
    65             RenderTableCell {TD} at (40,0) size 10x0 [r=0 c=4 rs=1 cs=1]
    66             RenderTableCell {TD} at (50,0) size 10x0 [r=0 c=5 rs=1 cs=1]
    67             RenderTableCell {TD} at (60,0) size 10x0 [r=0 c=6 rs=1 cs=1]
    68             RenderTableCell {TD} at (70,0) size 10x0 [r=0 c=7 rs=1 cs=1]
    69             RenderTableCell {TD} at (80,0) size 10x0 [r=0 c=8 rs=1 cs=1]
    70             RenderTableCell {TD} at (90,0) size 10x0 [r=0 c=9 rs=1 cs=1]
     53            RenderTableCell {TD} at (0,0) size 3x0 [r=0 c=0 rs=1 cs=1]
     54            RenderTableCell {TD} at (3,0) size 2x0 [r=0 c=1 rs=1 cs=1]
     55            RenderTableCell {TD} at (5,0) size 2x0 [r=0 c=2 rs=1 cs=1]
     56            RenderTableCell {TD} at (7,0) size 2x0 [r=0 c=3 rs=1 cs=1]
     57            RenderTableCell {TD} at (9,0) size 16x0 [r=0 c=4 rs=1 cs=1]
     58      RenderTable {TABLE} at (0,0) size 17x0
     59        RenderTableSection {TBODY} at (0,0) size 17x0
     60          RenderTableRow {TR} at (0,0) size 17x0
     61            RenderTableCell {TD} at (0,0) size 2x0 [r=0 c=0 rs=1 cs=1]
     62            RenderTableCell {TD} at (2,0) size 2x0 [r=0 c=1 rs=1 cs=1]
     63            RenderTableCell {TD} at (4,0) size 2x0 [r=0 c=2 rs=1 cs=1]
     64            RenderTableCell {TD} at (6,0) size 2x0 [r=0 c=3 rs=1 cs=1]
     65            RenderTableCell {TD} at (8,0) size 2x0 [r=0 c=4 rs=1 cs=1]
     66            RenderTableCell {TD} at (10,0) size 2x0 [r=0 c=5 rs=1 cs=1]
     67            RenderTableCell {TD} at (12,0) size 2x0 [r=0 c=6 rs=1 cs=1]
     68            RenderTableCell {TD} at (14,0) size 1x0 [r=0 c=7 rs=1 cs=1]
     69            RenderTableCell {TD} at (15,0) size 1x0 [r=0 c=8 rs=1 cs=1]
     70            RenderTableCell {TD} at (16,0) size 1x0 [r=0 c=9 rs=1 cs=1]
    7171      RenderBlock {PRE} at (0,13) size 784x450
    7272        RenderText {#text} at (0,0) size 216x15
     
    246246          text run at (0,270) width 168: "Actual TD widths:    "
    247247        RenderText {#text} at (168,270) size 32x15
    248           text run at (168,270) width 32: "4px "
     248          text run at (168,270) width 32: "2px "
    249249        RenderText {#text} at (200,270) size 32x15
    250           text run at (200,270) width 32: "4px "
     250          text run at (200,270) width 32: "2px "
    251251        RenderText {#text} at (232,270) size 32x15
    252           text run at (232,270) width 32: "3px "
     252          text run at (232,270) width 32: "2px "
    253253        RenderText {#text} at (264,270) size 32x15
    254           text run at (264,270) width 32: "3px "
     254          text run at (264,270) width 32: "2px "
    255255        RenderText {#text} at (296,270) size 40x15
    256           text run at (296,270) width 40: "10px "
     256          text run at (296,270) width 40: "16px "
    257257        RenderText {#text} at (336,270) size 336x30
    258258          text run at (336,270) width 0: " "
     
    281281          text run at (0,345) width 168: "Actual TD widths:    "
    282282        RenderText {#text} at (168,345) size 32x15
    283           text run at (168,345) width 32: "4px "
     283          text run at (168,345) width 32: "3px "
    284284        RenderText {#text} at (200,345) size 32x15
    285           text run at (200,345) width 32: "4px "
     285          text run at (200,345) width 32: "2px "
    286286        RenderText {#text} at (232,345) size 32x15
    287           text run at (232,345) width 32: "4px "
     287          text run at (232,345) width 32: "2px "
    288288        RenderText {#text} at (264,345) size 32x15
    289           text run at (264,345) width 32: "3px "
     289          text run at (264,345) width 32: "2px "
    290290        RenderText {#text} at (296,345) size 40x15
    291           text run at (296,345) width 40: "10px "
     291          text run at (296,345) width 40: "16px "
    292292        RenderText {#text} at (336,345) size 336x30
    293293          text run at (336,345) width 0: " "
     
    296296          text run at (0,375) width 216: "Specified table width: 17px"
    297297          text run at (216,375) width 0: " "
    298         RenderText {#text} at (0,390) size 224x15
    299           text run at (0,390) width 224: "Actual table width:    100px"
    300           text run at (224,390) width 0: " "
     298        RenderText {#text} at (0,390) size 216x15
     299          text run at (0,390) width 216: "Actual table width:    17px"
     300          text run at (216,390) width 0: " "
    301301        RenderText {#text} at (0,405) size 168x15
    302302          text run at (0,405) width 168: "Specified TD widths: "
     
    325325        RenderText {#text} at (0,420) size 168x15
    326326          text run at (0,420) width 168: "Actual TD widths:    "
    327         RenderText {#text} at (168,420) size 40x15
    328           text run at (168,420) width 40: "10px "
    329         RenderText {#text} at (208,420) size 40x15
    330           text run at (208,420) width 40: "10px "
    331         RenderText {#text} at (248,420) size 40x15
    332           text run at (248,420) width 40: "10px "
    333         RenderText {#text} at (288,420) size 40x15
    334           text run at (288,420) width 40: "10px "
    335         RenderText {#text} at (328,420) size 40x15
    336           text run at (328,420) width 40: "10px "
    337         RenderText {#text} at (368,420) size 40x15
    338           text run at (368,420) width 40: "10px "
    339         RenderText {#text} at (408,420) size 40x15
    340           text run at (408,420) width 40: "10px "
    341         RenderText {#text} at (448,420) size 40x15
    342           text run at (448,420) width 40: "10px "
    343         RenderText {#text} at (488,420) size 40x15
    344           text run at (488,420) width 40: "10px "
    345         RenderText {#text} at (528,420) size 40x15
    346           text run at (528,420) width 40: "10px "
    347         RenderText {#text} at (568,420) size 568x30
    348           text run at (568,420) width 0: " "
     327        RenderText {#text} at (168,420) size 32x15
     328          text run at (168,420) width 32: "2px "
     329        RenderText {#text} at (200,420) size 32x15
     330          text run at (200,420) width 32: "2px "
     331        RenderText {#text} at (232,420) size 32x15
     332          text run at (232,420) width 32: "2px "
     333        RenderText {#text} at (264,420) size 32x15
     334          text run at (264,420) width 32: "2px "
     335        RenderText {#text} at (296,420) size 32x15
     336          text run at (296,420) width 32: "2px "
     337        RenderText {#text} at (328,420) size 32x15
     338          text run at (328,420) width 32: "2px "
     339        RenderText {#text} at (360,420) size 32x15
     340          text run at (360,420) width 32: "2px "
     341        RenderText {#text} at (392,420) size 32x15
     342          text run at (392,420) width 32: "1px "
     343        RenderText {#text} at (424,420) size 32x15
     344          text run at (424,420) width 32: "1px "
     345        RenderText {#text} at (456,420) size 32x15
     346          text run at (456,420) width 32: "1px "
     347        RenderText {#text} at (488,420) size 488x30
     348          text run at (488,420) width 0: " "
    349349          text run at (0,435) width 0: " "
  • trunk/LayoutTests/tables/mozilla/bugs/bug44505-expected.checksum

    r16428 r18790  
    1 3dc0ee2d6ae1cea2c88defc9405414a2
     12dddf239d6fc289d8e025d9b6b2a0a50
  • trunk/LayoutTests/tables/mozilla/bugs/bug44505-expected.txt

    r14684 r18790  
    7474    RenderText {#text} at (2,2) size 4x18
    7575      text run at (2,2) width 4: " "
    76 layer at (11,115) size 186x22 clip at (12,116) size 184x20
    77   RenderTableCell {TD} at (2,2) size 186x22 [bgcolor=#0000FF] [border: (1px inset #808080)] [r=0 c=0 rs=1 cs=1]
    78     RenderText {#text} at (2,2) size 4x18
    79       text run at (2,2) width 4: " "
    80 layer at (199,115) size 106x22 clip at (200,116) size 104x20
    81   RenderTableCell {TD} at (190,2) size 106x22 [bgcolor=#0000FF] [border: (1px inset #808080)] [r=0 c=1 rs=1 cs=1]
    82     RenderText {#text} at (2,2) size 4x18
    83       text run at (2,2) width 4: " "
    84 layer at (11,139) size 186x22 clip at (12,140) size 184x20
    85   RenderTableCell {TD} at (2,26) size 186x22 [bgcolor=#0000FF] [border: (1px inset #808080)] [r=1 c=0 rs=1 cs=1]
    86     RenderText {#text} at (2,2) size 4x18
    87       text run at (2,2) width 4: " "
    88 layer at (199,139) size 106x22 clip at (200,140) size 104x20
    89   RenderTableCell {TD} at (190,26) size 106x22 [bgcolor=#0000FF] [border: (1px inset #808080)] [r=1 c=1 rs=1 cs=1]
     76layer at (11,115) size 233x22 clip at (12,116) size 231x20
     77  RenderTableCell {TD} at (2,2) size 233x22 [bgcolor=#0000FF] [border: (1px inset #808080)] [r=0 c=0 rs=1 cs=1]
     78    RenderText {#text} at (2,2) size 4x18
     79      text run at (2,2) width 4: " "
     80layer at (246,115) size 59x22 clip at (247,116) size 57x20
     81  RenderTableCell {TD} at (237,2) size 59x22 [bgcolor=#0000FF] [border: (1px inset #808080)] [r=0 c=1 rs=1 cs=1]
     82    RenderText {#text} at (2,2) size 4x18
     83      text run at (2,2) width 4: " "
     84layer at (11,139) size 233x22 clip at (12,140) size 231x20
     85  RenderTableCell {TD} at (2,26) size 233x22 [bgcolor=#0000FF] [border: (1px inset #808080)] [r=1 c=0 rs=1 cs=1]
     86    RenderText {#text} at (2,2) size 4x18
     87      text run at (2,2) width 4: " "
     88layer at (246,139) size 59x22 clip at (247,140) size 57x20
     89  RenderTableCell {TD} at (237,26) size 59x22 [bgcolor=#0000FF] [border: (1px inset #808080)] [r=1 c=1 rs=1 cs=1]
    9090    RenderText {#text} at (2,2) size 4x18
    9191      text run at (2,2) width 4: " "
  • trunk/LayoutTests/tables/mozilla_expected_failures/bugs/bug7243-expected.checksum

    r16430 r18790  
    1 cea4667d98e0d80f994bddcf9cc10b3e
     17be8b6d1e975ddade007fb9f4cb9f53f
  • trunk/LayoutTests/tables/mozilla_expected_failures/bugs/bug7243-expected.txt

    r16357 r18790  
    2222        RenderTableSection {TBODY} at (1,1) size 398x22
    2323          RenderTableRow {TR} at (0,0) size 398x22
    24             RenderTableCell {TD} at (0,0) size 149x22 [border: (1px inset #808080)] [r=0 c=0 rs=1 cs=1]
     24            RenderTableCell {TD} at (0,0) size 133x22 [border: (1px inset #808080)] [r=0 c=0 rs=1 cs=1]
    2525              RenderText {#text} at (2,2) size 21x18
    2626                text run at (2,2) width 21: "foo"
    27             RenderTableCell {TD} at (149,0) size 249x22 [border: (1px inset #808080)] [r=0 c=1 rs=1 cs=1]
     27            RenderTableCell {TD} at (133,0) size 265x22 [border: (1px inset #808080)] [r=0 c=1 rs=1 cs=1]
    2828              RenderText {#text} at (2,2) size 20x18
    2929                text run at (2,2) width 20: "bar"
     
    6969        RenderTableSection {TBODY} at (1,1) size 782x104
    7070          RenderTableRow {TR} at (0,20) size 782x22
    71             RenderTableCell {TD} at (20,20) size 422x22 [border: (1px inset #808080)] [r=0 c=0 rs=1 cs=2]
     71            RenderTableCell {TD} at (20,20) size 301x22 [border: (1px inset #808080)] [r=0 c=0 rs=1 cs=2]
    7272              RenderText {#text} at (2,2) size 21x18
    7373                text run at (2,2) width 21: "foo"
    74             RenderTableCell {TD} at (462,20) size 300x22 [border: (1px inset #808080)] [r=0 c=2 rs=1 cs=1]
     74            RenderTableCell {TD} at (341,20) size 421x22 [border: (1px inset #808080)] [r=0 c=2 rs=1 cs=1]
    7575              RenderText {#text} at (2,2) size 20x18
    7676                text run at (2,2) width 20: "bar"
    7777          RenderTableRow {TR} at (0,62) size 782x22
    78             RenderTableCell {TD} at (20,62) size 201x22 [border: (1px inset #808080)] [r=1 c=0 rs=1 cs=1]
     78            RenderTableCell {TD} at (20,62) size 141x22 [border: (1px inset #808080)] [r=1 c=0 rs=1 cs=1]
    7979              RenderText {#text} at (2,2) size 21x18
    8080                text run at (2,2) width 21: "foo"
    81             RenderTableCell {TD} at (241,62) size 201x22 [border: (1px inset #808080)] [r=1 c=1 rs=1 cs=1]
     81            RenderTableCell {TD} at (181,62) size 140x22 [border: (1px inset #808080)] [r=1 c=1 rs=1 cs=1]
    8282              RenderText {#text} at (2,2) size 20x18
    8383                text run at (2,2) width 20: "bar"
    84             RenderTableCell {TD} at (462,62) size 300x22 [border: (1px inset #808080)] [r=1 c=2 rs=1 cs=1]
     84            RenderTableCell {TD} at (341,62) size 421x22 [border: (1px inset #808080)] [r=1 c=2 rs=1 cs=1]
    8585              RenderText {#text} at (2,2) size 20x18
    8686                text run at (2,2) width 20: "bar"
     
    105105        RenderTableSection {TBODY} at (1,1) size 98x42
    106106          RenderTableRow {TR} at (0,10) size 98x22
    107             RenderTableCell {TD} at (10,10) size 23x22 [border: (1px inset #808080)] [r=0 c=0 rs=1 cs=1]
     107            RenderTableCell {TD} at (10,10) size 16x22 [border: (1px inset #808080)] [r=0 c=0 rs=1 cs=1]
    108108              RenderText {#text} at (2,2) size 21x18
    109109                text run at (2,2) width 21: "foo"
    110             RenderTableCell {TD} at (43,10) size 34x22 [border: (1px inset #808080)] [r=0 c=1 rs=1 cs=1]
     110            RenderTableCell {TD} at (36,10) size 22x22 [border: (1px inset #808080)] [r=0 c=1 rs=1 cs=1]
    111111              RenderText {#text} at (2,2) size 21x18
    112112                text run at (2,2) width 21: "foo"
    113             RenderTableCell {TD} at (87,10) size 20x22 [border: (1px inset #808080)] [r=0 c=2 rs=1 cs=1]
     113            RenderTableCell {TD} at (68,10) size 20x22 [border: (1px inset #808080)] [r=0 c=2 rs=1 cs=1]
    114114              RenderText {#text} at (2,2) size 21x18
    115115                text run at (2,2) width 21: "foo"
  • trunk/WebCore/ChangeLog

    r18788 r18790  
     12007-01-11  Mitz Pettel  <mitz@webkit.org>
     2
     3        Reviewed by Hyatt.
     4
     5        - fix http://bugs.webkit.org/show_bug.cgi?id=12115
     6          RTL text is jumbled on display
     7
     8        Fixed fixed table layout. Implemented an algorithm that matches the behavior
     9        of Firefox, up to rounding errors.
     10
     11        Fixes three existing table tests.
     12
     13        * rendering/FixedTableLayout.cpp:
     14        Undid accidental search-and-replace of "width" to "m_width" in the comments.
     15        Removed an outdated comment, since WebKit no longer honors table-layout:fixed
     16        for variable-width tables.
     17        (WebCore::FixedTableLayout::calcWidthArray): Fixed the logic that finds the
     18        first row. Changed to divide the width specified for a cell that spans multiple
     19        columns between the columns rather than assign its entire width to each column.
     20        (WebCore::FixedTableLayout::calcMinMaxWidth):
     21        (WebCore::FixedTableLayout::layout): Implemented the behavior observed in
     22        Firefox.
     23        * rendering/FixedTableLayout.h:
     24
    1252007-01-11  Mitz Pettel  <mitz@webkit.org>
    226
  • trunk/WebCore/rendering/FixedTableLayout.cpp

    r18608 r18790  
    3737  With this (fast) algorithm, the horizontal layout of the table does
    3838  not depend on the contents of the cells; it only depends on the
    39   table's m_width, the m_width of the columns, and borders or cell
     39  table's width, the width of the columns, and borders or cell
    4040  spacing.
    4141
    42   The table's m_width may be specified explicitly with the 'm_width'
     42  The table's width may be specified explicitly with the 'width'
    4343  property. A value of 'auto' (for both 'display: table' and 'display:
    4444  inline-table') means use the automatic table layout algorithm.
    4545
    46   In the fixed table layout algorithm, the m_width of each column is
     46  In the fixed table layout algorithm, the width of each column is
    4747  determined as follows:
    4848
    49     1. A column element with a value other than 'auto' for the 'm_width'
    50     property sets the m_width for that column.
     49    1. A column element with a value other than 'auto' for the 'width'
     50    property sets the width for that column.
    5151
    5252    2. Otherwise, a cell in the first row with a value other than
    53     'auto' for the 'm_width' property sets the m_width for that column. If
    54     the cell spans more than one column, the m_width is divided over the
     53    'auto' for the 'width' property sets the width for that column. If
     54    the cell spans more than one column, the width is divided over the
    5555    columns.
    5656
     
    5858    table space (minus borders or cell spacing).
    5959
    60   The m_width of the table is then the greater of the value of the
    61   'm_width' property for the table element and the sum of the column
     60  The width of the table is then the greater of the value of the
     61  'width' property for the table element and the sum of the column
    6262  widths (plus cell spacing or borders). If the table is wider than
    6363  the columns, the extra space should be distributed over the columns.
     
    6969  uses the 'overflow' property to determine whether to clip the
    7070  overflow content.
    71 
    72 _____________________________________________________
    73 
    74   This is not quite true when comparing to IE. IE always honours
    75   table-layout:fixed and treats a variable table m_width as 100%. Makes
    76   a lot of sense, and is implemented here the same way.
    77 
    7871*/
    7972
     
    8477FixedTableLayout::FixedTableLayout(RenderTable* table)
    8578    : TableLayout(table)
    86 {
    87 }
    88 
    89 FixedTableLayout::~FixedTableLayout()
    9079{
    9180}
     
    128117                    int eSpan = m_table->spanOfEffCol(cCol+i);
    129118                    if ((w.isFixed() || w.isPercent()) && w.isPositive()) {
    130                         m_width[cCol+i].setRawValue(w.type(), w.rawValue() * eSpan);
     119                        m_width[cCol + i].setRawValue(w.type(), w.rawValue() * eSpan);
    131120                        usedWidth += effWidth * eSpan;
    132121                    }
     
    149138    }
    150139
    151     // iterate over the first row in case some are unspecified.
     140    // Iterate over the first row in case some are unspecified.
    152141    RenderTableSection* section = m_table->header();
    153142    if (!section)
     
    155144    if (!section)
    156145        section = m_table->footer();
     146    if (!section->numRows())
     147        section = m_table->sectionBelow(section, true);
    157148    if (section) {
    158149        cCol = 0;
    159         // FIXME: Technically the first row could be in an arbitrary section (e.g., an nth section
    160         // if the previous n-1 sections have no rows), so this check isn't good enough.
    161         // get the first cell in the first row
    162150        RenderObject* firstRow = section->firstChild();
    163         child = firstRow ? firstRow->firstChild() : 0;
     151        child = firstRow->firstChild();
    164152        while (child) {
    165153            if (child->isTableCell()) {
    166                 RenderTableCell *cell = static_cast<RenderTableCell *>(child);
     154                RenderTableCell* cell = static_cast<RenderTableCell*>(child);
    167155                Length w = cell->styleOrColWidth();
    168156                int span = cell->colSpan();
    169157                int effWidth = 0;
    170                 // FIXME: This does not make sense (mixing percentages with absolute length)
    171                 if ((w.isFixed() || w.isPercent()) && w.isPositive())
    172                     effWidth = w.isPercent() ? w.rawValue() / percentScaleFactor : w.value();
     158                if (w.isFixed() && w.isPositive())
     159                    effWidth = w.value();
    173160               
    174161                int usedSpan = 0;
     
    176163                while (usedSpan < span) {
    177164                    ASSERT(cCol + i < nEffCols);
    178                     int eSpan = m_table->spanOfEffCol(cCol+i);
    179                     // only set if no col element has already set it.
    180                     if (m_width[cCol+i].isAuto() && w.type() != Auto) {
    181                         m_width[cCol+i].setRawValue(w.type(), w.rawValue() * eSpan);
    182                         usedWidth += effWidth*eSpan;
     165                    int eSpan = m_table->spanOfEffCol(cCol + i);
     166                    // Only set if no col element has already set it.
     167                    if (m_width[cCol + i].isAuto() && w.type() != Auto) {
     168                        m_width[cCol + i].setRawValue(w.type(), w.rawValue() * eSpan / span);
     169                        usedWidth += effWidth * eSpan / span;
    183170                    }
    184171                    usedSpan += eSpan;
     
    192179
    193180    return usedWidth;
    194 
    195181}
    196182
     
    202188    // layouting for the first time.
    203189
    204     // only need to calculate the minimum m_width as the sum of the
    205     // cols/cells with a fixed m_width.
     190    // only need to calculate the minimum width as the sum of the
     191    // cols/cells with a fixed width.
    206192    //
    207     // The maximum m_width is max(minWidth, tableWidth).
     193    // The maximum width is max(minWidth, tableWidth).
    208194    int bs = m_table->bordersPaddingAndSpacing();
    209195   
     
    218204{
    219205    int tableWidth = m_table->width() - m_table->bordersPaddingAndSpacing();
    220     int available = tableWidth;
    221206    int nEffCols = m_table->numEffCols();
    222     int totalPercent = 0;
    223 
    224     Vector<int> calcWidth(nEffCols, -1);
    225 
    226     // assign  percent m_width
    227     if (available > 0) {
    228         for (int i = 0; i < nEffCols; i++)
    229             if (m_width[i].isPercent())
    230                 totalPercent += m_width[i].rawValue();
    231 
    232         // calculate how much to distribute to percent cells.
    233         int base = tableWidth * totalPercent / (100 * percentScaleFactor);
    234         if (base > available)
    235             base = available;
    236         else
    237             totalPercent = 100 * percentScaleFactor;
    238 
    239         for (int i = 0; available > 0 && i < nEffCols; i++) {
    240             if (m_width[i].isPercent()) {
    241                 int w = base * m_width[i].rawValue() / totalPercent;
    242                 available -= w;
    243                 calcWidth[i] = w;
    244             }
    245         }
    246     }
    247    
    248     // next assign fixed m_width
     207    Vector<int> calcWidth(nEffCols, 0);
     208
     209    int numAuto = 0;
     210    int totalFixedWidth = 0;
     211    int totalPercentWidth = 0;
     212    int totalRawPercent = 0;
     213
     214    // Compute requirements and try to satisfy fixed and percent widths.
     215    // Percentages are of the table's width, so for example
     216    // for a table width of 100px with columns (40px, 10%), the 10% compute
     217    // to 10px here, and will scale up to 20px in the final (80px, 20px).
    249218    for (int i = 0; i < nEffCols; i++) {
    250219        if (m_width[i].isFixed()) {
    251220            calcWidth[i] = m_width[i].value();
    252             available -= m_width[i].value();
    253         }
    254     }
    255 
    256     // assign variable m_width
    257     if (available > 0) {
    258         int totalAuto = 0;
    259         for (int i = 0; i < nEffCols; i++)
    260             if (m_width[i].isAuto())
    261                 totalAuto++;
    262 
    263         for (int i = 0; available > 0 && i < nEffCols; i++) {
     221            totalFixedWidth += calcWidth[i];
     222        } else if (m_width[i].isPercent()) {
     223            calcWidth[i] = m_width[i].calcValue(tableWidth);
     224            totalPercentWidth += calcWidth[i];
     225            totalRawPercent += m_width[i].rawValue();
     226        } else if (m_width[i].isAuto())
     227            numAuto++;
     228    }
     229
     230    int totalWidth = totalFixedWidth + totalPercentWidth;
     231    if (!numAuto || totalWidth > tableWidth) {
     232        // If there are no auto columns, or if the total is too wide, take
     233        // what we have and scale it to fit as necessary.
     234        if (totalWidth != tableWidth) {
     235            // Fixed widths only scale up
     236            if (totalFixedWidth && totalWidth < tableWidth) {
     237                totalFixedWidth = 0;
     238                for (int i = 0; i < nEffCols; i++) {
     239                    if (m_width[i].isFixed()) {
     240                        calcWidth[i] = calcWidth[i] * tableWidth / totalWidth;
     241                        totalFixedWidth += calcWidth[i];
     242                    }
     243                }
     244            }
     245            if (totalRawPercent) {
     246                totalPercentWidth = 0;
     247                for (int i = 0; i < nEffCols; i++) {
     248                    if (m_width[i].isPercent()) {
     249                        calcWidth[i] = m_width[i].rawValue() * (tableWidth - totalFixedWidth) / totalRawPercent;
     250                        totalPercentWidth += calcWidth[i];
     251                    }
     252                }
     253            }
     254            totalWidth = totalFixedWidth + totalPercentWidth;
     255        }
     256    } else {
     257        // Divide the remaining width among the auto columns.
     258        int remainingWidth = tableWidth - totalFixedWidth - totalPercentWidth;
     259        int lastAuto = 0;
     260        for (int i = 0; i < nEffCols; i++) {
    264261            if (m_width[i].isAuto()) {
    265                 int w = available / totalAuto;
    266                 available -= w;
    267                 calcWidth[i] = w;
    268                 totalAuto--;
    269             }
    270         }
    271     }
    272 
    273     for (int i = 0; i < nEffCols; i++)
    274         if (calcWidth[i] <= 0)
    275             calcWidth[i] = 0; // IE gives min 1 px...
    276 
    277     // spread extra space over columns
    278     if (available > 0) {
     262                calcWidth[i] = remainingWidth / numAuto;
     263                remainingWidth -= calcWidth[i];
     264                if (!remainingWidth)
     265                    break;
     266                lastAuto = i;
     267                numAuto--;
     268            }
     269        }
     270        // Last one gets the remainder.
     271        if (remainingWidth)
     272            calcWidth[lastAuto] += remainingWidth;
     273        totalWidth = tableWidth;
     274    }
     275
     276    if (totalWidth < tableWidth) {
     277        // Spread extra space over columns.
     278        int remainingWidth = tableWidth - totalWidth;
    279279        int total = nEffCols;
    280         // still have some m_width to spread
    281         int i = nEffCols;
    282         while ( i--) {
    283             int w = available / total;
    284             available -= w;
    285             total--;
    286             calcWidth[i] += w;
    287         }
     280        while (total) {
     281            int w = remainingWidth / total;
     282            remainingWidth -= w;
     283            calcWidth[--total] += w;
     284        }
     285        calcWidth[nEffCols - 1] += remainingWidth;
    288286    }
    289287   
     
    294292        pos += calcWidth[i] + hspacing;
    295293    }
    296     m_table->columnPositions()[m_table->columnPositions().size()-1] = pos;
    297 }
    298 
    299 #undef DEBUG_LAYOUT
     294    m_table->columnPositions()[m_table->columnPositions().size() - 1] = pos;
     295}
    300296
    301297} // namespace WebCore
  • trunk/WebCore/rendering/FixedTableLayout.h

    r18608 r18790  
    2121 */
    2222
    23 #ifndef FixedTableLayout_H
    24 #define FixedTableLayout_H
     23#ifndef FixedTableLayout_h
     24#define FixedTableLayout_h
    2525
    2626#include "Length.h"
     
    3535public:
    3636    FixedTableLayout(RenderTable*);
    37     ~FixedTableLayout();
    3837
    3938    virtual void calcMinMaxWidth(int& minWidth, int& maxWidth);
     
    4847} // namespace WebCore
    4948
    50 #endif // FixedTableLayout_H
     49#endif // FixedTableLayout_h
Note: See TracChangeset for help on using the changeset viewer.