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_constraint_space_builder.h" |
9 #include "core/layout/ng/ng_physical_fragment.h" | 10 #include "core/layout/ng/ng_physical_fragment.h" |
10 #include "core/layout/ng/ng_length_utils.h" | 11 #include "core/layout/ng/ng_length_utils.h" |
11 #include "core/layout/ng/ng_units.h" | 12 #include "core/layout/ng/ng_units.h" |
12 #include "core/style/ComputedStyle.h" | 13 #include "core/style/ComputedStyle.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 namespace blink { | 16 namespace blink { |
16 namespace { | 17 namespace { |
17 | 18 |
18 NGConstraintSpace* ConstructConstraintSpace(NGWritingMode writing_mode, | 19 NGConstraintSpace* ConstructConstraintSpace(NGWritingMode writing_mode, |
19 NGDirection direction, | 20 NGDirection direction, |
20 NGPhysicalSize size) { | 21 NGLogicalSize size) { |
21 return new NGConstraintSpace(writing_mode, direction, | 22 NGConstraintSpaceBuilder builder(writing_mode); |
22 new NGPhysicalConstraintSpace(size)); | 23 return new NGConstraintSpace( |
| 24 writing_mode, direction, |
| 25 builder.SetContainerSize(size).ToConstraintSpace()); |
23 } | 26 } |
24 | 27 |
25 class NGBlockLayoutAlgorithmTest : public ::testing::Test { | 28 class NGBlockLayoutAlgorithmTest : public ::testing::Test { |
26 protected: | 29 protected: |
27 void SetUp() override { style_ = ComputedStyle::create(); } | 30 void SetUp() override { style_ = ComputedStyle::create(); } |
28 | 31 |
29 NGPhysicalFragment* RunBlockLayoutAlgorithm(NGConstraintSpace* space, | 32 NGPhysicalFragment* RunBlockLayoutAlgorithm(NGConstraintSpace* space, |
30 NGBox* first_child) { | 33 NGBox* first_child) { |
31 NGBlockLayoutAlgorithm algorithm(style_, first_child, space); | 34 NGBlockLayoutAlgorithm algorithm(style_, first_child, space); |
32 NGPhysicalFragment* frag; | 35 NGPhysicalFragment* frag; |
33 while (!algorithm.Layout(&frag)) | 36 while (!algorithm.Layout(&frag)) |
34 continue; | 37 continue; |
35 return frag; | 38 return frag; |
36 } | 39 } |
37 | 40 |
38 RefPtr<ComputedStyle> style_; | 41 RefPtr<ComputedStyle> style_; |
39 }; | 42 }; |
40 | 43 |
41 TEST_F(NGBlockLayoutAlgorithmTest, FixedSize) { | 44 TEST_F(NGBlockLayoutAlgorithmTest, FixedSize) { |
42 style_->setWidth(Length(30, Fixed)); | 45 style_->setWidth(Length(30, Fixed)); |
43 style_->setHeight(Length(40, Fixed)); | 46 style_->setHeight(Length(40, Fixed)); |
44 | 47 |
45 auto* space = ConstructConstraintSpace( | 48 auto* space = ConstructConstraintSpace( |
46 HorizontalTopBottom, LeftToRight, | 49 HorizontalTopBottom, LeftToRight, |
47 NGPhysicalSize(LayoutUnit(100), NGSizeIndefinite)); | 50 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
48 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, nullptr); | 51 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, nullptr); |
49 | 52 |
50 EXPECT_EQ(LayoutUnit(30), frag->Width()); | 53 EXPECT_EQ(LayoutUnit(30), frag->Width()); |
51 EXPECT_EQ(LayoutUnit(40), frag->Height()); | 54 EXPECT_EQ(LayoutUnit(40), frag->Height()); |
52 } | 55 } |
53 | 56 |
54 // Verifies that two children are laid out with the correct size and position. | 57 // Verifies that two children are laid out with the correct size and position. |
55 TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildren) { | 58 TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildren) { |
56 const int kWidth = 30; | 59 const int kWidth = 30; |
57 const int kHeight1 = 20; | 60 const int kHeight1 = 20; |
58 const int kHeight2 = 30; | 61 const int kHeight2 = 30; |
59 const int kMarginTop = 5; | 62 const int kMarginTop = 5; |
60 const int kMarginBottom = 20; | 63 const int kMarginBottom = 20; |
61 style_->setWidth(Length(kWidth, Fixed)); | 64 style_->setWidth(Length(kWidth, Fixed)); |
62 | 65 |
63 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); | 66 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); |
64 first_style->setHeight(Length(kHeight1, Fixed)); | 67 first_style->setHeight(Length(kHeight1, Fixed)); |
65 NGBox* first_child = new NGBox(first_style.get()); | 68 NGBox* first_child = new NGBox(first_style.get()); |
66 | 69 |
67 RefPtr<ComputedStyle> second_style = ComputedStyle::create(); | 70 RefPtr<ComputedStyle> second_style = ComputedStyle::create(); |
68 second_style->setHeight(Length(kHeight2, Fixed)); | 71 second_style->setHeight(Length(kHeight2, Fixed)); |
69 second_style->setMarginTop(Length(kMarginTop, Fixed)); | 72 second_style->setMarginTop(Length(kMarginTop, Fixed)); |
70 second_style->setMarginBottom(Length(kMarginBottom, Fixed)); | 73 second_style->setMarginBottom(Length(kMarginBottom, Fixed)); |
71 NGBox* second_child = new NGBox(second_style.get()); | 74 NGBox* second_child = new NGBox(second_style.get()); |
72 | 75 |
73 first_child->SetNextSibling(second_child); | 76 first_child->SetNextSibling(second_child); |
74 | 77 |
75 auto* space = ConstructConstraintSpace( | 78 auto* space = ConstructConstraintSpace( |
76 HorizontalTopBottom, LeftToRight, | 79 HorizontalTopBottom, LeftToRight, |
77 NGPhysicalSize(LayoutUnit(100), NGSizeIndefinite)); | 80 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
78 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); | 81 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); |
79 | 82 |
80 EXPECT_EQ(LayoutUnit(kWidth), frag->Width()); | 83 EXPECT_EQ(LayoutUnit(kWidth), frag->Width()); |
81 EXPECT_EQ(LayoutUnit(kHeight1 + kHeight2 + kMarginTop), frag->Height()); | 84 EXPECT_EQ(LayoutUnit(kHeight1 + kHeight2 + kMarginTop), frag->Height()); |
82 EXPECT_EQ(NGPhysicalFragmentBase::FragmentBox, frag->Type()); | 85 EXPECT_EQ(NGPhysicalFragmentBase::FragmentBox, frag->Type()); |
83 ASSERT_EQ(frag->Children().size(), 2UL); | 86 ASSERT_EQ(frag->Children().size(), 2UL); |
84 | 87 |
85 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 88 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
86 EXPECT_EQ(kHeight1, child->Height()); | 89 EXPECT_EQ(kHeight1, child->Height()); |
87 EXPECT_EQ(0, child->TopOffset()); | 90 EXPECT_EQ(0, child->TopOffset()); |
(...skipping 23 matching lines...) Expand all Loading... |
111 | 114 |
112 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 115 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
113 div2_style->setHeight(Length(kHeight, Fixed)); | 116 div2_style->setHeight(Length(kHeight, Fixed)); |
114 div2_style->setWidth(Length(kWidth, Fixed)); | 117 div2_style->setWidth(Length(kWidth, Fixed)); |
115 div1_style->setWritingMode(TopToBottomWritingMode); | 118 div1_style->setWritingMode(TopToBottomWritingMode); |
116 div2_style->setMarginLeft(Length(kMarginLeft, Fixed)); | 119 div2_style->setMarginLeft(Length(kMarginLeft, Fixed)); |
117 NGBox* div2 = new NGBox(div2_style.get()); | 120 NGBox* div2 = new NGBox(div2_style.get()); |
118 | 121 |
119 div1->SetFirstChild(div2); | 122 div1->SetFirstChild(div2); |
120 | 123 |
121 auto* space = ConstructConstraintSpace( | 124 auto* space = |
122 HorizontalTopBottom, LeftToRight, | 125 ConstructConstraintSpace(HorizontalTopBottom, LeftToRight, |
123 NGPhysicalSize(LayoutUnit(500), LayoutUnit(500))); | 126 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); |
124 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 127 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
125 | 128 |
126 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 129 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
127 // DIV2 | 130 // DIV2 |
128 child = static_cast<const NGPhysicalFragment*>(child)->Children()[0]; | 131 child = static_cast<const NGPhysicalFragment*>(child)->Children()[0]; |
129 | 132 |
130 EXPECT_EQ(kHeight, child->Height()); | 133 EXPECT_EQ(kHeight, child->Height()); |
131 EXPECT_EQ(0, child->TopOffset()); | 134 EXPECT_EQ(0, child->TopOffset()); |
132 EXPECT_EQ(kMarginLeft, child->LeftOffset()); | 135 EXPECT_EQ(kMarginLeft, child->LeftOffset()); |
133 } | 136 } |
(...skipping 23 matching lines...) Expand all Loading... |
157 | 160 |
158 // DIV2 | 161 // DIV2 |
159 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 162 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
160 div2_style->setMarginTop(Length(kDiv2MarginTop, Fixed)); | 163 div2_style->setMarginTop(Length(kDiv2MarginTop, Fixed)); |
161 NGBox* div2 = new NGBox(div2_style.get()); | 164 NGBox* div2 = new NGBox(div2_style.get()); |
162 | 165 |
163 div1->SetFirstChild(div2); | 166 div1->SetFirstChild(div2); |
164 | 167 |
165 auto* space = ConstructConstraintSpace( | 168 auto* space = ConstructConstraintSpace( |
166 HorizontalTopBottom, LeftToRight, | 169 HorizontalTopBottom, LeftToRight, |
167 NGPhysicalSize(LayoutUnit(100), NGSizeIndefinite)); | 170 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
168 space->SetIsNewFormattingContext(true); | 171 space->SetIsNewFormattingContext(true); |
169 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 172 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
170 | 173 |
171 EXPECT_TRUE(frag->MarginStrut().IsEmpty()); | 174 EXPECT_TRUE(frag->MarginStrut().IsEmpty()); |
172 ASSERT_EQ(frag->Children().size(), 1UL); | 175 ASSERT_EQ(frag->Children().size(), 1UL); |
173 const NGPhysicalFragment* div2_fragment = | 176 const NGPhysicalFragment* div2_fragment = |
174 static_cast<const NGPhysicalFragment*>(frag->Children()[0].get()); | 177 static_cast<const NGPhysicalFragment*>(frag->Children()[0].get()); |
175 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2MarginTop)}), | 178 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2MarginTop)}), |
176 div2_fragment->MarginStrut()); | 179 div2_fragment->MarginStrut()); |
177 EXPECT_EQ(kDiv1MarginTop, div2_fragment->TopOffset()); | 180 EXPECT_EQ(kDiv1MarginTop, div2_fragment->TopOffset()); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 235 |
233 div1->SetFirstChild(div2); | 236 div1->SetFirstChild(div2); |
234 div2->SetNextSibling(div3); | 237 div2->SetNextSibling(div3); |
235 div1->SetNextSibling(div4); | 238 div1->SetNextSibling(div4); |
236 div4->SetNextSibling(div5); | 239 div4->SetNextSibling(div5); |
237 div5->SetFirstChild(div6); | 240 div5->SetFirstChild(div6); |
238 div6->SetNextSibling(div7); | 241 div6->SetNextSibling(div7); |
239 | 242 |
240 auto* space = ConstructConstraintSpace( | 243 auto* space = ConstructConstraintSpace( |
241 HorizontalTopBottom, LeftToRight, | 244 HorizontalTopBottom, LeftToRight, |
242 NGPhysicalSize(LayoutUnit(100), NGSizeIndefinite)); | 245 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
243 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 246 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
244 | 247 |
245 ASSERT_EQ(frag->Children().size(), 3UL); | 248 ASSERT_EQ(frag->Children().size(), 3UL); |
246 | 249 |
247 // DIV1 | 250 // DIV1 |
248 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 251 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
249 EXPECT_EQ(kHeight, child->Height()); | 252 EXPECT_EQ(kHeight, child->Height()); |
250 EXPECT_EQ(0, child->TopOffset()); | 253 EXPECT_EQ(0, child->TopOffset()); |
251 | 254 |
252 // DIV5 | 255 // DIV5 |
(...skipping 28 matching lines...) Expand all Loading... |
281 // DIV2 | 284 // DIV2 |
282 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 285 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
283 div2_style->setHeight(Length(kHeight, Fixed)); | 286 div2_style->setHeight(Length(kHeight, Fixed)); |
284 div2_style->setMarginBottom(Length(kDiv2MarginBottom, Fixed)); | 287 div2_style->setMarginBottom(Length(kDiv2MarginBottom, Fixed)); |
285 NGBox* div2 = new NGBox(div2_style.get()); | 288 NGBox* div2 = new NGBox(div2_style.get()); |
286 | 289 |
287 div1->SetFirstChild(div2); | 290 div1->SetFirstChild(div2); |
288 | 291 |
289 auto* space = ConstructConstraintSpace( | 292 auto* space = ConstructConstraintSpace( |
290 HorizontalTopBottom, LeftToRight, | 293 HorizontalTopBottom, LeftToRight, |
291 NGPhysicalSize(LayoutUnit(100), NGSizeIndefinite)); | 294 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
292 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 295 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
293 | 296 |
294 // Verify that margins are collapsed. | 297 // Verify that margins are collapsed. |
295 EXPECT_EQ(NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv2MarginBottom)}), | 298 EXPECT_EQ(NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv2MarginBottom)}), |
296 frag->MarginStrut()); | 299 frag->MarginStrut()); |
297 | 300 |
298 // Verify that margins are NOT collapsed. | 301 // Verify that margins are NOT collapsed. |
299 div1_style->setHeight(Length(kHeight, Fixed)); | 302 div1_style->setHeight(Length(kHeight, Fixed)); |
300 frag = RunBlockLayoutAlgorithm(space, div1); | 303 frag = RunBlockLayoutAlgorithm(space, div1); |
301 EXPECT_EQ(NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv1MarginBottom)}), | 304 EXPECT_EQ(NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv1MarginBottom)}), |
(...skipping 28 matching lines...) Expand all Loading... |
330 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 333 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
331 div2_style->setHeight(Length(kHeight, Fixed)); | 334 div2_style->setHeight(Length(kHeight, Fixed)); |
332 div2_style->setMarginTop(Length(kDiv2Margin, Fixed)); | 335 div2_style->setMarginTop(Length(kDiv2Margin, Fixed)); |
333 div2_style->setMarginBottom(Length(kDiv2Margin, Fixed)); | 336 div2_style->setMarginBottom(Length(kDiv2Margin, Fixed)); |
334 NGBox* div2 = new NGBox(div2_style.get()); | 337 NGBox* div2 = new NGBox(div2_style.get()); |
335 | 338 |
336 div1->SetFirstChild(div2); | 339 div1->SetFirstChild(div2); |
337 | 340 |
338 auto* space = ConstructConstraintSpace( | 341 auto* space = ConstructConstraintSpace( |
339 HorizontalTopBottom, LeftToRight, | 342 HorizontalTopBottom, LeftToRight, |
340 NGPhysicalSize(LayoutUnit(100), NGSizeIndefinite)); | 343 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
341 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 344 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
342 | 345 |
343 // Verify that margins do NOT collapse. | 346 // Verify that margins do NOT collapse. |
344 frag = RunBlockLayoutAlgorithm(space, div1); | 347 frag = RunBlockLayoutAlgorithm(space, div1); |
345 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv1Margin), LayoutUnit(kDiv1Margin)}), | 348 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv1Margin), LayoutUnit(kDiv1Margin)}), |
346 frag->MarginStrut()); | 349 frag->MarginStrut()); |
347 ASSERT_EQ(frag->Children().size(), 1UL); | 350 ASSERT_EQ(frag->Children().size(), 1UL); |
348 | 351 |
349 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2Margin), LayoutUnit(kDiv2Margin)}), | 352 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2Margin), LayoutUnit(kDiv2Margin)}), |
350 static_cast<const NGPhysicalFragment*>(frag->Children()[0].get()) | 353 static_cast<const NGPhysicalFragment*>(frag->Children()[0].get()) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 NGBox* vertical_div = new NGBox(vertical_style.get()); | 387 NGBox* vertical_div = new NGBox(vertical_style.get()); |
385 | 388 |
386 // Horizontal DIV | 389 // Horizontal DIV |
387 RefPtr<ComputedStyle> horizontal_style = ComputedStyle::create(); | 390 RefPtr<ComputedStyle> horizontal_style = ComputedStyle::create(); |
388 horizontal_style->setMarginLeft(Length(kHorizontalDivMarginLeft, Fixed)); | 391 horizontal_style->setMarginLeft(Length(kHorizontalDivMarginLeft, Fixed)); |
389 horizontal_style->setWritingMode(TopToBottomWritingMode); | 392 horizontal_style->setWritingMode(TopToBottomWritingMode); |
390 NGBox* horizontal_div = new NGBox(horizontal_style.get()); | 393 NGBox* horizontal_div = new NGBox(horizontal_style.get()); |
391 | 394 |
392 vertical_div->SetNextSibling(horizontal_div); | 395 vertical_div->SetNextSibling(horizontal_div); |
393 | 396 |
394 auto* space = ConstructConstraintSpace( | 397 auto* space = |
395 VerticalLeftRight, LeftToRight, | 398 ConstructConstraintSpace(VerticalLeftRight, LeftToRight, |
396 NGPhysicalSize(LayoutUnit(500), LayoutUnit(500))); | 399 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); |
397 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, vertical_div); | 400 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, vertical_div); |
398 | 401 |
399 ASSERT_EQ(frag->Children().size(), 2UL); | 402 ASSERT_EQ(frag->Children().size(), 2UL); |
400 const NGPhysicalFragmentBase* child = frag->Children()[1]; | 403 const NGPhysicalFragmentBase* child = frag->Children()[1]; |
401 // Horizontal div | 404 // Horizontal div |
402 EXPECT_EQ(0, child->TopOffset()); | 405 EXPECT_EQ(0, child->TopOffset()); |
403 EXPECT_EQ(kVerticalDivWidth + kHorizontalDivMarginLeft, child->LeftOffset()); | 406 EXPECT_EQ(kVerticalDivWidth + kHorizontalDivMarginLeft, child->LeftOffset()); |
404 } | 407 } |
405 | 408 |
406 // Verifies that the margin strut of a child with a different writing mode does | 409 // 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... |
442 | 445 |
443 // DIV3 | 446 // DIV3 |
444 RefPtr<ComputedStyle> div3_style = ComputedStyle::create(); | 447 RefPtr<ComputedStyle> div3_style = ComputedStyle::create(); |
445 div3_style->setHeight(Length(kHeight, Fixed)); | 448 div3_style->setHeight(Length(kHeight, Fixed)); |
446 div3_style->setMarginTop(Length(kMarginTop, Fixed)); | 449 div3_style->setMarginTop(Length(kMarginTop, Fixed)); |
447 NGBox* div3 = new NGBox(div3_style.get()); | 450 NGBox* div3 = new NGBox(div3_style.get()); |
448 | 451 |
449 div1->SetFirstChild(div2); | 452 div1->SetFirstChild(div2); |
450 div1->SetNextSibling(div3); | 453 div1->SetNextSibling(div3); |
451 | 454 |
452 auto* space = ConstructConstraintSpace( | 455 auto* space = |
453 HorizontalTopBottom, LeftToRight, | 456 ConstructConstraintSpace(HorizontalTopBottom, LeftToRight, |
454 NGPhysicalSize(LayoutUnit(500), LayoutUnit(500))); | 457 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); |
455 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 458 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
456 | 459 |
457 ASSERT_EQ(frag->Children().size(), 2UL); | 460 ASSERT_EQ(frag->Children().size(), 2UL); |
458 | 461 |
459 const NGPhysicalFragmentBase* child1 = frag->Children()[0]; | 462 const NGPhysicalFragmentBase* child1 = frag->Children()[0]; |
460 EXPECT_EQ(0, child1->TopOffset()); | 463 EXPECT_EQ(0, child1->TopOffset()); |
461 EXPECT_EQ(kHeight, child1->Height()); | 464 EXPECT_EQ(kHeight, child1->Height()); |
462 | 465 |
463 const NGPhysicalFragmentBase* child2 = frag->Children()[1]; | 466 const NGPhysicalFragmentBase* child2 = frag->Children()[1]; |
464 EXPECT_EQ(kHeight + std::max(kMarginBottom, kMarginTop), child2->TopOffset()); | 467 EXPECT_EQ(kHeight + std::max(kMarginBottom, kMarginTop), child2->TopOffset()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 div1_style->setPaddingLeft(Length(kPaddingLeft, Fixed)); | 510 div1_style->setPaddingLeft(Length(kPaddingLeft, Fixed)); |
508 NGBox* div1 = new NGBox(div1_style.get()); | 511 NGBox* div1 = new NGBox(div1_style.get()); |
509 | 512 |
510 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 513 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
511 NGBox* div2 = new NGBox(div2_style.get()); | 514 NGBox* div2 = new NGBox(div2_style.get()); |
512 | 515 |
513 div1->SetFirstChild(div2); | 516 div1->SetFirstChild(div2); |
514 | 517 |
515 auto* space = ConstructConstraintSpace( | 518 auto* space = ConstructConstraintSpace( |
516 HorizontalTopBottom, LeftToRight, | 519 HorizontalTopBottom, LeftToRight, |
517 NGPhysicalSize(LayoutUnit(1000), NGSizeIndefinite)); | 520 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); |
518 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 521 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
519 | 522 |
520 ASSERT_EQ(frag->Children().size(), 1UL); | 523 ASSERT_EQ(frag->Children().size(), 1UL); |
521 | 524 |
522 // div1 | 525 // div1 |
523 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 526 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
524 EXPECT_EQ(kBorderLeft + kPaddingLeft + kWidth + kPaddingRight + kBorderRight, | 527 EXPECT_EQ(kBorderLeft + kPaddingLeft + kWidth + kPaddingRight + kBorderRight, |
525 child->Width()); | 528 child->Width()); |
526 EXPECT_EQ(kBorderTop + kPaddingTop + kHeight + kPaddingBottom + kBorderBottom, | 529 EXPECT_EQ(kBorderTop + kPaddingTop + kHeight + kPaddingBottom + kBorderBottom, |
527 child->Height()); | 530 child->Height()); |
(...skipping 13 matching lines...) Expand all Loading... |
541 const int kWidth = 30; | 544 const int kWidth = 30; |
542 style_->setWidth(Length(kWidth, Fixed)); | 545 style_->setWidth(Length(kWidth, Fixed)); |
543 style_->setPaddingLeft(Length(kPaddingLeft, Fixed)); | 546 style_->setPaddingLeft(Length(kPaddingLeft, Fixed)); |
544 | 547 |
545 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); | 548 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); |
546 first_style->setWidth(Length(40, Percent)); | 549 first_style->setWidth(Length(40, Percent)); |
547 NGBox* first_child = new NGBox(first_style.get()); | 550 NGBox* first_child = new NGBox(first_style.get()); |
548 | 551 |
549 auto* space = ConstructConstraintSpace( | 552 auto* space = ConstructConstraintSpace( |
550 HorizontalTopBottom, LeftToRight, | 553 HorizontalTopBottom, LeftToRight, |
551 NGPhysicalSize(LayoutUnit(100), NGSizeIndefinite)); | 554 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
552 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); | 555 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); |
553 | 556 |
554 EXPECT_EQ(frag->Width(), LayoutUnit(kWidth + kPaddingLeft)); | 557 EXPECT_EQ(frag->Width(), LayoutUnit(kWidth + kPaddingLeft)); |
555 EXPECT_EQ(frag->Type(), NGPhysicalFragmentBase::FragmentBox); | 558 EXPECT_EQ(frag->Type(), NGPhysicalFragmentBase::FragmentBox); |
556 ASSERT_EQ(frag->Children().size(), 1UL); | 559 ASSERT_EQ(frag->Children().size(), 1UL); |
557 | 560 |
558 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 561 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
559 EXPECT_EQ(child->Width(), LayoutUnit(12)); | 562 EXPECT_EQ(child->Width(), LayoutUnit(12)); |
560 } | 563 } |
561 | 564 |
562 // A very simple auto margin case. We rely on the tests in ng_length_utils_test | 565 // A very simple auto margin case. We rely on the tests in ng_length_utils_test |
563 // for the more complex cases; just make sure we handle auto at all here. | 566 // for the more complex cases; just make sure we handle auto at all here. |
564 TEST_F(NGBlockLayoutAlgorithmTest, AutoMargin) { | 567 TEST_F(NGBlockLayoutAlgorithmTest, AutoMargin) { |
565 const int kPaddingLeft = 10; | 568 const int kPaddingLeft = 10; |
566 const int kWidth = 30; | 569 const int kWidth = 30; |
567 style_->setWidth(Length(kWidth, Fixed)); | 570 style_->setWidth(Length(kWidth, Fixed)); |
568 style_->setPaddingLeft(Length(kPaddingLeft, Fixed)); | 571 style_->setPaddingLeft(Length(kPaddingLeft, Fixed)); |
569 | 572 |
570 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); | 573 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); |
571 const int kChildWidth = 10; | 574 const int kChildWidth = 10; |
572 first_style->setWidth(Length(kChildWidth, Fixed)); | 575 first_style->setWidth(Length(kChildWidth, Fixed)); |
573 first_style->setMarginLeft(Length(Auto)); | 576 first_style->setMarginLeft(Length(Auto)); |
574 first_style->setMarginRight(Length(Auto)); | 577 first_style->setMarginRight(Length(Auto)); |
575 NGBox* first_child = new NGBox(first_style.get()); | 578 NGBox* first_child = new NGBox(first_style.get()); |
576 | 579 |
577 auto* space = ConstructConstraintSpace( | 580 auto* space = ConstructConstraintSpace( |
578 HorizontalTopBottom, LeftToRight, | 581 HorizontalTopBottom, LeftToRight, |
579 NGPhysicalSize(LayoutUnit(100), NGSizeIndefinite)); | 582 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
580 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); | 583 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); |
581 | 584 |
582 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width()); | 585 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width()); |
583 EXPECT_EQ(NGPhysicalFragmentBase::FragmentBox, frag->Type()); | 586 EXPECT_EQ(NGPhysicalFragmentBase::FragmentBox, frag->Type()); |
584 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->WidthOverflow()); | 587 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->WidthOverflow()); |
585 ASSERT_EQ(1UL, frag->Children().size()); | 588 ASSERT_EQ(1UL, frag->Children().size()); |
586 | 589 |
587 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 590 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
588 EXPECT_EQ(LayoutUnit(kChildWidth), child->Width()); | 591 EXPECT_EQ(LayoutUnit(kChildWidth), child->Width()); |
589 EXPECT_EQ(LayoutUnit(kPaddingLeft + 10), child->LeftOffset()); | 592 EXPECT_EQ(LayoutUnit(kPaddingLeft + 10), child->LeftOffset()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 div3_style->setHeight(Length(kDiv3Size, Fixed)); | 641 div3_style->setHeight(Length(kDiv3Size, Fixed)); |
639 div3_style->setMarginLeft(Length(kDiv3LeftMargin, Fixed)); | 642 div3_style->setMarginLeft(Length(kDiv3LeftMargin, Fixed)); |
640 div3_style->setFloating(EFloat::Left); | 643 div3_style->setFloating(EFloat::Left); |
641 NGBox* div3 = new NGBox(div3_style.get()); | 644 NGBox* div3 = new NGBox(div3_style.get()); |
642 | 645 |
643 div1->SetNextSibling(div2); | 646 div1->SetNextSibling(div2); |
644 div2->SetNextSibling(div3); | 647 div2->SetNextSibling(div3); |
645 | 648 |
646 auto* space = ConstructConstraintSpace( | 649 auto* space = ConstructConstraintSpace( |
647 HorizontalTopBottom, LeftToRight, | 650 HorizontalTopBottom, LeftToRight, |
648 NGPhysicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); | 651 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); |
649 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 652 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
650 ASSERT_EQ(frag->Children().size(), 3UL); | 653 ASSERT_EQ(frag->Children().size(), 3UL); |
651 | 654 |
652 // DIV1 | 655 // DIV1 |
653 const NGPhysicalFragmentBase* child1 = frag->Children()[0]; | 656 const NGPhysicalFragmentBase* child1 = frag->Children()[0]; |
654 EXPECT_EQ(kDiv1TopMargin, child1->TopOffset()); | 657 EXPECT_EQ(kDiv1TopMargin, child1->TopOffset()); |
655 EXPECT_EQ(0, child1->LeftOffset()); | 658 EXPECT_EQ(0, child1->LeftOffset()); |
656 | 659 |
657 // DIV2 | 660 // DIV2 |
658 const NGPhysicalFragmentBase* child2 = frag->Children()[1]; | 661 const NGPhysicalFragmentBase* child2 = frag->Children()[1]; |
659 EXPECT_EQ(0, child2->TopOffset()); | 662 EXPECT_EQ(0, child2->TopOffset()); |
660 EXPECT_EQ(kParentSize - kDiv2Size, child2->LeftOffset()); | 663 EXPECT_EQ(kParentSize - kDiv2Size, child2->LeftOffset()); |
661 | 664 |
662 // DIV3 | 665 // DIV3 |
663 const NGPhysicalFragmentBase* child3 = frag->Children()[2]; | 666 const NGPhysicalFragmentBase* child3 = frag->Children()[2]; |
664 EXPECT_EQ(kDiv2Size, child3->TopOffset()); | 667 EXPECT_EQ(kDiv2Size, child3->TopOffset()); |
665 EXPECT_EQ(kDiv3LeftMargin, child3->LeftOffset()); | 668 EXPECT_EQ(kDiv3LeftMargin, child3->LeftOffset()); |
666 } | 669 } |
667 } // namespace | 670 } // namespace |
668 } // namespace blink | 671 } // namespace blink |
OLD | NEW |