Changeset 156355 in webkit


Ignore:
Timestamp:
Sep 24, 2013 1:47:01 PM (11 years ago)
Author:
Antti Koivisto
Message:

Tighten table rendering code
https://bugs.webkit.org/show_bug.cgi?id=121860

Reviewed by Andreas Kling.

Hide firstChild/lastChild/nextSibling/previousSibling in table renderers,
expose correctly typed firstRow/nextCell etc instead.

Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r156352 r156355  
     12013-09-24  Antti Koivisto  <antti@apple.com>
     2
     3        Tighten table rendering code
     4        https://bugs.webkit.org/show_bug.cgi?id=121860
     5
     6        Reviewed by Andreas Kling.
     7
     8        Hide firstChild/lastChild/nextSibling/previousSibling in table renderers,
     9        expose correctly typed firstRow/nextCell etc instead.
     10
    1112013-09-24  Dean Jackson  <dino@apple.com>
    212
  • trunk/Source/WebCore/rendering/FixedTableLayout.cpp

    r156285 r156355  
    137137    unsigned currentColumn = 0;
    138138
    139     RenderObject* firstRow = section->firstChild();
    140     for (RenderObject* child = firstRow->firstChildSlow(); child; child = child->nextSibling()) {
    141         if (!child->isTableCell())
    142             continue;
    143 
    144         RenderTableCell* cell = toRenderTableCell(child);
    145 
     139    RenderTableRow* firstRow = section->firstRow();
     140    for (RenderTableCell* cell = firstRow->firstCell(); cell; cell = cell->nextCell()) {
    146141        Length logicalWidth = cell->styleOrColLogicalWidth();
    147142        unsigned span = cell->colSpan();
  • trunk/Source/WebCore/rendering/RenderTable.cpp

    r156312 r156355  
    187187        RenderTableSection* section = toRenderTableSection(lastBox);
    188188        if (beforeChild == section)
    189             beforeChild = section->firstChild();
     189            beforeChild = section->firstRow();
    190190        section->addChild(child, beforeChild);
    191191        return;
     
    570570        if (!section->isTableSection())
    571571            continue;
    572         for (RenderObject* row = toRenderTableSection(section)->firstChild(); row; row = row->nextSibling()) {
    573             if (!row->isTableRow())
    574                 continue;
    575             for (RenderObject* cell = toRenderTableRow(row)->firstChild(); cell; cell = cell->nextSibling()) {
    576                 if (!cell->isTableCell())
    577                     continue;
    578                 ASSERT(toRenderTableCell(cell)->table() == this);
    579                 toRenderTableCell(cell)->collectBorderValues(m_collapsedBorders);
     572        for (RenderTableRow* row = toRenderTableSection(section)->firstRow(); row; row = row->nextRow()) {
     573            for (RenderTableCell* cell = row->firstCell(); cell; cell = cell->nextCell()) {
     574                ASSERT(cell->table() == this);
     575                cell->collectBorderValues(m_collapsedBorders);
    580576            }
    581577        }
  • trunk/Source/WebCore/rendering/RenderTableCell.cpp

    r155908 r156355  
    740740            prevRow = parent()->previousSibling();
    741741        else
    742             prevRow = prevCell->section()->lastChild();
     742            prevRow = prevCell->section()->lastRow();
    743743   
    744744        if (prevRow) {
  • trunk/Source/WebCore/rendering/RenderTableCell.h

    r156166 r156355  
    7171    }
    7272
     73    RenderTableCell* nextCell() const;
     74    RenderTableCell* previousCell() const;
     75
    7376    RenderTableRow* row() const { return toRenderTableRow(parent()); }
    7477    RenderTableSection* section() const { return toRenderTableSection(parent()->parent()); }
     
    208211    }
    209212
     213    using RenderBlockFlow::nodeAtPoint;
     214
    210215#ifndef NDEBUG
    211216    bool isFirstOrLastCellInRow() const
     
    279284    unsigned parseRowSpanFromDOM() const;
    280285    unsigned parseColSpanFromDOM() const;
     286
     287    void nextSibling() const WTF_DELETED_FUNCTION;
     288    void previousSibling() const WTF_DELETED_FUNCTION;
    281289
    282290    // Note MSVC will only pack members if they have identical types, hence we use unsigned instead of bool here.
     
    304312void toRenderTableCell(const RenderTableCell*);
    305313
     314inline RenderTableCell* RenderTableCell::nextCell() const
     315{
     316    return toRenderTableCell(RenderBlockFlow::nextSibling());
     317}
     318
     319inline RenderTableCell* RenderTableCell::previousCell() const
     320{
     321    return toRenderTableCell(RenderBlockFlow::previousSibling());
     322}
     323
     324inline RenderTableCell* RenderTableRow::firstCell() const
     325{
     326    return toRenderTableCell(RenderBox::firstChild());
     327}
     328
     329inline RenderTableCell* RenderTableRow::lastCell() const
     330{
     331    return toRenderTableCell(RenderBox::lastChild());
     332}
     333
    306334} // namespace WebCore
    307335
  • trunk/Source/WebCore/rendering/RenderTableRow.cpp

    r156312 r156355  
    110110        RenderObject* last = beforeChild;
    111111        if (!last)
    112             last = lastChild();
     112            last = lastCell();
    113113        if (last && last->isAnonymous() && last->isTableCell() && !last->isBeforeOrAfterContent()) {
    114114            RenderTableCell* cell = toRenderTableCell(last);
     
    151151    RenderBox::addChild(cell, beforeChild);
    152152
    153     if (beforeChild || nextSibling())
     153    if (beforeChild || nextRow())
    154154        section()->setNeedsCellRecalc();
    155155}
     
    165165    bool paginated = view().layoutState()->isPaginated();
    166166               
    167     for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
    168         if (child->isTableCell()) {
    169             RenderTableCell* cell = toRenderTableCell(child);
    170             if (!cell->needsLayout() && paginated && view().layoutState()->pageLogicalHeight() && view().layoutState()->pageLogicalOffset(cell, cell->logicalTop()) != cell->pageLogicalOffset())
    171                 cell->setChildNeedsLayout(true, MarkOnlyThis);
    172 
    173             if (child->needsLayout()) {
    174                 cell->computeAndSetBlockDirectionMargins(table());
    175                 cell->layout();
    176             }
     167    for (RenderTableCell* cell = firstCell(); cell; cell = cell->nextCell()) {
     168        if (!cell->needsLayout() && paginated && view().layoutState()->pageLogicalHeight() && view().layoutState()->pageLogicalOffset(cell, cell->logicalTop()) != cell->pageLogicalOffset())
     169            cell->setChildNeedsLayout(true, MarkOnlyThis);
     170
     171        if (cell->needsLayout()) {
     172            cell->computeAndSetBlockDirectionMargins(table());
     173            cell->layout();
    177174        }
    178175    }
     
    184181    // parent table, and being mid-layout, that is invalid. Instead, we repaint our cells.
    185182    if (selfNeedsLayout() && checkForRepaintDuringLayout()) {
    186         for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
    187             if (child->isTableCell())
    188                 child->repaint();
    189         }
     183        for (RenderTableCell* cell = firstCell(); cell; cell = cell->nextCell())
     184            cell->repaint();
    190185    }
    191186
     
    217212    // Table rows cannot ever be hit tested.  Effectively they do not exist.
    218213    // Just forward to our children always.
    219     for (RenderObject* child = lastChild(); child; child = child->previousSibling()) {
     214    for (RenderTableCell* cell = lastCell(); cell; cell = cell->previousCell()) {
    220215        // FIXME: We have to skip over inline flows, since they can show up inside table rows
    221216        // at the moment (a demoted inline <form> for example). If we ever implement a
    222217        // table-specific hit-test method (which we should do for performance reasons anyway),
    223218        // then we can remove this check.
    224         if (child->isTableCell() && !toRenderBox(child)->hasSelfPaintingLayer()) {
    225             LayoutPoint cellPoint = flipForWritingModeForChild(toRenderTableCell(child), accumulatedOffset);
    226             if (child->nodeAtPoint(request, result, locationInContainer, cellPoint, action)) {
     219        if (cell->hasSelfPaintingLayer()) {
     220            LayoutPoint cellPoint = flipForWritingModeForChild(cell, accumulatedOffset);
     221            if (cell->nodeAtPoint(request, result, locationInContainer, cellPoint, action)) {
    227222                updateHitTestResult(result, locationInContainer.point() - toLayoutSize(cellPoint));
    228223                return true;
     
    247242
    248243    paintOutlineForRowIfNeeded(paintInfo, paintOffset);
    249     for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
    250         if (child->isTableCell()) {
    251             // Paint the row background behind the cell.
    252             if (paintInfo.phase == PaintPhaseBlockBackground || paintInfo.phase == PaintPhaseChildBlockBackground) {
    253                 RenderTableCell* cell = toRenderTableCell(child);
    254                 cell->paintBackgroundsBehindCell(paintInfo, paintOffset, this);
    255             }
    256             if (!toRenderBox(child)->hasSelfPaintingLayer())
    257                 child->paint(paintInfo, paintOffset);
    258         }
     244    for (RenderTableCell* cell = firstCell(); cell; cell = cell->nextCell()) {
     245        // Paint the row background behind the cell.
     246        if (paintInfo.phase == PaintPhaseBlockBackground || paintInfo.phase == PaintPhaseChildBlockBackground)
     247            cell->paintBackgroundsBehindCell(paintInfo, paintOffset, this);
     248        if (!cell->hasSelfPaintingLayer())
     249            cell->paint(paintInfo, paintOffset);
    259250    }
    260251}
  • trunk/Source/WebCore/rendering/RenderTableRow.h

    r156278 r156355  
    3636public:
    3737    explicit RenderTableRow(Element*);
     38
     39    RenderTableRow* nextRow() const;
     40    RenderTableRow* previousRow() const;
     41
     42    RenderTableCell* firstCell() const;
     43    RenderTableCell* lastCell() const;
    3844
    3945    RenderTableSection* section() const { return toRenderTableSection(parent()); }
     
    8591    virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0) OVERRIDE;
    8692
     93    virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
     94
    8795private:
    8896    virtual const char* renderName() const OVERRIDE { return (isAnonymous() || isPseudoElement()) ? "RenderTableRow (anonymous)" : "RenderTableRow"; }
     
    95103    virtual void layout() OVERRIDE;
    96104    virtual LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const OVERRIDE;
    97     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
    98105
    99106    virtual bool requiresLayer() const OVERRIDE { return hasOverflowClip() || hasTransform() || hasHiddenBackface() || hasClipPath() || createsGroup(); }
     
    104111
    105112    virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE;
     113
     114    void firstChild() const WTF_DELETED_FUNCTION;
     115    void lastChild() const WTF_DELETED_FUNCTION;
     116    void nextSibling() const WTF_DELETED_FUNCTION;
     117    void previousSibling() const WTF_DELETED_FUNCTION;
    106118
    107119    unsigned m_rowIndex : 31;
     
    123135void toRenderTableRow(const RenderTableRow*);
    124136
     137inline RenderTableRow* RenderTableSection::firstRow() const
     138{
     139    return toRenderTableRow(RenderBox::firstChild());
     140}
     141
     142inline RenderTableRow* RenderTableSection::lastRow() const
     143{
     144    return toRenderTableRow(RenderBox::lastChild());
     145}
     146
     147inline RenderTableRow* RenderTableRow::nextRow() const
     148{
     149    return toRenderTableRow(RenderBox::nextSibling());
     150}
     151
     152inline RenderTableRow* RenderTableRow::previousRow() const
     153{
     154    return toRenderTableRow(RenderBox::previousSibling());
     155}
     156
    125157} // namespace WebCore
    126158
  • trunk/Source/WebCore/rendering/RenderTableSection.cpp

    r156312 r156355  
    129129        RenderObject* last = beforeChild;
    130130        if (!last)
    131             last = lastChild();
     131            last = lastRow();
    132132        if (last && last->isAnonymous() && !last->isBeforeOrAfterContent()) {
    133133            RenderTableRow* row = toRenderTableRow(last);
    134134            if (beforeChild == row)
    135                 beforeChild = row->firstChild();
     135                beforeChild = row->firstCell();
    136136            row->addChild(child, beforeChild);
    137137            return;
     
    720720        borderWidth = sb.width();
    721721
    722     const BorderValue& rb = firstChild()->style()->borderBefore();
     722    const BorderValue& rb = firstRow()->style()->borderBefore();
    723723    if (rb.style() == BHIDDEN)
    724724        return -1;
     
    771771        borderWidth = sb.width();
    772772
    773     const BorderValue& rb = lastChild()->style()->borderAfter();
     773    const BorderValue& rb = lastRow()->style()->borderAfter();
    774774    if (rb.style() == BHIDDEN)
    775775        return -1;
     
    12241224    m_grid.clear();
    12251225
    1226     for (RenderObject* row = firstChild(); row; row = row->nextSibling()) {
    1227         if (row->isTableRow()) {
    1228             unsigned insertionRow = m_cRow;
    1229             m_cRow++;
    1230             m_cCol = 0;
    1231             ensureRows(m_cRow);
    1232 
    1233             RenderTableRow* tableRow = toRenderTableRow(row);
    1234             m_grid[insertionRow].rowRenderer = tableRow;
    1235             tableRow->setRowIndex(insertionRow);
    1236             setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(m_grid[insertionRow]);
    1237 
    1238             for (RenderObject* cell = tableRow->firstChild(); cell; cell = cell->nextSibling()) {
    1239                 if (!cell->isTableCell())
    1240                     continue;
    1241 
    1242                 RenderTableCell* tableCell = toRenderTableCell(cell);
    1243                 addCell(tableCell, tableRow);
    1244             }
    1245         }
     1226    for (RenderTableRow* row = firstRow(); row; row = row->nextRow()) {
     1227        unsigned insertionRow = m_cRow;
     1228        m_cRow++;
     1229        m_cCol = 0;
     1230        ensureRows(m_cRow);
     1231
     1232        m_grid[insertionRow].rowRenderer = row;
     1233        row->setRowIndex(insertionRow);
     1234        setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(m_grid[insertionRow]);
     1235
     1236        for (RenderTableCell* cell = row->firstCell(); cell; cell = cell->nextCell())
     1237            addCell(cell, row);
    12461238    }
    12471239
     
    12581250    setRowLogicalHeightToRowStyleLogicalHeightIfNotRelative(m_grid[rowIndex]);
    12591251
    1260     for (RenderObject* cell = m_grid[rowIndex].rowRenderer->firstChild(); cell; cell = cell->nextSibling()) {
    1261         if (!cell->isTableCell())
    1262             continue;
    1263 
    1264         updateLogicalHeightForCell(m_grid[rowIndex], toRenderTableCell(cell));
    1265     }
     1252    for (RenderTableCell* cell = m_grid[rowIndex].rowRenderer->firstCell(); cell; cell = cell->nextCell())
     1253        updateLogicalHeightForCell(m_grid[rowIndex], cell);
    12661254}
    12671255
     
    13491337{
    13501338    // If we have no children then we have nothing to do.
    1351     if (!firstChild())
     1339    if (!firstRow())
    13521340        return false;
    13531341
     
    13601348
    13611349    if (hasOverflowingCell()) {
    1362         for (RenderObject* child = lastChild(); child; child = child->previousSibling()) {
     1350        for (RenderTableRow* row = lastRow(); row; row = row->previousRow()) {
    13631351            // FIXME: We have to skip over inline flows, since they can show up inside table rows
    13641352            // at the moment (a demoted inline <form> for example). If we ever implement a
    13651353            // table-specific hit-test method (which we should do for performance reasons anyway),
    13661354            // then we can remove this check.
    1367             if (child->isBox() && !toRenderBox(child)->hasSelfPaintingLayer()) {
    1368                 LayoutPoint childPoint = flipForWritingModeForChild(toRenderBox(child), adjustedLocation);
    1369                 if (child->nodeAtPoint(request, result, locationInContainer, childPoint, action)) {
     1355            if (row->hasSelfPaintingLayer()) {
     1356                LayoutPoint childPoint = flipForWritingModeForChild(row, adjustedLocation);
     1357                if (row->nodeAtPoint(request, result, locationInContainer, childPoint, action)) {
    13701358                    updateHitTestResult(result, toLayoutPoint(locationInContainer.point() - childPoint));
    13711359                    return true;
  • trunk/Source/WebCore/rendering/RenderTableSection.h

    r156278 r156355  
    3131namespace WebCore {
    3232
     33class RenderTableRow;
     34
    3335enum CollapsedBorderSide {
    3436    CBSBefore,
     
    6668    virtual ~RenderTableSection();
    6769
     70    RenderTableRow* firstRow() const;
     71    RenderTableRow* lastRow() const;
     72
    6873    virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0) OVERRIDE;
    6974
     
    239244    void setLogicalPositionForCell(RenderTableCell*, unsigned effectiveColumn) const;
    240245
     246    void firstChild() const WTF_DELETED_FUNCTION;
     247    void lastChild() const WTF_DELETED_FUNCTION;
     248
    241249    Vector<RowStruct> m_grid;
    242250    Vector<int> m_rowPos;
Note: See TracChangeset for help on using the changeset viewer.