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

Changeset 279508 in webkit


Ignore:
Timestamp:
Jul 2, 2021, 10:55:45 AM (5 years ago)
Author:
Alan Bujtas
Message:

[LFC][TFC] Keep track of both the fixed and percent maximum values for each column
​https://bugs.webkit.org/show_bug.cgi?id=227491

Reviewed by Antti Koivisto.

This patch is in preparation for supporting mixed column width types when each row
has diffrent type of widths (e.g <tr><td style="width: 100px;"></td></tr><tr><td style="width: 10%;"></td></tr>)

  • layout/formattingContexts/table/TableFormattingContext.cpp:

(WebCore::Layout::TableFormattingContext::computedPreferredWidthForColumns):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r279504 r279508  
     12021-07-02  Alan Bujtas  <zalan@apple.com>
     2
     3        [LFC][TFC] Keep track of both the fixed and percent maximum values for each column
     4        https://bugs.webkit.org/show_bug.cgi?id=227491
     5
     6        Reviewed by Antti Koivisto.
     7
     8        This patch is in preparation for supporting mixed column width types when each row
     9        has diffrent type of widths (e.g <tr><td style="width: 100px;"></td></tr><tr><td style="width: 10%;"></td></tr>)
     10
     11        * layout/formattingContexts/table/TableFormattingContext.cpp:
     12        (WebCore::Layout::TableFormattingContext::computedPreferredWidthForColumns):
     13
    1142021-07-02  Alan Bujtas  <zalan@apple.com>
    215
  • trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingContext.cpp

    r279504 r279508  
    340340    }
    341341
    342     Vector<std::optional<float>> columnPercentList(columnList.size());
    343342    auto hasColumnWithPercentWidth = false;
     343    auto hasColumnWithFixedWidth = false;
     344    Vector<std::optional<LayoutUnit>> maximumFixedColumnWidths(columnList.size());
     345    Vector<std::optional<float>> maximumPercentColumnWidths(columnList.size());
    344346    for (auto& cell : grid.cells()) {
    345347        auto& cellBox = cell->box();
    … …  
    352354        }
    353355        auto cellPosition = cell->position();
     356        auto& cellStyle = cellBox.style();
    354357        // Expand it with border and padding.
    355358        auto horizontalBorderAndPaddingWidth = formattingGeometry.computedCellBorder(*cell).width()
    356             + formattingGeometry.fixedValue(cellBox.style().paddingLeft()).value_or(0)
    357             + formattingGeometry.fixedValue(cellBox.style().paddingRight()).value_or(0);
     359            + formattingGeometry.fixedValue(cellStyle.paddingLeft()).value_or(0)
     360            + formattingGeometry.fixedValue(cellStyle.paddingRight()).value_or(0);
    358361        intrinsicWidth->expand(horizontalBorderAndPaddingWidth);
    359362        // Spanner cells put their intrinsic widths on the initial slots.
    360363        grid.slot(cellPosition)->setWidthConstraints(*intrinsicWidth);
    361         if (auto fixedWidth = formattingGeometry.fixedValue(cellBox.style().logicalWidth())) {
    362             *fixedWidth += horizontalBorderAndPaddingWidth;
    363             auto& column = columnList[cellPosition.column];
    364             if (*fixedWidth > column.computedLogicalWidth().value())
    365                 column.setComputedLogicalWidth({ *fixedWidth, LengthType::Fixed });
    366         }
    367         // Collect the percent values so that we can compute the maximum values per column.
    368         auto& cellLogicalWidth = cellBox.style().logicalWidth();
    369         if (cellLogicalWidth.isPercent()) {
    370             // FIXME: Add support for column spanning distribution.
    371             columnPercentList[cellPosition.column] = std::max(cellLogicalWidth.percent(), columnPercentList[cellPosition.column].value_or(0.0f));
     364
     365        auto cellLogicalWidth = cellStyle.logicalWidth();
     366        auto columnIndex = cellPosition.column;
     367        switch (cellLogicalWidth.type()) {
     368        case LengthType::Fixed: {
     369            auto fixedWidth = LayoutUnit { cellLogicalWidth.value() } + horizontalBorderAndPaddingWidth;
     370            maximumFixedColumnWidths[columnIndex] = std::max(maximumFixedColumnWidths[columnIndex].value_or(0_lu), fixedWidth);
     371            hasColumnWithFixedWidth = true;
     372            break;
     373        }
     374        case LengthType::Percent: {
     375            maximumPercentColumnWidths[columnIndex] = std::max(maximumPercentColumnWidths[columnIndex].value_or(0.f), cellLogicalWidth.percent());
    372376            hasColumnWithPercentWidth = true;
     377            break;
     378        }
     379        case LengthType::Relative:
     380            ASSERT_NOT_IMPLEMENTED_YET();
     381            break;
     382        default:
     383            break;
    373384        }
    374385    }
    … …  
    390401            }
    391402            auto widthConstraints = slot.widthConstraints();
    392             if (auto columnLogicalWidth = columnList[columnIndex].computedLogicalWidth(); columnLogicalWidth.isFixed())
    393                 widthConstraints.maximum = std::max(LayoutUnit { columnLogicalWidth.value() }, widthConstraints.minimum);
     403            if (auto fixedColumnWidth = maximumFixedColumnWidths[columnIndex])
     404                widthConstraints.maximum = std::max(*fixedColumnWidth, widthConstraints.minimum);
    394405
    395406            columnIntrinsicWidths[columnIndex].minimum = std::max(widthConstraints.minimum, columnIntrinsicWidths[columnIndex].minimum);
    … …  
    429440
    430441    // 6. Adjust the table max width with the percent column values if applicable.
    431     if (hasColumnWithPercentWidth) {
     442    if (hasColumnWithFixedWidth && !hasColumnWithPercentWidth) {
     443        for (size_t columnIndex = 0; columnIndex < columnList.size(); ++columnIndex) {
     444            if (auto fixedWidth = maximumFixedColumnWidths[columnIndex])
     445                columnList[columnIndex].setComputedLogicalWidth({ *fixedWidth, LengthType::Fixed });
     446        }
     447    } else if (hasColumnWithPercentWidth) {
    432448        auto remainingPercent = 100.0f;
    433449        auto percentMaximumWidth = LayoutUnit { };
    … …  
    439455        // - Compute the non-percent based columns width by using the remaining percent value (e.g 50% and 10% columns would leave 40% for the rest of the columns)
    440456        for (size_t columnIndex = 0; columnIndex < columnList.size(); ++columnIndex) {
    441             auto percent = columnPercentList[columnIndex];
    442             if (!percent) {
    443                 nonPercentColumnsWidth += columnIntrinsicWidths[columnIndex].maximum;
    444                 continue;
    445             }
    446             ASSERT(*percent > 0);
    447             percent = std::min(*percent, remainingPercent);
    448             columnList[columnIndex].setComputedLogicalWidth({ *percent, LengthType::Percent });
    449             percentMaximumWidth = std::max(percentMaximumWidth, LayoutUnit { columnIntrinsicWidths[columnIndex].maximum * 100.0f / *percent });
    450             remainingPercent -= *percent;
    451         }
    452 
     457            auto nonPercentColumnWidth = columnIntrinsicWidths[columnIndex].maximum;
     458            if (auto fixedWidth = maximumFixedColumnWidths[columnIndex]) {
     459                columnList[columnIndex].setComputedLogicalWidth({ *fixedWidth, LengthType::Fixed });
     460                nonPercentColumnWidth = std::max(nonPercentColumnWidth, *fixedWidth);
     461            }
     462            if (!maximumPercentColumnWidths[columnIndex]) {
     463                nonPercentColumnsWidth += nonPercentColumnWidth;
     464                continue;
     465            }
     466            auto percent = std::min(*maximumPercentColumnWidths[columnIndex], remainingPercent);
     467            ASSERT(percent > 0);
     468            columnList[columnIndex].setComputedLogicalWidth({ percent, LengthType::Percent });
     469            percentMaximumWidth = std::max(percentMaximumWidth, LayoutUnit { nonPercentColumnWidth * 100.0f / percent });
     470            remainingPercent -= percent;
     471        }
    453472        ASSERT(remainingPercent >= 0.f);
    454473        auto adjustedMaximumWidth = percentMaximumWidth;
    … …  
    457476        tableWidthConstraints.maximum = std::max(tableWidthConstraints.maximum, adjustedMaximumWidth);
    458477    }
    459 
    460478    // Expand the preferred width with leading and trailing cell spacing (note that column spanners count as one cell).
    461479    tableWidthConstraints += (numberOfActualColumns + 1) * grid.horizontalSpacing();
Note: See TracChangeset for help on using the changeset viewer.