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