Changeset 3952 in webkit


Ignore:
Timestamp:
Mar 27, 2003 6:17:17 PM (21 years ago)
Author:
hyatt
Message:

A collection of fixes for tables.

(1) Fixed table layout should only be used if an explicit width
is specified on a table.
(2) width="0" and height="0" should be ignored on table cells!
(3) Fixed table layout wasn't spreading extra space over
columns.

Reviewed by mjs

  • khtml/html/html_tableimpl.cpp: (HTMLTableCellElementImpl::parseAttribute):
  • khtml/rendering/render_table.cpp: (RenderTable::setStyle):
  • khtml/rendering/table_layout.cpp: (FixedTableLayout::layout):
Location:
trunk/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog-2003-10-25

    r3951 r3952  
     12003-03-27  David Hyatt  <hyatt@apple.com>
     2
     3        A collection of fixes for tables.
     4
     5        (1) Fixed table layout should only be used if an explicit width
     6        is specified on a table.
     7        (2) width="0" and height="0" should be ignored on table cells!
     8        (3) Fixed table layout wasn't spreading extra space over
     9        columns.
     10       
     11        Reviewed by mjs
     12
     13        * khtml/html/html_tableimpl.cpp:
     14        (HTMLTableCellElementImpl::parseAttribute):
     15        * khtml/rendering/render_table.cpp:
     16        (RenderTable::setStyle):
     17        * khtml/rendering/table_layout.cpp:
     18        (FixedTableLayout::layout):
     19
    1202003-03-27  David Hyatt  <hyatt@apple.com>
    221
  • trunk/WebCore/ChangeLog-2005-08-23

    r3951 r3952  
     12003-03-27  David Hyatt  <hyatt@apple.com>
     2
     3        A collection of fixes for tables.
     4
     5        (1) Fixed table layout should only be used if an explicit width
     6        is specified on a table.
     7        (2) width="0" and height="0" should be ignored on table cells!
     8        (3) Fixed table layout wasn't spreading extra space over
     9        columns.
     10       
     11        Reviewed by mjs
     12
     13        * khtml/html/html_tableimpl.cpp:
     14        (HTMLTableCellElementImpl::parseAttribute):
     15        * khtml/rendering/render_table.cpp:
     16        (RenderTable::setStyle):
     17        * khtml/rendering/table_layout.cpp:
     18        (FixedTableLayout::layout):
     19
    1202003-03-27  David Hyatt  <hyatt@apple.com>
    221
  • trunk/WebCore/khtml/html/html_tableimpl.cpp

    r3869 r3952  
    855855        break;
    856856    case ATTR_WIDTH:
    857         if (!attr->value().isEmpty())
    858             addCSSLength( CSS_PROP_WIDTH, attr->value() );
     857        if (!attr->value().isEmpty()) {
     858            int widthInt = attr->val()->toInt();
     859            if (widthInt > 0) // width="0" is ignored for compatibility with WinIE.
     860                addCSSLength( CSS_PROP_WIDTH, attr->value() );
     861        }
    859862        else
    860863            removeCSSProperty(CSS_PROP_WIDTH);
     864        break;
     865    case ATTR_HEIGHT:
     866        if (!attr->value().isEmpty()) {
     867            int heightInt = attr->val()->toInt();
     868            if (heightInt > 0) // height="0" is ignored for compatibility with WinIE.
     869                addCSSLength( CSS_PROP_HEIGHT, attr->value() );
     870        }
     871        else
     872            removeCSSProperty(CSS_PROP_HEIGHT);
    861873        break;
    862874    case ATTR_NOSAVE:
  • trunk/WebCore/khtml/rendering/render_table.cpp

    r3951 r3952  
    9292        delete tableLayout;
    9393
    94         if (style()->tableLayout() == TFIXED ) {
     94        // According to the CSS2 spec, you only use fixed table layout if an
     95        // explicit width is specified on the table.  Auto width implies auto table layout.
     96        if (style()->tableLayout() == TFIXED && !style()->width().isVariable()) {
    9597            tableLayout = new FixedTableLayout(this);
    9698#ifdef DEBUG_LAYOUT
  • trunk/WebCore/khtml/rendering/table_layout.cpp

    r3810 r3952  
    264264    int available = tableWidth;
    265265    int nEffCols = table->numEffCols();
     266    int totalPercent = 0;
     267   
    266268#ifdef DEBUG_LAYOUT
    267269    qDebug("FixedTableLayout::layout: tableWidth=%d, numEffCols=%d",  tableWidth, nEffCols);
     
    273275    calcWidth.fill( -1 );
    274276
    275     // first assign  fixed width
    276     for ( int i = 0; i < nEffCols; i++ ) {
    277         if ( width[i].type == Fixed ) {
    278             calcWidth[i] = width[i].value;
    279             available -= width[i].value;
    280         }
    281     }
    282 
    283277    // assign  percent width
    284278    if ( available > 0 ) {
    285         int totalPercent = 0;
    286         for ( int i = 0; i < nEffCols; i++ )
    287             if ( width[i].type == Percent )
    288                 totalPercent += width[i].value;
    289 
    290         // calculate how much to distribute to percent cells.
    291         int base = tableWidth * totalPercent / 100;
    292         if ( base > available )
    293             base = available;
    294         else
    295             totalPercent = 100;
    296 
    297 #ifdef DEBUG_LAYOUT
    298     qDebug("FixedTableLayout::layout: assigning percent width, base=%d, totalPercent=%d", base, totalPercent);
     279        for ( int i = 0; i < nEffCols; i++ )
     280            if ( width[i].type == Percent )
     281                totalPercent += width[i].value;
     282
     283        // calculate how much to distribute to percent cells.
     284        int base = tableWidth * totalPercent / 100;
     285        if ( base > available )
     286            base = available;
     287        else
     288            totalPercent = 100;
     289
     290#ifdef DEBUG_LAYOUT
     291        qDebug("FixedTableLayout::layout: assigning percent width, base=%d, totalPercent=%d", base, totalPercent);
    299292#endif
    300293        for ( int i = 0; available > 0 && i < nEffCols; i++ ) {
     
    306299        }
    307300    }
    308 
    309     // assign  variable width
     301   
     302    // next assign fixed width
     303    for ( int i = 0; i < nEffCols; i++ ) {
     304        if ( width[i].type == Fixed ) {
     305            calcWidth[i] = width[i].value;
     306            available -= width[i].value;
     307        }
     308    }
     309
     310    // assign variable width
    310311    if ( available > 0 ) {
    311312        int totalVariable = 0;
     
    328329            calcWidth[i] = 0; // IE gives min 1 px...
    329330
     331    // spread extra space over columns
     332    if ( available > 0 ) {
     333        int total = nEffCols;
     334        // still have some width to spread
     335        int i = nEffCols;
     336        while (  i-- ) {
     337            int w = available / total;
     338            available -= w;
     339            total--;
     340            calcWidth[i] += w;
     341        }
     342    }
     343   
    330344    int pos = 0;
    331345    int spacing = table->cellSpacing();
Note: See TracChangeset for help on using the changeset viewer.