| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/layout/ng/ng_block_layout_algorithm.h" | 5 #include "core/layout/ng/ng_block_layout_algorithm.h" |
| 6 | 6 |
| 7 #include "core/layout/ng/ng_box.h" | 7 #include "core/layout/ng/ng_box.h" |
| 8 #include "core/layout/ng/ng_constraint_space.h" | 8 #include "core/layout/ng/ng_constraint_space.h" |
| 9 #include "core/layout/ng/ng_physical_fragment.h" | 9 #include "core/layout/ng/ng_physical_fragment.h" |
| 10 #include "core/layout/ng/ng_length_utils.h" | 10 #include "core/layout/ng/ng_length_utils.h" |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 EXPECT_EQ(NGPhysicalFragmentBase::FragmentBox, frag->Type()); | 576 EXPECT_EQ(NGPhysicalFragmentBase::FragmentBox, frag->Type()); |
| 577 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->WidthOverflow()); | 577 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->WidthOverflow()); |
| 578 ASSERT_EQ(1UL, frag->Children().size()); | 578 ASSERT_EQ(1UL, frag->Children().size()); |
| 579 | 579 |
| 580 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 580 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
| 581 EXPECT_EQ(LayoutUnit(kChildWidth), child->Width()); | 581 EXPECT_EQ(LayoutUnit(kChildWidth), child->Width()); |
| 582 EXPECT_EQ(LayoutUnit(kPaddingLeft + 10), child->LeftOffset()); | 582 EXPECT_EQ(LayoutUnit(kPaddingLeft + 10), child->LeftOffset()); |
| 583 EXPECT_EQ(LayoutUnit(0), child->TopOffset()); | 583 EXPECT_EQ(LayoutUnit(0), child->TopOffset()); |
| 584 } | 584 } |
| 585 | 585 |
| 586 // Verifies that 2 Left/Right float fragments are correctly positioned by the | 586 // Verifies that 3 Left/Right float fragments are correctly positioned by the |
| 587 // algorithm. | 587 // algorithm. |
| 588 // | 588 // |
| 589 // Test case's HTML representation: | 589 // Test case's HTML representation: |
| 590 // <div id="parent" style="width: 200px; height: 200px;"> | 590 // <div id="parent" style="width: 200px; height: 200px;"> |
| 591 // <div style="float:left; width: 30px; height: 30px; | 591 // <div style="float:left; width: 30px; height: 30px; |
| 592 // margin: 15px;"/> <!-- DIV1 --> | 592 // margin-top: 10px;"/> <!-- DIV1 --> |
| 593 // <div style="float:right; width: 30px; height: 30px;"/> <!-- DIV2 --> | 593 // <div style="float:right; width: 50px; height: 50px;"/> <!-- DIV2 --> |
| 594 // <div style="float:left; width: 120px; height: 120px; |
| 595 // margin-left: 30px;"/> <!-- DIV3 --> |
| 594 // </div> | 596 // </div> |
| 595 // | 597 // |
| 596 // Expected: | 598 // Expected: |
| 597 // - Left float(DIV1) is positioned at the left. | 599 // - Left float(DIV1) is positioned at the left. |
| 598 // - Right float(DIV2) is positioned at the right. | 600 // - Right float(DIV2) is positioned at the right. |
| 601 // - Left float(DIV3) is positioned at the left below DIV2. |
| 599 TEST_F(NGBlockLayoutAlgorithmTest, PositionFloatFragments) { | 602 TEST_F(NGBlockLayoutAlgorithmTest, PositionFloatFragments) { |
| 600 const int kDiv1Margin = 10; | 603 const int kDiv1TopMargin = 10; |
| 601 const int kParentSize = 200; | 604 const int kParentSize = 200; |
| 602 const int kSmallDivSize = 30; | 605 const int kDiv1Size = 30; |
| 606 const int kDiv2Size = 50; |
| 607 const int kDiv3Size = kParentSize - kDiv1Size - kDiv2Size; |
| 608 const int kDiv3LeftMargin = kDiv1Size; |
| 609 |
| 610 style_->setHeight(Length(kParentSize, Fixed)); |
| 611 style_->setWidth(Length(kParentSize, Fixed)); |
| 603 | 612 |
| 604 // DIV1 | 613 // DIV1 |
| 605 RefPtr<ComputedStyle> div1_style = ComputedStyle::create(); | 614 RefPtr<ComputedStyle> div1_style = ComputedStyle::create(); |
| 606 div1_style->setWidth(Length(kSmallDivSize, Fixed)); | 615 div1_style->setWidth(Length(kDiv1Size, Fixed)); |
| 607 div1_style->setHeight(Length(kSmallDivSize, Fixed)); | 616 div1_style->setHeight(Length(kDiv1Size, Fixed)); |
| 608 div1_style->setFloating(EFloat::Left); | 617 div1_style->setFloating(EFloat::Left); |
| 609 div1_style->setMarginBottom(Length(kDiv1Margin, Fixed)); | 618 div1_style->setMarginTop(Length(kDiv1TopMargin, Fixed)); |
| 610 div1_style->setMarginTop(Length(kDiv1Margin, Fixed)); | |
| 611 div1_style->setMarginLeft(Length(kDiv1Margin, Fixed)); | |
| 612 div1_style->setMarginRight(Length(kDiv1Margin, Fixed)); | |
| 613 NGBox* div1 = new NGBox(div1_style.get()); | 619 NGBox* div1 = new NGBox(div1_style.get()); |
| 614 | 620 |
| 615 // DIV2 | 621 // DIV2 |
| 616 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 622 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
| 617 div2_style->setWidth(Length(kSmallDivSize, Fixed)); | 623 div2_style->setWidth(Length(kDiv2Size, Fixed)); |
| 618 div2_style->setHeight(Length(kSmallDivSize, Fixed)); | 624 div2_style->setHeight(Length(kDiv2Size, Fixed)); |
| 619 div2_style->setFloating(EFloat::Right); | 625 div2_style->setFloating(EFloat::Right); |
| 620 NGBox* div2 = new NGBox(div2_style.get()); | 626 NGBox* div2 = new NGBox(div2_style.get()); |
| 621 | 627 |
| 628 // DIV3 |
| 629 RefPtr<ComputedStyle> div3_style = ComputedStyle::create(); |
| 630 div3_style->setWidth(Length(kDiv3Size, Fixed)); |
| 631 div3_style->setHeight(Length(kDiv3Size, Fixed)); |
| 632 div3_style->setMarginLeft(Length(kDiv3LeftMargin, Fixed)); |
| 633 div3_style->setFloating(EFloat::Left); |
| 634 NGBox* div3 = new NGBox(div3_style.get()); |
| 635 |
| 622 div1->SetNextSibling(div2); | 636 div1->SetNextSibling(div2); |
| 637 div2->SetNextSibling(div3); |
| 623 | 638 |
| 624 auto* space = new NGConstraintSpace( | 639 auto* space = new NGConstraintSpace( |
| 625 HorizontalTopBottom, LeftToRight, | 640 HorizontalTopBottom, LeftToRight, |
| 626 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); | 641 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); |
| 627 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 642 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
| 628 ASSERT_EQ(frag->Children().size(), 2UL); | 643 ASSERT_EQ(frag->Children().size(), 3UL); |
| 629 | 644 |
| 630 // div1 | 645 // DIV1 |
| 631 const NGPhysicalFragmentBase* child1 = frag->Children()[0]; | 646 const NGPhysicalFragmentBase* child1 = frag->Children()[0]; |
| 632 EXPECT_EQ(kDiv1Margin, child1->TopOffset()); | 647 EXPECT_EQ(kDiv1TopMargin, child1->TopOffset()); |
| 633 EXPECT_EQ(kDiv1Margin, child1->LeftOffset()); | 648 EXPECT_EQ(0, child1->LeftOffset()); |
| 634 | 649 |
| 635 // div2 | 650 // DIV2 |
| 636 const NGPhysicalFragmentBase* child2 = frag->Children()[1]; | 651 const NGPhysicalFragmentBase* child2 = frag->Children()[1]; |
| 637 EXPECT_EQ(0, child2->TopOffset()); | 652 EXPECT_EQ(0, child2->TopOffset()); |
| 638 EXPECT_EQ(kParentSize - kSmallDivSize, child2->LeftOffset()); | 653 EXPECT_EQ(kParentSize - kDiv2Size, child2->LeftOffset()); |
| 654 |
| 655 // DIV3 |
| 656 const NGPhysicalFragmentBase* child3 = frag->Children()[2]; |
| 657 EXPECT_EQ(kDiv2Size, child3->TopOffset()); |
| 658 EXPECT_EQ(kDiv3LeftMargin, child3->LeftOffset()); |
| 639 } | 659 } |
| 640 } // namespace | 660 } // namespace |
| 641 } // namespace blink | 661 } // namespace blink |
| OLD | NEW |