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_length_utils.h" | 5 #include "core/layout/ng/ng_length_utils.h" |
6 | 6 |
7 #include "core/layout/ng/ng_constraint_space.h" | 7 #include "core/layout/ng/ng_constraint_space.h" |
| 8 #include "core/layout/ng/ng_constraint_space_builder.h" |
8 #include "core/layout/ng/ng_fragment.h" | 9 #include "core/layout/ng/ng_fragment.h" |
9 #include "core/layout/ng/ng_fragment_builder.h" | 10 #include "core/layout/ng/ng_fragment_builder.h" |
10 #include "core/layout/ng/ng_physical_fragment.h" | 11 #include "core/layout/ng/ng_physical_fragment.h" |
11 #include "core/layout/ng/ng_units.h" | 12 #include "core/layout/ng/ng_units.h" |
12 #include "core/style/ComputedStyle.h" | 13 #include "core/style/ComputedStyle.h" |
13 #include "platform/CalculationValue.h" | 14 #include "platform/CalculationValue.h" |
14 #include "platform/LayoutUnit.h" | 15 #include "platform/LayoutUnit.h" |
15 #include "platform/Length.h" | 16 #include "platform/Length.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "wtf/RefPtr.h" | 18 #include "wtf/RefPtr.h" |
18 | 19 |
19 namespace blink { | 20 namespace blink { |
20 namespace { | 21 namespace { |
21 | 22 |
22 class NGLengthUtilsTest : public ::testing::Test { | 23 class NGLengthUtilsTest : public ::testing::Test { |
23 protected: | 24 protected: |
24 void SetUp() override { style_ = ComputedStyle::create(); } | 25 void SetUp() override { style_ = ComputedStyle::create(); } |
25 | 26 |
26 static NGConstraintSpace* ConstructConstraintSpace(int inline_size, | 27 static NGConstraintSpace* ConstructConstraintSpace(int inline_size, |
27 int block_size, | 28 int block_size, |
28 bool fixed_inline = false, | 29 bool fixed_inline = false, |
29 bool fixed_block = false) { | 30 bool fixed_block = false) { |
30 return new NGConstraintSpace( | 31 NGConstraintSpaceBuilder builder(HorizontalTopBottom); |
31 HorizontalTopBottom, LeftToRight, | 32 builder |
32 new NGPhysicalConstraintSpace( | 33 .SetAvailableSize( |
33 NGPhysicalSize(LayoutUnit(inline_size), LayoutUnit(block_size)), | 34 NGLogicalSize(LayoutUnit(inline_size), LayoutUnit(block_size))) |
34 fixed_inline, fixed_block, false, false, FragmentNone, FragmentNone, | 35 .SetPercentageResolutionSize( |
35 false)); | 36 NGLogicalSize(LayoutUnit(inline_size), LayoutUnit(block_size))) |
| 37 .SetIsFixedSizeInline(fixed_inline) |
| 38 .SetIsFixedSizeBlock(fixed_block); |
| 39 |
| 40 return new NGConstraintSpace(HorizontalTopBottom, LeftToRight, |
| 41 builder.ToConstraintSpace()); |
36 } | 42 } |
37 | 43 |
38 LayoutUnit ResolveInlineLength( | 44 LayoutUnit ResolveInlineLength( |
39 const Length& length, | 45 const Length& length, |
40 LengthResolveType type = LengthResolveType::ContentSize) { | 46 LengthResolveType type = LengthResolveType::ContentSize) { |
41 NGConstraintSpace* constraintSpace = ConstructConstraintSpace(200, 300); | 47 NGConstraintSpace* constraintSpace = ConstructConstraintSpace(200, 300); |
42 return ::blink::ResolveInlineLength(*constraintSpace, *style_, length, | 48 return ::blink::ResolveInlineLength(*constraintSpace, *style_, length, |
43 type); | 49 type); |
44 } | 50 } |
45 | 51 |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 style_->setMarginRight(Length(5000, Fixed)); | 321 style_->setMarginRight(Length(5000, Fixed)); |
316 margins = NGBoxStrut(); | 322 margins = NGBoxStrut(); |
317 margins.inline_end = LayoutUnit(5000); | 323 margins.inline_end = LayoutUnit(5000); |
318 ApplyAutoMargins(*constraint_space, *style_, *fragment, &margins); | 324 ApplyAutoMargins(*constraint_space, *style_, *fragment, &margins); |
319 EXPECT_EQ(LayoutUnit(0), margins.inline_start); | 325 EXPECT_EQ(LayoutUnit(0), margins.inline_start); |
320 EXPECT_EQ(LayoutUnit(5000), margins.inline_end); | 326 EXPECT_EQ(LayoutUnit(5000), margins.inline_end); |
321 } | 327 } |
322 | 328 |
323 } // namespace | 329 } // namespace |
324 } // namespace blink | 330 } // namespace blink |
OLD | NEW |