Changeset 279508 in webkit
- Timestamp:
- Jul 2, 2021, 10:55:45 AM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
-
ChangeLog (modified) (1 diff)
-
layout/formattingContexts/table/TableFormattingContext.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r279504 r279508 1 2021-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 1 14 2021-07-02 Alan Bujtas <zalan@apple.com> 2 15 -
trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingContext.cpp
r279504 r279508 340 340 } 341 341 342 Vector<std::optional<float>> columnPercentList(columnList.size());343 342 auto hasColumnWithPercentWidth = false; 343 auto hasColumnWithFixedWidth = false; 344 Vector<std::optional<LayoutUnit>> maximumFixedColumnWidths(columnList.size()); 345 Vector<std::optional<float>> maximumPercentColumnWidths(columnList.size()); 344 346 for (auto& cell : grid.cells()) { 345 347 auto& cellBox = cell->box(); … … 352 354 } 353 355 auto cellPosition = cell->position(); 356 auto& cellStyle = cellBox.style(); 354 357 // Expand it with border and padding. 355 358 auto horizontalBorderAndPaddingWidth = formattingGeometry.computedCellBorder(*cell).width() 356 + formattingGeometry.fixedValue(cell Box.style().paddingLeft()).value_or(0)357 + formattingGeometry.fixedValue(cell Box.style().paddingRight()).value_or(0);359 + formattingGeometry.fixedValue(cellStyle.paddingLeft()).value_or(0) 360 + formattingGeometry.fixedValue(cellStyle.paddingRight()).value_or(0); 358 361 intrinsicWidth->expand(horizontalBorderAndPaddingWidth); 359 362 // Spanner cells put their intrinsic widths on the initial slots. 360 363 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()); 372 376 hasColumnWithPercentWidth = true; 377 break; 378 } 379 case LengthType::Relative: 380 ASSERT_NOT_IMPLEMENTED_YET(); 381 break; 382 default: 383 break; 373 384 } 374 385 } … … 390 401 } 391 402 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); 394 405 395 406 columnIntrinsicWidths[columnIndex].minimum = std::max(widthConstraints.minimum, columnIntrinsicWidths[columnIndex].minimum); … … 429 440 430 441 // 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) { 432 448 auto remainingPercent = 100.0f; 433 449 auto percentMaximumWidth = LayoutUnit { }; … … 439 455 // - 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) 440 456 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 } 453 472 ASSERT(remainingPercent >= 0.f); 454 473 auto adjustedMaximumWidth = percentMaximumWidth; … … 457 476 tableWidthConstraints.maximum = std::max(tableWidthConstraints.maximum, adjustedMaximumWidth); 458 477 } 459 460 478 // Expand the preferred width with leading and trailing cell spacing (note that column spanners count as one cell). 461 479 tableWidthConstraints += (numberOfActualColumns + 1) * grid.horizontalSpacing();
Note:
See TracChangeset
for help on using the changeset viewer.