Commit c78c300c authored by Ana SollanoKim's avatar Ana SollanoKim Committed by Commit Bot

[LayoutNG] Make fieldset legends monolithic

Previously, we had made the legends fragment in the following change
https://chromium-review.googlesource.com/c/chromium/src/+/2090762. In
this other change
https://chromium-review.googlesource.com/c/chromium/src/+/2263353
we decided to not break borders for now. Because the legend is part of
the fieldset border, we now want to treat the legend as monolithic.

We still have logic for breaking the fieldset border, this will be
addressed in a follow up change.

Bug: 1097012
Change-Id: Iace252447063eb694c47fb9eea2a406ba2fe79d7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2353354
Commit-Queue: Ana Sollano Kim <ansollan@microsoft.com>
Reviewed-by: default avatarAlison Maher <almaher@microsoft.com>
Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798528}
parent 1bf739db
...@@ -146,24 +146,19 @@ scoped_refptr<const NGLayoutResult> NGFieldsetLayoutAlgorithm::Layout() { ...@@ -146,24 +146,19 @@ scoped_refptr<const NGLayoutResult> NGFieldsetLayoutAlgorithm::Layout() {
} }
NGBreakStatus NGFieldsetLayoutAlgorithm::LayoutChildren() { NGBreakStatus NGFieldsetLayoutAlgorithm::LayoutChildren() {
scoped_refptr<const NGBlockBreakToken> legend_break_token;
scoped_refptr<const NGBlockBreakToken> content_break_token; scoped_refptr<const NGBlockBreakToken> content_break_token;
bool has_seen_all_children = false; bool has_seen_all_children = false;
if (const auto* token = BreakToken()) { if (const auto* token = BreakToken()) {
const auto child_tokens = token->ChildBreakTokens(); const auto child_tokens = token->ChildBreakTokens();
if (wtf_size_t break_token_count = child_tokens.size()) { if (wtf_size_t break_token_count = child_tokens.size()) {
DCHECK_LE(break_token_count, 2u); scoped_refptr<const NGBlockBreakToken> child_token =
for (wtf_size_t break_token_idx = 0; break_token_idx < break_token_count; To<NGBlockBreakToken>(child_tokens[0]);
break_token_idx++) { if (child_token) {
scoped_refptr<const NGBlockBreakToken> child_token = DCHECK(!child_token->InputNode().IsRenderedLegend());
To<NGBlockBreakToken>(child_tokens[break_token_idx]); content_break_token = child_token;
if (child_token && child_token->InputNode().IsRenderedLegend()) {
DCHECK_EQ(break_token_idx, 0u);
legend_break_token = child_token;
} else {
content_break_token = child_token;
}
} }
// There shouldn't be any additional break tokens.
DCHECK_EQ(child_tokens.size(), 1u);
} }
if (token->HasSeenAllChildren()) { if (token->HasSeenAllChildren()) {
container_builder_.SetHasSeenAllChildren(); container_builder_.SetHasSeenAllChildren();
...@@ -172,14 +167,8 @@ NGBreakStatus NGFieldsetLayoutAlgorithm::LayoutChildren() { ...@@ -172,14 +167,8 @@ NGBreakStatus NGFieldsetLayoutAlgorithm::LayoutChildren() {
} }
NGBlockNode legend = Node().GetRenderedLegend(); NGBlockNode legend = Node().GetRenderedLegend();
bool legend_needs_layout = if (legend && !IsResumingLayout(BreakToken())) {
legend && (legend_break_token || !IsResumingLayout(BreakToken())); LayoutLegend(legend);
if (legend_needs_layout) {
NGBreakStatus break_status = LayoutLegend(legend, legend_break_token);
if (break_status != NGBreakStatus::kContinue)
return break_status;
// The legend may eat from the available content box block size. Calculate // The legend may eat from the available content box block size. Calculate
// the minimum block size needed to encompass the legend. // the minimum block size needed to encompass the legend.
if (!Node().ShouldApplySizeContainment()) { if (!Node().ShouldApplySizeContainment()) {
...@@ -231,11 +220,6 @@ NGBreakStatus NGFieldsetLayoutAlgorithm::LayoutChildren() { ...@@ -231,11 +220,6 @@ NGBreakStatus NGFieldsetLayoutAlgorithm::LayoutChildren() {
// all live inside an anonymous child box of the fieldset container. // all live inside an anonymous child box of the fieldset container.
auto fieldset_content = Node().GetFieldsetContent(); auto fieldset_content = Node().GetFieldsetContent();
if (fieldset_content && (content_break_token || !has_seen_all_children)) { if (fieldset_content && (content_break_token || !has_seen_all_children)) {
if (ConstraintSpace().HasBlockFragmentation() && legend_broke_ &&
IsFragmentainerOutOfSpace(ConstraintSpace().FragmentainerOffsetAtBfc() +
intrinsic_block_size_))
return NGBreakStatus::kContinue;
NGBreakStatus break_status = NGBreakStatus break_status =
LayoutFieldsetContent(fieldset_content, content_break_token, LayoutFieldsetContent(fieldset_content, content_break_token,
adjusted_padding_box_size, !!legend); adjusted_padding_box_size, !!legend);
...@@ -253,9 +237,7 @@ NGBreakStatus NGFieldsetLayoutAlgorithm::LayoutChildren() { ...@@ -253,9 +237,7 @@ NGBreakStatus NGFieldsetLayoutAlgorithm::LayoutChildren() {
return NGBreakStatus::kContinue; return NGBreakStatus::kContinue;
} }
NGBreakStatus NGFieldsetLayoutAlgorithm::LayoutLegend( void NGFieldsetLayoutAlgorithm::LayoutLegend(NGBlockNode& legend) {
NGBlockNode& legend,
scoped_refptr<const NGBlockBreakToken> legend_break_token) {
// Lay out the legend. While the fieldset container normally ignores its // Lay out the legend. While the fieldset container normally ignores its
// padding, the legend is laid out within what would have been the content // padding, the legend is laid out within what would have been the content
// box had the fieldset been a regular block with no weirdness. // box had the fieldset been a regular block with no weirdness.
...@@ -265,101 +247,47 @@ NGBreakStatus NGFieldsetLayoutAlgorithm::LayoutLegend( ...@@ -265,101 +247,47 @@ NGBreakStatus NGFieldsetLayoutAlgorithm::LayoutLegend(
legend.Style(), percentage_size.inline_size, legend.Style(), percentage_size.inline_size,
ConstraintSpace().GetWritingMode(), ConstraintSpace().Direction()); ConstraintSpace().GetWritingMode(), ConstraintSpace().Direction());
if (legend_break_token)
legend_margins.block_start = LayoutUnit();
scoped_refptr<const NGLayoutResult> result;
scoped_refptr<const NGLayoutResult> previous_result;
LayoutUnit block_offset; LayoutUnit block_offset;
do { auto legend_space = CreateConstraintSpaceForLegend(
auto legend_space = CreateConstraintSpaceForLegend( legend, ChildAvailableSize(), percentage_size);
legend, ChildAvailableSize(), percentage_size, block_offset); scoped_refptr<const NGLayoutResult> result =
result = legend.Layout(legend_space, legend_break_token.get()); legend.Layout(legend_space, BreakToken());
// TODO(layout-dev): Handle abortions caused by block fragmentation.
DCHECK_EQ(result->Status(), NGLayoutResult::kSuccess);
if (ConstraintSpace().HasBlockFragmentation()) {
NGBreakStatus break_status = BreakBeforeChildIfNeeded(
ConstraintSpace(), legend, *result.get(),
ConstraintSpace().FragmentainerOffsetAtBfc() + block_offset,
/*has_container_separation*/ false, &container_builder_);
if (break_status != NGBreakStatus::kContinue)
return break_status;
EBreakBetween break_after = JoinFragmentainerBreakValues(
result->FinalBreakAfter(), legend.Style().BreakAfter());
container_builder_.SetPreviousBreakAfter(break_after);
}
const auto& physical_fragment = result->PhysicalFragment(); // TODO(layout-dev): Handle abortions caused by block fragmentation.
legend_broke_ = physical_fragment.BreakToken(); DCHECK_EQ(result->Status(), NGLayoutResult::kSuccess);
// We have already adjusted the legend block offset, no need to adjust
// again.
if (block_offset != LayoutUnit()) {
// If adjusting the block_offset caused the legend to break, revert back
// to the previous result.
if (legend_broke_) {
result = std::move(previous_result);
block_offset = LayoutUnit();
}
break;
}
LayoutUnit legend_border_box_block_size =
NGFragment(writing_mode_, physical_fragment).BlockSize();
LayoutUnit legend_margin_box_block_size =
legend_margins.block_start + legend_border_box_block_size;
LayoutUnit block_end_margin = legend_margins.block_end; const auto& physical_fragment = result->PhysicalFragment();
if (ConstraintSpace().HasKnownFragmentainerBlockSize()) {
block_end_margin = AdjustedMarginAfterFinalChildFragment( LayoutUnit legend_border_box_block_size =
ConstraintSpace(), legend_margin_box_block_size, block_end_margin); NGFragment(writing_mode_, physical_fragment).BlockSize();
} LayoutUnit legend_margin_box_block_size = legend_margins.block_start +
legend_margin_box_block_size += block_end_margin; legend_border_box_block_size +
legend_margins.block_end;
LayoutUnit space_left = borders_.block_start - legend_border_box_block_size;
if (space_left > LayoutUnit()) { LayoutUnit space_left = borders_.block_start - legend_border_box_block_size;
// Don't adjust the block-start offset of the legend if the legend broke. if (space_left > LayoutUnit()) {
if (legend_break_token || legend_broke_) // https://html.spec.whatwg.org/C/#the-fieldset-and-legend-elements
break; // * The element is expected to be positioned in the block-flow direction
// such that its border box is centered over the border on the
// https://html.spec.whatwg.org/C/#the-fieldset-and-legend-elements // block-start side of the fieldset element.
// * The element is expected to be positioned in the block-flow direction block_offset += space_left / 2;
// such that its border box is centered over the border on the }
// block-start side of the fieldset element. // If the border is smaller than the block end offset of the legend margin
block_offset += space_left / 2; // box, intrinsic_block_size_ should now be based on the the block end
if (ConstraintSpace().HasBlockFragmentation()) { // offset of the legend margin box instead of the border.
// Save the previous result in case adjusting the block_offset causes LayoutUnit legend_margin_end_offset =
// the legend to break. block_offset + legend_margin_box_block_size - legend_margins.block_start;
previous_result = std::move(result); if (legend_margin_end_offset > borders_.block_start) {
continue; intrinsic_block_size_ = legend_margin_end_offset;
}
} is_legend_past_border_ = true;
// If the border is smaller than the block end offset of the legend margin
// box, intrinsic_block_size_ should now be based on the the block end // If the legend is larger than the width of the fieldset block-start
// offset of the legend margin box instead of the border. // border, the actual padding edge of the fieldset will be moved
LayoutUnit legend_margin_end_offset = block_offset + // accordingly. This will be the block-start offset for the fieldset
legend_margin_box_block_size - // contents anonymous box.
legend_margins.block_start; borders_.block_start = legend_margin_end_offset;
if (legend_margin_end_offset > borders_.block_start) { }
intrinsic_block_size_ = legend_margin_end_offset;
is_legend_past_border_ = true;
// Don't adjust the block-start offset of the fragment border if it broke.
if (BreakToken() || (ConstraintSpace().HasKnownFragmentainerBlockSize() &&
legend_margin_end_offset >
ConstraintSpace().FragmentainerBlockSize()))
break;
// If the legend is larger than the width of the fieldset block-start
// border, the actual padding edge of the fieldset will be moved
// accordingly. This will be the block-start offset for the fieldset
// contents anonymous box.
borders_.block_start = legend_margin_end_offset;
}
break;
} while (true);
// If the margin box of the legend is at least as tall as the fieldset // If the margin box of the legend is at least as tall as the fieldset
// block-start border width, it will start at the block-start border edge // block-start border width, it will start at the block-start border edge
...@@ -375,7 +303,6 @@ NGBreakStatus NGFieldsetLayoutAlgorithm::LayoutLegend( ...@@ -375,7 +303,6 @@ NGBreakStatus NGFieldsetLayoutAlgorithm::LayoutLegend(
LogicalOffset legend_offset = {legend_inline_start, block_offset}; LogicalOffset legend_offset = {legend_inline_start, block_offset};
container_builder_.AddResult(*result, legend_offset); container_builder_.AddResult(*result, legend_offset);
return NGBreakStatus::kContinue;
} }
LayoutUnit NGFieldsetLayoutAlgorithm::ComputeLegendInlineOffset( LayoutUnit NGFieldsetLayoutAlgorithm::ComputeLegendInlineOffset(
...@@ -488,8 +415,7 @@ const NGConstraintSpace ...@@ -488,8 +415,7 @@ const NGConstraintSpace
NGFieldsetLayoutAlgorithm::CreateConstraintSpaceForLegend( NGFieldsetLayoutAlgorithm::CreateConstraintSpaceForLegend(
NGBlockNode legend, NGBlockNode legend,
LogicalSize available_size, LogicalSize available_size,
LogicalSize percentage_size, LogicalSize percentage_size) {
LayoutUnit block_offset) {
NGConstraintSpaceBuilder builder( NGConstraintSpaceBuilder builder(
ConstraintSpace(), legend.Style().GetWritingMode(), /* is_new_fc */ true); ConstraintSpace(), legend.Style().GetWritingMode(), /* is_new_fc */ true);
SetOrthogonalFallbackInlineSizeIfNeeded(Style(), legend, &builder); SetOrthogonalFallbackInlineSizeIfNeeded(Style(), legend, &builder);
...@@ -498,12 +424,6 @@ NGFieldsetLayoutAlgorithm::CreateConstraintSpaceForLegend( ...@@ -498,12 +424,6 @@ NGFieldsetLayoutAlgorithm::CreateConstraintSpaceForLegend(
builder.SetPercentageResolutionSize(percentage_size); builder.SetPercentageResolutionSize(percentage_size);
builder.SetIsShrinkToFit(legend.Style().LogicalWidth().IsAuto()); builder.SetIsShrinkToFit(legend.Style().LogicalWidth().IsAuto());
builder.SetTextDirection(legend.Style().Direction()); builder.SetTextDirection(legend.Style().Direction());
if (ConstraintSpace().HasBlockFragmentation()) {
SetupSpaceBuilderForFragmentation(ConstraintSpace(), legend, block_offset,
&builder, /* is_new_fc */ true);
builder.SetEarlyBreakAppeal(container_builder_.BreakAppeal());
}
return builder.ToConstraintSpace(); return builder.ToConstraintSpace();
} }
......
...@@ -37,9 +37,7 @@ class CORE_EXPORT NGFieldsetLayoutAlgorithm ...@@ -37,9 +37,7 @@ class CORE_EXPORT NGFieldsetLayoutAlgorithm
private: private:
NGBreakStatus LayoutChildren(); NGBreakStatus LayoutChildren();
NGBreakStatus LayoutLegend( void LayoutLegend(NGBlockNode& legend);
NGBlockNode& legend,
scoped_refptr<const NGBlockBreakToken> legend_break_token);
NGBreakStatus LayoutFieldsetContent( NGBreakStatus LayoutFieldsetContent(
NGBlockNode& fieldset_content, NGBlockNode& fieldset_content,
scoped_refptr<const NGBlockBreakToken> content_break_token, scoped_refptr<const NGBlockBreakToken> content_break_token,
...@@ -49,13 +47,11 @@ class CORE_EXPORT NGFieldsetLayoutAlgorithm ...@@ -49,13 +47,11 @@ class CORE_EXPORT NGFieldsetLayoutAlgorithm
const NGConstraintSpace CreateConstraintSpaceForLegend( const NGConstraintSpace CreateConstraintSpaceForLegend(
NGBlockNode legend, NGBlockNode legend,
LogicalSize available_size, LogicalSize available_size,
LogicalSize percentage_size, LogicalSize percentage_size);
LayoutUnit block_offset);
const NGConstraintSpace CreateConstraintSpaceForFieldsetContent( const NGConstraintSpace CreateConstraintSpaceForFieldsetContent(
NGBlockNode fieldset_content, NGBlockNode fieldset_content,
LogicalSize padding_box_size, LogicalSize padding_box_size,
LayoutUnit block_offset); LayoutUnit block_offset);
bool IsFragmentainerOutOfSpace(LayoutUnit block_offset) const; bool IsFragmentainerOutOfSpace(LayoutUnit block_offset) const;
const WritingMode writing_mode_; const WritingMode writing_mode_;
...@@ -76,10 +72,6 @@ class CORE_EXPORT NGFieldsetLayoutAlgorithm ...@@ -76,10 +72,6 @@ class CORE_EXPORT NGFieldsetLayoutAlgorithm
// fragments. // fragments.
LayoutUnit consumed_border_block_start_; LayoutUnit consumed_border_block_start_;
// If true, this indicates that the legend broke during the current layout
// pass.
bool legend_broke_ = false;
// If true, the legend is taller than the block-start border, so that it // If true, the legend is taller than the block-start border, so that it
// sticks below it, allowing for a class C breakpoint [1] before any fieldset // sticks below it, allowing for a class C breakpoint [1] before any fieldset
// content. // content.
......
...@@ -781,8 +781,8 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, FieldsetContentFragmentation) { ...@@ -781,8 +781,8 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, FieldsetContentFragmentation) {
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
} }
// Tests that a fieldset with auto height will fragment when its legend reaches // Tests that a fieldset with auto height will not fragment when its legend
// the fragmentation line. // reaches the fragmentation line.
TEST_F(NGFieldsetLayoutAlgorithmTest, LegendFragmentationAutoHeight) { TEST_F(NGFieldsetLayoutAlgorithmTest, LegendFragmentationAutoHeight) {
SetBodyInnerHTML(R"HTML( SetBodyInnerHTML(R"HTML(
<style> <style>
...@@ -811,20 +811,12 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendFragmentationAutoHeight) { ...@@ -811,20 +811,12 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendFragmentationAutoHeight) {
ASSERT_TRUE(fragment->BreakToken()); ASSERT_TRUE(fragment->BreakToken());
String dump = DumpFragmentTree(fragment.get()); String dump = DumpFragmentTree(fragment.get());
// TODO(crbug.com/1097012): The height of the outermost fragment here should
// be 500, not 490, but the fragmentation machinery gets confused by the
// fieldset padding.
String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::. String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:176x200 offset:unplaced size:176x490
offset:13,0 size:50x200 offset:13,0 size:50x500
)DUMP";
EXPECT_EQ(expectation, dump);
fragment = NGBaseLayoutAlgorithmTest::RunFieldsetLayoutAlgorithm(
node, space, fragment->BreakToken());
ASSERT_TRUE(fragment->BreakToken());
dump = DumpFragmentTree(fragment.get());
expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:176x200
offset:13,0 size:50x200
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
...@@ -834,14 +826,13 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendFragmentationAutoHeight) { ...@@ -834,14 +826,13 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendFragmentationAutoHeight) {
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:176x123 offset:unplaced size:176x23
offset:13,0 size:50x100 offset:3,0 size:170x20
offset:3,100 size:170x20
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
} }
// Tests that a fieldset with a set height will fragment when its legend // Tests that a fieldset with a set height will not fragment when its legend
// reaches the fragmentation line. The used height should also be extended to // reaches the fragmentation line. The used height should also be extended to
// encompass the legend. // encompass the legend.
TEST_F(NGFieldsetLayoutAlgorithmTest, LegendFragmentation) { TEST_F(NGFieldsetLayoutAlgorithmTest, LegendFragmentation) {
...@@ -872,20 +863,12 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendFragmentation) { ...@@ -872,20 +863,12 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendFragmentation) {
ASSERT_TRUE(fragment->BreakToken()); ASSERT_TRUE(fragment->BreakToken());
String dump = DumpFragmentTree(fragment.get()); String dump = DumpFragmentTree(fragment.get());
// TODO(crbug.com/1097012): The height of the outermost fragment here should
// be 500, not 490, but the fragmentation machinery gets confused by the
// fieldset padding.
String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::. String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:176x200 offset:unplaced size:176x490
offset:13,0 size:50x200 offset:13,0 size:50x500
)DUMP";
EXPECT_EQ(expectation, dump);
fragment = NGBaseLayoutAlgorithmTest::RunFieldsetLayoutAlgorithm(
node, space, fragment->BreakToken());
ASSERT_TRUE(fragment->BreakToken());
dump = DumpFragmentTree(fragment.get());
expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:176x200
offset:13,0 size:50x200
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
...@@ -894,16 +877,19 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendFragmentation) { ...@@ -894,16 +877,19 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendFragmentation) {
ASSERT_FALSE(fragment->BreakToken()); ASSERT_FALSE(fragment->BreakToken());
dump = DumpFragmentTree(fragment.get()); dump = DumpFragmentTree(fragment.get());
// TODO(crbug.com/1097012): The height of the outermost fragment here should
// be 23, not 0, but the fragmentation machinery gets confused by the
// fieldset padding.
expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::. expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:176x123 offset:unplaced size:176x0
offset:13,0 size:50x100 offset:3,0 size:170x20
offset:3,100 size:170x20
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
} }
// Tests that a fieldset with auto height will fragment when its legend/content // Tests that a fieldset with auto height will not fragment when its legend
// reaches the fragmentation line. // reaches the fragmentation line. The content of the fieldset should fragment
// when it reaches the fragmentation line.
TEST_F(NGFieldsetLayoutAlgorithmTest, LegendAndContentFragmentationAutoHeight) { TEST_F(NGFieldsetLayoutAlgorithmTest, LegendAndContentFragmentationAutoHeight) {
SetBodyInnerHTML(R"HTML( SetBodyInnerHTML(R"HTML(
<style> <style>
...@@ -936,36 +922,26 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendAndContentFragmentationAutoHeight) { ...@@ -936,36 +922,26 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendAndContentFragmentationAutoHeight) {
ASSERT_TRUE(fragment->BreakToken()); ASSERT_TRUE(fragment->BreakToken());
String dump = DumpFragmentTree(fragment.get()); String dump = DumpFragmentTree(fragment.get());
// TODO(crbug.com/1097012): The height of the outermost fragment here should
// be 500, not 490, but the fragmentation machinery gets confused by the
// fieldset padding.
String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::. String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:176x200 offset:unplaced size:176x490
offset:13,0 size:50x200 offset:13,0 size:50x500
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
fragment = NGBaseLayoutAlgorithmTest::RunFieldsetLayoutAlgorithm( fragment = NGBaseLayoutAlgorithmTest::RunFieldsetLayoutAlgorithm(
node, space, fragment->BreakToken()); node, space, fragment->BreakToken());
ASSERT_TRUE(fragment->BreakToken()); ASSERT_TRUE(fragment->BreakToken());
dump = DumpFragmentTree(fragment.get());
expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:176x200
offset:13,0 size:50x200
)DUMP";
EXPECT_EQ(expectation, dump);
fragment = NGBaseLayoutAlgorithmTest::RunFieldsetLayoutAlgorithm(
node, space, fragment->BreakToken());
ASSERT_TRUE(fragment->BreakToken());
dump = DumpFragmentTree(fragment.get());
// TODO(crbug.com/1097012): The height of the outermost fragment here should // TODO(crbug.com/1097012): The height of the outermost fragment here should
// be 200, not 190, but the fragmentation machinery gets confused by the // be 200, not 190, but the fragmentation machinery gets confused by the
// fieldset padding. // fieldset padding.
dump = DumpFragmentTree(fragment.get());
expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::. expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:176x190 offset:unplaced size:176x190
offset:13,0 size:50x100 offset:3,0 size:170x200
offset:3,100 size:170x100 offset:10,10 size:100x190
offset:10,10 size:100x90
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
...@@ -975,14 +951,15 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendAndContentFragmentationAutoHeight) { ...@@ -975,14 +951,15 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendAndContentFragmentationAutoHeight) {
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:176x123 offset:unplaced size:176x23
offset:3,0 size:170x120 offset:3,0 size:170x20
offset:10,0 size:100x110 offset:10,0 size:100x10
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
} }
// Tests that a fieldset with a set height will fragment when its legend/content // Tests that a fieldset with a set height will fragment when its legend reaches
// the fragmentation line. The content of the fieldset should fragment when it
// reaches the fragmentation line. // reaches the fragmentation line.
TEST_F(NGFieldsetLayoutAlgorithmTest, LegendAndContentFragmentation) { TEST_F(NGFieldsetLayoutAlgorithmTest, LegendAndContentFragmentation) {
SetBodyInnerHTML(R"HTML( SetBodyInnerHTML(R"HTML(
...@@ -1016,45 +993,34 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendAndContentFragmentation) { ...@@ -1016,45 +993,34 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendAndContentFragmentation) {
ASSERT_TRUE(fragment->BreakToken()); ASSERT_TRUE(fragment->BreakToken());
String dump = DumpFragmentTree(fragment.get()); String dump = DumpFragmentTree(fragment.get());
// TODO(crbug.com/1097012): The height of the outermost fragment here should
// be 500, not 490, but the fragmentation machinery gets confused by the
// fieldset padding.
String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::. String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:176x200 offset:unplaced size:176x490
offset:13,0 size:50x200 offset:13,0 size:50x500
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
fragment = NGBaseLayoutAlgorithmTest::RunFieldsetLayoutAlgorithm( fragment = NGBaseLayoutAlgorithmTest::RunFieldsetLayoutAlgorithm(
node, space, fragment->BreakToken()); node, space, fragment->BreakToken());
ASSERT_TRUE(fragment->BreakToken()); ASSERT_TRUE(fragment->BreakToken());
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:176x200 offset:unplaced size:176x0
offset:13,0 size:50x200 offset:3,0 size:170x20
)DUMP"; offset:10,10 size:100x190
EXPECT_EQ(expectation, dump);
fragment = NGBaseLayoutAlgorithmTest::RunFieldsetLayoutAlgorithm(
node, space, fragment->BreakToken());
ASSERT_TRUE(fragment->BreakToken());
dump = DumpFragmentTree(fragment.get());
expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:176x123
offset:13,0 size:50x100
offset:3,100 size:170x20
offset:10,10 size:100x90
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
fragment = NGBaseLayoutAlgorithmTest::RunFieldsetLayoutAlgorithm( fragment = NGBaseLayoutAlgorithmTest::RunFieldsetLayoutAlgorithm(
node, space, fragment->BreakToken()); node, space, fragment->BreakToken());
ASSERT_FALSE(fragment->BreakToken()); ASSERT_FALSE(fragment->BreakToken());
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:176x0 offset:unplaced size:176x0
offset:3,0 size:170x0 offset:3,0 size:170x0
offset:10,0 size:100x110 offset:10,0 size:100x10
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
} }
...@@ -1070,7 +1036,7 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendFragmentationWithOverflow) { ...@@ -1070,7 +1036,7 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendFragmentationWithOverflow) {
<div style="width:55px; height:150px;"></div> <div style="width:55px; height:150px;"></div>
</legend> </legend>
<div style="width:44px; height:150px;"></div> <div style="width:44px; height:150px;"></div>
</div> </fieldset>
)HTML"); )HTML");
LayoutUnit kFragmentainerSpaceAvailable(100); LayoutUnit kFragmentainerSpaceAvailable(100);
...@@ -1089,7 +1055,7 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendFragmentationWithOverflow) { ...@@ -1089,7 +1055,7 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendFragmentationWithOverflow) {
String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::. String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:1000x100 offset:unplaced size:1000x100
offset:0,0 size:55x30 offset:0,0 size:55x30
offset:0,0 size:55x100 offset:0,0 size:55x150
offset:0,30 size:1000x70 offset:0,30 size:1000x70
offset:0,0 size:44x70 offset:0,0 size:44x70
)DUMP"; )DUMP";
...@@ -1102,8 +1068,6 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendFragmentationWithOverflow) { ...@@ -1102,8 +1068,6 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendFragmentationWithOverflow) {
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:1000x80 offset:unplaced size:1000x80
offset:0,0 size:55x0
offset:0,0 size:55x50
offset:0,0 size:1000x80 offset:0,0 size:1000x80
offset:0,0 size:44x80 offset:0,0 size:44x80
)DUMP"; )DUMP";
...@@ -1195,28 +1159,16 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, OverflowedLegend) { ...@@ -1195,28 +1159,16 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, OverflowedLegend) {
scoped_refptr<const NGPhysicalBoxFragment> fragment = scoped_refptr<const NGPhysicalBoxFragment> fragment =
NGBaseLayoutAlgorithmTest::RunFieldsetLayoutAlgorithm(node, space); NGBaseLayoutAlgorithmTest::RunFieldsetLayoutAlgorithm(node, space);
ASSERT_TRUE(fragment->BreakToken()); ASSERT_FALSE(fragment->BreakToken());
String dump = DumpFragmentTree(fragment.get()); String dump = DumpFragmentTree(fragment.get());
String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::. String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:100x100 offset:unplaced size:100x100
offset:0,0 size:75x60 offset:0,0 size:75x60
offset:0,0 size:50x100 offset:0,0 size:50x120
offset:0,120 size:40x20
offset:0,60 size:100x40 offset:0,60 size:100x40
offset:0,0 size:85x10 offset:0,0 size:85x10
)DUMP";
EXPECT_EQ(expectation, dump);
fragment = NGBaseLayoutAlgorithmTest::RunFieldsetLayoutAlgorithm(
node, space, fragment->BreakToken());
ASSERT_FALSE(fragment->BreakToken());
dump = DumpFragmentTree(fragment.get());
expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:100x0
offset:0,0 size:75x0
offset:0,0 size:50x20
offset:0,20 size:40x20
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
} }
...@@ -1258,7 +1210,7 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, OverflowedFieldsetContent) { ...@@ -1258,7 +1210,7 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, OverflowedFieldsetContent) {
String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::. String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:100x100 offset:unplaced size:100x100
offset:0,0 size:75x10 offset:0,0 size:75x10
offset:0,0 size:50x100 offset:0,0 size:50x220
offset:0,10 size:100x90 offset:0,10 size:100x90
offset:0,0 size:85x10 offset:0,0 size:85x10
offset:0,10 size:65x10 offset:0,10 size:65x10
...@@ -1273,8 +1225,6 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, OverflowedFieldsetContent) { ...@@ -1273,8 +1225,6 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, OverflowedFieldsetContent) {
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:100x0 offset:unplaced size:100x0
offset:0,0 size:75x0
offset:0,0 size:50x100
offset:0,0 size:100x0 offset:0,0 size:100x0
offset:0,0 size:65x0 offset:0,0 size:65x0
offset:0,0 size:51x100 offset:0,0 size:51x100
...@@ -1288,8 +1238,6 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, OverflowedFieldsetContent) { ...@@ -1288,8 +1238,6 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, OverflowedFieldsetContent) {
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:100x0 offset:unplaced size:100x0
offset:0,0 size:75x0
offset:0,0 size:50x20
offset:0,0 size:100x0 offset:0,0 size:100x0
offset:0,0 size:65x0 offset:0,0 size:65x0
offset:0,0 size:51x40 offset:0,0 size:51x40
...@@ -1442,8 +1390,10 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendBreakInsideAvoid) { ...@@ -1442,8 +1390,10 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendBreakInsideAvoid) {
String dump = DumpFragmentTree(fragment.get()); String dump = DumpFragmentTree(fragment.get());
String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::. String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:1000x100 offset:unplaced size:1000x110
offset:0,0 size:20x50 offset:0,0 size:20x50
offset:0,50 size:100x60
offset:0,0 size:10x60
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
...@@ -1453,10 +1403,9 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendBreakInsideAvoid) { ...@@ -1453,10 +1403,9 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendBreakInsideAvoid) {
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:1000x60 offset:unplaced size:1000x0
offset:0,0 size:100x60 offset:0,0 size:100x0
offset:0,0 size:10x60 offset:0,0 size:100x0
offset:0,60 size:100x0
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
} }
...@@ -1530,7 +1479,7 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendBreakBeforeAvoid) { ...@@ -1530,7 +1479,7 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendBreakBeforeAvoid) {
<div id="container"> <div id="container">
<div style="width:20px; height:90px;"></div> <div style="width:20px; height:90px;"></div>
<fieldset id="fieldset"> <fieldset id="fieldset">
<legend id="legend" style="break-before:avoid; break-inside:avoid"></legend> <legend id="legend" style="break-before:avoid;"></legend>
</fieldset> </fieldset>
</div> </div>
)HTML"); )HTML");
...@@ -1549,8 +1498,10 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendBreakBeforeAvoid) { ...@@ -1549,8 +1498,10 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendBreakBeforeAvoid) {
String dump = DumpFragmentTree(fragment.get()); String dump = DumpFragmentTree(fragment.get());
String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::. String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:1000x100 offset:unplaced size:1000x125
offset:0,0 size:20x90 offset:0,0 size:20x90
offset:0,90 size:120x35
offset:20,0 size:10x25
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
...@@ -1560,10 +1511,9 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendBreakBeforeAvoid) { ...@@ -1560,10 +1511,9 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendBreakBeforeAvoid) {
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:1000x45 offset:unplaced size:1000x10
offset:0,0 size:120x45 offset:0,0 size:120x10
offset:20,0 size:10x25 offset:10,0 size:100x0
offset:10,35 size:100x0
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
} }
...@@ -1659,6 +1609,8 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendBreakAfterAvoid) { ...@@ -1659,6 +1609,8 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendBreakAfterAvoid) {
String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::. String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:1000x100 offset:unplaced size:1000x100
offset:0,0 size:20x50 offset:0,0 size:20x50
offset:0,50 size:100x50
offset:0,0 size:10x50
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
...@@ -1668,10 +1620,9 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendBreakAfterAvoid) { ...@@ -1668,10 +1620,9 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, LegendBreakAfterAvoid) {
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:1000x75 offset:unplaced size:1000x25
offset:0,0 size:100x75 offset:0,0 size:100x25
offset:0,0 size:10x50 offset:0,0 size:100x25
offset:0,50 size:100x25
offset:0,0 size:15x25 offset:0,0 size:15x25
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
...@@ -1710,8 +1661,11 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, MarginBottomPastEndOfFragmentainer) { ...@@ -1710,8 +1661,11 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, MarginBottomPastEndOfFragmentainer) {
ASSERT_TRUE(fragment->BreakToken()); ASSERT_TRUE(fragment->BreakToken());
String dump = DumpFragmentTree(fragment.get()); String dump = DumpFragmentTree(fragment.get());
// TODO(crbug.com/1097012): The height of the outermost fragment here should
// be 100, not 110, but the fragmentation machinery gets confused
// and includes the margin bottom.
String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::. String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:100x100 offset:unplaced size:100x110
offset:0,0 size:0x90 offset:0,0 size:0x90
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
...@@ -1763,7 +1717,7 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, SmallLegendLargeBorderFragmentation) { ...@@ -1763,7 +1717,7 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, SmallLegendLargeBorderFragmentation) {
String dump = DumpFragmentTree(fragment.get()); String dump = DumpFragmentTree(fragment.get());
String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::. String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:220x60 offset:unplaced size:220x60
offset:60,0 size:10x40 offset:60,5 size:10x50
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
...@@ -1774,7 +1728,6 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, SmallLegendLargeBorderFragmentation) { ...@@ -1774,7 +1728,6 @@ TEST_F(NGFieldsetLayoutAlgorithmTest, SmallLegendLargeBorderFragmentation) {
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:220x10 offset:unplaced size:220x10
offset:60,0 size:10x10
offset:60,0 size:100x10 offset:60,0 size:100x10
)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