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_block_layout_algorithm.h" | 5 #include "core/layout/ng/ng_block_layout_algorithm.h" |
6 | 6 |
7 #include "core/layout/ng/ng_box.h" | 7 #include "core/layout/ng/ng_box.h" |
8 #include "core/layout/ng/ng_constraint_space.h" | 8 #include "core/layout/ng/ng_constraint_space.h" |
9 #include "core/layout/ng/ng_physical_fragment.h" | 9 #include "core/layout/ng/ng_physical_fragment.h" |
10 #include "core/layout/ng/ng_length_utils.h" | 10 #include "core/layout/ng/ng_length_utils.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 TEST_F(NGBlockLayoutAlgorithmTest, FixedSize) { | 34 TEST_F(NGBlockLayoutAlgorithmTest, FixedSize) { |
35 style_->setWidth(Length(30, Fixed)); | 35 style_->setWidth(Length(30, Fixed)); |
36 style_->setHeight(Length(40, Fixed)); | 36 style_->setHeight(Length(40, Fixed)); |
37 | 37 |
38 auto* space = | 38 auto* space = |
39 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 39 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, |
40 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 40 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
41 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, nullptr); | 41 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, nullptr); |
42 | 42 |
43 EXPECT_EQ(frag->Width(), LayoutUnit(30)); | 43 EXPECT_EQ(LayoutUnit(30), frag->Width()); |
44 EXPECT_EQ(frag->Height(), LayoutUnit(40)); | 44 EXPECT_EQ(LayoutUnit(40), frag->Height()); |
45 } | 45 } |
46 | 46 |
47 // Verifies that two children are laid out with the correct size and position. | 47 // Verifies that two children are laid out with the correct size and position. |
48 TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildren) { | 48 TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildren) { |
49 const int kWidth = 30; | 49 const int kWidth = 30; |
50 const int kHeight1 = 20; | 50 const int kHeight1 = 20; |
51 const int kHeight2 = 30; | 51 const int kHeight2 = 30; |
52 const int kMarginTop = 5; | 52 const int kMarginTop = 5; |
53 const int kMarginBottom = 20; | 53 const int kMarginBottom = 20; |
54 style_->setWidth(Length(kWidth, Fixed)); | 54 style_->setWidth(Length(kWidth, Fixed)); |
55 | 55 |
56 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); | 56 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); |
57 first_style->setHeight(Length(kHeight1, Fixed)); | 57 first_style->setHeight(Length(kHeight1, Fixed)); |
58 NGBox* first_child = new NGBox(first_style.get()); | 58 NGBox* first_child = new NGBox(first_style.get()); |
59 | 59 |
60 RefPtr<ComputedStyle> second_style = ComputedStyle::create(); | 60 RefPtr<ComputedStyle> second_style = ComputedStyle::create(); |
61 second_style->setHeight(Length(kHeight2, Fixed)); | 61 second_style->setHeight(Length(kHeight2, Fixed)); |
62 second_style->setMarginTop(Length(kMarginTop, Fixed)); | 62 second_style->setMarginTop(Length(kMarginTop, Fixed)); |
63 second_style->setMarginBottom(Length(kMarginBottom, Fixed)); | 63 second_style->setMarginBottom(Length(kMarginBottom, Fixed)); |
64 NGBox* second_child = new NGBox(second_style.get()); | 64 NGBox* second_child = new NGBox(second_style.get()); |
65 | 65 |
66 first_child->SetNextSibling(second_child); | 66 first_child->SetNextSibling(second_child); |
67 | 67 |
68 auto* space = | 68 auto* space = |
69 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 69 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, |
70 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 70 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
71 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); | 71 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, first_child); |
72 | 72 |
73 EXPECT_EQ(frag->Width(), LayoutUnit(kWidth)); | 73 EXPECT_EQ(LayoutUnit(kWidth), frag->Width()); |
74 EXPECT_EQ(frag->Height(), LayoutUnit(kHeight1 + kHeight2 + kMarginTop)); | 74 EXPECT_EQ(LayoutUnit(kHeight1 + kHeight2 + kMarginTop), frag->Height()); |
75 EXPECT_EQ(frag->Type(), NGPhysicalFragmentBase::FragmentBox); | 75 EXPECT_EQ(NGPhysicalFragmentBase::FragmentBox, frag->Type()); |
76 ASSERT_EQ(frag->Children().size(), 2UL); | 76 ASSERT_EQ(frag->Children().size(), 2UL); |
77 | 77 |
78 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 78 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
79 EXPECT_EQ(child->Height(), kHeight1); | 79 EXPECT_EQ(kHeight1, child->Height()); |
80 EXPECT_EQ(child->TopOffset(), 0); | 80 EXPECT_EQ(0, child->TopOffset()); |
81 | 81 |
82 child = frag->Children()[1]; | 82 child = frag->Children()[1]; |
83 EXPECT_EQ(child->Height(), kHeight2); | 83 EXPECT_EQ(kHeight2, child->Height()); |
84 EXPECT_EQ(child->TopOffset(), kHeight1 + kMarginTop); | 84 EXPECT_EQ(kHeight1 + kMarginTop, child->TopOffset()); |
85 } | 85 } |
86 | 86 |
87 // Verifies that a child is laid out correctly if it's writing mode is different | 87 // Verifies that a child is laid out correctly if it's writing mode is different |
88 // from the parent's one. | 88 // from the parent's one. |
89 // | 89 // |
90 // Test case's HTML representation: | 90 // Test case's HTML representation: |
91 // <div style="writing-mode: vertical-lr;"> | 91 // <div style="writing-mode: vertical-lr;"> |
92 // <div style="width:50px; | 92 // <div style="width:50px; |
93 // height: 50px; margin-left: 100px; | 93 // height: 50px; margin-left: 100px; |
94 // writing-mode: horizontal-tb;"></div> | 94 // writing-mode: horizontal-tb;"></div> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 127 |
128 // Verifies the collapsing margins case for the next pair: | 128 // Verifies the collapsing margins case for the next pair: |
129 // - top margin of a box and top margin of its first in-flow child. | 129 // - top margin of a box and top margin of its first in-flow child. |
130 // | 130 // |
131 // Test case's HTML representation: | 131 // Test case's HTML representation: |
132 // <div style="margin-top: 20px; height: 50px;"> <!-- DIV1 --> | 132 // <div style="margin-top: 20px; height: 50px;"> <!-- DIV1 --> |
133 // <div style="margin-top: 10px"></div> <!-- DIV2 --> | 133 // <div style="margin-top: 10px"></div> <!-- DIV2 --> |
134 // </div> | 134 // </div> |
135 // | 135 // |
136 // Expected: | 136 // Expected: |
137 // Margins are collapsed resulting a single margin 20px = max(20px, 10px) | 137 // - Margins are collapsed resulting a single margin 20px = max(20px, 10px) |
| 138 // - The top offset of DIV2 == 20px |
138 TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase1) { | 139 TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase1) { |
139 const int kHeight = 50; | 140 const int kHeight = 50; |
140 const int kDiv1MarginTop = 20; | 141 const int kDiv1MarginTop = 20; |
141 const int kDiv2MarginTop = 10; | 142 const int kDiv2MarginTop = 10; |
142 | 143 |
143 // DIV1 | 144 // DIV1 |
144 RefPtr<ComputedStyle> div1_style = ComputedStyle::create(); | 145 RefPtr<ComputedStyle> div1_style = ComputedStyle::create(); |
145 div1_style->setHeight(Length(kHeight, Fixed)); | 146 div1_style->setHeight(Length(kHeight, Fixed)); |
146 div1_style->setMarginTop(Length(kDiv1MarginTop, Fixed)); | 147 div1_style->setMarginTop(Length(kDiv1MarginTop, Fixed)); |
147 NGBox* div1 = new NGBox(div1_style.get()); | 148 NGBox* div1 = new NGBox(div1_style.get()); |
148 | 149 |
149 // DIV2 | 150 // DIV2 |
150 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 151 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
151 div2_style->setMarginTop(Length(kDiv2MarginTop, Fixed)); | 152 div2_style->setMarginTop(Length(kDiv2MarginTop, Fixed)); |
152 NGBox* div2 = new NGBox(div2_style.get()); | 153 NGBox* div2 = new NGBox(div2_style.get()); |
153 | 154 |
154 div1->SetFirstChild(div2); | 155 div1->SetFirstChild(div2); |
155 | 156 |
156 auto* space = | 157 auto* space = |
157 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 158 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, |
158 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 159 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
159 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 160 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
160 | 161 |
161 EXPECT_EQ(frag->MarginStrut(), NGMarginStrut({LayoutUnit(kDiv1MarginTop)})); | 162 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv1MarginTop)}), frag->MarginStrut()); |
162 ASSERT_EQ(frag->Children().size(), 1UL); | 163 ASSERT_EQ(frag->Children().size(), 1UL); |
163 const NGPhysicalFragmentBase* div2_fragment = frag->Children()[0]; | 164 const NGPhysicalFragmentBase* div2_fragment = frag->Children()[0]; |
164 EXPECT_EQ(div2_fragment->MarginStrut(), | 165 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2MarginTop)}), |
165 NGMarginStrut({LayoutUnit(kDiv2MarginTop)})); | 166 div2_fragment->MarginStrut()); |
| 167 EXPECT_EQ(kDiv1MarginTop, div2_fragment->TopOffset()); |
166 } | 168 } |
167 | 169 |
168 // Verifies the collapsing margins case for the next pair: | 170 // Verifies the collapsing margins case for the next pair: |
169 // - bottom margin of box and top margin of its next in-flow following sibling. | 171 // - bottom margin of box and top margin of its next in-flow following sibling. |
170 // | 172 // |
171 // Test case's HTML representation: | 173 // Test case's HTML representation: |
172 // <div style="margin-bottom: 20px; height: 50px;"> <!-- DIV1 --> | 174 // <div style="margin-bottom: 20px; height: 50px;"> <!-- DIV1 --> |
173 // <div style="margin-bottom: -15px"></div> <!-- DIV2 --> | 175 // <div style="margin-bottom: -15px"></div> <!-- DIV2 --> |
| 176 // <div></div> <!-- DIV3 --> |
174 // </div> | 177 // </div> |
175 // <div style="margin-top: 10px; height: 50px;"> <!-- DIV3 --> | 178 // <div></div> <!-- DIV4 --> |
176 // <div style="margin-top: -30px"></div> <!-- DIV4 --> | 179 // <div style="margin-top: 10px; height: 50px;"> <!-- DIV5 --> |
| 180 // <div></div> <!-- DIV6 --> |
| 181 // <div style="margin-top: -30px"></div> <!-- DIV7 --> |
177 // </div> | 182 // </div> |
178 // | 183 // |
179 // Expected: | 184 // Expected: |
180 // Margins are collapsed resulting an overlap | 185 // Margins are collapsed resulting an overlap |
181 // -10px = max(20px, 10px) - max(abs(-15px), abs(-30px)) | 186 // -10px = max(20px, 10px) - max(abs(-15px), abs(-30px)) |
182 // between DIV2 and DIV3. | 187 // between DIV2 and DIV3. Zero-height blocks are ignored. |
183 TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase2) { | 188 TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase2) { |
184 const int kHeight = 50; | 189 const int kHeight = 50; |
185 const int kDiv1MarginBottom = 20; | 190 const int kDiv1MarginBottom = 20; |
186 const int kDiv2MarginBottom = -15; | 191 const int kDiv2MarginBottom = -15; |
187 const int kDiv3MarginTop = 10; | 192 const int kDiv5MarginTop = 10; |
188 const int kDiv4MarginTop = -30; | 193 const int kDiv7MarginTop = -30; |
189 const int kExpectedCollapsedMargin = -10; | 194 const int kExpectedCollapsedMargin = -10; |
190 | 195 |
191 // DIV1 | 196 // DIV1 |
192 RefPtr<ComputedStyle> div1_style = ComputedStyle::create(); | 197 RefPtr<ComputedStyle> div1_style = ComputedStyle::create(); |
193 div1_style->setHeight(Length(kHeight, Fixed)); | 198 div1_style->setHeight(Length(kHeight, Fixed)); |
194 div1_style->setMarginBottom(Length(kDiv1MarginBottom, Fixed)); | 199 div1_style->setMarginBottom(Length(kDiv1MarginBottom, Fixed)); |
195 NGBox* div1 = new NGBox(div1_style.get()); | 200 NGBox* div1 = new NGBox(div1_style.get()); |
196 | 201 |
197 // DIV2 | 202 // DIV2 |
198 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); | 203 RefPtr<ComputedStyle> div2_style = ComputedStyle::create(); |
199 div2_style->setMarginBottom(Length(kDiv2MarginBottom, Fixed)); | 204 div2_style->setMarginBottom(Length(kDiv2MarginBottom, Fixed)); |
200 NGBox* div2 = new NGBox(div2_style.get()); | 205 NGBox* div2 = new NGBox(div2_style.get()); |
201 | 206 |
202 // DIV3 | 207 // Empty DIVs: DIV3, DIV4, DIV6 |
203 RefPtr<ComputedStyle> div3_style = ComputedStyle::create(); | 208 NGBox* div3 = new NGBox(ComputedStyle::create().get()); |
204 div3_style->setHeight(Length(kHeight, Fixed)); | 209 NGBox* div4 = new NGBox(ComputedStyle::create().get()); |
205 div3_style->setMarginTop(Length(kDiv3MarginTop, Fixed)); | 210 NGBox* div6 = new NGBox(ComputedStyle::create().get()); |
206 NGBox* div3 = new NGBox(div3_style.get()); | |
207 | 211 |
208 // DIV4 | 212 // DIV5 |
209 RefPtr<ComputedStyle> div4_style = ComputedStyle::create(); | 213 RefPtr<ComputedStyle> div5_style = ComputedStyle::create(); |
210 div4_style->setMarginTop(Length(kDiv4MarginTop, Fixed)); | 214 div5_style->setHeight(Length(kHeight, Fixed)); |
211 NGBox* div4 = new NGBox(div4_style.get()); | 215 div5_style->setMarginTop(Length(kDiv5MarginTop, Fixed)); |
| 216 NGBox* div5 = new NGBox(div5_style.get()); |
| 217 |
| 218 // DIV7 |
| 219 RefPtr<ComputedStyle> div7_style = ComputedStyle::create(); |
| 220 div7_style->setMarginTop(Length(kDiv7MarginTop, Fixed)); |
| 221 NGBox* div7 = new NGBox(div7_style.get()); |
212 | 222 |
213 div1->SetFirstChild(div2); | 223 div1->SetFirstChild(div2); |
214 div3->SetFirstChild(div4); | 224 div2->SetNextSibling(div3); |
215 div1->SetNextSibling(div3); | 225 div1->SetNextSibling(div4); |
| 226 div4->SetNextSibling(div5); |
| 227 div5->SetFirstChild(div6); |
| 228 div6->SetNextSibling(div7); |
216 | 229 |
217 auto* space = | 230 auto* space = |
218 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 231 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, |
219 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 232 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
220 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 233 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
221 | 234 |
222 ASSERT_EQ(frag->Children().size(), 2UL); | 235 ASSERT_EQ(frag->Children().size(), 3UL); |
223 | 236 |
| 237 // DIV1 |
224 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 238 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
225 EXPECT_EQ(child->Height(), kHeight); | 239 EXPECT_EQ(kHeight, child->Height()); |
226 EXPECT_EQ(child->TopOffset(), 0); | 240 EXPECT_EQ(0, child->TopOffset()); |
227 | 241 |
228 child = frag->Children()[1]; | 242 // DIV5 |
229 EXPECT_EQ(child->Height(), kHeight); | 243 child = frag->Children()[2]; |
230 EXPECT_EQ(child->TopOffset(), kHeight + kExpectedCollapsedMargin); | 244 EXPECT_EQ(kHeight, child->Height()); |
| 245 EXPECT_EQ(kHeight + kExpectedCollapsedMargin, child->TopOffset()); |
231 } | 246 } |
232 | 247 |
233 // Verifies the collapsing margins case for the next pair: | 248 // Verifies the collapsing margins case for the next pair: |
234 // - bottom margin of a last in-flow child and bottom margin of its parent if | 249 // - bottom margin of a last in-flow child and bottom margin of its parent if |
235 // the parent has 'auto' computed height | 250 // the parent has 'auto' computed height |
236 // | 251 // |
237 // Test case's HTML representation: | 252 // Test case's HTML representation: |
238 // <div style="margin-bottom: 20px; height: 50px;"> <!-- DIV1 --> | 253 // <div style="margin-bottom: 20px; height: 50px;"> <!-- DIV1 --> |
239 // <div style="margin-bottom: 200px; height: 50px;"/> <!-- DIV2 --> | 254 // <div style="margin-bottom: 200px; height: 50px;"/> <!-- DIV2 --> |
240 // </div> | 255 // </div> |
(...skipping 19 matching lines...) Expand all Loading... |
260 NGBox* div2 = new NGBox(div2_style.get()); | 275 NGBox* div2 = new NGBox(div2_style.get()); |
261 | 276 |
262 div1->SetFirstChild(div2); | 277 div1->SetFirstChild(div2); |
263 | 278 |
264 auto* space = | 279 auto* space = |
265 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 280 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, |
266 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 281 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
267 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 282 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
268 | 283 |
269 // Verify that margins are collapsed. | 284 // Verify that margins are collapsed. |
270 EXPECT_EQ(frag->MarginStrut(), | 285 EXPECT_EQ(NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv2MarginBottom)}), |
271 NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv2MarginBottom)})); | 286 frag->MarginStrut()); |
272 | 287 |
273 // Verify that margins are NOT collapsed. | 288 // Verify that margins are NOT collapsed. |
274 div1_style->setHeight(Length(kHeight, Fixed)); | 289 div1_style->setHeight(Length(kHeight, Fixed)); |
275 frag = RunBlockLayoutAlgorithm(space, div1); | 290 frag = RunBlockLayoutAlgorithm(space, div1); |
276 EXPECT_EQ(frag->MarginStrut(), | 291 EXPECT_EQ(NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv1MarginBottom)}), |
277 NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv1MarginBottom)})); | 292 frag->MarginStrut()); |
278 } | 293 } |
279 | 294 |
280 // Verifies that 2 adjoining margins are not collapsed if there is padding or | 295 // Verifies that 2 adjoining margins are not collapsed if there is padding or |
281 // border that separates them. | 296 // border that separates them. |
282 // | 297 // |
283 // Test case's HTML representation: | 298 // Test case's HTML representation: |
284 // <div style="margin: 30px 0px; padding: 20px 0px;"> <!-- DIV1 --> | 299 // <div style="margin: 30px 0px; padding: 20px 0px;"> <!-- DIV1 --> |
285 // <div style="margin: 200px 0px; height: 50px;"/> <!-- DIV2 --> | 300 // <div style="margin: 200px 0px; height: 50px;"/> <!-- DIV2 --> |
286 // </div> | 301 // </div> |
287 // | 302 // |
(...skipping 22 matching lines...) Expand all Loading... |
310 | 325 |
311 div1->SetFirstChild(div2); | 326 div1->SetFirstChild(div2); |
312 | 327 |
313 auto* space = | 328 auto* space = |
314 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, | 329 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, |
315 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); | 330 NGLogicalSize(LayoutUnit(100), NGSizeIndefinite)); |
316 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); | 331 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1); |
317 | 332 |
318 // Verify that margins do NOT collapse. | 333 // Verify that margins do NOT collapse. |
319 frag = RunBlockLayoutAlgorithm(space, div1); | 334 frag = RunBlockLayoutAlgorithm(space, div1); |
320 EXPECT_EQ(frag->MarginStrut(), | 335 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv1Margin), LayoutUnit(kDiv1Margin)}), |
321 NGMarginStrut({LayoutUnit(kDiv1Margin), LayoutUnit(kDiv1Margin)})); | 336 frag->MarginStrut()); |
322 ASSERT_EQ(frag->Children().size(), 1UL); | 337 ASSERT_EQ(frag->Children().size(), 1UL); |
323 EXPECT_EQ(frag->Children()[0]->MarginStrut(), | 338 |
324 NGMarginStrut({LayoutUnit(kDiv2Margin), LayoutUnit(kDiv2Margin)})); | 339 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2Margin), LayoutUnit(kDiv2Margin)}), |
| 340 frag->Children()[0]->MarginStrut()); |
325 | 341 |
326 // Reset padding and verify that margins DO collapse. | 342 // Reset padding and verify that margins DO collapse. |
327 div1_style->setPaddingTop(Length(0, Fixed)); | 343 div1_style->setPaddingTop(Length(0, Fixed)); |
328 div1_style->setPaddingBottom(Length(0, Fixed)); | 344 div1_style->setPaddingBottom(Length(0, Fixed)); |
329 frag = RunBlockLayoutAlgorithm(space, div1); | 345 frag = RunBlockLayoutAlgorithm(space, div1); |
330 EXPECT_EQ(frag->MarginStrut(), | 346 EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2Margin), LayoutUnit(kDiv2Margin)}), |
331 NGMarginStrut({LayoutUnit(kDiv2Margin), LayoutUnit(kDiv2Margin)})); | 347 frag->MarginStrut()); |
| 348 } |
| 349 |
| 350 // Verifies that margins of 2 adjoining blocks with different writing modes |
| 351 // get collapsed. |
| 352 // |
| 353 // Test case's HTML representation: |
| 354 // <div style="writing-mode: vertical-lr;"> |
| 355 // <div style="margin-right: 60px; width: 60px;">vertical</div> |
| 356 // <div style="margin-left: 100px; writing-mode: horizontal-tb;"> |
| 357 // horizontal |
| 358 // </div> |
| 359 // </div> |
| 360 TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase5) { |
| 361 const int kVerticalDivMarginRight = 60; |
| 362 const int kVerticalDivWidth = 60; |
| 363 const int kHorizontalDivMarginLeft = 100; |
| 364 |
| 365 style_->setWidth(Length(500, Fixed)); |
| 366 style_->setHeight(Length(500, Fixed)); |
| 367 style_->setWritingMode(LeftToRightWritingMode); |
| 368 |
| 369 // Vertical DIV |
| 370 RefPtr<ComputedStyle> vertical_style = ComputedStyle::create(); |
| 371 vertical_style->setMarginRight(Length(kVerticalDivMarginRight, Fixed)); |
| 372 vertical_style->setWidth(Length(kVerticalDivWidth, Fixed)); |
| 373 NGBox* vertical_div = new NGBox(vertical_style.get()); |
| 374 |
| 375 // Horizontal DIV |
| 376 RefPtr<ComputedStyle> horizontal_style = ComputedStyle::create(); |
| 377 horizontal_style->setMarginLeft(Length(kHorizontalDivMarginLeft, Fixed)); |
| 378 horizontal_style->setWritingMode(TopToBottomWritingMode); |
| 379 NGBox* horizontal_div = new NGBox(horizontal_style.get()); |
| 380 |
| 381 vertical_div->SetNextSibling(horizontal_div); |
| 382 |
| 383 auto* space = |
| 384 new NGConstraintSpace(VerticalLeftRight, LeftToRight, |
| 385 NGLogicalSize(LayoutUnit(500), LayoutUnit(500))); |
| 386 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, vertical_div); |
| 387 |
| 388 ASSERT_EQ(frag->Children().size(), 2UL); |
| 389 const NGPhysicalFragmentBase* child = frag->Children()[1]; |
| 390 // Horizontal div |
| 391 EXPECT_EQ(0, child->TopOffset()); |
| 392 EXPECT_EQ(kVerticalDivWidth + kHorizontalDivMarginLeft, child->LeftOffset()); |
332 } | 393 } |
333 | 394 |
334 // Verifies that a box's size includes its borders and padding, and that | 395 // Verifies that a box's size includes its borders and padding, and that |
335 // children are positioned inside the content box. | 396 // children are positioned inside the content box. |
336 // | 397 // |
337 // Test case's HTML representation: | 398 // Test case's HTML representation: |
338 // <style> | 399 // <style> |
339 // #div1 { width:100px; height:100px; } | 400 // #div1 { width:100px; height:100px; } |
340 // #div1 { border-style:solid; border-width:1px 2px 3px 4px; } | 401 // #div1 { border-style:solid; border-width:1px 2px 3px 4px; } |
341 // #div1 { padding:5px 6px 7px 8px; } | 402 // #div1 { padding:5px 6px 7px 8px; } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 481 |
421 EXPECT_EQ(frag->Width(), LayoutUnit(kWidth + kPaddingLeft)); | 482 EXPECT_EQ(frag->Width(), LayoutUnit(kWidth + kPaddingLeft)); |
422 EXPECT_EQ(frag->Type(), NGPhysicalFragmentBase::FragmentBox); | 483 EXPECT_EQ(frag->Type(), NGPhysicalFragmentBase::FragmentBox); |
423 ASSERT_EQ(frag->Children().size(), 1UL); | 484 ASSERT_EQ(frag->Children().size(), 1UL); |
424 | 485 |
425 const NGPhysicalFragmentBase* child = frag->Children()[0]; | 486 const NGPhysicalFragmentBase* child = frag->Children()[0]; |
426 EXPECT_EQ(child->Width(), LayoutUnit(12)); | 487 EXPECT_EQ(child->Width(), LayoutUnit(12)); |
427 } | 488 } |
428 } // namespace | 489 } // namespace |
429 } // namespace blink | 490 } // namespace blink |
OLD | NEW |