Changeset 117988 in webkit


Ignore:
Timestamp:
May 22, 2012 9:43:48 AM (12 years ago)
Author:
jchaffraix@webkit.org
Message:

Centralize and clean-up table column iteration
https://bugs.webkit.org/show_bug.cgi?id=87051

Reviewed by Eric Seidel.

Source/WebCore:

Tests: fast/table/caption-between-column-and-column-group.html

fast/table/caption-between-column-group-and-column.html
fast/table/caption-between-columns.html

The existing code had duplications between different classes and some
of the iterating functions could use a better place. That's what this
change solves, along with several renamings.

  • rendering/RenderTableCol.h:

(WebCore::RenderTableCol::isTableColumnGroupWithColumnChildren):
Renamed isTableColGroup to this to better reflect what it checks.
Also added a new function: nextColumn.

  • rendering/FixedTableLayout.cpp:

(WebCore::FixedTableLayout::calcWidthArray):
Updated after isTableColGroup renaming.

  • rendering/RenderTable.cpp:

(WebCore::RenderTable::firstColumn):
Added this new function to get the first column (or column group).

(WebCore::RenderTable::colElement):
Cleaned up this function: switched the loop to a 'for' now that the
helper functions make it easy. Cleaned up the ordering and the naming.

  • rendering/RenderTable.h:

Added firstColumn.

  • rendering/RenderTableCell.cpp:

(WebCore::RenderTableCell::styleOrColLogicalWidth):
Updated to use nextColumn().

  • rendering/RenderTableCol.cpp:

(WebCore::RenderTableCol::nextColumn):
Added this new helper function to centralize the code to iterate over columns.

LayoutTests:

Those tests just validate and enforce what we were already doing that were
not covered by any existing tests.

  • fast/table/caption-between-column-and-column-group-expected.html: Added.
  • fast/table/caption-between-column-and-column-group.html: Added.
  • fast/table/caption-between-column-group-and-column-expected.html: Added.
  • fast/table/caption-between-column-group-and-column.html: Added.
  • fast/table/caption-between-columns-expected.html: Added.
  • fast/table/caption-between-columns.html: Added.
Location:
trunk
Files:
6 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r117986 r117988  
     12012-05-22  Julien Chaffraix  <jchaffraix@webkit.org>
     2
     3        Centralize and clean-up table column iteration
     4        https://bugs.webkit.org/show_bug.cgi?id=87051
     5
     6        Reviewed by Eric Seidel.
     7
     8        Those tests just validate and enforce what we were already doing that were
     9        not covered by any existing tests.
     10
     11        * fast/table/caption-between-column-and-column-group-expected.html: Added.
     12        * fast/table/caption-between-column-and-column-group.html: Added.
     13        * fast/table/caption-between-column-group-and-column-expected.html: Added.
     14        * fast/table/caption-between-column-group-and-column.html: Added.
     15        * fast/table/caption-between-columns-expected.html: Added.
     16        * fast/table/caption-between-columns.html: Added.
     17
    1182012-05-22  Sudarsana Nagineni  <sudarsana.nagineni@linux.intel.com>
    219
  • trunk/Source/WebCore/ChangeLog

    r117987 r117988  
     12012-05-22  Julien Chaffraix  <jchaffraix@webkit.org>
     2
     3        Centralize and clean-up table column iteration
     4        https://bugs.webkit.org/show_bug.cgi?id=87051
     5
     6        Reviewed by Eric Seidel.
     7
     8        Tests: fast/table/caption-between-column-and-column-group.html
     9               fast/table/caption-between-column-group-and-column.html
     10               fast/table/caption-between-columns.html
     11
     12        The existing code had duplications between different classes and some
     13        of the iterating functions could use a better place. That's what this
     14        change solves, along with several renamings.
     15
     16        * rendering/RenderTableCol.h:
     17        (WebCore::RenderTableCol::isTableColumnGroupWithColumnChildren):
     18        Renamed isTableColGroup to this to better reflect what it checks.
     19        Also added a new function: nextColumn.
     20
     21        * rendering/FixedTableLayout.cpp:
     22        (WebCore::FixedTableLayout::calcWidthArray):
     23        Updated after isTableColGroup renaming.
     24
     25        * rendering/RenderTable.cpp:
     26        (WebCore::RenderTable::firstColumn):
     27        Added this new function to get the first column (or column group).
     28
     29        (WebCore::RenderTable::colElement):
     30        Cleaned up this function: switched the loop to a 'for' now that the
     31        helper functions make it easy. Cleaned up the ordering and the naming.
     32
     33        * rendering/RenderTable.h:
     34        Added firstColumn.
     35
     36        * rendering/RenderTableCell.cpp:
     37        (WebCore::RenderTableCell::styleOrColLogicalWidth):
     38        Updated to use nextColumn().
     39
     40        * rendering/RenderTableCol.cpp:
     41        (WebCore::RenderTableCol::nextColumn):
     42        Added this new helper function to centralize the code to iterate over columns.
     43
    1442012-05-22  Hao Zheng  <zhenghao@chromium.org>
    245
  • trunk/Source/WebCore/rendering/FixedTableLayout.cpp

    r111742 r117988  
    7878}
    7979
    80 static RenderObject* nextCol(RenderObject* child)
    81 {
    82     // If child is a colgroup, the next col is the colgroup's first child col.
    83     if (RenderObject* next = child->firstChild())
    84         return next;
    85     // Otherwise it's the next col along.
    86     if (RenderObject* next = child->nextSibling())
    87         return next;
    88     // Failing that, the child is the last col in a colgroup, so the next col is the next col/colgroup after its colgroup.
    89     if (child->parent()->isTableCol())
    90         return child->parent()->nextSibling();
    91     return 0;
    92 }
    93 
    9480int FixedTableLayout::calcWidthArray(int)
    9581{
     
    10288
    10389    unsigned currentEffectiveColumn = 0;
    104     for (RenderObject* child = m_table->firstChild();child && child->isTableCol(); child = nextCol(child)) {
    105 
    106         // Width specified by column-groups does not affect column width in fixed layout tables
    107         RenderTableCol* col = toRenderTableCol(child);
     90    for (RenderTableCol* col = m_table->firstColumn(); col; col = col->nextColumn()) {
    10891        col->computePreferredLogicalWidths();
    10992
    110         if (col->isTableColGroup())
     93        // Width specified by column-groups that have column child does not affect column width in fixed layout tables
     94        if (col->isTableColumnGroupWithColumnChildren())
    11195            continue;
    11296
  • trunk/Source/WebCore/rendering/RenderTable.cpp

    r117697 r117988  
    727727}
    728728
    729 RenderTableCol* RenderTable::nextColElement(RenderTableCol* current) const
    730 {
    731     RenderObject* next = current->firstChild();
    732     if (!next)
    733         next = current->nextSibling();
    734     if (!next && current->parent()->isTableCol())
    735         next = current->parent()->nextSibling();
    736 
    737     while (next) {
    738         if (next->isTableCol())
    739             return toRenderTableCol(next);
    740         if (!m_captions.contains(next))
     729RenderTableCol* RenderTable::firstColumn() const
     730{
     731    for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
     732        if (child->isTableCol())
     733            return toRenderTableCol(child);
     734
     735        // We allow only table-captions before columns or column-groups.
     736        if (!child->isTableCaption())
    741737            return 0;
    742         next = next->nextSibling();
    743     }
    744    
     738    }
     739
    745740    return 0;
    746741}
     
    750745    if (!m_hasColElements)
    751746        return 0;
    752     RenderObject* child = firstChild();
    753     unsigned cCol = 0;
    754 
    755     while (child) {
    756         if (child->isTableCol())
    757             break;
    758         if (!m_captions.contains(child))
    759             return 0;
    760         child = child->nextSibling();
    761     }
    762     if (!child)
    763         return 0;
    764 
    765     RenderTableCol* colElem = toRenderTableCol(child);
    766     while (colElem) {
    767         unsigned span = colElem->span();
    768         if (!colElem->firstChild()) {
    769             unsigned startCol = cCol;
    770             ASSERT(span >= 1);
    771             unsigned endCol = cCol + span - 1;
    772             cCol += span;
    773             if (cCol > col) {
    774                 if (startEdge)
    775                     *startEdge = startCol == col;
    776                 if (endEdge)
    777                     *endEdge = endCol == col;
    778                 return colElem;
    779             }
    780         }
    781         colElem = nextColElement(colElem);
     747
     748    unsigned columnCount = 0;
     749    for (RenderTableCol* columnRenderer = firstColumn(); columnRenderer; columnRenderer = columnRenderer->nextColumn()) {
     750        if (columnRenderer->isTableColumnGroupWithColumnChildren())
     751            continue;
     752
     753        unsigned span = columnRenderer->span();
     754        unsigned startCol = columnCount;
     755        ASSERT(span >= 1);
     756        unsigned endCol = columnCount + span - 1;
     757        columnCount += span;
     758        if (columnCount > col) {
     759            if (startEdge)
     760                *startEdge = startCol == col;
     761            if (endEdge)
     762                *endEdge = endCol == col;
     763            return columnRenderer;
     764        }
    782765    }
    783766
  • trunk/Source/WebCore/rendering/RenderTable.h

    r117339 r117988  
    176176    }
    177177
     178    // Return the first column or column-group.
     179    RenderTableCol* firstColumn() const;
     180
    178181    RenderTableCol* colElement(unsigned col, bool* startEdge = 0, bool* endEdge = 0) const;
    179     RenderTableCol* nextColElement(RenderTableCol* current) const;
    180182
    181183    bool needsSectionRecalc() const { return m_needsSectionRecalc; }
  • trunk/Source/WebCore/rendering/RenderTableCell.cpp

    r117697 r117988  
    133133            colWidthSum = Length(colWidthSum.value() + colWidth.value(), Fixed);
    134134
    135             tableCol = table()->nextColElement(tableCol);
     135            tableCol = tableCol->nextColumn();
    136136            // If no next <col> tag found for the span we just return what we have for now.
    137137            if (!tableCol)
  • trunk/Source/WebCore/rendering/RenderTableCol.cpp

    r100386 r117988  
    117117}
    118118
     119RenderTableCol* RenderTableCol::nextColumn() const
     120{
     121    // If |this| is a column-group, the next column is the colgroup's first child column.
     122    if (RenderObject* firstChild = this->firstChild())
     123        return toRenderTableCol(firstChild);
     124
     125    // Otherwise it's the next column along.
     126    RenderObject* next = nextSibling();
     127
     128    // Failing that, the child is the last column in a column-group, so the next column is the next column/column-group after its column-group.
     129    if (!next && parent()->isTableCol())
     130        next = parent()->nextSibling();
     131
     132    for (; next && !next->isTableCol(); next = next->nextSibling()) {
     133        // We allow captions mixed with columns and column-groups.
     134        if (next->isTableCaption())
     135            continue;
     136
     137        return 0;
     138    }
     139
     140    return toRenderTableCol(next);
    119141}
     142
     143}
  • trunk/Source/WebCore/rendering/RenderTableCol.h

    r111118 r117988  
    4444    unsigned span() const { return m_span; }
    4545    void setSpan(unsigned span) { m_span = span; }
    46     bool isTableColGroup() { return firstChild() ? true : false; }
     46
     47    bool isTableColumnGroupWithColumnChildren() { return firstChild(); }
     48
     49    // Returns the next column or column-group.
     50    RenderTableCol* nextColumn() const;
     51
    4752private:
    4853    virtual RenderObjectChildList* virtualChildren() { return children(); }
Note: See TracChangeset for help on using the changeset viewer.