| 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_absolute_utils.h" | 7 #include "core/layout/ng/ng_absolute_utils.h" |
| 8 #include "core/layout/ng/ng_block_child_iterator.h" | 8 #include "core/layout/ng/ng_block_child_iterator.h" |
| 9 #include "core/layout/ng/ng_box_fragment.h" | 9 #include "core/layout/ng/ng_box_fragment.h" |
| 10 #include "core/layout/ng/ng_constraint_space.h" | 10 #include "core/layout/ng/ng_constraint_space.h" |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 if (ConstraintSpace().HasBlockFragmentation()) | 270 if (ConstraintSpace().HasBlockFragmentation()) |
| 271 FinalizeForFragmentation(); | 271 FinalizeForFragmentation(); |
| 272 | 272 |
| 273 return builder_.ToBoxFragment(); | 273 return builder_.ToBoxFragment(); |
| 274 } | 274 } |
| 275 | 275 |
| 276 void NGBlockLayoutAlgorithm::PrepareChildLayout(NGLayoutInputNode* child) { | 276 void NGBlockLayoutAlgorithm::PrepareChildLayout(NGLayoutInputNode* child) { |
| 277 DCHECK(child); | 277 DCHECK(child); |
| 278 | 278 |
| 279 // Calculate margins in parent's writing mode. | 279 // Calculate margins in parent's writing mode. |
| 280 curr_child_margins_ = CalculateMargins( | 280 curr_child_margins_ = ComputeMarginsForChild( |
| 281 child, *space_builder_.ToConstraintSpace( | 281 *space_builder_.ToConstraintSpace( |
| 282 FromPlatformWritingMode(Style().getWritingMode()))); | 282 FromPlatformWritingMode(Style().getWritingMode())), |
| 283 child); |
| 283 | 284 |
| 284 // Set estimated BFC offset to the next child's constraint space. | 285 // Set estimated BFC offset to the next child's constraint space. |
| 285 curr_bfc_offset_ = builder_.BfcOffset() ? builder_.BfcOffset().value() | 286 curr_bfc_offset_ = builder_.BfcOffset() ? builder_.BfcOffset().value() |
| 286 : ConstraintSpace().BfcOffset(); | 287 : ConstraintSpace().BfcOffset(); |
| 287 curr_bfc_offset_.block_offset += content_size_; | 288 curr_bfc_offset_.block_offset += content_size_; |
| 288 curr_bfc_offset_.inline_offset += border_and_padding_.inline_start; | 289 curr_bfc_offset_.inline_offset += border_and_padding_.inline_start; |
| 289 | 290 |
| 290 bool is_floating = child->IsBlock() && child->Style().isFloating(); | 291 bool is_floating = child->IsBlock() && child->Style().isFloating(); |
| 291 | 292 |
| 292 bool should_position_pending_floats = | 293 bool should_position_pending_floats = |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 builder_.SetBlockSize(space_left); | 457 builder_.SetBlockSize(space_left); |
| 457 builder_.SetBlockOverflow(space_left); | 458 builder_.SetBlockOverflow(space_left); |
| 458 return; | 459 return; |
| 459 } | 460 } |
| 460 | 461 |
| 461 // The end of the block fits in the current fragmentainer. | 462 // The end of the block fits in the current fragmentainer. |
| 462 builder_.SetBlockSize(block_size); | 463 builder_.SetBlockSize(block_size); |
| 463 builder_.SetBlockOverflow(content_size_); | 464 builder_.SetBlockOverflow(content_size_); |
| 464 } | 465 } |
| 465 | 466 |
| 466 NGBoxStrut NGBlockLayoutAlgorithm::CalculateMargins( | |
| 467 NGLayoutInputNode* child, | |
| 468 const NGConstraintSpace& space) { | |
| 469 DCHECK(child); | |
| 470 const ComputedStyle& child_style = child->Style(); | |
| 471 | |
| 472 WTF::Optional<MinMaxContentSize> sizes; | |
| 473 if (NeedMinMaxContentSize(space, child_style)) | |
| 474 sizes = child->ComputeMinMaxContentSize(); | |
| 475 | |
| 476 LayoutUnit child_inline_size = | |
| 477 ComputeInlineSizeForFragment(space, child_style, sizes); | |
| 478 NGBoxStrut margins = ComputeMargins(space, child_style, space.WritingMode(), | |
| 479 space.Direction()); | |
| 480 if (!child_style.isFloating()) { | |
| 481 ApplyAutoMargins(space, child_style, child_inline_size, &margins); | |
| 482 } | |
| 483 return margins; | |
| 484 } | |
| 485 | |
| 486 RefPtr<NGConstraintSpace> NGBlockLayoutAlgorithm::CreateConstraintSpaceForChild( | 467 RefPtr<NGConstraintSpace> NGBlockLayoutAlgorithm::CreateConstraintSpaceForChild( |
| 487 NGLayoutInputNode* child) { | 468 NGLayoutInputNode* child) { |
| 488 DCHECK(child); | 469 DCHECK(child); |
| 489 | 470 |
| 490 const ComputedStyle& child_style = child->Style(); | 471 const ComputedStyle& child_style = child->Style(); |
| 491 bool is_new_bfc = IsNewFormattingContextForBlockLevelChild(Style(), *child); | 472 bool is_new_bfc = IsNewFormattingContextForBlockLevelChild(Style(), *child); |
| 492 space_builder_.SetIsNewFormattingContext(is_new_bfc) | 473 space_builder_.SetIsNewFormattingContext(is_new_bfc) |
| 493 .SetBfcOffset(curr_bfc_offset_); | 474 .SetBfcOffset(curr_bfc_offset_); |
| 494 | 475 |
| 495 if (child->IsInline()) { | 476 if (child->IsInline()) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 521 DCHECK(builder_.BfcOffset()); | 502 DCHECK(builder_.BfcOffset()); |
| 522 space_available -= curr_bfc_offset_.block_offset; | 503 space_available -= curr_bfc_offset_.block_offset; |
| 523 } | 504 } |
| 524 } | 505 } |
| 525 space_builder_.SetFragmentainerSpaceAvailable(space_available); | 506 space_builder_.SetFragmentainerSpaceAvailable(space_available); |
| 526 | 507 |
| 527 return space_builder_.ToConstraintSpace( | 508 return space_builder_.ToConstraintSpace( |
| 528 FromPlatformWritingMode(child_style.getWritingMode())); | 509 FromPlatformWritingMode(child_style.getWritingMode())); |
| 529 } | 510 } |
| 530 } // namespace blink | 511 } // namespace blink |
| OLD | NEW |