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_constraint_space_builder.h" | 8 #include "core/layout/ng/ng_constraint_space_builder.h" |
9 #include "core/layout/ng/ng_layout_opportunity_iterator.h" | 9 #include "core/layout/ng/ng_layout_opportunity_iterator.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 .ToConstraintSpace(writing_mode); | 29 .ToConstraintSpace(writing_mode); |
30 } | 30 } |
31 | 31 |
32 TEST(NGConstraintSpaceTest, LayoutOpportunitiesNoExclusions) { | 32 TEST(NGConstraintSpaceTest, LayoutOpportunitiesNoExclusions) { |
33 NGLogicalSize size; | 33 NGLogicalSize size; |
34 size.inline_size = LayoutUnit(600); | 34 size.inline_size = LayoutUnit(600); |
35 size.block_size = LayoutUnit(400); | 35 size.block_size = LayoutUnit(400); |
36 RefPtr<NGConstraintSpace> space = | 36 RefPtr<NGConstraintSpace> space = |
37 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, size); | 37 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, size); |
38 | 38 |
39 NGLayoutOpportunityIterator iterator(space.get()); | 39 NGLayoutOpportunityIterator iterator(space.get(), space->AvailableSize()); |
40 // 600x400 at (0,0) | 40 // 600x400 at (0,0) |
41 NGLayoutOpportunity opp1 = {{}, {LayoutUnit(600), LayoutUnit(400)}}; | 41 NGLayoutOpportunity opp1 = {{}, {LayoutUnit(600), LayoutUnit(400)}}; |
42 EXPECT_EQ(opp1, iterator.Next()); | 42 EXPECT_EQ(opp1, iterator.Next()); |
43 | 43 |
44 EXPECT_EQ(NGLayoutOpportunity(), iterator.Next()); | 44 EXPECT_EQ(NGLayoutOpportunity(), iterator.Next()); |
45 } | 45 } |
46 | 46 |
47 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopRightExclusion) { | 47 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopRightExclusion) { |
48 NGLogicalSize size; | 48 NGLogicalSize size; |
49 size.inline_size = LayoutUnit(600); | 49 size.inline_size = LayoutUnit(600); |
50 size.block_size = LayoutUnit(400); | 50 size.block_size = LayoutUnit(400); |
51 // Create a space with a 100x100 exclusion in the top right corner. | 51 // Create a space with a 100x100 exclusion in the top right corner. |
52 RefPtr<NGConstraintSpace> space = | 52 RefPtr<NGConstraintSpace> space = |
53 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, size); | 53 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, size); |
54 NGExclusion exclusion; | 54 NGExclusion exclusion; |
55 exclusion.rect.size = {LayoutUnit(100), LayoutUnit(100)}; | 55 exclusion.rect.size = {LayoutUnit(100), LayoutUnit(100)}; |
56 exclusion.rect.offset = {LayoutUnit(500), LayoutUnit()}; | 56 exclusion.rect.offset = {LayoutUnit(500), LayoutUnit()}; |
57 space->AddExclusion(exclusion); | 57 space->AddExclusion(exclusion); |
58 | 58 |
59 NGLayoutOpportunityIterator iterator(space.get()); | 59 NGLayoutOpportunityIterator iterator(space.get(), space->AvailableSize()); |
60 | 60 |
61 // First opportunity should be to the left of the exclusion: 500x400 at (0,0) | 61 // First opportunity should be to the left of the exclusion: 500x400 at (0,0) |
62 NGLayoutOpportunity opp1 = {{}, {LayoutUnit(500), LayoutUnit(400)}}; | 62 NGLayoutOpportunity opp1 = {{}, {LayoutUnit(500), LayoutUnit(400)}}; |
63 EXPECT_EQ(opp1, iterator.Next()); | 63 EXPECT_EQ(opp1, iterator.Next()); |
64 | 64 |
65 // Second opportunity should be below the exclusion: 600x300 at (0,100) | 65 // Second opportunity should be below the exclusion: 600x300 at (0,100) |
66 NGLayoutOpportunity opp2 = {{LayoutUnit(), LayoutUnit(100)}, | 66 NGLayoutOpportunity opp2 = {{LayoutUnit(), LayoutUnit(100)}, |
67 {LayoutUnit(600), LayoutUnit(300)}}; | 67 {LayoutUnit(600), LayoutUnit(300)}}; |
68 EXPECT_EQ(opp2, iterator.Next()); | 68 EXPECT_EQ(opp2, iterator.Next()); |
69 | 69 |
70 EXPECT_EQ(NGLayoutOpportunity(), iterator.Next()); | 70 EXPECT_EQ(NGLayoutOpportunity(), iterator.Next()); |
71 } | 71 } |
72 | 72 |
73 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopLeftExclusion) { | 73 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopLeftExclusion) { |
74 NGLogicalSize size; | 74 NGLogicalSize size; |
75 size.inline_size = LayoutUnit(600); | 75 size.inline_size = LayoutUnit(600); |
76 size.block_size = LayoutUnit(400); | 76 size.block_size = LayoutUnit(400); |
77 // Create a space with a 100x100 exclusion in the top left corner. | 77 // Create a space with a 100x100 exclusion in the top left corner. |
78 RefPtr<NGConstraintSpace> space = | 78 RefPtr<NGConstraintSpace> space = |
79 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, size); | 79 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, size); |
80 NGExclusion exclusion; | 80 NGExclusion exclusion; |
81 exclusion.rect.size = {LayoutUnit(100), LayoutUnit(100)}; | 81 exclusion.rect.size = {LayoutUnit(100), LayoutUnit(100)}; |
82 space->AddExclusion(exclusion); | 82 space->AddExclusion(exclusion); |
83 | 83 |
84 NGLayoutOpportunityIterator iterator(space.get()); | 84 NGLayoutOpportunityIterator iterator(space.get(), space->AvailableSize()); |
85 // First opportunity should be to the right of the exclusion: | 85 // First opportunity should be to the right of the exclusion: |
86 // 500x400 at (100, 0) | 86 // 500x400 at (100, 0) |
87 NGLayoutOpportunity opp1 = {{LayoutUnit(100), LayoutUnit()}, | 87 NGLayoutOpportunity opp1 = {{LayoutUnit(100), LayoutUnit()}, |
88 {LayoutUnit(500), LayoutUnit(400)}}; | 88 {LayoutUnit(500), LayoutUnit(400)}}; |
89 EXPECT_EQ(opp1, iterator.Next()); | 89 EXPECT_EQ(opp1, iterator.Next()); |
90 | 90 |
91 // Second opportunity should be below the exclusion: 600x300 at (0,100) | 91 // Second opportunity should be below the exclusion: 600x300 at (0,100) |
92 NGLayoutOpportunity opp2 = {{LayoutUnit(), LayoutUnit(100)}, | 92 NGLayoutOpportunity opp2 = {{LayoutUnit(), LayoutUnit(100)}, |
93 {LayoutUnit(600), LayoutUnit(300)}}; | 93 {LayoutUnit(600), LayoutUnit(300)}}; |
94 EXPECT_EQ(opp2, iterator.Next()); | 94 EXPECT_EQ(opp2, iterator.Next()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // Add exclusions | 128 // Add exclusions |
129 NGExclusion exclusion1; | 129 NGExclusion exclusion1; |
130 exclusion1.rect.size = {LayoutUnit(100), LayoutUnit(100)}; | 130 exclusion1.rect.size = {LayoutUnit(100), LayoutUnit(100)}; |
131 exclusion1.rect.offset = {LayoutUnit(150), LayoutUnit(200)}; | 131 exclusion1.rect.offset = {LayoutUnit(150), LayoutUnit(200)}; |
132 space->AddExclusion(exclusion1); | 132 space->AddExclusion(exclusion1); |
133 NGExclusion exclusion2; | 133 NGExclusion exclusion2; |
134 exclusion2.rect.size = {LayoutUnit(50), LayoutUnit(50)}; | 134 exclusion2.rect.size = {LayoutUnit(50), LayoutUnit(50)}; |
135 exclusion2.rect.offset = {LayoutUnit(500), LayoutUnit(350)}; | 135 exclusion2.rect.offset = {LayoutUnit(500), LayoutUnit(350)}; |
136 space->AddExclusion(exclusion2); | 136 space->AddExclusion(exclusion2); |
137 | 137 |
138 NGLayoutOpportunityIterator iterator(space.get()); | 138 NGLayoutOpportunityIterator iterator(space.get(), space->AvailableSize()); |
139 NGLogicalOffset start_point1; | 139 NGLogicalOffset start_point1; |
140 // 600x200 at (0,0) | 140 // 600x200 at (0,0) |
141 NGLayoutOpportunity opp1 = {start_point1, {LayoutUnit(600), LayoutUnit(200)}}; | 141 NGLayoutOpportunity opp1 = {start_point1, {LayoutUnit(600), LayoutUnit(200)}}; |
142 EXPECT_EQ(opp1, (iterator.Next())); | 142 EXPECT_EQ(opp1, (iterator.Next())); |
143 // 150x400 at (0,0) | 143 // 150x400 at (0,0) |
144 NGLayoutOpportunity opp2 = {start_point1, {LayoutUnit(150), LayoutUnit(400)}}; | 144 NGLayoutOpportunity opp2 = {start_point1, {LayoutUnit(150), LayoutUnit(400)}}; |
145 EXPECT_EQ(opp2, (iterator.Next())); | 145 EXPECT_EQ(opp2, (iterator.Next())); |
146 | 146 |
147 NGLogicalOffset start_point2 = {LayoutUnit(250), LayoutUnit()}; | 147 NGLogicalOffset start_point2 = {LayoutUnit(250), LayoutUnit()}; |
148 // 350x350 at (250,0) | 148 // 350x350 at (250,0) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 exclusion1.rect.size = {LayoutUnit(100), LayoutUnit(100)}; | 193 exclusion1.rect.size = {LayoutUnit(100), LayoutUnit(100)}; |
194 exclusion1.rect.offset = {LayoutUnit(150), LayoutUnit(200)}; | 194 exclusion1.rect.offset = {LayoutUnit(150), LayoutUnit(200)}; |
195 space->AddExclusion(exclusion1); | 195 space->AddExclusion(exclusion1); |
196 NGExclusion exclusion2; | 196 NGExclusion exclusion2; |
197 exclusion2.rect.size = {LayoutUnit(50), LayoutUnit(50)}; | 197 exclusion2.rect.size = {LayoutUnit(50), LayoutUnit(50)}; |
198 exclusion2.rect.offset = {LayoutUnit(500), LayoutUnit(350)}; | 198 exclusion2.rect.offset = {LayoutUnit(500), LayoutUnit(350)}; |
199 space->AddExclusion(exclusion2); | 199 space->AddExclusion(exclusion2); |
200 | 200 |
201 const NGLogicalOffset origin_point = {LayoutUnit(), LayoutUnit(200)}; | 201 const NGLogicalOffset origin_point = {LayoutUnit(), LayoutUnit(200)}; |
202 const NGLogicalOffset leader_point = {LayoutUnit(250), LayoutUnit(300)}; | 202 const NGLogicalOffset leader_point = {LayoutUnit(250), LayoutUnit(300)}; |
203 NGLayoutOpportunityIterator iterator(space.get(), origin_point, leader_point); | 203 NGLayoutOpportunityIterator iterator(space.get(), space->AvailableSize(), |
| 204 origin_point, leader_point); |
204 | 205 |
205 NGLogicalOffset start_point1 = {LayoutUnit(250), LayoutUnit(200)}; | 206 NGLogicalOffset start_point1 = {LayoutUnit(250), LayoutUnit(200)}; |
206 // 350x150 at (250,200) | 207 // 350x150 at (250,200) |
207 NGLayoutOpportunity opp1 = {start_point1, {LayoutUnit(350), LayoutUnit(150)}}; | 208 NGLayoutOpportunity opp1 = {start_point1, {LayoutUnit(350), LayoutUnit(150)}}; |
208 EXPECT_EQ(opp1, iterator.Next()); | 209 EXPECT_EQ(opp1, iterator.Next()); |
209 // 250x400 at (250,200) | 210 // 250x400 at (250,200) |
210 NGLayoutOpportunity opp2 = {start_point1, {LayoutUnit(250), LayoutUnit(400)}}; | 211 NGLayoutOpportunity opp2 = {start_point1, {LayoutUnit(250), LayoutUnit(400)}}; |
211 EXPECT_EQ(opp2, iterator.Next()); | 212 EXPECT_EQ(opp2, iterator.Next()); |
212 | 213 |
213 NGLogicalOffset start_point2 = {LayoutUnit(550), LayoutUnit(200)}; | 214 NGLogicalOffset start_point2 = {LayoutUnit(550), LayoutUnit(200)}; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 // available constraint space, i.e. 0,0 600x200 | 253 // available constraint space, i.e. 0,0 600x200 |
253 TEST(NGConstraintSpaceTest, LayoutOpportunitiesWithOutOfBoundsExclusions) { | 254 TEST(NGConstraintSpaceTest, LayoutOpportunitiesWithOutOfBoundsExclusions) { |
254 NGLogicalSize size = {LayoutUnit(600), LayoutUnit(100)}; | 255 NGLogicalSize size = {LayoutUnit(600), LayoutUnit(100)}; |
255 RefPtr<NGConstraintSpace> space = | 256 RefPtr<NGConstraintSpace> space = |
256 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, size); | 257 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, size); |
257 NGExclusion exclusion; | 258 NGExclusion exclusion; |
258 exclusion.rect.size = {LayoutUnit(100), LayoutUnit(100)}; | 259 exclusion.rect.size = {LayoutUnit(100), LayoutUnit(100)}; |
259 exclusion.rect.offset = {LayoutUnit(), LayoutUnit(150)}; | 260 exclusion.rect.offset = {LayoutUnit(), LayoutUnit(150)}; |
260 space->AddExclusion(exclusion); | 261 space->AddExclusion(exclusion); |
261 | 262 |
262 NGLayoutOpportunityIterator iterator(space.get()); | 263 NGLayoutOpportunityIterator iterator(space.get(), space->AvailableSize()); |
263 // 600x100 at (0,0) | 264 // 600x100 at (0,0) |
264 NGLayoutOpportunity opp = {{}, size}; | 265 NGLayoutOpportunity opp = {{}, size}; |
265 EXPECT_EQ(opp, iterator.Next()); | 266 EXPECT_EQ(opp, iterator.Next()); |
266 | 267 |
267 EXPECT_EQ(NGLayoutOpportunity(), iterator.Next()); | 268 EXPECT_EQ(NGLayoutOpportunity(), iterator.Next()); |
268 } | 269 } |
269 | 270 |
270 // Verifies that we combine 2 adjoining left exclusions into one left exclusion. | 271 // Verifies that we combine 2 adjoining left exclusions into one left exclusion. |
271 TEST(NGConstraintSpaceTest, TwoLeftExclusionsShadowEachOther) { | 272 TEST(NGConstraintSpaceTest, TwoLeftExclusionsShadowEachOther) { |
272 NGLogicalOffset bfc_offset = {LayoutUnit(8), LayoutUnit(8)}; | 273 NGLogicalOffset bfc_offset = {LayoutUnit(8), LayoutUnit(8)}; |
273 RefPtr<NGConstraintSpace> space = | 274 RefPtr<NGConstraintSpace> space = |
274 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, | 275 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, |
275 {LayoutUnit(200), LayoutUnit(200)}, bfc_offset); | 276 {LayoutUnit(200), LayoutUnit(200)}, bfc_offset); |
276 | 277 |
277 NGExclusion small_left; | 278 NGExclusion small_left; |
278 small_left.rect.size = {LayoutUnit(10), LayoutUnit(10)}; | 279 small_left.rect.size = {LayoutUnit(10), LayoutUnit(10)}; |
279 small_left.rect.offset = bfc_offset; | 280 small_left.rect.offset = bfc_offset; |
280 small_left.type = NGExclusion::kFloatLeft; | 281 small_left.type = NGExclusion::kFloatLeft; |
281 space->AddExclusion(small_left); | 282 space->AddExclusion(small_left); |
282 | 283 |
283 NGExclusion big_left; | 284 NGExclusion big_left; |
284 big_left.rect.size = {LayoutUnit(20), LayoutUnit(20)}; | 285 big_left.rect.size = {LayoutUnit(20), LayoutUnit(20)}; |
285 big_left.rect.offset = bfc_offset; | 286 big_left.rect.offset = bfc_offset; |
286 big_left.rect.offset.inline_offset += small_left.rect.InlineSize(); | 287 big_left.rect.offset.inline_offset += small_left.rect.InlineSize(); |
287 big_left.type = NGExclusion::kFloatLeft; | 288 big_left.type = NGExclusion::kFloatLeft; |
288 space->AddExclusion(big_left); | 289 space->AddExclusion(big_left); |
289 | 290 |
290 NGLayoutOpportunityIterator iterator(space.get(), bfc_offset); | 291 NGLayoutOpportunityIterator iterator(space.get(), space->AvailableSize(), |
| 292 bfc_offset); |
291 | 293 |
292 NGLogicalOffset start_point1 = bfc_offset; | 294 NGLogicalOffset start_point1 = bfc_offset; |
293 start_point1.inline_offset += | 295 start_point1.inline_offset += |
294 small_left.rect.InlineSize() + big_left.rect.InlineSize(); | 296 small_left.rect.InlineSize() + big_left.rect.InlineSize(); |
295 // 170x200 at (38, 8) | 297 // 170x200 at (38, 8) |
296 NGLayoutOpportunity opportunity1 = {start_point1, | 298 NGLayoutOpportunity opportunity1 = {start_point1, |
297 {LayoutUnit(170), LayoutUnit(200)}}; | 299 {LayoutUnit(170), LayoutUnit(200)}}; |
298 EXPECT_EQ(opportunity1, iterator.Next()); | 300 EXPECT_EQ(opportunity1, iterator.Next()); |
299 | 301 |
300 NGLogicalOffset start_point2 = bfc_offset; | 302 NGLogicalOffset start_point2 = bfc_offset; |
(...skipping 24 matching lines...) Expand all Loading... |
325 | 327 |
326 NGExclusion big_right; | 328 NGExclusion big_right; |
327 big_right.rect.size = {LayoutUnit(20), LayoutUnit(20)}; | 329 big_right.rect.size = {LayoutUnit(20), LayoutUnit(20)}; |
328 big_right.rect.offset = bfc_offset; | 330 big_right.rect.offset = bfc_offset; |
329 big_right.rect.offset.inline_offset += space->AvailableSize().inline_size - | 331 big_right.rect.offset.inline_offset += space->AvailableSize().inline_size - |
330 small_right.rect.InlineSize() - | 332 small_right.rect.InlineSize() - |
331 big_right.rect.InlineSize(); | 333 big_right.rect.InlineSize(); |
332 big_right.type = NGExclusion::kFloatRight; | 334 big_right.type = NGExclusion::kFloatRight; |
333 space->AddExclusion(big_right); | 335 space->AddExclusion(big_right); |
334 | 336 |
335 NGLayoutOpportunityIterator iterator(space.get(), bfc_offset); | 337 NGLayoutOpportunityIterator iterator(space.get(), space->AvailableSize(), |
| 338 bfc_offset); |
336 | 339 |
337 NGLogicalOffset start_point1 = bfc_offset; | 340 NGLogicalOffset start_point1 = bfc_offset; |
338 // 170x200 at (8, 8) | 341 // 170x200 at (8, 8) |
339 NGLayoutOpportunity opportunity1 = {start_point1, | 342 NGLayoutOpportunity opportunity1 = {start_point1, |
340 {LayoutUnit(170), LayoutUnit(200)}}; | 343 {LayoutUnit(170), LayoutUnit(200)}}; |
341 EXPECT_EQ(opportunity1, iterator.Next()); | 344 EXPECT_EQ(opportunity1, iterator.Next()); |
342 | 345 |
343 NGLogicalOffset start_point2 = bfc_offset; | 346 NGLogicalOffset start_point2 = bfc_offset; |
344 start_point2.block_offset += big_right.rect.BlockSize(); | 347 start_point2.block_offset += big_right.rect.BlockSize(); |
345 // 200x180 at (8, 28) | 348 // 200x180 at (8, 28) |
346 NGLayoutOpportunity opportunity2 = {start_point2, | 349 NGLayoutOpportunity opportunity2 = {start_point2, |
347 {LayoutUnit(200), LayoutUnit(180)}}; | 350 {LayoutUnit(200), LayoutUnit(180)}}; |
348 EXPECT_EQ(opportunity2, iterator.Next()); | 351 EXPECT_EQ(opportunity2, iterator.Next()); |
349 | 352 |
350 EXPECT_EQ(NGLayoutOpportunity(), iterator.Next()); | 353 EXPECT_EQ(NGLayoutOpportunity(), iterator.Next()); |
351 } | 354 } |
352 | 355 |
353 } // namespace | 356 } // namespace |
354 } // namespace blink | 357 } // namespace blink |
OLD | NEW |