⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 275059 in webkit


Ignore:
Timestamp:
Mar 25, 2021, 2:45:05 PM (5 years ago)
Author:
Cameron McCormack
Message:

Collapse newly adjacent anonymous table cells when a table cell is detached from between them.
https://bugs.webkit.org/show_bug.cgi?id=220934

Reviewed by Zalan Bujtas.

Source/WebCore:

We already had support for collapsing newly adjacent table row cells when a
table row cell is detached from between them. We need to do this for anonymous
table cells too.

Test: fast/table/table-anonymous-cell-collapse.html

  • rendering/updating/RenderTreeBuilder.cpp:

(WebCore::RenderTreeBuilder::destroyAndCleanUpAnonymousWrappers): Call
into the RenderTreeBuilder::Table to collapse anonymous table cells when
needed.

  • rendering/updating/RenderTreeBuilderTable.cpp:

(WebCore::RenderTreeBuilder::Table::collapseAndDestroyAnonymousSiblings):
Factor out the existing collapseAndDestroyAnonymousSiblingRows into
something re-usable.
(WebCore::RenderTreeBuilder::Table::collapseAndDestroyAnonymousSiblingCells):
Added.
(WebCore::RenderTreeBuilder::Table::collapseAndDestroyAnonymousSiblingRows):
Factored out to collapseAndDestroyAnonymousSiblings.

  • rendering/updating/RenderTreeBuilderTable.h:

LayoutTests:

  • fast/table/table-anonymous-cell-collapse-expected.html: Added.
  • fast/table/table-anonymous-cell-collapse.html: Added.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r275055 r275059  
     12021-03-25  Cameron McCormack  <heycam@apple.com>
     2
     3        Collapse newly adjacent anonymous table cells when a table cell is detached from between them.
     4        https://bugs.webkit.org/show_bug.cgi?id=220934
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        * fast/table/table-anonymous-cell-collapse-expected.html: Added.
     9        * fast/table/table-anonymous-cell-collapse.html: Added.
     10
    1112021-03-25  Tim Nguyen  <ntim@apple.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r275055 r275059  
     12021-03-25  Cameron McCormack  <heycam@apple.com>
     2
     3        Collapse newly adjacent anonymous table cells when a table cell is detached from between them.
     4        https://bugs.webkit.org/show_bug.cgi?id=220934
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        We already had support for collapsing newly adjacent table row cells when a
     9        table row cell is detached from between them.  We need to do this for anonymous
     10        table cells too.
     11
     12        Test: fast/table/table-anonymous-cell-collapse.html
     13
     14        * rendering/updating/RenderTreeBuilder.cpp:
     15        (WebCore::RenderTreeBuilder::destroyAndCleanUpAnonymousWrappers): Call
     16        into the RenderTreeBuilder::Table to collapse anonymous table cells when
     17        needed.
     18        * rendering/updating/RenderTreeBuilderTable.cpp:
     19        (WebCore::RenderTreeBuilder::Table::collapseAndDestroyAnonymousSiblings):
     20        Factor out the existing collapseAndDestroyAnonymousSiblingRows into
     21        something re-usable.
     22        (WebCore::RenderTreeBuilder::Table::collapseAndDestroyAnonymousSiblingCells):
     23        Added.
     24        (WebCore::RenderTreeBuilder::Table::collapseAndDestroyAnonymousSiblingRows):
     25        Factored out to collapseAndDestroyAnonymousSiblings.
     26        * rendering/updating/RenderTreeBuilderTable.h:
     27
    1282021-03-25  Tim Nguyen  <ntim@apple.com>
    229
  • trunk/Source/WebCore/rendering/updating/RenderTreeBuilder.cpp

    r274398 r275059  
    5252#include "RenderSVGText.h"
    5353#include "RenderTable.h"
     54#include "RenderTableCell.h"
    5455#include "RenderTableRow.h"
    5556#include "RenderTableSection.h"
     
    827828    clearFloatsAndOutOfFlowPositionedObjects();
    828829
    829     if (is<RenderTableRow>(destroyRoot))
    830         tableBuilder().collapseAndDestroyAnonymousSiblingRows(downcast<RenderTableRow>(destroyRoot));
     830    auto collapseAndDestroyAnonymousSiblings = [&] {
     831        // FIXME: Probably need to handle other table parts here as well.
     832        if (is<RenderTableCell>(destroyRoot)) {
     833            tableBuilder().collapseAndDestroyAnonymousSiblingCells(downcast<RenderTableCell>(destroyRoot));
     834            return;
     835        }
     836
     837        if (is<RenderTableRow>(destroyRoot)) {
     838            tableBuilder().collapseAndDestroyAnonymousSiblingRows(downcast<RenderTableRow>(destroyRoot));
     839            return;
     840        }
     841    };
     842    collapseAndDestroyAnonymousSiblings();
    831843
    832844    // FIXME: Do not try to collapse/cleanup the anonymous wrappers inside destroy (see webkit.org/b/186746).
  • trunk/Source/WebCore/rendering/updating/RenderTreeBuilderTable.cpp

    r274739 r275059  
    248248}
    249249
     250template <typename Parent, typename Child>
     251void RenderTreeBuilder::Table::collapseAndDestroyAnonymousSiblings(Parent* parent, Child* previousSibling, Child* nextSibling)
     252{
     253    if (!parent || !previousSibling || !nextSibling)
     254        return;
     255
     256    if (previousSibling->isAnonymous() && nextSibling->isAnonymous()) {
     257        m_builder.moveAllChildren(*nextSibling, *previousSibling, RenderTreeBuilder::NormalizeAfterInsertion::No);
     258        auto toDestroy = m_builder.detach(*parent, *nextSibling);
     259    }
     260
     261    previousSibling->setNeedsLayout();
     262}
     263
     264void RenderTreeBuilder::Table::collapseAndDestroyAnonymousSiblingCells(RenderTableCell& cell)
     265{
     266    collapseAndDestroyAnonymousSiblings(cell.row(), cell.previousCell(), cell.nextCell());
     267}
     268
    250269void RenderTreeBuilder::Table::collapseAndDestroyAnonymousSiblingRows(RenderTableRow& row)
    251270{
    252     auto* section = row.section();
    253     if (!section)
    254         return;
    255 
    256     auto* before = row.previousRow();
    257     if (!before)
    258         return;
    259 
    260     auto* after = row.nextRow();
    261     if (!after)
    262         return;
    263 
    264     if (before->isAnonymous() && after->isAnonymous()) {
    265         m_builder.moveAllChildren(*after, *before, RenderTreeBuilder::NormalizeAfterInsertion::No);
    266         auto toDestroy = m_builder.detach(*section, *after);
    267     }
    268 
    269     before->setNeedsLayout();
    270 }
    271 
    272 }
     271    collapseAndDestroyAnonymousSiblings(row.section(), row.previousRow(), row.nextRow());
     272}
     273
     274}
  • trunk/Source/WebCore/rendering/updating/RenderTreeBuilderTable.h

    r228954 r275059  
    3333class RenderObject;
    3434class RenderTable;
     35class RenderTableCell;
    3536class RenderTableSection;
    3637class RenderTableRow;
     
    5253    bool childRequiresTable(const RenderElement& parent, const RenderObject& child);
    5354
     55    void collapseAndDestroyAnonymousSiblingCells(RenderTableCell&);
    5456    void collapseAndDestroyAnonymousSiblingRows(RenderTableRow&);
    5557
    5658private:
     59    template <typename Parent, typename Child>
     60    void collapseAndDestroyAnonymousSiblings(Parent*, Child* previousChild, Child* nextChild);
     61
    5762    RenderTreeBuilder& m_builder;
    5863};
Note: See TracChangeset for help on using the changeset viewer.