Chromium Code Reviews| 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/dom/NodeComputedStyle.h" | 7 #include "core/dom/NodeComputedStyle.h" |
| 8 #include "core/dom/TagCollection.h" | 8 #include "core/dom/TagCollection.h" |
| 9 #include "core/layout/LayoutTestHelper.h" | 9 #include "core/layout/LayoutTestHelper.h" |
| 10 #include "core/layout/ng/layout_ng_block_flow.h" | 10 #include "core/layout/ng/layout_ng_block_flow.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 bool shrink_to_fit = false, | 34 bool shrink_to_fit = false, |
| 35 LayoutUnit fragmentainer_space_available = LayoutUnit()) { | 35 LayoutUnit fragmentainer_space_available = LayoutUnit()) { |
| 36 NGFragmentationType block_fragmentation = | 36 NGFragmentationType block_fragmentation = |
| 37 fragmentainer_space_available != LayoutUnit() | 37 fragmentainer_space_available != LayoutUnit() |
| 38 ? NGFragmentationType::kFragmentColumn | 38 ? NGFragmentationType::kFragmentColumn |
| 39 : NGFragmentationType::kFragmentNone; | 39 : NGFragmentationType::kFragmentNone; |
| 40 | 40 |
| 41 return NGConstraintSpaceBuilder(writing_mode) | 41 return NGConstraintSpaceBuilder(writing_mode) |
| 42 .SetAvailableSize(size) | 42 .SetAvailableSize(size) |
| 43 .SetPercentageResolutionSize(size) | 43 .SetPercentageResolutionSize(size) |
| 44 .SetInitialContainingBlockSize(size.ConvertToPhysical(writing_mode)) | |
| 44 .SetTextDirection(direction) | 45 .SetTextDirection(direction) |
| 45 .SetIsShrinkToFit(shrink_to_fit) | 46 .SetIsShrinkToFit(shrink_to_fit) |
| 46 .SetFragmentainerSpaceAvailable(fragmentainer_space_available) | 47 .SetFragmentainerSpaceAvailable(fragmentainer_space_available) |
| 47 .SetFragmentationType(block_fragmentation) | 48 .SetFragmentationType(block_fragmentation) |
| 48 .ToConstraintSpace(writing_mode); | 49 .ToConstraintSpace(writing_mode); |
| 49 } | 50 } |
| 50 | 51 |
| 51 typedef bool TestParamLayoutNG; | 52 typedef bool TestParamLayoutNG; |
| 52 class NGBlockLayoutAlgorithmTest | 53 class NGBlockLayoutAlgorithmTest |
| 53 : public ::testing::WithParamInterface<TestParamLayoutNG>, | 54 : public ::testing::WithParamInterface<TestParamLayoutNG>, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 64 | 65 |
| 65 protected: | 66 protected: |
| 66 void SetUp() override { | 67 void SetUp() override { |
| 67 style_ = ComputedStyle::create(); | 68 style_ = ComputedStyle::create(); |
| 68 RenderingTest::SetUp(); | 69 RenderingTest::SetUp(); |
| 69 enableCompositing(); | 70 enableCompositing(); |
| 70 } | 71 } |
| 71 | 72 |
| 72 RefPtr<NGPhysicalBoxFragment> RunBlockLayoutAlgorithm( | 73 RefPtr<NGPhysicalBoxFragment> RunBlockLayoutAlgorithm( |
| 73 NGConstraintSpace* space, | 74 NGConstraintSpace* space, |
| 74 NGBlockNode* first_child) { | 75 NGBlockNode* block) { |
|
Gleb Lanbin
2017/03/01 21:08:42
NGBlockNode* node
we use "node" in most cases.
ht
atotic
2017/03/01 23:07:49
done. I went with node initially, but then thought
| |
| 75 NGBlockNode* node = new NGBlockNode(style_.get()); | |
| 76 node->SetFirstChild(first_child); | |
| 77 | |
| 78 RefPtr<NGLayoutResult> result = | 76 RefPtr<NGLayoutResult> result = |
| 79 NGBlockLayoutAlgorithm(node, space).Layout(); | 77 NGBlockLayoutAlgorithm(block, space).Layout(); |
| 80 | 78 |
| 81 return toNGPhysicalBoxFragment(result->PhysicalFragment().get()); | 79 return toNGPhysicalBoxFragment(result->PhysicalFragment().get()); |
| 82 } | 80 } |
| 83 | 81 |
| 84 std::pair<RefPtr<NGPhysicalBoxFragment>, NGConstraintSpace*> | 82 std::pair<RefPtr<NGPhysicalBoxFragment>, NGConstraintSpace*> |
| 85 RunBlockLayoutAlgorithmForElement(Element* element) { | 83 RunBlockLayoutAlgorithmForElement(Element* element) { |
| 86 LayoutNGBlockFlow* block_flow = | 84 LayoutNGBlockFlow* block_flow = |
| 87 toLayoutNGBlockFlow(element->layoutObject()); | 85 toLayoutNGBlockFlow(element->layoutObject()); |
| 88 NGBlockNode* node = new NGBlockNode(block_flow); | 86 NGBlockNode* node = new NGBlockNode(block_flow); |
| 89 NGConstraintSpace* space = | 87 NGConstraintSpace* space = |
| 90 NGConstraintSpace::CreateFromLayoutObject(*block_flow); | 88 NGConstraintSpace::CreateFromLayoutObject(*block_flow); |
| 91 | 89 |
| 92 RefPtr<NGLayoutResult> result = | 90 RefPtr<NGLayoutResult> result = |
| 93 NGBlockLayoutAlgorithm(node, space).Layout(); | 91 NGBlockLayoutAlgorithm(node, space).Layout(); |
| 94 return std::make_pair( | 92 return std::make_pair( |
| 95 toNGPhysicalBoxFragment(result->PhysicalFragment().get()), space); | 93 toNGPhysicalBoxFragment(result->PhysicalFragment().get()), space); |
| 96 } | 94 } |
| 97 | 95 |
| 98 MinAndMaxContentSizes RunComputeMinAndMax(NGBlockNode* first_child) { | 96 MinAndMaxContentSizes RunComputeMinAndMax(NGBlockNode* node) { |
| 99 // The constraint space is not used for min/max computation, but we need | 97 // The constraint space is not used for min/max computation, but we need |
| 100 // it to create the algorithm. | 98 // it to create the algorithm. |
| 101 NGConstraintSpace* space = | 99 NGConstraintSpace* space = |
| 102 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, | 100 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, |
| 103 NGLogicalSize(LayoutUnit(), LayoutUnit())); | 101 NGLogicalSize(LayoutUnit(), LayoutUnit())); |
| 104 NGBlockNode* node = new NGBlockNode(style_.get()); | |
| 105 node->SetFirstChild(first_child); | |
| 106 | 102 |
| 107 NGBlockLayoutAlgorithm algorithm(node, space); | 103 NGBlockLayoutAlgorithm algorithm(node, space); |
| 108 EXPECT_TRUE(algorithm.ComputeMinAndMaxContentSizes().has_value()); | 104 EXPECT_TRUE(algorithm.ComputeMinAndMaxContentSizes().has_value()); |
| 109 return *algorithm.ComputeMinAndMaxContentSizes(); | 105 return *algorithm.ComputeMinAndMaxContentSizes(); |
| 110 } | 106 } |
| 111 | 107 |
| 112 RefPtr<ComputedStyle> style_; | 108 RefPtr<ComputedStyle> style_; |
| 113 }; | 109 }; |
| 114 | 110 |
| 115 TEST_F(NGBlockLayoutAlgorithmTest, FixedSize) { | 111 TEST_F(NGBlockLayoutAlgorithmTest, FixedSize) { |
| 116 style_->setWidth(Length(30, Fixed)); | 112 setBodyInnerHTML(R"HTML( |
| 117 style_->setHeight(Length(40, Fixed)); | 113 <div id="box" style="width:30px; height:40px"></div> |
| 114 )HTML"); | |
| 118 | 115 |
| 119 auto* space = ConstructConstraintSpace( | 116 auto* space = ConstructConstraintSpace( |
| 120 kHorizontalTopBottom, TextDirection::kLtr, | 117 kHorizontalTopBottom, TextDirection::kLtr, |
| 121 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 118 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
| 122 RefPtr<NGPhysicalFragment> frag = RunBlockLayoutAlgorithm(space, nullptr); | 119 |
| 120 auto* box = new NGBlockNode(getLayoutObjectByElementId("box")); | |
| 121 | |
| 122 RefPtr<NGPhysicalFragment> frag = RunBlockLayoutAlgorithm(space, box); | |
| 123 | 123 |
| 124 EXPECT_EQ(LayoutUnit(30), frag->Width()); | 124 EXPECT_EQ(LayoutUnit(30), frag->Width()); |
| 125 EXPECT_EQ(LayoutUnit(40), frag->Height()); | 125 EXPECT_EQ(LayoutUnit(40), frag->Height()); |
| 126 } | 126 } |
| 127 | 127 |
| 128 // Verifies that two children are laid out with the correct size and position. | 128 // Verifies that two children are laid out with the correct size and position. |
| 129 TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildren) { | 129 TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildren) { |
| 130 setBodyInnerHTML(R"HTML( | |
| 131 <div id="container" style="width: 30px"> | |
| 132 <div style="height: 20px"> | |
| 133 </div> | |
| 134 <div style="height: 30px; margin-top: 5px; margin-bottom: 20px"> | |
| 135 </div> | |
| 136 </div> | |
| 137 )HTML"); | |
| 130 const int kWidth = 30; | 138 const int kWidth = 30; |
|
Gleb Lanbin
2017/03/01 21:08:41
optional
kContainerWidth
kFirstChildHeight
etc
atotic
2017/03/01 23:07:49
ack, but no. It is a fair amount of work, and I do
| |
| 131 const int kHeight1 = 20; | 139 const int kHeight1 = 20; |
| 132 const int kHeight2 = 30; | 140 const int kHeight2 = 30; |
| 133 const int kMarginTop = 5; | 141 const int kMarginTop = 5; |
| 134 const int kMarginBottom = 20; | |
| 135 style_->setWidth(Length(kWidth, Fixed)); | |
| 136 | 142 |
| 137 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); | 143 auto* container = new NGBlockNode(getLayoutObjectByElementId("container")); |
| 138 first_style->setHeight(Length(kHeight1, Fixed)); | |
| 139 NGBlockNode* first_child = new NGBlockNode(first_style.get()); | |
| 140 | |
| 141 RefPtr<ComputedStyle> second_style = ComputedStyle::create(); | |
| 142 second_style->setHeight(Length(kHeight2, Fixed)); | |
| 143 second_style->setMarginTop(Length(kMarginTop, Fixed)); | |
| 144 second_style->setMarginBottom(Length(kMarginBottom, Fixed)); | |
| 145 NGBlockNode* second_child = new NGBlockNode(second_style.get()); | |
| 146 | |
| 147 first_child->SetNextSibling(second_child); | |
| 148 | |
| 149 auto* space = ConstructConstraintSpace( | 144 auto* space = ConstructConstraintSpace( |
| 150 kHorizontalTopBottom, TextDirection::kLtr, | 145 kHorizontalTopBottom, TextDirection::kLtr, |
| 151 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 146 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
| 147 | |
| 152 RefPtr<NGPhysicalBoxFragment> frag = | 148 RefPtr<NGPhysicalBoxFragment> frag = |
| 153 RunBlockLayoutAlgorithm(space, first_child); | 149 RunBlockLayoutAlgorithm(space, container); |
| 154 | 150 |
| 155 EXPECT_EQ(LayoutUnit(kWidth), frag->Width()); | 151 EXPECT_EQ(LayoutUnit(kWidth), frag->Width()); |
| 156 EXPECT_EQ(LayoutUnit(kHeight1 + kHeight2 + kMarginTop), frag->Height()); | 152 EXPECT_EQ(LayoutUnit(kHeight1 + kHeight2 + kMarginTop), frag->Height()); |
| 157 EXPECT_EQ(NGPhysicalFragment::kFragmentBox, frag->Type()); | 153 EXPECT_EQ(NGPhysicalFragment::kFragmentBox, frag->Type()); |
| 158 ASSERT_EQ(frag->Children().size(), 2UL); | 154 ASSERT_EQ(frag->Children().size(), 2UL); |
| 159 | 155 |
| 160 const NGPhysicalFragment* child = frag->Children()[0].get(); | 156 const NGPhysicalFragment* first_child_fragment = frag->Children()[0].get(); |
| 161 EXPECT_EQ(kHeight1, child->Height()); | 157 EXPECT_EQ(kHeight1, first_child_fragment->Height()); |
| 162 EXPECT_EQ(0, child->TopOffset()); | 158 EXPECT_EQ(0, first_child_fragment->TopOffset()); |
| 163 | 159 |
| 164 child = frag->Children()[1].get(); | 160 const NGPhysicalFragment* second_child_fragment = frag->Children()[1].get(); |
| 165 EXPECT_EQ(kHeight2, child->Height()); | 161 EXPECT_EQ(kHeight2, second_child_fragment->Height()); |
| 166 EXPECT_EQ(kHeight1 + kMarginTop, child->TopOffset()); | 162 EXPECT_EQ(kHeight1 + kMarginTop, second_child_fragment->TopOffset()); |
| 167 } | 163 } |
| 168 | 164 |
| 169 // Verifies that a child is laid out correctly if it's writing mode is different | 165 // Verifies that a child is laid out correctly if it's writing mode is different |
| 170 // from the parent's one. | 166 // from the parent's one. |
| 171 // | |
| 172 // Test case's HTML representation: | |
| 173 // <div style="writing-mode: vertical-lr;"> | |
| 174 // <div style="width:50px; | |
| 175 // height: 50px; margin-left: 100px; | |
| 176 // writing-mode: horizontal-tb;"></div> | |
| 177 // </div> | |
| 178 TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildrenWithWritingMode) { | 167 TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildrenWithWritingMode) { |
| 179 const int kWidth = 50; | 168 setBodyInnerHTML(R"HTML( |
| 169 <style> | |
| 170 #div2 { | |
| 171 width: 50px; | |
| 172 height: 50px; | |
| 173 margin-left: 100px; | |
| 174 writing-mode: horizontal-tb; | |
| 175 } | |
| 176 </style> | |
| 177 <div id="container"> | |
| 178 <div id="div1" style="writing-mode: vertical-lr;"> | |
| 179 <div id="div2"> | |
| 180 </div> | |
| 181 </div> | |
| 182 </div> | |
| 183 )HTML"); | |
| 180 const int kHeight = 50; | 184 const int kHeight = 50; |
| 181 const int kMarginLeft = 100; | 185 const int kMarginLeft = 100; |
| 182 | 186 |
| 183 RefPtr<ComputedStyle> div1_style = ComputedStyle::create(); | 187 auto* container = new NGBlockNode(getLayoutObjectByElementId("container")); |
| 184 div1_style->setWritingMode(WritingMode::kVerticalLr); | |
| 185 NGBlockNode* div1 = new NGBlockNode(div1_style.get()); | |
| 186 | |
| 187 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | |
| 188 div2_style->setHeight(Length(kHeight, Fixed)); | |
| 189 div2_style->setWidth(Length(kWidth, Fixed)); | |
| 190 div1_style->setWritingMode(WritingMode::kHorizontalTb); | |
| 191 div2_style->setMarginLeft(Length(kMarginLeft, Fixed)); | |
| 192 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); | |
| 193 | |
| 194 div1->SetFirstChild(div2); | |
| 195 | |
| 196 auto* space = | 188 auto* space = |
| 197 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, | 189 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, |
| 198 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); | 190 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); |
| 199 RefPtr<NGPhysicalBoxFragment> frag = RunBlockLayoutAlgorithm(space, div1); | 191 RefPtr<NGPhysicalBoxFragment> frag = |
| 192 RunBlockLayoutAlgorithm(space, container); | |
| 200 | 193 |
| 201 const NGPhysicalFragment* child = frag->Children()[0].get(); | 194 const NGPhysicalFragment* child = frag->Children()[0].get(); |
| 202 // DIV2 | 195 // DIV2 |
| 203 child = static_cast<const NGPhysicalBoxFragment*>(child)->Children()[0].get(); | 196 child = static_cast<const NGPhysicalBoxFragment*>(child)->Children()[0].get(); |
| 204 | 197 |
| 205 EXPECT_EQ(kHeight, child->Height()); | 198 EXPECT_EQ(kHeight, child->Height()); |
| 206 EXPECT_EQ(0, child->TopOffset()); | 199 EXPECT_EQ(0, child->TopOffset()); |
| 207 EXPECT_EQ(kMarginLeft, child->LeftOffset()); | 200 EXPECT_EQ(kMarginLeft, child->LeftOffset()); |
| 208 } | 201 } |
| 209 | 202 |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 658 auto* p_fragment = | 651 auto* p_fragment = |
| 659 toNGPhysicalBoxFragment(body_fragment->Children()[0].get()); | 652 toNGPhysicalBoxFragment(body_fragment->Children()[0].get()); |
| 660 // Collapsed margins with result = 0. | 653 // Collapsed margins with result = 0. |
| 661 EXPECT_THAT(p_fragment->Offset(), | 654 EXPECT_THAT(p_fragment->Offset(), |
| 662 NGPhysicalOffset(LayoutUnit(20), LayoutUnit(0))); | 655 NGPhysicalOffset(LayoutUnit(20), LayoutUnit(0))); |
| 663 } | 656 } |
| 664 | 657 |
| 665 // Verifies that the margin strut of a child with a different writing mode does | 658 // Verifies that the margin strut of a child with a different writing mode does |
| 666 // not get used in the collapsing margins calculation. | 659 // not get used in the collapsing margins calculation. |
| 667 // | 660 // |
| 668 // Test case's HTML representation: | |
| 669 // <style> | |
| 670 // #div1 { margin-bottom: 10px; height: 60px; writing-mode: vertical-rl; } | |
| 671 // #div2 { margin-left: -20px; width: 10px; } | |
| 672 // #div3 { margin-top: 40px; height: 60px; } | |
| 673 // </style> | |
| 674 // <div id="div1"> | |
| 675 // <div id="div2">vertical</div> | |
| 676 // </div> | |
| 677 // <div id="div3"></div> | |
| 678 // TODO(glebl): Disabled for now. Follow-up with kojii@ on | 661 // TODO(glebl): Disabled for now. Follow-up with kojii@ on |
| 679 // https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=4844 | 662 // https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=4844 |
| 680 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_CollapsingMarginsCase6) { | 663 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_CollapsingMarginsCase6) { |
| 664 setBodyInnerHTML(R"HTML( | |
| 665 <style> | |
| 666 #div1 { | |
| 667 margin-bottom: 10px; | |
| 668 width: 10px; | |
| 669 height: 60px; | |
| 670 writing-mode: vertical-rl; | |
| 671 } | |
| 672 #div2 { margin-left: -20px; width: 10px; } | |
| 673 #div3 { margin-top: 40px; height: 60px; } | |
| 674 </style> | |
| 675 <div id="container" style="width:500px;height:500px"> | |
| 676 <div id="div1"> | |
| 677 <div id="div2">vertical</div> | |
| 678 </div> | |
| 679 <div id="div3"></div> | |
| 680 </div> | |
| 681 )HTML"); | |
| 681 const int kHeight = 60; | 682 const int kHeight = 60; |
| 682 const int kWidth = 10; | |
| 683 const int kMarginBottom = 10; | 683 const int kMarginBottom = 10; |
| 684 const int kMarginLeft = -20; | |
| 685 const int kMarginTop = 40; | 684 const int kMarginTop = 40; |
| 686 | 685 |
| 687 style_->setWidth(Length(500, Fixed)); | 686 auto* container = new NGBlockNode(getLayoutObjectByElementId("container")); |
| 688 style_->setHeight(Length(500, Fixed)); | |
| 689 | |
| 690 // DIV1 | |
| 691 RefPtr<ComputedStyle> div1_style = ComputedStyle::create(); | |
| 692 div1_style->setWidth(Length(kWidth, Fixed)); | |
| 693 div1_style->setHeight(Length(kHeight, Fixed)); | |
| 694 div1_style->setWritingMode(WritingMode::kVerticalRl); | |
| 695 div1_style->setMarginBottom(Length(kMarginBottom, Fixed)); | |
| 696 NGBlockNode* div1 = new NGBlockNode(div1_style.get()); | |
| 697 | |
| 698 // DIV2 | |
| 699 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | |
| 700 div2_style->setWidth(Length(kWidth, Fixed)); | |
| 701 div2_style->setMarginLeft(Length(kMarginLeft, Fixed)); | |
| 702 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); | |
| 703 | |
| 704 // DIV3 | |
| 705 RefPtr<ComputedStyle> div3_style = ComputedStyle::create(); | |
| 706 div3_style->setHeight(Length(kHeight, Fixed)); | |
| 707 div3_style->setMarginTop(Length(kMarginTop, Fixed)); | |
| 708 NGBlockNode* div3 = new NGBlockNode(div3_style.get()); | |
| 709 | |
| 710 div1->SetFirstChild(div2); | |
| 711 div1->SetNextSibling(div3); | |
| 712 | |
| 713 auto* space = | 687 auto* space = |
| 714 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, | 688 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, |
| 715 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); | 689 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); |
| 716 RefPtr<NGPhysicalBoxFragment> frag = RunBlockLayoutAlgorithm(space, div1); | 690 RefPtr<NGPhysicalBoxFragment> frag = |
| 691 RunBlockLayoutAlgorithm(space, container); | |
| 717 | 692 |
| 718 ASSERT_EQ(frag->Children().size(), 2UL); | 693 ASSERT_EQ(frag->Children().size(), 2UL); |
| 719 | 694 |
| 720 const NGPhysicalFragment* child1 = frag->Children()[0].get(); | 695 const NGPhysicalFragment* child1 = frag->Children()[0].get(); |
| 721 EXPECT_EQ(0, child1->TopOffset()); | 696 EXPECT_EQ(0, child1->TopOffset()); |
| 722 EXPECT_EQ(kHeight, child1->Height()); | 697 EXPECT_EQ(kHeight, child1->Height()); |
| 723 | 698 |
| 724 const NGPhysicalFragment* child2 = frag->Children()[1].get(); | 699 const NGPhysicalFragment* child2 = frag->Children()[1].get(); |
| 725 EXPECT_EQ(kHeight + std::max(kMarginBottom, kMarginTop), child2->TopOffset()); | 700 EXPECT_EQ(kHeight + std::max(kMarginBottom, kMarginTop), child2->TopOffset()); |
| 726 } | 701 } |
| 727 | 702 |
| 728 // Verifies that a box's size includes its borders and padding, and that | 703 // Verifies that a box's size includes its borders and padding, and that |
| 729 // children are positioned inside the content box. | 704 // children are positioned inside the content box. |
| 730 // | |
| 731 // Test case's HTML representation: | |
| 732 // <style> | |
| 733 // #div1 { width:100px; height:100px; } | |
| 734 // #div1 { border-style:solid; border-width:1px 2px 3px 4px; } | |
| 735 // #div1 { padding:5px 6px 7px 8px; } | |
| 736 // </style> | |
| 737 // <div id="div1"> | |
| 738 // <div id="div2"></div> | |
| 739 // </div> | |
| 740 TEST_F(NGBlockLayoutAlgorithmTest, BorderAndPadding) { | 705 TEST_F(NGBlockLayoutAlgorithmTest, BorderAndPadding) { |
| 706 setBodyInnerHTML(R"HTML( | |
| 707 <style> | |
| 708 #div1 { | |
| 709 width: 100px; | |
| 710 height: 100px; | |
| 711 border-style: solid; | |
| 712 border-width: 1px 2px 3px 4px; | |
| 713 padding: 5px 6px 7px 8px; | |
| 714 } | |
| 715 </style> | |
| 716 <div id="container"> | |
| 717 <div id="div1"> | |
| 718 <div id="div2"></div> | |
| 719 </div> | |
| 720 </div> | |
| 721 )HTML"); | |
| 741 const int kWidth = 100; | 722 const int kWidth = 100; |
| 742 const int kHeight = 100; | 723 const int kHeight = 100; |
| 743 const int kBorderTop = 1; | 724 const int kBorderTop = 1; |
| 744 const int kBorderRight = 2; | 725 const int kBorderRight = 2; |
| 745 const int kBorderBottom = 3; | 726 const int kBorderBottom = 3; |
| 746 const int kBorderLeft = 4; | 727 const int kBorderLeft = 4; |
| 747 const int kPaddingTop = 5; | 728 const int kPaddingTop = 5; |
| 748 const int kPaddingRight = 6; | 729 const int kPaddingRight = 6; |
| 749 const int kPaddingBottom = 7; | 730 const int kPaddingBottom = 7; |
| 750 const int kPaddingLeft = 8; | 731 const int kPaddingLeft = 8; |
| 751 RefPtr<ComputedStyle> div1_style = ComputedStyle::create(); | |
| 752 | 732 |
| 753 div1_style->setWidth(Length(kWidth, Fixed)); | 733 auto* container = new NGBlockNode(getLayoutObjectByElementId("container")); |
| 754 div1_style->setHeight(Length(kHeight, Fixed)); | |
| 755 | |
| 756 div1_style->setBorderTopWidth(kBorderTop); | |
| 757 div1_style->setBorderTopStyle(BorderStyleSolid); | |
| 758 div1_style->setBorderRightWidth(kBorderRight); | |
| 759 div1_style->setBorderRightStyle(BorderStyleSolid); | |
| 760 div1_style->setBorderBottomWidth(kBorderBottom); | |
| 761 div1_style->setBorderBottomStyle(BorderStyleSolid); | |
| 762 div1_style->setBorderLeftWidth(kBorderLeft); | |
| 763 div1_style->setBorderLeftStyle(BorderStyleSolid); | |
| 764 | |
| 765 div1_style->setPaddingTop(Length(kPaddingTop, Fixed)); | |
| 766 div1_style->setPaddingRight(Length(kPaddingRight, Fixed)); | |
| 767 div1_style->setPaddingBottom(Length(kPaddingBottom, Fixed)); | |
| 768 div1_style->setPaddingLeft(Length(kPaddingLeft, Fixed)); | |
| 769 NGBlockNode* div1 = new NGBlockNode(div1_style.get()); | |
| 770 | |
| 771 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | |
| 772 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); | |
| 773 | |
| 774 div1->SetFirstChild(div2); | |
| 775 | 734 |
| 776 auto* space = ConstructConstraintSpace( | 735 auto* space = ConstructConstraintSpace( |
| 777 kHorizontalTopBottom, TextDirection::kLtr, | 736 kHorizontalTopBottom, TextDirection::kLtr, |
| 778 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); | 737 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); |
| 779 RefPtr<NGPhysicalBoxFragment> frag = RunBlockLayoutAlgorithm(space, div1); | 738 |
| 739 RefPtr<NGPhysicalBoxFragment> frag = | |
| 740 RunBlockLayoutAlgorithm(space, container); | |
| 780 | 741 |
| 781 ASSERT_EQ(frag->Children().size(), 1UL); | 742 ASSERT_EQ(frag->Children().size(), 1UL); |
| 782 | 743 |
| 783 // div1 | 744 // div1 |
| 784 const NGPhysicalFragment* child = frag->Children()[0].get(); | 745 const NGPhysicalFragment* child = frag->Children()[0].get(); |
| 785 EXPECT_EQ(kBorderLeft + kPaddingLeft + kWidth + kPaddingRight + kBorderRight, | 746 EXPECT_EQ(kBorderLeft + kPaddingLeft + kWidth + kPaddingRight + kBorderRight, |
| 786 child->Width()); | 747 child->Width()); |
| 787 EXPECT_EQ(kBorderTop + kPaddingTop + kHeight + kPaddingBottom + kBorderBottom, | 748 EXPECT_EQ(kBorderTop + kPaddingTop + kHeight + kPaddingBottom + kBorderBottom, |
| 788 child->Height()); | 749 child->Height()); |
| 789 | 750 |
| 790 ASSERT_TRUE(child->Type() == NGPhysicalFragment::kFragmentBox); | 751 ASSERT_TRUE(child->Type() == NGPhysicalFragment::kFragmentBox); |
| 791 ASSERT_EQ(static_cast<const NGPhysicalBoxFragment*>(child)->Children().size(), | 752 ASSERT_EQ(static_cast<const NGPhysicalBoxFragment*>(child)->Children().size(), |
| 792 1UL); | 753 1UL); |
| 793 | 754 |
| 794 // div2 | 755 // div2 |
| 795 child = static_cast<const NGPhysicalBoxFragment*>(child)->Children()[0].get(); | 756 child = static_cast<const NGPhysicalBoxFragment*>(child)->Children()[0].get(); |
| 796 EXPECT_EQ(kBorderTop + kPaddingTop, child->TopOffset()); | 757 EXPECT_EQ(kBorderTop + kPaddingTop, child->TopOffset()); |
| 797 EXPECT_EQ(kBorderLeft + kPaddingLeft, child->LeftOffset()); | 758 EXPECT_EQ(kBorderLeft + kPaddingLeft, child->LeftOffset()); |
| 798 } | 759 } |
| 799 | 760 |
| 800 TEST_F(NGBlockLayoutAlgorithmTest, PercentageResolutionSize) { | 761 TEST_F(NGBlockLayoutAlgorithmTest, PercentageResolutionSize) { |
| 762 setBodyInnerHTML(R"HTML( | |
| 763 <div id="container" style="width: 30px; padding-left: 10px"> | |
| 764 <div id="div1" style="width: 40%"></div> | |
| 765 </div> | |
| 766 )HTML"); | |
| 801 const int kPaddingLeft = 10; | 767 const int kPaddingLeft = 10; |
| 802 const int kWidth = 30; | 768 const int kWidth = 30; |
| 803 style_->setWidth(Length(kWidth, Fixed)); | |
| 804 style_->setPaddingLeft(Length(kPaddingLeft, Fixed)); | |
| 805 | 769 |
| 806 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); | 770 auto* container = new NGBlockNode(getLayoutObjectByElementId("container")); |
| 807 first_style->setWidth(Length(40, Percent)); | |
| 808 NGBlockNode* first_child = new NGBlockNode(first_style.get()); | |
| 809 | 771 |
| 810 auto* space = ConstructConstraintSpace( | 772 auto* space = ConstructConstraintSpace( |
| 811 kHorizontalTopBottom, TextDirection::kLtr, | 773 kHorizontalTopBottom, TextDirection::kLtr, |
| 812 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 774 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
| 813 RefPtr<NGPhysicalBoxFragment> frag = | 775 RefPtr<NGPhysicalBoxFragment> frag = |
| 814 RunBlockLayoutAlgorithm(space, first_child); | 776 RunBlockLayoutAlgorithm(space, container); |
| 815 | 777 |
| 816 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width()); | 778 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width()); |
| 817 EXPECT_EQ(NGPhysicalFragment::kFragmentBox, frag->Type()); | 779 EXPECT_EQ(NGPhysicalFragment::kFragmentBox, frag->Type()); |
| 818 ASSERT_EQ(frag->Children().size(), 1UL); | 780 ASSERT_EQ(frag->Children().size(), 1UL); |
| 819 | 781 |
| 820 const NGPhysicalFragment* child = frag->Children()[0].get(); | 782 const NGPhysicalFragment* child = frag->Children()[0].get(); |
| 821 EXPECT_EQ(LayoutUnit(12), child->Width()); | 783 EXPECT_EQ(LayoutUnit(12), child->Width()); |
| 822 } | 784 } |
| 823 | 785 |
| 824 // A very simple auto margin case. We rely on the tests in ng_length_utils_test | 786 // A very simple auto margin case. We rely on the tests in ng_length_utils_test |
| 825 // for the more complex cases; just make sure we handle auto at all here. | 787 // for the more complex cases; just make sure we handle auto at all here. |
| 826 TEST_F(NGBlockLayoutAlgorithmTest, AutoMargin) { | 788 TEST_F(NGBlockLayoutAlgorithmTest, AutoMargin) { |
| 789 setBodyInnerHTML(R"HTML( | |
| 790 <style> | |
| 791 #first { width: 10px; margin-left: auto; margin-right: auto; } | |
| 792 </style> | |
| 793 <div id="container" style="width: 30px; padding-left: 10px"> | |
| 794 <div id="first"> | |
| 795 </div> | |
| 796 </div> | |
| 797 )HTML"); | |
| 827 const int kPaddingLeft = 10; | 798 const int kPaddingLeft = 10; |
| 828 const int kWidth = 30; | 799 const int kWidth = 30; |
| 829 style_->setWidth(Length(kWidth, Fixed)); | 800 const int kChildWidth = 10; |
| 830 style_->setPaddingLeft(Length(kPaddingLeft, Fixed)); | |
| 831 | 801 |
| 832 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); | 802 auto* container = new NGBlockNode(getLayoutObjectByElementId("container")); |
| 833 const int kChildWidth = 10; | |
| 834 first_style->setWidth(Length(kChildWidth, Fixed)); | |
| 835 first_style->setMarginLeft(Length(Auto)); | |
| 836 first_style->setMarginRight(Length(Auto)); | |
| 837 NGBlockNode* first_child = new NGBlockNode(first_style.get()); | |
| 838 | 803 |
| 839 auto* space = ConstructConstraintSpace( | 804 auto* space = ConstructConstraintSpace( |
| 840 kHorizontalTopBottom, TextDirection::kLtr, | 805 kHorizontalTopBottom, TextDirection::kLtr, |
| 841 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 806 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
| 842 RefPtr<NGPhysicalBoxFragment> frag = | 807 RefPtr<NGPhysicalBoxFragment> frag = |
| 843 RunBlockLayoutAlgorithm(space, first_child); | 808 RunBlockLayoutAlgorithm(space, container); |
| 844 | 809 |
| 845 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width()); | 810 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width()); |
| 846 EXPECT_EQ(NGPhysicalFragment::kFragmentBox, frag->Type()); | 811 EXPECT_EQ(NGPhysicalFragment::kFragmentBox, frag->Type()); |
| 847 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->WidthOverflow()); | 812 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->WidthOverflow()); |
| 848 ASSERT_EQ(1UL, frag->Children().size()); | 813 ASSERT_EQ(1UL, frag->Children().size()); |
| 849 | 814 |
| 850 const NGPhysicalFragment* child = frag->Children()[0].get(); | 815 const NGPhysicalFragment* child = frag->Children()[0].get(); |
| 851 EXPECT_EQ(LayoutUnit(kChildWidth), child->Width()); | 816 EXPECT_EQ(LayoutUnit(kChildWidth), child->Width()); |
| 852 EXPECT_EQ(LayoutUnit(kPaddingLeft + 10), child->LeftOffset()); | 817 EXPECT_EQ(LayoutUnit(kPaddingLeft + 10), child->LeftOffset()); |
| 853 EXPECT_EQ(LayoutUnit(0), child->TopOffset()); | 818 EXPECT_EQ(LayoutUnit(0), child->TopOffset()); |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1277 run_with_clearance(EClear::kBoth); | 1242 run_with_clearance(EClear::kBoth); |
| 1278 EXPECT_EQ(LayoutUnit(8), body_fragment->TopOffset()); | 1243 EXPECT_EQ(LayoutUnit(8), body_fragment->TopOffset()); |
| 1279 EXPECT_EQ(LayoutUnit(0), container_fragment->TopOffset()); | 1244 EXPECT_EQ(LayoutUnit(0), container_fragment->TopOffset()); |
| 1280 EXPECT_EQ(LayoutUnit(170), clerance_fragment->TopOffset()); | 1245 EXPECT_EQ(LayoutUnit(170), clerance_fragment->TopOffset()); |
| 1281 EXPECT_EQ(LayoutUnit(270), block_fragment->TopOffset()); | 1246 EXPECT_EQ(LayoutUnit(270), block_fragment->TopOffset()); |
| 1282 EXPECT_EQ(LayoutUnit(370), adjoining_clearance_fragment->TopOffset()); | 1247 EXPECT_EQ(LayoutUnit(370), adjoining_clearance_fragment->TopOffset()); |
| 1283 } | 1248 } |
| 1284 | 1249 |
| 1285 // Verifies that we compute the right min and max-content size. | 1250 // Verifies that we compute the right min and max-content size. |
| 1286 TEST_F(NGBlockLayoutAlgorithmTest, ComputeMinMaxContent) { | 1251 TEST_F(NGBlockLayoutAlgorithmTest, ComputeMinMaxContent) { |
| 1287 const int kWidth = 50; | 1252 setBodyInnerHTML(R"HTML( |
| 1288 const int kWidthChild1 = 20; | 1253 <div id="container" style="width: 50px"> |
| 1254 <div id="first_child" style="width: 20px"></div> | |
|
Gleb Lanbin
2017/03/01 21:08:42
should be first-child, second-child, same below
ht
atotic
2017/03/01 23:07:49
done
| |
| 1255 <div id="second_child" style="width: 30px"></div> | |
| 1256 </div> | |
| 1257 )HTML"); | |
| 1258 | |
| 1289 const int kWidthChild2 = 30; | 1259 const int kWidthChild2 = 30; |
| 1290 | 1260 |
| 1291 // This should have no impact on the min/max content size. | 1261 auto* container = new NGBlockNode(getLayoutObjectByElementId("container")); |
| 1292 style_->setWidth(Length(kWidth, Fixed)); | |
| 1293 | 1262 |
| 1294 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); | 1263 MinAndMaxContentSizes sizes = RunComputeMinAndMax(container); |
| 1295 first_style->setWidth(Length(kWidthChild1, Fixed)); | |
| 1296 NGBlockNode* first_child = new NGBlockNode(first_style.get()); | |
| 1297 | |
| 1298 RefPtr<ComputedStyle> second_style = ComputedStyle::create(); | |
| 1299 second_style->setWidth(Length(kWidthChild2, Fixed)); | |
| 1300 NGBlockNode* second_child = new NGBlockNode(second_style.get()); | |
| 1301 | |
| 1302 first_child->SetNextSibling(second_child); | |
| 1303 | |
| 1304 MinAndMaxContentSizes sizes = RunComputeMinAndMax(first_child); | |
| 1305 EXPECT_EQ(kWidthChild2, sizes.min_content); | 1264 EXPECT_EQ(kWidthChild2, sizes.min_content); |
| 1306 EXPECT_EQ(kWidthChild2, sizes.max_content); | 1265 EXPECT_EQ(kWidthChild2, sizes.max_content); |
| 1307 } | 1266 } |
| 1308 | 1267 |
| 1309 // Tests that we correctly handle shrink-to-fit | 1268 // Tests that we correctly handle shrink-to-fit |
| 1310 TEST_F(NGBlockLayoutAlgorithmTest, ShrinkToFit) { | 1269 TEST_F(NGBlockLayoutAlgorithmTest, ShrinkToFit) { |
| 1311 const int kWidthChild1 = 20; | 1270 setBodyInnerHTML(R"HTML( |
| 1271 <div id="container"> | |
| 1272 <div id="first_child" style="width: 20px"></div> | |
| 1273 <div id="second_child" style="width: 30px"></div> | |
| 1274 </div> | |
| 1275 )HTML"); | |
| 1312 const int kWidthChild2 = 30; | 1276 const int kWidthChild2 = 30; |
|
Gleb Lanbin
2017/03/01 21:08:41
What is Child2? kSecondChildWidth?
atotic
2017/03/01 23:07:49
done. It was existing code, now switched to kSecon
| |
| 1313 | 1277 |
| 1314 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); | 1278 auto* container = new NGBlockNode(getLayoutObjectByElementId("container")); |
| 1315 first_style->setWidth(Length(kWidthChild1, Fixed)); | |
| 1316 NGBlockNode* first_child = new NGBlockNode(first_style.get()); | |
| 1317 | |
| 1318 RefPtr<ComputedStyle> second_style = ComputedStyle::create(); | |
| 1319 second_style->setWidth(Length(kWidthChild2, Fixed)); | |
| 1320 NGBlockNode* second_child = new NGBlockNode(second_style.get()); | |
| 1321 | |
| 1322 first_child->SetNextSibling(second_child); | |
| 1323 | 1279 |
| 1324 auto* space = ConstructConstraintSpace( | 1280 auto* space = ConstructConstraintSpace( |
| 1325 kHorizontalTopBottom, TextDirection::kLtr, | 1281 kHorizontalTopBottom, TextDirection::kLtr, |
| 1326 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite), true); | 1282 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite), true); |
| 1327 RefPtr<NGPhysicalFragment> frag = RunBlockLayoutAlgorithm(space, first_child); | 1283 RefPtr<NGPhysicalFragment> frag = RunBlockLayoutAlgorithm(space, container); |
| 1328 | 1284 |
| 1329 EXPECT_EQ(LayoutUnit(30), frag->Width()); | 1285 EXPECT_EQ(LayoutUnit(kWidthChild2), frag->Width()); |
| 1330 } | 1286 } |
| 1331 | 1287 |
| 1332 class FragmentChildIterator { | 1288 class FragmentChildIterator { |
| 1333 STACK_ALLOCATED(); | 1289 STACK_ALLOCATED(); |
| 1334 | 1290 |
| 1335 public: | 1291 public: |
| 1336 explicit FragmentChildIterator(const NGPhysicalBoxFragment* parent) { | 1292 explicit FragmentChildIterator(const NGPhysicalBoxFragment* parent) { |
| 1337 SetParent(parent); | 1293 SetParent(parent); |
| 1338 } | 1294 } |
| 1339 void SetParent(const NGPhysicalBoxFragment* parent) { | 1295 void SetParent(const NGPhysicalBoxFragment* parent) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1353 return nullptr; | 1309 return nullptr; |
| 1354 } | 1310 } |
| 1355 return toNGPhysicalBoxFragment(parent_->Children()[index_++].get()); | 1311 return toNGPhysicalBoxFragment(parent_->Children()[index_++].get()); |
| 1356 } | 1312 } |
| 1357 | 1313 |
| 1358 private: | 1314 private: |
| 1359 const NGPhysicalBoxFragment* parent_; | 1315 const NGPhysicalBoxFragment* parent_; |
| 1360 unsigned index_; | 1316 unsigned index_; |
| 1361 }; | 1317 }; |
| 1362 | 1318 |
| 1363 // Test case's HTML representation: | |
| 1364 // <div id="parent" style="columns:2; column-fill:auto; column-gap:10px; | |
| 1365 // width:210px; height:100px;"> | |
| 1366 // </div> | |
| 1367 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm | 1319 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm |
| 1368 // is checked in. | 1320 // is checked in. |
| 1369 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_EmptyMulticol) { | 1321 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_EmptyMulticol) { |
| 1370 // parent | 1322 setBodyInnerHTML(R"HTML( |
| 1371 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); | 1323 <style> |
| 1372 parent_style->setColumnCount(2); | 1324 #parent { |
| 1373 parent_style->setColumnFill(ColumnFillAuto); | 1325 column-count: 2; |
| 1374 parent_style->setColumnGap(10); | 1326 column-fill: auto; |
| 1375 parent_style->setHeight(Length(100, Fixed)); | 1327 column-gap: 10px; |
| 1376 parent_style->setWidth(Length(210, Fixed)); | 1328 height: 100px; |
| 1377 NGBlockNode* parent = new NGBlockNode(parent_style.get()); | 1329 width: 210px; |
| 1330 } | |
| 1331 </style> | |
| 1332 <div id="container"> | |
| 1333 <div id="parent"> | |
| 1334 </div> | |
| 1335 </div> | |
| 1336 )HTML"); | |
| 1378 | 1337 |
| 1338 auto* container = new NGBlockNode(getLayoutObjectByElementId("container")); | |
| 1379 auto* space = ConstructConstraintSpace( | 1339 auto* space = ConstructConstraintSpace( |
| 1380 kHorizontalTopBottom, TextDirection::kLtr, | 1340 kHorizontalTopBottom, TextDirection::kLtr, |
| 1381 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); | 1341 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); |
| 1382 RefPtr<const NGPhysicalBoxFragment> parent_fragment = | 1342 RefPtr<const NGPhysicalBoxFragment> parent_fragment = |
| 1383 RunBlockLayoutAlgorithm(space, parent); | 1343 RunBlockLayoutAlgorithm(space, container); |
| 1384 FragmentChildIterator iterator(parent_fragment.get()); | 1344 FragmentChildIterator iterator(parent_fragment.get()); |
| 1385 const auto* fragment = iterator.NextChild(); | 1345 const auto* fragment = iterator.NextChild(); |
| 1386 ASSERT_TRUE(fragment); | 1346 ASSERT_TRUE(fragment); |
| 1387 EXPECT_EQ(LayoutUnit(210), fragment->Width()); | 1347 EXPECT_EQ(LayoutUnit(210), fragment->Width()); |
| 1388 EXPECT_EQ(LayoutUnit(100), fragment->Height()); | 1348 EXPECT_EQ(LayoutUnit(100), fragment->Height()); |
| 1389 EXPECT_FALSE(iterator.NextChild()); | 1349 EXPECT_FALSE(iterator.NextChild()); |
| 1390 | 1350 |
| 1391 // There should be nothing inside the multicol container. | 1351 // There should be nothing inside the multicol container. |
| 1392 EXPECT_FALSE(FragmentChildIterator(fragment).NextChild()); | 1352 EXPECT_FALSE(FragmentChildIterator(fragment).NextChild()); |
| 1393 } | 1353 } |
| 1394 | 1354 |
| 1395 // Test case's HTML representation: | |
| 1396 // <div id="parent" style="columns:2; column-fill:auto; column-gap:10px; | |
| 1397 // width:210px; height:100px;"> | |
| 1398 // <div id="child"></div> | |
| 1399 // </div> | |
| 1400 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm | 1355 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm |
| 1401 // is checked in. | 1356 // is checked in. |
| 1402 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_EmptyBlock) { | 1357 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_EmptyBlock) { |
| 1403 // parent | 1358 setBodyInnerHTML(R"HTML( |
| 1404 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); | 1359 <style> |
| 1405 parent_style->setColumnCount(2); | 1360 #parent { |
| 1406 parent_style->setColumnFill(ColumnFillAuto); | 1361 height: 100px; |
| 1407 parent_style->setColumnGap(10); | 1362 width: 210px; |
| 1408 parent_style->setHeight(Length(100, Fixed)); | 1363 } |
| 1409 parent_style->setWidth(Length(210, Fixed)); | 1364 </style> |
| 1410 NGBlockNode* parent = new NGBlockNode(parent_style.get()); | 1365 <div id="container"> |
| 1366 <div id="parent"> | |
| 1367 <div id="child"> | |
| 1368 </div> | |
| 1369 </div> | |
| 1370 </div> | |
| 1371 )HTML"); | |
| 1411 | 1372 |
| 1412 // child | 1373 auto* container = new NGBlockNode(getLayoutObjectByElementId("container")); |
| 1413 RefPtr<ComputedStyle> child_style = ComputedStyle::create(); | |
| 1414 NGBlockNode* child = new NGBlockNode(child_style.get()); | |
| 1415 | |
| 1416 parent->SetFirstChild(child); | |
| 1417 | |
| 1418 auto* space = ConstructConstraintSpace( | 1374 auto* space = ConstructConstraintSpace( |
| 1419 kHorizontalTopBottom, TextDirection::kLtr, | 1375 kHorizontalTopBottom, TextDirection::kLtr, |
| 1420 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); | 1376 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); |
| 1421 RefPtr<const NGPhysicalBoxFragment> parent_fragment = | 1377 RefPtr<const NGPhysicalBoxFragment> parent_fragment = |
| 1422 RunBlockLayoutAlgorithm(space, parent); | 1378 RunBlockLayoutAlgorithm(space, container); |
| 1423 FragmentChildIterator iterator(parent_fragment.get()); | 1379 FragmentChildIterator iterator(parent_fragment.get()); |
| 1424 const auto* fragment = iterator.NextChild(); | 1380 const auto* fragment = iterator.NextChild(); |
| 1425 EXPECT_EQ(LayoutUnit(210), fragment->Width()); | 1381 EXPECT_EQ(LayoutUnit(210), fragment->Width()); |
| 1426 EXPECT_EQ(LayoutUnit(100), fragment->Height()); | 1382 EXPECT_EQ(LayoutUnit(100), fragment->Height()); |
| 1427 ASSERT_TRUE(fragment); | 1383 ASSERT_TRUE(fragment); |
| 1428 EXPECT_FALSE(iterator.NextChild()); | 1384 EXPECT_FALSE(iterator.NextChild()); |
| 1429 iterator.SetParent(fragment); | 1385 iterator.SetParent(fragment); |
| 1430 | 1386 |
| 1431 // #child fragment in first column | 1387 // #child fragment in first column |
| 1432 fragment = iterator.NextChild(); | 1388 fragment = iterator.NextChild(); |
| 1433 ASSERT_TRUE(fragment); | 1389 ASSERT_TRUE(fragment); |
| 1434 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset()); | 1390 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset()); |
| 1435 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); | 1391 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); |
| 1436 EXPECT_EQ(LayoutUnit(100), fragment->Width()); | 1392 EXPECT_EQ(LayoutUnit(100), fragment->Width()); |
| 1437 EXPECT_EQ(LayoutUnit(), fragment->Height()); | 1393 EXPECT_EQ(LayoutUnit(), fragment->Height()); |
| 1438 EXPECT_EQ(0UL, fragment->Children().size()); | 1394 EXPECT_EQ(0UL, fragment->Children().size()); |
| 1439 EXPECT_FALSE(iterator.NextChild()); | 1395 EXPECT_FALSE(iterator.NextChild()); |
| 1440 } | 1396 } |
| 1441 | 1397 |
| 1442 // Test case's HTML representation: | |
| 1443 // <div id="parent" style="columns:2; column-fill:auto; column-gap:10px; | |
| 1444 // width:310px; height:100px;"> | |
| 1445 // <div id="child" style="width:60%; height:100px;"></div> | |
| 1446 // </div> | |
| 1447 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm | 1398 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm |
| 1448 // is checked in. | 1399 // is checked in. |
| 1449 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_BlockInOneColumn) { | 1400 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_BlockInOneColumn) { |
| 1450 // parent | 1401 setBodyInnerHTML(R"HTML( |
| 1451 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); | 1402 <style> |
| 1452 parent_style->setColumnCount(2); | 1403 #parent { |
| 1453 parent_style->setColumnFill(ColumnFillAuto); | 1404 column-count: 2; |
| 1454 parent_style->setColumnGap(10); | 1405 column-fill: auto; |
| 1455 parent_style->setHeight(Length(100, Fixed)); | 1406 column-gap: 10px; |
| 1456 parent_style->setWidth(Length(310, Fixed)); | 1407 height: 100px; |
| 1457 NGBlockNode* parent = new NGBlockNode(parent_style.get()); | 1408 width: 310px; |
| 1409 } | |
| 1410 </style> | |
| 1411 <div id="container"> | |
| 1412 <div id="parent"> | |
| 1413 <div id="child" style="width: 60%; height: 100%"> | |
| 1414 </div> | |
| 1415 </div> | |
| 1416 </div> | |
| 1417 )HTML"); | |
| 1458 | 1418 |
| 1459 // child | 1419 auto* container = new NGBlockNode(getLayoutObjectByElementId("container")); |
| 1460 RefPtr<ComputedStyle> child_style = ComputedStyle::create(); | |
| 1461 child_style->setWidth(Length(60, Percent)); | |
| 1462 child_style->setHeight(Length(100, Fixed)); | |
| 1463 NGBlockNode* child = new NGBlockNode(child_style.get()); | |
| 1464 | |
| 1465 parent->SetFirstChild(child); | |
| 1466 | |
| 1467 auto* space = ConstructConstraintSpace( | 1420 auto* space = ConstructConstraintSpace( |
| 1468 kHorizontalTopBottom, TextDirection::kLtr, | 1421 kHorizontalTopBottom, TextDirection::kLtr, |
| 1469 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); | 1422 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); |
| 1470 RefPtr<const NGPhysicalBoxFragment> parent_fragment = | 1423 RefPtr<const NGPhysicalBoxFragment> parent_fragment = |
| 1471 RunBlockLayoutAlgorithm(space, parent); | 1424 RunBlockLayoutAlgorithm(space, container); |
| 1472 | 1425 |
| 1473 FragmentChildIterator iterator(parent_fragment.get()); | 1426 FragmentChildIterator iterator(parent_fragment.get()); |
| 1474 const auto* fragment = iterator.NextChild(); | 1427 const auto* fragment = iterator.NextChild(); |
| 1475 ASSERT_TRUE(fragment); | 1428 ASSERT_TRUE(fragment); |
| 1476 EXPECT_EQ(LayoutUnit(310), fragment->Width()); | 1429 EXPECT_EQ(LayoutUnit(310), fragment->Width()); |
| 1477 EXPECT_EQ(LayoutUnit(100), fragment->Height()); | 1430 EXPECT_EQ(LayoutUnit(100), fragment->Height()); |
| 1478 EXPECT_FALSE(iterator.NextChild()); | 1431 EXPECT_FALSE(iterator.NextChild()); |
| 1479 iterator.SetParent(fragment); | 1432 iterator.SetParent(fragment); |
| 1480 | 1433 |
| 1481 // #child fragment in first column | 1434 // #child fragment in first column |
| 1482 fragment = iterator.NextChild(); | 1435 fragment = iterator.NextChild(); |
| 1483 ASSERT_TRUE(fragment); | 1436 ASSERT_TRUE(fragment); |
| 1484 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset()); | 1437 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset()); |
| 1485 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); | 1438 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); |
| 1486 EXPECT_EQ(LayoutUnit(90), fragment->Width()); | 1439 EXPECT_EQ(LayoutUnit(90), fragment->Width()); |
| 1487 EXPECT_EQ(LayoutUnit(100), fragment->Height()); | 1440 EXPECT_EQ(LayoutUnit(100), fragment->Height()); |
| 1488 EXPECT_EQ(0UL, fragment->Children().size()); | 1441 EXPECT_EQ(0UL, fragment->Children().size()); |
| 1489 EXPECT_FALSE(iterator.NextChild()); | 1442 EXPECT_FALSE(iterator.NextChild()); |
| 1490 } | 1443 } |
| 1491 | 1444 |
| 1492 // Test case's HTML representation: | |
| 1493 // <div id="parent" style="columns:2; column-fill:auto; column-gap:10px; | |
| 1494 // width:210px; height:100px;"> | |
| 1495 // <div id="child" style="width:75%; height:150px;"></div> | |
| 1496 // </div> | |
| 1497 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm | 1445 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm |
| 1498 // is checked in. | 1446 // is checked in. |
| 1499 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_BlockInTwoColumns) { | 1447 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_BlockInTwoColumns) { |
| 1500 // parent | 1448 setBodyInnerHTML(R"HTML( |
| 1501 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); | 1449 <style> |
| 1502 parent_style->setColumnCount(2); | 1450 #parent { |
| 1503 parent_style->setColumnFill(ColumnFillAuto); | 1451 column-count: 2; |
| 1504 parent_style->setColumnGap(10); | 1452 column-fill: auto; |
| 1505 parent_style->setHeight(Length(100, Fixed)); | 1453 column-gap: 10px; |
| 1506 parent_style->setWidth(Length(210, Fixed)); | 1454 height: 100px; |
| 1507 NGBlockNode* parent = new NGBlockNode(parent_style.get()); | 1455 width: 20px; |
| 1456 } | |
| 1457 </style> | |
| 1458 <div id="container"> | |
| 1459 <div id="parent"> | |
| 1460 <div id="child" style="width: 75%; height: 150px"></div> | |
| 1461 </div> | |
| 1462 </div> | |
| 1463 )HTML"); | |
| 1508 | 1464 |
| 1509 // child | 1465 auto* container = new NGBlockNode(getLayoutObjectByElementId("container")); |
| 1510 RefPtr<ComputedStyle> child_style = ComputedStyle::create(); | |
| 1511 child_style->setWidth(Length(75, Percent)); | |
| 1512 child_style->setHeight(Length(150, Fixed)); | |
| 1513 NGBlockNode* child = new NGBlockNode(child_style.get()); | |
| 1514 | |
| 1515 parent->SetFirstChild(child); | |
| 1516 | |
| 1517 auto* space = ConstructConstraintSpace( | 1466 auto* space = ConstructConstraintSpace( |
| 1518 kHorizontalTopBottom, TextDirection::kLtr, | 1467 kHorizontalTopBottom, TextDirection::kLtr, |
| 1519 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); | 1468 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); |
| 1520 RefPtr<const NGPhysicalBoxFragment> parent_fragment = | 1469 RefPtr<const NGPhysicalBoxFragment> parent_fragment = |
| 1521 RunBlockLayoutAlgorithm(space, parent); | 1470 RunBlockLayoutAlgorithm(space, container); |
| 1522 | 1471 |
| 1523 FragmentChildIterator iterator(parent_fragment.get()); | 1472 FragmentChildIterator iterator(parent_fragment.get()); |
| 1524 const auto* fragment = iterator.NextChild(); | 1473 const auto* fragment = iterator.NextChild(); |
| 1525 ASSERT_TRUE(fragment); | 1474 ASSERT_TRUE(fragment); |
| 1526 EXPECT_EQ(LayoutUnit(210), fragment->Width()); | 1475 EXPECT_EQ(LayoutUnit(210), fragment->Width()); |
| 1527 EXPECT_EQ(LayoutUnit(100), fragment->Height()); | 1476 EXPECT_EQ(LayoutUnit(100), fragment->Height()); |
| 1528 EXPECT_FALSE(iterator.NextChild()); | 1477 EXPECT_FALSE(iterator.NextChild()); |
| 1529 | 1478 |
| 1530 iterator.SetParent(fragment); | 1479 iterator.SetParent(fragment); |
| 1531 // #child fragment in first column | 1480 // #child fragment in first column |
| 1532 fragment = iterator.NextChild(); | 1481 fragment = iterator.NextChild(); |
| 1533 ASSERT_TRUE(fragment); | 1482 ASSERT_TRUE(fragment); |
| 1534 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset()); | 1483 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset()); |
| 1535 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); | 1484 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); |
| 1536 EXPECT_EQ(LayoutUnit(75), fragment->Width()); | 1485 EXPECT_EQ(LayoutUnit(75), fragment->Width()); |
| 1537 EXPECT_EQ(LayoutUnit(100), fragment->Height()); | 1486 EXPECT_EQ(LayoutUnit(100), fragment->Height()); |
| 1538 EXPECT_EQ(0UL, fragment->Children().size()); | 1487 EXPECT_EQ(0UL, fragment->Children().size()); |
| 1539 | 1488 |
| 1540 // #child fragment in second column | 1489 // #child fragment in second column |
| 1541 fragment = iterator.NextChild(); | 1490 fragment = iterator.NextChild(); |
| 1542 ASSERT_TRUE(fragment); | 1491 ASSERT_TRUE(fragment); |
| 1543 EXPECT_EQ(LayoutUnit(110), fragment->LeftOffset()); | 1492 EXPECT_EQ(LayoutUnit(110), fragment->LeftOffset()); |
| 1544 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); | 1493 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); |
| 1545 EXPECT_EQ(LayoutUnit(75), fragment->Width()); | 1494 EXPECT_EQ(LayoutUnit(75), fragment->Width()); |
| 1546 EXPECT_EQ(LayoutUnit(50), fragment->Height()); | 1495 EXPECT_EQ(LayoutUnit(50), fragment->Height()); |
| 1547 EXPECT_EQ(0U, fragment->Children().size()); | 1496 EXPECT_EQ(0U, fragment->Children().size()); |
| 1548 EXPECT_FALSE(iterator.NextChild()); | 1497 EXPECT_FALSE(iterator.NextChild()); |
| 1549 } | 1498 } |
| 1550 | 1499 |
| 1551 // Test case's HTML representation: | |
| 1552 // <div id="parent" style="columns:3; column-fill:auto; column-gap:10px; | |
| 1553 // width:320px; height:100px;"> | |
| 1554 // <div id="child" style="width:75%; height:250px;"></div> | |
| 1555 // </div> | |
| 1556 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm | 1500 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm |
| 1557 // is checked in. | 1501 // is checked in. |
| 1558 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_BlockInThreeColumns) { | 1502 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_BlockInThreeColumns) { |
| 1559 // parent | 1503 setBodyInnerHTML(R"HTML( |
| 1560 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); | 1504 <style> |
| 1561 parent_style->setColumnCount(3); | 1505 #parent { |
| 1562 parent_style->setColumnFill(ColumnFillAuto); | 1506 column-count: 3; |
| 1563 parent_style->setColumnGap(10); | 1507 column-fill: auto; |
| 1564 parent_style->setHeight(Length(100, Fixed)); | 1508 column-gap: 10px; |
| 1565 parent_style->setWidth(Length(320, Fixed)); | 1509 height: 100px; |
| 1566 NGBlockNode* parent = new NGBlockNode(parent_style.get()); | 1510 width: 320px; |
| 1511 } | |
| 1512 </style> | |
| 1513 <div id="container"> | |
| 1514 <div id="parent"> | |
| 1515 <div id="child" style="width: 75%; height: 250px;"> | |
| 1516 </div> | |
| 1517 </div> | |
| 1518 </div> | |
| 1519 )HTML"); | |
| 1567 | 1520 |
| 1568 // child | 1521 auto* container = new NGBlockNode(getLayoutObjectByElementId("container")); |
| 1569 RefPtr<ComputedStyle> child_style = ComputedStyle::create(); | |
| 1570 child_style->setWidth(Length(75, Percent)); | |
| 1571 child_style->setHeight(Length(250, Fixed)); | |
| 1572 NGBlockNode* child = new NGBlockNode(child_style.get()); | |
| 1573 | |
| 1574 parent->SetFirstChild(child); | |
| 1575 | |
| 1576 auto* space = ConstructConstraintSpace( | 1522 auto* space = ConstructConstraintSpace( |
| 1577 kHorizontalTopBottom, TextDirection::kLtr, | 1523 kHorizontalTopBottom, TextDirection::kLtr, |
| 1578 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); | 1524 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); |
| 1579 RefPtr<const NGPhysicalBoxFragment> parent_fragment = | 1525 RefPtr<const NGPhysicalBoxFragment> parent_fragment = |
| 1580 RunBlockLayoutAlgorithm(space, parent); | 1526 RunBlockLayoutAlgorithm(space, container); |
| 1581 | 1527 |
| 1582 FragmentChildIterator iterator(parent_fragment.get()); | 1528 FragmentChildIterator iterator(parent_fragment.get()); |
| 1583 const auto* fragment = iterator.NextChild(); | 1529 const auto* fragment = iterator.NextChild(); |
| 1584 ASSERT_TRUE(fragment); | 1530 ASSERT_TRUE(fragment); |
| 1585 EXPECT_EQ(LayoutUnit(320), fragment->Width()); | 1531 EXPECT_EQ(LayoutUnit(320), fragment->Width()); |
| 1586 EXPECT_EQ(LayoutUnit(100), fragment->Height()); | 1532 EXPECT_EQ(LayoutUnit(100), fragment->Height()); |
| 1587 EXPECT_FALSE(iterator.NextChild()); | 1533 EXPECT_FALSE(iterator.NextChild()); |
| 1588 | 1534 |
| 1589 iterator.SetParent(fragment); | 1535 iterator.SetParent(fragment); |
| 1590 // #child fragment in first column | 1536 // #child fragment in first column |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1609 fragment = iterator.NextChild(); | 1555 fragment = iterator.NextChild(); |
| 1610 ASSERT_TRUE(fragment); | 1556 ASSERT_TRUE(fragment); |
| 1611 EXPECT_EQ(LayoutUnit(220), fragment->LeftOffset()); | 1557 EXPECT_EQ(LayoutUnit(220), fragment->LeftOffset()); |
| 1612 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); | 1558 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); |
| 1613 EXPECT_EQ(LayoutUnit(75), fragment->Width()); | 1559 EXPECT_EQ(LayoutUnit(75), fragment->Width()); |
| 1614 EXPECT_EQ(LayoutUnit(50), fragment->Height()); | 1560 EXPECT_EQ(LayoutUnit(50), fragment->Height()); |
| 1615 EXPECT_EQ(0U, fragment->Children().size()); | 1561 EXPECT_EQ(0U, fragment->Children().size()); |
| 1616 EXPECT_FALSE(iterator.NextChild()); | 1562 EXPECT_FALSE(iterator.NextChild()); |
| 1617 } | 1563 } |
| 1618 | 1564 |
| 1619 // Test case's HTML representation: | |
| 1620 // <div id="parent" style="columns:2; column-fill:auto; column-gap:10px; | |
| 1621 // width:210px; height:100px;"> | |
| 1622 // <div id="child" style="width:1px; height:250px;"></div> | |
| 1623 // </div> | |
| 1624 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm | 1565 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm |
| 1625 // is checked in. | 1566 // is checked in. |
| 1626 TEST_F(NGBlockLayoutAlgorithmTest, | 1567 TEST_F(NGBlockLayoutAlgorithmTest, |
| 1627 DISABLED_ActualColumnCountGreaterThanSpecified) { | 1568 DISABLED_ActualColumnCountGreaterThanSpecified) { |
| 1628 // parent | 1569 setBodyInnerHTML(R"HTML( |
| 1629 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); | 1570 <style> |
| 1630 parent_style->setColumnCount(2); | 1571 #parent { |
| 1631 parent_style->setColumnFill(ColumnFillAuto); | 1572 column-count: 2; |
| 1632 parent_style->setColumnGap(10); | 1573 column-fill: auto; |
| 1633 parent_style->setHeight(Length(100, Fixed)); | 1574 column-gap: 10px; |
| 1634 parent_style->setWidth(Length(210, Fixed)); | 1575 height: 100px; |
| 1635 NGBlockNode* parent = new NGBlockNode(parent_style.get()); | 1576 width: 210px; |
| 1577 } | |
| 1578 </style> | |
| 1579 <div id="container"> | |
| 1580 <div id="parent"> | |
| 1581 <div id="child" style="width: 1px; height: 250px;"> | |
| 1582 </div> | |
| 1583 </div> | |
| 1584 </div> | |
| 1585 )HTML"); | |
| 1636 | 1586 |
| 1637 // child | 1587 auto* container = new NGBlockNode(getLayoutObjectByElementId("container")); |
| 1638 RefPtr<ComputedStyle> child_style = ComputedStyle::create(); | |
| 1639 child_style->setWidth(Length(1, Fixed)); | |
| 1640 child_style->setHeight(Length(250, Fixed)); | |
| 1641 NGBlockNode* child = new NGBlockNode(child_style.get()); | |
| 1642 | |
| 1643 parent->SetFirstChild(child); | |
| 1644 | |
| 1645 auto* space = ConstructConstraintSpace( | 1588 auto* space = ConstructConstraintSpace( |
| 1646 kHorizontalTopBottom, TextDirection::kLtr, | 1589 kHorizontalTopBottom, TextDirection::kLtr, |
| 1647 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); | 1590 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); |
| 1648 RefPtr<const NGPhysicalBoxFragment> parent_fragment = | 1591 RefPtr<const NGPhysicalBoxFragment> parent_fragment = |
| 1649 RunBlockLayoutAlgorithm(space, parent); | 1592 RunBlockLayoutAlgorithm(space, container); |
| 1650 | 1593 |
| 1651 FragmentChildIterator iterator(parent_fragment.get()); | 1594 FragmentChildIterator iterator(parent_fragment.get()); |
| 1652 const auto* fragment = iterator.NextChild(); | 1595 const auto* fragment = iterator.NextChild(); |
| 1653 ASSERT_TRUE(fragment); | 1596 ASSERT_TRUE(fragment); |
| 1654 EXPECT_EQ(LayoutUnit(210), fragment->Width()); | 1597 EXPECT_EQ(LayoutUnit(210), fragment->Width()); |
| 1655 EXPECT_EQ(LayoutUnit(100), fragment->Height()); | 1598 EXPECT_EQ(LayoutUnit(100), fragment->Height()); |
| 1656 EXPECT_FALSE(iterator.NextChild()); | 1599 EXPECT_FALSE(iterator.NextChild()); |
| 1657 | 1600 |
| 1658 iterator.SetParent(fragment); | 1601 iterator.SetParent(fragment); |
| 1659 // #child fragment in first column | 1602 // #child fragment in first column |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1678 fragment = iterator.NextChild(); | 1621 fragment = iterator.NextChild(); |
| 1679 ASSERT_TRUE(fragment); | 1622 ASSERT_TRUE(fragment); |
| 1680 EXPECT_EQ(LayoutUnit(220), fragment->LeftOffset()); | 1623 EXPECT_EQ(LayoutUnit(220), fragment->LeftOffset()); |
| 1681 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); | 1624 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); |
| 1682 EXPECT_EQ(LayoutUnit(1), fragment->Width()); | 1625 EXPECT_EQ(LayoutUnit(1), fragment->Width()); |
| 1683 EXPECT_EQ(LayoutUnit(50), fragment->Height()); | 1626 EXPECT_EQ(LayoutUnit(50), fragment->Height()); |
| 1684 EXPECT_EQ(0U, fragment->Children().size()); | 1627 EXPECT_EQ(0U, fragment->Children().size()); |
| 1685 EXPECT_FALSE(iterator.NextChild()); | 1628 EXPECT_FALSE(iterator.NextChild()); |
| 1686 } | 1629 } |
| 1687 | 1630 |
| 1688 // Test case's HTML representation: | |
| 1689 // <div id="parent" style="columns:3; column-fill:auto; column-gap:10px; | |
| 1690 // width:320px; height:100px;"> | |
| 1691 // <div id="child1" style="width:75%; height:60px;"></div> | |
| 1692 // <div id="child2" style="width:85%; height:60px;"></div> | |
| 1693 // </div> | |
| 1694 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm | 1631 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm |
| 1695 // is checked in. | 1632 // is checked in. |
| 1696 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_TwoBlocksInTwoColumns) { | 1633 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_TwoBlocksInTwoColumns) { |
| 1697 // parent | 1634 setBodyInnerHTML(R"HTML( |
| 1698 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); | 1635 <style> |
| 1699 parent_style->setColumnCount(3); | 1636 #parent { |
| 1700 parent_style->setColumnFill(ColumnFillAuto); | 1637 column-count: 3; |
| 1701 parent_style->setColumnGap(10); | 1638 column-fill: auto; |
| 1702 parent_style->setHeight(Length(100, Fixed)); | 1639 column-gap: 10px; |
| 1703 parent_style->setWidth(Length(320, Fixed)); | 1640 height: 100px; |
| 1704 NGBlockNode* parent = new NGBlockNode(parent_style.get()); | 1641 width: 320px; |
| 1642 } | |
| 1643 </style> | |
| 1644 <div id="container"> | |
| 1645 <div id="parent"> | |
| 1646 <div id="child1" style="width: 75%; height: 60px;"> | |
| 1647 </div> | |
| 1648 <div id="child2" style="width: 85%; height: 60px;"> | |
| 1649 </div> | |
| 1650 </div> | |
| 1651 </div> | |
| 1652 )HTML"); | |
| 1705 | 1653 |
| 1706 // child1 | 1654 auto* container = new NGBlockNode(getLayoutObjectByElementId("container")); |
| 1707 RefPtr<ComputedStyle> child1_style = ComputedStyle::create(); | |
| 1708 child1_style->setWidth(Length(75, Percent)); | |
| 1709 child1_style->setHeight(Length(60, Fixed)); | |
| 1710 NGBlockNode* child1 = new NGBlockNode(child1_style.get()); | |
| 1711 | |
| 1712 // child2 | |
| 1713 RefPtr<ComputedStyle> child2_style = ComputedStyle::create(); | |
| 1714 child2_style->setWidth(Length(85, Percent)); | |
| 1715 child2_style->setHeight(Length(60, Fixed)); | |
| 1716 NGBlockNode* child2 = new NGBlockNode(child2_style.get()); | |
| 1717 | |
| 1718 parent->SetFirstChild(child1); | |
| 1719 child1->SetNextSibling(child2); | |
| 1720 | |
| 1721 auto* space = ConstructConstraintSpace( | 1655 auto* space = ConstructConstraintSpace( |
| 1722 kHorizontalTopBottom, TextDirection::kLtr, | 1656 kHorizontalTopBottom, TextDirection::kLtr, |
| 1723 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); | 1657 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); |
| 1724 RefPtr<const NGPhysicalBoxFragment> parent_fragment = | 1658 RefPtr<const NGPhysicalBoxFragment> parent_fragment = |
| 1725 RunBlockLayoutAlgorithm(space, parent); | 1659 RunBlockLayoutAlgorithm(space, container); |
| 1726 | 1660 |
| 1727 FragmentChildIterator iterator(parent_fragment.get()); | 1661 FragmentChildIterator iterator(parent_fragment.get()); |
| 1728 const auto* fragment = iterator.NextChild(); | 1662 const auto* fragment = iterator.NextChild(); |
| 1729 ASSERT_TRUE(fragment); | 1663 ASSERT_TRUE(fragment); |
| 1730 EXPECT_EQ(LayoutUnit(320), fragment->Width()); | 1664 EXPECT_EQ(LayoutUnit(320), fragment->Width()); |
| 1731 EXPECT_EQ(LayoutUnit(100), fragment->Height()); | 1665 EXPECT_EQ(LayoutUnit(100), fragment->Height()); |
| 1732 EXPECT_FALSE(iterator.NextChild()); | 1666 EXPECT_FALSE(iterator.NextChild()); |
| 1733 | 1667 |
| 1734 iterator.SetParent(fragment); | 1668 iterator.SetParent(fragment); |
| 1735 // #child1 fragment in first column | 1669 // #child1 fragment in first column |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1753 fragment = iterator.NextChild(); | 1687 fragment = iterator.NextChild(); |
| 1754 ASSERT_TRUE(fragment); | 1688 ASSERT_TRUE(fragment); |
| 1755 EXPECT_EQ(LayoutUnit(110), fragment->LeftOffset()); | 1689 EXPECT_EQ(LayoutUnit(110), fragment->LeftOffset()); |
| 1756 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); | 1690 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); |
| 1757 EXPECT_EQ(LayoutUnit(85), fragment->Width()); | 1691 EXPECT_EQ(LayoutUnit(85), fragment->Width()); |
| 1758 EXPECT_EQ(LayoutUnit(20), fragment->Height()); | 1692 EXPECT_EQ(LayoutUnit(20), fragment->Height()); |
| 1759 EXPECT_EQ(0U, fragment->Children().size()); | 1693 EXPECT_EQ(0U, fragment->Children().size()); |
| 1760 EXPECT_FALSE(iterator.NextChild()); | 1694 EXPECT_FALSE(iterator.NextChild()); |
| 1761 } | 1695 } |
| 1762 | 1696 |
| 1763 // Test case's HTML representation: | |
| 1764 // <div id="parent" style="columns:3; column-fill:auto; column-gap:10px; | |
| 1765 // width:320px; height:100px;"> | |
| 1766 // <div id="child1" style="width:75%; height:60px;"> | |
| 1767 // <div id="grandchild1" style="width:50px; height:120px;"></div> | |
| 1768 // <div id="grandchild2" style="width:40px; height:20px;"></div> | |
| 1769 // </div> | |
| 1770 // <div id="child2" style="width:85%; height:10px;"></div> | |
| 1771 // </div> | |
| 1772 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm | 1697 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm |
| 1773 // is checked in. | 1698 // is checked in. |
| 1774 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_OverflowedBlock) { | 1699 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_OverflowedBlock) { |
| 1775 // parent | 1700 setBodyInnerHTML(R"HTML( |
| 1776 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); | 1701 <style> |
| 1777 parent_style->setColumnCount(3); | 1702 #parent { |
| 1778 parent_style->setColumnFill(ColumnFillAuto); | 1703 column-count: 2; |
| 1779 parent_style->setColumnGap(10); | 1704 column-fill: auto; |
| 1780 parent_style->setHeight(Length(100, Fixed)); | 1705 column-gap: 10px; |
| 1781 parent_style->setWidth(Length(320, Fixed)); | 1706 height: 100px; |
| 1782 NGBlockNode* parent = new NGBlockNode(parent_style.get()); | 1707 width: 320px; |
| 1708 } | |
| 1709 </style> | |
| 1710 <div id="container"> | |
| 1711 <div id="parent"> | |
| 1712 <div id="child1" style="width: 75%; height: 60px;"> | |
| 1713 <div id="grandchild1" style="width: 50px; height: 120px;"> | |
| 1714 </div> | |
| 1715 <div id="grandchild2" style="width: 40px; height: 20px;"> | |
| 1716 </div> | |
| 1717 </div> | |
| 1718 <div id="child2" style="width: 85%; height: 10px;"></div> | |
| 1719 </div> | |
| 1720 </div> | |
| 1721 </div> | |
| 1722 )HTML"); | |
| 1783 | 1723 |
| 1784 // child1 | 1724 auto* container = new NGBlockNode(getLayoutObjectByElementId("container")); |
| 1785 RefPtr<ComputedStyle> child1_style = ComputedStyle::create(); | |
| 1786 child1_style->setWidth(Length(75, Percent)); | |
| 1787 child1_style->setHeight(Length(60, Fixed)); | |
| 1788 NGBlockNode* child1 = new NGBlockNode(child1_style.get()); | |
| 1789 | |
| 1790 // grandchild1 | |
| 1791 RefPtr<ComputedStyle> grandchild1_style = ComputedStyle::create(); | |
| 1792 grandchild1_style->setWidth(Length(50, Fixed)); | |
| 1793 grandchild1_style->setHeight(Length(120, Fixed)); | |
| 1794 NGBlockNode* grandchild1 = new NGBlockNode(grandchild1_style.get()); | |
| 1795 | |
| 1796 // grandchild2 | |
| 1797 RefPtr<ComputedStyle> grandchild2_style = ComputedStyle::create(); | |
| 1798 grandchild2_style->setWidth(Length(40, Fixed)); | |
| 1799 grandchild2_style->setHeight(Length(20, Fixed)); | |
| 1800 NGBlockNode* grandchild2 = new NGBlockNode(grandchild2_style.get()); | |
| 1801 | |
| 1802 // child2 | |
| 1803 RefPtr<ComputedStyle> child2_style = ComputedStyle::create(); | |
| 1804 child2_style->setWidth(Length(85, Percent)); | |
| 1805 child2_style->setHeight(Length(10, Fixed)); | |
| 1806 NGBlockNode* child2 = new NGBlockNode(child2_style.get()); | |
| 1807 | |
| 1808 parent->SetFirstChild(child1); | |
| 1809 child1->SetNextSibling(child2); | |
| 1810 child1->SetFirstChild(grandchild1); | |
| 1811 grandchild1->SetNextSibling(grandchild2); | |
| 1812 | |
| 1813 auto* space = ConstructConstraintSpace( | 1725 auto* space = ConstructConstraintSpace( |
| 1814 kHorizontalTopBottom, TextDirection::kLtr, | 1726 kHorizontalTopBottom, TextDirection::kLtr, |
| 1815 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); | 1727 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); |
| 1816 RefPtr<const NGPhysicalBoxFragment> parent_fragment = | 1728 RefPtr<const NGPhysicalBoxFragment> parent_fragment = |
| 1817 RunBlockLayoutAlgorithm(space, parent); | 1729 RunBlockLayoutAlgorithm(space, container); |
| 1818 | 1730 |
| 1819 FragmentChildIterator iterator(parent_fragment.get()); | 1731 FragmentChildIterator iterator(parent_fragment.get()); |
| 1820 const auto* fragment = iterator.NextChild(); | 1732 const auto* fragment = iterator.NextChild(); |
| 1821 ASSERT_TRUE(fragment); | 1733 ASSERT_TRUE(fragment); |
| 1822 EXPECT_EQ(LayoutUnit(320), fragment->Width()); | 1734 EXPECT_EQ(LayoutUnit(320), fragment->Width()); |
| 1823 EXPECT_EQ(LayoutUnit(100), fragment->Height()); | 1735 EXPECT_EQ(LayoutUnit(100), fragment->Height()); |
| 1824 EXPECT_FALSE(iterator.NextChild()); | 1736 EXPECT_FALSE(iterator.NextChild()); |
| 1825 | 1737 |
| 1826 iterator.SetParent(fragment); | 1738 iterator.SetParent(fragment); |
| 1827 // #child1 fragment in first column | 1739 // #child1 fragment in first column |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1868 fragment = grandchild_iterator.NextChild(); | 1780 fragment = grandchild_iterator.NextChild(); |
| 1869 ASSERT_TRUE(fragment); | 1781 ASSERT_TRUE(fragment); |
| 1870 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset()); | 1782 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset()); |
| 1871 EXPECT_EQ(LayoutUnit(20), fragment->TopOffset()); | 1783 EXPECT_EQ(LayoutUnit(20), fragment->TopOffset()); |
| 1872 EXPECT_EQ(LayoutUnit(40), fragment->Width()); | 1784 EXPECT_EQ(LayoutUnit(40), fragment->Width()); |
| 1873 EXPECT_EQ(LayoutUnit(20), fragment->Height()); | 1785 EXPECT_EQ(LayoutUnit(20), fragment->Height()); |
| 1874 EXPECT_FALSE(grandchild_iterator.NextChild()); | 1786 EXPECT_FALSE(grandchild_iterator.NextChild()); |
| 1875 EXPECT_FALSE(iterator.NextChild()); | 1787 EXPECT_FALSE(iterator.NextChild()); |
| 1876 } | 1788 } |
| 1877 | 1789 |
| 1878 // Test case's HTML representation: | |
| 1879 // <div id="parent" style="columns:3; column-fill:auto; column-gap:10px; | |
| 1880 // width:320px; height:100px;"> | |
| 1881 // <div id="child" style="float:left; width:75%; height:100px;"></div> | |
| 1882 // </div> | |
| 1883 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm | 1790 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm |
| 1884 // is checked in. | 1791 // is checked in. |
| 1885 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_FloatInOneColumn) { | 1792 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_FloatInOneColumn) { |
| 1886 // parent | 1793 setBodyInnerHTML(R"HTML( |
| 1887 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); | 1794 <style> |
| 1888 parent_style->setColumnCount(3); | 1795 #parent { |
| 1889 parent_style->setColumnFill(ColumnFillAuto); | 1796 column-count: 3; |
| 1890 parent_style->setColumnGap(10); | 1797 column-fill: auto; |
| 1891 parent_style->setHeight(Length(100, Fixed)); | 1798 column-gap: 10px; |
| 1892 parent_style->setWidth(Length(320, Fixed)); | 1799 height: 100px; |
| 1893 NGBlockNode* parent = new NGBlockNode(parent_style.get()); | 1800 width: 320px; |
| 1801 } | |
| 1802 </style> | |
| 1803 <div id="container"> | |
| 1804 <div id="parent"> | |
| 1805 <div id="child" style="float: left; width: 75%; height: 100px;"> | |
| 1806 </div> | |
| 1807 </div> | |
| 1808 </div> | |
| 1809 )HTML"); | |
| 1894 | 1810 |
| 1895 // child | 1811 auto* container = new NGBlockNode(getLayoutObjectByElementId("container")); |
| 1896 RefPtr<ComputedStyle> child_style = ComputedStyle::create(); | |
| 1897 child_style->setFloating(EFloat::kLeft); | |
| 1898 child_style->setWidth(Length(75, Percent)); | |
| 1899 child_style->setHeight(Length(100, Fixed)); | |
| 1900 NGBlockNode* child = new NGBlockNode(child_style.get()); | |
| 1901 | |
| 1902 parent->SetFirstChild(child); | |
| 1903 | |
| 1904 auto* space = ConstructConstraintSpace( | 1812 auto* space = ConstructConstraintSpace( |
| 1905 kHorizontalTopBottom, TextDirection::kLtr, | 1813 kHorizontalTopBottom, TextDirection::kLtr, |
| 1906 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); | 1814 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); |
| 1907 RefPtr<const NGPhysicalBoxFragment> parent_fragment = | 1815 RefPtr<const NGPhysicalBoxFragment> parent_fragment = |
| 1908 RunBlockLayoutAlgorithm(space, parent); | 1816 RunBlockLayoutAlgorithm(space, container); |
| 1909 | 1817 |
| 1910 FragmentChildIterator iterator(parent_fragment.get()); | 1818 FragmentChildIterator iterator(parent_fragment.get()); |
| 1911 const auto* fragment = iterator.NextChild(); | 1819 const auto* fragment = iterator.NextChild(); |
| 1912 ASSERT_TRUE(fragment); | 1820 ASSERT_TRUE(fragment); |
| 1913 EXPECT_EQ(LayoutUnit(320), fragment->Width()); | 1821 EXPECT_EQ(LayoutUnit(320), fragment->Width()); |
| 1914 EXPECT_EQ(LayoutUnit(100), fragment->Height()); | 1822 EXPECT_EQ(LayoutUnit(100), fragment->Height()); |
| 1915 EXPECT_FALSE(iterator.NextChild()); | 1823 EXPECT_FALSE(iterator.NextChild()); |
| 1916 | 1824 |
| 1917 iterator.SetParent(fragment); | 1825 iterator.SetParent(fragment); |
| 1918 // #child fragment in first column | 1826 // #child fragment in first column |
| 1919 fragment = iterator.NextChild(); | 1827 fragment = iterator.NextChild(); |
| 1920 ASSERT_TRUE(fragment); | 1828 ASSERT_TRUE(fragment); |
| 1921 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset()); | 1829 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset()); |
| 1922 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); | 1830 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); |
| 1923 EXPECT_EQ(LayoutUnit(75), fragment->Width()); | 1831 EXPECT_EQ(LayoutUnit(75), fragment->Width()); |
| 1924 EXPECT_EQ(LayoutUnit(100), fragment->Height()); | 1832 EXPECT_EQ(LayoutUnit(100), fragment->Height()); |
| 1925 EXPECT_EQ(0UL, fragment->Children().size()); | 1833 EXPECT_EQ(0UL, fragment->Children().size()); |
| 1926 EXPECT_FALSE(iterator.NextChild()); | 1834 EXPECT_FALSE(iterator.NextChild()); |
| 1927 } | 1835 } |
| 1928 | 1836 |
| 1929 // Test case's HTML representation: | |
| 1930 // <div id="parent" style="columns:3; column-fill:auto; column-gap:10px; | |
| 1931 // width:320px; height:100px;"> | |
| 1932 // <div id="child1" style="float:left; width:15%; height:100px;"></div> | |
| 1933 // <div id="child2" style="float:right; width:16%; height:100px;"></div> | |
| 1934 // </div> | |
| 1935 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm | 1837 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm |
| 1936 // is checked in. | 1838 // is checked in. |
| 1937 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_TwoFloatsInOneColumn) { | 1839 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_TwoFloatsInOneColumn) { |
| 1938 // parent | 1840 setBodyInnerHTML(R"HTML( |
| 1939 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); | 1841 <style> |
| 1940 parent_style->setColumnCount(3); | 1842 #parent { |
| 1941 parent_style->setColumnFill(ColumnFillAuto); | 1843 column-count: 3; |
| 1942 parent_style->setColumnGap(10); | 1844 column-fill: auto; |
| 1943 parent_style->setHeight(Length(100, Fixed)); | 1845 column-gap: 10px; |
| 1944 parent_style->setWidth(Length(320, Fixed)); | 1846 width: 320px; |
| 1945 NGBlockNode* parent = new NGBlockNode(parent_style.get()); | 1847 height: 100px; |
| 1848 } | |
| 1849 </style> | |
| 1850 <div id="container"> | |
| 1851 <div id="parent"> | |
| 1852 <div id="child1" style="float: left; width: 15%; height: 100px;"> | |
| 1853 </div> | |
| 1854 <div id="child2" style="float: right; width: 16%; height: 100px;"> | |
| 1855 </div> | |
| 1856 </div> | |
| 1857 </div> | |
| 1858 )HTML"); | |
| 1946 | 1859 |
| 1947 // child1 | 1860 auto* container = new NGBlockNode(getLayoutObjectByElementId("container")); |
| 1948 RefPtr<ComputedStyle> child1_style = ComputedStyle::create(); | |
| 1949 child1_style->setFloating(EFloat::kLeft); | |
| 1950 child1_style->setWidth(Length(15, Percent)); | |
| 1951 child1_style->setHeight(Length(100, Fixed)); | |
| 1952 NGBlockNode* child1 = new NGBlockNode(child1_style.get()); | |
| 1953 | |
| 1954 // child2 | |
| 1955 RefPtr<ComputedStyle> child2_style = ComputedStyle::create(); | |
| 1956 child2_style->setFloating(EFloat::kRight); | |
| 1957 child2_style->setWidth(Length(16, Percent)); | |
| 1958 child2_style->setHeight(Length(100, Fixed)); | |
| 1959 NGBlockNode* child2 = new NGBlockNode(child2_style.get()); | |
| 1960 | |
| 1961 parent->SetFirstChild(child1); | |
| 1962 child1->SetNextSibling(child2); | |
| 1963 | |
| 1964 auto* space = ConstructConstraintSpace( | 1861 auto* space = ConstructConstraintSpace( |
| 1965 kHorizontalTopBottom, TextDirection::kLtr, | 1862 kHorizontalTopBottom, TextDirection::kLtr, |
| 1966 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); | 1863 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); |
| 1967 RefPtr<const NGPhysicalBoxFragment> parent_fragment = | 1864 RefPtr<const NGPhysicalBoxFragment> parent_fragment = |
| 1968 RunBlockLayoutAlgorithm(space, parent); | 1865 RunBlockLayoutAlgorithm(space, container); |
| 1969 | 1866 |
| 1970 FragmentChildIterator iterator(parent_fragment.get()); | 1867 FragmentChildIterator iterator(parent_fragment.get()); |
| 1971 const auto* fragment = iterator.NextChild(); | 1868 const auto* fragment = iterator.NextChild(); |
| 1972 ASSERT_TRUE(fragment); | 1869 ASSERT_TRUE(fragment); |
| 1973 EXPECT_EQ(LayoutUnit(320), fragment->Width()); | 1870 EXPECT_EQ(LayoutUnit(320), fragment->Width()); |
| 1974 EXPECT_EQ(LayoutUnit(100), fragment->Height()); | 1871 EXPECT_EQ(LayoutUnit(100), fragment->Height()); |
| 1975 EXPECT_FALSE(iterator.NextChild()); | 1872 EXPECT_FALSE(iterator.NextChild()); |
| 1976 | 1873 |
| 1977 iterator.SetParent(fragment); | 1874 iterator.SetParent(fragment); |
| 1978 // #child1 fragment in first column | 1875 // #child1 fragment in first column |
| 1979 fragment = iterator.NextChild(); | 1876 fragment = iterator.NextChild(); |
| 1980 ASSERT_TRUE(fragment); | 1877 ASSERT_TRUE(fragment); |
| 1981 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset()); | 1878 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset()); |
| 1982 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); | 1879 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); |
| 1983 EXPECT_EQ(LayoutUnit(15), fragment->Width()); | 1880 EXPECT_EQ(LayoutUnit(15), fragment->Width()); |
| 1984 EXPECT_EQ(LayoutUnit(100), fragment->Height()); | 1881 EXPECT_EQ(LayoutUnit(100), fragment->Height()); |
| 1985 EXPECT_EQ(0UL, fragment->Children().size()); | 1882 EXPECT_EQ(0UL, fragment->Children().size()); |
| 1986 // #child2 fragment in first column | 1883 // #child2 fragment in first column |
| 1987 fragment = iterator.NextChild(); | 1884 fragment = iterator.NextChild(); |
| 1988 ASSERT_TRUE(fragment); | 1885 ASSERT_TRUE(fragment); |
| 1989 EXPECT_EQ(LayoutUnit(84), fragment->LeftOffset()); | 1886 EXPECT_EQ(LayoutUnit(84), fragment->LeftOffset()); |
| 1990 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); | 1887 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); |
| 1991 EXPECT_EQ(LayoutUnit(16), fragment->Width()); | 1888 EXPECT_EQ(LayoutUnit(16), fragment->Width()); |
| 1992 EXPECT_EQ(LayoutUnit(100), fragment->Height()); | 1889 EXPECT_EQ(LayoutUnit(100), fragment->Height()); |
| 1993 EXPECT_EQ(0UL, fragment->Children().size()); | 1890 EXPECT_EQ(0UL, fragment->Children().size()); |
| 1994 EXPECT_FALSE(iterator.NextChild()); | 1891 EXPECT_FALSE(iterator.NextChild()); |
| 1995 } | 1892 } |
| 1996 | 1893 |
| 1997 // Test case's HTML representation: | |
| 1998 // <div id="parent" style="columns:3; column-fill:auto; column-gap:10px; | |
| 1999 // width:320px; height:100px;"> | |
| 2000 // <div id="child1" style="float:left; width:15%; height:150px;"></div> | |
| 2001 // <div id="child2" style="float:right; width:16%; height:150px;"></div> | |
| 2002 // </div> | |
| 2003 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm | 1894 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm |
| 2004 // is checked in. | 1895 // is checked in. |
| 2005 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_TwoFloatsInTwoColumns) { | 1896 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_TwoFloatsInTwoColumns) { |
| 2006 // parent | 1897 setBodyInnerHTML(R"HTML( |
| 2007 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); | 1898 <style> |
| 2008 parent_style->setColumnCount(3); | 1899 #parent { |
| 2009 parent_style->setColumnFill(ColumnFillAuto); | 1900 column-count: 3; |
| 2010 parent_style->setColumnGap(10); | 1901 column-fill: auto; |
| 2011 parent_style->setHeight(Length(100, Fixed)); | 1902 column-gap: 10px; |
| 2012 parent_style->setWidth(Length(320, Fixed)); | 1903 width: 320px; |
| 2013 NGBlockNode* parent = new NGBlockNode(parent_style.get()); | 1904 height: 100px; |
| 1905 } | |
| 1906 </style> | |
| 1907 <div id="container"> | |
| 1908 <div id="parent"> | |
| 1909 <div id="child1" style="float: left; width: 15%; height: 150px;"> | |
| 1910 </div> | |
| 1911 <div id="child2" style="float: right; width: 16%; height: 150px;"> | |
| 1912 </div> | |
| 1913 </div> | |
| 1914 </div> | |
| 1915 )HTML"); | |
| 2014 | 1916 |
| 2015 // child1 | 1917 auto* container = new NGBlockNode(getLayoutObjectByElementId("container")); |
| 2016 RefPtr<ComputedStyle> child1_style = ComputedStyle::create(); | |
| 2017 child1_style->setFloating(EFloat::kLeft); | |
| 2018 child1_style->setWidth(Length(15, Percent)); | |
| 2019 child1_style->setHeight(Length(150, Fixed)); | |
| 2020 NGBlockNode* child1 = new NGBlockNode(child1_style.get()); | |
| 2021 | |
| 2022 // child2 | |
| 2023 RefPtr<ComputedStyle> child2_style = ComputedStyle::create(); | |
| 2024 child2_style->setFloating(EFloat::kRight); | |
| 2025 child2_style->setWidth(Length(16, Percent)); | |
| 2026 child2_style->setHeight(Length(150, Fixed)); | |
| 2027 NGBlockNode* child2 = new NGBlockNode(child2_style.get()); | |
| 2028 | |
| 2029 parent->SetFirstChild(child1); | |
| 2030 child1->SetNextSibling(child2); | |
| 2031 | |
| 2032 auto* space = ConstructConstraintSpace( | 1918 auto* space = ConstructConstraintSpace( |
| 2033 kHorizontalTopBottom, TextDirection::kLtr, | 1919 kHorizontalTopBottom, TextDirection::kLtr, |
| 2034 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); | 1920 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); |
| 2035 RefPtr<const NGPhysicalBoxFragment> parent_fragment = | 1921 RefPtr<const NGPhysicalBoxFragment> parent_fragment = |
| 2036 RunBlockLayoutAlgorithm(space, parent); | 1922 RunBlockLayoutAlgorithm(space, container); |
| 2037 | 1923 |
| 2038 FragmentChildIterator iterator(parent_fragment.get()); | 1924 FragmentChildIterator iterator(parent_fragment.get()); |
| 2039 const auto* fragment = iterator.NextChild(); | 1925 const auto* fragment = iterator.NextChild(); |
| 2040 ASSERT_TRUE(fragment); | 1926 ASSERT_TRUE(fragment); |
| 2041 EXPECT_EQ(LayoutUnit(320), fragment->Width()); | 1927 EXPECT_EQ(LayoutUnit(320), fragment->Width()); |
| 2042 EXPECT_EQ(LayoutUnit(100), fragment->Height()); | 1928 EXPECT_EQ(LayoutUnit(100), fragment->Height()); |
| 2043 EXPECT_FALSE(iterator.NextChild()); | 1929 EXPECT_FALSE(iterator.NextChild()); |
| 2044 | 1930 |
| 2045 iterator.SetParent(fragment); | 1931 iterator.SetParent(fragment); |
| 2046 // #child1 fragment in first column | 1932 // #child1 fragment in first column |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2475 | 2361 |
| 2476 child = iterator.NextChild(); | 2362 child = iterator.NextChild(); |
| 2477 EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(100)), child->Size()); | 2363 EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(100)), child->Size()); |
| 2478 EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(40)), child->Offset()); | 2364 EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(40)), child->Offset()); |
| 2479 | 2365 |
| 2480 EXPECT_FALSE(iterator.NextChild()); | 2366 EXPECT_FALSE(iterator.NextChild()); |
| 2481 } | 2367 } |
| 2482 | 2368 |
| 2483 } // namespace | 2369 } // namespace |
| 2484 } // namespace blink | 2370 } // namespace blink |
| OLD | NEW |