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

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: 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/layout/ng/ng_block_node.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
ikilpatrick 2017/03/01 17:32:46 can we also remove/make private SetFirstChild now
atotic 2017/03/01 18:57:12 done. SetFirstChild/SetNextSibling are gone
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"));
ikilpatrick 2017/03/01 17:32:46 auto* box = ....
atotic 2017/03/01 18:57:13 done
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">
133 </div>
134 <div id="second_child"
135 style="height:30px;margin-top:5px;margin-bottom:20px">
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"));
ikilpatrick 2017/03/01 17:32:46 auto* (and elsewhere).
atotic 2017/03/01 18:57:13 done
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 // 168 //
172 // Test case's HTML representation: 169 // Test case's HTML representation:
173 // <div style="writing-mode: vertical-lr;"> 170 // <div style="writing-mode: vertical-lr;">
174 // <div style="width:50px; 171 // <div style="width:50px;
175 // height: 50px; margin-left: 100px; 172 // height: 50px; margin-left: 100px;
176 // writing-mode: horizontal-tb;"></div> 173 // writing-mode: horizontal-tb;"></div>
177 // </div> 174 // </div>
178 TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildrenWithWritingMode) { 175 TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildrenWithWritingMode) {
179 const int kWidth = 50; 176 setBodyInnerHTML(R"HTML(
177 <div id="container">
178 <div id="div1" style="writing-mode: vertical-lr;">
179 <div id="div2" style="width: 50px;
180 height: 50px; margin-left: 100px;
181 writing-mode: horizontal-tb;">
182 </div>
183 </div>
184 </div>
185 )HTML");
180 const int kHeight = 50; 186 const int kHeight = 50;
181 const int kMarginLeft = 100; 187 const int kMarginLeft = 100;
182 188
183 RefPtr<ComputedStyle> div1_style = ComputedStyle::create(); 189 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 = 190 auto* space =
197 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, 191 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr,
198 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); 192 NGLogicalSize(LayoutUnit(500), LayoutUnit(500)));
199 RefPtr<NGPhysicalBoxFragment> frag = RunBlockLayoutAlgorithm(space, div1); 193 RefPtr<NGPhysicalBoxFragment> frag =
194 RunBlockLayoutAlgorithm(space, container);
200 195
201 const NGPhysicalFragment* child = frag->Children()[0].get(); 196 const NGPhysicalFragment* child = frag->Children()[0].get();
202 // DIV2 197 // DIV2
203 child = static_cast<const NGPhysicalBoxFragment*>(child)->Children()[0].get(); 198 child = static_cast<const NGPhysicalBoxFragment*>(child)->Children()[0].get();
204 199
205 EXPECT_EQ(kHeight, child->Height()); 200 EXPECT_EQ(kHeight, child->Height());
206 EXPECT_EQ(0, child->TopOffset()); 201 EXPECT_EQ(0, child->TopOffset());
207 EXPECT_EQ(kMarginLeft, child->LeftOffset()); 202 EXPECT_EQ(kMarginLeft, child->LeftOffset());
208 } 203 }
209 204
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 toNGPhysicalBoxFragment(body_fragment->Children()[0].get()); 654 toNGPhysicalBoxFragment(body_fragment->Children()[0].get());
660 // Collapsed margins with result = 0. 655 // Collapsed margins with result = 0.
661 EXPECT_THAT(p_fragment->Offset(), 656 EXPECT_THAT(p_fragment->Offset(),
662 NGPhysicalOffset(LayoutUnit(20), LayoutUnit(0))); 657 NGPhysicalOffset(LayoutUnit(20), LayoutUnit(0)));
663 } 658 }
664 659
665 // Verifies that the margin strut of a child with a different writing mode does 660 // Verifies that the margin strut of a child with a different writing mode does
666 // not get used in the collapsing margins calculation. 661 // not get used in the collapsing margins calculation.
667 // 662 //
668 // Test case's HTML representation: 663 // Test case's HTML representation:
669 // <style> 664 // <style>
670 // #div1 { margin-bottom: 10px; height: 60px; writing-mode: vertical-rl; } 665 // #div1 { margin-bottom: 10px; height: 60px; writing-mode: vertical-rl; }
671 // #div2 { margin-left: -20px; width: 10px; } 666 // #div2 { margin-left: -20px; width: 10px; }
672 // #div3 { margin-top: 40px; height: 60px; } 667 // #div3 { margin-top: 40px; height: 60px; }
673 // </style> 668 // </style>
674 // <div id="div1"> 669 // <div id="div1">
675 // <div id="div2">vertical</div> 670 // <div id="div2">vertical</div>
676 // </div> 671 // </div>
677 // <div id="div3"></div> 672 // <div id="div3"></div>
678 // TODO(glebl): Disabled for now. Follow-up with kojii@ on 673 // TODO(glebl): Disabled for now. Follow-up with kojii@ on
679 // https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=4844 674 // https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=4844
680 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_CollapsingMarginsCase6) { 675 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_CollapsingMarginsCase6) {
676 setBodyInnerHTML(R"HTML(
677 <style>
678 #div1 { margin-bottom: 10px; width: 10px; height: 60px; writing-mode: vert ical-rl; }
Gleb Lanbin 2017/03/01 17:25:22 this shouldn't be longer than 80 symbols.
atotic 2017/03/01 18:57:12 done
679 #div2 { margin-left: -20px; width: 10px; }
680 #div3 { margin-top: 40px; height: 60px; }
681 </style>
682 <div id="container" style="width:500px;height:500px">
683 <div id="div1">
684 <div id="div2">vertical</div>
685 </div>
686 <div id="div3"></div>
687 </div>
688 )HTML");
681 const int kHeight = 60; 689 const int kHeight = 60;
682 const int kWidth = 10;
683 const int kMarginBottom = 10; 690 const int kMarginBottom = 10;
684 const int kMarginLeft = -20;
685 const int kMarginTop = 40; 691 const int kMarginTop = 40;
686 692
687 style_->setWidth(Length(500, Fixed)); 693 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 = 694 auto* space =
714 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, 695 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr,
715 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); 696 NGLogicalSize(LayoutUnit(500), LayoutUnit(500)));
716 RefPtr<NGPhysicalBoxFragment> frag = RunBlockLayoutAlgorithm(space, div1); 697 RefPtr<NGPhysicalBoxFragment> frag =
698 RunBlockLayoutAlgorithm(space, container);
717 699
718 ASSERT_EQ(frag->Children().size(), 2UL); 700 ASSERT_EQ(frag->Children().size(), 2UL);
719 701
720 const NGPhysicalFragment* child1 = frag->Children()[0].get(); 702 const NGPhysicalFragment* child1 = frag->Children()[0].get();
721 EXPECT_EQ(0, child1->TopOffset()); 703 EXPECT_EQ(0, child1->TopOffset());
722 EXPECT_EQ(kHeight, child1->Height()); 704 EXPECT_EQ(kHeight, child1->Height());
723 705
724 const NGPhysicalFragment* child2 = frag->Children()[1].get(); 706 const NGPhysicalFragment* child2 = frag->Children()[1].get();
725 EXPECT_EQ(kHeight + std::max(kMarginBottom, kMarginTop), child2->TopOffset()); 707 EXPECT_EQ(kHeight + std::max(kMarginBottom, kMarginTop), child2->TopOffset());
726 } 708 }
727 709
728 // Verifies that a box's size includes its borders and padding, and that 710 // Verifies that a box's size includes its borders and padding, and that
729 // children are positioned inside the content box. 711 // children are positioned inside the content box.
730 // 712 //
731 // Test case's HTML representation: 713 // Test case's HTML representation:
732 // <style> 714 // <style>
733 // #div1 { width:100px; height:100px; } 715 // #div1 { width:100px; height:100px; }
734 // #div1 { border-style:solid; border-width:1px 2px 3px 4px; } 716 // #div1 { border-style:solid; border-width:1px 2px 3px 4px; }
735 // #div1 { padding:5px 6px 7px 8px; } 717 // #div1 { padding:5px 6px 7px 8px; }
736 // </style> 718 // </style>
737 // <div id="div1"> 719 // <div id="div1">
738 // <div id="div2"></div> 720 // <div id="div2"></div>
739 // </div> 721 // </div>
740 TEST_F(NGBlockLayoutAlgorithmTest, BorderAndPadding) { 722 TEST_F(NGBlockLayoutAlgorithmTest, BorderAndPadding) {
723 setBodyInnerHTML(R"HTML(
724 <style>
725 #div1 { width:100px; height:100px; }
726 #div1 { border-style:solid; border-width:1px 2px 3px 4px; }
727 #div1 { padding:5px 6px 7px 8px; }
728 </style>
729 <div id="container">
730 <div id="div1">
731 <div id="div2"></div>
732 </div>
733 </div>
734 )HTML");
741 const int kWidth = 100; 735 const int kWidth = 100;
742 const int kHeight = 100; 736 const int kHeight = 100;
743 const int kBorderTop = 1; 737 const int kBorderTop = 1;
744 const int kBorderRight = 2; 738 const int kBorderRight = 2;
745 const int kBorderBottom = 3; 739 const int kBorderBottom = 3;
746 const int kBorderLeft = 4; 740 const int kBorderLeft = 4;
747 const int kPaddingTop = 5; 741 const int kPaddingTop = 5;
748 const int kPaddingRight = 6; 742 const int kPaddingRight = 6;
749 const int kPaddingBottom = 7; 743 const int kPaddingBottom = 7;
750 const int kPaddingLeft = 8; 744 const int kPaddingLeft = 8;
751 RefPtr<ComputedStyle> div1_style = ComputedStyle::create();
752 745
753 div1_style->setWidth(Length(kWidth, Fixed)); 746 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 747
776 auto* space = ConstructConstraintSpace( 748 auto* space = ConstructConstraintSpace(
777 kHorizontalTopBottom, TextDirection::kLtr, 749 kHorizontalTopBottom, TextDirection::kLtr,
778 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 750 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
779 RefPtr<NGPhysicalBoxFragment> frag = RunBlockLayoutAlgorithm(space, div1); 751
752 RefPtr<NGPhysicalBoxFragment> frag =
753 RunBlockLayoutAlgorithm(space, container);
780 754
781 ASSERT_EQ(frag->Children().size(), 1UL); 755 ASSERT_EQ(frag->Children().size(), 1UL);
782 756
783 // div1 757 // div1
784 const NGPhysicalFragment* child = frag->Children()[0].get(); 758 const NGPhysicalFragment* child = frag->Children()[0].get();
785 EXPECT_EQ(kBorderLeft + kPaddingLeft + kWidth + kPaddingRight + kBorderRight, 759 EXPECT_EQ(kBorderLeft + kPaddingLeft + kWidth + kPaddingRight + kBorderRight,
786 child->Width()); 760 child->Width());
787 EXPECT_EQ(kBorderTop + kPaddingTop + kHeight + kPaddingBottom + kBorderBottom, 761 EXPECT_EQ(kBorderTop + kPaddingTop + kHeight + kPaddingBottom + kBorderBottom,
788 child->Height()); 762 child->Height());
789 763
790 ASSERT_TRUE(child->Type() == NGPhysicalFragment::kFragmentBox); 764 ASSERT_TRUE(child->Type() == NGPhysicalFragment::kFragmentBox);
791 ASSERT_EQ(static_cast<const NGPhysicalBoxFragment*>(child)->Children().size(), 765 ASSERT_EQ(static_cast<const NGPhysicalBoxFragment*>(child)->Children().size(),
792 1UL); 766 1UL);
793 767
794 // div2 768 // div2
795 child = static_cast<const NGPhysicalBoxFragment*>(child)->Children()[0].get(); 769 child = static_cast<const NGPhysicalBoxFragment*>(child)->Children()[0].get();
796 EXPECT_EQ(kBorderTop + kPaddingTop, child->TopOffset()); 770 EXPECT_EQ(kBorderTop + kPaddingTop, child->TopOffset());
797 EXPECT_EQ(kBorderLeft + kPaddingLeft, child->LeftOffset()); 771 EXPECT_EQ(kBorderLeft + kPaddingLeft, child->LeftOffset());
798 } 772 }
799 773
800 TEST_F(NGBlockLayoutAlgorithmTest, PercentageResolutionSize) { 774 TEST_F(NGBlockLayoutAlgorithmTest, PercentageResolutionSize) {
775 setBodyInnerHTML(R"HTML(
776 <div id="container" style="width:30px;padding-left:10px">
777 <div id="div1" style="width:40%"></div>
778 </div>
779 )HTML");
801 const int kPaddingLeft = 10; 780 const int kPaddingLeft = 10;
802 const int kWidth = 30; 781 const int kWidth = 30;
803 style_->setWidth(Length(kWidth, Fixed));
804 style_->setPaddingLeft(Length(kPaddingLeft, Fixed));
805 782
806 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); 783 auto container = new NGBlockNode(getLayoutObjectByElementId("container"));
807 first_style->setWidth(Length(40, Percent));
808 NGBlockNode* first_child = new NGBlockNode(first_style.get());
809 784
810 auto* space = ConstructConstraintSpace( 785 auto* space = ConstructConstraintSpace(
811 kHorizontalTopBottom, TextDirection::kLtr, 786 kHorizontalTopBottom, TextDirection::kLtr,
812 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); 787 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite));
813 RefPtr<NGPhysicalBoxFragment> frag = 788 RefPtr<NGPhysicalBoxFragment> frag =
814 RunBlockLayoutAlgorithm(space, first_child); 789 RunBlockLayoutAlgorithm(space, container);
815 790
816 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width()); 791 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width());
817 EXPECT_EQ(NGPhysicalFragment::kFragmentBox, frag->Type()); 792 EXPECT_EQ(NGPhysicalFragment::kFragmentBox, frag->Type());
818 ASSERT_EQ(frag->Children().size(), 1UL); 793 ASSERT_EQ(frag->Children().size(), 1UL);
819 794
820 const NGPhysicalFragment* child = frag->Children()[0].get(); 795 const NGPhysicalFragment* child = frag->Children()[0].get();
821 EXPECT_EQ(LayoutUnit(12), child->Width()); 796 EXPECT_EQ(LayoutUnit(12), child->Width());
822 } 797 }
823 798
824 // A very simple auto margin case. We rely on the tests in ng_length_utils_test 799 // 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. 800 // for the more complex cases; just make sure we handle auto at all here.
826 TEST_F(NGBlockLayoutAlgorithmTest, AutoMargin) { 801 TEST_F(NGBlockLayoutAlgorithmTest, AutoMargin) {
802 setBodyInnerHTML(R"HTML(
803 <div id="container" style="width:30px;padding-left:10px">
804 <div id="first" style="width:10px;margin-left:auto;margin-right:auto"></di v>
Gleb Lanbin 2017/03/01 17:25:22 same here.
atotic 2017/03/01 18:57:13 done
805 </div>
806 )HTML");
827 const int kPaddingLeft = 10; 807 const int kPaddingLeft = 10;
828 const int kWidth = 30; 808 const int kWidth = 30;
829 style_->setWidth(Length(kWidth, Fixed)); 809 const int kChildWidth = 10;
830 style_->setPaddingLeft(Length(kPaddingLeft, Fixed));
831 810
832 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); 811 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 812
839 auto* space = ConstructConstraintSpace( 813 auto* space = ConstructConstraintSpace(
840 kHorizontalTopBottom, TextDirection::kLtr, 814 kHorizontalTopBottom, TextDirection::kLtr,
841 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); 815 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite));
842 RefPtr<NGPhysicalBoxFragment> frag = 816 RefPtr<NGPhysicalBoxFragment> frag =
843 RunBlockLayoutAlgorithm(space, first_child); 817 RunBlockLayoutAlgorithm(space, container);
844 818
845 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width()); 819 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width());
846 EXPECT_EQ(NGPhysicalFragment::kFragmentBox, frag->Type()); 820 EXPECT_EQ(NGPhysicalFragment::kFragmentBox, frag->Type());
847 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->WidthOverflow()); 821 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->WidthOverflow());
848 ASSERT_EQ(1UL, frag->Children().size()); 822 ASSERT_EQ(1UL, frag->Children().size());
849 823
850 const NGPhysicalFragment* child = frag->Children()[0].get(); 824 const NGPhysicalFragment* child = frag->Children()[0].get();
851 EXPECT_EQ(LayoutUnit(kChildWidth), child->Width()); 825 EXPECT_EQ(LayoutUnit(kChildWidth), child->Width());
852 EXPECT_EQ(LayoutUnit(kPaddingLeft + 10), child->LeftOffset()); 826 EXPECT_EQ(LayoutUnit(kPaddingLeft + 10), child->LeftOffset());
853 EXPECT_EQ(LayoutUnit(0), child->TopOffset()); 827 EXPECT_EQ(LayoutUnit(0), child->TopOffset());
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 run_with_clearance(EClear::kBoth); 1251 run_with_clearance(EClear::kBoth);
1278 EXPECT_EQ(LayoutUnit(8), body_fragment->TopOffset()); 1252 EXPECT_EQ(LayoutUnit(8), body_fragment->TopOffset());
1279 EXPECT_EQ(LayoutUnit(0), container_fragment->TopOffset()); 1253 EXPECT_EQ(LayoutUnit(0), container_fragment->TopOffset());
1280 EXPECT_EQ(LayoutUnit(170), clerance_fragment->TopOffset()); 1254 EXPECT_EQ(LayoutUnit(170), clerance_fragment->TopOffset());
1281 EXPECT_EQ(LayoutUnit(270), block_fragment->TopOffset()); 1255 EXPECT_EQ(LayoutUnit(270), block_fragment->TopOffset());
1282 EXPECT_EQ(LayoutUnit(370), adjoining_clearance_fragment->TopOffset()); 1256 EXPECT_EQ(LayoutUnit(370), adjoining_clearance_fragment->TopOffset());
1283 } 1257 }
1284 1258
1285 // Verifies that we compute the right min and max-content size. 1259 // Verifies that we compute the right min and max-content size.
1286 TEST_F(NGBlockLayoutAlgorithmTest, ComputeMinMaxContent) { 1260 TEST_F(NGBlockLayoutAlgorithmTest, ComputeMinMaxContent) {
1287 const int kWidth = 50; 1261 setBodyInnerHTML(R"HTML(
1288 const int kWidthChild1 = 20; 1262 <div id="container" style="width:50px">
1263 <div id="first_child" style="width:20px"></div>
1264 <div id="second_child" style="width:30px"></div>
1265 </div>
1266 )HTML");
1267
1289 const int kWidthChild2 = 30; 1268 const int kWidthChild2 = 30;
1290 1269
1291 // This should have no impact on the min/max content size. 1270 auto container = new NGBlockNode(getLayoutObjectByElementId("container"));
1292 style_->setWidth(Length(kWidth, Fixed));
1293 1271
1294 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); 1272 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); 1273 EXPECT_EQ(kWidthChild2, sizes.min_content);
1306 EXPECT_EQ(kWidthChild2, sizes.max_content); 1274 EXPECT_EQ(kWidthChild2, sizes.max_content);
1307 } 1275 }
1308 1276
1309 // Tests that we correctly handle shrink-to-fit 1277 // Tests that we correctly handle shrink-to-fit
1310 TEST_F(NGBlockLayoutAlgorithmTest, ShrinkToFit) { 1278 TEST_F(NGBlockLayoutAlgorithmTest, ShrinkToFit) {
1311 const int kWidthChild1 = 20; 1279 setBodyInnerHTML(R"HTML(
1280 <div id="container">
1281 <div id="first_child" style="width:20px"></div>
1282 <div id="second_child" style="width:30px"></div>
1283 </div>
1284 )HTML");
1312 const int kWidthChild2 = 30; 1285 const int kWidthChild2 = 30;
1313 1286
1314 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); 1287 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 1288
1324 auto* space = ConstructConstraintSpace( 1289 auto* space = ConstructConstraintSpace(
1325 kHorizontalTopBottom, TextDirection::kLtr, 1290 kHorizontalTopBottom, TextDirection::kLtr,
1326 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite), true); 1291 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite), true);
1327 RefPtr<NGPhysicalFragment> frag = RunBlockLayoutAlgorithm(space, first_child); 1292 RefPtr<NGPhysicalFragment> frag = RunBlockLayoutAlgorithm(space, container);
1328 1293
1329 EXPECT_EQ(LayoutUnit(30), frag->Width()); 1294 EXPECT_EQ(LayoutUnit(kWidthChild2), frag->Width());
1330 } 1295 }
1331 1296
1332 class FragmentChildIterator { 1297 class FragmentChildIterator {
1333 STACK_ALLOCATED(); 1298 STACK_ALLOCATED();
1334 1299
1335 public: 1300 public:
1336 explicit FragmentChildIterator(const NGPhysicalBoxFragment* parent) { 1301 explicit FragmentChildIterator(const NGPhysicalBoxFragment* parent) {
1337 SetParent(parent); 1302 SetParent(parent);
1338 } 1303 }
1339 void SetParent(const NGPhysicalBoxFragment* parent) { 1304 void SetParent(const NGPhysicalBoxFragment* parent) {
(...skipping 20 matching lines...) Expand all
1360 unsigned index_; 1325 unsigned index_;
1361 }; 1326 };
1362 1327
1363 // Test case's HTML representation: 1328 // Test case's HTML representation:
1364 // <div id="parent" style="columns:2; column-fill:auto; column-gap:10px; 1329 // <div id="parent" style="columns:2; column-fill:auto; column-gap:10px;
1365 // width:210px; height:100px;"> 1330 // width:210px; height:100px;">
1366 // </div> 1331 // </div>
1367 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm 1332 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm
1368 // is checked in. 1333 // is checked in.
1369 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_EmptyMulticol) { 1334 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_EmptyMulticol) {
1370 // parent 1335 setBodyInnerHTML(R"HTML(
1371 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); 1336 <div id="container">
1372 parent_style->setColumnCount(2); 1337 <div id="parent" style="column-count: 2; column-fill: auto;
1373 parent_style->setColumnFill(ColumnFillAuto); 1338 column-gap: 10px; height: 100px; width: 210px;">
1374 parent_style->setColumnGap(10); 1339 </div>
1375 parent_style->setHeight(Length(100, Fixed)); 1340 </div>
1376 parent_style->setWidth(Length(210, Fixed)); 1341 )HTML");
1377 NGBlockNode* parent = new NGBlockNode(parent_style.get());
1378 1342
1343 auto container = new NGBlockNode(getLayoutObjectByElementId("container"));
Gleb Lanbin 2017/03/01 17:25:22 auto* ? here and below.
atotic 2017/03/01 18:57:13 done
1379 auto* space = ConstructConstraintSpace( 1344 auto* space = ConstructConstraintSpace(
1380 kHorizontalTopBottom, TextDirection::kLtr, 1345 kHorizontalTopBottom, TextDirection::kLtr,
1381 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 1346 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
1382 RefPtr<const NGPhysicalBoxFragment> parent_fragment = 1347 RefPtr<const NGPhysicalBoxFragment> parent_fragment =
1383 RunBlockLayoutAlgorithm(space, parent); 1348 RunBlockLayoutAlgorithm(space, container);
1384 FragmentChildIterator iterator(parent_fragment.get()); 1349 FragmentChildIterator iterator(parent_fragment.get());
1385 const auto* fragment = iterator.NextChild(); 1350 const auto* fragment = iterator.NextChild();
1386 ASSERT_TRUE(fragment); 1351 ASSERT_TRUE(fragment);
1387 EXPECT_EQ(LayoutUnit(210), fragment->Width()); 1352 EXPECT_EQ(LayoutUnit(210), fragment->Width());
1388 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1353 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1389 EXPECT_FALSE(iterator.NextChild()); 1354 EXPECT_FALSE(iterator.NextChild());
1390 1355
1391 // There should be nothing inside the multicol container. 1356 // There should be nothing inside the multicol container.
1392 EXPECT_FALSE(FragmentChildIterator(fragment).NextChild()); 1357 EXPECT_FALSE(FragmentChildIterator(fragment).NextChild());
1393 } 1358 }
1394 1359
1395 // Test case's HTML representation: 1360 // Test case's HTML representation:
1396 // <div id="parent" style="columns:2; column-fill:auto; column-gap:10px; 1361 // <div id="parent" style="columns:2; column-fill:auto; column-gap:10px;
1397 // width:210px; height:100px;"> 1362 // width:210px; height:100px;">
1398 // <div id="child"></div> 1363 // <div id="child"></div>
1399 // </div> 1364 // </div>
1400 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm 1365 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm
1401 // is checked in. 1366 // is checked in.
1402 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_EmptyBlock) { 1367 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_EmptyBlock) {
1403 // parent 1368 setBodyInnerHTML(R"HTML(
1404 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); 1369 <div id="container">
1405 parent_style->setColumnCount(2); 1370 <div id="parent" style="column-count: 2; column-fill: auto;
1406 parent_style->setColumnFill(ColumnFillAuto); 1371 column-gap: 10px; height: 100px; width: 210px;">
1407 parent_style->setColumnGap(10); 1372 <div id="child"></div>
1408 parent_style->setHeight(Length(100, Fixed)); 1373 </div>
1409 parent_style->setWidth(Length(210, Fixed)); 1374 </div>
1410 NGBlockNode* parent = new NGBlockNode(parent_style.get()); 1375 )HTML");
1411 1376
1412 // child 1377 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( 1378 auto* space = ConstructConstraintSpace(
1419 kHorizontalTopBottom, TextDirection::kLtr, 1379 kHorizontalTopBottom, TextDirection::kLtr,
1420 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 1380 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
1421 RefPtr<const NGPhysicalBoxFragment> parent_fragment = 1381 RefPtr<const NGPhysicalBoxFragment> parent_fragment =
1422 RunBlockLayoutAlgorithm(space, parent); 1382 RunBlockLayoutAlgorithm(space, container);
1423 FragmentChildIterator iterator(parent_fragment.get()); 1383 FragmentChildIterator iterator(parent_fragment.get());
1424 const auto* fragment = iterator.NextChild(); 1384 const auto* fragment = iterator.NextChild();
1425 EXPECT_EQ(LayoutUnit(210), fragment->Width()); 1385 EXPECT_EQ(LayoutUnit(210), fragment->Width());
1426 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1386 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1427 ASSERT_TRUE(fragment); 1387 ASSERT_TRUE(fragment);
1428 EXPECT_FALSE(iterator.NextChild()); 1388 EXPECT_FALSE(iterator.NextChild());
1429 iterator.SetParent(fragment); 1389 iterator.SetParent(fragment);
1430 1390
1431 // #child fragment in first column 1391 // #child fragment in first column
1432 fragment = iterator.NextChild(); 1392 fragment = iterator.NextChild();
1433 ASSERT_TRUE(fragment); 1393 ASSERT_TRUE(fragment);
1434 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset()); 1394 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset());
1435 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); 1395 EXPECT_EQ(LayoutUnit(), fragment->TopOffset());
1436 EXPECT_EQ(LayoutUnit(100), fragment->Width()); 1396 EXPECT_EQ(LayoutUnit(100), fragment->Width());
1437 EXPECT_EQ(LayoutUnit(), fragment->Height()); 1397 EXPECT_EQ(LayoutUnit(), fragment->Height());
1438 EXPECT_EQ(0UL, fragment->Children().size()); 1398 EXPECT_EQ(0UL, fragment->Children().size());
1439 EXPECT_FALSE(iterator.NextChild()); 1399 EXPECT_FALSE(iterator.NextChild());
1440 } 1400 }
1441 1401
1442 // Test case's HTML representation: 1402 // Test case's HTML representation:
1443 // <div id="parent" style="columns:2; column-fill:auto; column-gap:10px; 1403 // <div id="parent" style="columns:2; column-fill:auto; column-gap:10px;
1444 // width:310px; height:100px;"> 1404 // width:310px; height:100px;">
1445 // <div id="child" style="width:60%; height:100px;"></div> 1405 // <div id="child" style="width:60%; height:100px;"></div>
1446 // </div> 1406 // </div>
1447 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm 1407 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm
1448 // is checked in. 1408 // is checked in.
1449 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_BlockInOneColumn) { 1409 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_BlockInOneColumn) {
1450 // parent 1410 setBodyInnerHTML(R"HTML(
1451 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); 1411 <div id="container">
1452 parent_style->setColumnCount(2); 1412 <div id="parent" style="column-count: 2; column-fill: auto;
1453 parent_style->setColumnFill(ColumnFillAuto); 1413 column-gap: 10px; height: 100px; width: 310px;">
1454 parent_style->setColumnGap(10); 1414 <div id="child" style="width: 60%; height: 100%">
1455 parent_style->setHeight(Length(100, Fixed)); 1415 </div>
1456 parent_style->setWidth(Length(310, Fixed)); 1416 </div>
1457 NGBlockNode* parent = new NGBlockNode(parent_style.get()); 1417 </div>
1418 )HTML");
1458 1419
1459 // child 1420 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( 1421 auto* space = ConstructConstraintSpace(
1468 kHorizontalTopBottom, TextDirection::kLtr, 1422 kHorizontalTopBottom, TextDirection::kLtr,
1469 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 1423 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
1470 RefPtr<const NGPhysicalBoxFragment> parent_fragment = 1424 RefPtr<const NGPhysicalBoxFragment> parent_fragment =
1471 RunBlockLayoutAlgorithm(space, parent); 1425 RunBlockLayoutAlgorithm(space, container);
1472 1426
1473 FragmentChildIterator iterator(parent_fragment.get()); 1427 FragmentChildIterator iterator(parent_fragment.get());
1474 const auto* fragment = iterator.NextChild(); 1428 const auto* fragment = iterator.NextChild();
1475 ASSERT_TRUE(fragment); 1429 ASSERT_TRUE(fragment);
1476 EXPECT_EQ(LayoutUnit(310), fragment->Width()); 1430 EXPECT_EQ(LayoutUnit(310), fragment->Width());
1477 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1431 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1478 EXPECT_FALSE(iterator.NextChild()); 1432 EXPECT_FALSE(iterator.NextChild());
1479 iterator.SetParent(fragment); 1433 iterator.SetParent(fragment);
1480 1434
1481 // #child fragment in first column 1435 // #child fragment in first column
1482 fragment = iterator.NextChild(); 1436 fragment = iterator.NextChild();
1483 ASSERT_TRUE(fragment); 1437 ASSERT_TRUE(fragment);
1484 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset()); 1438 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset());
1485 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); 1439 EXPECT_EQ(LayoutUnit(), fragment->TopOffset());
1486 EXPECT_EQ(LayoutUnit(90), fragment->Width()); 1440 EXPECT_EQ(LayoutUnit(90), fragment->Width());
1487 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1441 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1488 EXPECT_EQ(0UL, fragment->Children().size()); 1442 EXPECT_EQ(0UL, fragment->Children().size());
1489 EXPECT_FALSE(iterator.NextChild()); 1443 EXPECT_FALSE(iterator.NextChild());
1490 } 1444 }
1491 1445
1492 // Test case's HTML representation: 1446 // Test case's HTML representation:
1493 // <div id="parent" style="columns:2; column-fill:auto; column-gap:10px; 1447 // <div id="parent" style="columns:2; column-fill:auto; column-gap:10px;
1494 // width:210px; height:100px;"> 1448 // width:210px; height:100px;">
1495 // <div id="child" style="width:75%; height:150px;"></div> 1449 // <div id="child" style="width:75%; height:150px;"></div>
1496 // </div> 1450 // </div>
1497 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm 1451 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm
1498 // is checked in. 1452 // is checked in.
1499 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_BlockInTwoColumns) { 1453 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_BlockInTwoColumns) {
1500 // parent 1454 setBodyInnerHTML(R"HTML(
1501 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); 1455 <div id="container">
1502 parent_style->setColumnCount(2); 1456 <div id="parent" style="column-count: 2; column-fill: auto;
Gleb Lanbin 2017/03/01 17:25:22 can you move the style definition to <style> ? and
atotic 2017/03/01 18:57:12 done for long style defs.
1503 parent_style->setColumnFill(ColumnFillAuto); 1457 column-gap: 10px; height: 100px; width: 210px;">
1504 parent_style->setColumnGap(10); 1458 <div id="child" style="width: 75%; height: 150px"></div>
1505 parent_style->setHeight(Length(100, Fixed)); 1459 </div>
1506 parent_style->setWidth(Length(210, Fixed)); 1460 </div>
1507 NGBlockNode* parent = new NGBlockNode(parent_style.get()); 1461 )HTML");
1508 1462
1509 // child 1463 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( 1464 auto* space = ConstructConstraintSpace(
1518 kHorizontalTopBottom, TextDirection::kLtr, 1465 kHorizontalTopBottom, TextDirection::kLtr,
1519 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 1466 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
1520 RefPtr<const NGPhysicalBoxFragment> parent_fragment = 1467 RefPtr<const NGPhysicalBoxFragment> parent_fragment =
1521 RunBlockLayoutAlgorithm(space, parent); 1468 RunBlockLayoutAlgorithm(space, container);
1522 1469
1523 FragmentChildIterator iterator(parent_fragment.get()); 1470 FragmentChildIterator iterator(parent_fragment.get());
1524 const auto* fragment = iterator.NextChild(); 1471 const auto* fragment = iterator.NextChild();
1525 ASSERT_TRUE(fragment); 1472 ASSERT_TRUE(fragment);
1526 EXPECT_EQ(LayoutUnit(210), fragment->Width()); 1473 EXPECT_EQ(LayoutUnit(210), fragment->Width());
1527 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1474 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1528 EXPECT_FALSE(iterator.NextChild()); 1475 EXPECT_FALSE(iterator.NextChild());
1529 1476
1530 iterator.SetParent(fragment); 1477 iterator.SetParent(fragment);
1531 // #child fragment in first column 1478 // #child fragment in first column
(...skipping 17 matching lines...) Expand all
1549 } 1496 }
1550 1497
1551 // Test case's HTML representation: 1498 // Test case's HTML representation:
1552 // <div id="parent" style="columns:3; column-fill:auto; column-gap:10px; 1499 // <div id="parent" style="columns:3; column-fill:auto; column-gap:10px;
1553 // width:320px; height:100px;"> 1500 // width:320px; height:100px;">
1554 // <div id="child" style="width:75%; height:250px;"></div> 1501 // <div id="child" style="width:75%; height:250px;"></div>
1555 // </div> 1502 // </div>
1556 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm 1503 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm
1557 // is checked in. 1504 // is checked in.
1558 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_BlockInThreeColumns) { 1505 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_BlockInThreeColumns) {
1559 // parent 1506 setBodyInnerHTML(R"HTML(
1560 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); 1507 <div id="container">
1561 parent_style->setColumnCount(3); 1508 <div id="parent" style="column-count: 3; column-fill: auto;
1562 parent_style->setColumnFill(ColumnFillAuto); 1509 column-gap: 10px; height: 100px; width: 320px;">
1563 parent_style->setColumnGap(10); 1510 <div id="child" style="width: 75%; height: 250px;">
1564 parent_style->setHeight(Length(100, Fixed)); 1511 </div>
1565 parent_style->setWidth(Length(320, Fixed)); 1512 </div>
1566 NGBlockNode* parent = new NGBlockNode(parent_style.get()); 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 27 matching lines...) Expand all
1618 1559
1619 // Test case's HTML representation: 1560 // Test case's HTML representation:
1620 // <div id="parent" style="columns:2; column-fill:auto; column-gap:10px; 1561 // <div id="parent" style="columns:2; column-fill:auto; column-gap:10px;
1621 // width:210px; height:100px;"> 1562 // width:210px; height:100px;">
1622 // <div id="child" style="width:1px; height:250px;"></div> 1563 // <div id="child" style="width:1px; height:250px;"></div>
1623 // </div> 1564 // </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 <div id="container">
1630 parent_style->setColumnCount(2); 1571 <div id="parent" style="column-count: 2; column-fill: auto;
1631 parent_style->setColumnFill(ColumnFillAuto); 1572 column-gap: 10px; height: 100px; width: 210px;">
1632 parent_style->setColumnGap(10); 1573 <div id="child" style="width: 1px; height: 250px;">
1633 parent_style->setHeight(Length(100, Fixed)); 1574 </div>
1634 parent_style->setWidth(Length(210, Fixed)); 1575 </div>
1635 NGBlockNode* parent = new NGBlockNode(parent_style.get()); 1576 </div>
1577 )HTML");
1636 1578
1637 // child 1579 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( 1580 auto* space = ConstructConstraintSpace(
1646 kHorizontalTopBottom, TextDirection::kLtr, 1581 kHorizontalTopBottom, TextDirection::kLtr,
1647 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 1582 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
1648 RefPtr<const NGPhysicalBoxFragment> parent_fragment = 1583 RefPtr<const NGPhysicalBoxFragment> parent_fragment =
1649 RunBlockLayoutAlgorithm(space, parent); 1584 RunBlockLayoutAlgorithm(space, container);
1650 1585
1651 FragmentChildIterator iterator(parent_fragment.get()); 1586 FragmentChildIterator iterator(parent_fragment.get());
1652 const auto* fragment = iterator.NextChild(); 1587 const auto* fragment = iterator.NextChild();
1653 ASSERT_TRUE(fragment); 1588 ASSERT_TRUE(fragment);
1654 EXPECT_EQ(LayoutUnit(210), fragment->Width()); 1589 EXPECT_EQ(LayoutUnit(210), fragment->Width());
1655 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1590 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1656 EXPECT_FALSE(iterator.NextChild()); 1591 EXPECT_FALSE(iterator.NextChild());
1657 1592
1658 iterator.SetParent(fragment); 1593 iterator.SetParent(fragment);
1659 // #child fragment in first column 1594 // #child fragment in first column
(...skipping 27 matching lines...) Expand all
1687 1622
1688 // Test case's HTML representation: 1623 // Test case's HTML representation:
1689 // <div id="parent" style="columns:3; column-fill:auto; column-gap:10px; 1624 // <div id="parent" style="columns:3; column-fill:auto; column-gap:10px;
1690 // width:320px; height:100px;"> 1625 // width:320px; height:100px;">
1691 // <div id="child1" style="width:75%; height:60px;"></div> 1626 // <div id="child1" style="width:75%; height:60px;"></div>
1692 // <div id="child2" style="width:85%; height:60px;"></div> 1627 // <div id="child2" style="width:85%; height:60px;"></div>
1693 // </div> 1628 // </div>
1694 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm 1629 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm
1695 // is checked in. 1630 // is checked in.
1696 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_TwoBlocksInTwoColumns) { 1631 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_TwoBlocksInTwoColumns) {
1697 // parent 1632 setBodyInnerHTML(R"HTML(
1698 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); 1633 <div id="container">
1699 parent_style->setColumnCount(3); 1634 <div id="parent" style="column-count: 3; column-fill: auto;
1700 parent_style->setColumnFill(ColumnFillAuto); 1635 column-gap: 10px; height: 100px; width: 320px;">
1701 parent_style->setColumnGap(10); 1636 <div id="child1" style="width: 75%; height: 60px;">
1702 parent_style->setHeight(Length(100, Fixed)); 1637 </div>
1703 parent_style->setWidth(Length(320, Fixed)); 1638 <div id="child2" style="width: 85%; height: 60px;">
1704 NGBlockNode* parent = new NGBlockNode(parent_style.get()); 1639 </div>
1640 </div>
1641 </div>
1642 )HTML");
1705 1643
1706 // child1 1644 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( 1645 auto* space = ConstructConstraintSpace(
1722 kHorizontalTopBottom, TextDirection::kLtr, 1646 kHorizontalTopBottom, TextDirection::kLtr,
1723 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 1647 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
1724 RefPtr<const NGPhysicalBoxFragment> parent_fragment = 1648 RefPtr<const NGPhysicalBoxFragment> parent_fragment =
1725 RunBlockLayoutAlgorithm(space, parent); 1649 RunBlockLayoutAlgorithm(space, container);
1726 1650
1727 FragmentChildIterator iterator(parent_fragment.get()); 1651 FragmentChildIterator iterator(parent_fragment.get());
1728 const auto* fragment = iterator.NextChild(); 1652 const auto* fragment = iterator.NextChild();
1729 ASSERT_TRUE(fragment); 1653 ASSERT_TRUE(fragment);
1730 EXPECT_EQ(LayoutUnit(320), fragment->Width()); 1654 EXPECT_EQ(LayoutUnit(320), fragment->Width());
1731 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1655 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1732 EXPECT_FALSE(iterator.NextChild()); 1656 EXPECT_FALSE(iterator.NextChild());
1733 1657
1734 iterator.SetParent(fragment); 1658 iterator.SetParent(fragment);
1735 // #child1 fragment in first column 1659 // #child1 fragment in first column
(...skipping 20 matching lines...) Expand all
1756 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); 1680 EXPECT_EQ(LayoutUnit(), fragment->TopOffset());
1757 EXPECT_EQ(LayoutUnit(85), fragment->Width()); 1681 EXPECT_EQ(LayoutUnit(85), fragment->Width());
1758 EXPECT_EQ(LayoutUnit(20), fragment->Height()); 1682 EXPECT_EQ(LayoutUnit(20), fragment->Height());
1759 EXPECT_EQ(0U, fragment->Children().size()); 1683 EXPECT_EQ(0U, fragment->Children().size());
1760 EXPECT_FALSE(iterator.NextChild()); 1684 EXPECT_FALSE(iterator.NextChild());
1761 } 1685 }
1762 1686
1763 // Test case's HTML representation: 1687 // Test case's HTML representation:
1764 // <div id="parent" style="columns:3; column-fill:auto; column-gap:10px; 1688 // <div id="parent" style="columns:3; column-fill:auto; column-gap:10px;
1765 // width:320px; height:100px;"> 1689 // width:320px; height:100px;">
1766 // <div id="child1" style="width:75%; height:60px;"> 1690 // <div id="child1" style="width:75%; height:60px;">
1767 // <div id="grandchild1" style="width:50px; height:120px;"></div> 1691 // <div id="grandchild1" style="width:50px; height:120px;"></div>
1768 // <div id="grandchild2" style="width:40px; height:20px;"></div> 1692 // <div id="grandchild2" style="width:40px; height:20px;"></div>
1769 // </div> 1693 // </div>
1770 // <div id="child2" style="width:85%; height:10px;"></div> 1694 // <div id="child2" style="width:85%; height:10px;"></div>
1771 // </div> 1695 // </div>
1772 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm 1696 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm
1773 // is checked in. 1697 // is checked in.
1774 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_OverflowedBlock) { 1698 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_OverflowedBlock) {
1775 // parent 1699 setBodyInnerHTML(R"HTML(
1776 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); 1700 <div id="container">
1777 parent_style->setColumnCount(3); 1701 <div id="parent" style="column-count: 2; column-fill: auto;
1778 parent_style->setColumnFill(ColumnFillAuto); 1702 column-gap: 10px; height: 100px; width: 320px;">
1779 parent_style->setColumnGap(10); 1703 <div id="child1" style="width:75%; height:60px;">
1780 parent_style->setHeight(Length(100, Fixed)); 1704 <div id="grandchild1" style="width:50px; height:120px;">
1781 parent_style->setWidth(Length(320, Fixed)); 1705 </div>
1782 NGBlockNode* parent = new NGBlockNode(parent_style.get()); 1706 <div id="grandchild2" style="width:40px; height:20px;">
1707 </div>
1708 </div>
1709 <div id="child2" style="width:85%; height:10px;"></div>
1710 </div>
1711 </div>
1712 </div>
1713 )HTML");
1783 1714
1784 // child1 1715 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( 1716 auto* space = ConstructConstraintSpace(
1814 kHorizontalTopBottom, TextDirection::kLtr, 1717 kHorizontalTopBottom, TextDirection::kLtr,
1815 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 1718 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
1816 RefPtr<const NGPhysicalBoxFragment> parent_fragment = 1719 RefPtr<const NGPhysicalBoxFragment> parent_fragment =
1817 RunBlockLayoutAlgorithm(space, parent); 1720 RunBlockLayoutAlgorithm(space, container);
1818 1721
1819 FragmentChildIterator iterator(parent_fragment.get()); 1722 FragmentChildIterator iterator(parent_fragment.get());
1820 const auto* fragment = iterator.NextChild(); 1723 const auto* fragment = iterator.NextChild();
1821 ASSERT_TRUE(fragment); 1724 ASSERT_TRUE(fragment);
1822 EXPECT_EQ(LayoutUnit(320), fragment->Width()); 1725 EXPECT_EQ(LayoutUnit(320), fragment->Width());
1823 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1726 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1824 EXPECT_FALSE(iterator.NextChild()); 1727 EXPECT_FALSE(iterator.NextChild());
1825 1728
1826 iterator.SetParent(fragment); 1729 iterator.SetParent(fragment);
1827 // #child1 fragment in first column 1730 // #child1 fragment in first column
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1876 } 1779 }
1877 1780
1878 // Test case's HTML representation: 1781 // Test case's HTML representation:
1879 // <div id="parent" style="columns:3; column-fill:auto; column-gap:10px; 1782 // <div id="parent" style="columns:3; column-fill:auto; column-gap:10px;
1880 // width:320px; height:100px;"> 1783 // width:320px; height:100px;">
1881 // <div id="child" style="float:left; width:75%; height:100px;"></div> 1784 // <div id="child" style="float:left; width:75%; height:100px;"></div>
1882 // </div> 1785 // </div>
1883 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm 1786 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm
1884 // is checked in. 1787 // is checked in.
1885 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_FloatInOneColumn) { 1788 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_FloatInOneColumn) {
1886 // parent 1789 setBodyInnerHTML(R"HTML(
1887 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); 1790 <div id="container">
1888 parent_style->setColumnCount(3); 1791 <div id="parent" style="columns:3; column-fill:auto; column-gap:10px;
1889 parent_style->setColumnFill(ColumnFillAuto); 1792 width:320px; height:100px;">
Gleb Lanbin 2017/03/01 17:25:22 wrong indentation and please move it to <style>
atotic 2017/03/01 18:57:12 done
1890 parent_style->setColumnGap(10); 1793 <div id="child" style="float:left; width:75%; height:100px;">
1891 parent_style->setHeight(Length(100, Fixed)); 1794 </div>
1892 parent_style->setWidth(Length(320, Fixed)); 1795 </div>
1893 NGBlockNode* parent = new NGBlockNode(parent_style.get()); 1796 </div>
1797 )HTML");
1894 1798
1895 // child 1799 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( 1800 auto* space = ConstructConstraintSpace(
1905 kHorizontalTopBottom, TextDirection::kLtr, 1801 kHorizontalTopBottom, TextDirection::kLtr,
1906 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 1802 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
1907 RefPtr<const NGPhysicalBoxFragment> parent_fragment = 1803 RefPtr<const NGPhysicalBoxFragment> parent_fragment =
1908 RunBlockLayoutAlgorithm(space, parent); 1804 RunBlockLayoutAlgorithm(space, container);
1909 1805
1910 FragmentChildIterator iterator(parent_fragment.get()); 1806 FragmentChildIterator iterator(parent_fragment.get());
1911 const auto* fragment = iterator.NextChild(); 1807 const auto* fragment = iterator.NextChild();
1912 ASSERT_TRUE(fragment); 1808 ASSERT_TRUE(fragment);
1913 EXPECT_EQ(LayoutUnit(320), fragment->Width()); 1809 EXPECT_EQ(LayoutUnit(320), fragment->Width());
1914 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1810 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1915 EXPECT_FALSE(iterator.NextChild()); 1811 EXPECT_FALSE(iterator.NextChild());
1916 1812
1917 iterator.SetParent(fragment); 1813 iterator.SetParent(fragment);
1918 // #child fragment in first column 1814 // #child fragment in first column
1919 fragment = iterator.NextChild(); 1815 fragment = iterator.NextChild();
1920 ASSERT_TRUE(fragment); 1816 ASSERT_TRUE(fragment);
1921 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset()); 1817 EXPECT_EQ(LayoutUnit(), fragment->LeftOffset());
1922 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); 1818 EXPECT_EQ(LayoutUnit(), fragment->TopOffset());
1923 EXPECT_EQ(LayoutUnit(75), fragment->Width()); 1819 EXPECT_EQ(LayoutUnit(75), fragment->Width());
1924 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1820 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1925 EXPECT_EQ(0UL, fragment->Children().size()); 1821 EXPECT_EQ(0UL, fragment->Children().size());
1926 EXPECT_FALSE(iterator.NextChild()); 1822 EXPECT_FALSE(iterator.NextChild());
1927 } 1823 }
1928 1824
1929 // Test case's HTML representation: 1825 // Test case's HTML representation:
1930 // <div id="parent" style="columns:3; column-fill:auto; column-gap:10px; 1826 // <div id="parent" style="columns:3; column-fill:auto; column-gap:10px;
1931 // width:320px; height:100px;"> 1827 // width:320px; height:100px;">
1932 // <div id="child1" style="float:left; width:15%; height:100px;"></div> 1828 // <div id="child1" style="float:left; width:15%; height:100px;"></div>
1933 // <div id="child2" style="float:right; width:16%; height:100px;"></div> 1829 // <div id="child2" style="float:right; width:16%; height:100px;"></div>
1934 // </div> 1830 // </div>
1935 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm 1831 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm
1936 // is checked in. 1832 // is checked in.
1937 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_TwoFloatsInOneColumn) { 1833 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_TwoFloatsInOneColumn) {
1938 // parent 1834 setBodyInnerHTML(R"HTML(
1939 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); 1835 <div id="container">
1940 parent_style->setColumnCount(3); 1836 <div id="parent" style="columns:3; column-fill:auto; column-gap:10px;
1941 parent_style->setColumnFill(ColumnFillAuto); 1837 width:320px; height:100px;">
1942 parent_style->setColumnGap(10); 1838 <div id="child1" style="float:left; width:15%; height:100px;">
1943 parent_style->setHeight(Length(100, Fixed)); 1839 </div>
1944 parent_style->setWidth(Length(320, Fixed)); 1840 <div id="child2" style="float:right; width:16%; height:100px;">
1945 NGBlockNode* parent = new NGBlockNode(parent_style.get()); 1841 </div>
1842 </div>
1843 </div>
1844 )HTML");
1946 1845
1947 // child1 1846 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( 1847 auto* space = ConstructConstraintSpace(
1965 kHorizontalTopBottom, TextDirection::kLtr, 1848 kHorizontalTopBottom, TextDirection::kLtr,
1966 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 1849 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
1967 RefPtr<const NGPhysicalBoxFragment> parent_fragment = 1850 RefPtr<const NGPhysicalBoxFragment> parent_fragment =
1968 RunBlockLayoutAlgorithm(space, parent); 1851 RunBlockLayoutAlgorithm(space, container);
1969 1852
1970 FragmentChildIterator iterator(parent_fragment.get()); 1853 FragmentChildIterator iterator(parent_fragment.get());
1971 const auto* fragment = iterator.NextChild(); 1854 const auto* fragment = iterator.NextChild();
1972 ASSERT_TRUE(fragment); 1855 ASSERT_TRUE(fragment);
1973 EXPECT_EQ(LayoutUnit(320), fragment->Width()); 1856 EXPECT_EQ(LayoutUnit(320), fragment->Width());
1974 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1857 EXPECT_EQ(LayoutUnit(100), fragment->Height());
1975 EXPECT_FALSE(iterator.NextChild()); 1858 EXPECT_FALSE(iterator.NextChild());
1976 1859
1977 iterator.SetParent(fragment); 1860 iterator.SetParent(fragment);
1978 // #child1 fragment in first column 1861 // #child1 fragment in first column
(...skipping 17 matching lines...) Expand all
1996 1879
1997 // Test case's HTML representation: 1880 // Test case's HTML representation:
1998 // <div id="parent" style="columns:3; column-fill:auto; column-gap:10px; 1881 // <div id="parent" style="columns:3; column-fill:auto; column-gap:10px;
1999 // width:320px; height:100px;"> 1882 // width:320px; height:100px;">
2000 // <div id="child1" style="float:left; width:15%; height:150px;"></div> 1883 // <div id="child1" style="float:left; width:15%; height:150px;"></div>
2001 // <div id="child2" style="float:right; width:16%; height:150px;"></div> 1884 // <div id="child2" style="float:right; width:16%; height:150px;"></div>
2002 // </div> 1885 // </div>
2003 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm 1886 // TODO(glebl): reenable multicol after new margin collapsing/floats algorithm
2004 // is checked in. 1887 // is checked in.
2005 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_TwoFloatsInTwoColumns) { 1888 TEST_F(NGBlockLayoutAlgorithmTest, DISABLED_TwoFloatsInTwoColumns) {
2006 // parent 1889 setBodyInnerHTML(R"HTML(
2007 RefPtr<ComputedStyle> parent_style = ComputedStyle::create(); 1890 <div id="container">
2008 parent_style->setColumnCount(3); 1891 <div id="parent" style="columns:3; column-fill:auto; column-gap:10px;
2009 parent_style->setColumnFill(ColumnFillAuto); 1892 width:320px; height:100px;">
2010 parent_style->setColumnGap(10); 1893 <div id="child1" style="float:left; width:15%; height:150px;">
2011 parent_style->setHeight(Length(100, Fixed)); 1894 </div>
2012 parent_style->setWidth(Length(320, Fixed)); 1895 <div id="child2" style="float:right; width:16%; height:150px;">
2013 NGBlockNode* parent = new NGBlockNode(parent_style.get()); 1896 </div>
1897 </div>
1898 </div>
1899 )HTML");
2014 1900
2015 // child1 1901 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( 1902 auto* space = ConstructConstraintSpace(
2033 kHorizontalTopBottom, TextDirection::kLtr, 1903 kHorizontalTopBottom, TextDirection::kLtr,
2034 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); 1904 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
2035 RefPtr<const NGPhysicalBoxFragment> parent_fragment = 1905 RefPtr<const NGPhysicalBoxFragment> parent_fragment =
2036 RunBlockLayoutAlgorithm(space, parent); 1906 RunBlockLayoutAlgorithm(space, container);
2037 1907
2038 FragmentChildIterator iterator(parent_fragment.get()); 1908 FragmentChildIterator iterator(parent_fragment.get());
2039 const auto* fragment = iterator.NextChild(); 1909 const auto* fragment = iterator.NextChild();
2040 ASSERT_TRUE(fragment); 1910 ASSERT_TRUE(fragment);
2041 EXPECT_EQ(LayoutUnit(320), fragment->Width()); 1911 EXPECT_EQ(LayoutUnit(320), fragment->Width());
2042 EXPECT_EQ(LayoutUnit(100), fragment->Height()); 1912 EXPECT_EQ(LayoutUnit(100), fragment->Height());
2043 EXPECT_FALSE(iterator.NextChild()); 1913 EXPECT_FALSE(iterator.NextChild());
2044 1914
2045 iterator.SetParent(fragment); 1915 iterator.SetParent(fragment);
2046 // #child1 fragment in first column 1916 // #child1 fragment in first column
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
2475 2345
2476 child = iterator.NextChild(); 2346 child = iterator.NextChild();
2477 EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(100)), child->Size()); 2347 EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(100)), child->Size());
2478 EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(40)), child->Offset()); 2348 EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(40)), child->Offset());
2479 2349
2480 EXPECT_FALSE(iterator.NextChild()); 2350 EXPECT_FALSE(iterator.NextChild());
2481 } 2351 }
2482 2352
2483 } // namespace 2353 } // namespace
2484 } // namespace blink 2354 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/layout/ng/ng_block_node.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698