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" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 NGConstraintSpace* ConstructConstraintSpace(NGWritingMode writing_mode, | |
17 NGDirection direction, | |
18 NGPhysicalSize size) { | |
19 return new NGConstraintSpace( | |
20 writing_mode, direction, | |
21 new NGPhysicalConstraintSpace( | |
22 size, /* fixed_width */ true, /* fixed_height */ false, | |
23 /* width_direction_triggers_scrollbar */ true, | |
24 /* height_direction_triggers_scrollbar */ false, FragmentNone, | |
25 FragmentColumn, /* is_new_fc */ false)); | |
26 } | |
27 | |
28 TEST(NGConstraintSpaceTest, WritingMode) { | 16 TEST(NGConstraintSpaceTest, WritingMode) { |
29 NGPhysicalConstraintSpace* phy_space = new NGPhysicalConstraintSpace( | 17 NGPhysicalConstraintSpace* phy_space = new NGPhysicalConstraintSpace( |
30 NGPhysicalSize(LayoutUnit(200), LayoutUnit(100)), /* fixed_width */ true, | 18 NGPhysicalSize(LayoutUnit(200), LayoutUnit(100)), /* fixed_width */ true, |
31 /* fixed_height */ false, /* width_direction_triggers_scrollbar */ true, | 19 /* fixed_height */ false, /* width_direction_triggers_scrollbar */ true, |
32 /* height_direction_triggers_scrollbar */ false, FragmentNone, | 20 /* height_direction_triggers_scrollbar */ false, FragmentNone, |
33 FragmentColumn, /* is_new_fc */ false); | 21 FragmentColumn, /* is_new_fc */ false); |
34 | 22 |
35 NGConstraintSpace* horz_space = | 23 NGConstraintSpace* horz_space = |
36 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, phy_space); | 24 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, phy_space); |
37 | 25 |
(...skipping 23 matching lines...) Expand all Loading... |
61 } | 49 } |
62 | 50 |
63 static String OpportunityToString(const NGLayoutOpportunity& opportunity) { | 51 static String OpportunityToString(const NGLayoutOpportunity& opportunity) { |
64 return opportunity.IsEmpty() ? String("(empty)") : opportunity.ToString(); | 52 return opportunity.IsEmpty() ? String("(empty)") : opportunity.ToString(); |
65 } | 53 } |
66 | 54 |
67 TEST(NGConstraintSpaceTest, LayoutOpportunitiesNoExclusions) { | 55 TEST(NGConstraintSpaceTest, LayoutOpportunitiesNoExclusions) { |
68 NGPhysicalSize physical_size; | 56 NGPhysicalSize physical_size; |
69 physical_size.width = LayoutUnit(600); | 57 physical_size.width = LayoutUnit(600); |
70 physical_size.height = LayoutUnit(400); | 58 physical_size.height = LayoutUnit(400); |
| 59 auto* physical_space = new NGPhysicalConstraintSpace(physical_size); |
| 60 auto* space = |
| 61 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, physical_space); |
71 | 62 |
72 auto* space = | |
73 ConstructConstraintSpace(HorizontalTopBottom, LeftToRight, physical_size); | |
74 auto* iterator = space->LayoutOpportunities(); | 63 auto* iterator = space->LayoutOpportunities(); |
75 | 64 |
76 EXPECT_EQ("0,0 600x400", OpportunityToString(iterator->Next())); | 65 EXPECT_EQ("0,0 600x400", OpportunityToString(iterator->Next())); |
77 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 66 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
78 } | 67 } |
79 | 68 |
80 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopRightExclusion) { | 69 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopRightExclusion) { |
81 NGPhysicalSize physical_size; | 70 NGPhysicalSize physical_size; |
82 physical_size.width = LayoutUnit(600); | 71 physical_size.width = LayoutUnit(600); |
83 physical_size.height = LayoutUnit(400); | 72 physical_size.height = LayoutUnit(400); |
| 73 auto* physical_space = new NGPhysicalConstraintSpace(physical_size); |
84 | 74 |
85 // Create a space with a 100x100 exclusion in the top right corner. | 75 // Add a 100x100 exclusion in the top right corner. |
| 76 physical_space->AddExclusion(new NGExclusion( |
| 77 LayoutUnit(0), LayoutUnit(600), LayoutUnit(100), LayoutUnit(500))); |
| 78 |
86 auto* space = | 79 auto* space = |
87 ConstructConstraintSpace(HorizontalTopBottom, LeftToRight, physical_size); | 80 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, physical_space); |
88 space->AddExclusion(new NGExclusion(LayoutUnit(0), LayoutUnit(600), | |
89 LayoutUnit(100), LayoutUnit(500))); | |
90 | |
91 auto* iterator = space->LayoutOpportunities(); | 81 auto* iterator = space->LayoutOpportunities(); |
92 | 82 |
93 // First opportunity should be to the left of the exclusion. | 83 // First opportunity should be to the left of the exclusion. |
94 EXPECT_EQ("0,0 500x400", OpportunityToString(iterator->Next())); | 84 EXPECT_EQ("0,0 500x400", OpportunityToString(iterator->Next())); |
95 | 85 |
96 // Second opportunity should be below the exclusion. | 86 // Second opportunity should be below the exclusion. |
97 EXPECT_EQ("0,100 600x300", OpportunityToString(iterator->Next())); | 87 EXPECT_EQ("0,100 600x300", OpportunityToString(iterator->Next())); |
98 | 88 |
99 // There should be no third opportunity. | 89 // There should be no third opportunity. |
100 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 90 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
101 } | 91 } |
102 | 92 |
103 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopLeftExclusion) { | 93 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopLeftExclusion) { |
104 NGPhysicalSize physical_size; | 94 NGPhysicalSize physical_size; |
105 physical_size.width = LayoutUnit(600); | 95 physical_size.width = LayoutUnit(600); |
106 physical_size.height = LayoutUnit(400); | 96 physical_size.height = LayoutUnit(400); |
| 97 auto* physical_space = new NGPhysicalConstraintSpace(physical_size); |
107 | 98 |
108 // Create a space with a 100x100 exclusion in the top left corner. | 99 // Add a 100x100 exclusion in the top left corner. |
| 100 physical_space->AddExclusion(new NGExclusion(LayoutUnit(0), LayoutUnit(100), |
| 101 LayoutUnit(100), LayoutUnit(0))); |
| 102 |
109 auto* space = | 103 auto* space = |
110 ConstructConstraintSpace(HorizontalTopBottom, LeftToRight, physical_size); | 104 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, physical_space); |
111 space->AddExclusion(new NGExclusion(LayoutUnit(0), LayoutUnit(100), | |
112 LayoutUnit(100), LayoutUnit(0))); | |
113 | |
114 auto* iterator = space->LayoutOpportunities(); | 105 auto* iterator = space->LayoutOpportunities(); |
115 | 106 |
116 // First opportunity should be to the right of the exclusion. | 107 // First opportunity should be to the right of the exclusion. |
117 EXPECT_EQ("100,0 500x400", OpportunityToString(iterator->Next())); | 108 EXPECT_EQ("100,0 500x400", OpportunityToString(iterator->Next())); |
118 | 109 |
119 // Second opportunity should be below the exclusion. | 110 // Second opportunity should be below the exclusion. |
120 EXPECT_EQ("0,100 600x300", OpportunityToString(iterator->Next())); | 111 EXPECT_EQ("0,100 600x300", OpportunityToString(iterator->Next())); |
121 | 112 |
122 // There should be no third opportunity. | 113 // There should be no third opportunity. |
123 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 114 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
(...skipping 19 matching lines...) Expand all Loading... |
143 // Expected: | 134 // Expected: |
144 // Layout opportunity iterator generates the next opportunities: | 135 // Layout opportunity iterator generates the next opportunities: |
145 // - 1st Start Point: 0,0 600x200; 0,0 150x400 | 136 // - 1st Start Point: 0,0 600x200; 0,0 150x400 |
146 // - 2nd Start Point: 250,0 350x350; 250,0 250x400 | 137 // - 2nd Start Point: 250,0 350x350; 250,0 250x400 |
147 // - 3rd Start Point: 550,0 50x400 | 138 // - 3rd Start Point: 550,0 50x400 |
148 // - 4th Start Point: 0,300 600x50; 0,300 500x100 | 139 // - 4th Start Point: 0,300 600x50; 0,300 500x100 |
149 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddle) { | 140 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddle) { |
150 NGPhysicalSize physical_size; | 141 NGPhysicalSize physical_size; |
151 physical_size.width = LayoutUnit(600); | 142 physical_size.width = LayoutUnit(600); |
152 physical_size.height = LayoutUnit(400); | 143 physical_size.height = LayoutUnit(400); |
| 144 auto* physical_space = new NGPhysicalConstraintSpace(physical_size); |
| 145 |
| 146 // Add exclusions |
| 147 physical_space->AddExclusion(new NGExclusion( |
| 148 LayoutUnit(200), LayoutUnit(250), LayoutUnit(300), LayoutUnit(150))); |
| 149 physical_space->AddExclusion(new NGExclusion( |
| 150 LayoutUnit(350), LayoutUnit(550), LayoutUnit(400), LayoutUnit(500))); |
153 | 151 |
154 auto* space = | 152 auto* space = |
155 ConstructConstraintSpace(HorizontalTopBottom, LeftToRight, physical_size); | 153 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, physical_space); |
156 | |
157 // Add exclusions | |
158 space->AddExclusion(new NGExclusion(LayoutUnit(200), LayoutUnit(250), | |
159 LayoutUnit(300), LayoutUnit(150))); | |
160 space->AddExclusion(new NGExclusion(LayoutUnit(350), LayoutUnit(550), | |
161 LayoutUnit(400), LayoutUnit(500))); | |
162 | |
163 auto* iterator = space->LayoutOpportunities(); | 154 auto* iterator = space->LayoutOpportunities(); |
164 | 155 |
165 // 1st Start point | 156 // 1st Start point |
166 EXPECT_EQ("0,0 600x200", OpportunityToString(iterator->Next())); | 157 EXPECT_EQ("0,0 600x200", OpportunityToString(iterator->Next())); |
167 EXPECT_EQ("0,0 150x400", OpportunityToString(iterator->Next())); | 158 EXPECT_EQ("0,0 150x400", OpportunityToString(iterator->Next())); |
168 | 159 |
169 // 2nd Start point | 160 // 2nd Start point |
170 EXPECT_EQ("250,0 350x350", OpportunityToString(iterator->Next())); | 161 EXPECT_EQ("250,0 350x350", OpportunityToString(iterator->Next())); |
171 EXPECT_EQ("250,0 250x400", OpportunityToString(iterator->Next())); | 162 EXPECT_EQ("250,0 250x400", OpportunityToString(iterator->Next())); |
172 | 163 |
(...skipping 18 matching lines...) Expand all Loading... |
191 // - 1st Start Point (0, 200): 150x200 | 182 // - 1st Start Point (0, 200): 150x200 |
192 // - 2nd Start Point (250, 200): 350x150, 250x200 | 183 // - 2nd Start Point (250, 200): 350x150, 250x200 |
193 // - 3rd Start Point (550, 200): 50x200 | 184 // - 3rd Start Point (550, 200): 50x200 |
194 // - 4th Start Point (0, 300): 600x50, 500x100 | 185 // - 4th Start Point (0, 300): 600x50, 500x100 |
195 // All other opportunities that are located before the origin point should be | 186 // All other opportunities that are located before the origin point should be |
196 // filtered out. | 187 // filtered out. |
197 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddleWithOrigin) { | 188 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddleWithOrigin) { |
198 NGPhysicalSize physical_size; | 189 NGPhysicalSize physical_size; |
199 physical_size.width = LayoutUnit(600); | 190 physical_size.width = LayoutUnit(600); |
200 physical_size.height = LayoutUnit(400); | 191 physical_size.height = LayoutUnit(400); |
| 192 auto* physical_space = new NGPhysicalConstraintSpace(physical_size); |
| 193 |
| 194 // Add exclusions |
| 195 physical_space->AddExclusion(new NGExclusion( |
| 196 LayoutUnit(200), LayoutUnit(250), LayoutUnit(300), LayoutUnit(150))); |
| 197 physical_space->AddExclusion(new NGExclusion( |
| 198 LayoutUnit(350), LayoutUnit(550), LayoutUnit(400), LayoutUnit(500))); |
201 | 199 |
202 auto* space = | 200 auto* space = |
203 ConstructConstraintSpace(HorizontalTopBottom, LeftToRight, physical_size); | 201 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, physical_space); |
204 | |
205 // Add exclusions | |
206 space->AddExclusion(new NGExclusion(LayoutUnit(200), LayoutUnit(250), | |
207 LayoutUnit(300), LayoutUnit(150))); | |
208 space->AddExclusion(new NGExclusion(LayoutUnit(350), LayoutUnit(550), | |
209 LayoutUnit(400), LayoutUnit(500))); | |
210 | |
211 const NGLogicalOffset origin_point = {LayoutUnit(0), LayoutUnit(200)}; | 202 const NGLogicalOffset origin_point = {LayoutUnit(0), LayoutUnit(200)}; |
212 auto* iterator = new NGLayoutOpportunityIterator(space, origin_point); | 203 auto* iterator = new NGLayoutOpportunityIterator(space, origin_point); |
213 | 204 |
214 // 1st Start Point | 205 // 1st Start Point |
215 EXPECT_EQ("0,200 150x200", OpportunityToString(iterator->Next())); | 206 EXPECT_EQ("0,200 150x200", OpportunityToString(iterator->Next())); |
216 | 207 |
217 // 2nd Start Point | 208 // 2nd Start Point |
218 EXPECT_EQ("250,200 350x150", OpportunityToString(iterator->Next())); | 209 EXPECT_EQ("250,200 350x150", OpportunityToString(iterator->Next())); |
219 EXPECT_EQ("250,200 250x200", OpportunityToString(iterator->Next())); | 210 EXPECT_EQ("250,200 250x200", OpportunityToString(iterator->Next())); |
220 | 211 |
(...skipping 21 matching lines...) Expand all Loading... |
242 // *** <- Exclusion | 233 // *** <- Exclusion |
243 // | 234 // |
244 // Expected: | 235 // Expected: |
245 // Layout opportunity iterator generates only one opportunity that equals to | 236 // Layout opportunity iterator generates only one opportunity that equals to |
246 // available constraint space, i.e. 0,0 600x200 | 237 // available constraint space, i.e. 0,0 600x200 |
247 TEST(NGConstraintSpaceTest, LayoutOpportunitiesWithOutOfBoundsExclusions) { | 238 TEST(NGConstraintSpaceTest, LayoutOpportunitiesWithOutOfBoundsExclusions) { |
248 NGPhysicalSize physical_size; | 239 NGPhysicalSize physical_size; |
249 physical_size.width = LayoutUnit(600); | 240 physical_size.width = LayoutUnit(600); |
250 physical_size.height = LayoutUnit(100); | 241 physical_size.height = LayoutUnit(100); |
251 | 242 |
| 243 auto* physical_space = new NGPhysicalConstraintSpace(physical_size); |
| 244 physical_space->AddExclusion(new NGExclusion(LayoutUnit(150), LayoutUnit(100), |
| 245 LayoutUnit(200), LayoutUnit(0))); |
252 auto* space = | 246 auto* space = |
253 ConstructConstraintSpace(HorizontalTopBottom, LeftToRight, physical_size); | 247 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, physical_space); |
254 space->AddExclusion(new NGExclusion(LayoutUnit(150), LayoutUnit(100), | |
255 LayoutUnit(200), LayoutUnit(0))); | |
256 | 248 |
257 auto* iterator = space->LayoutOpportunities(); | 249 auto* iterator = space->LayoutOpportunities(); |
258 | 250 |
259 EXPECT_EQ("0,0 600x100", OpportunityToString(iterator->Next())); | 251 EXPECT_EQ("0,0 600x100", OpportunityToString(iterator->Next())); |
260 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 252 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
261 } | 253 } |
262 | 254 |
263 } // namespace | 255 } // namespace |
264 } // namespace blink | 256 } // namespace blink |
OLD | NEW |