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_block_node.h" | 7 #include "core/layout/ng/ng_block_node.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_constraint_space_builder.h" |
10 #include "core/layout/ng/ng_physical_fragment_base.h" | 10 #include "core/layout/ng/ng_physical_fragment_base.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 } | 41 } |
42 | 42 |
43 RefPtr<ComputedStyle> style_; | 43 RefPtr<ComputedStyle> style_; |
44 }; | 44 }; |
45 | 45 |
46 TEST_F(NGBlockLayoutAlgorithmTest, FixedSize) { | 46 TEST_F(NGBlockLayoutAlgorithmTest, FixedSize) { |
47 style_->setWidth(Length(30, Fixed)); | 47 style_->setWidth(Length(30, Fixed)); |
48 style_->setHeight(Length(40, Fixed)); | 48 style_->setHeight(Length(40, Fixed)); |
49 | 49 |
50 auto* space = ConstructConstraintSpace( | 50 auto* space = ConstructConstraintSpace( |
51 HorizontalTopBottom, LTR, | 51 kHorizontalTopBottom, LTR, |
52 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 52 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
53 NGPhysicalFragmentBase* frag = RunBlockLayoutAlgorithm(space, nullptr); | 53 NGPhysicalFragmentBase* frag = RunBlockLayoutAlgorithm(space, nullptr); |
54 | 54 |
55 EXPECT_EQ(LayoutUnit(30), frag->Width()); | 55 EXPECT_EQ(LayoutUnit(30), frag->Width()); |
56 EXPECT_EQ(LayoutUnit(40), frag->Height()); | 56 EXPECT_EQ(LayoutUnit(40), frag->Height()); |
57 } | 57 } |
58 | 58 |
59 // Verifies that two children are laid out with the correct size and position. | 59 // Verifies that two children are laid out with the correct size and position. |
60 TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildren) { | 60 TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildren) { |
61 const int kWidth = 30; | 61 const int kWidth = 30; |
62 const int kHeight1 = 20; | 62 const int kHeight1 = 20; |
63 const int kHeight2 = 30; | 63 const int kHeight2 = 30; |
64 const int kMarginTop = 5; | 64 const int kMarginTop = 5; |
65 const int kMarginBottom = 20; | 65 const int kMarginBottom = 20; |
66 style_->setWidth(Length(kWidth, Fixed)); | 66 style_->setWidth(Length(kWidth, Fixed)); |
67 | 67 |
68 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); | 68 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); |
69 first_style->setHeight(Length(kHeight1, Fixed)); | 69 first_style->setHeight(Length(kHeight1, Fixed)); |
70 NGBlockNode* first_child = new NGBlockNode(first_style.get()); | 70 NGBlockNode* first_child = new NGBlockNode(first_style.get()); |
71 | 71 |
72 RefPtr<ComputedStyle> second_style = ComputedStyle::create(); | 72 RefPtr<ComputedStyle> second_style = ComputedStyle::create(); |
73 second_style->setHeight(Length(kHeight2, Fixed)); | 73 second_style->setHeight(Length(kHeight2, Fixed)); |
74 second_style->setMarginTop(Length(kMarginTop, Fixed)); | 74 second_style->setMarginTop(Length(kMarginTop, Fixed)); |
75 second_style->setMarginBottom(Length(kMarginBottom, Fixed)); | 75 second_style->setMarginBottom(Length(kMarginBottom, Fixed)); |
76 NGBlockNode* second_child = new NGBlockNode(second_style.get()); | 76 NGBlockNode* second_child = new NGBlockNode(second_style.get()); |
77 | 77 |
78 first_child->SetNextSibling(second_child); | 78 first_child->SetNextSibling(second_child); |
79 | 79 |
80 auto* space = ConstructConstraintSpace( | 80 auto* space = ConstructConstraintSpace( |
81 HorizontalTopBottom, LTR, | 81 kHorizontalTopBottom, LTR, |
82 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 82 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
83 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); | 83 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); |
84 | 84 |
85 EXPECT_EQ(LayoutUnit(kWidth), frag->Width()); | 85 EXPECT_EQ(LayoutUnit(kWidth), frag->Width()); |
86 EXPECT_EQ(LayoutUnit(kHeight1 + kHeight2 + kMarginTop), frag->Height()); | 86 EXPECT_EQ(LayoutUnit(kHeight1 + kHeight2 + kMarginTop), frag->Height()); |
87 EXPECT_EQ(NGPhysicalFragmentBase::FragmentBox, frag->Type()); | 87 EXPECT_EQ(NGPhysicalFragmentBase::kFragmentBox, frag->Type()); |
88 ASSERT_EQ(frag->Children().size(), 2UL); | 88 ASSERT_EQ(frag->Children().size(), 2UL); |
89 | 89 |
90 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 90 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
91 EXPECT_EQ(kHeight1, child->Height()); | 91 EXPECT_EQ(kHeight1, child->Height()); |
92 EXPECT_EQ(0, child->TopOffset()); | 92 EXPECT_EQ(0, child->TopOffset()); |
93 | 93 |
94 child = frag->Children()[1]; | 94 child = frag->Children()[1]; |
95 EXPECT_EQ(kHeight2, child->Height()); | 95 EXPECT_EQ(kHeight2, child->Height()); |
96 EXPECT_EQ(kHeight1 + kMarginTop, child->TopOffset()); | 96 EXPECT_EQ(kHeight1 + kMarginTop, child->TopOffset()); |
97 } | 97 } |
(...skipping 19 matching lines...) Expand all Loading... |
117 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 117 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
118 div2_style->setHeight(Length(kHeight, Fixed)); | 118 div2_style->setHeight(Length(kHeight, Fixed)); |
119 div2_style->setWidth(Length(kWidth, Fixed)); | 119 div2_style->setWidth(Length(kWidth, Fixed)); |
120 div1_style->setWritingMode(TopToBottomWritingMode); | 120 div1_style->setWritingMode(TopToBottomWritingMode); |
121 div2_style->setMarginLeft(Length(kMarginLeft, Fixed)); | 121 div2_style->setMarginLeft(Length(kMarginLeft, Fixed)); |
122 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); | 122 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); |
123 | 123 |
124 div1->SetFirstChild(div2); | 124 div1->SetFirstChild(div2); |
125 | 125 |
126 auto* space = | 126 auto* space = |
127 ConstructConstraintSpace(HorizontalTopBottom, LTR, | 127 ConstructConstraintSpace(kHorizontalTopBottom, LTR, |
128 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); | 128 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); |
129 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 129 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
130 | 130 |
131 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 131 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
132 // DIV2 | 132 // DIV2 |
133 child = static_cast<const NGPhysicalFragment*>(child)->Children()[0]; | 133 child = static_cast<const NGPhysicalFragment*>(child)->Children()[0]; |
134 | 134 |
135 EXPECT_EQ(kHeight, child->Height()); | 135 EXPECT_EQ(kHeight, child->Height()); |
136 EXPECT_EQ(0, child->TopOffset()); | 136 EXPECT_EQ(0, child->TopOffset()); |
137 EXPECT_EQ(kMarginLeft, child->LeftOffset()); | 137 EXPECT_EQ(kMarginLeft, child->LeftOffset()); |
(...skipping 23 matching lines...) Expand all Loading... |
161 NGBlockNode* div1 = new NGBlockNode(div1_style.get()); | 161 NGBlockNode* div1 = new NGBlockNode(div1_style.get()); |
162 | 162 |
163 // DIV2 | 163 // DIV2 |
164 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 164 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
165 div2_style->setMarginTop(Length(kDiv2MarginTop, Fixed)); | 165 div2_style->setMarginTop(Length(kDiv2MarginTop, Fixed)); |
166 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); | 166 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); |
167 | 167 |
168 div1->SetFirstChild(div2); | 168 div1->SetFirstChild(div2); |
169 | 169 |
170 NGLogicalSize size(LayoutUnit(100), NGSizeIndefinite); | 170 NGLogicalSize size(LayoutUnit(100), NGSizeIndefinite); |
171 NGConstraintSpaceBuilder builder(HorizontalTopBottom); | 171 NGConstraintSpaceBuilder builder(kHorizontalTopBottom); |
172 builder.SetAvailableSize(size) | 172 builder.SetAvailableSize(size) |
173 .SetPercentageResolutionSize(size) | 173 .SetPercentageResolutionSize(size) |
174 .SetIsNewFormattingContext(true); | 174 .SetIsNewFormattingContext(true); |
175 auto* space = new NGConstraintSpace(HorizontalTopBottom, LTR, | 175 auto* space = new NGConstraintSpace(kHorizontalTopBottom, LTR, |
176 builder.ToConstraintSpace()); | 176 builder.ToConstraintSpace()); |
177 | 177 |
178 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 178 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
179 | 179 |
180 EXPECT_TRUE(frag->MarginStrut().IsEmpty()); | 180 EXPECT_TRUE(frag->MarginStrut().IsEmpty()); |
181 ASSERT_EQ(frag->Children().size(), 1UL); | 181 ASSERT_EQ(frag->Children().size(), 1UL); |
182 const NGPhysicalFragment* div2_fragment = | 182 const NGPhysicalFragment* div2_fragment = |
183 static_cast<const NGPhysicalFragment*>(frag->Children()[0].get()); | 183 static_cast<const NGPhysicalFragment*>(frag->Children()[0].get()); |
184 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2MarginTop)}), | 184 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2MarginTop)}), |
185 div2_fragment->MarginStrut()); | 185 div2_fragment->MarginStrut()); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 NGBlockNode* div7 = new NGBlockNode(div7_style.get()); | 240 NGBlockNode* div7 = new NGBlockNode(div7_style.get()); |
241 | 241 |
242 div1->SetFirstChild(div2); | 242 div1->SetFirstChild(div2); |
243 div2->SetNextSibling(div3); | 243 div2->SetNextSibling(div3); |
244 div1->SetNextSibling(div4); | 244 div1->SetNextSibling(div4); |
245 div4->SetNextSibling(div5); | 245 div4->SetNextSibling(div5); |
246 div5->SetFirstChild(div6); | 246 div5->SetFirstChild(div6); |
247 div6->SetNextSibling(div7); | 247 div6->SetNextSibling(div7); |
248 | 248 |
249 auto* space = ConstructConstraintSpace( | 249 auto* space = ConstructConstraintSpace( |
250 HorizontalTopBottom, LTR, | 250 kHorizontalTopBottom, LTR, |
251 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 251 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
252 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 252 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
253 | 253 |
254 ASSERT_EQ(frag->Children().size(), 3UL); | 254 ASSERT_EQ(frag->Children().size(), 3UL); |
255 | 255 |
256 // DIV1 | 256 // DIV1 |
257 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 257 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
258 EXPECT_EQ(kHeight, child->Height()); | 258 EXPECT_EQ(kHeight, child->Height()); |
259 EXPECT_EQ(0, child->TopOffset()); | 259 EXPECT_EQ(0, child->TopOffset()); |
260 | 260 |
(...skipping 28 matching lines...) Expand all Loading... |
289 | 289 |
290 // DIV2 | 290 // DIV2 |
291 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 291 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
292 div2_style->setHeight(Length(kHeight, Fixed)); | 292 div2_style->setHeight(Length(kHeight, Fixed)); |
293 div2_style->setMarginBottom(Length(kDiv2MarginBottom, Fixed)); | 293 div2_style->setMarginBottom(Length(kDiv2MarginBottom, Fixed)); |
294 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); | 294 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); |
295 | 295 |
296 div1->SetFirstChild(div2); | 296 div1->SetFirstChild(div2); |
297 | 297 |
298 auto* space = ConstructConstraintSpace( | 298 auto* space = ConstructConstraintSpace( |
299 HorizontalTopBottom, LTR, | 299 kHorizontalTopBottom, LTR, |
300 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 300 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
301 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 301 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
302 | 302 |
303 // Verify that margins are collapsed. | 303 // Verify that margins are collapsed. |
304 EXPECT_EQ(NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv2MarginBottom)}), | 304 EXPECT_EQ(NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv2MarginBottom)}), |
305 frag->MarginStrut()); | 305 frag->MarginStrut()); |
306 | 306 |
307 // Verify that margins are NOT collapsed. | 307 // Verify that margins are NOT collapsed. |
308 div1_style->setHeight(Length(kHeight, Fixed)); | 308 div1_style->setHeight(Length(kHeight, Fixed)); |
309 frag = RunBlockLayoutAlgorithm(space, div1); | 309 frag = RunBlockLayoutAlgorithm(space, div1); |
(...skipping 28 matching lines...) Expand all Loading... |
338 // DIV2 | 338 // DIV2 |
339 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 339 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
340 div2_style->setHeight(Length(kHeight, Fixed)); | 340 div2_style->setHeight(Length(kHeight, Fixed)); |
341 div2_style->setMarginTop(Length(kDiv2Margin, Fixed)); | 341 div2_style->setMarginTop(Length(kDiv2Margin, Fixed)); |
342 div2_style->setMarginBottom(Length(kDiv2Margin, Fixed)); | 342 div2_style->setMarginBottom(Length(kDiv2Margin, Fixed)); |
343 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); | 343 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); |
344 | 344 |
345 div1->SetFirstChild(div2); | 345 div1->SetFirstChild(div2); |
346 | 346 |
347 auto* space = ConstructConstraintSpace( | 347 auto* space = ConstructConstraintSpace( |
348 HorizontalTopBottom, LTR, | 348 kHorizontalTopBottom, LTR, |
349 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 349 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
350 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 350 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
351 | 351 |
352 // Verify that margins do NOT collapse. | 352 // Verify that margins do NOT collapse. |
353 frag = RunBlockLayoutAlgorithm(space, div1); | 353 frag = RunBlockLayoutAlgorithm(space, div1); |
354 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv1Margin), LayoutUnit(kDiv1Margin)}), | 354 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv1Margin), LayoutUnit(kDiv1Margin)}), |
355 frag->MarginStrut()); | 355 frag->MarginStrut()); |
356 ASSERT_EQ(frag->Children().size(), 1UL); | 356 ASSERT_EQ(frag->Children().size(), 1UL); |
357 | 357 |
358 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2Margin), LayoutUnit(kDiv2Margin)}), | 358 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2Margin), LayoutUnit(kDiv2Margin)}), |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 | 394 |
395 // Horizontal DIV | 395 // Horizontal DIV |
396 RefPtr<ComputedStyle> horizontal_style = ComputedStyle::create(); | 396 RefPtr<ComputedStyle> horizontal_style = ComputedStyle::create(); |
397 horizontal_style->setMarginLeft(Length(kHorizontalDivMarginLeft, Fixed)); | 397 horizontal_style->setMarginLeft(Length(kHorizontalDivMarginLeft, Fixed)); |
398 horizontal_style->setWritingMode(TopToBottomWritingMode); | 398 horizontal_style->setWritingMode(TopToBottomWritingMode); |
399 NGBlockNode* horizontal_div = new NGBlockNode(horizontal_style.get()); | 399 NGBlockNode* horizontal_div = new NGBlockNode(horizontal_style.get()); |
400 | 400 |
401 vertical_div->SetNextSibling(horizontal_div); | 401 vertical_div->SetNextSibling(horizontal_div); |
402 | 402 |
403 auto* space = ConstructConstraintSpace( | 403 auto* space = ConstructConstraintSpace( |
404 VerticalLeftRight, LTR, NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); | 404 kVerticalLeftRight, LTR, NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); |
405 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, vertical_div); | 405 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, vertical_div); |
406 | 406 |
407 ASSERT_EQ(frag->Children().size(), 2UL); | 407 ASSERT_EQ(frag->Children().size(), 2UL); |
408 const NGPhysicalFragmentBase* child = frag->Children()[1]; | 408 const NGPhysicalFragmentBase* child = frag->Children()[1]; |
409 // Horizontal div | 409 // Horizontal div |
410 EXPECT_EQ(0, child->TopOffset()); | 410 EXPECT_EQ(0, child->TopOffset()); |
411 EXPECT_EQ(kVerticalDivWidth + kHorizontalDivMarginLeft, child->LeftOffset()); | 411 EXPECT_EQ(kVerticalDivWidth + kHorizontalDivMarginLeft, child->LeftOffset()); |
412 } | 412 } |
413 | 413 |
414 // Verifies that the margin strut of a child with a different writing mode does | 414 // Verifies that the margin strut of a child with a different writing mode does |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 // DIV3 | 451 // DIV3 |
452 RefPtr<ComputedStyle> div3_style = ComputedStyle::create(); | 452 RefPtr<ComputedStyle> div3_style = ComputedStyle::create(); |
453 div3_style->setHeight(Length(kHeight, Fixed)); | 453 div3_style->setHeight(Length(kHeight, Fixed)); |
454 div3_style->setMarginTop(Length(kMarginTop, Fixed)); | 454 div3_style->setMarginTop(Length(kMarginTop, Fixed)); |
455 NGBlockNode* div3 = new NGBlockNode(div3_style.get()); | 455 NGBlockNode* div3 = new NGBlockNode(div3_style.get()); |
456 | 456 |
457 div1->SetFirstChild(div2); | 457 div1->SetFirstChild(div2); |
458 div1->SetNextSibling(div3); | 458 div1->SetNextSibling(div3); |
459 | 459 |
460 auto* space = | 460 auto* space = |
461 ConstructConstraintSpace(HorizontalTopBottom, LTR, | 461 ConstructConstraintSpace(kHorizontalTopBottom, LTR, |
462 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); | 462 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); |
463 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 463 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
464 | 464 |
465 ASSERT_EQ(frag->Children().size(), 2UL); | 465 ASSERT_EQ(frag->Children().size(), 2UL); |
466 | 466 |
467 const NGPhysicalFragmentBase* child1 = frag->Children()[0]; | 467 const NGPhysicalFragmentBase* child1 = frag->Children()[0]; |
468 EXPECT_EQ(0, child1->TopOffset()); | 468 EXPECT_EQ(0, child1->TopOffset()); |
469 EXPECT_EQ(kHeight, child1->Height()); | 469 EXPECT_EQ(kHeight, child1->Height()); |
470 | 470 |
471 const NGPhysicalFragmentBase* child2 = frag->Children()[1]; | 471 const NGPhysicalFragmentBase* child2 = frag->Children()[1]; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 div1_style->setPaddingBottom(Length(kPaddingBottom, Fixed)); | 514 div1_style->setPaddingBottom(Length(kPaddingBottom, Fixed)); |
515 div1_style->setPaddingLeft(Length(kPaddingLeft, Fixed)); | 515 div1_style->setPaddingLeft(Length(kPaddingLeft, Fixed)); |
516 NGBlockNode* div1 = new NGBlockNode(div1_style.get()); | 516 NGBlockNode* div1 = new NGBlockNode(div1_style.get()); |
517 | 517 |
518 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 518 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
519 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); | 519 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); |
520 | 520 |
521 div1->SetFirstChild(div2); | 521 div1->SetFirstChild(div2); |
522 | 522 |
523 auto* space = ConstructConstraintSpace( | 523 auto* space = ConstructConstraintSpace( |
524 HorizontalTopBottom, LTR, | 524 kHorizontalTopBottom, LTR, |
525 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); | 525 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); |
526 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 526 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
527 | 527 |
528 ASSERT_EQ(frag->Children().size(), 1UL); | 528 ASSERT_EQ(frag->Children().size(), 1UL); |
529 | 529 |
530 // div1 | 530 // div1 |
531 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 531 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
532 EXPECT_EQ(kBorderLeft + kPaddingLeft + kWidth + kPaddingRight + kBorderRight, | 532 EXPECT_EQ(kBorderLeft + kPaddingLeft + kWidth + kPaddingRight + kBorderRight, |
533 child->Width()); | 533 child->Width()); |
534 EXPECT_EQ(kBorderTop + kPaddingTop + kHeight + kPaddingBottom + kBorderBottom, | 534 EXPECT_EQ(kBorderTop + kPaddingTop + kHeight + kPaddingBottom + kBorderBottom, |
535 child->Height()); | 535 child->Height()); |
536 | 536 |
537 ASSERT_TRUE(child->Type() == NGPhysicalFragmentBase::FragmentBox); | 537 ASSERT_TRUE(child->Type() == NGPhysicalFragmentBase::kFragmentBox); |
538 ASSERT_EQ(static_cast<const NGPhysicalFragment*>(child)->Children().size(), | 538 ASSERT_EQ(static_cast<const NGPhysicalFragment*>(child)->Children().size(), |
539 1UL); | 539 1UL); |
540 | 540 |
541 // div2 | 541 // div2 |
542 child = static_cast<const NGPhysicalFragment*>(child)->Children()[0]; | 542 child = static_cast<const NGPhysicalFragment*>(child)->Children()[0]; |
543 EXPECT_EQ(kBorderTop + kPaddingTop, child->TopOffset()); | 543 EXPECT_EQ(kBorderTop + kPaddingTop, child->TopOffset()); |
544 EXPECT_EQ(kBorderLeft + kPaddingLeft, child->LeftOffset()); | 544 EXPECT_EQ(kBorderLeft + kPaddingLeft, child->LeftOffset()); |
545 } | 545 } |
546 | 546 |
547 TEST_F(NGBlockLayoutAlgorithmTest, PercentageResolutionSize) { | 547 TEST_F(NGBlockLayoutAlgorithmTest, PercentageResolutionSize) { |
548 const int kPaddingLeft = 10; | 548 const int kPaddingLeft = 10; |
549 const int kWidth = 30; | 549 const int kWidth = 30; |
550 style_->setWidth(Length(kWidth, Fixed)); | 550 style_->setWidth(Length(kWidth, Fixed)); |
551 style_->setPaddingLeft(Length(kPaddingLeft, Fixed)); | 551 style_->setPaddingLeft(Length(kPaddingLeft, Fixed)); |
552 | 552 |
553 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); | 553 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); |
554 first_style->setWidth(Length(40, Percent)); | 554 first_style->setWidth(Length(40, Percent)); |
555 NGBlockNode* first_child = new NGBlockNode(first_style.get()); | 555 NGBlockNode* first_child = new NGBlockNode(first_style.get()); |
556 | 556 |
557 auto* space = ConstructConstraintSpace( | 557 auto* space = ConstructConstraintSpace( |
558 HorizontalTopBottom, LTR, | 558 kHorizontalTopBottom, LTR, |
559 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 559 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
560 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); | 560 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); |
561 | 561 |
562 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width()); | 562 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width()); |
563 EXPECT_EQ(NGPhysicalFragmentBase::FragmentBox, frag->Type()); | 563 EXPECT_EQ(NGPhysicalFragmentBase::kFragmentBox, frag->Type()); |
564 ASSERT_EQ(frag->Children().size(), 1UL); | 564 ASSERT_EQ(frag->Children().size(), 1UL); |
565 | 565 |
566 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 566 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
567 EXPECT_EQ(LayoutUnit(12), child->Width()); | 567 EXPECT_EQ(LayoutUnit(12), child->Width()); |
568 } | 568 } |
569 | 569 |
570 // A very simple auto margin case. We rely on the tests in ng_length_utils_test | 570 // A very simple auto margin case. We rely on the tests in ng_length_utils_test |
571 // for the more complex cases; just make sure we handle auto at all here. | 571 // for the more complex cases; just make sure we handle auto at all here. |
572 TEST_F(NGBlockLayoutAlgorithmTest, AutoMargin) { | 572 TEST_F(NGBlockLayoutAlgorithmTest, AutoMargin) { |
573 const int kPaddingLeft = 10; | 573 const int kPaddingLeft = 10; |
574 const int kWidth = 30; | 574 const int kWidth = 30; |
575 style_->setWidth(Length(kWidth, Fixed)); | 575 style_->setWidth(Length(kWidth, Fixed)); |
576 style_->setPaddingLeft(Length(kPaddingLeft, Fixed)); | 576 style_->setPaddingLeft(Length(kPaddingLeft, Fixed)); |
577 | 577 |
578 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); | 578 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); |
579 const int kChildWidth = 10; | 579 const int kChildWidth = 10; |
580 first_style->setWidth(Length(kChildWidth, Fixed)); | 580 first_style->setWidth(Length(kChildWidth, Fixed)); |
581 first_style->setMarginLeft(Length(Auto)); | 581 first_style->setMarginLeft(Length(Auto)); |
582 first_style->setMarginRight(Length(Auto)); | 582 first_style->setMarginRight(Length(Auto)); |
583 NGBlockNode* first_child = new NGBlockNode(first_style.get()); | 583 NGBlockNode* first_child = new NGBlockNode(first_style.get()); |
584 | 584 |
585 auto* space = ConstructConstraintSpace( | 585 auto* space = ConstructConstraintSpace( |
586 HorizontalTopBottom, LTR, | 586 kHorizontalTopBottom, LTR, |
587 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 587 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
588 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); | 588 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); |
589 | 589 |
590 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width()); | 590 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width()); |
591 EXPECT_EQ(NGPhysicalFragmentBase::FragmentBox, frag->Type()); | 591 EXPECT_EQ(NGPhysicalFragmentBase::kFragmentBox, frag->Type()); |
592 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->WidthOverflow()); | 592 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->WidthOverflow()); |
593 ASSERT_EQ(1UL, frag->Children().size()); | 593 ASSERT_EQ(1UL, frag->Children().size()); |
594 | 594 |
595 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 595 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
596 EXPECT_EQ(LayoutUnit(kChildWidth), child->Width()); | 596 EXPECT_EQ(LayoutUnit(kChildWidth), child->Width()); |
597 EXPECT_EQ(LayoutUnit(kPaddingLeft + 10), child->LeftOffset()); | 597 EXPECT_EQ(LayoutUnit(kPaddingLeft + 10), child->LeftOffset()); |
598 EXPECT_EQ(LayoutUnit(0), child->TopOffset()); | 598 EXPECT_EQ(LayoutUnit(0), child->TopOffset()); |
599 } | 599 } |
600 | 600 |
601 // Verifies that 3 Left/Right float fragments and one regular block fragment | 601 // Verifies that 3 Left/Right float fragments and one regular block fragment |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 div4_style->setHeight(Length(kDiv4Size, Fixed)); | 657 div4_style->setHeight(Length(kDiv4Size, Fixed)); |
658 div4_style->setMarginLeft(Length(kDiv4LeftMargin, Fixed)); | 658 div4_style->setMarginLeft(Length(kDiv4LeftMargin, Fixed)); |
659 div4_style->setFloating(EFloat::Left); | 659 div4_style->setFloating(EFloat::Left); |
660 NGBlockNode* div4 = new NGBlockNode(div4_style.get()); | 660 NGBlockNode* div4 = new NGBlockNode(div4_style.get()); |
661 | 661 |
662 div1->SetNextSibling(div2); | 662 div1->SetNextSibling(div2); |
663 div2->SetNextSibling(div3); | 663 div2->SetNextSibling(div3); |
664 div3->SetNextSibling(div4); | 664 div3->SetNextSibling(div4); |
665 | 665 |
666 auto* space = ConstructConstraintSpace( | 666 auto* space = ConstructConstraintSpace( |
667 HorizontalTopBottom, LTR, | 667 kHorizontalTopBottom, LTR, |
668 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); | 668 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); |
669 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 669 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
670 ASSERT_EQ(frag->Children().size(), 4UL); | 670 ASSERT_EQ(frag->Children().size(), 4UL); |
671 | 671 |
672 // DIV1 | 672 // DIV1 |
673 const NGPhysicalFragmentBase* child1 = frag->Children()[0]; | 673 const NGPhysicalFragmentBase* child1 = frag->Children()[0]; |
674 EXPECT_EQ(kDiv1TopMargin, child1->TopOffset()); | 674 EXPECT_EQ(kDiv1TopMargin, child1->TopOffset()); |
675 EXPECT_EQ(kParentLeftPadding, child1->LeftOffset()); | 675 EXPECT_EQ(kParentLeftPadding, child1->LeftOffset()); |
676 | 676 |
677 // DIV2 | 677 // DIV2 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 div3_style->setWidth(Length(kDiv3Size, Fixed)); | 734 div3_style->setWidth(Length(kDiv3Size, Fixed)); |
735 div3_style->setHeight(Length(kDiv3Size, Fixed)); | 735 div3_style->setHeight(Length(kDiv3Size, Fixed)); |
736 NGBlockNode* div3 = new NGBlockNode(div3_style.get()); | 736 NGBlockNode* div3 = new NGBlockNode(div3_style.get()); |
737 | 737 |
738 div1->SetNextSibling(div2); | 738 div1->SetNextSibling(div2); |
739 div2->SetNextSibling(div3); | 739 div2->SetNextSibling(div3); |
740 | 740 |
741 // clear: left; | 741 // clear: left; |
742 div3_style->setClear(EClear::ClearLeft); | 742 div3_style->setClear(EClear::ClearLeft); |
743 auto* space = ConstructConstraintSpace( | 743 auto* space = ConstructConstraintSpace( |
744 HorizontalTopBottom, LTR, | 744 kHorizontalTopBottom, LTR, |
745 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); | 745 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); |
746 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 746 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
747 const NGPhysicalFragmentBase* child3 = frag->Children()[2]; | 747 const NGPhysicalFragmentBase* child3 = frag->Children()[2]; |
748 EXPECT_EQ(kDiv1Size, child3->TopOffset()); | 748 EXPECT_EQ(kDiv1Size, child3->TopOffset()); |
749 | 749 |
750 // clear: right; | 750 // clear: right; |
751 div3_style->setClear(EClear::ClearRight); | 751 div3_style->setClear(EClear::ClearRight); |
752 space = ConstructConstraintSpace( | 752 space = ConstructConstraintSpace( |
753 HorizontalTopBottom, LTR, | 753 kHorizontalTopBottom, LTR, |
754 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); | 754 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); |
755 frag = RunBlockLayoutAlgorithm(space, div1); | 755 frag = RunBlockLayoutAlgorithm(space, div1); |
756 child3 = frag->Children()[2]; | 756 child3 = frag->Children()[2]; |
757 EXPECT_EQ(kDiv1Size + kDiv2Size, child3->TopOffset()); | 757 EXPECT_EQ(kDiv1Size + kDiv2Size, child3->TopOffset()); |
758 | 758 |
759 // clear: both; | 759 // clear: both; |
760 div3_style->setClear(EClear::ClearBoth); | 760 div3_style->setClear(EClear::ClearBoth); |
761 space = ConstructConstraintSpace( | 761 space = ConstructConstraintSpace( |
762 HorizontalTopBottom, LTR, | 762 kHorizontalTopBottom, LTR, |
763 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); | 763 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); |
764 frag = RunBlockLayoutAlgorithm(space, div1); | 764 frag = RunBlockLayoutAlgorithm(space, div1); |
765 space = ConstructConstraintSpace( | 765 space = ConstructConstraintSpace( |
766 HorizontalTopBottom, LTR, | 766 kHorizontalTopBottom, LTR, |
767 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); | 767 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); |
768 child3 = frag->Children()[2]; | 768 child3 = frag->Children()[2]; |
769 EXPECT_EQ(kDiv1Size + kDiv2Size, child3->TopOffset()); | 769 EXPECT_EQ(kDiv1Size + kDiv2Size, child3->TopOffset()); |
770 } | 770 } |
771 | 771 |
772 } // namespace | 772 } // namespace |
773 } // namespace blink | 773 } // namespace blink |
OLD | NEW |