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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 190 |
191 // 4th Start point | 191 // 4th Start point |
192 EXPECT_EQ("0,300 600x50", OpportunityToString(iterator->Next())); | 192 EXPECT_EQ("0,300 600x50", OpportunityToString(iterator->Next())); |
193 EXPECT_EQ("0,300 500x100", OpportunityToString(iterator->Next())); | 193 EXPECT_EQ("0,300 500x100", OpportunityToString(iterator->Next())); |
194 | 194 |
195 // Iterator is exhausted. | 195 // Iterator is exhausted. |
196 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 196 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
197 } | 197 } |
198 | 198 |
199 // This test is the same as LayoutOpportunitiesTwoInMiddle with the only | 199 // This test is the same as LayoutOpportunitiesTwoInMiddle with the only |
200 // difference that NGLayoutOpportunityIterator takes the additional argument | 200 // difference that NGLayoutOpportunityIterator takes 2 additional arguments: |
201 // origin_point that changes the iterator to return Layout Opportunities that | 201 // - origin_point that changes the iterator to return Layout Opportunities that |
202 // lay after the origin point. | 202 // lay after the origin point. |
| 203 // - leader_point that together with origin_point creates a temporary exclusion |
203 // | 204 // |
204 // Expected: | 205 // Expected: |
205 // Layout opportunity iterator generates the next opportunities: | 206 // Layout opportunity iterator generates the next opportunities: |
206 // - 1st Start Point (0, 200): 150x200 | 207 // - 1st Start Point (0, 200): 350x150, 250x200 |
207 // - 2nd Start Point (250, 200): 350x150, 250x200 | |
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, LayoutOpportunitiesTwoInMiddleWithOrigin) { | 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, LeftToRight, physical_size); | 218 ConstructConstraintSpace(HorizontalTopBottom, LeftToRight, physical_size); |
219 // Add exclusions | 219 // Add exclusions |
220 NGLogicalRect exclusion1; | 220 NGLogicalRect exclusion1; |
221 exclusion1.size = {/* inline_size */ LayoutUnit(100), | 221 exclusion1.size = {/* inline_size */ LayoutUnit(100), |
222 /* block_size */ LayoutUnit(100)}; | 222 /* block_size */ LayoutUnit(100)}; |
223 exclusion1.offset = {/* inline_offset */ LayoutUnit(150), | 223 exclusion1.offset = {/* inline_offset */ LayoutUnit(150), |
224 /* block_offset */ LayoutUnit(200)}; | 224 /* block_offset */ LayoutUnit(200)}; |
225 space->AddExclusion(exclusion1); | 225 space->AddExclusion(exclusion1); |
226 NGLogicalRect exclusion2; | 226 NGLogicalRect exclusion2; |
227 exclusion2.size = {/* inline_size */ LayoutUnit(50), | 227 exclusion2.size = {/* inline_size */ LayoutUnit(50), |
228 /* block_size */ LayoutUnit(50)}; | 228 /* block_size */ LayoutUnit(50)}; |
229 exclusion2.offset = {/* inline_offset */ LayoutUnit(500), | 229 exclusion2.offset = {/* inline_offset */ LayoutUnit(500), |
230 /* block_offset */ LayoutUnit(350)}; | 230 /* block_offset */ LayoutUnit(350)}; |
231 space->AddExclusion(exclusion2); | 231 space->AddExclusion(exclusion2); |
232 | 232 |
233 const NGLogicalOffset origin_point = {LayoutUnit(0), LayoutUnit(200)}; | 233 const NGLogicalOffset origin_point = {LayoutUnit(0), LayoutUnit(200)}; |
234 auto* iterator = new NGLayoutOpportunityIterator(space, origin_point); | 234 const NGLogicalOffset leader_point = {LayoutUnit(250), LayoutUnit(300)}; |
| 235 auto* iterator = |
| 236 new NGLayoutOpportunityIterator(space, origin_point, leader_point); |
235 | 237 |
236 // 1st Start Point | 238 // 1st Start Point |
237 EXPECT_EQ("0,200 150x200", OpportunityToString(iterator->Next())); | |
238 | |
239 // 2nd Start Point | |
240 EXPECT_EQ("250,200 350x150", OpportunityToString(iterator->Next())); | 239 EXPECT_EQ("250,200 350x150", OpportunityToString(iterator->Next())); |
241 EXPECT_EQ("250,200 250x200", OpportunityToString(iterator->Next())); | 240 EXPECT_EQ("250,200 250x200", OpportunityToString(iterator->Next())); |
242 | 241 |
243 // 3rd Start Point | 242 // 2nd Start Point |
244 EXPECT_EQ("550,200 50x200", OpportunityToString(iterator->Next())); | 243 EXPECT_EQ("550,200 50x200", OpportunityToString(iterator->Next())); |
245 | 244 |
246 // 4th Start Point | 245 // 3rd Start Point |
247 EXPECT_EQ("0,300 600x50", OpportunityToString(iterator->Next())); | 246 EXPECT_EQ("0,300 600x50", OpportunityToString(iterator->Next())); |
248 EXPECT_EQ("0,300 500x100", OpportunityToString(iterator->Next())); | 247 EXPECT_EQ("0,300 500x100", OpportunityToString(iterator->Next())); |
249 | 248 |
250 // Iterator is exhausted. | 249 // Iterator is exhausted. |
251 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 250 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
252 } | 251 } |
253 | 252 |
254 // Verifies that Layout Opportunity iterator ignores the exclusion that is not | 253 // Verifies that Layout Opportunity iterator ignores the exclusion that is not |
255 // within constraint space. | 254 // within constraint space. |
256 // | 255 // |
(...skipping 24 matching lines...) Expand all Loading... |
281 space->AddExclusion(exclusion); | 280 space->AddExclusion(exclusion); |
282 | 281 |
283 auto* iterator = space->LayoutOpportunities(); | 282 auto* iterator = space->LayoutOpportunities(); |
284 | 283 |
285 EXPECT_EQ("0,0 600x100", OpportunityToString(iterator->Next())); | 284 EXPECT_EQ("0,0 600x100", OpportunityToString(iterator->Next())); |
286 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 285 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
287 } | 286 } |
288 | 287 |
289 } // namespace | 288 } // namespace |
290 } // namespace blink | 289 } // namespace blink |
OLD | NEW |