Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm_test.cc

Issue 2346473003: Do not collapse margins with padding/border b/w parent and first/last child (Closed)
Patch Set: synced to the head Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 EXPECT_EQ(frag->MarginStrut(), 224 EXPECT_EQ(frag->MarginStrut(),
225 NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv2MarginBottom)})); 225 NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv2MarginBottom)}));
226 226
227 // Verify that margins are NOT collapsed. 227 // Verify that margins are NOT collapsed.
228 div1_style->setHeight(Length(kHeight, Fixed)); 228 div1_style->setHeight(Length(kHeight, Fixed));
229 frag = RunBlockLayoutAlgorithm(space, div1); 229 frag = RunBlockLayoutAlgorithm(space, div1);
230 EXPECT_EQ(frag->MarginStrut(), 230 EXPECT_EQ(frag->MarginStrut(),
231 NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv1MarginBottom)})); 231 NGMarginStrut({LayoutUnit(0), LayoutUnit(kDiv1MarginBottom)}));
232 } 232 }
233 233
234 // Verifies that 2 adjoining margins are not collapsed if there is padding or
235 // border that separates them.
236 //
237 // Test case's HTML representation:
238 // <div style="margin: 30px 0px; padding: 20px 0px;"> <!-- DIV1 -->
239 // <div style="margin: 200px 0px; height: 50px;"/> <!-- DIV2 -->
240 // </div>
241 //
242 // Expected:
243 // Margins do NOT collapse if there is an interfering padding or border.
244 TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase4) {
245 const int kHeight = 50;
246 const int kDiv1Margin = 30;
247 const int kDiv1Padding = 20;
248 const int kDiv2Margin = 200;
249
250 // DIV1
251 RefPtr<ComputedStyle> div1_style = ComputedStyle::create();
252 div1_style->setMarginTop(Length(kDiv1Margin, Fixed));
253 div1_style->setMarginBottom(Length(kDiv1Margin, Fixed));
254 div1_style->setPaddingTop(Length(kDiv1Padding, Fixed));
255 div1_style->setPaddingBottom(Length(kDiv1Padding, Fixed));
256 NGBox* div1 = new NGBox(div1_style.get());
257
258 // DIV2
259 RefPtr<ComputedStyle> div2_style = ComputedStyle::create();
260 div2_style->setHeight(Length(kHeight, Fixed));
261 div2_style->setMarginTop(Length(kDiv2Margin, Fixed));
262 div2_style->setMarginBottom(Length(kDiv2Margin, Fixed));
263 NGBox* div2 = new NGBox(div2_style.get());
264
265 div1->SetFirstChild(div2);
266
267 auto* space = new NGConstraintSpace(
268 HorizontalTopBottom, NGLogicalSize(LayoutUnit(100), NGSizeIndefinite));
269 NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1);
270
271 // Verify that margins do NOT collapse.
272 frag = RunBlockLayoutAlgorithm(space, div1);
273 EXPECT_EQ(frag->MarginStrut(),
274 NGMarginStrut({LayoutUnit(kDiv1Margin), LayoutUnit(kDiv1Margin)}));
275 ASSERT_EQ(frag->Children().size(), 1UL);
276 EXPECT_EQ(frag->Children()[0]->MarginStrut(),
277 NGMarginStrut({LayoutUnit(kDiv2Margin), LayoutUnit(kDiv2Margin)}));
278
279 // Reset padding and verify that margins DO collapse.
280 div1_style->setPaddingTop(Length(0, Fixed));
281 div1_style->setPaddingBottom(Length(0, Fixed));
282 frag = RunBlockLayoutAlgorithm(space, div1);
283 EXPECT_EQ(frag->MarginStrut(),
284 NGMarginStrut({LayoutUnit(kDiv2Margin), LayoutUnit(kDiv2Margin)}));
285 }
286
234 // Verifies that a box's size includes its borders and padding, and that 287 // Verifies that a box's size includes its borders and padding, and that
235 // children are positioned inside the content box. 288 // children are positioned inside the content box.
236 // 289 //
237 // Test case's HTML representation: 290 // Test case's HTML representation:
238 // <style> 291 // <style>
239 // #div1 { width:100px; height:100px; } 292 // #div1 { width:100px; height:100px; }
240 // #div1 { border-style:solid; border-width:1px 2px 3px 4px; } 293 // #div1 { border-style:solid; border-width:1px 2px 3px 4px; }
241 // #div1 { padding:5px 6px 7px 8px; } 294 // #div1 { padding:5px 6px 7px 8px; }
242 // </style> 295 // </style>
243 // <div id="div1"> 296 // <div id="div1">
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 ASSERT_EQ(static_cast<const NGPhysicalFragment*>(child)->Children().size(), 349 ASSERT_EQ(static_cast<const NGPhysicalFragment*>(child)->Children().size(),
297 1UL); 350 1UL);
298 351
299 // div2 352 // div2
300 child = static_cast<const NGPhysicalFragment*>(child)->Children()[0]; 353 child = static_cast<const NGPhysicalFragment*>(child)->Children()[0];
301 EXPECT_EQ(kBorderTop + kPaddingTop, child->TopOffset()); 354 EXPECT_EQ(kBorderTop + kPaddingTop, child->TopOffset());
302 EXPECT_EQ(kBorderLeft + kPaddingLeft, child->LeftOffset()); 355 EXPECT_EQ(kBorderLeft + kPaddingLeft, child->LeftOffset());
303 } 356 }
304 } // namespace 357 } // namespace
305 } // namespace blink 358 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698