| 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_length_utils.h" | 5 #include "core/layout/ng/ng_length_utils.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_constraint_space_builder.h" | 8 #include "core/layout/ng/ng_constraint_space_builder.h" |
| 9 #include "core/layout/ng/ng_fragment_builder.h" | 9 #include "core/layout/ng/ng_fragment_builder.h" |
| 10 #include "core/layout/ng/ng_units.h" | 10 #include "core/layout/ng/ng_units.h" |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 } | 337 } |
| 338 | 338 |
| 339 TEST_F(NGLengthUtilsTest, testMargins) { | 339 TEST_F(NGLengthUtilsTest, testMargins) { |
| 340 style_->setMarginTop(Length(10, Percent)); | 340 style_->setMarginTop(Length(10, Percent)); |
| 341 style_->setMarginRight(Length(52, Fixed)); | 341 style_->setMarginRight(Length(52, Fixed)); |
| 342 style_->setMarginBottom(Length(Auto)); | 342 style_->setMarginBottom(Length(Auto)); |
| 343 style_->setMarginLeft(Length(11, Percent)); | 343 style_->setMarginLeft(Length(11, Percent)); |
| 344 | 344 |
| 345 NGConstraintSpace* constraintSpace(ConstructConstraintSpace(200, 300)); | 345 NGConstraintSpace* constraintSpace(ConstructConstraintSpace(200, 300)); |
| 346 | 346 |
| 347 NGBoxStrut margins = ComputeMargins(*constraintSpace, *style_, | 347 NGBoxStrut margins = ComputeMargins( |
| 348 kHorizontalTopBottom, TextDirection::Ltr); | 348 *constraintSpace, *style_, kHorizontalTopBottom, TextDirection::kLtr); |
| 349 | 349 |
| 350 EXPECT_EQ(LayoutUnit(20), margins.block_start); | 350 EXPECT_EQ(LayoutUnit(20), margins.block_start); |
| 351 EXPECT_EQ(LayoutUnit(52), margins.inline_end); | 351 EXPECT_EQ(LayoutUnit(52), margins.inline_end); |
| 352 EXPECT_EQ(LayoutUnit(), margins.block_end); | 352 EXPECT_EQ(LayoutUnit(), margins.block_end); |
| 353 EXPECT_EQ(LayoutUnit(22), margins.inline_start); | 353 EXPECT_EQ(LayoutUnit(22), margins.inline_start); |
| 354 } | 354 } |
| 355 | 355 |
| 356 TEST_F(NGLengthUtilsTest, testBorders) { | 356 TEST_F(NGLengthUtilsTest, testBorders) { |
| 357 style_->setBorderTopWidth(1); | 357 style_->setBorderTopWidth(1); |
| 358 style_->setBorderRightWidth(2); | 358 style_->setBorderRightWidth(2); |
| 359 style_->setBorderBottomWidth(3); | 359 style_->setBorderBottomWidth(3); |
| 360 style_->setBorderLeftWidth(4); | 360 style_->setBorderLeftWidth(4); |
| 361 style_->setBorderTopStyle(BorderStyleSolid); | 361 style_->setBorderTopStyle(BorderStyleSolid); |
| 362 style_->setBorderRightStyle(BorderStyleSolid); | 362 style_->setBorderRightStyle(BorderStyleSolid); |
| 363 style_->setBorderBottomStyle(BorderStyleSolid); | 363 style_->setBorderBottomStyle(BorderStyleSolid); |
| 364 style_->setBorderLeftStyle(BorderStyleSolid); | 364 style_->setBorderLeftStyle(BorderStyleSolid); |
| 365 style_->setWritingMode(WritingMode::VerticalLr); | 365 style_->setWritingMode(WritingMode::kVerticalLr); |
| 366 | 366 |
| 367 NGBoxStrut borders = ComputeBorders(*style_); | 367 NGBoxStrut borders = ComputeBorders(*style_); |
| 368 | 368 |
| 369 EXPECT_EQ(LayoutUnit(4), borders.block_start); | 369 EXPECT_EQ(LayoutUnit(4), borders.block_start); |
| 370 EXPECT_EQ(LayoutUnit(3), borders.inline_end); | 370 EXPECT_EQ(LayoutUnit(3), borders.inline_end); |
| 371 EXPECT_EQ(LayoutUnit(2), borders.block_end); | 371 EXPECT_EQ(LayoutUnit(2), borders.block_end); |
| 372 EXPECT_EQ(LayoutUnit(1), borders.inline_start); | 372 EXPECT_EQ(LayoutUnit(1), borders.inline_start); |
| 373 } | 373 } |
| 374 | 374 |
| 375 TEST_F(NGLengthUtilsTest, testPadding) { | 375 TEST_F(NGLengthUtilsTest, testPadding) { |
| 376 style_->setPaddingTop(Length(10, Percent)); | 376 style_->setPaddingTop(Length(10, Percent)); |
| 377 style_->setPaddingRight(Length(52, Fixed)); | 377 style_->setPaddingRight(Length(52, Fixed)); |
| 378 style_->setPaddingBottom(Length(Auto)); | 378 style_->setPaddingBottom(Length(Auto)); |
| 379 style_->setPaddingLeft(Length(11, Percent)); | 379 style_->setPaddingLeft(Length(11, Percent)); |
| 380 style_->setWritingMode(WritingMode::VerticalRl); | 380 style_->setWritingMode(WritingMode::kVerticalRl); |
| 381 | 381 |
| 382 NGConstraintSpace* constraintSpace(ConstructConstraintSpace(200, 300)); | 382 NGConstraintSpace* constraintSpace(ConstructConstraintSpace(200, 300)); |
| 383 | 383 |
| 384 NGBoxStrut padding = ComputePadding(*constraintSpace, *style_); | 384 NGBoxStrut padding = ComputePadding(*constraintSpace, *style_); |
| 385 | 385 |
| 386 EXPECT_EQ(LayoutUnit(52), padding.block_start); | 386 EXPECT_EQ(LayoutUnit(52), padding.block_start); |
| 387 EXPECT_EQ(LayoutUnit(), padding.inline_end); | 387 EXPECT_EQ(LayoutUnit(), padding.inline_end); |
| 388 EXPECT_EQ(LayoutUnit(22), padding.block_end); | 388 EXPECT_EQ(LayoutUnit(22), padding.block_end); |
| 389 EXPECT_EQ(LayoutUnit(20), padding.inline_start); | 389 EXPECT_EQ(LayoutUnit(20), padding.inline_start); |
| 390 } | 390 } |
| 391 | 391 |
| 392 TEST_F(NGLengthUtilsTest, testAutoMargins) { | 392 TEST_F(NGLengthUtilsTest, testAutoMargins) { |
| 393 style_->setMarginRight(Length(Auto)); | 393 style_->setMarginRight(Length(Auto)); |
| 394 style_->setMarginLeft(Length(Auto)); | 394 style_->setMarginLeft(Length(Auto)); |
| 395 | 395 |
| 396 NGFragmentBuilder builder(NGPhysicalFragment::kFragmentBox); | 396 NGFragmentBuilder builder(NGPhysicalFragment::kFragmentBox); |
| 397 builder.SetInlineSize(LayoutUnit(150)); | 397 builder.SetInlineSize(LayoutUnit(150)); |
| 398 NGPhysicalBoxFragment* physical_fragment = builder.ToBoxFragment(); | 398 NGPhysicalBoxFragment* physical_fragment = builder.ToBoxFragment(); |
| 399 NGBoxFragment* fragment = new NGBoxFragment( | 399 NGBoxFragment* fragment = new NGBoxFragment( |
| 400 kHorizontalTopBottom, TextDirection::Ltr, physical_fragment); | 400 kHorizontalTopBottom, TextDirection::kLtr, physical_fragment); |
| 401 | 401 |
| 402 NGConstraintSpace* constraint_space(ConstructConstraintSpace(200, 300)); | 402 NGConstraintSpace* constraint_space(ConstructConstraintSpace(200, 300)); |
| 403 | 403 |
| 404 NGBoxStrut margins; | 404 NGBoxStrut margins; |
| 405 ApplyAutoMargins(*constraint_space, *style_, *fragment, &margins); | 405 ApplyAutoMargins(*constraint_space, *style_, *fragment, &margins); |
| 406 | 406 |
| 407 EXPECT_EQ(LayoutUnit(), margins.block_start); | 407 EXPECT_EQ(LayoutUnit(), margins.block_start); |
| 408 EXPECT_EQ(LayoutUnit(), margins.block_end); | 408 EXPECT_EQ(LayoutUnit(), margins.block_end); |
| 409 EXPECT_EQ(LayoutUnit(25), margins.inline_start); | 409 EXPECT_EQ(LayoutUnit(25), margins.inline_start); |
| 410 EXPECT_EQ(LayoutUnit(25), margins.inline_end); | 410 EXPECT_EQ(LayoutUnit(25), margins.inline_end); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 EXPECT_EQ(125, GetUsedColumnWidth(4, 100, 10, 530)); | 493 EXPECT_EQ(125, GetUsedColumnWidth(4, 100, 10, 530)); |
| 494 EXPECT_EQ(4, GetUsedColumnCount(4, 100, 10, 530)); | 494 EXPECT_EQ(4, GetUsedColumnCount(4, 100, 10, 530)); |
| 495 EXPECT_EQ(100, GetUsedColumnWidth(6, 100, 10, 540)); | 495 EXPECT_EQ(100, GetUsedColumnWidth(6, 100, 10, 540)); |
| 496 EXPECT_EQ(5, GetUsedColumnCount(6, 100, 10, 540)); | 496 EXPECT_EQ(5, GetUsedColumnCount(6, 100, 10, 540)); |
| 497 EXPECT_EQ(100, GetUsedColumnWidth(0, 100, 10, 540)); | 497 EXPECT_EQ(100, GetUsedColumnWidth(0, 100, 10, 540)); |
| 498 EXPECT_EQ(5, GetUsedColumnCount(0, 100, 10, 540)); | 498 EXPECT_EQ(5, GetUsedColumnCount(0, 100, 10, 540)); |
| 499 } | 499 } |
| 500 | 500 |
| 501 } // namespace | 501 } // namespace |
| 502 } // namespace blink | 502 } // namespace blink |
| OLD | NEW |