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" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 } | 78 } |
79 | 79 |
80 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopRightExclusion) { | 80 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopRightExclusion) { |
81 NGPhysicalSize physical_size; | 81 NGPhysicalSize physical_size; |
82 physical_size.width = LayoutUnit(600); | 82 physical_size.width = LayoutUnit(600); |
83 physical_size.height = LayoutUnit(400); | 83 physical_size.height = LayoutUnit(400); |
84 | 84 |
85 // Create a space with a 100x100 exclusion in the top right corner. | 85 // Create a space with a 100x100 exclusion in the top right corner. |
86 auto* space = | 86 auto* space = |
87 ConstructConstraintSpace(HorizontalTopBottom, LeftToRight, physical_size); | 87 ConstructConstraintSpace(HorizontalTopBottom, LeftToRight, physical_size); |
88 NGLogicalRect exclusion; | 88 space->AddExclusion(new NGExclusion(LayoutUnit(0), LayoutUnit(600), |
89 exclusion.size = {/* inline_size */ LayoutUnit(100), | 89 LayoutUnit(100), LayoutUnit(500))); |
90 /* block_size */ LayoutUnit(100)}; | |
91 exclusion.offset = {/* inline_offset */ LayoutUnit(500), | |
92 /* block_offset */ LayoutUnit(0)}; | |
93 space->AddExclusion(exclusion); | |
94 | 90 |
95 auto* iterator = space->LayoutOpportunities(); | 91 auto* iterator = space->LayoutOpportunities(); |
96 | 92 |
97 // First opportunity should be to the left of the exclusion. | 93 // First opportunity should be to the left of the exclusion. |
98 EXPECT_EQ("0,0 500x400", OpportunityToString(iterator->Next())); | 94 EXPECT_EQ("0,0 500x400", OpportunityToString(iterator->Next())); |
99 | 95 |
100 // Second opportunity should be below the exclusion. | 96 // Second opportunity should be below the exclusion. |
101 EXPECT_EQ("0,100 600x300", OpportunityToString(iterator->Next())); | 97 EXPECT_EQ("0,100 600x300", OpportunityToString(iterator->Next())); |
102 | 98 |
103 // There should be no third opportunity. | 99 // There should be no third opportunity. |
104 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 100 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
105 } | 101 } |
106 | 102 |
107 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopLeftExclusion) { | 103 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopLeftExclusion) { |
108 NGPhysicalSize physical_size; | 104 NGPhysicalSize physical_size; |
109 physical_size.width = LayoutUnit(600); | 105 physical_size.width = LayoutUnit(600); |
110 physical_size.height = LayoutUnit(400); | 106 physical_size.height = LayoutUnit(400); |
111 | 107 |
112 // Create a space with a 100x100 exclusion in the top left corner. | 108 // Create a space with a 100x100 exclusion in the top left corner. |
113 auto* space = | 109 auto* space = |
114 ConstructConstraintSpace(HorizontalTopBottom, LeftToRight, physical_size); | 110 ConstructConstraintSpace(HorizontalTopBottom, LeftToRight, physical_size); |
115 NGLogicalRect exclusion; | 111 space->AddExclusion(new NGExclusion(LayoutUnit(0), LayoutUnit(100), |
116 exclusion.size = {/* inline_size */ LayoutUnit(100), | 112 LayoutUnit(100), LayoutUnit(0))); |
117 /* block_size */ LayoutUnit(100)}; | |
118 exclusion.offset = {/* inline_offset */ LayoutUnit(0), | |
119 /* block_offset */ LayoutUnit(0)}; | |
120 space->AddExclusion(exclusion); | |
121 | 113 |
122 auto* iterator = space->LayoutOpportunities(); | 114 auto* iterator = space->LayoutOpportunities(); |
123 | 115 |
124 // First opportunity should be to the right of the exclusion. | 116 // First opportunity should be to the right of the exclusion. |
125 EXPECT_EQ("100,0 500x400", OpportunityToString(iterator->Next())); | 117 EXPECT_EQ("100,0 500x400", OpportunityToString(iterator->Next())); |
126 | 118 |
127 // Second opportunity should be below the exclusion. | 119 // Second opportunity should be below the exclusion. |
128 EXPECT_EQ("0,100 600x300", OpportunityToString(iterator->Next())); | 120 EXPECT_EQ("0,100 600x300", OpportunityToString(iterator->Next())); |
129 | 121 |
130 // There should be no third opportunity. | 122 // There should be no third opportunity. |
(...skipping 23 matching lines...) Expand all Loading... |
154 // - 2nd Start Point: 250,0 350x350; 250,0 250x400 | 146 // - 2nd Start Point: 250,0 350x350; 250,0 250x400 |
155 // - 3rd Start Point: 550,0 50x400 | 147 // - 3rd Start Point: 550,0 50x400 |
156 // - 4th Start Point: 0,300 600x50; 0,300 500x100 | 148 // - 4th Start Point: 0,300 600x50; 0,300 500x100 |
157 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddle) { | 149 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddle) { |
158 NGPhysicalSize physical_size; | 150 NGPhysicalSize physical_size; |
159 physical_size.width = LayoutUnit(600); | 151 physical_size.width = LayoutUnit(600); |
160 physical_size.height = LayoutUnit(400); | 152 physical_size.height = LayoutUnit(400); |
161 | 153 |
162 auto* space = | 154 auto* space = |
163 ConstructConstraintSpace(HorizontalTopBottom, LeftToRight, physical_size); | 155 ConstructConstraintSpace(HorizontalTopBottom, LeftToRight, physical_size); |
| 156 |
164 // Add exclusions | 157 // Add exclusions |
165 NGLogicalRect exclusion1; | 158 space->AddExclusion(new NGExclusion(LayoutUnit(200), LayoutUnit(250), |
166 exclusion1.size = {/* inline_size */ LayoutUnit(100), | 159 LayoutUnit(300), LayoutUnit(150))); |
167 /* block_size */ LayoutUnit(100)}; | 160 space->AddExclusion(new NGExclusion(LayoutUnit(350), LayoutUnit(550), |
168 exclusion1.offset = {/* inline_offset */ LayoutUnit(150), | 161 LayoutUnit(400), LayoutUnit(500))); |
169 /* block_offset */ LayoutUnit(200)}; | |
170 space->AddExclusion(exclusion1); | |
171 NGLogicalRect exclusion2; | |
172 exclusion2.size = {/* inline_size */ LayoutUnit(50), | |
173 /* block_size */ LayoutUnit(50)}; | |
174 exclusion2.offset = {/* inline_offset */ LayoutUnit(500), | |
175 /* block_offset */ LayoutUnit(350)}; | |
176 space->AddExclusion(exclusion2); | |
177 | 162 |
178 auto* iterator = space->LayoutOpportunities(); | 163 auto* iterator = space->LayoutOpportunities(); |
179 | 164 |
180 // 1st Start point | 165 // 1st Start point |
181 EXPECT_EQ("0,0 600x200", OpportunityToString(iterator->Next())); | 166 EXPECT_EQ("0,0 600x200", OpportunityToString(iterator->Next())); |
182 EXPECT_EQ("0,0 150x400", OpportunityToString(iterator->Next())); | 167 EXPECT_EQ("0,0 150x400", OpportunityToString(iterator->Next())); |
183 | 168 |
184 // 2nd Start point | 169 // 2nd Start point |
185 EXPECT_EQ("250,0 350x350", OpportunityToString(iterator->Next())); | 170 EXPECT_EQ("250,0 350x350", OpportunityToString(iterator->Next())); |
186 EXPECT_EQ("250,0 250x400", OpportunityToString(iterator->Next())); | 171 EXPECT_EQ("250,0 250x400", OpportunityToString(iterator->Next())); |
(...skipping 22 matching lines...) Expand all Loading... |
209 // - 4th Start Point (0, 300): 600x50, 500x100 | 194 // - 4th Start Point (0, 300): 600x50, 500x100 |
210 // All other opportunities that are located before the origin point should be | 195 // All other opportunities that are located before the origin point should be |
211 // filtered out. | 196 // filtered out. |
212 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddleWithOrigin) { | 197 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddleWithOrigin) { |
213 NGPhysicalSize physical_size; | 198 NGPhysicalSize physical_size; |
214 physical_size.width = LayoutUnit(600); | 199 physical_size.width = LayoutUnit(600); |
215 physical_size.height = LayoutUnit(400); | 200 physical_size.height = LayoutUnit(400); |
216 | 201 |
217 auto* space = | 202 auto* space = |
218 ConstructConstraintSpace(HorizontalTopBottom, LeftToRight, physical_size); | 203 ConstructConstraintSpace(HorizontalTopBottom, LeftToRight, physical_size); |
| 204 |
219 // Add exclusions | 205 // Add exclusions |
220 NGLogicalRect exclusion1; | 206 space->AddExclusion(new NGExclusion(LayoutUnit(200), LayoutUnit(250), |
221 exclusion1.size = {/* inline_size */ LayoutUnit(100), | 207 LayoutUnit(300), LayoutUnit(150))); |
222 /* block_size */ LayoutUnit(100)}; | 208 space->AddExclusion(new NGExclusion(LayoutUnit(350), LayoutUnit(550), |
223 exclusion1.offset = {/* inline_offset */ LayoutUnit(150), | 209 LayoutUnit(400), LayoutUnit(500))); |
224 /* block_offset */ LayoutUnit(200)}; | |
225 space->AddExclusion(exclusion1); | |
226 NGLogicalRect exclusion2; | |
227 exclusion2.size = {/* inline_size */ LayoutUnit(50), | |
228 /* block_size */ LayoutUnit(50)}; | |
229 exclusion2.offset = {/* inline_offset */ LayoutUnit(500), | |
230 /* block_offset */ LayoutUnit(350)}; | |
231 space->AddExclusion(exclusion2); | |
232 | 210 |
233 const NGLogicalOffset origin_point = {LayoutUnit(0), LayoutUnit(200)}; | 211 const NGLogicalOffset origin_point = {LayoutUnit(0), LayoutUnit(200)}; |
234 auto* iterator = new NGLayoutOpportunityIterator(space, origin_point); | 212 auto* iterator = new NGLayoutOpportunityIterator(space, origin_point); |
235 | 213 |
236 // 1st Start Point | 214 // 1st Start Point |
237 EXPECT_EQ("0,200 150x200", OpportunityToString(iterator->Next())); | 215 EXPECT_EQ("0,200 150x200", OpportunityToString(iterator->Next())); |
238 | 216 |
239 // 2nd Start Point | 217 // 2nd Start Point |
240 EXPECT_EQ("250,200 350x150", OpportunityToString(iterator->Next())); | 218 EXPECT_EQ("250,200 350x150", OpportunityToString(iterator->Next())); |
241 EXPECT_EQ("250,200 250x200", OpportunityToString(iterator->Next())); | 219 EXPECT_EQ("250,200 250x200", OpportunityToString(iterator->Next())); |
(...skipping 24 matching lines...) Expand all Loading... |
266 // Expected: | 244 // Expected: |
267 // Layout opportunity iterator generates only one opportunity that equals to | 245 // Layout opportunity iterator generates only one opportunity that equals to |
268 // available constraint space, i.e. 0,0 600x200 | 246 // available constraint space, i.e. 0,0 600x200 |
269 TEST(NGConstraintSpaceTest, LayoutOpportunitiesWithOutOfBoundsExclusions) { | 247 TEST(NGConstraintSpaceTest, LayoutOpportunitiesWithOutOfBoundsExclusions) { |
270 NGPhysicalSize physical_size; | 248 NGPhysicalSize physical_size; |
271 physical_size.width = LayoutUnit(600); | 249 physical_size.width = LayoutUnit(600); |
272 physical_size.height = LayoutUnit(100); | 250 physical_size.height = LayoutUnit(100); |
273 | 251 |
274 auto* space = | 252 auto* space = |
275 ConstructConstraintSpace(HorizontalTopBottom, LeftToRight, physical_size); | 253 ConstructConstraintSpace(HorizontalTopBottom, LeftToRight, physical_size); |
276 NGLogicalRect exclusion; | 254 space->AddExclusion(new NGExclusion(LayoutUnit(150), LayoutUnit(100), |
277 exclusion.size = {/* inline_size */ LayoutUnit(100), | 255 LayoutUnit(200), LayoutUnit(0))); |
278 /* block_size */ LayoutUnit(100)}; | |
279 exclusion.offset = {/* inline_offset */ LayoutUnit(0), | |
280 /* block_offset */ LayoutUnit(150)}; | |
281 space->AddExclusion(exclusion); | |
282 | 256 |
283 auto* iterator = space->LayoutOpportunities(); | 257 auto* iterator = space->LayoutOpportunities(); |
284 | 258 |
285 EXPECT_EQ("0,0 600x100", OpportunityToString(iterator->Next())); | 259 EXPECT_EQ("0,0 600x100", OpportunityToString(iterator->Next())); |
286 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 260 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
287 } | 261 } |
288 | 262 |
289 } // namespace | 263 } // namespace |
290 } // namespace blink | 264 } // namespace blink |
OLD | NEW |