Changeset 106479 in webkit


Ignore:
Timestamp:
Feb 1, 2012 11:38:23 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Source/WebCore: Add support for fixed and percent min-width on the table element for table-layout: auto to
match Firefox and Opera's behavior.

In FixedTableLayout.cpp, the computePreferredLogicalWidths method looks like it has
issues based on the comment: "FIXME: This entire calculation is incorrect for both
minwidth and maxwidth." (minwidth and maxwidth refer to the preferred widths, not the
min-width and max-width styles). I have not implemented min-width for FixedTableLayout
in this patch since it requires some more research around that comment.

min-width and max-width on the table element was discussed on the www-style list:
http://lists.w3.org/Archives/Public/www-style/2012Jan/0684.html

min-width is not implemented on <table> for table-layout: auto
https://bugs.webkit.org/show_bug.cgi?id=76553

Patch by Max Vujovic <mvujovic@adobe.com> on 2012-02-01
Reviewed by Julien Chaffraix.

Test: fast/table/min-width.html

  • rendering/AutoTableLayout.cpp:

(WebCore::AutoTableLayout::computePreferredLogicalWidths):

If the min or max preferred logical width is less than a fixed min width style, it is
set to the fixed min width style. Like a percent width style, a percent min-width style
does not affect the min or max preferred logical widths computed by the table layout
algorithm. RenderTable's computeLogicalWidth method handles percent min-width styles.

min-width for the table-layout: fixed case has been split out into this bug:
https://bugs.webkit.org/show_bug.cgi?id=76948

  • rendering/RenderTable.cpp:

(WebCore::RenderTable::computeLogicalWidth):

If the RenderStyle's logical min width is defined and greater than the logical width
calculation, this method sets the logical width to the logical min width.

(WebCore::RenderTable::convertStyleWidthToComputedWidth):

This new method generalizes and factors out logic from RenderTable::computeLogicalWidth
that converted the width style to a computed value in the fixed and percent case.
RenderTable::computeLogicalWidth now calls this method to determine the computed values
for both the width style and the min-width style. In the future, it can also be used for
the max-width style.

Note that this method handles the special CSS table case, which requires borders and
paddings to be included in the computed width calculation. This applies to all width
styles, including width, min-width, and max-width. Before, this special case was handled
in RenderTable::computeLogicalWidth.

  • rendering/RenderTable.h:

LayoutTests: Add support for min-width on the table element.

min-width is not implemented on <table> for table-layout: auto
https://bugs.webkit.org/show_bug.cgi?id=76553

Patch by Max Vujovic <mvujovic@adobe.com> on 2012-02-01
Reviewed by Julien Chaffraix.

  • fast/table/min-width-css-block-table.html: Added.
  • fast/table/min-width-css-block-table-expected.txt: Added.
  • fast/table/min-width-css-inline-table.html: Added.
  • fast/table/min-width-css-inline-table-expected.txt: Added.
  • fast/table/min-width-html-block-table.html: Added.
  • fast/table/min-width-html-block-table-expected.txt: Added.
  • fast/table/min-width-html-inline-table.html: Added.
  • fast/table/min-width-html-inline-table-expected.txt: Added.
  • fast/table/script-tests/min-width-css-block-table.js: Added.

(computeLogicalWidth):

  • fast/table/script-tests/min-width-css-inline-table.js: Added.

(computeLogicalWidth):

  • fast/table/script-tests/min-width-helpers.js: Added.

(runTests):
(createTableStyle):
(computeLogicalWidthHelper):
(createSpan):

  • fast/table/script-tests/min-width-html-block-table.js: Added.

(computeLogicalWidth):

  • fast/table/script-tests/min-width-html-inline-table.js: Added.

(computeLogicalWidth):

Location:
trunk
Files:
14 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r106477 r106479  
     12012-02-01  Max Vujovic  <mvujovic@adobe.com>
     2
     3        Add support for min-width on the table element.
     4
     5        min-width is not implemented on <table> for table-layout: auto
     6        https://bugs.webkit.org/show_bug.cgi?id=76553
     7
     8        Reviewed by Julien Chaffraix.
     9
     10        * fast/table/min-width-css-block-table.html: Added.
     11        * fast/table/min-width-css-block-table-expected.txt: Added.
     12        * fast/table/min-width-css-inline-table.html: Added.
     13        * fast/table/min-width-css-inline-table-expected.txt: Added.
     14        * fast/table/min-width-html-block-table.html: Added.
     15        * fast/table/min-width-html-block-table-expected.txt: Added.
     16        * fast/table/min-width-html-inline-table.html: Added.
     17        * fast/table/min-width-html-inline-table-expected.txt: Added.
     18        * fast/table/script-tests/min-width-css-block-table.js: Added.
     19        (computeLogicalWidth):
     20        * fast/table/script-tests/min-width-css-inline-table.js: Added.
     21        (computeLogicalWidth):
     22        * fast/table/script-tests/min-width-helpers.js: Added.
     23        (runTests):
     24        (createTableStyle):
     25        (computeLogicalWidthHelper):
     26        (createSpan):
     27        * fast/table/script-tests/min-width-html-block-table.js: Added.
     28        (computeLogicalWidth):
     29        * fast/table/script-tests/min-width-html-inline-table.js: Added.
     30        (computeLogicalWidth):
     31
    1322012-02-01  Brian Salomon  <bsalomon@google.com>
    233
  • trunk/Source/WebCore/ChangeLog

    r106477 r106479  
     12012-02-01  Max Vujovic  <mvujovic@adobe.com>
     2
     3        Add support for fixed and percent min-width on the table element for table-layout: auto to
     4        match Firefox and Opera's behavior.
     5
     6        In FixedTableLayout.cpp, the computePreferredLogicalWidths method looks like it has
     7        issues based on the comment: "FIXME: This entire calculation is incorrect for both
     8        minwidth and maxwidth." (minwidth and maxwidth refer to the preferred widths, not the
     9        min-width and max-width styles). I have not implemented min-width for FixedTableLayout
     10        in this patch since it requires some more research around that comment.
     11
     12        min-width and max-width on the table element was discussed on the www-style list:
     13        http://lists.w3.org/Archives/Public/www-style/2012Jan/0684.html
     14
     15        min-width is not implemented on <table> for table-layout: auto
     16        https://bugs.webkit.org/show_bug.cgi?id=76553
     17
     18        Reviewed by Julien Chaffraix.
     19
     20        Test: fast/table/min-width.html
     21
     22        * rendering/AutoTableLayout.cpp:
     23        (WebCore::AutoTableLayout::computePreferredLogicalWidths):
     24
     25            If the min or max preferred logical width is less than a fixed min width style, it is
     26            set to the fixed min width style. Like a percent width style, a percent min-width style
     27            does not affect the min or max preferred logical widths computed by the table layout
     28            algorithm. RenderTable's computeLogicalWidth method handles percent min-width styles.
     29
     30            min-width for the table-layout: fixed case has been split out into this bug:
     31            https://bugs.webkit.org/show_bug.cgi?id=76948
     32
     33        * rendering/RenderTable.cpp:
     34        (WebCore::RenderTable::computeLogicalWidth):
     35
     36            If the RenderStyle's logical min width is defined and greater than the logical width
     37            calculation, this method sets the logical width to the logical min width.
     38
     39        (WebCore::RenderTable::convertStyleWidthToComputedWidth):
     40
     41            This new method generalizes and factors out logic from RenderTable::computeLogicalWidth
     42            that converted the width style to a computed value in the fixed and percent case.
     43            RenderTable::computeLogicalWidth now calls this method to determine the computed values
     44            for both the width style and the min-width style. In the future, it can also be used for
     45            the max-width style.
     46
     47            Note that this method handles the special CSS table case, which requires borders and
     48            paddings to be included in the computed width calculation. This applies to all width
     49            styles, including width, min-width, and max-width. Before, this special case was handled
     50            in RenderTable::computeLogicalWidth.
     51
     52        * rendering/RenderTable.h:
     53
    1542012-02-01  Brian Salomon  <bsalomon@google.com>
    255
  • trunk/Source/WebCore/rendering/AutoTableLayout.cpp

    r105775 r106479  
    263263
    264264    Length tableLogicalWidth = m_table->style()->logicalWidth();
    265     if (tableLogicalWidth.isFixed() && tableLogicalWidth.value() > 0) {
     265    if (tableLogicalWidth.isFixed() && tableLogicalWidth.isPositive()) {
    266266        minWidth = max<int>(minWidth, tableLogicalWidth.value());
    267267        maxWidth = minWidth;
     
    269269        // if there was no remaining percent, maxWidth is invalid.
    270270        maxWidth = intMaxForLength;       
     271    }
     272
     273    Length tableLogicalMinWidth = m_table->style()->logicalMinWidth();
     274    if (tableLogicalMinWidth.isFixed() && tableLogicalMinWidth.isPositive()) {
     275        minWidth = max<int>(minWidth, tableLogicalMinWidth.value());
     276        maxWidth = max<int>(minWidth, maxWidth);
    271277    }
    272278}
  • trunk/Source/WebCore/rendering/RenderTable.cpp

    r105768 r106479  
    228228    LayoutUnit containerWidthInInlineDirection = hasPerpendicularContainingBlock ? perpendicularContainingBlockLogicalHeight() : availableLogicalWidth;
    229229
    230     LengthType logicalWidthType = style()->logicalWidth().type();
    231     if (logicalWidthType > Relative && style()->logicalWidth().isPositive()) {
    232         // Percent or fixed table
    233         // HTML tables size as though CSS width includes border/padding, CSS tables do not.
    234         LayoutUnit borders = 0;
    235         if (logicalWidthType != Percent && (!node() || !node()->hasTagName(tableTag))) {
    236             recalcBordersInRowDirection();
    237             borders = borderStart() + borderEnd() + (collapseBorders() ? 0 : paddingStart() + paddingEnd());
    238          }
    239         setLogicalWidth(style()->logicalWidth().calcMinValue(containerWidthInInlineDirection) + borders);
    240         setLogicalWidth(max(minPreferredLogicalWidth(), logicalWidth()));
    241     } else {
     230    Length styleLogicalWidth = style()->logicalWidth();
     231    if (styleLogicalWidth.isSpecified() && styleLogicalWidth.isPositive())
     232        setLogicalWidth(convertStyleLogicalWidthToComputedWidth(styleLogicalWidth, containerWidthInInlineDirection));
     233    else {
    242234        // Subtract out any fixed margins from our available width for auto width tables.
    243235        LayoutUnit marginTotal = 0;
     
    246238        if (!style()->marginEnd().isAuto())
    247239            marginTotal += style()->marginEnd().calcValue(availableLogicalWidth);
    248            
     240
    249241        // Subtract out our margins to get the available content width.
    250242        LayoutUnit availableContentLogicalWidth = max<LayoutUnit>(0, containerWidthInInlineDirection - marginTotal);
    251        
    252         // Ensure we aren't bigger than our max width or smaller than our min width.
     243
     244        // Ensure we aren't bigger than our available width.
    253245        setLogicalWidth(min(availableContentLogicalWidth, maxPreferredLogicalWidth()));
    254246    }
    255247
     248    // Ensure we aren't smaller than our min preferred width.
    256249    setLogicalWidth(max(logicalWidth(), minPreferredLogicalWidth()));
     250
     251    // Ensure we aren't smaller than our min-width style.
     252    Length styleMinLogicalWidth = style()->logicalMinWidth();
     253    if (styleMinLogicalWidth.isSpecified() && styleMinLogicalWidth.isPositive())
     254        setLogicalWidth(max(logicalWidth(), convertStyleLogicalWidthToComputedWidth(styleMinLogicalWidth, availableLogicalWidth)));
    257255
    258256    // Finally, with our true width determined, compute our margins for real.
     
    265263        setMarginEnd(style()->marginEnd().calcMinValue(availableLogicalWidth));
    266264    }
     265}
     266
     267// This method takes a RenderStyle's logical width, min-width, or max-width length and computes its actual value.
     268LayoutUnit RenderTable::convertStyleLogicalWidthToComputedWidth(const Length& styleLogicalWidth, LayoutUnit availableWidth)
     269{
     270    // HTML tables' width styles already include borders and paddings, but CSS tables' width styles do not.
     271    LayoutUnit borders = 0;
     272    bool isCSSTable = !node() || !node()->hasTagName(tableTag);
     273    if (isCSSTable && styleLogicalWidth.isFixed() && styleLogicalWidth.isPositive()) {
     274        recalcBordersInRowDirection();
     275        borders = borderStart() + borderEnd() + (collapseBorders() ? 0 : paddingStart() + paddingEnd());
     276    }
     277    return styleLogicalWidth.calcMinValue(availableWidth) + borders;
    267278}
    268279
  • trunk/Source/WebCore/rendering/RenderTable.h

    r105768 r106479  
    241241    virtual void computeLogicalWidth();
    242242
     243    LayoutUnit convertStyleLogicalWidthToComputedWidth(const Length& styleLogicalWidth, LayoutUnit availableWidth);
     244
    243245    virtual LayoutRect overflowClipRect(const LayoutPoint& location, RenderRegion*, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize);
    244246
Note: See TracChangeset for help on using the changeset viewer.