Commit 215b0cd8 authored by Alison Maher's avatar Alison Maher Committed by Commit Bot

[LayoutNG] Fieldset border block-start

This change ensures that the intrinsic_block_size_ for fieldsets
includes the amount of the border block-start that has not already
been consumed in previous fragments, rather than simply setting
this to 0 when the fieldset breaks.

This change also alters the design for large legends/small borders.
Instead of adjusting the fieldset border block-start offset when
the legend doesn't break, this change updates the design so that
we adjust the offset when the border block-start doesn't break.

Doing so ensures that we know the size of the border consumed in
previous fragments without having to store its offset for later
fragments to reference.

Bug: 875235
Change-Id: If29c0166453c95c43d9cc08197095b2221e1b309
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2137525Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Commit-Queue: Alison Maher <almaher@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#757154}
parent 9e807eee
...@@ -43,9 +43,6 @@ NGFieldsetLayoutAlgorithm::NGFieldsetLayoutAlgorithm( ...@@ -43,9 +43,6 @@ NGFieldsetLayoutAlgorithm::NGFieldsetLayoutAlgorithm(
} }
scoped_refptr<const NGLayoutResult> NGFieldsetLayoutAlgorithm::Layout() { scoped_refptr<const NGLayoutResult> NGFieldsetLayoutAlgorithm::Layout() {
// TODO(almaher): Make sure the border start is handled correctly during
// fragmentation.
// Layout of a fieldset container consists of two parts: Create a child // Layout of a fieldset container consists of two parts: Create a child
// fragment for the rendered legend (if any), and create a child fragment for // fragment for the rendered legend (if any), and create a child fragment for
// the fieldset contents anonymous box (if any). Fieldset scrollbars and // the fieldset contents anonymous box (if any). Fieldset scrollbars and
...@@ -68,11 +65,11 @@ scoped_refptr<const NGLayoutResult> NGFieldsetLayoutAlgorithm::Layout() { ...@@ -68,11 +65,11 @@ scoped_refptr<const NGLayoutResult> NGFieldsetLayoutAlgorithm::Layout() {
container_builder_.SetIsInitialColumnBalancingPass(); container_builder_.SetIsInitialColumnBalancingPass();
} }
// TODO(almaher): Instead of setting this to 0 when resuming layout, this // Calculate the amount of the border block-start that was consumed in
// should equal the amount of the border block-start that is remaining from // previous fragments.
// the previous fragment(s). consumed_border_block_start_ =
if (!IsResumingLayout(BreakToken())) std::min(consumed_block_size_, borders_.block_start);
intrinsic_block_size_ = borders_.block_start; intrinsic_block_size_ = borders_.block_start - consumed_border_block_start_;
NGBreakStatus break_status = LayoutChildren(); NGBreakStatus break_status = LayoutChildren();
if (break_status == NGBreakStatus::kNeedsEarlierBreak) { if (break_status == NGBreakStatus::kNeedsEarlierBreak) {
...@@ -174,10 +171,11 @@ NGBreakStatus NGFieldsetLayoutAlgorithm::LayoutChildren() { ...@@ -174,10 +171,11 @@ NGBreakStatus NGFieldsetLayoutAlgorithm::LayoutChildren() {
ShrinkAvailableSize(border_box_size_, borders_with_legend); ShrinkAvailableSize(border_box_size_, borders_with_legend);
if (adjusted_padding_box_size.block_size != kIndefiniteSize) { if (adjusted_padding_box_size.block_size != kIndefiniteSize) {
// If intrinsic_block_size_ does not include the border block-start, exclude // If intrinsic_block_size_ does not include the border block-start that was
// it from adjusted_padding_box_size, as well. // consumed in previous fragments, exclude consumed_border_block_start_ from
if (intrinsic_block_size_ == LayoutUnit()) // adjusted_padding_box_size, as well.
adjusted_padding_box_size.block_size -= borders_.block_start; if (consumed_border_block_start_ > LayoutUnit())
adjusted_padding_box_size.block_size -= consumed_border_block_start_;
// If the legend has been laid out in previous fragments, // If the legend has been laid out in previous fragments,
// adjusted_padding_box_size will need to be adjusted further to account for // adjusted_padding_box_size will need to be adjusted further to account for
...@@ -281,17 +279,11 @@ NGBreakStatus NGFieldsetLayoutAlgorithm::LayoutLegend( ...@@ -281,17 +279,11 @@ NGBreakStatus NGFieldsetLayoutAlgorithm::LayoutLegend(
legend_margins.BlockSum(); legend_margins.BlockSum();
LayoutUnit space_left = borders_.block_start - legend_margin_box_block_size; LayoutUnit space_left = borders_.block_start - legend_margin_box_block_size;
// If the border is smaller, intrinsic_block_size_ should now be based on
// the size of the legend instead of the border.
if (space_left <= LayoutUnit())
intrinsic_block_size_ = legend_margin_box_block_size;
// Don't adjust the block-start offset of the legend or fragment border if
// the legend broke.
if (legend_break_token || legend_broke_)
break;
if (space_left > LayoutUnit()) { if (space_left > LayoutUnit()) {
// Don't adjust the block-start offset of the legend if the legend broke.
if (legend_break_token || legend_broke_)
break;
// If the border is the larger one, though, it will stay put at the // If the border is the larger one, though, it will stay put at the
// border-box block-start edge of the fieldset. Then it's the legend // border-box block-start edge of the fieldset. Then it's the legend
// that needs to be pushed. We'll center the margin box in this case, to // that needs to be pushed. We'll center the margin box in this case, to
...@@ -305,6 +297,15 @@ NGBreakStatus NGFieldsetLayoutAlgorithm::LayoutLegend( ...@@ -305,6 +297,15 @@ NGBreakStatus NGFieldsetLayoutAlgorithm::LayoutLegend(
continue; continue;
} }
} else { } else {
// If the border is smaller, intrinsic_block_size_ should now be based on
// the size of the legend instead of the border.
intrinsic_block_size_ = legend_margin_box_block_size;
// Don't adjust the block-start offset of the fragment border if it broke.
if (BreakToken() || (ConstraintSpace().HasKnownFragmentainerBlockSize() &&
legend_margin_box_block_size >
ConstraintSpace().FragmentainerBlockSize()))
break;
// If the legend is larger than the width of the fieldset block-start // If the legend is larger than the width of the fieldset block-start
// border, the actual padding edge of the fieldset will be moved // border, the actual padding edge of the fieldset will be moved
// accordingly. This will be the block-start offset for the fieldset // accordingly. This will be the block-start offset for the fieldset
......
...@@ -70,6 +70,10 @@ class CORE_EXPORT NGFieldsetLayoutAlgorithm ...@@ -70,6 +70,10 @@ class CORE_EXPORT NGFieldsetLayoutAlgorithm
// the legend. // the legend.
LayoutUnit minimum_border_box_block_size_; LayoutUnit minimum_border_box_block_size_;
// The amount of the border block-start that was consumed in previous
// fragments.
LayoutUnit consumed_border_block_start_;
// If true, this indicates that the legend broke during the current layout // If true, this indicates that the legend broke during the current layout
// pass. // pass.
bool legend_broke_ = false; bool legend_broke_ = false;
......
...@@ -1811,12 +1811,11 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, SmallLegendLargeBorderFragmentation) { ...@@ -1811,12 +1811,11 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, SmallLegendLargeBorderFragmentation) {
node, space, fragment->BreakToken()); node, space, fragment->BreakToken());
ASSERT_TRUE(fragment->BreakToken()); ASSERT_TRUE(fragment->BreakToken());
// TODO(almaher): The fieldset content should start at offset 60,20.
dump = DumpFragmentTree(fragment.get()); dump = DumpFragmentTree(fragment.get());
expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::. expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:220x40 offset:unplaced size:220x40
offset:60,0 size:10x10 offset:60,0 size:10x10
offset:60,0 size:100x0 offset:60,20 size:100x0
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
...@@ -1879,11 +1878,10 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, SmallerLegendLargeBorderFragmentation) { ...@@ -1879,11 +1878,10 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, SmallerLegendLargeBorderFragmentation) {
node, space, fragment->BreakToken()); node, space, fragment->BreakToken());
ASSERT_TRUE(fragment->BreakToken()); ASSERT_TRUE(fragment->BreakToken());
// TODO(almaher): The fieldset content should start at offset 60,20.
dump = DumpFragmentTree(fragment.get()); dump = DumpFragmentTree(fragment.get());
expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::. expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:220x40 offset:unplaced size:220x40
offset:60,0 size:100x0 offset:60,20 size:100x0
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
...@@ -1946,11 +1944,10 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, SmallerLegendLargeBorderWithBreak) { ...@@ -1946,11 +1944,10 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, SmallerLegendLargeBorderWithBreak) {
node, space, fragment->BreakToken()); node, space, fragment->BreakToken());
ASSERT_TRUE(fragment->BreakToken()); ASSERT_TRUE(fragment->BreakToken());
// TODO(almaher): The fieldset content should start at offset 60,20.
dump = DumpFragmentTree(fragment.get()); dump = DumpFragmentTree(fragment.get());
expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::. expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:220x40 offset:unplaced size:220x40
offset:60,0 size:100x0 offset:60,20 size:100x0
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
......
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