Commit ca706d87 authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[LayoutNG] Allow negative-inline-size opportunity to fit zero-with lines

Following the CL:916262 that allowed zero-width layout opportunities,
this patch allows negative-width layout opportunities (e.g.,
120%-width floats.)

Zero-width lines (<br> only) can fit into such opportunities.

Bug: 636993
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_layout_tests_layout_ng
Change-Id: I66cf214732a0618500f2422a285282deda4f7eb3
Reviewed-on: https://chromium-review.googlesource.com/870950
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551768}
parent c2ac7c32
...@@ -1462,7 +1462,6 @@ crbug.com/591099 fast/text-autosizing/vertical-writing-mode.html [ Failure ] ...@@ -1462,7 +1462,6 @@ crbug.com/591099 fast/text-autosizing/vertical-writing-mode.html [ Failure ]
crbug.com/591099 fast/text-autosizing/wide-block.html [ Failure ] crbug.com/591099 fast/text-autosizing/wide-block.html [ Failure ]
crbug.com/591099 fast/text-autosizing/wide-child.html [ Failure ] crbug.com/591099 fast/text-autosizing/wide-child.html [ Failure ]
crbug.com/591099 fast/text-autosizing/wide-in-narrow-overflow-scroll.html [ Failure ] crbug.com/591099 fast/text-autosizing/wide-in-narrow-overflow-scroll.html [ Failure ]
crbug.com/591099 fast/text/break-word-with-floats.html [ Failure ]
crbug.com/591099 fast/text/complex-text-opacity.html [ Failure ] crbug.com/591099 fast/text/complex-text-opacity.html [ Failure ]
crbug.com/591099 fast/text/container-align-with-inlines.html [ Failure ] crbug.com/591099 fast/text/container-align-with-inlines.html [ Failure ]
crbug.com/591099 fast/text/decorations-transformed.html [ Failure ] crbug.com/591099 fast/text/decorations-transformed.html [ Failure ]
......
...@@ -101,10 +101,18 @@ bool Intersects(const NGLayoutOpportunity& opportunity, ...@@ -101,10 +101,18 @@ bool Intersects(const NGLayoutOpportunity& opportunity,
bool Intersects(const NGExclusionSpace::NGShelf& shelf, bool Intersects(const NGExclusionSpace::NGShelf& shelf,
const NGBfcOffset& offset, const NGBfcOffset& offset,
const LayoutUnit inline_size) { const LayoutUnit inline_size) {
return (shelf.line_right == LayoutUnit::Max() || if (shelf.line_right >= offset.line_offset &&
shelf.line_right >= offset.line_offset) && shelf.line_left <= offset.line_offset + inline_size)
(shelf.line_left == LayoutUnit::Min() || return true;
shelf.line_left <= offset.line_offset + inline_size); // Negative available space creates a zero-width opportunity at the inline-end
// of the shelf. Consider such shelf intersects.
// TODO(kojii): This is correct to find layout opportunities for zero-width
// in-flow inline or block objects (e.g., <br>,) but not correct for
// zero-width floats.
if (UNLIKELY(shelf.line_left > offset.line_offset ||
shelf.line_right < offset.line_offset + inline_size))
return true;
return false;
} }
// Creates a new layout opportunity. The given layout opportunity *must* // Creates a new layout opportunity. The given layout opportunity *must*
...@@ -136,8 +144,11 @@ NGLayoutOpportunity CreateLayoutOpportunity( ...@@ -136,8 +144,11 @@ NGLayoutOpportunity CreateLayoutOpportunity(
NGBfcOffset start_offset(std::max(shelf.line_left, offset.line_offset), NGBfcOffset start_offset(std::max(shelf.line_left, offset.line_offset),
std::max(shelf.block_offset, offset.block_offset)); std::max(shelf.block_offset, offset.block_offset));
// Max with |start_offset.line_offset| in case the shelf has a negative
// inline-size.
NGBfcOffset end_offset( NGBfcOffset end_offset(
std::min(shelf.line_right, offset.line_offset + inline_size), std::max(std::min(shelf.line_right, offset.line_offset + inline_size),
start_offset.line_offset),
LayoutUnit::Max()); LayoutUnit::Max());
return NGLayoutOpportunity(NGBfcRect(start_offset, end_offset)); return NGLayoutOpportunity(NGBfcRect(start_offset, end_offset));
...@@ -333,6 +344,9 @@ void NGExclusionSpace::Add(scoped_refptr<const NGExclusion> exclusion) { ...@@ -333,6 +344,9 @@ void NGExclusionSpace::Add(scoped_refptr<const NGExclusion> exclusion) {
} }
} }
// Just in case the shelf has a negative inline-size.
shelf.line_right = std::max(shelf.line_left, shelf.line_right);
// We can end up in a situation where a shelf is the same as the // We can end up in a situation where a shelf is the same as the
// previous one. For example: // previous one. For example:
// //
...@@ -351,12 +365,7 @@ void NGExclusionSpace::Add(scoped_refptr<const NGExclusion> exclusion) { ...@@ -351,12 +365,7 @@ void NGExclusionSpace::Add(scoped_refptr<const NGExclusion> exclusion) {
bool is_same_as_previous = bool is_same_as_previous =
(i > 0) && shelf.line_left == shelves_[i - 1].line_left && (i > 0) && shelf.line_left == shelves_[i - 1].line_left &&
shelf.line_right == shelves_[i - 1].line_right; shelf.line_right == shelves_[i - 1].line_right;
if (is_same_as_previous) {
// The shelf also may now be non-existent. Note that zero inline size is
// allowed, since subsequent zero-size content may still fit there.
bool shelf_disappearing = shelf.line_right < shelf.line_left;
if (is_same_as_previous || shelf_disappearing) {
shelves_.EraseAt(i); shelves_.EraseAt(i);
removed_shelf = true; removed_shelf = true;
} }
......
...@@ -97,16 +97,18 @@ TEST(NGExclusionSpaceTest, SingleExclusion) { ...@@ -97,16 +97,18 @@ TEST(NGExclusionSpaceTest, SingleExclusion) {
TEST_OPPORTUNITY(opportunites[2], NGBfcOffset(LayoutUnit(10), LayoutUnit(90)), TEST_OPPORTUNITY(opportunites[2], NGBfcOffset(LayoutUnit(10), LayoutUnit(90)),
NGBfcOffset(LayoutUnit(60), LayoutUnit::Max())); NGBfcOffset(LayoutUnit(60), LayoutUnit::Max()));
// This will only produce two opportunities, as the RHS opportunity will be // This will also produce three opportunities, as the RHS opportunity outside
// outside the search area. // the search area creates a zero-width opportunity.
opportunites = exclusion_space.AllLayoutOpportunities( opportunites = exclusion_space.AllLayoutOpportunities(
/* offset */ {LayoutUnit(10), LayoutUnit(10)}, /* offset */ {LayoutUnit(10), LayoutUnit(10)},
/* available_size */ LayoutUnit(49)); /* available_size */ LayoutUnit(49));
EXPECT_EQ(2u, opportunites.size()); EXPECT_EQ(3u, opportunites.size());
TEST_OPPORTUNITY(opportunites[0], NGBfcOffset(LayoutUnit(10), LayoutUnit(10)), TEST_OPPORTUNITY(opportunites[0], NGBfcOffset(LayoutUnit(10), LayoutUnit(10)),
NGBfcOffset(LayoutUnit(59), LayoutUnit(20))); NGBfcOffset(LayoutUnit(59), LayoutUnit(20)));
TEST_OPPORTUNITY(opportunites[1], NGBfcOffset(LayoutUnit(10), LayoutUnit(90)), TEST_OPPORTUNITY(opportunites[1], NGBfcOffset(LayoutUnit(60), LayoutUnit(10)),
NGBfcOffset(LayoutUnit(60), LayoutUnit::Max()));
TEST_OPPORTUNITY(opportunites[2], NGBfcOffset(LayoutUnit(10), LayoutUnit(90)),
NGBfcOffset(LayoutUnit(59), LayoutUnit::Max())); NGBfcOffset(LayoutUnit(59), LayoutUnit::Max()));
} }
...@@ -127,12 +129,14 @@ TEST(NGExclusionSpaceTest, TwoExclusions) { ...@@ -127,12 +129,14 @@ TEST(NGExclusionSpaceTest, TwoExclusions) {
/* offset */ {LayoutUnit(), LayoutUnit()}, /* offset */ {LayoutUnit(), LayoutUnit()},
/* available_size */ LayoutUnit(400)); /* available_size */ LayoutUnit(400));
EXPECT_EQ(3u, opportunites.size()); EXPECT_EQ(4u, opportunites.size());
TEST_OPPORTUNITY(opportunites[0], NGBfcOffset(LayoutUnit(150), LayoutUnit()), TEST_OPPORTUNITY(opportunites[0], NGBfcOffset(LayoutUnit(150), LayoutUnit()),
NGBfcOffset(LayoutUnit(400), LayoutUnit(75))); NGBfcOffset(LayoutUnit(400), LayoutUnit(75)));
TEST_OPPORTUNITY(opportunites[1], NGBfcOffset(LayoutUnit(), LayoutUnit(75)), TEST_OPPORTUNITY(opportunites[1], NGBfcOffset(LayoutUnit(150), LayoutUnit()),
NGBfcOffset(LayoutUnit(150), LayoutUnit::Max()));
TEST_OPPORTUNITY(opportunites[2], NGBfcOffset(LayoutUnit(), LayoutUnit(75)),
NGBfcOffset(LayoutUnit(100), LayoutUnit::Max())); NGBfcOffset(LayoutUnit(100), LayoutUnit::Max()));
TEST_OPPORTUNITY(opportunites[2], NGBfcOffset(LayoutUnit(), LayoutUnit(150)), TEST_OPPORTUNITY(opportunites[3], NGBfcOffset(LayoutUnit(), LayoutUnit(150)),
NGBfcOffset(LayoutUnit(400), LayoutUnit::Max())); NGBfcOffset(LayoutUnit(400), LayoutUnit::Max()));
} }
...@@ -286,5 +290,65 @@ TEST(NGExclusionSpaceTest, InsertBetweenShelves) { ...@@ -286,5 +290,65 @@ TEST(NGExclusionSpaceTest, InsertBetweenShelves) {
NGBfcOffset(LayoutUnit(60), LayoutUnit::Max())); NGBfcOffset(LayoutUnit(60), LayoutUnit::Max()));
} }
TEST(NGExclusionSpaceTest, ZeroInlineSizeOpportunity) {
NGExclusionSpace exclusion_space;
exclusion_space.Add(NGExclusion::Create(
NGBfcRect(NGBfcOffset(LayoutUnit(), LayoutUnit()),
NGBfcOffset(LayoutUnit(100), LayoutUnit(10))),
EFloat::kLeft));
Vector<NGLayoutOpportunity> opportunites =
exclusion_space.AllLayoutOpportunities(
/* offset */ {LayoutUnit(), LayoutUnit()},
/* available_size */ LayoutUnit(100));
EXPECT_EQ(2u, opportunites.size());
TEST_OPPORTUNITY(opportunites[0], NGBfcOffset(LayoutUnit(100), LayoutUnit()),
NGBfcOffset(LayoutUnit(100), LayoutUnit::Max()));
TEST_OPPORTUNITY(opportunites[1], NGBfcOffset(LayoutUnit(), LayoutUnit(10)),
NGBfcOffset(LayoutUnit(100), LayoutUnit::Max()));
}
TEST(NGExclusionSpaceTest, NegativeInlineSizeOpportunityLeft) {
NGExclusionSpace exclusion_space;
exclusion_space.Add(NGExclusion::Create(
NGBfcRect(NGBfcOffset(LayoutUnit(), LayoutUnit()),
NGBfcOffset(LayoutUnit(120), LayoutUnit(10))),
EFloat::kLeft));
Vector<NGLayoutOpportunity> opportunites =
exclusion_space.AllLayoutOpportunities(
/* offset */ {LayoutUnit(), LayoutUnit()},
/* available_size */ LayoutUnit(100));
EXPECT_EQ(2u, opportunites.size());
TEST_OPPORTUNITY(opportunites[0], NGBfcOffset(LayoutUnit(120), LayoutUnit()),
NGBfcOffset(LayoutUnit(120), LayoutUnit::Max()));
TEST_OPPORTUNITY(opportunites[1], NGBfcOffset(LayoutUnit(), LayoutUnit(10)),
NGBfcOffset(LayoutUnit(100), LayoutUnit::Max()));
}
TEST(NGExclusionSpaceTest, NegativeInlineSizeOpportunityRight) {
NGExclusionSpace exclusion_space;
exclusion_space.Add(NGExclusion::Create(
NGBfcRect(NGBfcOffset(LayoutUnit(-20), LayoutUnit()),
NGBfcOffset(LayoutUnit(100), LayoutUnit(10))),
EFloat::kRight));
Vector<NGLayoutOpportunity> opportunites =
exclusion_space.AllLayoutOpportunities(
/* offset */ {LayoutUnit(), LayoutUnit()},
/* available_size */ LayoutUnit(100));
EXPECT_EQ(2u, opportunites.size());
TEST_OPPORTUNITY(opportunites[0], NGBfcOffset(LayoutUnit(), LayoutUnit()),
NGBfcOffset(LayoutUnit(), LayoutUnit::Max()));
TEST_OPPORTUNITY(opportunites[1], NGBfcOffset(LayoutUnit(), LayoutUnit(10)),
NGBfcOffset(LayoutUnit(100), LayoutUnit::Max()));
}
} // namespace } // namespace
} // namespace blink } // namespace blink
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