Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm_test.cc

Issue 2725773002: Remove NGBlockNode constructor, SetFirstChild, SetNextSibling methods (Closed)
Patch Set: CR fixes Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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) {
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);
Gleb Lanbin 2017/03/01 19:47:44 can you update the description because it doesn't
atotic 2017/03/01 20:20:38 done
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 id="first_child" style="height: 20px">
Gleb Lanbin 2017/03/01 19:47:44 ids: first_child, second_child etc. are not used a
atotic 2017/03/01 20:20:38 done
133 </div>
134 <div id="second_child"
135 style="height: 30px;margin-top: 5px;margin-bottom: 20px">
Gleb Lanbin 2017/03/01 19:47:44 please follow https://google.github.io/styleguide/
atotic 2017/03/01 20:20:38 done.
136 </div>
137 </div>
138 )HTML");
130 const int kWidth = 30; 139 const int kWidth = 30;
131 const int kHeight1 = 20; 140 const int kHeight1 = 20;
132 const int kHeight2 = 30; 141 const int kHeight2 = 30;
133 const int kMarginTop = 5; 142 const int kMarginTop = 5;
134 const int kMarginBottom = 20;
135 style_->setWidth(Length(kWidth, Fixed));
136 143
137 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); 144 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( 145 auto* space = ConstructConstraintSpace(
150 kHorizontalTopBottom, TextDirection::kLtr, 146 kHorizontalTopBottom, TextDirection::kLtr,
151 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); 147 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite));
148
152 RefPtr<NGPhysicalBoxFragment> frag = 149 RefPtr<NGPhysicalBoxFragment> frag =
153 RunBlockLayoutAlgorithm(space, first_child); 150 RunBlockLayoutAlgorithm(space, container);
154 151
155 EXPECT_EQ(LayoutUnit(kWidth), frag->Width()); 152 EXPECT_EQ(LayoutUnit(kWidth), frag->Width());
156 EXPECT_EQ(LayoutUnit(kHeight1 + kHeight2 + kMarginTop), frag->Height()); 153 EXPECT_EQ(LayoutUnit(kHeight1 + kHeight2 + kMarginTop), frag->Height());
157 EXPECT_EQ(NGPhysicalFragment::kFragmentBox, frag->Type()); 154 EXPECT_EQ(NGPhysicalFragment::kFragmentBox, frag->Type());
158 ASSERT_EQ(frag->Children().size(), 2UL); 155 ASSERT_EQ(frag->Children().size(), 2UL);
159 156
160 const NGPhysicalFragment* child = frag->Children()[0].get(); 157 const NGPhysicalFragment* child = frag->Children()[0].get();
161 EXPECT_EQ(kHeight1, child->Height()); 158 EXPECT_EQ(kHeight1, child->Height());
162 EXPECT_EQ(0, child->TopOffset()); 159 EXPECT_EQ(0, child->TopOffset());
163 160
164 child = frag->Children()[1].get(); 161 child = frag->Children()[1].get();
165 EXPECT_EQ(kHeight2, child->Height()); 162 EXPECT_EQ(kHeight2, child->Height());
166 EXPECT_EQ(kHeight1 + kMarginTop, child->TopOffset()); 163 EXPECT_EQ(kHeight1 + kMarginTop, child->TopOffset());
167 } 164 }
168 165
169 // Verifies that a child is laid out correctly if it's writing mode is different 166 // Verifies that a child is laid out correctly if it's writing mode is different
170 // from the parent's one. 167 // 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) { 168 TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildrenWithWritingMode) {
179 const int kWidth = 50; 169 setBodyInnerHTML(R"HTML(
170 <div id="container">
171 <div id="div1" style="writing-mode: vertical-lr;">
172 <div id="div2" style="width: 50px;
Gleb Lanbin 2017/03/01 19:47:44 the style definition takes more than 3 lines? move
atotic 2017/03/01 20:20:39 done
173 height: 50px; margin-left: 100px;
174 writing-mode: horizontal-tb;">
175 </div>
176 </div>
177 </div>
178 )HTML");
180 const int kHeight = 50; 179 const int kHeight = 50;
181 const int kMarginLeft = 100; 180 const int kMarginLeft = 100;
182 181
183 RefPtr<ComputedStyle> div1_style = ComputedStyle::create(); 182 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 = 183 auto* space =
197 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, 184 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr,
198 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); 185 NGLogicalSize(LayoutUnit(500), LayoutUnit(500)));
199 RefPtr<NGPhysicalBoxFragment> frag = RunBlockLayoutAlgorithm(space, div1); 186 RefPtr<NGPhysicalBoxFragment> frag =
187 RunBlockLayoutAlgorithm(space, container);
200 188
201 const NGPhysicalFragment* child = frag->Children()[0].get(); 189 const NGPhysicalFragment* child = frag->Children()[0].get();
202 // DIV2 190 // DIV2
203 child = static_cast<const NGPhysicalBoxFragment*>(child)->Children()[0].get(); 191 child = static_cast<const NGPhysicalBoxFragment*>(child)->Children()[0].get();
204 192
205 EXPECT_EQ(kHeight, child->Height()); 193 EXPECT_EQ(kHeight, child->Height());
206 EXPECT_EQ(0, child->TopOffset()); 194 EXPECT_EQ(0, child->TopOffset());
207 EXPECT_EQ(kMarginLeft, child->LeftOffset()); 195 EXPECT_EQ(kMarginLeft, child->LeftOffset());
208 } 196 }
209 197
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 auto* p_fragment = 646 auto* p_fragment =
659 toNGPhysicalBoxFragment(body_fragment->Children()[0].get()); 647 toNGPhysicalBoxFragment(body_fragment->Children()[0].get());
660 // Collapsed margins with result = 0. 648 // Collapsed margins with result = 0.
661 EXPECT_THAT(p_fragment->Offset(), 649 EXPECT_THAT(p_fragment->Offset(),
662 NGPhysicalOffset(LayoutUnit(20), LayoutUnit(0))); 650 NGPhysicalOffset(LayoutUnit(20), LayoutUnit(0)));
663 } 651 }
664 652
665 // Verifies that the margin strut of a child with a different writing mode does 653 // Verifies that the margin strut of a child with a different writing mode does
666 // not get used in the collapsing margins calculation. 654 // not get used in the collapsing margins calculation.
667 // 655 //
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 656 // TODO(glebl): Disabled for now. Follow-up with kojii@ on
679 // https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=4844 657 // https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=4844
680 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_CollapsingMarginsCase6) { 658 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_CollapsingMarginsCase6) {
659 setBodyInnerHTML(R"HTML(
660 <style>
661 #div1 {
662 margin-bottom: 10px;
663 width: 10px;
664 height: 60px;
665 writing-mode: vertical-rl;
666 }
667 #div2 { margin-left: -20px; width: 10px; }
668 #div3 { margin-top: 40px; height: 60px; }
669 </style>
670 <div id="container" style="width:500px;height:500px">
671 <div id="div1">
672 <div id="div2">vertical</div>
673 </div>
674 <div id="div3"></div>
675 </div>
676 )HTML");
681 const int kHeight = 60; 677 const int kHeight = 60;
682 const int kWidth = 10;
683 const int kMarginBottom = 10; 678 const int kMarginBottom = 10;
684 const int kMarginLeft = -20;
685 const int kMarginTop = 40; 679 const int kMarginTop = 40;
686 680
687 style_->setWidth(Length(500, Fixed)); 681 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 = 682 auto* space =
714 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, 683 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr,
715 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); 684 NGLogicalSize(LayoutUnit(500), LayoutUnit(500)));
716 RefPtr<NGPhysicalBoxFragment> frag = RunBlockLayoutAlgorithm(space, div1); 685 RefPtr<NGPhysicalBoxFragment> frag =
686 RunBlockLayoutAlgorithm(space, container);
717 687
718 ASSERT_EQ(frag->Children().size(), 2UL); 688 ASSERT_EQ(frag->Children().size(), 2UL);
719 689
720 const NGPhysicalFragment* child1 = frag->Children()[0].get(); 690 const NGPhysicalFragment* child1 = frag->Children()[0].get();
721 EXPECT_EQ(0, child1->TopOffset()); 691 EXPECT_EQ(0, child1->TopOffset());
722 EXPECT_EQ(kHeight, child1->Height()); 692 EXPECT_EQ(kHeight, child1->Height());
723 693
724 const NGPhysicalFragment* child2 = frag->Children()[1].get(); 694 const NGPhysicalFragment* child2 = frag->Children()[1].get();
725 EXPECT_EQ(kHeight + std::max(kMarginBottom, kMarginTop), child2->TopOffset()); 695 EXPECT_EQ(kHeight + std::max(kMarginBottom, kMarginTop), child2->TopOffset());
726 } 696 }
727 697
728 // Verifies that a box's size includes its borders and padding, and that 698 // Verifies that a box's size includes its borders and padding, and that
729 // children are positioned inside the content box. 699 // 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) { 700 TEST_F(NGBlockLayoutAlgorithmTest, BorderAndPadding) {
701 setBodyInnerHTML(R"HTML(
702 <style>
703 #div1 {
704 width: 100px;
705 height: 100px;
706 border-style: solid;
707 border-width: 1px 2px 3px 4px;
708 padding: 5px 6px 7px 8px;
709 }
710 </style>
711 <div id="container">
712 <div id="div1">
713 <div id="div2"></div>
714 </div>
715 </div>
716 )HTML");
741 const int kWidth = 100; 717 const int kWidth = 100;
742 const int kHeight = 100; 718 const int kHeight = 100;
743 const int kBorderTop = 1; 719 const int kBorderTop = 1;
744 const int kBorderRight = 2; 720 const int kBorderRight = 2;
745 const int kBorderBottom = 3; 721 const int kBorderBottom = 3;
746 const int kBorderLeft = 4; 722 const int kBorderLeft = 4;
747 const int kPaddingTop = 5; 723 const int kPaddingTop = 5;
748 const int kPaddingRight = 6; 724 const int kPaddingRight = 6;
749 const int kPaddingBottom = 7; 725 const int kPaddingBottom = 7;
750 const int kPaddingLeft = 8; 726 const int kPaddingLeft = 8;
751 RefPtr<ComputedStyle> div1_style = ComputedStyle::create();
752 727
753 div1_style->setWidth(Length(kWidth, Fixed)); 728 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 729
776 auto* space = ConstructConstraintSpace( 730 auto* space = ConstructConstraintSpace(
777 kHorizontalTopBottom, TextDirection::kLtr, 731 kHorizontalTopBottom, TextDirection::kLtr,
778 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 732 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
779 RefPtr<NGPhysicalBoxFragment> frag = RunBlockLayoutAlgorithm(space, div1); 733
734 RefPtr<NGPhysicalBoxFragment> frag =
735 RunBlockLayoutAlgorithm(space, container);
780 736
781 ASSERT_EQ(frag->Children().size(), 1UL); 737 ASSERT_EQ(frag->Children().size(), 1UL);
782 738
783 // div1 739 // div1
784 const NGPhysicalFragment* child = frag->Children()[0].get(); 740 const NGPhysicalFragment* child = frag->Children()[0].get();
785 EXPECT_EQ(kBorderLeft + kPaddingLeft + kWidth + kPaddingRight + kBorderRight, 741 EXPECT_EQ(kBorderLeft + kPaddingLeft + kWidth + kPaddingRight + kBorderRight,
786 child->Width()); 742 child->Width());
787 EXPECT_EQ(kBorderTop + kPaddingTop + kHeight + kPaddingBottom + kBorderBottom, 743 EXPECT_EQ(kBorderTop + kPaddingTop + kHeight + kPaddingBottom + kBorderBottom,
788 child->Height()); 744 child->Height());
789 745
790 ASSERT_TRUE(child->Type() == NGPhysicalFragment::kFragmentBox); 746 ASSERT_TRUE(child->Type() == NGPhysicalFragment::kFragmentBox);
791 ASSERT_EQ(static_cast<const NGPhysicalBoxFragment*>(child)->Children().size(), 747 ASSERT_EQ(static_cast<const NGPhysicalBoxFragment*>(child)->Children().size(),
792 1UL); 748 1UL);
793 749
794 // div2 750 // div2
795 child = static_cast<const NGPhysicalBoxFragment*>(child)->Children()[0].get(); 751 child = static_cast<const NGPhysicalBoxFragment*>(child)->Children()[0].get();
796 EXPECT_EQ(kBorderTop + kPaddingTop, child->TopOffset()); 752 EXPECT_EQ(kBorderTop + kPaddingTop, child->TopOffset());
797 EXPECT_EQ(kBorderLeft + kPaddingLeft, child->LeftOffset()); 753 EXPECT_EQ(kBorderLeft + kPaddingLeft, child->LeftOffset());
798 } 754 }
799 755
800 TEST_F(NGBlockLayoutAlgorithmTest, PercentageResolutionSize) { 756 TEST_F(NGBlockLayoutAlgorithmTest, PercentageResolutionSize) {
757 setBodyInnerHTML(R"HTML(
758 <div id="container" style="width: 30px; padding-left: 10px">
759 <div id="div1" style="width: 40%"></div>
760 </div>
761 )HTML");
801 const int kPaddingLeft = 10; 762 const int kPaddingLeft = 10;
802 const int kWidth = 30; 763 const int kWidth = 30;
803 style_->setWidth(Length(kWidth, Fixed));
804 style_->setPaddingLeft(Length(kPaddingLeft, Fixed));
805 764
806 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); 765 auto* container = new NGBlockNode(getLayoutObjectByElementId("container"));
807 first_style->setWidth(Length(40, Percent));
808 NGBlockNode* first_child = new NGBlockNode(first_style.get());
809 766
810 auto* space = ConstructConstraintSpace( 767 auto* space = ConstructConstraintSpace(
811 kHorizontalTopBottom, TextDirection::kLtr, 768 kHorizontalTopBottom, TextDirection::kLtr,
812 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); 769 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite));
813 RefPtr<NGPhysicalBoxFragment> frag = 770 RefPtr<NGPhysicalBoxFragment> frag =
814 RunBlockLayoutAlgorithm(space, first_child); 771 RunBlockLayoutAlgorithm(space, container);
815 772
816 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width()); 773 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width());
817 EXPECT_EQ(NGPhysicalFragment::kFragmentBox, frag->Type()); 774 EXPECT_EQ(NGPhysicalFragment::kFragmentBox, frag->Type());
818 ASSERT_EQ(frag->Children().size(), 1UL); 775 ASSERT_EQ(frag->Children().size(), 1UL);
819 776
820 const NGPhysicalFragment* child = frag->Children()[0].get(); 777 const NGPhysicalFragment* child = frag->Children()[0].get();
821 EXPECT_EQ(LayoutUnit(12), child->Width()); 778 EXPECT_EQ(LayoutUnit(12), child->Width());
822 } 779 }
823 780
824 // A very simple auto margin case. We rely on the tests in ng_length_utils_test 781 // 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. 782 // for the more complex cases; just make sure we handle auto at all here.
826 TEST_F(NGBlockLayoutAlgorithmTest, AutoMargin) { 783 TEST_F(NGBlockLayoutAlgorithmTest, AutoMargin) {
784 setBodyInnerHTML(R"HTML(
785 <style>
786 #first { width: 10px; margin-left: auto; margin-right: auto; }
787 </style>
788 <div id="container" style="width: 30px; padding-left: 10px">
789 <div id="first">
790 </div>
791 </div>
792 )HTML");
827 const int kPaddingLeft = 10; 793 const int kPaddingLeft = 10;
828 const int kWidth = 30; 794 const int kWidth = 30;
829 style_->setWidth(Length(kWidth, Fixed)); 795 const int kChildWidth = 10;
830 style_->setPaddingLeft(Length(kPaddingLeft, Fixed));
831 796
832 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); 797 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 798
839 auto* space = ConstructConstraintSpace( 799 auto* space = ConstructConstraintSpace(
840 kHorizontalTopBottom, TextDirection::kLtr, 800 kHorizontalTopBottom, TextDirection::kLtr,
841 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); 801 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite));
842 RefPtr<NGPhysicalBoxFragment> frag = 802 RefPtr<NGPhysicalBoxFragment> frag =
843 RunBlockLayoutAlgorithm(space, first_child); 803 RunBlockLayoutAlgorithm(space, container);
844 804
845 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width()); 805 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width());
846 EXPECT_EQ(NGPhysicalFragment::kFragmentBox, frag->Type()); 806 EXPECT_EQ(NGPhysicalFragment::kFragmentBox, frag->Type());
847 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->WidthOverflow()); 807 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->WidthOverflow());
848 ASSERT_EQ(1UL, frag->Children().size()); 808 ASSERT_EQ(1UL, frag->Children().size());
849 809
850 const NGPhysicalFragment* child = frag->Children()[0].get(); 810 const NGPhysicalFragment* child = frag->Children()[0].get();
851 EXPECT_EQ(LayoutUnit(kChildWidth), child->Width()); 811 EXPECT_EQ(LayoutUnit(kChildWidth), child->Width());
852 EXPECT_EQ(LayoutUnit(kPaddingLeft + 10), child->LeftOffset()); 812 EXPECT_EQ(LayoutUnit(kPaddingLeft + 10), child->LeftOffset());
853 EXPECT_EQ(LayoutUnit(0), child->TopOffset()); 813 EXPECT_EQ(LayoutUnit(0), child->TopOffset());
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 run_with_clearance(EClear::kBoth); 1237 run_with_clearance(EClear::kBoth);
1278 EXPECT_EQ(LayoutUnit(8), body_fragment->TopOffset()); 1238 EXPECT_EQ(LayoutUnit(8), body_fragment->TopOffset());
1279 EXPECT_EQ(LayoutUnit(0), container_fragment->TopOffset()); 1239 EXPECT_EQ(LayoutUnit(0), container_fragment->TopOffset());
1280 EXPECT_EQ(LayoutUnit(170), clerance_fragment->TopOffset()); 1240 EXPECT_EQ(LayoutUnit(170), clerance_fragment->TopOffset());
1281 EXPECT_EQ(LayoutUnit(270), block_fragment->TopOffset()); 1241 EXPECT_EQ(LayoutUnit(270), block_fragment->TopOffset());
1282 EXPECT_EQ(LayoutUnit(370), adjoining_clearance_fragment->TopOffset()); 1242 EXPECT_EQ(LayoutUnit(370), adjoining_clearance_fragment->TopOffset());
1283 } 1243 }
1284 1244
1285 // Verifies that we compute the right min and max-content size. 1245 // Verifies that we compute the right min and max-content size.
1286 TEST_F(NGBlockLayoutAlgorithmTest, ComputeMinMaxContent) { 1246 TEST_F(NGBlockLayoutAlgorithmTest, ComputeMinMaxContent) {
1287 const int kWidth = 50; 1247 setBodyInnerHTML(R"HTML(
1288 const int kWidthChild1 = 20; 1248 <div id="container" style="width: 50px">
1249 <div id="first_child" style="width: 20px"></div>
1250 <div id="second_child" style="width: 30px"></div>
1251 </div>
1252 )HTML");
1253
1289 const int kWidthChild2 = 30; 1254 const int kWidthChild2 = 30;
1290 1255
1291 // This should have no impact on the min/max content size. 1256 auto* container = new NGBlockNode(getLayoutObjectByElementId("container"));
1292 style_->setWidth(Length(kWidth, Fixed));
1293 1257
1294 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); 1258 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); 1259 EXPECT_EQ(kWidthChild2, sizes.min_content);
1306 EXPECT_EQ(kWidthChild2, sizes.max_content); 1260 EXPECT_EQ(kWidthChild2, sizes.max_content);
1307 } 1261 }
1308 1262
1309 // Tests that we correctly handle shrink-to-fit 1263 // Tests that we correctly handle shrink-to-fit
1310 TEST_F(NGBlockLayoutAlgorithmTest, ShrinkToFit) { 1264 TEST_F(NGBlockLayoutAlgorithmTest, ShrinkToFit) {
1311 const int kWidthChild1 = 20; 1265 setBodyInnerHTML(R"HTML(
1266 <div id="container">
1267 <div id="first_child" style="width: 20px"></div>
1268 <div id="second_child" style="width: 30px"></div>
1269 </div>
1270 )HTML");
1312 const int kWidthChild2 = 30; 1271 const int kWidthChild2 = 30;
1313 1272
1314 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); 1273 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 1274
1324 auto* space = ConstructConstraintSpace( 1275 auto* space = ConstructConstraintSpace(
1325 kHorizontalTopBottom, TextDirection::kLtr, 1276 kHorizontalTopBottom, TextDirection::kLtr,
1326 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite), true); 1277 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite), true);
1327 RefPtr<NGPhysicalFragment> frag = RunBlockLayoutAlgorithm(space, first_child); 1278 RefPtr<NGPhysicalFragment> frag = RunBlockLayoutAlgorithm(space, container);
1328 1279
1329 EXPECT_EQ(LayoutUnit(30), frag->Width()); 1280 EXPECT_EQ(LayoutUnit(kWidthChild2), frag->Width());
1330 } 1281 }
1331 1282
1332 class FragmentChildIterator { 1283 class FragmentChildIterator {
1333 STACK_ALLOCATED(); 1284 STACK_ALLOCATED();
1334 1285
1335 public: 1286 public:
1336 explicit FragmentChildIterator(const NGPhysicalBoxFragment* parent) { 1287 explicit FragmentChildIterator(const NGPhysicalBoxFragment* parent) {
1337 SetParent(parent); 1288 SetParent(parent);
1338 } 1289 }
1339 void SetParent(const NGPhysicalBoxFragment* parent) { 1290 void SetParent(const NGPhysicalBoxFragment* parent) {
(...skipping 13 matching lines...) Expand all
1353 return nullptr; 1304 return nullptr;
1354 } 1305 }
1355 return toNGPhysicalBoxFragment(parent_->Children()[index_++].get()); 1306 return toNGPhysicalBoxFragment(parent_->Children()[index_++].get());
1356 } 1307 }
1357 1308
1358 private: 1309 private:
1359 const NGPhysicalBoxFragment* parent_; 1310 const NGPhysicalBoxFragment* parent_;
1360 unsigned index_; 1311 unsigned index_;
1361 }; 1312 };
1362 1313
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 1314 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm
1368 // is checked in. 1315 // is checked in.
1369 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_EmptyMulticol) { 1316 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_EmptyMulticol) {
1370 // parent 1317 setBodyInnerHTML(R"HTML(
1371 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); 1318 <style>
1372 parent_style->setColumnCount(2); 1319 #parent {
1373 parent_style->setColumnFill(ColumnFillAuto); 1320 column-count: 2;
1374 parent_style->setColumnGap(10); 1321 column-fill: auto;
1375 parent_style->setHeight(Length(100, Fixed)); 1322 column-gap: 10px;
1376 parent_style->setWidth(Length(210, Fixed)); 1323 height: 100px;
1377 NGBlockNode* parent = new NGBlockNode(parent_style.get()); 1324 width: 210px;
1325 }
1326 </style>
1327 <div id="container">
1328 <div id="parent">
1329 </div>
1330 </div>
1331 )HTML");
1378 1332
1333 auto* container = new NGBlockNode(getLayoutObjectByElementId("container"));
1379 auto* space = ConstructConstraintSpace( 1334 auto* space = ConstructConstraintSpace(
1380 kHorizontalTopBottom, TextDirection::kLtr, 1335 kHorizontalTopBottom, TextDirection::kLtr,
1381 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 1336 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
1382 RefPtr<const NGPhysicalBoxFragment> parent_fragment = 1337 RefPtr<const NGPhysicalBoxFragment> parent_fragment =
1383 RunBlockLayoutAlgorithm(space, parent); 1338 RunBlockLayoutAlgorithm(space, container);
1384 FragmentChildIterator iterator(parent_fragment.get()); 1339 FragmentChildIterator iterator(parent_fragment.get());
1385 const auto* fragment = iterator.NextChild(); 1340 const auto* fragment = iterator.NextChild();
1386 ASSERT_TRUE(fragment); 1341 ASSERT_TRUE(fragment);
1387 EXPECT_EQ(LayoutUnit(210), fragment->Width()); 1342 EXPECT_EQ(LayoutUnit(210), fragment->Width());
1388 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1343 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1389 EXPECT_FALSE(iterator.NextChild()); 1344 EXPECT_FALSE(iterator.NextChild());
1390 1345
1391 // There should be nothing inside the multicol container. 1346 // There should be nothing inside the multicol container.
1392 EXPECT_FALSE(FragmentChildIterator(fragment).NextChild()); 1347 EXPECT_FALSE(FragmentChildIterator(fragment).NextChild());
1393 } 1348 }
1394 1349
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 1350 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm
1401 // is checked in. 1351 // is checked in.
1402 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_EmptyBlock) { 1352 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_EmptyBlock) {
1403 // parent 1353 setBodyInnerHTML(R"HTML(
1404 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); 1354 <style>
1405 parent_style->setColumnCount(2); 1355 #parent {
1406 parent_style->setColumnFill(ColumnFillAuto); 1356 height: 100px;
1407 parent_style->setColumnGap(10); 1357 width: 210px;
1408 parent_style->setHeight(Length(100, Fixed)); 1358 }
1409 parent_style->setWidth(Length(210, Fixed)); 1359 </style>
1410 NGBlockNode* parent = new NGBlockNode(parent_style.get()); 1360 <div id="container">
1361 <div id="parent">
1362 <div id="child">
1363 </div>
1364 </div>
1365 </div>
1366 )HTML");
1411 1367
1412 // child 1368 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( 1369 auto* space = ConstructConstraintSpace(
1419 kHorizontalTopBottom, TextDirection::kLtr, 1370 kHorizontalTopBottom, TextDirection::kLtr,
1420 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 1371 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
1421 RefPtr<const NGPhysicalBoxFragment> parent_fragment = 1372 RefPtr<const NGPhysicalBoxFragment> parent_fragment =
1422 RunBlockLayoutAlgorithm(space, parent); 1373 RunBlockLayoutAlgorithm(space, container);
1423 FragmentChildIterator iterator(parent_fragment.get()); 1374 FragmentChildIterator iterator(parent_fragment.get());
1424 const auto* fragment = iterator.NextChild(); 1375 const auto* fragment = iterator.NextChild();
1425 EXPECT_EQ(LayoutUnit(210), fragment->Width()); 1376 EXPECT_EQ(LayoutUnit(210), fragment->Width());
1426 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1377 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1427 ASSERT_TRUE(fragment); 1378 ASSERT_TRUE(fragment);
1428 EXPECT_FALSE(iterator.NextChild()); 1379 EXPECT_FALSE(iterator.NextChild());
1429 iterator.SetParent(fragment); 1380 iterator.SetParent(fragment);
1430 1381
1431 // #child fragment in first column 1382 // #child fragment in first column
1432 fragment = iterator.NextChild(); 1383 fragment = iterator.NextChild();
1433 ASSERT_TRUE(fragment); 1384 ASSERT_TRUE(fragment);
1434 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset()); 1385 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset());
1435 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); 1386 EXPECT_EQ(LayoutUnit(), fragment->TopOffset());
1436 EXPECT_EQ(LayoutUnit(100), fragment->Width()); 1387 EXPECT_EQ(LayoutUnit(100), fragment->Width());
1437 EXPECT_EQ(LayoutUnit(), fragment->Height()); 1388 EXPECT_EQ(LayoutUnit(), fragment->Height());
1438 EXPECT_EQ(0UL, fragment->Children().size()); 1389 EXPECT_EQ(0UL, fragment->Children().size());
1439 EXPECT_FALSE(iterator.NextChild()); 1390 EXPECT_FALSE(iterator.NextChild());
1440 } 1391 }
1441 1392
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 1393 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm
1448 // is checked in. 1394 // is checked in.
1449 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_BlockInOneColumn) { 1395 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_BlockInOneColumn) {
1450 // parent 1396 setBodyInnerHTML(R"HTML(
1451 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); 1397 <style>
1452 parent_style->setColumnCount(2); 1398 #parent {
1453 parent_style->setColumnFill(ColumnFillAuto); 1399 column-count: 2;
1454 parent_style->setColumnGap(10); 1400 column-fill: auto;
1455 parent_style->setHeight(Length(100, Fixed)); 1401 column-gap: 10px;
1456 parent_style->setWidth(Length(310, Fixed)); 1402 height: 100px;
1457 NGBlockNode* parent = new NGBlockNode(parent_style.get()); 1403 width: 310px;
1404 }
1405 </style>
1406 <div id="container">
1407 <div id="parent">
1408 <div id="child" style="width: 60%; height: 100%">
1409 </div>
1410 </div>
1411 </div>
1412 )HTML");
1458 1413
1459 // child 1414 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( 1415 auto* space = ConstructConstraintSpace(
1468 kHorizontalTopBottom, TextDirection::kLtr, 1416 kHorizontalTopBottom, TextDirection::kLtr,
1469 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 1417 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
1470 RefPtr<const NGPhysicalBoxFragment> parent_fragment = 1418 RefPtr<const NGPhysicalBoxFragment> parent_fragment =
1471 RunBlockLayoutAlgorithm(space, parent); 1419 RunBlockLayoutAlgorithm(space, container);
1472 1420
1473 FragmentChildIterator iterator(parent_fragment.get()); 1421 FragmentChildIterator iterator(parent_fragment.get());
1474 const auto* fragment = iterator.NextChild(); 1422 const auto* fragment = iterator.NextChild();
1475 ASSERT_TRUE(fragment); 1423 ASSERT_TRUE(fragment);
1476 EXPECT_EQ(LayoutUnit(310), fragment->Width()); 1424 EXPECT_EQ(LayoutUnit(310), fragment->Width());
1477 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1425 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1478 EXPECT_FALSE(iterator.NextChild()); 1426 EXPECT_FALSE(iterator.NextChild());
1479 iterator.SetParent(fragment); 1427 iterator.SetParent(fragment);
1480 1428
1481 // #child fragment in first column 1429 // #child fragment in first column
1482 fragment = iterator.NextChild(); 1430 fragment = iterator.NextChild();
1483 ASSERT_TRUE(fragment); 1431 ASSERT_TRUE(fragment);
1484 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset()); 1432 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset());
1485 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); 1433 EXPECT_EQ(LayoutUnit(), fragment->TopOffset());
1486 EXPECT_EQ(LayoutUnit(90), fragment->Width()); 1434 EXPECT_EQ(LayoutUnit(90), fragment->Width());
1487 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1435 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1488 EXPECT_EQ(0UL, fragment->Children().size()); 1436 EXPECT_EQ(0UL, fragment->Children().size());
1489 EXPECT_FALSE(iterator.NextChild()); 1437 EXPECT_FALSE(iterator.NextChild());
1490 } 1438 }
1491 1439
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 1440 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm
1498 // is checked in. 1441 // is checked in.
1499 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_BlockInTwoColumns) { 1442 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_BlockInTwoColumns) {
1500 // parent 1443 setBodyInnerHTML(R"HTML(
1501 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); 1444 <style>
1502 parent_style->setColumnCount(2); 1445 #parent {
1503 parent_style->setColumnFill(ColumnFillAuto); 1446 column-count: 2;
1504 parent_style->setColumnGap(10); 1447 column-fill: auto;
1505 parent_style->setHeight(Length(100, Fixed)); 1448 column-gap: 10px;
1506 parent_style->setWidth(Length(210, Fixed)); 1449 height: 100px;
1507 NGBlockNode* parent = new NGBlockNode(parent_style.get()); 1450 width: 20px;
1451 }
1452 </style>
1453 <div id="container">
1454 <div id="parent">
1455 <div id="child" style="width: 75%; height: 150px"></div>
1456 </div>
1457 </div>
1458 )HTML");
1508 1459
1509 // child 1460 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( 1461 auto* space = ConstructConstraintSpace(
1518 kHorizontalTopBottom, TextDirection::kLtr, 1462 kHorizontalTopBottom, TextDirection::kLtr,
1519 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 1463 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
1520 RefPtr<const NGPhysicalBoxFragment> parent_fragment = 1464 RefPtr<const NGPhysicalBoxFragment> parent_fragment =
1521 RunBlockLayoutAlgorithm(space, parent); 1465 RunBlockLayoutAlgorithm(space, container);
1522 1466
1523 FragmentChildIterator iterator(parent_fragment.get()); 1467 FragmentChildIterator iterator(parent_fragment.get());
1524 const auto* fragment = iterator.NextChild(); 1468 const auto* fragment = iterator.NextChild();
1525 ASSERT_TRUE(fragment); 1469 ASSERT_TRUE(fragment);
1526 EXPECT_EQ(LayoutUnit(210), fragment->Width()); 1470 EXPECT_EQ(LayoutUnit(210), fragment->Width());
1527 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1471 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1528 EXPECT_FALSE(iterator.NextChild()); 1472 EXPECT_FALSE(iterator.NextChild());
1529 1473
1530 iterator.SetParent(fragment); 1474 iterator.SetParent(fragment);
1531 // #child fragment in first column 1475 // #child fragment in first column
1532 fragment = iterator.NextChild(); 1476 fragment = iterator.NextChild();
1533 ASSERT_TRUE(fragment); 1477 ASSERT_TRUE(fragment);
1534 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset()); 1478 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset());
1535 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); 1479 EXPECT_EQ(LayoutUnit(), fragment->TopOffset());
1536 EXPECT_EQ(LayoutUnit(75), fragment->Width()); 1480 EXPECT_EQ(LayoutUnit(75), fragment->Width());
1537 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1481 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1538 EXPECT_EQ(0UL, fragment->Children().size()); 1482 EXPECT_EQ(0UL, fragment->Children().size());
1539 1483
1540 // #child fragment in second column 1484 // #child fragment in second column
1541 fragment = iterator.NextChild(); 1485 fragment = iterator.NextChild();
1542 ASSERT_TRUE(fragment); 1486 ASSERT_TRUE(fragment);
1543 EXPECT_EQ(LayoutUnit(110), fragment->LeftOffset()); 1487 EXPECT_EQ(LayoutUnit(110), fragment->LeftOffset());
1544 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); 1488 EXPECT_EQ(LayoutUnit(), fragment->TopOffset());
1545 EXPECT_EQ(LayoutUnit(75), fragment->Width()); 1489 EXPECT_EQ(LayoutUnit(75), fragment->Width());
1546 EXPECT_EQ(LayoutUnit(50), fragment->Height()); 1490 EXPECT_EQ(LayoutUnit(50), fragment->Height());
1547 EXPECT_EQ(0U, fragment->Children().size()); 1491 EXPECT_EQ(0U, fragment->Children().size());
1548 EXPECT_FALSE(iterator.NextChild()); 1492 EXPECT_FALSE(iterator.NextChild());
1549 } 1493 }
1550 1494
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 1495 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm
1557 // is checked in. 1496 // is checked in.
1558 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_BlockInThreeColumns) { 1497 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_BlockInThreeColumns) {
1559 // parent 1498 setBodyInnerHTML(R"HTML(
1560 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); 1499 <style>
1561 parent_style->setColumnCount(3); 1500 #parent {
1562 parent_style->setColumnFill(ColumnFillAuto); 1501 column-count: 3;
1563 parent_style->setColumnGap(10); 1502 column-fill: auto;
1564 parent_style->setHeight(Length(100, Fixed)); 1503 column-gap: 10px;
1565 parent_style->setWidth(Length(320, Fixed)); 1504 height: 100px;
1566 NGBlockNode* parent = new NGBlockNode(parent_style.get()); 1505 width: 320px;
1506 }
1507 </style>
1508 <div id="container">
1509 <div id="parent">
1510 <div id="child" style="width: 75%; height: 250px;">
1511 </div>
1512 </div>
1513 </div>
1514 )HTML");
1567 1515
1568 // child 1516 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( 1517 auto* space = ConstructConstraintSpace(
1577 kHorizontalTopBottom, TextDirection::kLtr, 1518 kHorizontalTopBottom, TextDirection::kLtr,
1578 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 1519 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
1579 RefPtr<const NGPhysicalBoxFragment> parent_fragment = 1520 RefPtr<const NGPhysicalBoxFragment> parent_fragment =
1580 RunBlockLayoutAlgorithm(space, parent); 1521 RunBlockLayoutAlgorithm(space, container);
1581 1522
1582 FragmentChildIterator iterator(parent_fragment.get()); 1523 FragmentChildIterator iterator(parent_fragment.get());
1583 const auto* fragment = iterator.NextChild(); 1524 const auto* fragment = iterator.NextChild();
1584 ASSERT_TRUE(fragment); 1525 ASSERT_TRUE(fragment);
1585 EXPECT_EQ(LayoutUnit(320), fragment->Width()); 1526 EXPECT_EQ(LayoutUnit(320), fragment->Width());
1586 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1527 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1587 EXPECT_FALSE(iterator.NextChild()); 1528 EXPECT_FALSE(iterator.NextChild());
1588 1529
1589 iterator.SetParent(fragment); 1530 iterator.SetParent(fragment);
1590 // #child fragment in first column 1531 // #child fragment in first column
(...skipping 18 matching lines...) Expand all
1609 fragment = iterator.NextChild(); 1550 fragment = iterator.NextChild();
1610 ASSERT_TRUE(fragment); 1551 ASSERT_TRUE(fragment);
1611 EXPECT_EQ(LayoutUnit(220), fragment->LeftOffset()); 1552 EXPECT_EQ(LayoutUnit(220), fragment->LeftOffset());
1612 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); 1553 EXPECT_EQ(LayoutUnit(), fragment->TopOffset());
1613 EXPECT_EQ(LayoutUnit(75), fragment->Width()); 1554 EXPECT_EQ(LayoutUnit(75), fragment->Width());
1614 EXPECT_EQ(LayoutUnit(50), fragment->Height()); 1555 EXPECT_EQ(LayoutUnit(50), fragment->Height());
1615 EXPECT_EQ(0U, fragment->Children().size()); 1556 EXPECT_EQ(0U, fragment->Children().size());
1616 EXPECT_FALSE(iterator.NextChild()); 1557 EXPECT_FALSE(iterator.NextChild());
1617 } 1558 }
1618 1559
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 1560 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm
1625 // is checked in. 1561 // is checked in.
1626 TEST_F(NGBlockLayoutAlgorithmTest, 1562 TEST_F(NGBlockLayoutAlgorithmTest,
1627 DISABLED_ActualColumnCountGreaterThanSpecified) { 1563 DISABLED_ActualColumnCountGreaterThanSpecified) {
1628 // parent 1564 setBodyInnerHTML(R"HTML(
1629 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); 1565 <style>
1630 parent_style->setColumnCount(2); 1566 #parent {
1631 parent_style->setColumnFill(ColumnFillAuto); 1567 column-count: 2;
1632 parent_style->setColumnGap(10); 1568 column-fill: auto;
1633 parent_style->setHeight(Length(100, Fixed)); 1569 column-gap: 10px;
1634 parent_style->setWidth(Length(210, Fixed)); 1570 height: 100px;
1635 NGBlockNode* parent = new NGBlockNode(parent_style.get()); 1571 width: 210px;
1572 }
1573 </style>
1574 <div id="container">
1575 <div id="parent">
1576 <div id="child" style="width: 1px; height: 250px;">
1577 </div>
1578 </div>
1579 </div>
1580 )HTML");
1636 1581
1637 // child 1582 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( 1583 auto* space = ConstructConstraintSpace(
1646 kHorizontalTopBottom, TextDirection::kLtr, 1584 kHorizontalTopBottom, TextDirection::kLtr,
1647 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 1585 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
1648 RefPtr<const NGPhysicalBoxFragment> parent_fragment = 1586 RefPtr<const NGPhysicalBoxFragment> parent_fragment =
1649 RunBlockLayoutAlgorithm(space, parent); 1587 RunBlockLayoutAlgorithm(space, container);
1650 1588
1651 FragmentChildIterator iterator(parent_fragment.get()); 1589 FragmentChildIterator iterator(parent_fragment.get());
1652 const auto* fragment = iterator.NextChild(); 1590 const auto* fragment = iterator.NextChild();
1653 ASSERT_TRUE(fragment); 1591 ASSERT_TRUE(fragment);
1654 EXPECT_EQ(LayoutUnit(210), fragment->Width()); 1592 EXPECT_EQ(LayoutUnit(210), fragment->Width());
1655 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1593 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1656 EXPECT_FALSE(iterator.NextChild()); 1594 EXPECT_FALSE(iterator.NextChild());
1657 1595
1658 iterator.SetParent(fragment); 1596 iterator.SetParent(fragment);
1659 // #child fragment in first column 1597 // #child fragment in first column
(...skipping 18 matching lines...) Expand all
1678 fragment = iterator.NextChild(); 1616 fragment = iterator.NextChild();
1679 ASSERT_TRUE(fragment); 1617 ASSERT_TRUE(fragment);
1680 EXPECT_EQ(LayoutUnit(220), fragment->LeftOffset()); 1618 EXPECT_EQ(LayoutUnit(220), fragment->LeftOffset());
1681 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); 1619 EXPECT_EQ(LayoutUnit(), fragment->TopOffset());
1682 EXPECT_EQ(LayoutUnit(1), fragment->Width()); 1620 EXPECT_EQ(LayoutUnit(1), fragment->Width());
1683 EXPECT_EQ(LayoutUnit(50), fragment->Height()); 1621 EXPECT_EQ(LayoutUnit(50), fragment->Height());
1684 EXPECT_EQ(0U, fragment->Children().size()); 1622 EXPECT_EQ(0U, fragment->Children().size());
1685 EXPECT_FALSE(iterator.NextChild()); 1623 EXPECT_FALSE(iterator.NextChild());
1686 } 1624 }
1687 1625
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 1626 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm
1695 // is checked in. 1627 // is checked in.
1696 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_TwoBlocksInTwoColumns) { 1628 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_TwoBlocksInTwoColumns) {
1697 // parent 1629 setBodyInnerHTML(R"HTML(
1698 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); 1630 <style>
1699 parent_style->setColumnCount(3); 1631 #parent {
1700 parent_style->setColumnFill(ColumnFillAuto); 1632 column-count: 3;
1701 parent_style->setColumnGap(10); 1633 column-fill: auto;
1702 parent_style->setHeight(Length(100, Fixed)); 1634 column-gap: 10px;
1703 parent_style->setWidth(Length(320, Fixed)); 1635 height: 100px;
1704 NGBlockNode* parent = new NGBlockNode(parent_style.get()); 1636 width: 320px;
1637 }
1638 </style>
1639 <div id="container">
1640 <div id="parent">
1641 <div id="child1" style="width: 75%; height: 60px;">
1642 </div>
1643 <div id="child2" style="width: 85%; height: 60px;">
1644 </div>
1645 </div>
1646 </div>
1647 )HTML");
1705 1648
1706 // child1 1649 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( 1650 auto* space = ConstructConstraintSpace(
1722 kHorizontalTopBottom, TextDirection::kLtr, 1651 kHorizontalTopBottom, TextDirection::kLtr,
1723 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 1652 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
1724 RefPtr<const NGPhysicalBoxFragment> parent_fragment = 1653 RefPtr<const NGPhysicalBoxFragment> parent_fragment =
1725 RunBlockLayoutAlgorithm(space, parent); 1654 RunBlockLayoutAlgorithm(space, container);
1726 1655
1727 FragmentChildIterator iterator(parent_fragment.get()); 1656 FragmentChildIterator iterator(parent_fragment.get());
1728 const auto* fragment = iterator.NextChild(); 1657 const auto* fragment = iterator.NextChild();
1729 ASSERT_TRUE(fragment); 1658 ASSERT_TRUE(fragment);
1730 EXPECT_EQ(LayoutUnit(320), fragment->Width()); 1659 EXPECT_EQ(LayoutUnit(320), fragment->Width());
1731 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1660 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1732 EXPECT_FALSE(iterator.NextChild()); 1661 EXPECT_FALSE(iterator.NextChild());
1733 1662
1734 iterator.SetParent(fragment); 1663 iterator.SetParent(fragment);
1735 // #child1 fragment in first column 1664 // #child1 fragment in first column
(...skipping 17 matching lines...) Expand all
1753 fragment = iterator.NextChild(); 1682 fragment = iterator.NextChild();
1754 ASSERT_TRUE(fragment); 1683 ASSERT_TRUE(fragment);
1755 EXPECT_EQ(LayoutUnit(110), fragment->LeftOffset()); 1684 EXPECT_EQ(LayoutUnit(110), fragment->LeftOffset());
1756 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); 1685 EXPECT_EQ(LayoutUnit(), fragment->TopOffset());
1757 EXPECT_EQ(LayoutUnit(85), fragment->Width()); 1686 EXPECT_EQ(LayoutUnit(85), fragment->Width());
1758 EXPECT_EQ(LayoutUnit(20), fragment->Height()); 1687 EXPECT_EQ(LayoutUnit(20), fragment->Height());
1759 EXPECT_EQ(0U, fragment->Children().size()); 1688 EXPECT_EQ(0U, fragment->Children().size());
1760 EXPECT_FALSE(iterator.NextChild()); 1689 EXPECT_FALSE(iterator.NextChild());
1761 } 1690 }
1762 1691
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 1692 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm
1773 // is checked in. 1693 // is checked in.
1774 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_OverflowedBlock) { 1694 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_OverflowedBlock) {
1775 // parent 1695 setBodyInnerHTML(R"HTML(
1776 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); 1696 <style>
1777 parent_style->setColumnCount(3); 1697 #parent {
1778 parent_style->setColumnFill(ColumnFillAuto); 1698 column-count: 2;
1779 parent_style->setColumnGap(10); 1699 column-fill: auto;
1780 parent_style->setHeight(Length(100, Fixed)); 1700 column-gap: 10px;
1781 parent_style->setWidth(Length(320, Fixed)); 1701 height: 100px;
1782 NGBlockNode* parent = new NGBlockNode(parent_style.get()); 1702 width: 320px;
1703 }
1704 </style>
1705 <div id="container">
1706 <div id="parent">
1707 <div id="child1" style="width: 75%; height: 60px;">
1708 <div id="grandchild1" style="width: 50px; height: 120px;">
1709 </div>
1710 <div id="grandchild2" style="width: 40px; height: 20px;">
1711 </div>
1712 </div>
1713 <div id="child2" style="width: 85%; height: 10px;"></div>
1714 </div>
1715 </div>
1716 </div>
1717 )HTML");
1783 1718
1784 // child1 1719 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( 1720 auto* space = ConstructConstraintSpace(
1814 kHorizontalTopBottom, TextDirection::kLtr, 1721 kHorizontalTopBottom, TextDirection::kLtr,
1815 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 1722 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
1816 RefPtr<const NGPhysicalBoxFragment> parent_fragment = 1723 RefPtr<const NGPhysicalBoxFragment> parent_fragment =
1817 RunBlockLayoutAlgorithm(space, parent); 1724 RunBlockLayoutAlgorithm(space, container);
1818 1725
1819 FragmentChildIterator iterator(parent_fragment.get()); 1726 FragmentChildIterator iterator(parent_fragment.get());
1820 const auto* fragment = iterator.NextChild(); 1727 const auto* fragment = iterator.NextChild();
1821 ASSERT_TRUE(fragment); 1728 ASSERT_TRUE(fragment);
1822 EXPECT_EQ(LayoutUnit(320), fragment->Width()); 1729 EXPECT_EQ(LayoutUnit(320), fragment->Width());
1823 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1730 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1824 EXPECT_FALSE(iterator.NextChild()); 1731 EXPECT_FALSE(iterator.NextChild());
1825 1732
1826 iterator.SetParent(fragment); 1733 iterator.SetParent(fragment);
1827 // #child1 fragment in first column 1734 // #child1 fragment in first column
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1868 fragment = grandchild_iterator.NextChild(); 1775 fragment = grandchild_iterator.NextChild();
1869 ASSERT_TRUE(fragment); 1776 ASSERT_TRUE(fragment);
1870 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset()); 1777 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset());
1871 EXPECT_EQ(LayoutUnit(20), fragment->TopOffset()); 1778 EXPECT_EQ(LayoutUnit(20), fragment->TopOffset());
1872 EXPECT_EQ(LayoutUnit(40), fragment->Width()); 1779 EXPECT_EQ(LayoutUnit(40), fragment->Width());
1873 EXPECT_EQ(LayoutUnit(20), fragment->Height()); 1780 EXPECT_EQ(LayoutUnit(20), fragment->Height());
1874 EXPECT_FALSE(grandchild_iterator.NextChild()); 1781 EXPECT_FALSE(grandchild_iterator.NextChild());
1875 EXPECT_FALSE(iterator.NextChild()); 1782 EXPECT_FALSE(iterator.NextChild());
1876 } 1783 }
1877 1784
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 1785 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm
1884 // is checked in. 1786 // is checked in.
1885 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_FloatInOneColumn) { 1787 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_FloatInOneColumn) {
1886 // parent 1788 setBodyInnerHTML(R"HTML(
1887 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); 1789 <style>
1888 parent_style->setColumnCount(3); 1790 #parent {
1889 parent_style->setColumnFill(ColumnFillAuto); 1791 column-count: 3;
1890 parent_style->setColumnGap(10); 1792 column-fill: auto;
1891 parent_style->setHeight(Length(100, Fixed)); 1793 column-gap: 10px;
1892 parent_style->setWidth(Length(320, Fixed)); 1794 height: 100px;
1893 NGBlockNode* parent = new NGBlockNode(parent_style.get()); 1795 width: 320px;
1796 }
1797 </style>
1798 <div id="container">
1799 <div id="parent">
1800 <div id="child" style="float: left; width: 75%; height: 100px;">
1801 </div>
1802 </div>
1803 </div>
1804 )HTML");
1894 1805
1895 // child 1806 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( 1807 auto* space = ConstructConstraintSpace(
1905 kHorizontalTopBottom, TextDirection::kLtr, 1808 kHorizontalTopBottom, TextDirection::kLtr,
1906 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 1809 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
1907 RefPtr<const NGPhysicalBoxFragment> parent_fragment = 1810 RefPtr<const NGPhysicalBoxFragment> parent_fragment =
1908 RunBlockLayoutAlgorithm(space, parent); 1811 RunBlockLayoutAlgorithm(space, container);
1909 1812
1910 FragmentChildIterator iterator(parent_fragment.get()); 1813 FragmentChildIterator iterator(parent_fragment.get());
1911 const auto* fragment = iterator.NextChild(); 1814 const auto* fragment = iterator.NextChild();
1912 ASSERT_TRUE(fragment); 1815 ASSERT_TRUE(fragment);
1913 EXPECT_EQ(LayoutUnit(320), fragment->Width()); 1816 EXPECT_EQ(LayoutUnit(320), fragment->Width());
1914 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1817 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1915 EXPECT_FALSE(iterator.NextChild()); 1818 EXPECT_FALSE(iterator.NextChild());
1916 1819
1917 iterator.SetParent(fragment); 1820 iterator.SetParent(fragment);
1918 // #child fragment in first column 1821 // #child fragment in first column
1919 fragment = iterator.NextChild(); 1822 fragment = iterator.NextChild();
1920 ASSERT_TRUE(fragment); 1823 ASSERT_TRUE(fragment);
1921 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset()); 1824 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset());
1922 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); 1825 EXPECT_EQ(LayoutUnit(), fragment->TopOffset());
1923 EXPECT_EQ(LayoutUnit(75), fragment->Width()); 1826 EXPECT_EQ(LayoutUnit(75), fragment->Width());
1924 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1827 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1925 EXPECT_EQ(0UL, fragment->Children().size()); 1828 EXPECT_EQ(0UL, fragment->Children().size());
1926 EXPECT_FALSE(iterator.NextChild()); 1829 EXPECT_FALSE(iterator.NextChild());
1927 } 1830 }
1928 1831
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 1832 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm
1936 // is checked in. 1833 // is checked in.
1937 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_TwoFloatsInOneColumn) { 1834 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_TwoFloatsInOneColumn) {
1938 // parent 1835 setBodyInnerHTML(R"HTML(
1939 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); 1836 <style>
1940 parent_style->setColumnCount(3); 1837 #parent {
1941 parent_style->setColumnFill(ColumnFillAuto); 1838 column-count: 3;
1942 parent_style->setColumnGap(10); 1839 column-fill: auto;
1943 parent_style->setHeight(Length(100, Fixed)); 1840 column-gap: 10px;
1944 parent_style->setWidth(Length(320, Fixed)); 1841 width: 320px;
1945 NGBlockNode* parent = new NGBlockNode(parent_style.get()); 1842 height: 100px;
1843 }
1844 </style>
1845 <div id="container">
1846 <div id="parent">
1847 <div id="child1" style="float: left; width: 15%; height: 100px;">
1848 </div>
1849 <div id="child2" style="float: right; width: 16%; height: 100px;">
1850 </div>
1851 </div>
1852 </div>
1853 )HTML");
1946 1854
1947 // child1 1855 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( 1856 auto* space = ConstructConstraintSpace(
1965 kHorizontalTopBottom, TextDirection::kLtr, 1857 kHorizontalTopBottom, TextDirection::kLtr,
1966 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 1858 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
1967 RefPtr<const NGPhysicalBoxFragment> parent_fragment = 1859 RefPtr<const NGPhysicalBoxFragment> parent_fragment =
1968 RunBlockLayoutAlgorithm(space, parent); 1860 RunBlockLayoutAlgorithm(space, container);
1969 1861
1970 FragmentChildIterator iterator(parent_fragment.get()); 1862 FragmentChildIterator iterator(parent_fragment.get());
1971 const auto* fragment = iterator.NextChild(); 1863 const auto* fragment = iterator.NextChild();
1972 ASSERT_TRUE(fragment); 1864 ASSERT_TRUE(fragment);
1973 EXPECT_EQ(LayoutUnit(320), fragment->Width()); 1865 EXPECT_EQ(LayoutUnit(320), fragment->Width());
1974 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1866 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1975 EXPECT_FALSE(iterator.NextChild()); 1867 EXPECT_FALSE(iterator.NextChild());
1976 1868
1977 iterator.SetParent(fragment); 1869 iterator.SetParent(fragment);
1978 // #child1 fragment in first column 1870 // #child1 fragment in first column
1979 fragment = iterator.NextChild(); 1871 fragment = iterator.NextChild();
1980 ASSERT_TRUE(fragment); 1872 ASSERT_TRUE(fragment);
1981 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset()); 1873 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset());
1982 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); 1874 EXPECT_EQ(LayoutUnit(), fragment->TopOffset());
1983 EXPECT_EQ(LayoutUnit(15), fragment->Width()); 1875 EXPECT_EQ(LayoutUnit(15), fragment->Width());
1984 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1876 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1985 EXPECT_EQ(0UL, fragment->Children().size()); 1877 EXPECT_EQ(0UL, fragment->Children().size());
1986 // #child2 fragment in first column 1878 // #child2 fragment in first column
1987 fragment = iterator.NextChild(); 1879 fragment = iterator.NextChild();
1988 ASSERT_TRUE(fragment); 1880 ASSERT_TRUE(fragment);
1989 EXPECT_EQ(LayoutUnit(84), fragment->LeftOffset()); 1881 EXPECT_EQ(LayoutUnit(84), fragment->LeftOffset());
1990 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); 1882 EXPECT_EQ(LayoutUnit(), fragment->TopOffset());
1991 EXPECT_EQ(LayoutUnit(16), fragment->Width()); 1883 EXPECT_EQ(LayoutUnit(16), fragment->Width());
1992 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1884 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1993 EXPECT_EQ(0UL, fragment->Children().size()); 1885 EXPECT_EQ(0UL, fragment->Children().size());
1994 EXPECT_FALSE(iterator.NextChild()); 1886 EXPECT_FALSE(iterator.NextChild());
1995 } 1887 }
1996 1888
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 1889 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm
2004 // is checked in. 1890 // is checked in.
2005 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_TwoFloatsInTwoColumns) { 1891 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_TwoFloatsInTwoColumns) {
2006 // parent 1892 setBodyInnerHTML(R"HTML(
2007 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); 1893 <style>
2008 parent_style->setColumnCount(3); 1894 #parent {
2009 parent_style->setColumnFill(ColumnFillAuto); 1895 column-count: 3;
2010 parent_style->setColumnGap(10); 1896 column-fill: auto;
2011 parent_style->setHeight(Length(100, Fixed)); 1897 column-gap: 10px;
2012 parent_style->setWidth(Length(320, Fixed)); 1898 width: 320px;
2013 NGBlockNode* parent = new NGBlockNode(parent_style.get()); 1899 height: 100px;
1900 }
1901 </style>
1902 <div id="container">
1903 <div id="parent">
1904 <div id="child1" style="float: left; width: 15%; height: 150px;">
1905 </div>
1906 <div id="child2" style="float: right; width: 16%; height: 150px;">
1907 </div>
1908 </div>
1909 </div>
1910 )HTML");
2014 1911
2015 // child1 1912 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( 1913 auto* space = ConstructConstraintSpace(
2033 kHorizontalTopBottom, TextDirection::kLtr, 1914 kHorizontalTopBottom, TextDirection::kLtr,
2034 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 1915 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
2035 RefPtr<const NGPhysicalBoxFragment> parent_fragment = 1916 RefPtr<const NGPhysicalBoxFragment> parent_fragment =
2036 RunBlockLayoutAlgorithm(space, parent); 1917 RunBlockLayoutAlgorithm(space, container);
2037 1918
2038 FragmentChildIterator iterator(parent_fragment.get()); 1919 FragmentChildIterator iterator(parent_fragment.get());
2039 const auto* fragment = iterator.NextChild(); 1920 const auto* fragment = iterator.NextChild();
2040 ASSERT_TRUE(fragment); 1921 ASSERT_TRUE(fragment);
2041 EXPECT_EQ(LayoutUnit(320), fragment->Width()); 1922 EXPECT_EQ(LayoutUnit(320), fragment->Width());
2042 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1923 EXPECT_EQ(LayoutUnit(100), fragment->Height());
2043 EXPECT_FALSE(iterator.NextChild()); 1924 EXPECT_FALSE(iterator.NextChild());
2044 1925
2045 iterator.SetParent(fragment); 1926 iterator.SetParent(fragment);
2046 // #child1 fragment in first column 1927 // #child1 fragment in first column
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
2475 2356
2476 child = iterator.NextChild(); 2357 child = iterator.NextChild();
2477 EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(100)), child->Size()); 2358 EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(100)), child->Size());
2478 EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(40)), child->Offset()); 2359 EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(40)), child->Offset());
2479 2360
2480 EXPECT_FALSE(iterator.NextChild()); 2361 EXPECT_FALSE(iterator.NextChild());
2481 } 2362 }
2482 2363
2483 } // namespace 2364 } // namespace
2484 } // namespace blink 2365 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698