Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm_test.cc

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

Powered by Google App Engine
This is Rietveld 408576698