Commit 3da47124 authored by Aleks Totic's avatar Aleks Totic Committed by Commit Bot

[TablesNG] Make LayoutTableTest* unit tests pass

Small change to ComputeGridMinMax was necessary.
0% width cells are treated as "no percentage".
This is a common pattern in table algorithms:
"Zeroes are special!"

The fix for LayoutNGTable::AddVisualEffectOverflow was
good. It made 11 more invalidation tests pass.
The old visualoverflow was too large.

Bug: 958381
Change-Id: Ie6eec7f749ebd4400674e581f1dc128e4c3f81ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2551540Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Commit-Queue: Aleks Totic <atotic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#829888}
parent 208321c0
...@@ -80,9 +80,16 @@ TEST_F(LayoutTableTest, OverflowWithCollapsedBorders) { ...@@ -80,9 +80,16 @@ TEST_F(LayoutTableTest, OverflowWithCollapsedBorders) {
LayoutUnit(0), LayoutUnit(10)); LayoutUnit(0), LayoutUnit(10));
EXPECT_EQ(expected_self_visual_overflow, EXPECT_EQ(expected_self_visual_overflow,
table->PhysicalSelfVisualOverflowRect()); table->PhysicalSelfVisualOverflowRect());
// For this table, its layout overflow equals self visual overflow. if (RuntimeEnabledFeatures::LayoutNGTableEnabled()) {
EXPECT_EQ(expected_self_visual_overflow, table->PhysicalLayoutOverflowRect()); EXPECT_EQ(table->PhysicalContentBoxRect(),
table->PhysicalLayoutOverflowRect());
} else {
// In Legacy, visual overflow incorrectly does not include borders
// that extend beyond table boundaries.
// For this table, its layout overflow equals self visual overflow.
EXPECT_EQ(expected_self_visual_overflow,
table->PhysicalLayoutOverflowRect());
}
// The table's visual overflow covers self visual overflow and content visual // The table's visual overflow covers self visual overflow and content visual
// overflows. // overflows.
auto expected_visual_overflow = table->PhysicalContentBoxRect(); auto expected_visual_overflow = table->PhysicalContentBoxRect();
...@@ -133,14 +140,25 @@ TEST_F(LayoutTableTest, CollapsedBorders) { ...@@ -133,14 +140,25 @@ TEST_F(LayoutTableTest, CollapsedBorders) {
// Cells have wider borders. // Cells have wider borders.
auto* table3 = GetTableByElementId("table3"); auto* table3 = GetTableByElementId("table3");
// Cell E's border-top won. if (RuntimeEnabledFeatures::LayoutNGTableEnabled()) {
EXPECT_EQ(7, table3->BorderBefore()); // Cell E's border-top won.
// Cell H's border-bottom won. EXPECT_EQ(LayoutUnit(7.5), table3->BorderBefore());
EXPECT_EQ(20, table3->BorderAfter()); // Cell H's border-bottom won.
// Cell E's border-left won. EXPECT_EQ(20, table3->BorderAfter());
EXPECT_EQ(10, table3->BorderStart()); // Cell E's border-left won.
// Cell F's border-bottom won. EXPECT_EQ(LayoutUnit(10.5), table3->BorderStart());
EXPECT_EQ(13, table3->BorderEnd()); // Cell F's border-bottom won.
EXPECT_EQ(LayoutUnit(12.5), table3->BorderEnd());
} else {
// Cell E's border-top won.
EXPECT_EQ(7, table3->BorderBefore());
// Cell H's border-bottom won.
EXPECT_EQ(20, table3->BorderAfter());
// Cell E's border-left won.
EXPECT_EQ(10, table3->BorderStart());
// Cell F's border-bottom won.
EXPECT_EQ(13, table3->BorderEnd());
}
} }
TEST_F(LayoutTableTest, CollapsedBordersWithCol) { TEST_F(LayoutTableTest, CollapsedBordersWithCol) {
...@@ -224,7 +242,11 @@ TEST_F(LayoutTableTest, WidthPercentagesExceedHundred) { ...@@ -224,7 +242,11 @@ TEST_F(LayoutTableTest, WidthPercentagesExceedHundred) {
// Table width should be TableLayoutAlgorithm::kMaxTableWidth // Table width should be TableLayoutAlgorithm::kMaxTableWidth
auto* table = GetTableByElementId("onlyTable"); auto* table = GetTableByElementId("onlyTable");
EXPECT_EQ(1000000, table->OffsetWidth()); // TablesNG will grow up to LayoutUnit::Max()
if (RuntimeEnabledFeatures::LayoutNGTableEnabled())
EXPECT_EQ(2000000, table->OffsetWidth());
else
EXPECT_EQ(1000000, table->OffsetWidth());
} }
TEST_F(LayoutTableTest, CloseToMaxWidth) { TEST_F(LayoutTableTest, CloseToMaxWidth) {
......
...@@ -225,17 +225,23 @@ void LayoutNGTable::AddVisualEffectOverflow() { ...@@ -225,17 +225,23 @@ void LayoutNGTable::AddVisualEffectOverflow() {
if (const NGPhysicalBoxFragment* fragment = GetPhysicalFragment(0)) { if (const NGPhysicalBoxFragment* fragment = GetPhysicalFragment(0)) {
DCHECK_EQ(PhysicalFragmentCount(), 1u); DCHECK_EQ(PhysicalFragmentCount(), 1u);
// Table's collapsed borders contribute to visual overflow. // Table's collapsed borders contribute to visual overflow.
// Table border side can be composed of multiple border segments. // In the inline direction, table's border box does not include
// Inline visual overflow uses size of the largest border segment. // visual border width (largest border), but does include
// Block visual overflow uses size of first border segment. // layout border width (border of first cell).
// Expands border box to include visual border width.
if (const NGTableBorders* collapsed_borders = if (const NGTableBorders* collapsed_borders =
fragment->TableCollapsedBorders()) { fragment->TableCollapsedBorders()) {
PhysicalRect borders_overflow = PhysicalBorderBoxRect(); PhysicalRect borders_overflow = PhysicalBorderBoxRect();
NGBoxStrut table_borders = collapsed_borders->TableBorder(); NGBoxStrut table_borders = collapsed_borders->TableBorder();
auto visual_inline_strut = auto visual_inline_strut =
collapsed_borders->GetCollapsedBorderVisualInlineStrut(); collapsed_borders->GetCollapsedBorderVisualInlineStrut();
table_borders.inline_start = visual_inline_strut.first; // Expand by difference between visual and layout border width.
table_borders.inline_end = visual_inline_strut.second; table_borders.inline_start =
visual_inline_strut.first - table_borders.inline_start;
table_borders.inline_end =
visual_inline_strut.second - table_borders.inline_end;
table_borders.block_start = LayoutUnit();
table_borders.block_end = LayoutUnit();
borders_overflow.Expand( borders_overflow.Expand(
table_borders.ConvertToPhysical(StyleRef().GetWritingDirection())); table_borders.ConvertToPhysical(StyleRef().GetWritingDirection()));
AddSelfVisualOverflow(borders_overflow); AddSelfVisualOverflow(borders_overflow);
......
...@@ -108,6 +108,10 @@ class CORE_EXPORT LayoutNGTable : public LayoutNGMixin<LayoutBlock>, ...@@ -108,6 +108,10 @@ class CORE_EXPORT LayoutNGTable : public LayoutNGMixin<LayoutBlock>,
LayoutRectOutsets BorderBoxOutsets() const override; LayoutRectOutsets BorderBoxOutsets() const override;
// TODO(1151101)
// ClientLeft/Top are incorrect for tables, but cannot be fixed
// by subclassing ClientLeft/Top.
PhysicalRect OverflowClipRect(const PhysicalOffset&, PhysicalRect OverflowClipRect(const PhysicalOffset&,
OverlayScrollbarClipBehavior) const override; OverlayScrollbarClipBehavior) const override;
...@@ -177,8 +181,8 @@ class CORE_EXPORT LayoutNGTable : public LayoutNGMixin<LayoutBlock>, ...@@ -177,8 +181,8 @@ class CORE_EXPORT LayoutNGTable : public LayoutNGMixin<LayoutBlock>,
return absolute_column_index; return absolute_column_index;
} }
// Legacy caches sections. Might not be needed by NG. // NG does not need this method. Sections are not cached.
void RecalcSectionsIfNeeded() const final { NOTIMPLEMENTED(); } void RecalcSectionsIfNeeded() const final {}
// Legacy caches sections. Might not be needed by NG. // Legacy caches sections. Might not be needed by NG.
void ForceSectionsRecalc() final { NOTIMPLEMENTED(); } void ForceSectionsRecalc() final { NOTIMPLEMENTED(); }
......
...@@ -37,8 +37,13 @@ void LayoutNGTableCell::InvalidateLayoutResultCacheAfterMeasure() const { ...@@ -37,8 +37,13 @@ void LayoutNGTableCell::InvalidateLayoutResultCacheAfterMeasure() const {
LayoutRectOutsets LayoutNGTableCell::BorderBoxOutsets() const { LayoutRectOutsets LayoutNGTableCell::BorderBoxOutsets() const {
NOT_DESTROYED(); NOT_DESTROYED();
DCHECK_GE(PhysicalFragmentCount(), 0u); // TODO(1061423) This function should not be called before layout.
return GetPhysicalFragment(0)->Borders().ToLayoutRectOutsets(); // ScrollAnchor::Examine does. Example trigger:
// ScrollTimelineTest.TimelineInvalidationWhenScrollerDisplayPropertyChanges
// DCHECK_GE(PhysicalFragmentCount(), 0u);
if (PhysicalFragmentCount() > 0)
return GetPhysicalFragment(0)->Borders().ToLayoutRectOutsets();
return LayoutNGBlockFlowMixin<LayoutBlockFlow>::BorderBoxOutsets();
} }
LayoutUnit LayoutNGTableCell::BorderTop() const { LayoutUnit LayoutNGTableCell::BorderTop() const {
......
...@@ -855,8 +855,8 @@ MinMaxSizes NGTableAlgorithmHelpers::ComputeGridInlineMinMax( ...@@ -855,8 +855,8 @@ MinMaxSizes NGTableAlgorithmHelpers::ComputeGridInlineMinMax(
} else { } else {
minmax.min_size += *column.min_inline_size; minmax.min_size += *column.min_inline_size;
} }
if (column.percent) { if (column.percent && *column.percent > 0) {
if (*column.max_inline_size > LayoutUnit() && *column.percent > 0) { if (*column.max_inline_size > LayoutUnit()) {
LayoutUnit estimate = LayoutUnit( LayoutUnit estimate = LayoutUnit(
100 / *column.percent * 100 / *column.percent *
(*column.max_inline_size - column.percent_border_padding)); (*column.max_inline_size - column.percent_border_padding));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment