| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 } | 144 } |
| 145 | 145 |
| 146 // This test is the same as LayoutOpportunitiesTwoInMiddle with the only | 146 // This test is the same as LayoutOpportunitiesTwoInMiddle with the only |
| 147 // difference that NGLayoutOpportunityIterator takes 2 additional arguments: | 147 // difference that NGLayoutOpportunityIterator takes 2 additional arguments: |
| 148 // - origin_point that changes the iterator to return Layout Opportunities that | 148 // - origin_point that changes the iterator to return Layout Opportunities that |
| 149 // lay after the origin point. | 149 // lay after the origin point. |
| 150 // - leader_point that together with origin_point creates a temporary exclusion | 150 // - leader_point that together with origin_point creates a temporary exclusion |
| 151 // | 151 // |
| 152 // Expected: | 152 // Expected: |
| 153 // Layout opportunity iterator generates the next opportunities: | 153 // Layout opportunity iterator generates the next opportunities: |
| 154 // - 1st Start Point (0, 200): 350x150, 250x200 | 154 // - 1st Start Point (0, 200): 350x150, 250x400 |
| 155 // - 3rd Start Point (550, 200): 50x200 | 155 // - 3rd Start Point (550, 200): 50x400 |
| 156 // - 4th Start Point (0, 300): 600x50, 500x100 | 156 // - 4th Start Point (0, 300): 600x50, 500x300 |
| 157 // - 5th Start Point (0, 400): 600x200 |
| 157 // All other opportunities that are located before the origin point should be | 158 // All other opportunities that are located before the origin point should be |
| 158 // filtered out. | 159 // filtered out. |
| 159 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddleWithOriginAndLeader) { | 160 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddleWithOriginAndLeader) { |
| 160 NGLogicalSize size; | 161 NGLogicalSize size; |
| 161 size.inline_size = LayoutUnit(600); | 162 size.inline_size = LayoutUnit(600); |
| 162 size.block_size = LayoutUnit(400); | 163 size.block_size = LayoutUnit(400); |
| 163 auto* space = | 164 auto* space = |
| 164 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, size); | 165 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, size); |
| 165 // Add exclusions | 166 // Add exclusions |
| 166 NGExclusion exclusion1; | 167 NGExclusion exclusion1; |
| 167 exclusion1.rect.size = {/* inline_size */ LayoutUnit(100), | 168 exclusion1.rect.size = {/* inline_size */ LayoutUnit(100), |
| 168 /* block_size */ LayoutUnit(100)}; | 169 /* block_size */ LayoutUnit(100)}; |
| 169 exclusion1.rect.offset = {/* inline_offset */ LayoutUnit(150), | 170 exclusion1.rect.offset = {/* inline_offset */ LayoutUnit(150), |
| 170 /* block_offset */ LayoutUnit(200)}; | 171 /* block_offset */ LayoutUnit(200)}; |
| 171 space->AddExclusion(exclusion1); | 172 space->AddExclusion(exclusion1); |
| 172 NGExclusion exclusion2; | 173 NGExclusion exclusion2; |
| 173 exclusion2.rect.size = {/* inline_size */ LayoutUnit(50), | 174 exclusion2.rect.size = {/* inline_size */ LayoutUnit(50), |
| 174 /* block_size */ LayoutUnit(50)}; | 175 /* block_size */ LayoutUnit(50)}; |
| 175 exclusion2.rect.offset = {/* inline_offset */ LayoutUnit(500), | 176 exclusion2.rect.offset = {/* inline_offset */ LayoutUnit(500), |
| 176 /* block_offset */ LayoutUnit(350)}; | 177 /* block_offset */ LayoutUnit(350)}; |
| 177 space->AddExclusion(exclusion2); | 178 space->AddExclusion(exclusion2); |
| 178 const NGLogicalOffset origin_point = {LayoutUnit(0), LayoutUnit(200)}; | 179 const NGLogicalOffset origin_point = {LayoutUnit(0), LayoutUnit(200)}; |
| 179 const NGLogicalOffset leader_point = {LayoutUnit(250), LayoutUnit(300)}; | 180 const NGLogicalOffset leader_point = {LayoutUnit(250), LayoutUnit(300)}; |
| 180 auto* iterator = | 181 auto* iterator = |
| 181 new NGLayoutOpportunityIterator(space, origin_point, leader_point); | 182 new NGLayoutOpportunityIterator(space, origin_point, leader_point); |
| 182 // 1st Start Point | 183 // 1st Start Point |
| 183 EXPECT_EQ("250,200 350x150", OpportunityToString(iterator->Next())); | 184 EXPECT_EQ("250,200 350x150", OpportunityToString(iterator->Next())); |
| 184 EXPECT_EQ("250,200 250x200", OpportunityToString(iterator->Next())); | 185 EXPECT_EQ("250,200 250x400", OpportunityToString(iterator->Next())); |
| 185 // 2nd Start Point | 186 // 2nd Start Point |
| 186 EXPECT_EQ("550,200 50x200", OpportunityToString(iterator->Next())); | 187 EXPECT_EQ("550,200 50x400", OpportunityToString(iterator->Next())); |
| 187 // 3rd Start Point | 188 // 3rd Start Point |
| 188 EXPECT_EQ("0,300 600x50", OpportunityToString(iterator->Next())); | 189 EXPECT_EQ("0,300 600x50", OpportunityToString(iterator->Next())); |
| 189 EXPECT_EQ("0,300 500x100", OpportunityToString(iterator->Next())); | 190 EXPECT_EQ("0,300 500x300", OpportunityToString(iterator->Next())); |
| 191 // 4th Start Point |
| 192 EXPECT_EQ("0,400 600x200", OpportunityToString(iterator->Next())); |
| 193 // TODO(glebl): The opportunity below should not be generated. |
| 194 EXPECT_EQ("250,400 350x200", OpportunityToString(iterator->Next())); |
| 190 // Iterator is exhausted. | 195 // Iterator is exhausted. |
| 191 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 196 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
| 192 } | 197 } |
| 193 // Verifies that Layout Opportunity iterator ignores the exclusion that is not | 198 // Verifies that Layout Opportunity iterator ignores the exclusion that is not |
| 194 // within constraint space. | 199 // within constraint space. |
| 195 // | 200 // |
| 196 // Test case visual representation: | 201 // Test case visual representation: |
| 197 // | 202 // |
| 198 // 100 200 300 400 500 | 203 // 100 200 300 400 500 |
| 199 // +----|----|----|----|----|----+ | 204 // +----|----|----|----|----|----+ |
| (...skipping 17 matching lines...) Expand all Loading... |
| 217 exclusion.rect.offset = {/* inline_offset */ LayoutUnit(0), | 222 exclusion.rect.offset = {/* inline_offset */ LayoutUnit(0), |
| 218 /* block_offset */ LayoutUnit(150)}; | 223 /* block_offset */ LayoutUnit(150)}; |
| 219 space->AddExclusion(exclusion); | 224 space->AddExclusion(exclusion); |
| 220 auto* iterator = space->LayoutOpportunities(); | 225 auto* iterator = space->LayoutOpportunities(); |
| 221 EXPECT_EQ("0,0 600x100", OpportunityToString(iterator->Next())); | 226 EXPECT_EQ("0,0 600x100", OpportunityToString(iterator->Next())); |
| 222 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 227 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
| 223 } | 228 } |
| 224 | 229 |
| 225 } // namespace | 230 } // namespace |
| 226 } // namespace blink | 231 } // namespace blink |
| OLD | NEW |