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