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

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

Issue 2325073002: [LayoutNG] Handle border and padding when sizing a block and when placing its children. (Closed)
Patch Set: Use modern CSS terms, rather than old XSL terms, for box sides 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 ASSERT_EQ(frag->Children().size(), 2UL); 178 ASSERT_EQ(frag->Children().size(), 2UL);
179 179
180 const NGPhysicalFragmentBase* child = frag->Children()[0]; 180 const NGPhysicalFragmentBase* child = frag->Children()[0];
181 EXPECT_EQ(child->Height(), kHeight); 181 EXPECT_EQ(child->Height(), kHeight);
182 EXPECT_EQ(child->TopOffset(), 0); 182 EXPECT_EQ(child->TopOffset(), 0);
183 183
184 child = frag->Children()[1]; 184 child = frag->Children()[1];
185 EXPECT_EQ(child->Height(), kHeight); 185 EXPECT_EQ(child->Height(), kHeight);
186 EXPECT_EQ(child->TopOffset(), kHeight + kExpectedCollapsedMargin); 186 EXPECT_EQ(child->TopOffset(), kHeight + kExpectedCollapsedMargin);
187 } 187 }
188
189 // Verifies that a box's size includes its borders and padding, and that
190 // children are positioned inside the content box.
191 //
192 // Test case's HTML representation:
193 // <style>
194 // #div1 { width:100px; height:100px; }
195 // #div1 { border-style:solid; border-width:1px 2px 3px 4px; }
196 // #div1 { padding:5px 6px 7px 8px; }
197 // </style>
198 // <div id="div1">
199 // <div id="div2"></div>
200 // </div>
201 TEST_F(NGBlockLayoutAlgorithmTest, BorderAndPadding) {
202 const int kWidth = 100;
203 const int kHeight = 100;
204 const int kBorderTop = 1;
205 const int kBorderRight = 2;
206 const int kBorderBottom = 3;
207 const int kBorderLeft = 4;
208 const int kPaddingTop = 5;
209 const int kPaddingRight = 6;
210 const int kPaddingBottom = 7;
211 const int kPaddingLeft = 8;
212 RefPtr<ComputedStyle> div1_style = ComputedStyle::create();
213
214 div1_style->setWidth(Length(kWidth, Fixed));
215 div1_style->setHeight(Length(kHeight, Fixed));
216
217 div1_style->setBorderTopWidth(kBorderTop);
218 div1_style->setBorderTopStyle(BorderStyleSolid);
219 div1_style->setBorderRightWidth(kBorderRight);
220 div1_style->setBorderRightStyle(BorderStyleSolid);
221 div1_style->setBorderBottomWidth(kBorderBottom);
222 div1_style->setBorderBottomStyle(BorderStyleSolid);
223 div1_style->setBorderLeftWidth(kBorderLeft);
224 div1_style->setBorderLeftStyle(BorderStyleSolid);
225
226 div1_style->setPaddingTop(Length(kPaddingTop, Fixed));
227 div1_style->setPaddingRight(Length(kPaddingRight, Fixed));
228 div1_style->setPaddingBottom(Length(kPaddingBottom, Fixed));
229 div1_style->setPaddingLeft(Length(kPaddingLeft, Fixed));
230 NGBox* div1 = new NGBox(div1_style.get());
231
232 RefPtr<ComputedStyle> div2_style = ComputedStyle::create();
233 NGBox* div2 = new NGBox(div2_style.get());
234
235 div1->SetFirstChild(div2);
236
237 NGConstraintSpace* space = new NGConstraintSpace(
238 HorizontalTopBottom, NGLogicalSize(LayoutUnit(1000), NGSizeIndefinite));
239 NGBlockLayoutAlgorithm algorithm(style_, div1);
240 NGPhysicalFragment* frag;
241 while (!algorithm.Layout(space, &frag))
242 ;
243
244 ASSERT_EQ(frag->Children().size(), 1UL);
245
246 // div1
247 const NGPhysicalFragmentBase* child = frag->Children()[0];
248 EXPECT_EQ(kBorderLeft + kPaddingLeft + kWidth + kPaddingRight + kBorderRight,
249 child->Width());
250 EXPECT_EQ(kBorderTop + kPaddingTop + kHeight + kPaddingBottom + kBorderBottom,
251 child->Height());
252
253 ASSERT_TRUE(child->Type() == NGPhysicalFragmentBase::FragmentBox);
254 ASSERT_EQ(static_cast<const NGPhysicalFragment*>(child)->Children().size(),
255 1UL);
256
257 // div2
258 child = static_cast<const NGPhysicalFragment*>(child)->Children()[0];
259 EXPECT_EQ(kBorderTop + kPaddingTop, child->TopOffset());
260 EXPECT_EQ(kBorderLeft + kPaddingLeft, child->LeftOffset());
261 }
188 } // namespace 262 } // namespace
189 } // namespace blink 263 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698