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_length_utils.h" | 10 #include "core/layout/ng/ng_length_utils.h" |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)) | 202 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)) |
203 .SetTextDirection(TextDirection::kLtr) | 203 .SetTextDirection(TextDirection::kLtr) |
204 .SetIsNewFormattingContext(true) | 204 .SetIsNewFormattingContext(true) |
205 .ToConstraintSpace(); | 205 .ToConstraintSpace(); |
206 NGPhysicalBoxFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 206 NGPhysicalBoxFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
207 | 207 |
208 EXPECT_TRUE(frag->MarginStrut().IsEmpty()); | 208 EXPECT_TRUE(frag->MarginStrut().IsEmpty()); |
209 ASSERT_EQ(frag->Children().size(), 1UL); | 209 ASSERT_EQ(frag->Children().size(), 1UL); |
210 const NGPhysicalBoxFragment* div2_fragment = | 210 const NGPhysicalBoxFragment* div2_fragment = |
211 static_cast<const NGPhysicalBoxFragment*>(frag->Children()[0].get()); | 211 static_cast<const NGPhysicalBoxFragment*>(frag->Children()[0].get()); |
212 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2MarginTop)}), | 212 EXPECT_EQ(NGDeprecatedMarginStrut({LayoutUnit(kDiv2MarginTop)}), |
213 div2_fragment->MarginStrut()); | 213 div2_fragment->MarginStrut()); |
214 EXPECT_EQ(kDiv1MarginTop, div2_fragment->TopOffset()); | 214 EXPECT_EQ(kDiv1MarginTop, div2_fragment->TopOffset()); |
215 } | 215 } |
216 | 216 |
217 // Verifies the collapsing margins case for the next pair: | 217 // Verifies the collapsing margins case for the next pair: |
218 // - bottom margin of box and top margin of its next in-flow following sibling. | 218 // - bottom margin of box and top margin of its next in-flow following sibling. |
219 // | 219 // |
220 // Test case's HTML representation: | 220 // Test case's HTML representation: |
221 // <div style="margin-bottom: 20px; height: 50px;"> <!-- DIV1 --> | 221 // <div style="margin-bottom: 20px; height: 50px;"> <!-- DIV1 --> |
222 // <div style="margin-bottom: -15px"></div> <!-- DIV2 --> | 222 // <div style="margin-bottom: -15px"></div> <!-- DIV2 --> |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); | 322 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); |
323 | 323 |
324 div1->SetFirstChild(div2); | 324 div1->SetFirstChild(div2); |
325 | 325 |
326 auto* space = ConstructConstraintSpace( | 326 auto* space = ConstructConstraintSpace( |
327 kHorizontalTopBottom, TextDirection::kLtr, | 327 kHorizontalTopBottom, TextDirection::kLtr, |
328 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 328 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
329 NGPhysicalBoxFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 329 NGPhysicalBoxFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
330 | 330 |
331 // Verify that margins are collapsed. | 331 // Verify that margins are collapsed. |
332 EXPECT_EQ(NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv2MarginBottom)}), | 332 EXPECT_EQ( |
333 frag->MarginStrut()); | 333 NGDeprecatedMarginStrut({LayoutUnit(0), LayoutUnit(kDiv2MarginBottom)}), |
| 334 frag->MarginStrut()); |
334 | 335 |
335 // Verify that margins are NOT collapsed. | 336 // Verify that margins are NOT collapsed. |
336 div1_style->setHeight(Length(kHeight, Fixed)); | 337 div1_style->setHeight(Length(kHeight, Fixed)); |
337 frag = RunBlockLayoutAlgorithm(space, div1); | 338 frag = RunBlockLayoutAlgorithm(space, div1); |
338 EXPECT_EQ(NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv1MarginBottom)}), | 339 EXPECT_EQ( |
339 frag->MarginStrut()); | 340 NGDeprecatedMarginStrut({LayoutUnit(0), LayoutUnit(kDiv1MarginBottom)}), |
| 341 frag->MarginStrut()); |
340 } | 342 } |
341 | 343 |
342 // Verifies that 2 adjoining margins are not collapsed if there is padding or | 344 // Verifies that 2 adjoining margins are not collapsed if there is padding or |
343 // border that separates them. | 345 // border that separates them. |
344 // | 346 // |
345 // Test case's HTML representation: | 347 // Test case's HTML representation: |
346 // <div style="margin: 30px 0px; padding: 20px 0px;"> <!-- DIV1 --> | 348 // <div style="margin: 30px 0px; padding: 20px 0px;"> <!-- DIV1 --> |
347 // <div style="margin: 200px 0px; height: 50px;"/> <!-- DIV2 --> | 349 // <div style="margin: 200px 0px; height: 50px;"/> <!-- DIV2 --> |
348 // </div> | 350 // </div> |
349 // | 351 // |
(...skipping 22 matching lines...) Expand all Loading... |
372 | 374 |
373 div1->SetFirstChild(div2); | 375 div1->SetFirstChild(div2); |
374 | 376 |
375 auto* space = ConstructConstraintSpace( | 377 auto* space = ConstructConstraintSpace( |
376 kHorizontalTopBottom, TextDirection::kLtr, | 378 kHorizontalTopBottom, TextDirection::kLtr, |
377 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 379 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
378 NGPhysicalBoxFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 380 NGPhysicalBoxFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
379 | 381 |
380 // Verify that margins do NOT collapse. | 382 // Verify that margins do NOT collapse. |
381 frag = RunBlockLayoutAlgorithm(space, div1); | 383 frag = RunBlockLayoutAlgorithm(space, div1); |
382 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv1Margin), LayoutUnit(kDiv1Margin)}), | 384 EXPECT_EQ(NGDeprecatedMarginStrut( |
| 385 {LayoutUnit(kDiv1Margin), LayoutUnit(kDiv1Margin)}), |
383 frag->MarginStrut()); | 386 frag->MarginStrut()); |
384 ASSERT_EQ(frag->Children().size(), 1UL); | 387 ASSERT_EQ(frag->Children().size(), 1UL); |
385 | 388 |
386 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2Margin), LayoutUnit(kDiv2Margin)}), | 389 EXPECT_EQ(NGDeprecatedMarginStrut( |
| 390 {LayoutUnit(kDiv2Margin), LayoutUnit(kDiv2Margin)}), |
387 static_cast<const NGPhysicalBoxFragment*>(frag->Children()[0].get()) | 391 static_cast<const NGPhysicalBoxFragment*>(frag->Children()[0].get()) |
388 ->MarginStrut()); | 392 ->MarginStrut()); |
389 | 393 |
390 // Reset padding and verify that margins DO collapse. | 394 // Reset padding and verify that margins DO collapse. |
391 div1_style->setPaddingTop(Length(0, Fixed)); | 395 div1_style->setPaddingTop(Length(0, Fixed)); |
392 div1_style->setPaddingBottom(Length(0, Fixed)); | 396 div1_style->setPaddingBottom(Length(0, Fixed)); |
393 frag = RunBlockLayoutAlgorithm(space, div1); | 397 frag = RunBlockLayoutAlgorithm(space, div1); |
394 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2Margin), LayoutUnit(kDiv2Margin)}), | 398 EXPECT_EQ(NGDeprecatedMarginStrut( |
| 399 {LayoutUnit(kDiv2Margin), LayoutUnit(kDiv2Margin)}), |
395 frag->MarginStrut()); | 400 frag->MarginStrut()); |
396 } | 401 } |
397 | 402 |
398 // Verifies that margins of 2 adjoining blocks with different writing modes | 403 // Verifies that margins of 2 adjoining blocks with different writing modes |
399 // get collapsed. | 404 // get collapsed. |
400 // | 405 // |
401 // Test case's HTML representation: | 406 // Test case's HTML representation: |
402 // <div style="writing-mode: vertical-lr;"> | 407 // <div style="writing-mode: vertical-lr;"> |
403 // <div style="margin-right: 60px; width: 60px;">vertical</div> | 408 // <div style="margin-right: 60px; width: 60px;">vertical</div> |
404 // <div style="margin-left: 100px; writing-mode: horizontal-tb;"> | 409 // <div style="margin-left: 100px; writing-mode: horizontal-tb;"> |
(...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1558 EXPECT_EQ(LayoutUnit(194), fragment->LeftOffset()); | 1563 EXPECT_EQ(LayoutUnit(194), fragment->LeftOffset()); |
1559 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); | 1564 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); |
1560 EXPECT_EQ(LayoutUnit(16), fragment->Width()); | 1565 EXPECT_EQ(LayoutUnit(16), fragment->Width()); |
1561 EXPECT_EQ(LayoutUnit(50), fragment->Height()); | 1566 EXPECT_EQ(LayoutUnit(50), fragment->Height()); |
1562 EXPECT_EQ(0UL, fragment->Children().size()); | 1567 EXPECT_EQ(0UL, fragment->Children().size()); |
1563 EXPECT_FALSE(iterator.NextChild()); | 1568 EXPECT_FALSE(iterator.NextChild()); |
1564 } | 1569 } |
1565 | 1570 |
1566 } // namespace | 1571 } // namespace |
1567 } // namespace blink | 1572 } // namespace blink |
OLD | NEW |