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

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

Issue 2724133003: [LayoutNG] Switch NGConstraintSpace to being RefCounted. (Closed)
Patch Set: moar. Created 3 years, 9 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_length_utils.h" 5 #include "core/layout/ng/ng_length_utils.h"
6 6
7 #include "core/layout/ng/ng_box_fragment.h" 7 #include "core/layout/ng/ng_box_fragment.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_constraint_space_builder.h" 9 #include "core/layout/ng/ng_constraint_space_builder.h"
10 #include "core/layout/ng/ng_fragment_builder.h" 10 #include "core/layout/ng/ng_fragment_builder.h"
11 #include "core/layout/ng/ng_physical_box_fragment.h" 11 #include "core/layout/ng/ng_physical_box_fragment.h"
12 #include "core/layout/ng/ng_units.h" 12 #include "core/layout/ng/ng_units.h"
13 #include "core/style/ComputedStyle.h" 13 #include "core/style/ComputedStyle.h"
14 #include "platform/CalculationValue.h" 14 #include "platform/CalculationValue.h"
15 #include "platform/LayoutUnit.h" 15 #include "platform/LayoutUnit.h"
16 #include "platform/Length.h" 16 #include "platform/Length.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "wtf/RefPtr.h" 18 #include "wtf/RefPtr.h"
19 19
20 namespace blink { 20 namespace blink {
21 namespace { 21 namespace {
22 22
23 class NGLengthUtilsTest : public ::testing::Test { 23 class NGLengthUtilsTest : public ::testing::Test {
24 protected: 24 protected:
25 void SetUp() override { style_ = ComputedStyle::create(); } 25 void SetUp() override { style_ = ComputedStyle::create(); }
26 26
27 static NGConstraintSpace* ConstructConstraintSpace(int inline_size, 27 static RefPtr<NGConstraintSpace> ConstructConstraintSpace(
28 int block_size, 28 int inline_size,
29 bool fixed_inline = false, 29 int block_size,
30 bool fixed_block = false) { 30 bool fixed_inline = false,
31 bool fixed_block = false) {
31 return NGConstraintSpaceBuilder(kHorizontalTopBottom) 32 return NGConstraintSpaceBuilder(kHorizontalTopBottom)
32 .SetAvailableSize( 33 .SetAvailableSize(
33 NGLogicalSize(LayoutUnit(inline_size), LayoutUnit(block_size))) 34 NGLogicalSize(LayoutUnit(inline_size), LayoutUnit(block_size)))
34 .SetPercentageResolutionSize( 35 .SetPercentageResolutionSize(
35 NGLogicalSize(LayoutUnit(inline_size), LayoutUnit(block_size))) 36 NGLogicalSize(LayoutUnit(inline_size), LayoutUnit(block_size)))
36 .SetIsFixedSizeInline(fixed_inline) 37 .SetIsFixedSizeInline(fixed_inline)
37 .SetIsFixedSizeBlock(fixed_block) 38 .SetIsFixedSizeBlock(fixed_block)
38 .ToConstraintSpace(kHorizontalTopBottom); 39 .ToConstraintSpace(kHorizontalTopBottom);
39 } 40 }
40 41
41 LayoutUnit ResolveInlineLength( 42 LayoutUnit ResolveInlineLength(
42 const Length& length, 43 const Length& length,
43 LengthResolveType type = LengthResolveType::kContentSize, 44 LengthResolveType type = LengthResolveType::kContentSize,
44 const WTF::Optional<MinAndMaxContentSizes>& sizes = WTF::nullopt) { 45 const WTF::Optional<MinAndMaxContentSizes>& sizes = WTF::nullopt) {
45 NGConstraintSpace* constraintSpace = ConstructConstraintSpace(200, 300); 46 RefPtr<NGConstraintSpace> constraintSpace =
47 ConstructConstraintSpace(200, 300);
46 return ::blink::ResolveInlineLength(*constraintSpace, *style_, sizes, 48 return ::blink::ResolveInlineLength(*constraintSpace, *style_, sizes,
47 length, type); 49 length, type);
48 } 50 }
49 51
50 LayoutUnit ResolveBlockLength( 52 LayoutUnit ResolveBlockLength(
51 const Length& length, 53 const Length& length,
52 LengthResolveType type = LengthResolveType::kContentSize, 54 LengthResolveType type = LengthResolveType::kContentSize,
53 LayoutUnit contentSize = LayoutUnit()) { 55 LayoutUnit contentSize = LayoutUnit()) {
54 NGConstraintSpace* constraintSpace = ConstructConstraintSpace(200, 300); 56 RefPtr<NGConstraintSpace> constraintSpace =
57 ConstructConstraintSpace(200, 300);
55 return ::blink::ResolveBlockLength(*constraintSpace, *style_, length, 58 return ::blink::ResolveBlockLength(*constraintSpace, *style_, length,
56 contentSize, type); 59 contentSize, type);
57 } 60 }
58 61
59 LayoutUnit ComputeInlineSizeForFragment( 62 LayoutUnit ComputeInlineSizeForFragment(
60 const NGConstraintSpace* constraintSpace = ConstructConstraintSpace(200, 63 RefPtr<const NGConstraintSpace> constraintSpace =
61 300), 64 ConstructConstraintSpace(200, 300),
62 const MinAndMaxContentSizes& sizes = MinAndMaxContentSizes()) { 65 const MinAndMaxContentSizes& sizes = MinAndMaxContentSizes()) {
63 return ::blink::ComputeInlineSizeForFragment(*constraintSpace, *style_, 66 return ::blink::ComputeInlineSizeForFragment(*constraintSpace, *style_,
64 sizes); 67 sizes);
65 } 68 }
66 69
67 LayoutUnit ComputeBlockSizeForFragment( 70 LayoutUnit ComputeBlockSizeForFragment(
68 const NGConstraintSpace* constraintSpace = ConstructConstraintSpace(200, 71 RefPtr<const NGConstraintSpace> constraintSpace =
69 300), 72 ConstructConstraintSpace(200, 300),
70 LayoutUnit contentSize = LayoutUnit()) { 73 LayoutUnit contentSize = LayoutUnit()) {
71 return ::blink::ComputeBlockSizeForFragment(*constraintSpace, *style_, 74 return ::blink::ComputeBlockSizeForFragment(*constraintSpace, *style_,
72 contentSize); 75 contentSize);
73 } 76 }
74 77
75 RefPtr<ComputedStyle> style_; 78 RefPtr<ComputedStyle> style_;
76 }; 79 };
77 80
78 TEST_F(NGLengthUtilsTest, testResolveInlineLength) { 81 TEST_F(NGLengthUtilsTest, testResolveInlineLength) {
79 EXPECT_EQ(LayoutUnit(60), ResolveInlineLength(Length(30, Percent))); 82 EXPECT_EQ(LayoutUnit(60), ResolveInlineLength(Length(30, Percent)));
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 style_->setLogicalWidth(Length(Auto)); 210 style_->setLogicalWidth(Length(Auto));
208 EXPECT_EQ(LayoutUnit(200), ComputeInlineSizeForFragment()); 211 EXPECT_EQ(LayoutUnit(200), ComputeInlineSizeForFragment());
209 212
210 style_->setLogicalWidth(Length(FillAvailable)); 213 style_->setLogicalWidth(Length(FillAvailable));
211 EXPECT_EQ(LayoutUnit(200), ComputeInlineSizeForFragment()); 214 EXPECT_EQ(LayoutUnit(200), ComputeInlineSizeForFragment());
212 215
213 style_->setLogicalWidth(Length(CalculationValue::create( 216 style_->setLogicalWidth(Length(CalculationValue::create(
214 PixelsAndPercent(100, -10), ValueRangeNonNegative))); 217 PixelsAndPercent(100, -10), ValueRangeNonNegative)));
215 EXPECT_EQ(LayoutUnit(80), ComputeInlineSizeForFragment()); 218 EXPECT_EQ(LayoutUnit(80), ComputeInlineSizeForFragment());
216 219
217 NGConstraintSpace* constraintSpace = 220 RefPtr<NGConstraintSpace> constraintSpace =
218 ConstructConstraintSpace(120, 120, true, true); 221 ConstructConstraintSpace(120, 120, true, true);
219 style_->setLogicalWidth(Length(150, Fixed)); 222 style_->setLogicalWidth(Length(150, Fixed));
220 EXPECT_EQ(LayoutUnit(120), ComputeInlineSizeForFragment(constraintSpace)); 223 EXPECT_EQ(LayoutUnit(120), ComputeInlineSizeForFragment(constraintSpace));
221 224
222 style_->setLogicalWidth(Length(200, Fixed)); 225 style_->setLogicalWidth(Length(200, Fixed));
223 style_->setMaxWidth(Length(80, Percent)); 226 style_->setMaxWidth(Length(80, Percent));
224 EXPECT_EQ(LayoutUnit(160), ComputeInlineSizeForFragment()); 227 EXPECT_EQ(LayoutUnit(160), ComputeInlineSizeForFragment());
225 228
226 style_->setLogicalWidth(Length(100, Fixed)); 229 style_->setLogicalWidth(Length(100, Fixed));
227 style_->setMinWidth(Length(80, Percent)); 230 style_->setMinWidth(Length(80, Percent));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 ComputeBlockSizeForFragment(ConstructConstraintSpace(200, 300), 280 ComputeBlockSizeForFragment(ConstructConstraintSpace(200, 300),
278 LayoutUnit(120))); 281 LayoutUnit(120)));
279 282
280 style_->setLogicalHeight(Length(FillAvailable)); 283 style_->setLogicalHeight(Length(FillAvailable));
281 EXPECT_EQ(LayoutUnit(300), ComputeBlockSizeForFragment()); 284 EXPECT_EQ(LayoutUnit(300), ComputeBlockSizeForFragment());
282 285
283 style_->setLogicalHeight(Length(CalculationValue::create( 286 style_->setLogicalHeight(Length(CalculationValue::create(
284 PixelsAndPercent(100, -10), ValueRangeNonNegative))); 287 PixelsAndPercent(100, -10), ValueRangeNonNegative)));
285 EXPECT_EQ(LayoutUnit(70), ComputeBlockSizeForFragment()); 288 EXPECT_EQ(LayoutUnit(70), ComputeBlockSizeForFragment());
286 289
287 NGConstraintSpace* constraintSpace = 290 RefPtr<NGConstraintSpace> constraintSpace =
288 ConstructConstraintSpace(200, 200, true, true); 291 ConstructConstraintSpace(200, 200, true, true);
289 style_->setLogicalHeight(Length(150, Fixed)); 292 style_->setLogicalHeight(Length(150, Fixed));
290 EXPECT_EQ(LayoutUnit(200), ComputeBlockSizeForFragment(constraintSpace)); 293 EXPECT_EQ(LayoutUnit(200), ComputeBlockSizeForFragment(constraintSpace));
291 294
292 style_->setLogicalHeight(Length(300, Fixed)); 295 style_->setLogicalHeight(Length(300, Fixed));
293 style_->setMaxHeight(Length(80, Percent)); 296 style_->setMaxHeight(Length(80, Percent));
294 EXPECT_EQ(LayoutUnit(240), ComputeBlockSizeForFragment()); 297 EXPECT_EQ(LayoutUnit(240), ComputeBlockSizeForFragment());
295 298
296 style_->setLogicalHeight(Length(100, Fixed)); 299 style_->setLogicalHeight(Length(100, Fixed));
297 style_->setMinHeight(Length(80, Percent)); 300 style_->setMinHeight(Length(80, Percent));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 ComputeBlockSizeForFragment(ConstructConstraintSpace(200, -1), 338 ComputeBlockSizeForFragment(ConstructConstraintSpace(200, -1),
336 LayoutUnit(120))); 339 LayoutUnit(120)));
337 } 340 }
338 341
339 TEST_F(NGLengthUtilsTest, testMargins) { 342 TEST_F(NGLengthUtilsTest, testMargins) {
340 style_->setMarginTop(Length(10, Percent)); 343 style_->setMarginTop(Length(10, Percent));
341 style_->setMarginRight(Length(52, Fixed)); 344 style_->setMarginRight(Length(52, Fixed));
342 style_->setMarginBottom(Length(Auto)); 345 style_->setMarginBottom(Length(Auto));
343 style_->setMarginLeft(Length(11, Percent)); 346 style_->setMarginLeft(Length(11, Percent));
344 347
345 NGConstraintSpace* constraintSpace(ConstructConstraintSpace(200, 300)); 348 RefPtr<NGConstraintSpace> constraintSpace(ConstructConstraintSpace(200, 300));
346 349
347 NGBoxStrut margins = ComputeMargins( 350 NGBoxStrut margins = ComputeMargins(
348 *constraintSpace, *style_, kHorizontalTopBottom, TextDirection::kLtr); 351 *constraintSpace, *style_, kHorizontalTopBottom, TextDirection::kLtr);
349 352
350 EXPECT_EQ(LayoutUnit(20), margins.block_start); 353 EXPECT_EQ(LayoutUnit(20), margins.block_start);
351 EXPECT_EQ(LayoutUnit(52), margins.inline_end); 354 EXPECT_EQ(LayoutUnit(52), margins.inline_end);
352 EXPECT_EQ(LayoutUnit(), margins.block_end); 355 EXPECT_EQ(LayoutUnit(), margins.block_end);
353 EXPECT_EQ(LayoutUnit(22), margins.inline_start); 356 EXPECT_EQ(LayoutUnit(22), margins.inline_start);
354 } 357 }
355 358
356 TEST_F(NGLengthUtilsTest, testBorders) { 359 TEST_F(NGLengthUtilsTest, testBorders) {
357 style_->setBorderTopWidth(1); 360 style_->setBorderTopWidth(1);
358 style_->setBorderRightWidth(2); 361 style_->setBorderRightWidth(2);
359 style_->setBorderBottomWidth(3); 362 style_->setBorderBottomWidth(3);
360 style_->setBorderLeftWidth(4); 363 style_->setBorderLeftWidth(4);
361 style_->setBorderTopStyle(BorderStyleSolid); 364 style_->setBorderTopStyle(BorderStyleSolid);
362 style_->setBorderRightStyle(BorderStyleSolid); 365 style_->setBorderRightStyle(BorderStyleSolid);
363 style_->setBorderBottomStyle(BorderStyleSolid); 366 style_->setBorderBottomStyle(BorderStyleSolid);
364 style_->setBorderLeftStyle(BorderStyleSolid); 367 style_->setBorderLeftStyle(BorderStyleSolid);
365 style_->setWritingMode(WritingMode::kVerticalLr); 368 style_->setWritingMode(WritingMode::kVerticalLr);
366 369
367 NGConstraintSpace* constraint_space(ConstructConstraintSpace(200, 300)); 370 RefPtr<NGConstraintSpace> constraint_space(
371 ConstructConstraintSpace(200, 300));
368 372
369 NGBoxStrut borders = ComputeBorders(*constraint_space, *style_); 373 NGBoxStrut borders = ComputeBorders(*constraint_space, *style_);
370 374
371 EXPECT_EQ(LayoutUnit(4), borders.block_start); 375 EXPECT_EQ(LayoutUnit(4), borders.block_start);
372 EXPECT_EQ(LayoutUnit(3), borders.inline_end); 376 EXPECT_EQ(LayoutUnit(3), borders.inline_end);
373 EXPECT_EQ(LayoutUnit(2), borders.block_end); 377 EXPECT_EQ(LayoutUnit(2), borders.block_end);
374 EXPECT_EQ(LayoutUnit(1), borders.inline_start); 378 EXPECT_EQ(LayoutUnit(1), borders.inline_start);
375 } 379 }
376 380
377 TEST_F(NGLengthUtilsTest, testPadding) { 381 TEST_F(NGLengthUtilsTest, testPadding) {
378 style_->setPaddingTop(Length(10, Percent)); 382 style_->setPaddingTop(Length(10, Percent));
379 style_->setPaddingRight(Length(52, Fixed)); 383 style_->setPaddingRight(Length(52, Fixed));
380 style_->setPaddingBottom(Length(Auto)); 384 style_->setPaddingBottom(Length(Auto));
381 style_->setPaddingLeft(Length(11, Percent)); 385 style_->setPaddingLeft(Length(11, Percent));
382 style_->setWritingMode(WritingMode::kVerticalRl); 386 style_->setWritingMode(WritingMode::kVerticalRl);
383 387
384 NGConstraintSpace* constraintSpace(ConstructConstraintSpace(200, 300)); 388 RefPtr<NGConstraintSpace> constraintSpace(ConstructConstraintSpace(200, 300));
385 389
386 NGBoxStrut padding = ComputePadding(*constraintSpace, *style_); 390 NGBoxStrut padding = ComputePadding(*constraintSpace, *style_);
387 391
388 EXPECT_EQ(LayoutUnit(52), padding.block_start); 392 EXPECT_EQ(LayoutUnit(52), padding.block_start);
389 EXPECT_EQ(LayoutUnit(), padding.inline_end); 393 EXPECT_EQ(LayoutUnit(), padding.inline_end);
390 EXPECT_EQ(LayoutUnit(22), padding.block_end); 394 EXPECT_EQ(LayoutUnit(22), padding.block_end);
391 EXPECT_EQ(LayoutUnit(20), padding.inline_start); 395 EXPECT_EQ(LayoutUnit(20), padding.inline_start);
392 } 396 }
393 397
394 TEST_F(NGLengthUtilsTest, testAutoMargins) { 398 TEST_F(NGLengthUtilsTest, testAutoMargins) {
395 style_->setMarginRight(Length(Auto)); 399 style_->setMarginRight(Length(Auto));
396 style_->setMarginLeft(Length(Auto)); 400 style_->setMarginLeft(Length(Auto));
397 401
398 LayoutUnit kInlineSize = LayoutUnit(150); 402 LayoutUnit kInlineSize = LayoutUnit(150);
399 NGConstraintSpace* constraint_space(ConstructConstraintSpace(200, 300)); 403 RefPtr<NGConstraintSpace> constraint_space(
404 ConstructConstraintSpace(200, 300));
400 405
401 NGBoxStrut margins; 406 NGBoxStrut margins;
402 ApplyAutoMargins(*constraint_space, *style_, kInlineSize, &margins); 407 ApplyAutoMargins(*constraint_space, *style_, kInlineSize, &margins);
403 408
404 EXPECT_EQ(LayoutUnit(), margins.block_start); 409 EXPECT_EQ(LayoutUnit(), margins.block_start);
405 EXPECT_EQ(LayoutUnit(), margins.block_end); 410 EXPECT_EQ(LayoutUnit(), margins.block_end);
406 EXPECT_EQ(LayoutUnit(25), margins.inline_start); 411 EXPECT_EQ(LayoutUnit(25), margins.inline_start);
407 EXPECT_EQ(LayoutUnit(25), margins.inline_end); 412 EXPECT_EQ(LayoutUnit(25), margins.inline_end);
408 413
409 style_->setMarginLeft(Length(0, Fixed)); 414 style_->setMarginLeft(Length(0, Fixed));
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 EXPECT_EQ(125, GetUsedColumnWidth(4, 100, 10, 530)); 495 EXPECT_EQ(125, GetUsedColumnWidth(4, 100, 10, 530));
491 EXPECT_EQ(4, GetUsedColumnCount(4, 100, 10, 530)); 496 EXPECT_EQ(4, GetUsedColumnCount(4, 100, 10, 530));
492 EXPECT_EQ(100, GetUsedColumnWidth(6, 100, 10, 540)); 497 EXPECT_EQ(100, GetUsedColumnWidth(6, 100, 10, 540));
493 EXPECT_EQ(5, GetUsedColumnCount(6, 100, 10, 540)); 498 EXPECT_EQ(5, GetUsedColumnCount(6, 100, 10, 540));
494 EXPECT_EQ(100, GetUsedColumnWidth(0, 100, 10, 540)); 499 EXPECT_EQ(100, GetUsedColumnWidth(0, 100, 10, 540));
495 EXPECT_EQ(5, GetUsedColumnCount(0, 100, 10, 540)); 500 EXPECT_EQ(5, GetUsedColumnCount(0, 100, 10, 540));
496 } 501 }
497 502
498 } // namespace 503 } // namespace
499 } // namespace blink 504 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698