diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-07-31 15:50:41 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-08-30 12:35:23 +0000 |
commit | 7b2ffa587235a47d4094787d72f38102089f402a (patch) | |
tree | 30e82af9cbab08a7fa028bb18f4f2987a3f74dfa /chromium/third_party/blink/renderer/core/layout/ng/ng_block_layout_algorithm_test.cc | |
parent | d94af01c90575348c4e81a418257f254b6f8d225 (diff) | |
download | qtwebengine-chromium-7b2ffa587235a47d4094787d72f38102089f402a.tar.gz |
BASELINE: Update Chromium to 76.0.3809.94
Change-Id: I321c3f5f929c105aec0f98c5091ef6108822e647
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/third_party/blink/renderer/core/layout/ng/ng_block_layout_algorithm_test.cc')
-rw-r--r-- | chromium/third_party/blink/renderer/core/layout/ng/ng_block_layout_algorithm_test.cc | 579 |
1 files changed, 281 insertions, 298 deletions
diff --git a/chromium/third_party/blink/renderer/core/layout/ng/ng_block_layout_algorithm_test.cc b/chromium/third_party/blink/renderer/core/layout/ng/ng_block_layout_algorithm_test.cc index 94559f82244..986c3484c6f 100644 --- a/chromium/third_party/blink/renderer/core/layout/ng/ng_block_layout_algorithm_test.cc +++ b/chromium/third_party/blink/renderer/core/layout/ng/ng_block_layout_algorithm_test.cc @@ -33,23 +33,16 @@ class NGBlockLayoutAlgorithmTest : public NGBaseLayoutAlgorithmTest { NGBaseLayoutAlgorithmTest::SetUp(); } - scoped_refptr<const NGPhysicalBoxFragment> RunBlockLayoutAlgorithm( - const NGConstraintSpace& space, - NGBlockNode node) { - scoped_refptr<const NGLayoutResult> result = - NGBlockLayoutAlgorithm(node, space).Layout(); - - return To<NGPhysicalBoxFragment>(result->PhysicalFragment()); - } - MinMaxSize RunComputeMinAndMax(NGBlockNode node) { // The constraint space is not used for min/max computation, but we need // it to create the algorithm. NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(), LayoutUnit())); + LogicalSize(LayoutUnit(), LayoutUnit())); + NGFragmentGeometry fragment_geometry = + CalculateInitialMinMaxFragmentGeometry(space, node); - NGBlockLayoutAlgorithm algorithm(node, space); + NGBlockLayoutAlgorithm algorithm({node, fragment_geometry, space}); MinMaxSizeInput input( /* percentage_resolution_block_size */ (LayoutUnit())); auto min_max = algorithm.ComputeMinMaxSize(input); @@ -57,6 +50,16 @@ class NGBlockLayoutAlgorithmTest : public NGBaseLayoutAlgorithmTest { return *min_max; } + scoped_refptr<const NGLayoutResult> RunCachedLayoutResult( + const NGConstraintSpace& space, + const NGBlockNode& node) { + NGLayoutCacheStatus cache_status; + base::Optional<NGFragmentGeometry> initial_fragment_geometry; + return To<LayoutBlockFlow>(node.GetLayoutBox()) + ->CachedLayoutResult(space, nullptr, &initial_fragment_geometry, + &cache_status); + } + String DumpFragmentTree(const NGPhysicalBoxFragment* fragment) { NGPhysicalFragment::DumpFlags flags = NGPhysicalFragment::DumpHeaderText | NGPhysicalFragment::DumpSubtree | @@ -83,14 +86,14 @@ TEST_F(NGBlockLayoutAlgorithmTest, FixedSize) { NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); + LogicalSize(LayoutUnit(100), kIndefiniteSize)); NGBlockNode box(ToLayoutBox(GetLayoutObjectByElementId("box"))); - scoped_refptr<const NGPhysicalFragment> frag = - RunBlockLayoutAlgorithm(space, box); + scoped_refptr<const NGPhysicalBoxFragment> fragment = + RunBlockLayoutAlgorithm(box, space); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(30), LayoutUnit(40)), frag->Size()); + EXPECT_EQ(PhysicalSize(30, 40), fragment->Size()); } TEST_F(NGBlockLayoutAlgorithmTest, Caching) { @@ -102,44 +105,43 @@ TEST_F(NGBlockLayoutAlgorithmTest, Caching) { NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(100), LayoutUnit(100))); + LogicalSize(LayoutUnit(100), LayoutUnit(100))); auto* block_flow = To<LayoutBlockFlow>(GetLayoutObjectByElementId("box")); NGBlockNode node(block_flow); scoped_refptr<const NGLayoutResult> result(node.Layout(space, nullptr)); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(30), LayoutUnit(40)), - result->PhysicalFragment()->Size()); + EXPECT_EQ(PhysicalSize(30, 40), result->PhysicalFragment().Size()); // Test pointer-equal constraint space. - result = block_flow->CachedLayoutResult(space, nullptr); + result = RunCachedLayoutResult(space, node); EXPECT_NE(result.get(), nullptr); // Test identical, but not pointer-equal, constraint space. space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(100), LayoutUnit(100))); - result = block_flow->CachedLayoutResult(space, nullptr); + LogicalSize(LayoutUnit(100), LayoutUnit(100))); + result = RunCachedLayoutResult(space, node); EXPECT_NE(result.get(), nullptr); // Test different constraint space. space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(200), LayoutUnit(100))); - result = block_flow->CachedLayoutResult(space, nullptr); + LogicalSize(LayoutUnit(200), LayoutUnit(100))); + result = RunCachedLayoutResult(space, node); EXPECT_NE(result.get(), nullptr); // Test a different constraint space that will actually result in a different // size. space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(200), LayoutUnit(200))); - result = block_flow->CachedLayoutResult(space, nullptr); + LogicalSize(LayoutUnit(200), LayoutUnit(200))); + result = RunCachedLayoutResult(space, node); EXPECT_EQ(result.get(), nullptr); // Test layout invalidation block_flow->SetNeedsLayout(""); - result = block_flow->CachedLayoutResult(space, nullptr); + result = RunCachedLayoutResult(space, node); EXPECT_EQ(result.get(), nullptr); } @@ -152,39 +154,38 @@ TEST_F(NGBlockLayoutAlgorithmTest, MinInlineSizeCaching) { NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(100), LayoutUnit(100))); + LogicalSize(LayoutUnit(100), LayoutUnit(100))); auto* block_flow = To<LayoutBlockFlow>(GetLayoutObjectByElementId("box")); NGBlockNode node(block_flow); scoped_refptr<const NGLayoutResult> result(node.Layout(space, nullptr)); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(30), LayoutUnit(40)), - result->PhysicalFragment()->Size()); + EXPECT_EQ(PhysicalSize(30, 40), result->PhysicalFragment().Size()); // Test pointer-equal constraint space. - result = block_flow->CachedLayoutResult(space, nullptr); + result = RunCachedLayoutResult(space, node); EXPECT_NE(result.get(), nullptr); // Test identical, but not pointer-equal, constraint space. space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(100), LayoutUnit(100))); - result = block_flow->CachedLayoutResult(space, nullptr); + LogicalSize(LayoutUnit(100), LayoutUnit(100))); + result = RunCachedLayoutResult(space, node); EXPECT_NE(result.get(), nullptr); // Test different constraint space. space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(100), LayoutUnit(200))); - result = block_flow->CachedLayoutResult(space, nullptr); + LogicalSize(LayoutUnit(100), LayoutUnit(200))); + result = RunCachedLayoutResult(space, node); EXPECT_NE(result.get(), nullptr); // Test a different constraint space that will actually result in a different // size. space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(200), LayoutUnit(100))); - result = block_flow->CachedLayoutResult(space, nullptr); + LogicalSize(LayoutUnit(200), LayoutUnit(100))); + result = RunCachedLayoutResult(space, node); EXPECT_EQ(result.get(), nullptr); } @@ -244,21 +245,22 @@ TEST_F(NGBlockLayoutAlgorithmTest, PercentageBlockSizeQuirkDescendantsCaching) { }; NGConstraintSpace space100 = - create_space(NGLogicalSize(LayoutUnit(100), LayoutUnit(100))); + create_space(LogicalSize(LayoutUnit(100), LayoutUnit(100))); NGConstraintSpace space200 = - create_space(NGLogicalSize(LayoutUnit(100), LayoutUnit(200))); + create_space(LogicalSize(LayoutUnit(100), LayoutUnit(200))); auto run_test = [&](auto id) -> scoped_refptr<const NGLayoutResult> { // Grab the box under test. auto* box = To<LayoutBlockFlow>(GetLayoutObjectByElementId(id)); + NGBlockNode node(box); // Check that we have a cache hit with space100. scoped_refptr<const NGLayoutResult> result = - box->CachedLayoutResult(space100, nullptr); + RunCachedLayoutResult(space100, node); EXPECT_NE(result.get(), nullptr); // Return the result of the cache with space200. - return box->CachedLayoutResult(space200, nullptr); + return RunCachedLayoutResult(space200, node); }; // Test 1: No descendants. @@ -309,8 +311,8 @@ TEST_F(NGBlockLayoutAlgorithmTest, ShrinkToFitCaching) { <div style="display: inline-block; width: 350px;"></div> <div style="display: inline-block; width: 250px;"></div> </div> - <div id="box3" style="float: left; min-width: 50%;"> - <div style="display: inline-block; width: 350px;"></div> + <div id="box3" style="float: left; min-width: 80%;"> + <div style="display: inline-block; width: 150px;"></div> <div style="display: inline-block; width: 250px;"></div> </div> <div id="box4" style="float: left; margin-left: 75px;"> @@ -322,23 +324,23 @@ TEST_F(NGBlockLayoutAlgorithmTest, ShrinkToFitCaching) { NGConstraintSpace space100 = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(100), LayoutUnit(100)), + LogicalSize(LayoutUnit(100), LayoutUnit(100)), /* shrink_to_fit */ true, /* is_new_formatting_context */ true); NGConstraintSpace space200 = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(200), LayoutUnit(100)), + LogicalSize(LayoutUnit(200), LayoutUnit(100)), /* shrink_to_fit */ true, /* is_new_formatting_context */ true); NGConstraintSpace space250 = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(250), LayoutUnit(100)), + LogicalSize(LayoutUnit(250), LayoutUnit(100)), /* shrink_to_fit */ true, /* is_new_formatting_context */ true); NGConstraintSpace space300 = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(300), LayoutUnit(100)), + LogicalSize(LayoutUnit(300), LayoutUnit(100)), /* shrink_to_fit */ true, /* is_new_formatting_context */ true); NGConstraintSpace space400 = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(400), LayoutUnit(100)), + LogicalSize(LayoutUnit(400), LayoutUnit(100)), /* shrink_to_fit */ true, /* is_new_formatting_context */ true); scoped_refptr<const NGLayoutResult> result; @@ -348,41 +350,41 @@ TEST_F(NGBlockLayoutAlgorithmTest, ShrinkToFitCaching) { auto* box4 = To<LayoutBlockFlow>(GetLayoutObjectByElementId("box4")); // Ensure we cached the result for box1 in the first layout pass. - result = box1->CachedLayoutResult(space300, nullptr); + result = RunCachedLayoutResult(space300, NGBlockNode(box1)); EXPECT_NE(result.get(), nullptr); // box1 was sized to its max-content size in the first layout pass, passing // an available size larger than the fragment should hit the cache. - result = box1->CachedLayoutResult(space400, nullptr); + result = RunCachedLayoutResult(space400, NGBlockNode(box1)); EXPECT_NE(result.get(), nullptr); // Passing an available size smaller than the fragment should miss the cache // as the fragment may shrink. - result = box1->CachedLayoutResult(space100, nullptr); + result = RunCachedLayoutResult(space100, NGBlockNode(box1)); EXPECT_EQ(result.get(), nullptr); // Ensure we cached the result for box2 in the first layout pass. - result = box2->CachedLayoutResult(space300, nullptr); + result = RunCachedLayoutResult(space300, NGBlockNode(box2)); EXPECT_NE(result.get(), nullptr); // box2 was sized to its min-content size in the first layout pass, passing // an available size smaller than the fragment should hit the cache. - result = box2->CachedLayoutResult(space200, nullptr); + result = RunCachedLayoutResult(space200, NGBlockNode(box2)); EXPECT_NE(result.get(), nullptr); // Passing an available size larger than the fragment should miss the cache // as the fragment may shrink. - result = box2->CachedLayoutResult(space400, nullptr); + result = RunCachedLayoutResult(space400, NGBlockNode(box2)); EXPECT_EQ(result.get(), nullptr); // box3 was sized to its min-content size in the first layout pass, however // it should miss the cache as it has a %-min-size. - result = box3->CachedLayoutResult(space200, nullptr); + result = RunCachedLayoutResult(space200, NGBlockNode(box3)); EXPECT_EQ(result.get(), nullptr); // box4 was sized to its max-content size in the first layout pass (the same // as box1) however it should miss the cache due to its margin. - result = box4->CachedLayoutResult(space250, nullptr); + result = RunCachedLayoutResult(space250, NGBlockNode(box4)); EXPECT_EQ(result.get(), nullptr); } @@ -411,14 +413,14 @@ TEST_F(NGBlockLayoutAlgorithmTest, LineOffsetCaching) { }; NGConstraintSpace space200 = - create_space(NGLogicalSize(LayoutUnit(300), LayoutUnit(100)), + create_space(LogicalSize(LayoutUnit(300), LayoutUnit(100)), NGBfcOffset(LayoutUnit(50), LayoutUnit())); scoped_refptr<const NGLayoutResult> result; auto* box1 = To<LayoutBlockFlow>(GetLayoutObjectByElementId("box1")); // Ensure we get a cached layout result, even if our BFC line-offset changed. - result = box1->CachedLayoutResult(space200, nullptr); + result = RunCachedLayoutResult(space200, NGBlockNode(box1)); EXPECT_NE(result.get(), nullptr); } @@ -440,21 +442,22 @@ TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildren) { NGBlockNode container(ToLayoutBox(GetLayoutObjectByElementId("container"))); NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); + LogicalSize(LayoutUnit(100), kIndefiniteSize)); - scoped_refptr<const NGPhysicalBoxFragment> frag = - RunBlockLayoutAlgorithm(space, container); + scoped_refptr<const NGPhysicalBoxFragment> fragment = + RunBlockLayoutAlgorithm(container, space); - EXPECT_EQ(LayoutUnit(kWidth), frag->Size().width); - EXPECT_EQ(LayoutUnit(kHeight1 + kHeight2 + kMarginTop), frag->Size().height); - EXPECT_EQ(NGPhysicalFragment::kFragmentBox, frag->Type()); - ASSERT_EQ(frag->Children().size(), 2UL); + EXPECT_EQ(LayoutUnit(kWidth), fragment->Size().width); + EXPECT_EQ(LayoutUnit(kHeight1 + kHeight2 + kMarginTop), + fragment->Size().height); + EXPECT_EQ(NGPhysicalFragment::kFragmentBox, fragment->Type()); + ASSERT_EQ(fragment->Children().size(), 2UL); - const NGLink& first_child = frag->Children()[0]; + const NGLink& first_child = fragment->Children()[0]; EXPECT_EQ(kHeight1, first_child->Size().height); EXPECT_EQ(0, first_child.Offset().top); - const NGLink& second_child = frag->Children()[1]; + const NGLink& second_child = fragment->Children()[1]; EXPECT_EQ(kHeight2, second_child->Size().height); EXPECT_EQ(kHeight1 + kMarginTop, second_child.Offset().top); } @@ -484,11 +487,11 @@ TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildrenWithWritingMode) { NGBlockNode container(ToLayoutBox(GetLayoutObjectByElementId("container"))); NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); - scoped_refptr<const NGPhysicalBoxFragment> frag = - RunBlockLayoutAlgorithm(space, container); + LogicalSize(LayoutUnit(500), LayoutUnit(500))); + scoped_refptr<const NGPhysicalBoxFragment> fragment = + RunBlockLayoutAlgorithm(container, space); - const NGLink& child = frag->Children()[0]; + const NGLink& child = fragment->Children()[0]; const NGLink& child2 = static_cast<const NGPhysicalBoxFragment*>(child.get())->Children()[0]; @@ -542,7 +545,7 @@ TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase1WithFloats) { std::tie(fragment, space) = RunBlockLayoutAlgorithmForElement( GetDocument().getElementsByTagName("html")->item(0)); ASSERT_EQ(fragment->Children().size(), 1UL); - NGPhysicalOffset body_offset = fragment->Children()[0].Offset(); + PhysicalOffset body_offset = fragment->Children()[0].Offset(); auto* body_fragment = To<NGPhysicalBoxFragment>(fragment->Children()[0].get()); // 20 = max(first child's margin top, containers's margin top) @@ -555,13 +558,13 @@ TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase1WithFloats) { auto* container_fragment = To<NGPhysicalBoxFragment>(body_fragment->Children()[0].get()); - NGPhysicalOffset container_offset = body_fragment->Children()[0].Offset(); + PhysicalOffset container_offset = body_fragment->Children()[0].Offset(); // 0 = collapsed with body's margin EXPECT_THAT(LayoutUnit(0), container_offset.top); ASSERT_EQ(3UL, container_fragment->Children().size()); - NGPhysicalOffset child_offset = container_fragment->Children()[2].Offset(); + PhysicalOffset child_offset = container_fragment->Children()[2].Offset(); // 0 = collapsed with container's margin EXPECT_THAT(LayoutUnit(0), child_offset.top); @@ -626,13 +629,13 @@ TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase2WithFloats) { auto* body_fragment = To<NGPhysicalBoxFragment>(fragment->Children()[0].get()); - NGPhysicalOffset body_offset = fragment->Children()[0].Offset(); + PhysicalOffset body_offset = fragment->Children()[0].Offset(); // -7 = empty1's margin(-15) + body's margin(8) EXPECT_THAT(LayoutUnit(-7), body_offset.top); ASSERT_EQ(4UL, body_fragment->Children().size()); FragmentChildIterator iterator(body_fragment); - NGPhysicalOffset offset; + PhysicalOffset offset; iterator.NextChild(&offset); EXPECT_THAT(LayoutUnit(), offset.top); @@ -698,13 +701,13 @@ TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase3) { run_test(Length::Auto()); // Margins are collapsed with the result 200 = std::max(20, 200) // The fragment size 258 == body's margin 8 + child's height 50 + 200 - EXPECT_EQ(NGPhysicalSize(LayoutUnit(800), LayoutUnit(258)), fragment->Size()); + EXPECT_EQ(PhysicalSize(800, 258), fragment->Size()); // height == fixed run_test(Length::Fixed(50)); // Margins are not collapsed, so fragment still has margins == 20. // The fragment size 78 == body's margin 8 + child's height 50 + 20 - EXPECT_EQ(NGPhysicalSize(LayoutUnit(800), LayoutUnit(78)), fragment->Size()); + EXPECT_EQ(PhysicalSize(800, 78), fragment->Size()); } // Verifies that 2 adjoining margins are not collapsed if there is padding or @@ -727,9 +730,9 @@ TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase4) { </div> )HTML"); - NGPhysicalOffset body_offset; - NGPhysicalOffset container_offset; - NGPhysicalOffset child_offset; + PhysicalOffset body_offset; + PhysicalOffset container_offset; + PhysicalOffset child_offset; scoped_refptr<const NGPhysicalBoxFragment> fragment; auto run_test = [&](const Length& container_padding_top) { Element* container = GetDocument().getElementById("container"); @@ -752,7 +755,7 @@ TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase4) { run_test(Length::Fixed(20)); // 500 = child's height 50 + 2xmargin 400 + paddint-top 20 + // container's margin 30 - EXPECT_EQ(NGPhysicalSize(LayoutUnit(800), LayoutUnit(500)), fragment->Size()); + EXPECT_EQ(PhysicalSize(800, 500), fragment->Size()); // 30 = max(body's margin 8, container margin 30) EXPECT_EQ(LayoutUnit(30), body_offset.top); // 220 = container's padding top 20 + child's margin @@ -762,7 +765,7 @@ TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase4) { run_test(Length::Fixed(0)); // 450 = 2xmax(body's margin 8, container's margin 30, child's margin 200) + // child's height 50 - EXPECT_EQ(NGPhysicalSize(LayoutUnit(800), LayoutUnit(450)), fragment->Size()); + EXPECT_EQ(PhysicalSize(800, 450), fragment->Size()); // 200 = (body's margin 8, container's margin 30, child's margin 200) EXPECT_EQ(LayoutUnit(200), body_offset.top); // 0 = collapsed margins @@ -804,7 +807,7 @@ TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase5) { // body auto* body_fragment = To<NGPhysicalBoxFragment>(fragment->Children()[0].get()); - NGPhysicalOffset body_offset = fragment->Children()[0].Offset(); + PhysicalOffset body_offset = fragment->Children()[0].Offset(); // 10 = std::max(body's margin 8, container's margin top) int body_top_offset = 10; EXPECT_THAT(body_offset.top, LayoutUnit(body_top_offset)); @@ -812,27 +815,25 @@ TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase5) { EXPECT_THAT(body_offset.left, LayoutUnit(body_left_offset)); // height = 70. std::max(vertical height's 70, horizontal's height's 60) - ASSERT_EQ(NGPhysicalSize(LayoutUnit(784), LayoutUnit(70)), - body_fragment->Size()); + ASSERT_EQ(PhysicalSize(784, 70), body_fragment->Size()); ASSERT_EQ(1UL, body_fragment->Children().size()); // container auto* container_fragment = To<NGPhysicalBoxFragment>(body_fragment->Children()[0].get()); - NGPhysicalOffset container_offset = body_fragment->Children()[0].Offset(); + PhysicalOffset container_offset = body_fragment->Children()[0].Offset(); // Container's margins are collapsed with body's fragment. EXPECT_THAT(container_offset.top, LayoutUnit()); EXPECT_THAT(container_offset.left, LayoutUnit()); ASSERT_EQ(2UL, container_fragment->Children().size()); // vertical - NGPhysicalOffset vertical_offset = container_fragment->Children()[0].Offset(); + PhysicalOffset vertical_offset = container_fragment->Children()[0].Offset(); EXPECT_THAT(vertical_offset.top, LayoutUnit()); EXPECT_THAT(vertical_offset.left, LayoutUnit()); // horizontal - NGPhysicalOffset orizontal_offset = - container_fragment->Children()[1].Offset(); + PhysicalOffset orizontal_offset = container_fragment->Children()[1].Offset(); EXPECT_THAT(orizontal_offset.top, LayoutUnit()); // 130 = vertical's width 30 + // std::max(vertical's margin right 90, horizontal's margin-left 100) @@ -859,13 +860,13 @@ TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsWithText) { const NGPhysicalBoxFragment* body_fragment = To<NGPhysicalBoxFragment>(html_fragment->Children()[0].get()); - NGPhysicalOffset body_offset = html_fragment->Children()[0].Offset(); + PhysicalOffset body_offset = html_fragment->Children()[0].Offset(); // 20 = std::max(body's margin, p's margin) - EXPECT_THAT(body_offset, NGPhysicalOffset(LayoutUnit(10), LayoutUnit(20))); + EXPECT_THAT(body_offset, PhysicalOffset(10, 20)); - NGPhysicalOffset p_offset = body_fragment->Children()[0].Offset(); + PhysicalOffset p_offset = body_fragment->Children()[0].Offset(); // Collapsed margins with result = 0. - EXPECT_THAT(p_offset, NGPhysicalOffset(LayoutUnit(20), LayoutUnit(0))); + EXPECT_THAT(p_offset, PhysicalOffset(20, 0)); } // Verifies that the margin strut of a child with a different writing mode does @@ -896,18 +897,18 @@ TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase6) { NGBlockNode container(ToLayoutBox(GetLayoutObjectByElementId("container"))); NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); - scoped_refptr<const NGPhysicalBoxFragment> frag = - RunBlockLayoutAlgorithm(space, container); + LogicalSize(LayoutUnit(500), LayoutUnit(500))); + scoped_refptr<const NGPhysicalBoxFragment> fragment = + RunBlockLayoutAlgorithm(container, space); - ASSERT_EQ(frag->Children().size(), 2UL); + ASSERT_EQ(fragment->Children().size(), 2UL); - const NGPhysicalFragment* child1 = frag->Children()[0].get(); - NGPhysicalOffset child1_offset = frag->Children()[0].Offset(); + const NGPhysicalFragment* child1 = fragment->Children()[0].get(); + PhysicalOffset child1_offset = fragment->Children()[0].Offset(); EXPECT_EQ(0, child1_offset.top); EXPECT_EQ(kHeight, child1->Size().height); - NGPhysicalOffset child2_offset = frag->Children()[1].Offset(); + PhysicalOffset child2_offset = fragment->Children()[1].Offset(); EXPECT_EQ(kHeight + std::max(kMarginBottom, kMarginTop), child2_offset.top); } @@ -951,21 +952,21 @@ TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase7) { FragmentChildIterator iterator(fragment.get()); // body - NGPhysicalOffset offset; + PhysicalOffset offset; const NGPhysicalBoxFragment* child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(200), LayoutUnit(20)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(8), LayoutUnit(20)), offset); + EXPECT_EQ(PhysicalSize(200, 20), child->Size()); + EXPECT_EQ(PhysicalOffset(8, 20), offset); // #zero iterator.SetParent(child); child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(200), LayoutUnit(0)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(0)), offset); + EXPECT_EQ(PhysicalSize(200, 0), child->Size()); + EXPECT_EQ(PhysicalOffset(0, 0), offset); // #inflow child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(200), LayoutUnit(20)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(0)), offset); + EXPECT_EQ(PhysicalSize(200, 20), child->Size()); + EXPECT_EQ(PhysicalOffset(0, 0), offset); } // An empty block level element (with margins collapsing through it) has @@ -1198,15 +1199,15 @@ TEST_F(NGBlockLayoutAlgorithmTest, BorderAndPadding) { NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); + LogicalSize(LayoutUnit(1000), kIndefiniteSize)); - scoped_refptr<const NGPhysicalBoxFragment> frag = - RunBlockLayoutAlgorithm(space, container); + scoped_refptr<const NGPhysicalBoxFragment> fragment = + RunBlockLayoutAlgorithm(container, space); - ASSERT_EQ(frag->Children().size(), 1UL); + ASSERT_EQ(fragment->Children().size(), 1UL); // div1 - const NGPhysicalFragment* child = frag->Children()[0].get(); + const NGPhysicalFragment* child = fragment->Children()[0].get(); EXPECT_EQ(kBorderLeft + kPaddingLeft + kWidth + kPaddingRight + kBorderRight, child->Size().width); EXPECT_EQ(kBorderTop + kPaddingTop + kHeight + kPaddingBottom + kBorderBottom, @@ -1216,7 +1217,7 @@ TEST_F(NGBlockLayoutAlgorithmTest, BorderAndPadding) { ASSERT_EQ(static_cast<const NGPhysicalBoxFragment*>(child)->Children().size(), 1UL); - NGPhysicalOffset div2_offset = + PhysicalOffset div2_offset = static_cast<const NGPhysicalBoxFragment*>(child)->Children()[0].Offset(); EXPECT_EQ(kBorderTop + kPaddingTop, div2_offset.top); EXPECT_EQ(kBorderLeft + kPaddingLeft, div2_offset.left); @@ -1235,15 +1236,15 @@ TEST_F(NGBlockLayoutAlgorithmTest, PercentageResolutionSize) { NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); - scoped_refptr<const NGPhysicalBoxFragment> frag = - RunBlockLayoutAlgorithm(space, container); + LogicalSize(LayoutUnit(100), kIndefiniteSize)); + scoped_refptr<const NGPhysicalBoxFragment> fragment = + RunBlockLayoutAlgorithm(container, space); - EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Size().width); - EXPECT_EQ(NGPhysicalFragment::kFragmentBox, frag->Type()); - ASSERT_EQ(frag->Children().size(), 1UL); + EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), fragment->Size().width); + EXPECT_EQ(NGPhysicalFragment::kFragmentBox, fragment->Type()); + ASSERT_EQ(fragment->Children().size(), 1UL); - const NGPhysicalFragment* child = frag->Children()[0].get(); + const NGPhysicalFragment* child = fragment->Children()[0].get(); EXPECT_EQ(LayoutUnit(12), child->Size().width); } @@ -1267,16 +1268,16 @@ TEST_F(NGBlockLayoutAlgorithmTest, AutoMargin) { NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); - scoped_refptr<const NGPhysicalBoxFragment> frag = - RunBlockLayoutAlgorithm(space, container); + LogicalSize(LayoutUnit(100), kIndefiniteSize)); + scoped_refptr<const NGPhysicalBoxFragment> fragment = + RunBlockLayoutAlgorithm(container, space); - EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Size().width); - EXPECT_EQ(NGPhysicalFragment::kFragmentBox, frag->Type()); - ASSERT_EQ(1UL, frag->Children().size()); + EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), fragment->Size().width); + EXPECT_EQ(NGPhysicalFragment::kFragmentBox, fragment->Type()); + ASSERT_EQ(1UL, fragment->Children().size()); - const NGPhysicalFragment* child = frag->Children()[0].get(); - NGPhysicalOffset child_offset = frag->Children()[0].Offset(); + const NGPhysicalFragment* child = fragment->Children()[0].get(); + PhysicalOffset child_offset = fragment->Children()[0].Offset(); EXPECT_EQ(LayoutUnit(kChildWidth), child->Size().width); EXPECT_EQ(LayoutUnit(kPaddingLeft + 10), child_offset.left); EXPECT_EQ(LayoutUnit(0), child_offset.top); @@ -1334,7 +1335,7 @@ TEST_F(NGBlockLayoutAlgorithmTest, PositionFloatInsideEmptyBlocks) { const auto* body_fragment = To<NGPhysicalBoxFragment>(fragment->Children()[0].get()); - NGPhysicalOffset body_offset = fragment->Children()[0].Offset(); + PhysicalOffset body_offset = fragment->Children()[0].Offset(); FragmentChildIterator iterator(body_fragment); // 20 = std::max(empty1's margin, empty2's margin, body's margin) int body_top_offset = 20; @@ -1345,7 +1346,7 @@ TEST_F(NGBlockLayoutAlgorithmTest, PositionFloatInsideEmptyBlocks) { ASSERT_EQ(1UL, container_fragment->Children().size()); iterator.SetParent(container_fragment); - NGPhysicalOffset offset; + PhysicalOffset offset; const auto* empty1_fragment = iterator.NextChild(&offset); // 0, vertical margins got collapsed EXPECT_THAT(offset.top, LayoutUnit()); @@ -1364,17 +1365,19 @@ TEST_F(NGBlockLayoutAlgorithmTest, PositionFloatInsideEmptyBlocks) { offset = To<NGPhysicalLineBoxFragment>(linebox_fragment)->Children()[0].offset; - // inline 10 = left float's margin(10) + // The floats are positioned outside the line-box as the line-box is + // "avoiding" these floats. + // inline -35 = inline-size of left-float (including margins). // block 10 = left float's margin - EXPECT_THAT(offset, NGPhysicalOffset(LayoutUnit(10), LayoutUnit(10))); + EXPECT_THAT(offset, PhysicalOffset(-35, 10)); offset = To<NGPhysicalLineBoxFragment>(linebox_fragment)->Children()[1].offset; - // inline offset 135 = right float's margin(10) + right float offset(125) + // inline offset 90 = right float's margin(10) + right float offset(80) // block offset 15 = right float's margin - LayoutUnit right_float_offset = LayoutUnit(125); - EXPECT_THAT(offset, NGPhysicalOffset(LayoutUnit(10) + right_float_offset, - LayoutUnit(15))); + LayoutUnit right_float_offset = LayoutUnit(80); + EXPECT_THAT(offset, PhysicalOffset(LayoutUnit(10) + right_float_offset, + LayoutUnit(15))); // ** Verify layout tree ** Element* left_float = GetDocument().getElementById("left-float"); @@ -1445,7 +1448,7 @@ TEST_F(NGBlockLayoutAlgorithmTest, PositionFloatFragments) { ASSERT_EQ(1UL, fragment->Children().size()); const auto* body_fragment = To<NGPhysicalBoxFragment>(fragment->Children()[0].get()); - NGPhysicalOffset body_offset = fragment->Children()[0].Offset(); + PhysicalOffset body_offset = fragment->Children()[0].Offset(); EXPECT_THAT(LayoutUnit(8), body_offset.top); FragmentChildIterator iterator(body_fragment); @@ -1458,7 +1461,7 @@ TEST_F(NGBlockLayoutAlgorithmTest, PositionFloatFragments) { EXPECT_EQ(8, left_float->OffsetTop()); iterator.SetParent(container_fragment); - NGPhysicalOffset offset; + PhysicalOffset offset; iterator.NextChild(&offset); EXPECT_THAT(LayoutUnit(), offset.top); @@ -1556,11 +1559,11 @@ TEST_F(NGBlockLayoutAlgorithmTest, PositionFragmentsWithClear) { </div> )HTML"); - NGPhysicalOffset clerance_offset; - NGPhysicalOffset body_offset; - NGPhysicalOffset container_offset; - NGPhysicalOffset block_offset; - NGPhysicalOffset adjoining_clearance_offset; + PhysicalOffset clerance_offset; + PhysicalOffset body_offset; + PhysicalOffset container_offset; + PhysicalOffset block_offset; + PhysicalOffset adjoining_clearance_offset; scoped_refptr<const NGPhysicalBoxFragment> fragment; auto run_with_clearance = [&](EClear clear_value) { Element* el_with_clear = GetDocument().getElementById("clearance"); @@ -1770,11 +1773,11 @@ TEST_F(NGBlockLayoutAlgorithmTest, ShrinkToFit) { NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(100), NGSizeIndefinite), true); - scoped_refptr<const NGPhysicalFragment> frag = - RunBlockLayoutAlgorithm(space, container); + LogicalSize(LayoutUnit(100), kIndefiniteSize), true); + scoped_refptr<const NGPhysicalBoxFragment> fragment = + RunBlockLayoutAlgorithm(container, space); - EXPECT_EQ(LayoutUnit(kWidthChild2), frag->Size().width); + EXPECT_EQ(LayoutUnit(kWidthChild2), fragment->Size().width); } // Verifies that we position empty blocks and floats correctly inside of the @@ -1813,17 +1816,15 @@ TEST_F(NGBlockLayoutAlgorithmTest, PositionEmptyBlocksInNewBfc) { To<NGPhysicalBoxFragment>(html_fragment->Children()[0].get()); auto* container_fragment = To<NGPhysicalBoxFragment>(body_fragment->Children()[0].get()); - NGPhysicalOffset empty_block1_offset = + PhysicalOffset empty_block1_offset = container_fragment->Children()[1].Offset(); // empty-block1's margin == 8 - EXPECT_THAT(empty_block1_offset, - NGPhysicalOffset(LayoutUnit(8), LayoutUnit(8))); + EXPECT_THAT(empty_block1_offset, PhysicalOffset(8, 8)); - NGPhysicalOffset empty_block2_offset = + PhysicalOffset empty_block2_offset = container_fragment->Children()[2].Offset(); // empty-block2's margin == 50 - EXPECT_THAT(empty_block2_offset, - NGPhysicalOffset(LayoutUnit(0), LayoutUnit(50))); + EXPECT_THAT(empty_block2_offset, PhysicalOffset(0, 50)); } // Verifies that we can correctly position blocks with clearance and @@ -1886,11 +1887,9 @@ TEST_F(NGBlockLayoutAlgorithmTest, // Verify #container-clear block auto* container_clear_fragment = To<NGPhysicalBoxFragment>(body_fragment->Children()[3].get()); - NGPhysicalOffset container_clear_offset = - body_fragment->Children()[3].Offset(); + PhysicalOffset container_clear_offset = body_fragment->Children()[3].Offset(); // 60 = block1's height 30 + std::max(block1's margin 20, zero's margin 30) - EXPECT_THAT(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(60)), - container_clear_offset); + EXPECT_THAT(PhysicalOffset(0, 60), container_clear_offset); Element* container_clear = GetDocument().getElementById("container-clear"); // 190 = block1's margin 130 + block1's height 30 + // std::max(block1's margin 20, zero's margin 30) @@ -1898,12 +1897,11 @@ TEST_F(NGBlockLayoutAlgorithmTest, // Verify #clears-right block ASSERT_EQ(2UL, container_clear_fragment->Children().size()); - NGPhysicalOffset clears_right_offset = + PhysicalOffset clears_right_offset = container_clear_fragment->Children()[1].Offset(); // 20 = right-float's block end offset (130 + 80) - // container_clear->offsetTop() 190 - EXPECT_THAT(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(20)), - clears_right_offset); + EXPECT_THAT(PhysicalOffset(0, 20), clears_right_offset); } // Tests that a block won't fragment if it doesn't reach the fragmentation line. @@ -1924,13 +1922,13 @@ TEST_F(NGBlockLayoutAlgorithmTest, NoFragmentation) { NGBlockNode node(ToLayoutBox(GetLayoutObjectByElementId("container"))); NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite), false, + LogicalSize(LayoutUnit(1000), kIndefiniteSize), false, node.CreatesNewFormattingContext(), kFragmentainerSpaceAvailable); // We should only have one 150x200 fragment with no fragmentation. - scoped_refptr<const NGPhysicalFragment> fragment = - NGBlockLayoutAlgorithm(node, space).Layout()->PhysicalFragment(); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(200)), fragment->Size()); + scoped_refptr<const NGPhysicalBoxFragment> fragment = + RunBlockLayoutAlgorithm(node, space); + EXPECT_EQ(PhysicalSize(150, 200), fragment->Size()); ASSERT_TRUE(fragment->BreakToken()->IsFinished()); } @@ -1952,19 +1950,16 @@ TEST_F(NGBlockLayoutAlgorithmTest, SimpleFragmentation) { NGBlockNode node(ToLayoutBox(GetLayoutObjectByElementId("container"))); NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite), false, + LogicalSize(LayoutUnit(1000), kIndefiniteSize), false, node.CreatesNewFormattingContext(), kFragmentainerSpaceAvailable); - scoped_refptr<const NGPhysicalFragment> fragment = - NGBlockLayoutAlgorithm(node, space).Layout()->PhysicalFragment(); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(200)), fragment->Size()); + scoped_refptr<const NGPhysicalBoxFragment> fragment = + RunBlockLayoutAlgorithm(node, space); + EXPECT_EQ(PhysicalSize(150, 200), fragment->Size()); ASSERT_FALSE(fragment->BreakToken()->IsFinished()); - fragment = NGBlockLayoutAlgorithm( - node, space, To<NGBlockBreakToken>(fragment->BreakToken())) - .Layout() - ->PhysicalFragment(); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(100)), fragment->Size()); + fragment = RunBlockLayoutAlgorithm(node, space, fragment->BreakToken()); + EXPECT_EQ(PhysicalSize(150, 100), fragment->Size()); ASSERT_TRUE(fragment->BreakToken()->IsFinished()); } @@ -1998,37 +1993,34 @@ TEST_F(NGBlockLayoutAlgorithmTest, InnerChildrenFragmentation) { NGBlockNode node(ToLayoutBox(GetLayoutObjectByElementId("container"))); NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite), false, + LogicalSize(LayoutUnit(1000), kIndefiniteSize), false, node.CreatesNewFormattingContext(), kFragmentainerSpaceAvailable); - scoped_refptr<const NGPhysicalFragment> fragment = - NGBlockLayoutAlgorithm(node, space).Layout()->PhysicalFragment(); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(200)), fragment->Size()); + scoped_refptr<const NGPhysicalBoxFragment> fragment = + RunBlockLayoutAlgorithm(node, space); + EXPECT_EQ(PhysicalSize(150, 200), fragment->Size()); ASSERT_FALSE(fragment->BreakToken()->IsFinished()); FragmentChildIterator iterator(To<NGPhysicalBoxFragment>(fragment.get())); - NGPhysicalOffset offset; + PhysicalOffset offset; const NGPhysicalBoxFragment* child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(180)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(20)), offset); + EXPECT_EQ(PhysicalSize(150, 180), child->Size()); + EXPECT_EQ(PhysicalOffset(0, 20), offset); EXPECT_FALSE(iterator.NextChild()); - fragment = NGBlockLayoutAlgorithm( - node, space, To<NGBlockBreakToken>(fragment->BreakToken())) - .Layout() - ->PhysicalFragment(); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(140)), fragment->Size()); + fragment = RunBlockLayoutAlgorithm(node, space, fragment->BreakToken()); + EXPECT_EQ(PhysicalSize(150, 140), fragment->Size()); ASSERT_TRUE(fragment->BreakToken()->IsFinished()); iterator.SetParent(To<NGPhysicalBoxFragment>(fragment.get())); child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(20)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(0)), offset); + EXPECT_EQ(PhysicalSize(150, 20), child->Size()); + EXPECT_EQ(PhysicalOffset(0, 0), offset); child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(100)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(40)), offset); + EXPECT_EQ(PhysicalSize(150, 100), child->Size()); + EXPECT_EQ(PhysicalOffset(0, 40), offset); EXPECT_FALSE(iterator.NextChild()); } @@ -2066,37 +2058,34 @@ TEST_F(NGBlockLayoutAlgorithmTest, NGBlockNode node(ToLayoutBox(GetLayoutObjectByElementId("container"))); NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite), false, + LogicalSize(LayoutUnit(1000), kIndefiniteSize), false, node.CreatesNewFormattingContext(), kFragmentainerSpaceAvailable); - scoped_refptr<const NGPhysicalFragment> fragment = - NGBlockLayoutAlgorithm(node, space).Layout()->PhysicalFragment(); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(200)), fragment->Size()); + scoped_refptr<const NGPhysicalBoxFragment> fragment = + RunBlockLayoutAlgorithm(node, space); + EXPECT_EQ(PhysicalSize(150, 200), fragment->Size()); ASSERT_FALSE(fragment->BreakToken()->IsFinished()); FragmentChildIterator iterator(To<NGPhysicalBoxFragment>(fragment.get())); - NGPhysicalOffset offset; + PhysicalOffset offset; const NGPhysicalBoxFragment* child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(180)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(20)), offset); + EXPECT_EQ(PhysicalSize(150, 180), child->Size()); + EXPECT_EQ(PhysicalOffset(0, 20), offset); EXPECT_FALSE(iterator.NextChild()); - fragment = NGBlockLayoutAlgorithm( - node, space, To<NGBlockBreakToken>(fragment->BreakToken())) - .Layout() - ->PhysicalFragment(); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(140)), fragment->Size()); + fragment = RunBlockLayoutAlgorithm(node, space, fragment->BreakToken()); + EXPECT_EQ(PhysicalSize(150, 140), fragment->Size()); ASSERT_TRUE(fragment->BreakToken()->IsFinished()); iterator.SetParent(To<NGPhysicalBoxFragment>(fragment.get())); child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(20)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(0)), offset); + EXPECT_EQ(PhysicalSize(150, 20), child->Size()); + EXPECT_EQ(PhysicalOffset(0, 0), offset); child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(100)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(40)), offset); + EXPECT_EQ(PhysicalSize(150, 100), child->Size()); + EXPECT_EQ(PhysicalOffset(0, 40), offset); EXPECT_FALSE(iterator.NextChild()); } @@ -2132,37 +2121,34 @@ TEST_F(NGBlockLayoutAlgorithmTest, InnerChildrenFragmentationSmallHeight) { NGBlockNode node(ToLayoutBox(GetLayoutObjectByElementId("container"))); NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite), false, + LogicalSize(LayoutUnit(1000), kIndefiniteSize), false, node.CreatesNewFormattingContext(), kFragmentainerSpaceAvailable); - scoped_refptr<const NGPhysicalFragment> fragment = - NGBlockLayoutAlgorithm(node, space).Layout()->PhysicalFragment(); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(70)), fragment->Size()); + scoped_refptr<const NGPhysicalBoxFragment> fragment = + RunBlockLayoutAlgorithm(node, space); + EXPECT_EQ(PhysicalSize(150, 70), fragment->Size()); ASSERT_FALSE(fragment->BreakToken()->IsFinished()); FragmentChildIterator iterator(To<NGPhysicalBoxFragment>(fragment.get())); - NGPhysicalOffset offset; + PhysicalOffset offset; const NGPhysicalBoxFragment* child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(180)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(20)), offset); + EXPECT_EQ(PhysicalSize(150, 180), child->Size()); + EXPECT_EQ(PhysicalOffset(0, 20), offset); EXPECT_FALSE(iterator.NextChild()); - fragment = NGBlockLayoutAlgorithm( - node, space, To<NGBlockBreakToken>(fragment->BreakToken())) - .Layout() - ->PhysicalFragment(); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(0)), fragment->Size()); + fragment = RunBlockLayoutAlgorithm(node, space, fragment->BreakToken()); + EXPECT_EQ(PhysicalSize(150, 0), fragment->Size()); ASSERT_TRUE(fragment->BreakToken()->IsFinished()); iterator.SetParent(To<NGPhysicalBoxFragment>(fragment.get())); child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(20)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(0)), offset); + EXPECT_EQ(PhysicalSize(150, 20), child->Size()); + EXPECT_EQ(PhysicalOffset(0, 0), offset); child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(100)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(40)), offset); + EXPECT_EQ(PhysicalSize(150, 100), child->Size()); + EXPECT_EQ(PhysicalOffset(0, 40), offset); EXPECT_FALSE(iterator.NextChild()); } @@ -2201,49 +2187,47 @@ TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_FloatFragmentationParallelFlows) { To<LayoutBlockFlow>(GetLayoutObjectByElementId("container"))); NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite), false, + LogicalSize(LayoutUnit(1000), kIndefiniteSize), false, node.CreatesNewFormattingContext(), kFragmentainerSpaceAvailable); - scoped_refptr<const NGPhysicalFragment> fragment = - NGBlockLayoutAlgorithm(node, space).Layout()->PhysicalFragment(); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(50)), fragment->Size()); + scoped_refptr<const NGPhysicalBoxFragment> fragment = + RunBlockLayoutAlgorithm(node, space); + EXPECT_EQ(PhysicalSize(150, 50), fragment->Size()); ASSERT_FALSE(fragment->BreakToken()->IsFinished()); FragmentChildIterator iterator(To<NGPhysicalBoxFragment>(fragment.get())); // First fragment of float1. - NGPhysicalOffset offset; + PhysicalOffset offset; const auto* child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(50), LayoutUnit(150)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(0)), offset); + EXPECT_EQ(PhysicalSize(50, 150), child->Size()); + EXPECT_EQ(PhysicalOffset(0, 0), offset); // First fragment of float2. child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(75), LayoutUnit(150)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(65), LayoutUnit(10)), offset); + EXPECT_EQ(PhysicalSize(75, 150), child->Size()); + EXPECT_EQ(PhysicalOffset(65, 10), offset); space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite), false, + LogicalSize(LayoutUnit(1000), kIndefiniteSize), false, node.CreatesNewFormattingContext(), kFragmentainerSpaceAvailable); - fragment = NGBlockLayoutAlgorithm( - node, space, To<NGBlockBreakToken>(fragment->BreakToken())) - .Layout() - ->PhysicalFragment(); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(0)), fragment->Size()); + + fragment = RunBlockLayoutAlgorithm(node, space, fragment->BreakToken()); + EXPECT_EQ(PhysicalSize(150, 0), fragment->Size()); ASSERT_TRUE(fragment->BreakToken()->IsFinished()); iterator.SetParent(To<NGPhysicalBoxFragment>(fragment.get())); // Second fragment of float1. child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(50), LayoutUnit(50)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(0)), offset); + EXPECT_EQ(PhysicalSize(50, 50), child->Size()); + EXPECT_EQ(PhysicalOffset(0, 0), offset); // Second fragment of float2. child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(75), LayoutUnit(100)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(65), LayoutUnit()), offset); + EXPECT_EQ(PhysicalSize(75, 100), child->Size()); + EXPECT_EQ(PhysicalOffset(65, 0), offset); } // Tests that float children don't fragment if they aren't in the same writing @@ -2281,14 +2265,14 @@ TEST_F(NGBlockLayoutAlgorithmTest, FloatFragmentationOrthogonalFlows) { To<LayoutBlockFlow>(GetLayoutObjectByElementId("container"))); NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite), false, true, + LogicalSize(LayoutUnit(1000), kIndefiniteSize), false, true, kFragmentainerSpaceAvailable); AdvanceToLayoutPhase(); - scoped_refptr<const NGPhysicalFragment> fragment = - NGBlockLayoutAlgorithm(node, space).Layout()->PhysicalFragment(); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(60)), fragment->Size()); + scoped_refptr<const NGPhysicalBoxFragment> fragment = + RunBlockLayoutAlgorithm(node, space); + EXPECT_EQ(PhysicalSize(150, 60), fragment->Size()); ASSERT_TRUE(!fragment->BreakToken() || fragment->BreakToken()->IsFinished()); const auto* linebox = @@ -2297,8 +2281,10 @@ TEST_F(NGBlockLayoutAlgorithmTest, FloatFragmentationOrthogonalFlows) { To<NGPhysicalLineBoxFragment>(linebox)->Children()[1].fragment; // float2 should only have one fragment. - EXPECT_EQ(NGPhysicalSize(LayoutUnit(60), LayoutUnit(200)), float2->Size()); - ASSERT_TRUE(!float2->BreakToken() || float2->BreakToken()->IsFinished()); + EXPECT_EQ(PhysicalSize(60, 200), float2->Size()); + ASSERT_TRUE(float2->IsBox()); + NGBreakToken* break_token = To<NGPhysicalBoxFragment>(float2)->BreakToken(); + EXPECT_TRUE(!break_token || break_token->IsFinished()); } // Tests that a float child inside a zero height block fragments correctly. @@ -2331,12 +2317,12 @@ TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_FloatFragmentationZeroHeight) { To<LayoutBlockFlow>(GetLayoutObjectByElementId("container"))); NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite), false, + LogicalSize(LayoutUnit(1000), kIndefiniteSize), false, node.CreatesNewFormattingContext(), kFragmentainerSpaceAvailable); - scoped_refptr<const NGPhysicalFragment> fragment = - NGBlockLayoutAlgorithm(node, space).Layout()->PhysicalFragment(); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(50)), fragment->Size()); + scoped_refptr<const NGPhysicalBoxFragment> fragment = + RunBlockLayoutAlgorithm(node, space); + EXPECT_EQ(PhysicalSize(150, 50), fragment->Size()); ASSERT_FALSE(fragment->BreakToken()->IsFinished()); FragmentChildIterator iterator(To<NGPhysicalBoxFragment>(fragment.get())); @@ -2344,20 +2330,18 @@ TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_FloatFragmentationZeroHeight) { // First fragment of float. iterator.SetParent(child); - NGPhysicalOffset offset; + PhysicalOffset offset; child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(75), LayoutUnit(150)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(10), LayoutUnit(10)), offset); + EXPECT_EQ(PhysicalSize(75, 150), child->Size()); + EXPECT_EQ(PhysicalOffset(10, 10), offset); space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite), false, + LogicalSize(LayoutUnit(1000), kIndefiniteSize), false, node.CreatesNewFormattingContext(), kFragmentainerSpaceAvailable); - fragment = NGBlockLayoutAlgorithm( - node, space, To<NGBlockBreakToken>(fragment->BreakToken())) - .Layout() - ->PhysicalFragment(); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(0)), fragment->Size()); + + fragment = RunBlockLayoutAlgorithm(node, space, fragment->BreakToken()); + EXPECT_EQ(PhysicalSize(150, 0), fragment->Size()); ASSERT_TRUE(fragment->BreakToken()->IsFinished()); iterator.SetParent(To<NGPhysicalBoxFragment>(fragment.get())); @@ -2366,10 +2350,10 @@ TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_FloatFragmentationZeroHeight) { // Second fragment of float. iterator.SetParent(child); child = iterator.NextChild(); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(75), LayoutUnit(50)), child->Size()); + EXPECT_EQ(PhysicalSize(75, 50), child->Size()); // TODO(ikilpatrick): Don't include the block-start margin of a float which // has fragmented. - // EXPECT_EQ(NGPhysicalOffset(LayoutUnit(10), LayoutUnit(0)), + // EXPECT_EQ(PhysicalOffset(10, 0), // child->Offset()); } @@ -2397,8 +2381,8 @@ TEST_F(NGBlockLayoutAlgorithmTest, </div> )HTML"); - NGPhysicalOffset body_offset; - NGPhysicalOffset new_fc_offset; + PhysicalOffset body_offset; + PhysicalOffset new_fc_offset; scoped_refptr<const NGPhysicalBoxFragment> fragment; auto run_test = [&](const Length& block_width) { @@ -2420,17 +2404,17 @@ TEST_F(NGBlockLayoutAlgorithmTest, // #new-fc is small enough to fit on the same line with #float. run_test(Length::Fixed(80)); // 100 = float's width, 0 = no margin collapsing - EXPECT_THAT(new_fc_offset, NGPhysicalOffset(LayoutUnit(100), LayoutUnit(0))); + EXPECT_THAT(new_fc_offset, PhysicalOffset(100, 0)); // 8 = body's margins, 20 = new-fc's margin top(20) collapses with // body's margin(8) - EXPECT_THAT(body_offset, NGPhysicalOffset(LayoutUnit(8), LayoutUnit(20))); + EXPECT_THAT(body_offset, PhysicalOffset(8, 20)); // #new-fc is too wide to be positioned on the same line with #float run_test(Length::Fixed(120)); // 30 = #float's height - EXPECT_THAT(new_fc_offset, NGPhysicalOffset(LayoutUnit(0), LayoutUnit(30))); + EXPECT_THAT(new_fc_offset, PhysicalOffset(0, 30)); // 8 = body's margins, no margin collapsing - EXPECT_THAT(body_offset, NGPhysicalOffset(LayoutUnit(8), LayoutUnit(8))); + EXPECT_THAT(body_offset, PhysicalOffset(8, 8)); } TEST_F(NGBlockLayoutAlgorithmTest, NewFcAvoidsFloats) { @@ -2457,22 +2441,22 @@ TEST_F(NGBlockLayoutAlgorithmTest, NewFcAvoidsFloats) { To<LayoutBlockFlow>(GetLayoutObjectByElementId("container"))); NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); + LogicalSize(LayoutUnit(1000), kIndefiniteSize)); - scoped_refptr<const NGPhysicalFragment> fragment = - NGBlockLayoutAlgorithm(node, space).Layout()->PhysicalFragment(); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(200), LayoutUnit(150)), fragment->Size()); + scoped_refptr<const NGPhysicalBoxFragment> fragment = + RunBlockLayoutAlgorithm(node, space); + EXPECT_EQ(PhysicalSize(200, 150), fragment->Size()); FragmentChildIterator iterator(To<NGPhysicalBoxFragment>(fragment.get())); - NGPhysicalOffset offset; + PhysicalOffset offset; const NGPhysicalBoxFragment* child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(100), LayoutUnit(30)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(0)), offset); + EXPECT_EQ(PhysicalSize(100, 30), child->Size()); + EXPECT_EQ(PhysicalOffset(0, 0), offset); child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(120)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(30)), offset); + EXPECT_EQ(PhysicalSize(150, 120), child->Size()); + EXPECT_EQ(PhysicalOffset(0, 30), offset); } TEST_F(NGBlockLayoutAlgorithmTest, ZeroBlockSizeAboveEdge) { @@ -2493,22 +2477,22 @@ TEST_F(NGBlockLayoutAlgorithmTest, ZeroBlockSizeAboveEdge) { To<LayoutBlockFlow>(GetLayoutObjectByElementId("container"))); NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite), false, true); + LogicalSize(LayoutUnit(1000), kIndefiniteSize), false, true); - scoped_refptr<const NGPhysicalFragment> fragment = - NGBlockLayoutAlgorithm(node, space).Layout()->PhysicalFragment(); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(200), LayoutUnit(10)), fragment->Size()); + scoped_refptr<const NGPhysicalBoxFragment> fragment = + RunBlockLayoutAlgorithm(node, space); + EXPECT_EQ(PhysicalSize(200, 10), fragment->Size()); FragmentChildIterator iterator(To<NGPhysicalBoxFragment>(fragment.get())); - NGPhysicalOffset offset; + PhysicalOffset offset; const NGPhysicalBoxFragment* child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(50), LayoutUnit(50)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(-70)), offset); + EXPECT_EQ(PhysicalSize(50, 50), child->Size()); + EXPECT_EQ(PhysicalOffset(0, -70), offset); child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(70), LayoutUnit(0)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(-10)), offset); + EXPECT_EQ(PhysicalSize(70, 0), child->Size()); + EXPECT_EQ(PhysicalOffset(0, -10), offset); } TEST_F(NGBlockLayoutAlgorithmTest, NewFcFirstChildIsZeroBlockSize) { @@ -2531,26 +2515,26 @@ TEST_F(NGBlockLayoutAlgorithmTest, NewFcFirstChildIsZeroBlockSize) { To<LayoutBlockFlow>(GetLayoutObjectByElementId("container"))); NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace( WritingMode::kHorizontalTb, TextDirection::kLtr, - NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite), false, true); + LogicalSize(LayoutUnit(1000), kIndefiniteSize), false, true); - scoped_refptr<const NGPhysicalFragment> fragment = - NGBlockLayoutAlgorithm(node, space).Layout()->PhysicalFragment(); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(200), LayoutUnit(10)), fragment->Size()); + scoped_refptr<const NGPhysicalBoxFragment> fragment = + RunBlockLayoutAlgorithm(node, space); + EXPECT_EQ(PhysicalSize(200, 10), fragment->Size()); FragmentChildIterator iterator(To<NGPhysicalBoxFragment>(fragment.get())); - NGPhysicalOffset offset; + PhysicalOffset offset; const NGPhysicalBoxFragment* child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(50), LayoutUnit(0)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(-30)), offset); + EXPECT_EQ(PhysicalSize(50, 0), child->Size()); + EXPECT_EQ(PhysicalOffset(0, -30), offset); child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(70), LayoutUnit(0)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(-10)), offset); + EXPECT_EQ(PhysicalSize(70, 0), child->Size()); + EXPECT_EQ(PhysicalOffset(0, -10), offset); child = iterator.NextChild(&offset); - EXPECT_EQ(NGPhysicalSize(LayoutUnit(90), LayoutUnit(20)), child->Size()); - EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(-10)), offset); + EXPECT_EQ(PhysicalSize(90, 20), child->Size()); + EXPECT_EQ(PhysicalOffset(0, -10), offset); } // This test assumes that tables are not yet implemented in LayoutNG. @@ -2572,8 +2556,7 @@ TEST_F(NGBlockLayoutAlgorithmTest, RootFragmentOffsetInsideLegacy) { ASSERT_TRUE(fragment); // TODO(crbug.com/781241: Re-enable when we calculate inline offset at // the right time. - // EXPECT_EQ(NGPhysicalOffset(LayoutUnit(20), LayoutUnit(10)), - // fragment->Offset()); + // EXPECT_EQ(PhysicalOffset(20, 10), fragment->Offset()); } // TODO(dgrogan): Move this to ng_flex_layout_algorithm_test.cc if there ever is |