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_constraint_space.h" | 5 #include "core/layout/ng/ng_constraint_space.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_layout_opportunity_iterator.h" | 8 #include "core/layout/ng/ng_layout_opportunity_iterator.h" |
9 #include "core/layout/ng/ng_physical_constraint_space.h" | 9 #include "core/layout/ng/ng_physical_constraint_space.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 NGConstraintSpace* ConstructConstraintSpace(NGWritingMode writing_mode, | 16 NGConstraintSpace* ConstructConstraintSpace(NGWritingMode writing_mode, |
17 TextDirection direction, | 17 TextDirection direction, |
18 NGPhysicalSize size) { | 18 NGPhysicalSize size) { |
19 return new NGConstraintSpace( | 19 return new NGConstraintSpace( |
20 writing_mode, direction, | 20 writing_mode, direction, |
21 new NGPhysicalConstraintSpace( | 21 new NGPhysicalConstraintSpace( |
22 size, size, /* fixed_width */ true, /* fixed_height */ false, | 22 size, size, /* fixed_width */ true, /* fixed_height */ false, |
23 /* width_direction_triggers_scrollbar */ true, | 23 /* width_direction_triggers_scrollbar */ true, |
24 /* height_direction_triggers_scrollbar */ false, FragmentNone, | 24 /* height_direction_triggers_scrollbar */ false, kFragmentNone, |
25 FragmentColumn, /* is_new_fc */ false)); | 25 kFragmentColumn, /* is_new_fc */ false)); |
26 } | 26 } |
27 | 27 |
28 TEST(NGConstraintSpaceTest, WritingMode) { | 28 TEST(NGConstraintSpaceTest, WritingMode) { |
29 NGPhysicalConstraintSpace* phy_space = new NGPhysicalConstraintSpace( | 29 NGPhysicalConstraintSpace* phy_space = new NGPhysicalConstraintSpace( |
30 NGPhysicalSize(LayoutUnit(200), LayoutUnit(100)), | 30 NGPhysicalSize(LayoutUnit(200), LayoutUnit(100)), |
31 NGPhysicalSize(LayoutUnit(200), LayoutUnit(100)), /* fixed_width */ true, | 31 NGPhysicalSize(LayoutUnit(200), LayoutUnit(100)), /* fixed_width */ true, |
32 /* fixed_height */ false, /* width_direction_triggers_scrollbar */ true, | 32 /* fixed_height */ false, /* width_direction_triggers_scrollbar */ true, |
33 /* height_direction_triggers_scrollbar */ false, FragmentNone, | 33 /* height_direction_triggers_scrollbar */ false, kFragmentNone, |
34 FragmentColumn, /* is_new_fc */ false); | 34 kFragmentColumn, /* is_new_fc */ false); |
35 | 35 |
36 NGConstraintSpace* horz_space = | 36 NGConstraintSpace* horz_space = |
37 new NGConstraintSpace(HorizontalTopBottom, LTR, phy_space); | 37 new NGConstraintSpace(kHorizontalTopBottom, LTR, phy_space); |
38 | 38 |
39 NGConstraintSpace* vert_space = | 39 NGConstraintSpace* vert_space = |
40 new NGConstraintSpace(VerticalRightLeft, LTR, phy_space); | 40 new NGConstraintSpace(kVerticalRightLeft, LTR, phy_space); |
41 | 41 |
42 EXPECT_EQ(LayoutUnit(200), horz_space->AvailableSize().inline_size); | 42 EXPECT_EQ(LayoutUnit(200), horz_space->AvailableSize().inline_size); |
43 EXPECT_EQ(LayoutUnit(200), vert_space->AvailableSize().block_size); | 43 EXPECT_EQ(LayoutUnit(200), vert_space->AvailableSize().block_size); |
44 | 44 |
45 EXPECT_EQ(LayoutUnit(100), horz_space->AvailableSize().block_size); | 45 EXPECT_EQ(LayoutUnit(100), horz_space->AvailableSize().block_size); |
46 EXPECT_EQ(LayoutUnit(100), vert_space->AvailableSize().inline_size); | 46 EXPECT_EQ(LayoutUnit(100), vert_space->AvailableSize().inline_size); |
47 | 47 |
48 EXPECT_TRUE(horz_space->InlineTriggersScrollbar()); | 48 EXPECT_TRUE(horz_space->InlineTriggersScrollbar()); |
49 EXPECT_TRUE(vert_space->BlockTriggersScrollbar()); | 49 EXPECT_TRUE(vert_space->BlockTriggersScrollbar()); |
50 | 50 |
51 EXPECT_FALSE(horz_space->BlockTriggersScrollbar()); | 51 EXPECT_FALSE(horz_space->BlockTriggersScrollbar()); |
52 EXPECT_FALSE(vert_space->InlineTriggersScrollbar()); | 52 EXPECT_FALSE(vert_space->InlineTriggersScrollbar()); |
53 | 53 |
54 EXPECT_TRUE(horz_space->FixedInlineSize()); | 54 EXPECT_TRUE(horz_space->FixedInlineSize()); |
55 EXPECT_TRUE(vert_space->FixedBlockSize()); | 55 EXPECT_TRUE(vert_space->FixedBlockSize()); |
56 | 56 |
57 EXPECT_FALSE(horz_space->FixedBlockSize()); | 57 EXPECT_FALSE(horz_space->FixedBlockSize()); |
58 EXPECT_FALSE(vert_space->FixedInlineSize()); | 58 EXPECT_FALSE(vert_space->FixedInlineSize()); |
59 | 59 |
60 EXPECT_EQ(FragmentColumn, horz_space->BlockFragmentationType()); | 60 EXPECT_EQ(kFragmentColumn, horz_space->BlockFragmentationType()); |
61 EXPECT_EQ(FragmentNone, vert_space->BlockFragmentationType()); | 61 EXPECT_EQ(kFragmentNone, vert_space->BlockFragmentationType()); |
62 } | 62 } |
63 | 63 |
64 static String OpportunityToString(const NGLayoutOpportunity& opportunity) { | 64 static String OpportunityToString(const NGLayoutOpportunity& opportunity) { |
65 return opportunity.IsEmpty() ? String("(empty)") : opportunity.ToString(); | 65 return opportunity.IsEmpty() ? String("(empty)") : opportunity.ToString(); |
66 } | 66 } |
67 | 67 |
68 TEST(NGConstraintSpaceTest, LayoutOpportunitiesNoExclusions) { | 68 TEST(NGConstraintSpaceTest, LayoutOpportunitiesNoExclusions) { |
69 NGPhysicalSize physical_size; | 69 NGPhysicalSize physical_size; |
70 physical_size.width = LayoutUnit(600); | 70 physical_size.width = LayoutUnit(600); |
71 physical_size.height = LayoutUnit(400); | 71 physical_size.height = LayoutUnit(400); |
72 | 72 |
73 auto* space = | 73 auto* space = |
74 ConstructConstraintSpace(HorizontalTopBottom, LTR, physical_size); | 74 ConstructConstraintSpace(kHorizontalTopBottom, LTR, physical_size); |
75 auto* iterator = space->LayoutOpportunities(); | 75 auto* iterator = space->LayoutOpportunities(); |
76 | 76 |
77 EXPECT_EQ("0,0 600x400", OpportunityToString(iterator->Next())); | 77 EXPECT_EQ("0,0 600x400", OpportunityToString(iterator->Next())); |
78 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 78 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
79 } | 79 } |
80 | 80 |
81 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopRightExclusion) { | 81 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopRightExclusion) { |
82 NGPhysicalSize physical_size; | 82 NGPhysicalSize physical_size; |
83 physical_size.width = LayoutUnit(600); | 83 physical_size.width = LayoutUnit(600); |
84 physical_size.height = LayoutUnit(400); | 84 physical_size.height = LayoutUnit(400); |
85 | 85 |
86 // Create a space with a 100x100 exclusion in the top right corner. | 86 // Create a space with a 100x100 exclusion in the top right corner. |
87 auto* space = | 87 auto* space = |
88 ConstructConstraintSpace(HorizontalTopBottom, LTR, physical_size); | 88 ConstructConstraintSpace(kHorizontalTopBottom, LTR, physical_size); |
89 NGExclusion exclusion; | 89 NGExclusion exclusion; |
90 exclusion.rect.size = {/* inline_size */ LayoutUnit(100), | 90 exclusion.rect.size = {/* inline_size */ LayoutUnit(100), |
91 /* block_size */ LayoutUnit(100)}; | 91 /* block_size */ LayoutUnit(100)}; |
92 exclusion.rect.offset = {/* inline_offset */ LayoutUnit(500), | 92 exclusion.rect.offset = {/* inline_offset */ LayoutUnit(500), |
93 /* block_offset */ LayoutUnit(0)}; | 93 /* block_offset */ LayoutUnit(0)}; |
94 space->AddExclusion(exclusion); | 94 space->AddExclusion(exclusion); |
95 auto* iterator = space->LayoutOpportunities(); | 95 auto* iterator = space->LayoutOpportunities(); |
96 | 96 |
97 // First opportunity should be to the left of the exclusion. | 97 // First opportunity should be to the left of the exclusion. |
98 EXPECT_EQ("0,0 500x400", OpportunityToString(iterator->Next())); | 98 EXPECT_EQ("0,0 500x400", OpportunityToString(iterator->Next())); |
99 | 99 |
100 // Second opportunity should be below the exclusion. | 100 // Second opportunity should be below the exclusion. |
101 EXPECT_EQ("0,100 600x300", OpportunityToString(iterator->Next())); | 101 EXPECT_EQ("0,100 600x300", OpportunityToString(iterator->Next())); |
102 | 102 |
103 // There should be no third opportunity. | 103 // There should be no third opportunity. |
104 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 104 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
105 } | 105 } |
106 | 106 |
107 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopLeftExclusion) { | 107 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopLeftExclusion) { |
108 NGPhysicalSize physical_size; | 108 NGPhysicalSize physical_size; |
109 physical_size.width = LayoutUnit(600); | 109 physical_size.width = LayoutUnit(600); |
110 physical_size.height = LayoutUnit(400); | 110 physical_size.height = LayoutUnit(400); |
111 | 111 |
112 // Create a space with a 100x100 exclusion in the top left corner. | 112 // Create a space with a 100x100 exclusion in the top left corner. |
113 auto* space = | 113 auto* space = |
114 ConstructConstraintSpace(HorizontalTopBottom, LTR, physical_size); | 114 ConstructConstraintSpace(kHorizontalTopBottom, LTR, physical_size); |
115 NGExclusion exclusion; | 115 NGExclusion exclusion; |
116 exclusion.rect.size = {/* inline_size */ LayoutUnit(100), | 116 exclusion.rect.size = {/* inline_size */ LayoutUnit(100), |
117 /* block_size */ LayoutUnit(100)}; | 117 /* block_size */ LayoutUnit(100)}; |
118 exclusion.rect.offset = {/* inline_offset */ LayoutUnit(0), | 118 exclusion.rect.offset = {/* inline_offset */ LayoutUnit(0), |
119 /* block_offset */ LayoutUnit(0)}; | 119 /* block_offset */ LayoutUnit(0)}; |
120 space->AddExclusion(exclusion); | 120 space->AddExclusion(exclusion); |
121 | 121 |
122 auto* iterator = space->LayoutOpportunities(); | 122 auto* iterator = space->LayoutOpportunities(); |
123 | 123 |
124 // First opportunity should be to the right of the exclusion. | 124 // First opportunity should be to the right of the exclusion. |
(...skipping 28 matching lines...) Expand all Loading... |
153 // - 1st Start Point: 0,0 600x200; 0,0 150x400 | 153 // - 1st Start Point: 0,0 600x200; 0,0 150x400 |
154 // - 2nd Start Point: 250,0 350x350; 250,0 250x400 | 154 // - 2nd Start Point: 250,0 350x350; 250,0 250x400 |
155 // - 3rd Start Point: 550,0 50x400 | 155 // - 3rd Start Point: 550,0 50x400 |
156 // - 4th Start Point: 0,300 600x50; 0,300 500x100 | 156 // - 4th Start Point: 0,300 600x50; 0,300 500x100 |
157 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddle) { | 157 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddle) { |
158 NGPhysicalSize physical_size; | 158 NGPhysicalSize physical_size; |
159 physical_size.width = LayoutUnit(600); | 159 physical_size.width = LayoutUnit(600); |
160 physical_size.height = LayoutUnit(400); | 160 physical_size.height = LayoutUnit(400); |
161 | 161 |
162 auto* space = | 162 auto* space = |
163 ConstructConstraintSpace(HorizontalTopBottom, LTR, physical_size); | 163 ConstructConstraintSpace(kHorizontalTopBottom, LTR, physical_size); |
164 // Add exclusions | 164 // Add exclusions |
165 NGExclusion exclusion1; | 165 NGExclusion exclusion1; |
166 exclusion1.rect.size = {/* inline_size */ LayoutUnit(100), | 166 exclusion1.rect.size = {/* inline_size */ LayoutUnit(100), |
167 /* block_size */ LayoutUnit(100)}; | 167 /* block_size */ LayoutUnit(100)}; |
168 exclusion1.rect.offset = {/* inline_offset */ LayoutUnit(150), | 168 exclusion1.rect.offset = {/* inline_offset */ LayoutUnit(150), |
169 /* block_offset */ LayoutUnit(200)}; | 169 /* block_offset */ LayoutUnit(200)}; |
170 space->AddExclusion(exclusion1); | 170 space->AddExclusion(exclusion1); |
171 NGExclusion exclusion2; | 171 NGExclusion exclusion2; |
172 exclusion2.rect.size = {/* inline_size */ LayoutUnit(50), | 172 exclusion2.rect.size = {/* inline_size */ LayoutUnit(50), |
173 /* block_size */ LayoutUnit(50)}; | 173 /* block_size */ LayoutUnit(50)}; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 // - 3rd Start Point (550, 200): 50x200 | 208 // - 3rd Start Point (550, 200): 50x200 |
209 // - 4th Start Point (0, 300): 600x50, 500x100 | 209 // - 4th Start Point (0, 300): 600x50, 500x100 |
210 // All other opportunities that are located before the origin point should be | 210 // All other opportunities that are located before the origin point should be |
211 // filtered out. | 211 // filtered out. |
212 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddleWithOriginAndLeader) { | 212 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddleWithOriginAndLeader) { |
213 NGPhysicalSize physical_size; | 213 NGPhysicalSize physical_size; |
214 physical_size.width = LayoutUnit(600); | 214 physical_size.width = LayoutUnit(600); |
215 physical_size.height = LayoutUnit(400); | 215 physical_size.height = LayoutUnit(400); |
216 | 216 |
217 auto* space = | 217 auto* space = |
218 ConstructConstraintSpace(HorizontalTopBottom, LTR, physical_size); | 218 ConstructConstraintSpace(kHorizontalTopBottom, LTR, physical_size); |
219 // Add exclusions | 219 // Add exclusions |
220 NGExclusion exclusion1; | 220 NGExclusion exclusion1; |
221 exclusion1.rect.size = {/* inline_size */ LayoutUnit(100), | 221 exclusion1.rect.size = {/* inline_size */ LayoutUnit(100), |
222 /* block_size */ LayoutUnit(100)}; | 222 /* block_size */ LayoutUnit(100)}; |
223 exclusion1.rect.offset = {/* inline_offset */ LayoutUnit(150), | 223 exclusion1.rect.offset = {/* inline_offset */ LayoutUnit(150), |
224 /* block_offset */ LayoutUnit(200)}; | 224 /* block_offset */ LayoutUnit(200)}; |
225 space->AddExclusion(exclusion1); | 225 space->AddExclusion(exclusion1); |
226 NGExclusion exclusion2; | 226 NGExclusion exclusion2; |
227 exclusion2.rect.size = {/* inline_size */ LayoutUnit(50), | 227 exclusion2.rect.size = {/* inline_size */ LayoutUnit(50), |
228 /* block_size */ LayoutUnit(50)}; | 228 /* block_size */ LayoutUnit(50)}; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 // | 264 // |
265 // Expected: | 265 // Expected: |
266 // Layout opportunity iterator generates only one opportunity that equals to | 266 // Layout opportunity iterator generates only one opportunity that equals to |
267 // available constraint space, i.e. 0,0 600x200 | 267 // available constraint space, i.e. 0,0 600x200 |
268 TEST(NGConstraintSpaceTest, LayoutOpportunitiesWithOutOfBoundsExclusions) { | 268 TEST(NGConstraintSpaceTest, LayoutOpportunitiesWithOutOfBoundsExclusions) { |
269 NGPhysicalSize physical_size; | 269 NGPhysicalSize physical_size; |
270 physical_size.width = LayoutUnit(600); | 270 physical_size.width = LayoutUnit(600); |
271 physical_size.height = LayoutUnit(100); | 271 physical_size.height = LayoutUnit(100); |
272 | 272 |
273 auto* space = | 273 auto* space = |
274 ConstructConstraintSpace(HorizontalTopBottom, LTR, physical_size); | 274 ConstructConstraintSpace(kHorizontalTopBottom, LTR, physical_size); |
275 NGExclusion exclusion; | 275 NGExclusion exclusion; |
276 exclusion.rect.size = {/* inline_size */ LayoutUnit(100), | 276 exclusion.rect.size = {/* inline_size */ LayoutUnit(100), |
277 /* block_size */ LayoutUnit(100)}; | 277 /* block_size */ LayoutUnit(100)}; |
278 exclusion.rect.offset = {/* inline_offset */ LayoutUnit(0), | 278 exclusion.rect.offset = {/* inline_offset */ LayoutUnit(0), |
279 /* block_offset */ LayoutUnit(150)}; | 279 /* block_offset */ LayoutUnit(150)}; |
280 space->AddExclusion(exclusion); | 280 space->AddExclusion(exclusion); |
281 | 281 |
282 auto* iterator = space->LayoutOpportunities(); | 282 auto* iterator = space->LayoutOpportunities(); |
283 | 283 |
284 EXPECT_EQ("0,0 600x100", OpportunityToString(iterator->Next())); | 284 EXPECT_EQ("0,0 600x100", OpportunityToString(iterator->Next())); |
285 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 285 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
286 } | 286 } |
287 | 287 |
288 } // namespace | 288 } // namespace |
289 } // namespace blink | 289 } // namespace blink |
OLD | NEW |