| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 } | 50 } |
| 51 | 51 |
| 52 RefPtr<ComputedStyle> style_; | 52 RefPtr<ComputedStyle> style_; |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 TEST_F(NGBlockLayoutAlgorithmTest, FixedSize) { | 55 TEST_F(NGBlockLayoutAlgorithmTest, FixedSize) { |
| 56 style_->setWidth(Length(30, Fixed)); | 56 style_->setWidth(Length(30, Fixed)); |
| 57 style_->setHeight(Length(40, Fixed)); | 57 style_->setHeight(Length(40, Fixed)); |
| 58 | 58 |
| 59 auto* space = ConstructConstraintSpace( | 59 auto* space = ConstructConstraintSpace( |
| 60 kHorizontalTopBottom, LTR, | 60 kHorizontalTopBottom, TextDirection::Ltr, |
| 61 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 61 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
| 62 NGPhysicalFragmentBase* frag = RunBlockLayoutAlgorithm(space, nullptr); | 62 NGPhysicalFragmentBase* frag = RunBlockLayoutAlgorithm(space, nullptr); |
| 63 | 63 |
| 64 EXPECT_EQ(LayoutUnit(30), frag->Width()); | 64 EXPECT_EQ(LayoutUnit(30), frag->Width()); |
| 65 EXPECT_EQ(LayoutUnit(40), frag->Height()); | 65 EXPECT_EQ(LayoutUnit(40), frag->Height()); |
| 66 } | 66 } |
| 67 | 67 |
| 68 // Verifies that two children are laid out with the correct size and position. | 68 // Verifies that two children are laid out with the correct size and position. |
| 69 TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildren) { | 69 TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildren) { |
| 70 const int kWidth = 30; | 70 const int kWidth = 30; |
| 71 const int kHeight1 = 20; | 71 const int kHeight1 = 20; |
| 72 const int kHeight2 = 30; | 72 const int kHeight2 = 30; |
| 73 const int kMarginTop = 5; | 73 const int kMarginTop = 5; |
| 74 const int kMarginBottom = 20; | 74 const int kMarginBottom = 20; |
| 75 style_->setWidth(Length(kWidth, Fixed)); | 75 style_->setWidth(Length(kWidth, Fixed)); |
| 76 | 76 |
| 77 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); | 77 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); |
| 78 first_style->setHeight(Length(kHeight1, Fixed)); | 78 first_style->setHeight(Length(kHeight1, Fixed)); |
| 79 NGBlockNode* first_child = new NGBlockNode(first_style.get()); | 79 NGBlockNode* first_child = new NGBlockNode(first_style.get()); |
| 80 | 80 |
| 81 RefPtr<ComputedStyle> second_style = ComputedStyle::create(); | 81 RefPtr<ComputedStyle> second_style = ComputedStyle::create(); |
| 82 second_style->setHeight(Length(kHeight2, Fixed)); | 82 second_style->setHeight(Length(kHeight2, Fixed)); |
| 83 second_style->setMarginTop(Length(kMarginTop, Fixed)); | 83 second_style->setMarginTop(Length(kMarginTop, Fixed)); |
| 84 second_style->setMarginBottom(Length(kMarginBottom, Fixed)); | 84 second_style->setMarginBottom(Length(kMarginBottom, Fixed)); |
| 85 NGBlockNode* second_child = new NGBlockNode(second_style.get()); | 85 NGBlockNode* second_child = new NGBlockNode(second_style.get()); |
| 86 | 86 |
| 87 first_child->SetNextSibling(second_child); | 87 first_child->SetNextSibling(second_child); |
| 88 | 88 |
| 89 auto* space = ConstructConstraintSpace( | 89 auto* space = ConstructConstraintSpace( |
| 90 kHorizontalTopBottom, LTR, | 90 kHorizontalTopBottom, TextDirection::Ltr, |
| 91 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 91 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
| 92 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); | 92 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); |
| 93 | 93 |
| 94 EXPECT_EQ(LayoutUnit(kWidth), frag->Width()); | 94 EXPECT_EQ(LayoutUnit(kWidth), frag->Width()); |
| 95 EXPECT_EQ(LayoutUnit(kHeight1 + kHeight2 + kMarginTop), frag->Height()); | 95 EXPECT_EQ(LayoutUnit(kHeight1 + kHeight2 + kMarginTop), frag->Height()); |
| 96 EXPECT_EQ(NGPhysicalFragmentBase::kFragmentBox, frag->Type()); | 96 EXPECT_EQ(NGPhysicalFragmentBase::kFragmentBox, frag->Type()); |
| 97 ASSERT_EQ(frag->Children().size(), 2UL); | 97 ASSERT_EQ(frag->Children().size(), 2UL); |
| 98 | 98 |
| 99 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 99 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
| 100 EXPECT_EQ(kHeight1, child->Height()); | 100 EXPECT_EQ(kHeight1, child->Height()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 126 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 126 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
| 127 div2_style->setHeight(Length(kHeight, Fixed)); | 127 div2_style->setHeight(Length(kHeight, Fixed)); |
| 128 div2_style->setWidth(Length(kWidth, Fixed)); | 128 div2_style->setWidth(Length(kWidth, Fixed)); |
| 129 div1_style->setWritingMode(TopToBottomWritingMode); | 129 div1_style->setWritingMode(TopToBottomWritingMode); |
| 130 div2_style->setMarginLeft(Length(kMarginLeft, Fixed)); | 130 div2_style->setMarginLeft(Length(kMarginLeft, Fixed)); |
| 131 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); | 131 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); |
| 132 | 132 |
| 133 div1->SetFirstChild(div2); | 133 div1->SetFirstChild(div2); |
| 134 | 134 |
| 135 auto* space = | 135 auto* space = |
| 136 ConstructConstraintSpace(kHorizontalTopBottom, LTR, | 136 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::Ltr, |
| 137 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); | 137 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); |
| 138 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 138 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
| 139 | 139 |
| 140 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 140 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
| 141 // DIV2 | 141 // DIV2 |
| 142 child = static_cast<const NGPhysicalFragment*>(child)->Children()[0]; | 142 child = static_cast<const NGPhysicalFragment*>(child)->Children()[0]; |
| 143 | 143 |
| 144 EXPECT_EQ(kHeight, child->Height()); | 144 EXPECT_EQ(kHeight, child->Height()); |
| 145 EXPECT_EQ(0, child->TopOffset()); | 145 EXPECT_EQ(0, child->TopOffset()); |
| 146 EXPECT_EQ(kMarginLeft, child->LeftOffset()); | 146 EXPECT_EQ(kMarginLeft, child->LeftOffset()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 174 div2_style->setMarginTop(Length(kDiv2MarginTop, Fixed)); | 174 div2_style->setMarginTop(Length(kDiv2MarginTop, Fixed)); |
| 175 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); | 175 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); |
| 176 | 176 |
| 177 div1->SetFirstChild(div2); | 177 div1->SetFirstChild(div2); |
| 178 | 178 |
| 179 auto* space = | 179 auto* space = |
| 180 NGConstraintSpaceBuilder(kHorizontalTopBottom) | 180 NGConstraintSpaceBuilder(kHorizontalTopBottom) |
| 181 .SetAvailableSize(NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)) | 181 .SetAvailableSize(NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)) |
| 182 .SetPercentageResolutionSize( | 182 .SetPercentageResolutionSize( |
| 183 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)) | 183 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)) |
| 184 .SetTextDirection(LTR) | 184 .SetTextDirection(TextDirection::Ltr) |
| 185 .SetIsNewFormattingContext(true) | 185 .SetIsNewFormattingContext(true) |
| 186 .ToConstraintSpace(); | 186 .ToConstraintSpace(); |
| 187 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 187 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
| 188 | 188 |
| 189 EXPECT_TRUE(frag->MarginStrut().IsEmpty()); | 189 EXPECT_TRUE(frag->MarginStrut().IsEmpty()); |
| 190 ASSERT_EQ(frag->Children().size(), 1UL); | 190 ASSERT_EQ(frag->Children().size(), 1UL); |
| 191 const NGPhysicalFragment* div2_fragment = | 191 const NGPhysicalFragment* div2_fragment = |
| 192 static_cast<const NGPhysicalFragment*>(frag->Children()[0].get()); | 192 static_cast<const NGPhysicalFragment*>(frag->Children()[0].get()); |
| 193 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2MarginTop)}), | 193 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2MarginTop)}), |
| 194 div2_fragment->MarginStrut()); | 194 div2_fragment->MarginStrut()); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 NGBlockNode* div7 = new NGBlockNode(div7_style.get()); | 249 NGBlockNode* div7 = new NGBlockNode(div7_style.get()); |
| 250 | 250 |
| 251 div1->SetFirstChild(div2); | 251 div1->SetFirstChild(div2); |
| 252 div2->SetNextSibling(div3); | 252 div2->SetNextSibling(div3); |
| 253 div1->SetNextSibling(div4); | 253 div1->SetNextSibling(div4); |
| 254 div4->SetNextSibling(div5); | 254 div4->SetNextSibling(div5); |
| 255 div5->SetFirstChild(div6); | 255 div5->SetFirstChild(div6); |
| 256 div6->SetNextSibling(div7); | 256 div6->SetNextSibling(div7); |
| 257 | 257 |
| 258 auto* space = ConstructConstraintSpace( | 258 auto* space = ConstructConstraintSpace( |
| 259 kHorizontalTopBottom, LTR, | 259 kHorizontalTopBottom, TextDirection::Ltr, |
| 260 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 260 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
| 261 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 261 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
| 262 | 262 |
| 263 ASSERT_EQ(frag->Children().size(), 3UL); | 263 ASSERT_EQ(frag->Children().size(), 3UL); |
| 264 | 264 |
| 265 // DIV1 | 265 // DIV1 |
| 266 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 266 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
| 267 EXPECT_EQ(kHeight, child->Height()); | 267 EXPECT_EQ(kHeight, child->Height()); |
| 268 EXPECT_EQ(0, child->TopOffset()); | 268 EXPECT_EQ(0, child->TopOffset()); |
| 269 | 269 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 298 | 298 |
| 299 // DIV2 | 299 // DIV2 |
| 300 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 300 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
| 301 div2_style->setHeight(Length(kHeight, Fixed)); | 301 div2_style->setHeight(Length(kHeight, Fixed)); |
| 302 div2_style->setMarginBottom(Length(kDiv2MarginBottom, Fixed)); | 302 div2_style->setMarginBottom(Length(kDiv2MarginBottom, Fixed)); |
| 303 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); | 303 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); |
| 304 | 304 |
| 305 div1->SetFirstChild(div2); | 305 div1->SetFirstChild(div2); |
| 306 | 306 |
| 307 auto* space = ConstructConstraintSpace( | 307 auto* space = ConstructConstraintSpace( |
| 308 kHorizontalTopBottom, LTR, | 308 kHorizontalTopBottom, TextDirection::Ltr, |
| 309 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 309 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
| 310 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 310 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
| 311 | 311 |
| 312 // Verify that margins are collapsed. | 312 // Verify that margins are collapsed. |
| 313 EXPECT_EQ(NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv2MarginBottom)}), | 313 EXPECT_EQ(NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv2MarginBottom)}), |
| 314 frag->MarginStrut()); | 314 frag->MarginStrut()); |
| 315 | 315 |
| 316 // Verify that margins are NOT collapsed. | 316 // Verify that margins are NOT collapsed. |
| 317 div1_style->setHeight(Length(kHeight, Fixed)); | 317 div1_style->setHeight(Length(kHeight, Fixed)); |
| 318 frag = RunBlockLayoutAlgorithm(space, div1); | 318 frag = RunBlockLayoutAlgorithm(space, div1); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 347 // DIV2 | 347 // DIV2 |
| 348 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 348 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
| 349 div2_style->setHeight(Length(kHeight, Fixed)); | 349 div2_style->setHeight(Length(kHeight, Fixed)); |
| 350 div2_style->setMarginTop(Length(kDiv2Margin, Fixed)); | 350 div2_style->setMarginTop(Length(kDiv2Margin, Fixed)); |
| 351 div2_style->setMarginBottom(Length(kDiv2Margin, Fixed)); | 351 div2_style->setMarginBottom(Length(kDiv2Margin, Fixed)); |
| 352 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); | 352 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); |
| 353 | 353 |
| 354 div1->SetFirstChild(div2); | 354 div1->SetFirstChild(div2); |
| 355 | 355 |
| 356 auto* space = ConstructConstraintSpace( | 356 auto* space = ConstructConstraintSpace( |
| 357 kHorizontalTopBottom, LTR, | 357 kHorizontalTopBottom, TextDirection::Ltr, |
| 358 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 358 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
| 359 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 359 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
| 360 | 360 |
| 361 // Verify that margins do NOT collapse. | 361 // Verify that margins do NOT collapse. |
| 362 frag = RunBlockLayoutAlgorithm(space, div1); | 362 frag = RunBlockLayoutAlgorithm(space, div1); |
| 363 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv1Margin), LayoutUnit(kDiv1Margin)}), | 363 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv1Margin), LayoutUnit(kDiv1Margin)}), |
| 364 frag->MarginStrut()); | 364 frag->MarginStrut()); |
| 365 ASSERT_EQ(frag->Children().size(), 1UL); | 365 ASSERT_EQ(frag->Children().size(), 1UL); |
| 366 | 366 |
| 367 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2Margin), LayoutUnit(kDiv2Margin)}), | 367 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2Margin), LayoutUnit(kDiv2Margin)}), |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 NGBlockNode* vertical_div = new NGBlockNode(vertical_style.get()); | 402 NGBlockNode* vertical_div = new NGBlockNode(vertical_style.get()); |
| 403 | 403 |
| 404 // Horizontal DIV | 404 // Horizontal DIV |
| 405 RefPtr<ComputedStyle> horizontal_style = ComputedStyle::create(); | 405 RefPtr<ComputedStyle> horizontal_style = ComputedStyle::create(); |
| 406 horizontal_style->setMarginLeft(Length(kHorizontalDivMarginLeft, Fixed)); | 406 horizontal_style->setMarginLeft(Length(kHorizontalDivMarginLeft, Fixed)); |
| 407 horizontal_style->setWritingMode(TopToBottomWritingMode); | 407 horizontal_style->setWritingMode(TopToBottomWritingMode); |
| 408 NGBlockNode* horizontal_div = new NGBlockNode(horizontal_style.get()); | 408 NGBlockNode* horizontal_div = new NGBlockNode(horizontal_style.get()); |
| 409 | 409 |
| 410 vertical_div->SetNextSibling(horizontal_div); | 410 vertical_div->SetNextSibling(horizontal_div); |
| 411 | 411 |
| 412 auto* space = ConstructConstraintSpace( | 412 auto* space = |
| 413 kVerticalLeftRight, LTR, NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); | 413 ConstructConstraintSpace(kVerticalLeftRight, TextDirection::Ltr, |
| 414 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); |
| 414 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, vertical_div); | 415 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, vertical_div); |
| 415 | 416 |
| 416 ASSERT_EQ(frag->Children().size(), 2UL); | 417 ASSERT_EQ(frag->Children().size(), 2UL); |
| 417 const NGPhysicalFragmentBase* child = frag->Children()[1]; | 418 const NGPhysicalFragmentBase* child = frag->Children()[1]; |
| 418 // Horizontal div | 419 // Horizontal div |
| 419 EXPECT_EQ(0, child->TopOffset()); | 420 EXPECT_EQ(0, child->TopOffset()); |
| 420 EXPECT_EQ(kVerticalDivWidth + kHorizontalDivMarginLeft, child->LeftOffset()); | 421 EXPECT_EQ(kVerticalDivWidth + kHorizontalDivMarginLeft, child->LeftOffset()); |
| 421 } | 422 } |
| 422 | 423 |
| 423 // Verifies that the margin strut of a child with a different writing mode does | 424 // 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... |
| 460 // DIV3 | 461 // DIV3 |
| 461 RefPtr<ComputedStyle> div3_style = ComputedStyle::create(); | 462 RefPtr<ComputedStyle> div3_style = ComputedStyle::create(); |
| 462 div3_style->setHeight(Length(kHeight, Fixed)); | 463 div3_style->setHeight(Length(kHeight, Fixed)); |
| 463 div3_style->setMarginTop(Length(kMarginTop, Fixed)); | 464 div3_style->setMarginTop(Length(kMarginTop, Fixed)); |
| 464 NGBlockNode* div3 = new NGBlockNode(div3_style.get()); | 465 NGBlockNode* div3 = new NGBlockNode(div3_style.get()); |
| 465 | 466 |
| 466 div1->SetFirstChild(div2); | 467 div1->SetFirstChild(div2); |
| 467 div1->SetNextSibling(div3); | 468 div1->SetNextSibling(div3); |
| 468 | 469 |
| 469 auto* space = | 470 auto* space = |
| 470 ConstructConstraintSpace(kHorizontalTopBottom, LTR, | 471 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::Ltr, |
| 471 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); | 472 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); |
| 472 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 473 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
| 473 | 474 |
| 474 ASSERT_EQ(frag->Children().size(), 2UL); | 475 ASSERT_EQ(frag->Children().size(), 2UL); |
| 475 | 476 |
| 476 const NGPhysicalFragmentBase* child1 = frag->Children()[0]; | 477 const NGPhysicalFragmentBase* child1 = frag->Children()[0]; |
| 477 EXPECT_EQ(0, child1->TopOffset()); | 478 EXPECT_EQ(0, child1->TopOffset()); |
| 478 EXPECT_EQ(kHeight, child1->Height()); | 479 EXPECT_EQ(kHeight, child1->Height()); |
| 479 | 480 |
| 480 const NGPhysicalFragmentBase* child2 = frag->Children()[1]; | 481 const NGPhysicalFragmentBase* child2 = frag->Children()[1]; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 div1_style->setPaddingBottom(Length(kPaddingBottom, Fixed)); | 524 div1_style->setPaddingBottom(Length(kPaddingBottom, Fixed)); |
| 524 div1_style->setPaddingLeft(Length(kPaddingLeft, Fixed)); | 525 div1_style->setPaddingLeft(Length(kPaddingLeft, Fixed)); |
| 525 NGBlockNode* div1 = new NGBlockNode(div1_style.get()); | 526 NGBlockNode* div1 = new NGBlockNode(div1_style.get()); |
| 526 | 527 |
| 527 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 528 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
| 528 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); | 529 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); |
| 529 | 530 |
| 530 div1->SetFirstChild(div2); | 531 div1->SetFirstChild(div2); |
| 531 | 532 |
| 532 auto* space = ConstructConstraintSpace( | 533 auto* space = ConstructConstraintSpace( |
| 533 kHorizontalTopBottom, LTR, | 534 kHorizontalTopBottom, TextDirection::Ltr, |
| 534 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); | 535 NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite)); |
| 535 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 536 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
| 536 | 537 |
| 537 ASSERT_EQ(frag->Children().size(), 1UL); | 538 ASSERT_EQ(frag->Children().size(), 1UL); |
| 538 | 539 |
| 539 // div1 | 540 // div1 |
| 540 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 541 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
| 541 EXPECT_EQ(kBorderLeft + kPaddingLeft + kWidth + kPaddingRight + kBorderRight, | 542 EXPECT_EQ(kBorderLeft + kPaddingLeft + kWidth + kPaddingRight + kBorderRight, |
| 542 child->Width()); | 543 child->Width()); |
| 543 EXPECT_EQ(kBorderTop + kPaddingTop + kHeight + kPaddingBottom + kBorderBottom, | 544 EXPECT_EQ(kBorderTop + kPaddingTop + kHeight + kPaddingBottom + kBorderBottom, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 557 const int kPaddingLeft = 10; | 558 const int kPaddingLeft = 10; |
| 558 const int kWidth = 30; | 559 const int kWidth = 30; |
| 559 style_->setWidth(Length(kWidth, Fixed)); | 560 style_->setWidth(Length(kWidth, Fixed)); |
| 560 style_->setPaddingLeft(Length(kPaddingLeft, Fixed)); | 561 style_->setPaddingLeft(Length(kPaddingLeft, Fixed)); |
| 561 | 562 |
| 562 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); | 563 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); |
| 563 first_style->setWidth(Length(40, Percent)); | 564 first_style->setWidth(Length(40, Percent)); |
| 564 NGBlockNode* first_child = new NGBlockNode(first_style.get()); | 565 NGBlockNode* first_child = new NGBlockNode(first_style.get()); |
| 565 | 566 |
| 566 auto* space = ConstructConstraintSpace( | 567 auto* space = ConstructConstraintSpace( |
| 567 kHorizontalTopBottom, LTR, | 568 kHorizontalTopBottom, TextDirection::Ltr, |
| 568 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 569 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
| 569 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); | 570 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); |
| 570 | 571 |
| 571 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width()); | 572 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width()); |
| 572 EXPECT_EQ(NGPhysicalFragmentBase::kFragmentBox, frag->Type()); | 573 EXPECT_EQ(NGPhysicalFragmentBase::kFragmentBox, frag->Type()); |
| 573 ASSERT_EQ(frag->Children().size(), 1UL); | 574 ASSERT_EQ(frag->Children().size(), 1UL); |
| 574 | 575 |
| 575 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 576 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
| 576 EXPECT_EQ(LayoutUnit(12), child->Width()); | 577 EXPECT_EQ(LayoutUnit(12), child->Width()); |
| 577 } | 578 } |
| 578 | 579 |
| 579 // A very simple auto margin case. We rely on the tests in ng_length_utils_test | 580 // A very simple auto margin case. We rely on the tests in ng_length_utils_test |
| 580 // for the more complex cases; just make sure we handle auto at all here. | 581 // for the more complex cases; just make sure we handle auto at all here. |
| 581 TEST_F(NGBlockLayoutAlgorithmTest, AutoMargin) { | 582 TEST_F(NGBlockLayoutAlgorithmTest, AutoMargin) { |
| 582 const int kPaddingLeft = 10; | 583 const int kPaddingLeft = 10; |
| 583 const int kWidth = 30; | 584 const int kWidth = 30; |
| 584 style_->setWidth(Length(kWidth, Fixed)); | 585 style_->setWidth(Length(kWidth, Fixed)); |
| 585 style_->setPaddingLeft(Length(kPaddingLeft, Fixed)); | 586 style_->setPaddingLeft(Length(kPaddingLeft, Fixed)); |
| 586 | 587 |
| 587 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); | 588 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); |
| 588 const int kChildWidth = 10; | 589 const int kChildWidth = 10; |
| 589 first_style->setWidth(Length(kChildWidth, Fixed)); | 590 first_style->setWidth(Length(kChildWidth, Fixed)); |
| 590 first_style->setMarginLeft(Length(Auto)); | 591 first_style->setMarginLeft(Length(Auto)); |
| 591 first_style->setMarginRight(Length(Auto)); | 592 first_style->setMarginRight(Length(Auto)); |
| 592 NGBlockNode* first_child = new NGBlockNode(first_style.get()); | 593 NGBlockNode* first_child = new NGBlockNode(first_style.get()); |
| 593 | 594 |
| 594 auto* space = ConstructConstraintSpace( | 595 auto* space = ConstructConstraintSpace( |
| 595 kHorizontalTopBottom, LTR, | 596 kHorizontalTopBottom, TextDirection::Ltr, |
| 596 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 597 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
| 597 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); | 598 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); |
| 598 | 599 |
| 599 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width()); | 600 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->Width()); |
| 600 EXPECT_EQ(NGPhysicalFragmentBase::kFragmentBox, frag->Type()); | 601 EXPECT_EQ(NGPhysicalFragmentBase::kFragmentBox, frag->Type()); |
| 601 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->WidthOverflow()); | 602 EXPECT_EQ(LayoutUnit(kWidth + kPaddingLeft), frag->WidthOverflow()); |
| 602 ASSERT_EQ(1UL, frag->Children().size()); | 603 ASSERT_EQ(1UL, frag->Children().size()); |
| 603 | 604 |
| 604 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 605 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
| 605 EXPECT_EQ(LayoutUnit(kChildWidth), child->Width()); | 606 EXPECT_EQ(LayoutUnit(kChildWidth), child->Width()); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 div4_style->setHeight(Length(kDiv4Size, Fixed)); | 667 div4_style->setHeight(Length(kDiv4Size, Fixed)); |
| 667 div4_style->setMarginLeft(Length(kDiv4LeftMargin, Fixed)); | 668 div4_style->setMarginLeft(Length(kDiv4LeftMargin, Fixed)); |
| 668 div4_style->setFloating(EFloat::Left); | 669 div4_style->setFloating(EFloat::Left); |
| 669 NGBlockNode* div4 = new NGBlockNode(div4_style.get()); | 670 NGBlockNode* div4 = new NGBlockNode(div4_style.get()); |
| 670 | 671 |
| 671 div1->SetNextSibling(div2); | 672 div1->SetNextSibling(div2); |
| 672 div2->SetNextSibling(div3); | 673 div2->SetNextSibling(div3); |
| 673 div3->SetNextSibling(div4); | 674 div3->SetNextSibling(div4); |
| 674 | 675 |
| 675 auto* space = ConstructConstraintSpace( | 676 auto* space = ConstructConstraintSpace( |
| 676 kHorizontalTopBottom, LTR, | 677 kHorizontalTopBottom, TextDirection::Ltr, |
| 677 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); | 678 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); |
| 678 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 679 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
| 679 ASSERT_EQ(frag->Children().size(), 4UL); | 680 ASSERT_EQ(frag->Children().size(), 4UL); |
| 680 | 681 |
| 681 // DIV1 | 682 // DIV1 |
| 682 const NGPhysicalFragmentBase* child1 = frag->Children()[0]; | 683 const NGPhysicalFragmentBase* child1 = frag->Children()[0]; |
| 683 EXPECT_EQ(kDiv1TopMargin, child1->TopOffset()); | 684 EXPECT_EQ(kDiv1TopMargin, child1->TopOffset()); |
| 684 EXPECT_EQ(kParentLeftPadding, child1->LeftOffset()); | 685 EXPECT_EQ(kParentLeftPadding, child1->LeftOffset()); |
| 685 | 686 |
| 686 // DIV2 | 687 // DIV2 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 div3_style->setWidth(Length(kDiv3Size, Fixed)); | 744 div3_style->setWidth(Length(kDiv3Size, Fixed)); |
| 744 div3_style->setHeight(Length(kDiv3Size, Fixed)); | 745 div3_style->setHeight(Length(kDiv3Size, Fixed)); |
| 745 NGBlockNode* div3 = new NGBlockNode(div3_style.get()); | 746 NGBlockNode* div3 = new NGBlockNode(div3_style.get()); |
| 746 | 747 |
| 747 div1->SetNextSibling(div2); | 748 div1->SetNextSibling(div2); |
| 748 div2->SetNextSibling(div3); | 749 div2->SetNextSibling(div3); |
| 749 | 750 |
| 750 // clear: left; | 751 // clear: left; |
| 751 div3_style->setClear(EClear::ClearLeft); | 752 div3_style->setClear(EClear::ClearLeft); |
| 752 auto* space = ConstructConstraintSpace( | 753 auto* space = ConstructConstraintSpace( |
| 753 kHorizontalTopBottom, LTR, | 754 kHorizontalTopBottom, TextDirection::Ltr, |
| 754 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); | 755 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); |
| 755 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 756 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
| 756 const NGPhysicalFragmentBase* child3 = frag->Children()[2]; | 757 const NGPhysicalFragmentBase* child3 = frag->Children()[2]; |
| 757 EXPECT_EQ(kDiv1Size, child3->TopOffset()); | 758 EXPECT_EQ(kDiv1Size, child3->TopOffset()); |
| 758 | 759 |
| 759 // clear: right; | 760 // clear: right; |
| 760 div3_style->setClear(EClear::ClearRight); | 761 div3_style->setClear(EClear::ClearRight); |
| 761 space = ConstructConstraintSpace( | 762 space = ConstructConstraintSpace( |
| 762 kHorizontalTopBottom, LTR, | 763 kHorizontalTopBottom, TextDirection::Ltr, |
| 763 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); | 764 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); |
| 764 frag = RunBlockLayoutAlgorithm(space, div1); | 765 frag = RunBlockLayoutAlgorithm(space, div1); |
| 765 child3 = frag->Children()[2]; | 766 child3 = frag->Children()[2]; |
| 766 EXPECT_EQ(kDiv1Size + kDiv2Size, child3->TopOffset()); | 767 EXPECT_EQ(kDiv1Size + kDiv2Size, child3->TopOffset()); |
| 767 | 768 |
| 768 // clear: both; | 769 // clear: both; |
| 769 div3_style->setClear(EClear::ClearBoth); | 770 div3_style->setClear(EClear::ClearBoth); |
| 770 space = ConstructConstraintSpace( | 771 space = ConstructConstraintSpace( |
| 771 kHorizontalTopBottom, LTR, | 772 kHorizontalTopBottom, TextDirection::Ltr, |
| 772 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); | 773 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); |
| 773 frag = RunBlockLayoutAlgorithm(space, div1); | 774 frag = RunBlockLayoutAlgorithm(space, div1); |
| 774 space = ConstructConstraintSpace( | 775 space = ConstructConstraintSpace( |
| 775 kHorizontalTopBottom, LTR, | 776 kHorizontalTopBottom, TextDirection::Ltr, |
| 776 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); | 777 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); |
| 777 child3 = frag->Children()[2]; | 778 child3 = frag->Children()[2]; |
| 778 EXPECT_EQ(kDiv1Size + kDiv2Size, child3->TopOffset()); | 779 EXPECT_EQ(kDiv1Size + kDiv2Size, child3->TopOffset()); |
| 779 } | 780 } |
| 780 | 781 |
| 781 } // namespace | 782 } // namespace |
| 782 } // namespace blink | 783 } // namespace blink |
| OLD | NEW |