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 class NGBlockLayoutAlgorithmTest : public ::testing::Test { | 18 class NGBlockLayoutAlgorithmTest : public ::testing::Test { |
19 protected: | 19 protected: |
20 void SetUp() override { style_ = ComputedStyle::create(); } | 20 void SetUp() override { style_ = ComputedStyle::create(); } |
21 | 21 |
22 NGPhysicalFragment* RunBlockLayoutAlgorithm(const NGConstraintSpace* space, | 22 NGPhysicalFragment* RunBlockLayoutAlgorithm(const NGConstraintSpace* space, |
23 NGBox* first_child) { | 23 NGBox* first_child) { |
24 NGBlockLayoutAlgorithm algorithm(style_, first_child); | 24 NGBlockLayoutAlgorithm algorithm(style_, first_child); |
25 NGPhysicalFragment* frag; | 25 NGPhysicalFragment* frag; |
26 while (!algorithm.Layout(space, &frag)) | 26 while (!algorithm.Layout(*space, &frag)) |
27 continue; | 27 continue; |
28 return frag; | 28 return frag; |
29 } | 29 } |
30 | 30 |
31 RefPtr<ComputedStyle> style_; | 31 RefPtr<ComputedStyle> style_; |
32 }; | 32 }; |
33 | 33 |
34 TEST_F(NGBlockLayoutAlgorithmTest, FixedSize) { | 34 TEST_F(NGBlockLayoutAlgorithmTest, FixedSize) { |
35 style_->setWidth(Length(30, Fixed)); | 35 style_->setWidth(Length(30, Fixed)); |
36 style_->setHeight(Length(40, Fixed)); | 36 style_->setHeight(Length(40, Fixed)); |
37 | 37 |
38 auto* space = | 38 auto* space = |
39 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 39 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, |
40 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 40 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
41 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, nullptr); | 41 std::unique_ptr<NGPhysicalFragment> frag( |
| 42 RunBlockLayoutAlgorithm(space, nullptr)); |
42 | 43 |
43 EXPECT_EQ(LayoutUnit(30), frag->Width()); | 44 EXPECT_EQ(LayoutUnit(30), frag->Width()); |
44 EXPECT_EQ(LayoutUnit(40), frag->Height()); | 45 EXPECT_EQ(LayoutUnit(40), frag->Height()); |
45 } | 46 } |
46 | 47 |
47 // Verifies that two children are laid out with the correct size and position. | 48 // Verifies that two children are laid out with the correct size and position. |
48 TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildren) { | 49 TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildren) { |
49 const int kWidth = 30; | 50 const int kWidth = 30; |
50 const int kHeight1 = 20; | 51 const int kHeight1 = 20; |
51 const int kHeight2 = 30; | 52 const int kHeight2 = 30; |
52 const int kMarginTop = 5; | 53 const int kMarginTop = 5; |
53 const int kMarginBottom = 20; | 54 const int kMarginBottom = 20; |
54 style_->setWidth(Length(kWidth, Fixed)); | 55 style_->setWidth(Length(kWidth, Fixed)); |
55 | 56 |
56 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); | 57 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); |
57 first_style->setHeight(Length(kHeight1, Fixed)); | 58 first_style->setHeight(Length(kHeight1, Fixed)); |
58 NGBox* first_child = new NGBox(first_style.get()); | 59 NGBox* first_child = new NGBox(first_style.get()); |
59 | 60 |
60 RefPtr<ComputedStyle> second_style = ComputedStyle::create(); | 61 RefPtr<ComputedStyle> second_style = ComputedStyle::create(); |
61 second_style->setHeight(Length(kHeight2, Fixed)); | 62 second_style->setHeight(Length(kHeight2, Fixed)); |
62 second_style->setMarginTop(Length(kMarginTop, Fixed)); | 63 second_style->setMarginTop(Length(kMarginTop, Fixed)); |
63 second_style->setMarginBottom(Length(kMarginBottom, Fixed)); | 64 second_style->setMarginBottom(Length(kMarginBottom, Fixed)); |
64 NGBox* second_child = new NGBox(second_style.get()); | 65 NGBox* second_child = new NGBox(second_style.get()); |
65 | 66 |
66 first_child->SetNextSibling(second_child); | 67 first_child->SetNextSibling(second_child); |
67 | 68 |
68 auto* space = | 69 auto* space = |
69 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 70 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, |
70 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 71 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
71 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); | 72 std::unique_ptr<NGPhysicalFragment> frag( |
| 73 RunBlockLayoutAlgorithm(space, first_child)); |
72 | 74 |
73 EXPECT_EQ(LayoutUnit(kWidth), frag->Width()); | 75 EXPECT_EQ(LayoutUnit(kWidth), frag->Width()); |
74 EXPECT_EQ(LayoutUnit(kHeight1 + kHeight2 + kMarginTop), frag->Height()); | 76 EXPECT_EQ(LayoutUnit(kHeight1 + kHeight2 + kMarginTop), frag->Height()); |
75 EXPECT_EQ(NGPhysicalFragmentBase::FragmentBox, frag->Type()); | 77 EXPECT_EQ(NGPhysicalFragmentBase::FragmentBox, frag->Type()); |
76 ASSERT_EQ(frag->Children().size(), 2UL); | 78 ASSERT_EQ(frag->Children().size(), 2UL); |
77 | 79 |
78 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 80 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
79 EXPECT_EQ(kHeight1, child->Height()); | 81 EXPECT_EQ(kHeight1, child->Height()); |
80 EXPECT_EQ(0, child->TopOffset()); | 82 EXPECT_EQ(0, child->TopOffset()); |
81 | 83 |
(...skipping 25 matching lines...) Expand all Loading... |
107 div2_style->setWidth(Length(kWidth, Fixed)); | 109 div2_style->setWidth(Length(kWidth, Fixed)); |
108 div1_style->setWritingMode(TopToBottomWritingMode); | 110 div1_style->setWritingMode(TopToBottomWritingMode); |
109 div2_style->setMarginLeft(Length(kMarginLeft, Fixed)); | 111 div2_style->setMarginLeft(Length(kMarginLeft, Fixed)); |
110 NGBox* div2 = new NGBox(div2_style.get()); | 112 NGBox* div2 = new NGBox(div2_style.get()); |
111 | 113 |
112 div1->SetFirstChild(div2); | 114 div1->SetFirstChild(div2); |
113 | 115 |
114 auto* space = | 116 auto* space = |
115 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 117 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, |
116 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); | 118 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); |
117 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 119 std::unique_ptr<NGPhysicalFragment> frag( |
| 120 RunBlockLayoutAlgorithm(space, div1)); |
118 | 121 |
119 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 122 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
120 // DIV2 | 123 // DIV2 |
121 child = static_cast<const NGPhysicalFragment*>(child)->Children()[0]; | 124 child = static_cast<const NGPhysicalFragment*>(child)->Children()[0]; |
122 | 125 |
123 EXPECT_EQ(kHeight, child->Height()); | 126 EXPECT_EQ(kHeight, child->Height()); |
124 EXPECT_EQ(0, child->TopOffset()); | 127 EXPECT_EQ(0, child->TopOffset()); |
125 EXPECT_EQ(kMarginLeft, child->LeftOffset()); | 128 EXPECT_EQ(kMarginLeft, child->LeftOffset()); |
126 } | 129 } |
127 | 130 |
(...skipping 22 matching lines...) Expand all Loading... |
150 // DIV2 | 153 // DIV2 |
151 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 154 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
152 div2_style->setMarginTop(Length(kDiv2MarginTop, Fixed)); | 155 div2_style->setMarginTop(Length(kDiv2MarginTop, Fixed)); |
153 NGBox* div2 = new NGBox(div2_style.get()); | 156 NGBox* div2 = new NGBox(div2_style.get()); |
154 | 157 |
155 div1->SetFirstChild(div2); | 158 div1->SetFirstChild(div2); |
156 | 159 |
157 auto* space = | 160 auto* space = |
158 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 161 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, |
159 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 162 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
160 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 163 std::unique_ptr<NGPhysicalFragment> frag( |
| 164 RunBlockLayoutAlgorithm(space, div1)); |
161 | 165 |
162 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv1MarginTop)}), frag->MarginStrut()); | 166 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv1MarginTop)}), frag->MarginStrut()); |
163 ASSERT_EQ(frag->Children().size(), 1UL); | 167 ASSERT_EQ(frag->Children().size(), 1UL); |
164 const NGPhysicalFragmentBase* div2_fragment = frag->Children()[0]; | 168 const NGPhysicalFragmentBase* div2_fragment = frag->Children()[0]; |
165 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2MarginTop)}), | 169 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2MarginTop)}), |
166 div2_fragment->MarginStrut()); | 170 div2_fragment->MarginStrut()); |
167 EXPECT_EQ(kDiv1MarginTop, div2_fragment->TopOffset()); | 171 EXPECT_EQ(kDiv1MarginTop, div2_fragment->TopOffset()); |
168 } | 172 } |
169 | 173 |
170 // Verifies the collapsing margins case for the next pair: | 174 // Verifies the collapsing margins case for the next pair: |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 div1->SetFirstChild(div2); | 227 div1->SetFirstChild(div2); |
224 div2->SetNextSibling(div3); | 228 div2->SetNextSibling(div3); |
225 div1->SetNextSibling(div4); | 229 div1->SetNextSibling(div4); |
226 div4->SetNextSibling(div5); | 230 div4->SetNextSibling(div5); |
227 div5->SetFirstChild(div6); | 231 div5->SetFirstChild(div6); |
228 div6->SetNextSibling(div7); | 232 div6->SetNextSibling(div7); |
229 | 233 |
230 auto* space = | 234 auto* space = |
231 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 235 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, |
232 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 236 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
233 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 237 std::unique_ptr<NGPhysicalFragment> frag( |
| 238 RunBlockLayoutAlgorithm(space, div1)); |
234 | 239 |
235 ASSERT_EQ(frag->Children().size(), 3UL); | 240 ASSERT_EQ(frag->Children().size(), 3UL); |
236 | 241 |
237 // DIV1 | 242 // DIV1 |
238 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 243 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
239 EXPECT_EQ(kHeight, child->Height()); | 244 EXPECT_EQ(kHeight, child->Height()); |
240 EXPECT_EQ(0, child->TopOffset()); | 245 EXPECT_EQ(0, child->TopOffset()); |
241 | 246 |
242 // DIV5 | 247 // DIV5 |
243 child = frag->Children()[2]; | 248 child = frag->Children()[2]; |
(...skipping 28 matching lines...) Expand all Loading... |
272 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 277 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
273 div2_style->setHeight(Length(kHeight, Fixed)); | 278 div2_style->setHeight(Length(kHeight, Fixed)); |
274 div2_style->setMarginBottom(Length(kDiv2MarginBottom, Fixed)); | 279 div2_style->setMarginBottom(Length(kDiv2MarginBottom, Fixed)); |
275 NGBox* div2 = new NGBox(div2_style.get()); | 280 NGBox* div2 = new NGBox(div2_style.get()); |
276 | 281 |
277 div1->SetFirstChild(div2); | 282 div1->SetFirstChild(div2); |
278 | 283 |
279 auto* space = | 284 auto* space = |
280 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 285 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, |
281 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 286 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
282 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 287 std::unique_ptr<NGPhysicalFragment> frag( |
| 288 RunBlockLayoutAlgorithm(space, div1)); |
283 | 289 |
284 // Verify that margins are collapsed. | 290 // Verify that margins are collapsed. |
285 EXPECT_EQ(NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv2MarginBottom)}), | 291 EXPECT_EQ(NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv2MarginBottom)}), |
286 frag->MarginStrut()); | 292 frag->MarginStrut()); |
287 | 293 |
288 // Verify that margins are NOT collapsed. | 294 // Verify that margins are NOT collapsed. |
289 div1_style->setHeight(Length(kHeight, Fixed)); | 295 div1_style->setHeight(Length(kHeight, Fixed)); |
290 frag = RunBlockLayoutAlgorithm(space, div1); | 296 frag.reset(RunBlockLayoutAlgorithm(space, div1)); |
291 EXPECT_EQ(NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv1MarginBottom)}), | 297 EXPECT_EQ(NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv1MarginBottom)}), |
292 frag->MarginStrut()); | 298 frag->MarginStrut()); |
293 } | 299 } |
294 | 300 |
295 // Verifies that 2 adjoining margins are not collapsed if there is padding or | 301 // Verifies that 2 adjoining margins are not collapsed if there is padding or |
296 // border that separates them. | 302 // border that separates them. |
297 // | 303 // |
298 // Test case's HTML representation: | 304 // Test case's HTML representation: |
299 // <div style="margin: 30px 0px; padding: 20px 0px;"> <!-- DIV1 --> | 305 // <div style="margin: 30px 0px; padding: 20px 0px;"> <!-- DIV1 --> |
300 // <div style="margin: 200px 0px; height: 50px;"/> <!-- DIV2 --> | 306 // <div style="margin: 200px 0px; height: 50px;"/> <!-- DIV2 --> |
(...skipping 20 matching lines...) Expand all Loading... |
321 div2_style->setHeight(Length(kHeight, Fixed)); | 327 div2_style->setHeight(Length(kHeight, Fixed)); |
322 div2_style->setMarginTop(Length(kDiv2Margin, Fixed)); | 328 div2_style->setMarginTop(Length(kDiv2Margin, Fixed)); |
323 div2_style->setMarginBottom(Length(kDiv2Margin, Fixed)); | 329 div2_style->setMarginBottom(Length(kDiv2Margin, Fixed)); |
324 NGBox* div2 = new NGBox(div2_style.get()); | 330 NGBox* div2 = new NGBox(div2_style.get()); |
325 | 331 |
326 div1->SetFirstChild(div2); | 332 div1->SetFirstChild(div2); |
327 | 333 |
328 auto* space = | 334 auto* space = |
329 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 335 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, |
330 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 336 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
331 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 337 std::unique_ptr<NGPhysicalFragment> frag( |
| 338 RunBlockLayoutAlgorithm(space, div1)); |
332 | 339 |
333 // Verify that margins do NOT collapse. | 340 // Verify that margins do NOT collapse. |
334 frag = RunBlockLayoutAlgorithm(space, div1); | |
335 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv1Margin), LayoutUnit(kDiv1Margin)}), | 341 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv1Margin), LayoutUnit(kDiv1Margin)}), |
336 frag->MarginStrut()); | 342 frag->MarginStrut()); |
337 ASSERT_EQ(frag->Children().size(), 1UL); | 343 ASSERT_EQ(frag->Children().size(), 1UL); |
338 | 344 |
339 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2Margin), LayoutUnit(kDiv2Margin)}), | 345 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2Margin), LayoutUnit(kDiv2Margin)}), |
340 frag->Children()[0]->MarginStrut()); | 346 frag->Children()[0]->MarginStrut()); |
341 | 347 |
342 // Reset padding and verify that margins DO collapse. | 348 // Reset padding and verify that margins DO collapse. |
343 div1_style->setPaddingTop(Length(0, Fixed)); | 349 div1_style->setPaddingTop(Length(0, Fixed)); |
344 div1_style->setPaddingBottom(Length(0, Fixed)); | 350 div1_style->setPaddingBottom(Length(0, Fixed)); |
345 frag = RunBlockLayoutAlgorithm(space, div1); | 351 frag.reset(RunBlockLayoutAlgorithm(space, div1)); |
346 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2Margin), LayoutUnit(kDiv2Margin)}), | 352 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2Margin), LayoutUnit(kDiv2Margin)}), |
347 frag->MarginStrut()); | 353 frag->MarginStrut()); |
348 } | 354 } |
349 | 355 |
350 // Verifies that margins of 2 adjoining blocks with different writing modes | 356 // Verifies that margins of 2 adjoining blocks with different writing modes |
351 // get collapsed. | 357 // get collapsed. |
352 // | 358 // |
353 // Test case's HTML representation: | 359 // Test case's HTML representation: |
354 // <div style="writing-mode: vertical-lr;"> | 360 // <div style="writing-mode: vertical-lr;"> |
355 // <div style="margin-right: 60px; width: 60px;">vertical</div> | 361 // <div style="margin-right: 60px; width: 60px;">vertical</div> |
(...skipping 20 matching lines...) Expand all Loading... |
376 RefPtr<ComputedStyle> horizontal_style = ComputedStyle::create(); | 382 RefPtr<ComputedStyle> horizontal_style = ComputedStyle::create(); |
377 horizontal_style->setMarginLeft(Length(kHorizontalDivMarginLeft, Fixed)); | 383 horizontal_style->setMarginLeft(Length(kHorizontalDivMarginLeft, Fixed)); |
378 horizontal_style->setWritingMode(TopToBottomWritingMode); | 384 horizontal_style->setWritingMode(TopToBottomWritingMode); |
379 NGBox* horizontal_div = new NGBox(horizontal_style.get()); | 385 NGBox* horizontal_div = new NGBox(horizontal_style.get()); |
380 | 386 |
381 vertical_div->SetNextSibling(horizontal_div); | 387 vertical_div->SetNextSibling(horizontal_div); |
382 | 388 |
383 auto* space = | 389 auto* space = |
384 new NGConstraintSpace(VerticalLeftRight, LeftToRight, | 390 new NGConstraintSpace(VerticalLeftRight, LeftToRight, |
385 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); | 391 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); |
386 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, vertical_div); | 392 std::unique_ptr<NGPhysicalFragment> frag( |
| 393 RunBlockLayoutAlgorithm(space, vertical_div)); |
387 | 394 |
388 ASSERT_EQ(frag->Children().size(), 2UL); | 395 ASSERT_EQ(frag->Children().size(), 2UL); |
389 const NGPhysicalFragmentBase* child = frag->Children()[1]; | 396 const NGPhysicalFragmentBase* child = frag->Children()[1]; |
390 // Horizontal div | 397 // Horizontal div |
391 EXPECT_EQ(0, child->TopOffset()); | 398 EXPECT_EQ(0, child->TopOffset()); |
392 EXPECT_EQ(kVerticalDivWidth + kHorizontalDivMarginLeft, child->LeftOffset()); | 399 EXPECT_EQ(kVerticalDivWidth + kHorizontalDivMarginLeft, child->LeftOffset()); |
393 } | 400 } |
394 | 401 |
395 // Verifies that a box's size includes its borders and padding, and that | 402 // Verifies that a box's size includes its borders and padding, and that |
396 // children are positioned inside the content box. | 403 // children are positioned inside the content box. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 NGBox* div1 = new NGBox(div1_style.get()); | 443 NGBox* div1 = new NGBox(div1_style.get()); |
437 | 444 |
438 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 445 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
439 NGBox* div2 = new NGBox(div2_style.get()); | 446 NGBox* div2 = new NGBox(div2_style.get()); |
440 | 447 |
441 div1->SetFirstChild(div2); | 448 div1->SetFirstChild(div2); |
442 | 449 |
443 auto* space = | 450 auto* space = |
444 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 451 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, |
445 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); | 452 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); |
446 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 453 std::unique_ptr<NGPhysicalFragment> frag( |
| 454 RunBlockLayoutAlgorithm(space, div1)); |
447 | 455 |
448 ASSERT_EQ(frag->Children().size(), 1UL); | 456 ASSERT_EQ(frag->Children().size(), 1UL); |
449 | 457 |
450 // div1 | 458 // div1 |
451 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 459 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
452 EXPECT_EQ(kBorderLeft + kPaddingLeft + kWidth + kPaddingRight + kBorderRight, | 460 EXPECT_EQ(kBorderLeft + kPaddingLeft + kWidth + kPaddingRight + kBorderRight, |
453 child->Width()); | 461 child->Width()); |
454 EXPECT_EQ(kBorderTop + kPaddingTop + kHeight + kPaddingBottom + kBorderBottom, | 462 EXPECT_EQ(kBorderTop + kPaddingTop + kHeight + kPaddingBottom + kBorderBottom, |
455 child->Height()); | 463 child->Height()); |
456 | 464 |
(...skipping 13 matching lines...) Expand all Loading... |
470 style_->setWidth(Length(kWidth, Fixed)); | 478 style_->setWidth(Length(kWidth, Fixed)); |
471 style_->setPaddingLeft(Length(kPaddingLeft, Fixed)); | 479 style_->setPaddingLeft(Length(kPaddingLeft, Fixed)); |
472 | 480 |
473 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); | 481 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); |
474 first_style->setWidth(Length(40, Percent)); | 482 first_style->setWidth(Length(40, Percent)); |
475 NGBox* first_child = new NGBox(first_style.get()); | 483 NGBox* first_child = new NGBox(first_style.get()); |
476 | 484 |
477 auto* space = | 485 auto* space = |
478 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 486 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, |
479 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 487 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
480 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); | 488 std::unique_ptr<NGPhysicalFragment> frag( |
| 489 RunBlockLayoutAlgorithm(space, first_child)); |
481 | 490 |
482 EXPECT_EQ(frag->Width(), LayoutUnit(kWidth + kPaddingLeft)); | 491 EXPECT_EQ(frag->Width(), LayoutUnit(kWidth + kPaddingLeft)); |
483 EXPECT_EQ(frag->Type(), NGPhysicalFragmentBase::FragmentBox); | 492 EXPECT_EQ(frag->Type(), NGPhysicalFragmentBase::FragmentBox); |
484 ASSERT_EQ(frag->Children().size(), 1UL); | 493 ASSERT_EQ(frag->Children().size(), 1UL); |
485 | 494 |
486 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 495 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
487 EXPECT_EQ(child->Width(), LayoutUnit(12)); | 496 EXPECT_EQ(child->Width(), LayoutUnit(12)); |
488 } | 497 } |
489 } // namespace | 498 } // namespace |
490 } // namespace blink | 499 } // namespace blink |
OLD | NEW |