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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 LayoutUnit inline_offset = | 352 LayoutUnit inline_offset = |
353 border_and_padding_.inline_start + curr_child_margins_.inline_start; | 353 border_and_padding_.inline_start + curr_child_margins_.inline_start; |
354 LayoutUnit block_offset = content_size_; | 354 LayoutUnit block_offset = content_size_; |
355 if (known_fragment_offset) { | 355 if (known_fragment_offset) { |
356 block_offset = known_fragment_offset.value().block_offset - | 356 block_offset = known_fragment_offset.value().block_offset - |
357 builder_->BfcOffset().value().block_offset; | 357 builder_->BfcOffset().value().block_offset; |
358 } | 358 } |
359 return {inline_offset, block_offset}; | 359 return {inline_offset, block_offset}; |
360 } | 360 } |
361 | 361 |
362 RefPtr<NGPhysicalFragment> NGBlockLayoutAlgorithm::Layout() { | 362 RefPtr<NGLayoutResult> NGBlockLayoutAlgorithm::Layout() { |
363 WTF::Optional<MinAndMaxContentSizes> sizes; | 363 WTF::Optional<MinAndMaxContentSizes> sizes; |
364 if (NeedMinAndMaxContentSizes(ConstraintSpace(), Style())) | 364 if (NeedMinAndMaxContentSizes(ConstraintSpace(), Style())) |
365 sizes = ComputeMinAndMaxContentSizes(); | 365 sizes = ComputeMinAndMaxContentSizes(); |
366 | 366 |
367 border_and_padding_ = | 367 border_and_padding_ = |
368 ComputeBorders(Style()) + ComputePadding(ConstraintSpace(), Style()); | 368 ComputeBorders(Style()) + ComputePadding(ConstraintSpace(), Style()); |
369 | 369 |
370 LayoutUnit inline_size = | 370 LayoutUnit inline_size = |
371 ComputeInlineSizeForFragment(ConstraintSpace(), Style(), sizes); | 371 ComputeInlineSizeForFragment(ConstraintSpace(), Style(), sizes); |
372 LayoutUnit adjusted_inline_size = | 372 LayoutUnit adjusted_inline_size = |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 | 440 |
441 DCHECK(!ConstraintSpace().HasBlockFragmentation() || | 441 DCHECK(!ConstraintSpace().HasBlockFragmentation() || |
442 SpaceAvailableForCurrentChild() > LayoutUnit()); | 442 SpaceAvailableForCurrentChild() > LayoutUnit()); |
443 space_for_current_child_ = CreateConstraintSpaceForCurrentChild(); | 443 space_for_current_child_ = CreateConstraintSpaceForCurrentChild(); |
444 | 444 |
445 if (current_child_->Type() == NGLayoutInputNode::kLegacyInline) { | 445 if (current_child_->Type() == NGLayoutInputNode::kLegacyInline) { |
446 LayoutInlineChildren(toNGInlineNode(current_child_)); | 446 LayoutInlineChildren(toNGInlineNode(current_child_)); |
447 continue; | 447 continue; |
448 } | 448 } |
449 | 449 |
450 RefPtr<NGPhysicalFragment> physical_fragment = | 450 RefPtr<NGLayoutResult> layout_result = |
451 current_child_->Layout(space_for_current_child_); | 451 current_child_->Layout(space_for_current_child_); |
452 | 452 |
453 FinishCurrentChildLayout(toNGPhysicalBoxFragment(physical_fragment.get())); | 453 FinishCurrentChildLayout(layout_result); |
454 | 454 |
455 if (!ProceedToNextUnfinishedSibling(physical_fragment.get())) | 455 if (!ProceedToNextUnfinishedSibling( |
| 456 layout_result->PhysicalFragment().get())) |
456 break; | 457 break; |
457 } | 458 } |
458 | 459 |
459 // Margins collapsing: | 460 // Margins collapsing: |
460 // Bottom margins of an in-flow block box doesn't collapse with its last | 461 // Bottom margins of an in-flow block box doesn't collapse with its last |
461 // in-flow block-level child's bottom margin if the box has bottom | 462 // in-flow block-level child's bottom margin if the box has bottom |
462 // border/padding. | 463 // border/padding. |
463 content_size_ += border_and_padding_.block_end; | 464 content_size_ += border_and_padding_.block_end; |
464 if (border_and_padding_.block_end || | 465 if (border_and_padding_.block_end || |
465 ConstraintSpace().IsNewFormattingContext()) { | 466 ConstraintSpace().IsNewFormattingContext()) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 void NGBlockLayoutAlgorithm::LayoutInlineChildren(NGInlineNode* current_child) { | 504 void NGBlockLayoutAlgorithm::LayoutInlineChildren(NGInlineNode* current_child) { |
504 // TODO(kojii): This logic does not handle when children are mix of | 505 // TODO(kojii): This logic does not handle when children are mix of |
505 // inline/block. We need to detect the case and setup appropriately; e.g., | 506 // inline/block. We need to detect the case and setup appropriately; e.g., |
506 // constraint space, margin collapsing, next siblings, etc. | 507 // constraint space, margin collapsing, next siblings, etc. |
507 NGLineBuilder line_builder(current_child, space_for_current_child_); | 508 NGLineBuilder line_builder(current_child, space_for_current_child_); |
508 current_child->LayoutInline(space_for_current_child_, &line_builder); | 509 current_child->LayoutInline(space_for_current_child_, &line_builder); |
509 // TODO(kojii): The wrapper fragment should not be needed. | 510 // TODO(kojii): The wrapper fragment should not be needed. |
510 NGFragmentBuilder wrapper_fragment_builder(NGPhysicalFragment::kFragmentBox, | 511 NGFragmentBuilder wrapper_fragment_builder(NGPhysicalFragment::kFragmentBox, |
511 current_child->GetLayoutObject()); | 512 current_child->GetLayoutObject()); |
512 line_builder.CreateFragments(&wrapper_fragment_builder); | 513 line_builder.CreateFragments(&wrapper_fragment_builder); |
513 RefPtr<NGPhysicalBoxFragment> child_fragment = | 514 RefPtr<NGLayoutResult> child_result = |
514 wrapper_fragment_builder.ToBoxFragment(); | 515 wrapper_fragment_builder.ToBoxFragment(); |
515 line_builder.CopyFragmentDataToLayoutBlockFlow(); | 516 line_builder.CopyFragmentDataToLayoutBlockFlow(); |
516 FinishCurrentChildLayout(child_fragment.get()); | 517 FinishCurrentChildLayout(child_result); |
517 current_child_ = nullptr; | 518 current_child_ = nullptr; |
518 } | 519 } |
519 | 520 |
520 void NGBlockLayoutAlgorithm::FinishCurrentChildLayout( | 521 void NGBlockLayoutAlgorithm::FinishCurrentChildLayout( |
521 RefPtr<NGPhysicalBoxFragment> physical_fragment) { | 522 RefPtr<NGLayoutResult> layout_result) { |
522 NGBoxFragment fragment(ConstraintSpace().WritingMode(), | 523 NGBoxFragment fragment( |
523 physical_fragment.get()); | 524 ConstraintSpace().WritingMode(), |
| 525 toNGPhysicalBoxFragment(layout_result->PhysicalFragment().get())); |
524 | 526 |
525 if (!physical_fragment->UnpositionedFloats().isEmpty()) | 527 if (!layout_result->UnpositionedFloats().isEmpty()) |
526 DCHECK(!builder_->BfcOffset()) << "Parent BFC offset shouldn't be set here"; | 528 DCHECK(!builder_->BfcOffset()) << "Parent BFC offset shouldn't be set here"; |
527 // Pull out unpositioned floats to the current fragment. This may needed if | 529 // Pull out unpositioned floats to the current fragment. This may needed if |
528 // for example the child fragment could not position its floats because it's | 530 // for example the child fragment could not position its floats because it's |
529 // empty and therefore couldn't determine its position in space. | 531 // empty and therefore couldn't determine its position in space. |
530 builder_->MutableUnpositionedFloats().appendVector( | 532 builder_->MutableUnpositionedFloats().appendVector( |
531 physical_fragment->UnpositionedFloats()); | 533 layout_result->UnpositionedFloats()); |
532 | 534 |
533 if (current_child_->Type() == NGLayoutInputNode::kLegacyBlock && | 535 if (current_child_->Type() == NGLayoutInputNode::kLegacyBlock && |
534 CurrentChildStyle().isFloating()) { | 536 CurrentChildStyle().isFloating()) { |
535 NGFloatingObject* floating_object = | 537 NGFloatingObject* floating_object = new NGFloatingObject( |
536 new NGFloatingObject(physical_fragment.get(), space_for_current_child_, | 538 layout_result->PhysicalFragment().get(), space_for_current_child_, |
537 constraint_space_, toNGBlockNode(current_child_), | 539 constraint_space_, toNGBlockNode(current_child_), CurrentChildStyle(), |
538 CurrentChildStyle(), curr_child_margins_); | 540 curr_child_margins_); |
539 builder_->AddUnpositionedFloat(floating_object); | 541 builder_->AddUnpositionedFloat(floating_object); |
540 // No need to postpone the positioning if we know the correct offset. | 542 // No need to postpone the positioning if we know the correct offset. |
541 if (builder_->BfcOffset()) { | 543 if (builder_->BfcOffset()) { |
542 NGLogicalOffset origin_point = curr_bfc_offset_; | 544 NGLogicalOffset origin_point = curr_bfc_offset_; |
543 // Adjust origin point to the margins of the last child. | 545 // Adjust origin point to the margins of the last child. |
544 // Example: <div style="margin-bottom: 20px"><float></div> | 546 // Example: <div style="margin-bottom: 20px"><float></div> |
545 // <div style="margin-bottom: 30px"></div> | 547 // <div style="margin-bottom: 30px"></div> |
546 origin_point.block_offset += curr_margin_strut_.Sum(); | 548 origin_point.block_offset += curr_margin_strut_.Sum(); |
547 PositionPendingFloats(origin_point.block_offset, ConstraintSpace(), | 549 PositionPendingFloats(origin_point.block_offset, ConstraintSpace(), |
548 builder_.get()); | 550 builder_.get()); |
(...skipping 27 matching lines...) Expand all Loading... |
576 // Update margin strut. | 578 // Update margin strut. |
577 curr_margin_strut_ = fragment.EndMarginStrut(); | 579 curr_margin_strut_ = fragment.EndMarginStrut(); |
578 curr_margin_strut_.Append(curr_child_margins_.block_end); | 580 curr_margin_strut_.Append(curr_child_margins_.block_end); |
579 | 581 |
580 content_size_ = fragment.BlockSize() + logical_offset.block_offset; | 582 content_size_ = fragment.BlockSize() + logical_offset.block_offset; |
581 max_inline_size_ = | 583 max_inline_size_ = |
582 std::max(max_inline_size_, fragment.InlineSize() + | 584 std::max(max_inline_size_, fragment.InlineSize() + |
583 curr_child_margins_.InlineSum() + | 585 curr_child_margins_.InlineSum() + |
584 border_and_padding_.InlineSum()); | 586 border_and_padding_.InlineSum()); |
585 | 587 |
586 builder_->AddChild(std::move(physical_fragment), logical_offset); | 588 builder_->AddChild(layout_result, logical_offset); |
587 } | 589 } |
588 | 590 |
589 bool NGBlockLayoutAlgorithm::ProceedToNextUnfinishedSibling( | 591 bool NGBlockLayoutAlgorithm::ProceedToNextUnfinishedSibling( |
590 NGPhysicalFragment* child_fragment) { | 592 NGPhysicalFragment* child_fragment) { |
591 DCHECK(current_child_); | 593 DCHECK(current_child_); |
592 NGBlockNode* finished_child = toNGBlockNode(current_child_); | 594 NGBlockNode* finished_child = toNGBlockNode(current_child_); |
593 current_child_ = current_child_->NextSibling(); | 595 current_child_ = current_child_->NextSibling(); |
594 if (!ConstraintSpace().HasBlockFragmentation() && !fragmentainer_mapper_) | 596 if (!ConstraintSpace().HasBlockFragmentation() && !fragmentainer_mapper_) |
595 return true; | 597 return true; |
596 // If we're resuming layout after a fragmentainer break, we need to skip | 598 // 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... |
813 curr_bfc_offset_.inline_offset += curr_child_margins_.inline_start; | 815 curr_bfc_offset_.inline_offset += curr_child_margins_.inline_start; |
814 } | 816 } |
815 | 817 |
816 space_builder_->SetBfcOffset(curr_bfc_offset_); | 818 space_builder_->SetBfcOffset(curr_bfc_offset_); |
817 | 819 |
818 return space_builder_->ToConstraintSpace( | 820 return space_builder_->ToConstraintSpace( |
819 FromPlatformWritingMode(current_child_style.getWritingMode())); | 821 FromPlatformWritingMode(current_child_style.getWritingMode())); |
820 } | 822 } |
821 | 823 |
822 } // namespace blink | 824 } // namespace blink |
OLD | NEW |