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" |
11 #include "core/layout/ng/ng_physical_fragment.h" | 11 #include "core/layout/ng/ng_physical_fragment.h" |
12 #include "core/layout/ng/ng_length_utils.h" | 12 #include "core/layout/ng/ng_length_utils.h" |
13 #include "core/layout/ng/ng_units.h" | 13 #include "core/layout/ng/ng_units.h" |
14 #include "core/style/ComputedStyle.h" | 14 #include "core/style/ComputedStyle.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 namespace blink { | 17 namespace blink { |
18 namespace { | 18 namespace { |
19 | 19 |
20 NGConstraintSpace* ConstructConstraintSpace(NGWritingMode writing_mode, | 20 NGConstraintSpace* ConstructConstraintSpace(NGWritingMode writing_mode, |
21 TextDirection direction, | 21 TextDirection direction, |
22 NGLogicalSize size) { | 22 NGLogicalSize size) { |
23 NGConstraintSpaceBuilder builder(writing_mode); | 23 return NGConstraintSpaceBuilder(writing_mode) |
24 builder.SetAvailableSize(size).SetPercentageResolutionSize(size); | 24 .SetAvailableSize(size) |
25 | 25 .SetPercentageResolutionSize(size) |
26 return new NGConstraintSpace(writing_mode, direction, | 26 .SetTextDirection(direction) |
27 builder.ToConstraintSpace()); | 27 .ToConstraintSpace(); |
28 } | 28 } |
29 | 29 |
30 class NGBlockLayoutAlgorithmTest : public ::testing::Test { | 30 class NGBlockLayoutAlgorithmTest : public ::testing::Test { |
31 protected: | 31 protected: |
32 void SetUp() override { style_ = ComputedStyle::create(); } | 32 void SetUp() override { style_ = ComputedStyle::create(); } |
33 | 33 |
34 NGPhysicalFragment* RunBlockLayoutAlgorithm(NGConstraintSpace* space, | 34 NGPhysicalFragment* RunBlockLayoutAlgorithm(NGConstraintSpace* space, |
35 NGBlockNode* first_child) { | 35 NGBlockNode* first_child) { |
36 NGBlockLayoutAlgorithm algorithm(style_, first_child, space); | 36 NGBlockLayoutAlgorithm algorithm(style_, first_child, space); |
37 NGPhysicalFragmentBase* frag; | 37 NGPhysicalFragmentBase* frag; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 div1_style->setMarginTop(Length(kDiv1MarginTop, Fixed)); | 160 div1_style->setMarginTop(Length(kDiv1MarginTop, Fixed)); |
161 NGBlockNode* div1 = new NGBlockNode(div1_style.get()); | 161 NGBlockNode* div1 = new NGBlockNode(div1_style.get()); |
162 | 162 |
163 // DIV2 | 163 // DIV2 |
164 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 164 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
165 div2_style->setMarginTop(Length(kDiv2MarginTop, Fixed)); | 165 div2_style->setMarginTop(Length(kDiv2MarginTop, Fixed)); |
166 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); | 166 NGBlockNode* div2 = new NGBlockNode(div2_style.get()); |
167 | 167 |
168 div1->SetFirstChild(div2); | 168 div1->SetFirstChild(div2); |
169 | 169 |
170 NGLogicalSize size(LayoutUnit(100), NGSizeIndefinite); | 170 auto* space = |
171 NGConstraintSpaceBuilder builder(kHorizontalTopBottom); | 171 NGConstraintSpaceBuilder(kHorizontalTopBottom) |
172 builder.SetAvailableSize(size) | 172 .SetAvailableSize(NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)) |
173 .SetPercentageResolutionSize(size) | 173 .SetPercentageResolutionSize( |
174 .SetIsNewFormattingContext(true); | 174 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)) |
175 auto* space = new NGConstraintSpace(kHorizontalTopBottom, LTR, | 175 .SetTextDirection(LTR) |
176 builder.ToConstraintSpace()); | 176 .SetIsNewFormattingContext(true) |
177 | 177 .ToConstraintSpace(); |
178 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 178 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
179 | 179 |
180 EXPECT_TRUE(frag->MarginStrut().IsEmpty()); | 180 EXPECT_TRUE(frag->MarginStrut().IsEmpty()); |
181 ASSERT_EQ(frag->Children().size(), 1UL); | 181 ASSERT_EQ(frag->Children().size(), 1UL); |
182 const NGPhysicalFragment* div2_fragment = | 182 const NGPhysicalFragment* div2_fragment = |
183 static_cast<const NGPhysicalFragment*>(frag->Children()[0].get()); | 183 static_cast<const NGPhysicalFragment*>(frag->Children()[0].get()); |
184 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2MarginTop)}), | 184 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2MarginTop)}), |
185 div2_fragment->MarginStrut()); | 185 div2_fragment->MarginStrut()); |
186 EXPECT_EQ(kDiv1MarginTop, div2_fragment->TopOffset()); | 186 EXPECT_EQ(kDiv1MarginTop, div2_fragment->TopOffset()); |
187 } | 187 } |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 frag = RunBlockLayoutAlgorithm(space, div1); | 764 frag = RunBlockLayoutAlgorithm(space, div1); |
765 space = ConstructConstraintSpace( | 765 space = ConstructConstraintSpace( |
766 kHorizontalTopBottom, LTR, | 766 kHorizontalTopBottom, LTR, |
767 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); | 767 NGLogicalSize(LayoutUnit(kParentSize), LayoutUnit(kParentSize))); |
768 child3 = frag->Children()[2]; | 768 child3 = frag->Children()[2]; |
769 EXPECT_EQ(kDiv1Size + kDiv2Size, child3->TopOffset()); | 769 EXPECT_EQ(kDiv1Size + kDiv2Size, child3->TopOffset()); |
770 } | 770 } |
771 | 771 |
772 } // namespace | 772 } // namespace |
773 } // namespace blink | 773 } // namespace blink |
OLD | NEW |