| 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" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 127 |
| 128 // Verifies the collapsing margins case for the next pair: | 128 // Verifies the collapsing margins case for the next pair: |
| 129 // - top margin of a box and top margin of its first in-flow child. | 129 // - top margin of a box and top margin of its first in-flow child. |
| 130 // | 130 // |
| 131 // Test case's HTML representation: | 131 // Test case's HTML representation: |
| 132 // <div style="margin-top: 20px; height: 50px;"> <!-- DIV1 --> | 132 // <div style="margin-top: 20px; height: 50px;"> <!-- DIV1 --> |
| 133 // <div style="margin-top: 10px"></div> <!-- DIV2 --> | 133 // <div style="margin-top: 10px"></div> <!-- DIV2 --> |
| 134 // </div> | 134 // </div> |
| 135 // | 135 // |
| 136 // Expected: | 136 // Expected: |
| 137 // - Empty margin strut of the fragment that establishes new formatting context |
| 137 // - Margins are collapsed resulting a single margin 20px = max(20px, 10px) | 138 // - Margins are collapsed resulting a single margin 20px = max(20px, 10px) |
| 138 // - The top offset of DIV2 == 20px | 139 // - The top offset of DIV2 == 20px |
| 139 TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase1) { | 140 TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase1) { |
| 140 const int kHeight = 50; | 141 const int kHeight = 50; |
| 141 const int kDiv1MarginTop = 20; | 142 const int kDiv1MarginTop = 20; |
| 142 const int kDiv2MarginTop = 10; | 143 const int kDiv2MarginTop = 10; |
| 143 | 144 |
| 144 // DIV1 | 145 // DIV1 |
| 145 RefPtr<ComputedStyle> div1_style = ComputedStyle::create(); | 146 RefPtr<ComputedStyle> div1_style = ComputedStyle::create(); |
| 146 div1_style->setHeight(Length(kHeight, Fixed)); | 147 div1_style->setHeight(Length(kHeight, Fixed)); |
| 147 div1_style->setMarginTop(Length(kDiv1MarginTop, Fixed)); | 148 div1_style->setMarginTop(Length(kDiv1MarginTop, Fixed)); |
| 148 NGBox* div1 = new NGBox(div1_style.get()); | 149 NGBox* div1 = new NGBox(div1_style.get()); |
| 149 | 150 |
| 150 // DIV2 | 151 // DIV2 |
| 151 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 152 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
| 152 div2_style->setMarginTop(Length(kDiv2MarginTop, Fixed)); | 153 div2_style->setMarginTop(Length(kDiv2MarginTop, Fixed)); |
| 153 NGBox* div2 = new NGBox(div2_style.get()); | 154 NGBox* div2 = new NGBox(div2_style.get()); |
| 154 | 155 |
| 155 div1->SetFirstChild(div2); | 156 div1->SetFirstChild(div2); |
| 156 | 157 |
| 157 auto* space = | 158 auto* space = |
| 158 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 159 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, |
| 159 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 160 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
| 160 space->SetIsNewFormattingContext(true); | 161 space->SetIsNewFormattingContext(true); |
| 161 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 162 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
| 162 | 163 |
| 163 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv1MarginTop)}), frag->MarginStrut()); | 164 EXPECT_TRUE(frag->MarginStrut().IsEmpty()); |
| 164 ASSERT_EQ(frag->Children().size(), 1UL); | 165 ASSERT_EQ(frag->Children().size(), 1UL); |
| 165 const NGPhysicalFragmentBase* div2_fragment = frag->Children()[0]; | 166 const NGPhysicalFragmentBase* div2_fragment = frag->Children()[0]; |
| 166 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2MarginTop)}), | 167 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2MarginTop)}), |
| 167 div2_fragment->MarginStrut()); | 168 div2_fragment->MarginStrut()); |
| 168 EXPECT_EQ(kDiv1MarginTop, div2_fragment->TopOffset()); | 169 EXPECT_EQ(kDiv1MarginTop, div2_fragment->TopOffset()); |
| 169 } | 170 } |
| 170 | 171 |
| 171 // Verifies the collapsing margins case for the next pair: | 172 // Verifies the collapsing margins case for the next pair: |
| 172 // - bottom margin of box and top margin of its next in-flow following sibling. | 173 // - bottom margin of box and top margin of its next in-flow following sibling. |
| 173 // | 174 // |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 | 483 |
| 483 EXPECT_EQ(frag->Width(), LayoutUnit(kWidth + kPaddingLeft)); | 484 EXPECT_EQ(frag->Width(), LayoutUnit(kWidth + kPaddingLeft)); |
| 484 EXPECT_EQ(frag->Type(), NGPhysicalFragmentBase::FragmentBox); | 485 EXPECT_EQ(frag->Type(), NGPhysicalFragmentBase::FragmentBox); |
| 485 ASSERT_EQ(frag->Children().size(), 1UL); | 486 ASSERT_EQ(frag->Children().size(), 1UL); |
| 486 | 487 |
| 487 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 488 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
| 488 EXPECT_EQ(child->Width(), LayoutUnit(12)); | 489 EXPECT_EQ(child->Width(), LayoutUnit(12)); |
| 489 } | 490 } |
| 490 } // namespace | 491 } // namespace |
| 491 } // namespace blink | 492 } // namespace blink |
| OLD | NEW |