| 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_break_token.h" | 8 #include "core/layout/ng/ng_block_break_token.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_column_mapper.h" | 10 #include "core/layout/ng/ng_column_mapper.h" |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 LayoutUnit inline_offset = | 349 LayoutUnit inline_offset = |
| 350 border_and_padding_.inline_start + curr_child_margins_.inline_start; | 350 border_and_padding_.inline_start + curr_child_margins_.inline_start; |
| 351 LayoutUnit block_offset = content_size_; | 351 LayoutUnit block_offset = content_size_; |
| 352 if (known_fragment_offset) { | 352 if (known_fragment_offset) { |
| 353 block_offset = known_fragment_offset.value().block_offset - | 353 block_offset = known_fragment_offset.value().block_offset - |
| 354 builder_->BfcOffset().value().block_offset; | 354 builder_->BfcOffset().value().block_offset; |
| 355 } | 355 } |
| 356 return {inline_offset, block_offset}; | 356 return {inline_offset, block_offset}; |
| 357 } | 357 } |
| 358 | 358 |
| 359 RefPtr<NGPhysicalFragment> NGBlockLayoutAlgorithm::Layout() { | 359 RefPtr<NGLayoutResult> NGBlockLayoutAlgorithm::Layout() { |
| 360 WTF::Optional<MinAndMaxContentSizes> sizes; | 360 WTF::Optional<MinAndMaxContentSizes> sizes; |
| 361 if (NeedMinAndMaxContentSizes(ConstraintSpace(), Style())) | 361 if (NeedMinAndMaxContentSizes(ConstraintSpace(), Style())) |
| 362 sizes = ComputeMinAndMaxContentSizes(); | 362 sizes = ComputeMinAndMaxContentSizes(); |
| 363 | 363 |
| 364 border_and_padding_ = | 364 border_and_padding_ = |
| 365 ComputeBorders(Style()) + ComputePadding(ConstraintSpace(), Style()); | 365 ComputeBorders(Style()) + ComputePadding(ConstraintSpace(), Style()); |
| 366 | 366 |
| 367 LayoutUnit inline_size = | 367 LayoutUnit inline_size = |
| 368 ComputeInlineSizeForFragment(ConstraintSpace(), Style(), sizes); | 368 ComputeInlineSizeForFragment(ConstraintSpace(), Style(), sizes); |
| 369 LayoutUnit adjusted_inline_size = | 369 LayoutUnit adjusted_inline_size = |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 | 446 |
| 447 DCHECK(!ConstraintSpace().HasBlockFragmentation() || | 447 DCHECK(!ConstraintSpace().HasBlockFragmentation() || |
| 448 SpaceAvailableForCurrentChild() > LayoutUnit()); | 448 SpaceAvailableForCurrentChild() > LayoutUnit()); |
| 449 space_for_current_child_ = CreateConstraintSpaceForCurrentChild(); | 449 space_for_current_child_ = CreateConstraintSpaceForCurrentChild(); |
| 450 | 450 |
| 451 if (current_child_->Type() == NGLayoutInputNode::kLegacyInline) { | 451 if (current_child_->Type() == NGLayoutInputNode::kLegacyInline) { |
| 452 LayoutInlineChildren(toNGInlineNode(current_child_)); | 452 LayoutInlineChildren(toNGInlineNode(current_child_)); |
| 453 continue; | 453 continue; |
| 454 } | 454 } |
| 455 | 455 |
| 456 RefPtr<NGPhysicalFragment> physical_fragment = | 456 RefPtr<NGLayoutResult> layout_result = |
| 457 current_child_->Layout(space_for_current_child_); | 457 current_child_->Layout(space_for_current_child_); |
| 458 | 458 |
| 459 FinishCurrentChildLayout(toNGPhysicalBoxFragment(physical_fragment.get())); | 459 FinishCurrentChildLayout(layout_result); |
| 460 | 460 |
| 461 if (!ProceedToNextUnfinishedSibling(physical_fragment.get())) | 461 if (!ProceedToNextUnfinishedSibling( |
| 462 layout_result->PhysicalFragment().get())) |
| 462 break; | 463 break; |
| 463 } | 464 } |
| 464 | 465 |
| 465 // Margins collapsing: | 466 // Margins collapsing: |
| 466 // Bottom margins of an in-flow block box doesn't collapse with its last | 467 // Bottom margins of an in-flow block box doesn't collapse with its last |
| 467 // in-flow block-level child's bottom margin if the box has bottom | 468 // in-flow block-level child's bottom margin if the box has bottom |
| 468 // border/padding. | 469 // border/padding. |
| 469 content_size_ += border_and_padding_.block_end; | 470 content_size_ += border_and_padding_.block_end; |
| 470 if (border_and_padding_.block_end || | 471 if (border_and_padding_.block_end || |
| 471 ConstraintSpace().IsNewFormattingContext()) { | 472 ConstraintSpace().IsNewFormattingContext()) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 void NGBlockLayoutAlgorithm::LayoutInlineChildren(NGInlineNode* current_child) { | 510 void NGBlockLayoutAlgorithm::LayoutInlineChildren(NGInlineNode* current_child) { |
| 510 // TODO(kojii): This logic does not handle when children are mix of | 511 // TODO(kojii): This logic does not handle when children are mix of |
| 511 // inline/block. We need to detect the case and setup appropriately; e.g., | 512 // inline/block. We need to detect the case and setup appropriately; e.g., |
| 512 // constraint space, margin collapsing, next siblings, etc. | 513 // constraint space, margin collapsing, next siblings, etc. |
| 513 NGLineBuilder line_builder(current_child, space_for_current_child_); | 514 NGLineBuilder line_builder(current_child, space_for_current_child_); |
| 514 current_child->LayoutInline(space_for_current_child_, &line_builder); | 515 current_child->LayoutInline(space_for_current_child_, &line_builder); |
| 515 // TODO(kojii): The wrapper fragment should not be needed. | 516 // TODO(kojii): The wrapper fragment should not be needed. |
| 516 NGFragmentBuilder wrapper_fragment_builder(NGPhysicalFragment::kFragmentBox, | 517 NGFragmentBuilder wrapper_fragment_builder(NGPhysicalFragment::kFragmentBox, |
| 517 current_child); | 518 current_child); |
| 518 line_builder.CreateFragments(&wrapper_fragment_builder); | 519 line_builder.CreateFragments(&wrapper_fragment_builder); |
| 519 RefPtr<NGPhysicalBoxFragment> child_fragment = | 520 RefPtr<NGLayoutResult> child_result = |
| 520 wrapper_fragment_builder.ToBoxFragment(); | 521 wrapper_fragment_builder.ToBoxFragment(); |
| 521 line_builder.CopyFragmentDataToLayoutBlockFlow(); | 522 line_builder.CopyFragmentDataToLayoutBlockFlow(); |
| 522 FinishCurrentChildLayout(child_fragment.get()); | 523 FinishCurrentChildLayout(child_result); |
| 523 current_child_ = nullptr; | 524 current_child_ = nullptr; |
| 524 } | 525 } |
| 525 | 526 |
| 526 void NGBlockLayoutAlgorithm::FinishCurrentChildLayout( | 527 void NGBlockLayoutAlgorithm::FinishCurrentChildLayout( |
| 527 RefPtr<NGPhysicalBoxFragment> physical_fragment) { | 528 RefPtr<NGLayoutResult> layout_result) { |
| 528 NGBoxFragment fragment(ConstraintSpace().WritingMode(), | 529 NGBoxFragment fragment( |
| 529 physical_fragment.get()); | 530 ConstraintSpace().WritingMode(), |
| 531 toNGPhysicalBoxFragment(layout_result->PhysicalFragment().get())); |
| 530 | 532 |
| 531 // Pull out unpositioned floats to the current fragment. This may needed if | 533 // Pull out unpositioned floats to the current fragment. This may needed if |
| 532 // for example the child fragment could not position its floats because it's | 534 // for example the child fragment could not position its floats because it's |
| 533 // empty and therefore couldn't determine its position in space. | 535 // empty and therefore couldn't determine its position in space. |
| 534 builder_->MutableUnpositionedFloats().appendVector( | 536 builder_->MutableUnpositionedFloats().appendVector( |
| 535 physical_fragment->UnpositionedFloats()); | 537 layout_result->UnpositionedFloats()); |
| 536 | 538 |
| 537 if (current_child_->Type() == NGLayoutInputNode::kLegacyBlock && | 539 if (current_child_->Type() == NGLayoutInputNode::kLegacyBlock && |
| 538 CurrentChildStyle().isFloating()) { | 540 CurrentChildStyle().isFloating()) { |
| 539 NGFloatingObject* floating_object = | 541 NGFloatingObject* floating_object = new NGFloatingObject( |
| 540 new NGFloatingObject(physical_fragment.get(), space_for_current_child_, | 542 layout_result->PhysicalFragment().get(), space_for_current_child_, |
| 541 constraint_space_, toNGBlockNode(current_child_), | 543 constraint_space_, toNGBlockNode(current_child_), CurrentChildStyle(), |
| 542 CurrentChildStyle(), curr_child_margins_); | 544 curr_child_margins_); |
| 543 builder_->AddUnpositionedFloat(floating_object); | 545 builder_->AddUnpositionedFloat(floating_object); |
| 544 // No need to postpone the positioning if we know the correct offset. | 546 // No need to postpone the positioning if we know the correct offset. |
| 545 if (builder_->BfcOffset()) { | 547 if (builder_->BfcOffset()) { |
| 546 NGLogicalOffset origin_point = curr_bfc_offset_; | 548 NGLogicalOffset origin_point = curr_bfc_offset_; |
| 547 // Adjust origin point to the margins of the last child. | 549 // Adjust origin point to the margins of the last child. |
| 548 // Example: <div style="margin-bottom: 20px"><float></div> | 550 // Example: <div style="margin-bottom: 20px"><float></div> |
| 549 // <div style="margin-bottom: 30px"></div> | 551 // <div style="margin-bottom: 30px"></div> |
| 550 origin_point.block_offset += curr_margin_strut_.Sum(); | 552 origin_point.block_offset += curr_margin_strut_.Sum(); |
| 551 PositionPendingFloats(origin_point.block_offset, ConstraintSpace(), | 553 PositionPendingFloats(origin_point.block_offset, ConstraintSpace(), |
| 552 builder_.get()); | 554 builder_.get()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 // <div style="margin-top: 8px"></div> | 599 // <div style="margin-top: 8px"></div> |
| 598 // <div style="margin-top: 10px"></div> | 600 // <div style="margin-top: 10px"></div> |
| 599 // </div> | 601 // </div> |
| 600 if (fragment.BlockSize()) | 602 if (fragment.BlockSize()) |
| 601 content_size_ = fragment.BlockSize() + logical_offset.block_offset; | 603 content_size_ = fragment.BlockSize() + logical_offset.block_offset; |
| 602 max_inline_size_ = | 604 max_inline_size_ = |
| 603 std::max(max_inline_size_, fragment.InlineSize() + | 605 std::max(max_inline_size_, fragment.InlineSize() + |
| 604 curr_child_margins_.InlineSum() + | 606 curr_child_margins_.InlineSum() + |
| 605 border_and_padding_.InlineSum()); | 607 border_and_padding_.InlineSum()); |
| 606 | 608 |
| 607 builder_->AddChild(std::move(physical_fragment), logical_offset); | 609 builder_->AddChild(layout_result, logical_offset); |
| 608 } | 610 } |
| 609 | 611 |
| 610 bool NGBlockLayoutAlgorithm::ProceedToNextUnfinishedSibling( | 612 bool NGBlockLayoutAlgorithm::ProceedToNextUnfinishedSibling( |
| 611 NGPhysicalFragment* child_fragment) { | 613 NGPhysicalFragment* child_fragment) { |
| 612 DCHECK(current_child_); | 614 DCHECK(current_child_); |
| 613 NGBlockNode* finished_child = toNGBlockNode(current_child_); | 615 NGBlockNode* finished_child = toNGBlockNode(current_child_); |
| 614 current_child_ = current_child_->NextSibling(); | 616 current_child_ = current_child_->NextSibling(); |
| 615 if (!ConstraintSpace().HasBlockFragmentation() && !fragmentainer_mapper_) | 617 if (!ConstraintSpace().HasBlockFragmentation() && !fragmentainer_mapper_) |
| 616 return true; | 618 return true; |
| 617 // If we're resuming layout after a fragmentainer break, we need to skip | 619 // If we're resuming layout after a fragmentainer break, we need to skip |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 space_builder_->SetMarginStrut(curr_margin_strut_); | 836 space_builder_->SetMarginStrut(curr_margin_strut_); |
| 835 } | 837 } |
| 836 | 838 |
| 837 space_builder_->SetBfcOffset(curr_bfc_offset_); | 839 space_builder_->SetBfcOffset(curr_bfc_offset_); |
| 838 | 840 |
| 839 return space_builder_->ToConstraintSpace( | 841 return space_builder_->ToConstraintSpace( |
| 840 FromPlatformWritingMode(current_child_style.getWritingMode())); | 842 FromPlatformWritingMode(current_child_style.getWritingMode())); |
| 841 } | 843 } |
| 842 | 844 |
| 843 } // namespace blink | 845 } // namespace blink |
| OLD | NEW |