OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/layout/ng/ng_block_layout_algorithm.h" | 5 #include "core/layout/ng/ng_block_layout_algorithm.h" |
6 | 6 |
7 #include "core/layout/ng/ng_box.h" | 7 #include "core/layout/ng/ng_box.h" |
8 #include "core/layout/ng/ng_constraint_space.h" | 8 #include "core/layout/ng/ng_constraint_space.h" |
9 #include "core/layout/ng/ng_physical_fragment.h" | 9 #include "core/layout/ng/ng_physical_fragment.h" |
10 #include "core/layout/ng/ng_length_utils.h" | 10 #include "core/layout/ng/ng_length_utils.h" |
11 #include "core/layout/ng/ng_units.h" | 11 #include "core/layout/ng/ng_units.h" |
12 #include "core/style/ComputedStyle.h" | 12 #include "core/style/ComputedStyle.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 namespace { | 16 namespace { |
17 | 17 |
| 18 NGConstraintSpace* ConstructConstraintSpace(NGWritingMode writing_mode, |
| 19 NGDirection direction, |
| 20 NGPhysicalSize size) { |
| 21 return new NGConstraintSpace(writing_mode, direction, |
| 22 new NGPhysicalConstraintSpace(size)); |
| 23 } |
| 24 |
18 class NGBlockLayoutAlgorithmTest : public ::testing::Test { | 25 class NGBlockLayoutAlgorithmTest : public ::testing::Test { |
19 protected: | 26 protected: |
20 void SetUp() override { style_ = ComputedStyle::create(); } | 27 void SetUp() override { style_ = ComputedStyle::create(); } |
21 | 28 |
22 NGPhysicalFragment* RunBlockLayoutAlgorithm(const NGConstraintSpace* space, | 29 NGPhysicalFragment* RunBlockLayoutAlgorithm(const NGConstraintSpace* space, |
23 NGBox* first_child) { | 30 NGBox* first_child) { |
24 NGBlockLayoutAlgorithm algorithm(style_, first_child); | 31 NGBlockLayoutAlgorithm algorithm(style_, first_child); |
25 NGPhysicalFragment* frag; | 32 NGPhysicalFragment* frag; |
26 while (!algorithm.Layout(space, &frag)) | 33 while (!algorithm.Layout(space, &frag)) |
27 continue; | 34 continue; |
28 return frag; | 35 return frag; |
29 } | 36 } |
30 | 37 |
31 RefPtr<ComputedStyle> style_; | 38 RefPtr<ComputedStyle> style_; |
32 }; | 39 }; |
33 | 40 |
34 TEST_F(NGBlockLayoutAlgorithmTest, FixedSize) { | 41 TEST_F(NGBlockLayoutAlgorithmTest, FixedSize) { |
35 style_->setWidth(Length(30, Fixed)); | 42 style_->setWidth(Length(30, Fixed)); |
36 style_->setHeight(Length(40, Fixed)); | 43 style_->setHeight(Length(40, Fixed)); |
37 | 44 |
38 auto* space = | 45 auto* space = ConstructConstraintSpace( |
39 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 46 HorizontalTopBottom, LeftToRight, |
40 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 47 NGPhysicalSize(LayoutUnit(100), NGSizeIndefinite)); |
41 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, nullptr); | 48 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, nullptr); |
42 | 49 |
43 EXPECT_EQ(LayoutUnit(30), frag->Width()); | 50 EXPECT_EQ(LayoutUnit(30), frag->Width()); |
44 EXPECT_EQ(LayoutUnit(40), frag->Height()); | 51 EXPECT_EQ(LayoutUnit(40), frag->Height()); |
45 } | 52 } |
46 | 53 |
47 // Verifies that two children are laid out with the correct size and position. | 54 // Verifies that two children are laid out with the correct size and position. |
48 TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildren) { | 55 TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildren) { |
49 const int kWidth = 30; | 56 const int kWidth = 30; |
50 const int kHeight1 = 20; | 57 const int kHeight1 = 20; |
51 const int kHeight2 = 30; | 58 const int kHeight2 = 30; |
52 const int kMarginTop = 5; | 59 const int kMarginTop = 5; |
53 const int kMarginBottom = 20; | 60 const int kMarginBottom = 20; |
54 style_->setWidth(Length(kWidth, Fixed)); | 61 style_->setWidth(Length(kWidth, Fixed)); |
55 | 62 |
56 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); | 63 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); |
57 first_style->setHeight(Length(kHeight1, Fixed)); | 64 first_style->setHeight(Length(kHeight1, Fixed)); |
58 NGBox* first_child = new NGBox(first_style.get()); | 65 NGBox* first_child = new NGBox(first_style.get()); |
59 | 66 |
60 RefPtr<ComputedStyle> second_style = ComputedStyle::create(); | 67 RefPtr<ComputedStyle> second_style = ComputedStyle::create(); |
61 second_style->setHeight(Length(kHeight2, Fixed)); | 68 second_style->setHeight(Length(kHeight2, Fixed)); |
62 second_style->setMarginTop(Length(kMarginTop, Fixed)); | 69 second_style->setMarginTop(Length(kMarginTop, Fixed)); |
63 second_style->setMarginBottom(Length(kMarginBottom, Fixed)); | 70 second_style->setMarginBottom(Length(kMarginBottom, Fixed)); |
64 NGBox* second_child = new NGBox(second_style.get()); | 71 NGBox* second_child = new NGBox(second_style.get()); |
65 | 72 |
66 first_child->SetNextSibling(second_child); | 73 first_child->SetNextSibling(second_child); |
67 | 74 |
68 auto* space = | 75 auto* space = ConstructConstraintSpace( |
69 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 76 HorizontalTopBottom, LeftToRight, |
70 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 77 NGPhysicalSize(LayoutUnit(100), NGSizeIndefinite)); |
71 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); | 78 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); |
72 | 79 |
73 EXPECT_EQ(LayoutUnit(kWidth), frag->Width()); | 80 EXPECT_EQ(LayoutUnit(kWidth), frag->Width()); |
74 EXPECT_EQ(LayoutUnit(kHeight1 + kHeight2 + kMarginTop), frag->Height()); | 81 EXPECT_EQ(LayoutUnit(kHeight1 + kHeight2 + kMarginTop), frag->Height()); |
75 EXPECT_EQ(NGPhysicalFragmentBase::FragmentBox, frag->Type()); | 82 EXPECT_EQ(NGPhysicalFragmentBase::FragmentBox, frag->Type()); |
76 ASSERT_EQ(frag->Children().size(), 2UL); | 83 ASSERT_EQ(frag->Children().size(), 2UL); |
77 | 84 |
78 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 85 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
79 EXPECT_EQ(kHeight1, child->Height()); | 86 EXPECT_EQ(kHeight1, child->Height()); |
80 EXPECT_EQ(0, child->TopOffset()); | 87 EXPECT_EQ(0, child->TopOffset()); |
(...skipping 23 matching lines...) Expand all Loading... |
104 | 111 |
105 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 112 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
106 div2_style->setHeight(Length(kHeight, Fixed)); | 113 div2_style->setHeight(Length(kHeight, Fixed)); |
107 div2_style->setWidth(Length(kWidth, Fixed)); | 114 div2_style->setWidth(Length(kWidth, Fixed)); |
108 div1_style->setWritingMode(TopToBottomWritingMode); | 115 div1_style->setWritingMode(TopToBottomWritingMode); |
109 div2_style->setMarginLeft(Length(kMarginLeft, Fixed)); | 116 div2_style->setMarginLeft(Length(kMarginLeft, Fixed)); |
110 NGBox* div2 = new NGBox(div2_style.get()); | 117 NGBox* div2 = new NGBox(div2_style.get()); |
111 | 118 |
112 div1->SetFirstChild(div2); | 119 div1->SetFirstChild(div2); |
113 | 120 |
114 auto* space = | 121 auto* space = ConstructConstraintSpace( |
115 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 122 HorizontalTopBottom, LeftToRight, |
116 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); | 123 NGPhysicalSize(LayoutUnit(500), LayoutUnit(500))); |
117 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 124 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
118 | 125 |
119 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 126 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
120 // DIV2 | 127 // DIV2 |
121 child = static_cast<const NGPhysicalFragment*>(child)->Children()[0]; | 128 child = static_cast<const NGPhysicalFragment*>(child)->Children()[0]; |
122 | 129 |
123 EXPECT_EQ(kHeight, child->Height()); | 130 EXPECT_EQ(kHeight, child->Height()); |
124 EXPECT_EQ(0, child->TopOffset()); | 131 EXPECT_EQ(0, child->TopOffset()); |
125 EXPECT_EQ(kMarginLeft, child->LeftOffset()); | 132 EXPECT_EQ(kMarginLeft, child->LeftOffset()); |
126 } | 133 } |
(...skipping 21 matching lines...) Expand all Loading... |
148 div1_style->setMarginTop(Length(kDiv1MarginTop, Fixed)); | 155 div1_style->setMarginTop(Length(kDiv1MarginTop, Fixed)); |
149 NGBox* div1 = new NGBox(div1_style.get()); | 156 NGBox* div1 = new NGBox(div1_style.get()); |
150 | 157 |
151 // DIV2 | 158 // DIV2 |
152 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 159 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
153 div2_style->setMarginTop(Length(kDiv2MarginTop, Fixed)); | 160 div2_style->setMarginTop(Length(kDiv2MarginTop, Fixed)); |
154 NGBox* div2 = new NGBox(div2_style.get()); | 161 NGBox* div2 = new NGBox(div2_style.get()); |
155 | 162 |
156 div1->SetFirstChild(div2); | 163 div1->SetFirstChild(div2); |
157 | 164 |
158 auto* space = | 165 auto* space = ConstructConstraintSpace( |
159 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 166 HorizontalTopBottom, LeftToRight, |
160 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 167 NGPhysicalSize(LayoutUnit(100), NGSizeIndefinite)); |
161 space->SetIsNewFormattingContext(true); | 168 space->SetIsNewFormattingContext(true); |
162 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 169 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
163 | 170 |
164 EXPECT_TRUE(frag->MarginStrut().IsEmpty()); | 171 EXPECT_TRUE(frag->MarginStrut().IsEmpty()); |
165 ASSERT_EQ(frag->Children().size(), 1UL); | 172 ASSERT_EQ(frag->Children().size(), 1UL); |
166 const NGPhysicalFragment* div2_fragment = | 173 const NGPhysicalFragment* div2_fragment = |
167 static_cast<const NGPhysicalFragment*>(frag->Children()[0].get()); | 174 static_cast<const NGPhysicalFragment*>(frag->Children()[0].get()); |
168 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2MarginTop)}), | 175 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2MarginTop)}), |
169 div2_fragment->MarginStrut()); | 176 div2_fragment->MarginStrut()); |
170 EXPECT_EQ(kDiv1MarginTop, div2_fragment->TopOffset()); | 177 EXPECT_EQ(kDiv1MarginTop, div2_fragment->TopOffset()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 div7_style->setMarginTop(Length(kDiv7MarginTop, Fixed)); | 230 div7_style->setMarginTop(Length(kDiv7MarginTop, Fixed)); |
224 NGBox* div7 = new NGBox(div7_style.get()); | 231 NGBox* div7 = new NGBox(div7_style.get()); |
225 | 232 |
226 div1->SetFirstChild(div2); | 233 div1->SetFirstChild(div2); |
227 div2->SetNextSibling(div3); | 234 div2->SetNextSibling(div3); |
228 div1->SetNextSibling(div4); | 235 div1->SetNextSibling(div4); |
229 div4->SetNextSibling(div5); | 236 div4->SetNextSibling(div5); |
230 div5->SetFirstChild(div6); | 237 div5->SetFirstChild(div6); |
231 div6->SetNextSibling(div7); | 238 div6->SetNextSibling(div7); |
232 | 239 |
233 auto* space = | 240 auto* space = ConstructConstraintSpace( |
234 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 241 HorizontalTopBottom, LeftToRight, |
235 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 242 NGPhysicalSize(LayoutUnit(100), NGSizeIndefinite)); |
236 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 243 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
237 | 244 |
238 ASSERT_EQ(frag->Children().size(), 3UL); | 245 ASSERT_EQ(frag->Children().size(), 3UL); |
239 | 246 |
240 // DIV1 | 247 // DIV1 |
241 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 248 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
242 EXPECT_EQ(kHeight, child->Height()); | 249 EXPECT_EQ(kHeight, child->Height()); |
243 EXPECT_EQ(0, child->TopOffset()); | 250 EXPECT_EQ(0, child->TopOffset()); |
244 | 251 |
245 // DIV5 | 252 // DIV5 |
(...skipping 26 matching lines...) Expand all Loading... |
272 NGBox* div1 = new NGBox(div1_style.get()); | 279 NGBox* div1 = new NGBox(div1_style.get()); |
273 | 280 |
274 // DIV2 | 281 // DIV2 |
275 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 282 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
276 div2_style->setHeight(Length(kHeight, Fixed)); | 283 div2_style->setHeight(Length(kHeight, Fixed)); |
277 div2_style->setMarginBottom(Length(kDiv2MarginBottom, Fixed)); | 284 div2_style->setMarginBottom(Length(kDiv2MarginBottom, Fixed)); |
278 NGBox* div2 = new NGBox(div2_style.get()); | 285 NGBox* div2 = new NGBox(div2_style.get()); |
279 | 286 |
280 div1->SetFirstChild(div2); | 287 div1->SetFirstChild(div2); |
281 | 288 |
282 auto* space = | 289 auto* space = ConstructConstraintSpace( |
283 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 290 HorizontalTopBottom, LeftToRight, |
284 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 291 NGPhysicalSize(LayoutUnit(100), NGSizeIndefinite)); |
285 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 292 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
286 | 293 |
287 // Verify that margins are collapsed. | 294 // Verify that margins are collapsed. |
288 EXPECT_EQ(NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv2MarginBottom)}), | 295 EXPECT_EQ(NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv2MarginBottom)}), |
289 frag->MarginStrut()); | 296 frag->MarginStrut()); |
290 | 297 |
291 // Verify that margins are NOT collapsed. | 298 // Verify that margins are NOT collapsed. |
292 div1_style->setHeight(Length(kHeight, Fixed)); | 299 div1_style->setHeight(Length(kHeight, Fixed)); |
293 frag = RunBlockLayoutAlgorithm(space, div1); | 300 frag = RunBlockLayoutAlgorithm(space, div1); |
294 EXPECT_EQ(NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv1MarginBottom)}), | 301 EXPECT_EQ(NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv1MarginBottom)}), |
(...skipping 26 matching lines...) Expand all Loading... |
321 | 328 |
322 // DIV2 | 329 // DIV2 |
323 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 330 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
324 div2_style->setHeight(Length(kHeight, Fixed)); | 331 div2_style->setHeight(Length(kHeight, Fixed)); |
325 div2_style->setMarginTop(Length(kDiv2Margin, Fixed)); | 332 div2_style->setMarginTop(Length(kDiv2Margin, Fixed)); |
326 div2_style->setMarginBottom(Length(kDiv2Margin, Fixed)); | 333 div2_style->setMarginBottom(Length(kDiv2Margin, Fixed)); |
327 NGBox* div2 = new NGBox(div2_style.get()); | 334 NGBox* div2 = new NGBox(div2_style.get()); |
328 | 335 |
329 div1->SetFirstChild(div2); | 336 div1->SetFirstChild(div2); |
330 | 337 |
331 auto* space = | 338 auto* space = ConstructConstraintSpace( |
332 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 339 HorizontalTopBottom, LeftToRight, |
333 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 340 NGPhysicalSize(LayoutUnit(100), NGSizeIndefinite)); |
334 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 341 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
335 | 342 |
336 // Verify that margins do NOT collapse. | 343 // Verify that margins do NOT collapse. |
337 frag = RunBlockLayoutAlgorithm(space, div1); | 344 frag = RunBlockLayoutAlgorithm(space, div1); |
338 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv1Margin), LayoutUnit(kDiv1Margin)}), | 345 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv1Margin), LayoutUnit(kDiv1Margin)}), |
339 frag->MarginStrut()); | 346 frag->MarginStrut()); |
340 ASSERT_EQ(frag->Children().size(), 1UL); | 347 ASSERT_EQ(frag->Children().size(), 1UL); |
341 | 348 |
342 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2Margin), LayoutUnit(kDiv2Margin)}), | 349 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2Margin), LayoutUnit(kDiv2Margin)}), |
343 static_cast<const NGPhysicalFragment*>(frag->Children()[0].get()) | 350 static_cast<const NGPhysicalFragment*>(frag->Children()[0].get()) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 NGBox* vertical_div = new NGBox(vertical_style.get()); | 384 NGBox* vertical_div = new NGBox(vertical_style.get()); |
378 | 385 |
379 // Horizontal DIV | 386 // Horizontal DIV |
380 RefPtr<ComputedStyle> horizontal_style = ComputedStyle::create(); | 387 RefPtr<ComputedStyle> horizontal_style = ComputedStyle::create(); |
381 horizontal_style->setMarginLeft(Length(kHorizontalDivMarginLeft, Fixed)); | 388 horizontal_style->setMarginLeft(Length(kHorizontalDivMarginLeft, Fixed)); |
382 horizontal_style->setWritingMode(TopToBottomWritingMode); | 389 horizontal_style->setWritingMode(TopToBottomWritingMode); |
383 NGBox* horizontal_div = new NGBox(horizontal_style.get()); | 390 NGBox* horizontal_div = new NGBox(horizontal_style.get()); |
384 | 391 |
385 vertical_div->SetNextSibling(horizontal_div); | 392 vertical_div->SetNextSibling(horizontal_div); |
386 | 393 |
387 auto* space = | 394 auto* space = ConstructConstraintSpace( |
388 new NGConstraintSpace(VerticalLeftRight, LeftToRight, | 395 VerticalLeftRight, LeftToRight, |
389 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); | 396 NGPhysicalSize(LayoutUnit(500), LayoutUnit(500))); |
390 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, vertical_div); | 397 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, vertical_div); |
391 | 398 |
392 ASSERT_EQ(frag->Children().size(), 2UL); | 399 ASSERT_EQ(frag->Children().size(), 2UL); |
393 const NGPhysicalFragmentBase* child = frag->Children()[1]; | 400 const NGPhysicalFragmentBase* child = frag->Children()[1]; |
394 // Horizontal div | 401 // Horizontal div |
395 EXPECT_EQ(0, child->TopOffset()); | 402 EXPECT_EQ(0, child->TopOffset()); |
396 EXPECT_EQ(kVerticalDivWidth + kHorizontalDivMarginLeft, child->LeftOffset()); | 403 EXPECT_EQ(kVerticalDivWidth + kHorizontalDivMarginLeft, child->LeftOffset()); |
397 } | 404 } |
398 | 405 |
399 // Verifies that the margin strut of a child with a different writing mode does | 406 // Verifies that the margin strut of a child with a different writing mode does |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 | 442 |
436 // DIV3 | 443 // DIV3 |
437 RefPtr<ComputedStyle> div3_style = ComputedStyle::create(); | 444 RefPtr<ComputedStyle> div3_style = ComputedStyle::create(); |
438 div3_style->setHeight(Length(kHeight, Fixed)); | 445 div3_style->setHeight(Length(kHeight, Fixed)); |
439 div3_style->setMarginTop(Length(kMarginTop, Fixed)); | 446 div3_style->setMarginTop(Length(kMarginTop, Fixed)); |
440 NGBox* div3 = new NGBox(div3_style.get()); | 447 NGBox* div3 = new NGBox(div3_style.get()); |
441 | 448 |
442 div1->SetFirstChild(div2); | 449 div1->SetFirstChild(div2); |
443 div1->SetNextSibling(div3); | 450 div1->SetNextSibling(div3); |
444 | 451 |
445 auto* space = | 452 auto* space = ConstructConstraintSpace( |
446 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 453 HorizontalTopBottom, LeftToRight, |
447 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); | 454 NGPhysicalSize(LayoutUnit(500), LayoutUnit(500))); |
448 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 455 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
449 | 456 |
450 ASSERT_EQ(frag->Children().size(), 2UL); | 457 ASSERT_EQ(frag->Children().size(), 2UL); |
451 | 458 |
452 const NGPhysicalFragmentBase* child1 = frag->Children()[0]; | 459 const NGPhysicalFragmentBase* child1 = frag->Children()[0]; |
453 EXPECT_EQ(0, child1->TopOffset()); | 460 EXPECT_EQ(0, child1->TopOffset()); |
454 EXPECT_EQ(kHeight, child1->Height()); | 461 EXPECT_EQ(kHeight, child1->Height()); |
455 | 462 |
456 const NGPhysicalFragmentBase* child2 = frag->Children()[1]; | 463 const NGPhysicalFragmentBase* child2 = frag->Children()[1]; |
457 EXPECT_EQ(kHeight + std::max(kMarginBottom, kMarginTop), child2->TopOffset()); | 464 EXPECT_EQ(kHeight + std::max(kMarginBottom, kMarginTop), child2->TopOffset()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 div1_style->setPaddingRight(Length(kPaddingRight, Fixed)); | 505 div1_style->setPaddingRight(Length(kPaddingRight, Fixed)); |
499 div1_style->setPaddingBottom(Length(kPaddingBottom, Fixed)); | 506 div1_style->setPaddingBottom(Length(kPaddingBottom, Fixed)); |
500 div1_style->setPaddingLeft(Length(kPaddingLeft, Fixed)); | 507 div1_style->setPaddingLeft(Length(kPaddingLeft, Fixed)); |
501 NGBox* div1 = new NGBox(div1_style.get()); | 508 NGBox* div1 = new NGBox(div1_style.get()); |
502 | 509 |
503 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 510 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
504 NGBox* div2 = new NGBox(div2_style.get()); | 511 NGBox* div2 = new NGBox(div2_style.get()); |
505 | 512 |
506 div1->SetFirstChild(div2); | 513 div1->SetFirstChild(div2); |
507 | 514 |
508 auto* space = | 515 auto* space = ConstructConstraintSpace( |
509 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 516 HorizontalTopBottom, LeftToRight, |
510 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); | 517 NGPhysicalSize(LayoutUnit(1000), NGSizeIndefinite)); |
511 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 518 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
512 | 519 |
513 ASSERT_EQ(frag->Children().size(), 1UL); | 520 ASSERT_EQ(frag->Children().size(), 1UL); |
514 | 521 |
515 // div1 | 522 // div1 |
516 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 523 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
517 EXPECT_EQ(kBorderLeft + kPaddingLeft + kWidth + kPaddingRight + kBorderRight, | 524 EXPECT_EQ(kBorderLeft + kPaddingLeft + kWidth + kPaddingRight + kBorderRight, |
518 child->Width()); | 525 child->Width()); |
519 EXPECT_EQ(kBorderTop + kPaddingTop + kHeight + kPaddingBottom + kBorderBottom, | 526 EXPECT_EQ(kBorderTop + kPaddingTop + kHeight + kPaddingBottom + kBorderBottom, |
520 child->Height()); | 527 child->Height()); |
(...skipping 11 matching lines...) Expand all Loading... |
532 TEST_F(NGBlockLayoutAlgorithmTest, PercentageSize) { | 539 TEST_F(NGBlockLayoutAlgorithmTest, PercentageSize) { |
533 const int kPaddingLeft = 10; | 540 const int kPaddingLeft = 10; |
534 const int kWidth = 30; | 541 const int kWidth = 30; |
535 style_->setWidth(Length(kWidth, Fixed)); | 542 style_->setWidth(Length(kWidth, Fixed)); |
536 style_->setPaddingLeft(Length(kPaddingLeft, Fixed)); | 543 style_->setPaddingLeft(Length(kPaddingLeft, Fixed)); |
537 | 544 |
538 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); | 545 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); |
539 first_style->setWidth(Length(40, Percent)); | 546 first_style->setWidth(Length(40, Percent)); |
540 NGBox* first_child = new NGBox(first_style.get()); | 547 NGBox* first_child = new NGBox(first_style.get()); |
541 | 548 |
542 auto* space = | 549 auto* space = ConstructConstraintSpace( |
543 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 550 HorizontalTopBottom, LeftToRight, |
544 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 551 NGPhysicalSize(LayoutUnit(100), NGSizeIndefinite)); |
545 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); | 552 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); |
546 | 553 |
547 EXPECT_EQ(frag->Width(), LayoutUnit(kWidth + kPaddingLeft)); | 554 EXPECT_EQ(frag->Width(), LayoutUnit(kWidth + kPaddingLeft)); |
548 EXPECT_EQ(frag->Type(), NGPhysicalFragmentBase::FragmentBox); | 555 EXPECT_EQ(frag->Type(), NGPhysicalFragmentBase::FragmentBox); |
549 ASSERT_EQ(frag->Children().size(), 1UL); | 556 ASSERT_EQ(frag->Children().size(), 1UL); |
550 | 557 |
551 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 558 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
552 EXPECT_EQ(child->Width(), LayoutUnit(12)); | 559 EXPECT_EQ(child->Width(), LayoutUnit(12)); |
553 } | 560 } |
554 | 561 |
555 // A very simple auto margin case. We rely on the tests in ng_length_utils_test | 562 // A very simple auto margin case. We rely on the tests in ng_length_utils_test |
556 // for the more complex cases; just make sure we handle auto at all here. | 563 // for the more complex cases; just make sure we handle auto at all here. |
557 TEST_F(NGBlockLayoutAlgorithmTest, AutoMargin) { | 564 TEST_F(NGBlockLayoutAlgorithmTest, AutoMargin) { |
558 const int kPaddingLeft = 10; | 565 const int kPaddingLeft = 10; |
559 const int kWidth = 30; | 566 const int kWidth = 30; |
560 style_->setWidth(Length(kWidth, Fixed)); | 567 style_->setWidth(Length(kWidth, Fixed)); |
561 style_->setPaddingLeft(Length(kPaddingLeft, Fixed)); | 568 style_->setPaddingLeft(Length(kPaddingLeft, Fixed)); |
562 | 569 |
563 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); | 570 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); |
564 const int kChildWidth = 10; | 571 const int kChildWidth = 10; |
565 first_style->setWidth(Length(kChildWidth, Fixed)); | 572 first_style->setWidth(Length(kChildWidth, Fixed)); |
566 first_style->setMarginLeft(Length(Auto)); | 573 first_style->setMarginLeft(Length(Auto)); |
567 first_style->setMarginRight(Length(Auto)); | 574 first_style->setMarginRight(Length(Auto)); |
568 NGBox* first_child = new NGBox(first_style.get()); | 575 NGBox* first_child = new NGBox(first_style.get()); |
569 | 576 |
570 auto* space = | 577 auto* space = ConstructConstraintSpace( |
571 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 578 HorizontalTopBottom, LeftToRight, |
572 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 579 NGPhysicalSize(LayoutUnit(100), NGSizeIndefinite)); |
573 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); | 580 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); |
574 | 581 |
575 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width()); | 582 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width()); |
576 EXPECT_EQ(NGPhysicalFragmentBase::FragmentBox, frag->Type()); | 583 EXPECT_EQ(NGPhysicalFragmentBase::FragmentBox, frag->Type()); |
577 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->WidthOverflow()); | 584 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->WidthOverflow()); |
578 ASSERT_EQ(1UL, frag->Children().size()); | 585 ASSERT_EQ(1UL, frag->Children().size()); |
579 | 586 |
580 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 587 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
581 EXPECT_EQ(LayoutUnit(kChildWidth), child->Width()); | 588 EXPECT_EQ(LayoutUnit(kChildWidth), child->Width()); |
582 EXPECT_EQ(LayoutUnit(kPaddingLeft + 10), child->LeftOffset()); | 589 EXPECT_EQ(LayoutUnit(kPaddingLeft + 10), child->LeftOffset()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 RefPtr<ComputedStyle> div3_style = ComputedStyle::create(); | 636 RefPtr<ComputedStyle> div3_style = ComputedStyle::create(); |
630 div3_style->setWidth(Length(kDiv3Size, Fixed)); | 637 div3_style->setWidth(Length(kDiv3Size, Fixed)); |
631 div3_style->setHeight(Length(kDiv3Size, Fixed)); | 638 div3_style->setHeight(Length(kDiv3Size, Fixed)); |
632 div3_style->setMarginLeft(Length(kDiv3LeftMargin, Fixed)); | 639 div3_style->setMarginLeft(Length(kDiv3LeftMargin, Fixed)); |
633 div3_style->setFloating(EFloat::Left); | 640 div3_style->setFloating(EFloat::Left); |
634 NGBox* div3 = new NGBox(div3_style.get()); | 641 NGBox* div3 = new NGBox(div3_style.get()); |
635 | 642 |
636 div1->SetNextSibling(div2); | 643 div1->SetNextSibling(div2); |
637 div2->SetNextSibling(div3); | 644 div2->SetNextSibling(div3); |
638 | 645 |
639 auto* space = new NGConstraintSpace( | 646 auto* space = ConstructConstraintSpace( |
640 HorizontalTopBottom, LeftToRight, | 647 HorizontalTopBottom, LeftToRight, |
641 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); | 648 NGPhysicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); |
642 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 649 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
643 ASSERT_EQ(frag->Children().size(), 3UL); | 650 ASSERT_EQ(frag->Children().size(), 3UL); |
644 | 651 |
645 // DIV1 | 652 // DIV1 |
646 const NGPhysicalFragmentBase* child1 = frag->Children()[0]; | 653 const NGPhysicalFragmentBase* child1 = frag->Children()[0]; |
647 EXPECT_EQ(kDiv1TopMargin, child1->TopOffset()); | 654 EXPECT_EQ(kDiv1TopMargin, child1->TopOffset()); |
648 EXPECT_EQ(0, child1->LeftOffset()); | 655 EXPECT_EQ(0, child1->LeftOffset()); |
649 | 656 |
650 // DIV2 | 657 // DIV2 |
651 const NGPhysicalFragmentBase* child2 = frag->Children()[1]; | 658 const NGPhysicalFragmentBase* child2 = frag->Children()[1]; |
652 EXPECT_EQ(0, child2->TopOffset()); | 659 EXPECT_EQ(0, child2->TopOffset()); |
653 EXPECT_EQ(kParentSize - kDiv2Size, child2->LeftOffset()); | 660 EXPECT_EQ(kParentSize - kDiv2Size, child2->LeftOffset()); |
654 | 661 |
655 // DIV3 | 662 // DIV3 |
656 const NGPhysicalFragmentBase* child3 = frag->Children()[2]; | 663 const NGPhysicalFragmentBase* child3 = frag->Children()[2]; |
657 EXPECT_EQ(kDiv2Size, child3->TopOffset()); | 664 EXPECT_EQ(kDiv2Size, child3->TopOffset()); |
658 EXPECT_EQ(kDiv3LeftMargin, child3->LeftOffset()); | 665 EXPECT_EQ(kDiv3LeftMargin, child3->LeftOffset()); |
659 } | 666 } |
660 } // namespace | 667 } // namespace |
661 } // namespace blink | 668 } // namespace blink |
OLD | NEW |