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/inline/ng_inline_node.h" | 7 #include "core/layout/ng/inline/ng_inline_node.h" |
8 #include "core/layout/ng/ng_absolute_utils.h" | 8 #include "core/layout/ng/ng_absolute_utils.h" |
9 #include "core/layout/ng/ng_block_child_iterator.h" | 9 #include "core/layout/ng/ng_block_child_iterator.h" |
10 #include "core/layout/ng/ng_constraint_space.h" | 10 #include "core/layout/ng/ng_constraint_space.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 NGFragmentBuilder* builder) { | 84 NGFragmentBuilder* builder) { |
85 DCHECK(builder); | 85 DCHECK(builder); |
86 if (!builder->BfcOffset()) { | 86 if (!builder->BfcOffset()) { |
87 NGLogicalOffset bfc_offset = {space.BfcOffset().inline_offset, | 87 NGLogicalOffset bfc_offset = {space.BfcOffset().inline_offset, |
88 bfc_block_offset}; | 88 bfc_block_offset}; |
89 AdjustToClearance(space.ClearanceOffset(), &bfc_offset); | 89 AdjustToClearance(space.ClearanceOffset(), &bfc_offset); |
90 builder->SetBfcOffset(bfc_offset); | 90 builder->SetBfcOffset(bfc_offset); |
91 } | 91 } |
92 } | 92 } |
93 | 93 |
94 void PositionPendingFloatsFromOffset(LayoutUnit origin_block_offset, | |
95 LayoutUnit from_block_offset, | |
96 NGFragmentBuilder* container_builder, | |
97 NGConstraintSpace* space) { | |
98 DCHECK(container_builder->BfcOffset()) | |
99 << "Parent BFC offset should be known here"; | |
100 const auto& unpositioned_floats = container_builder->UnpositionedFloats(); | |
101 const auto positioned_floats = | |
102 PositionFloats(origin_block_offset, from_block_offset, | |
103 container_builder->BfcOffset().value().block_offset, | |
104 unpositioned_floats, space); | |
105 for (const auto& positioned_float : positioned_floats) | |
106 container_builder->AddPositionedFloat(positioned_float); | |
107 | |
108 container_builder->MutableUnpositionedFloats().clear(); | |
109 } | |
110 | |
111 void PositionPendingFloats(LayoutUnit origin_block_offset, | 94 void PositionPendingFloats(LayoutUnit origin_block_offset, |
112 NGFragmentBuilder* container_builder, | 95 NGFragmentBuilder* container_builder, |
113 NGConstraintSpace* space) { | 96 NGConstraintSpace* space) { |
114 DCHECK(container_builder->BfcOffset()) | 97 DCHECK(container_builder->BfcOffset()) |
115 << "Parent BFC offset should be known here"; | 98 << "Parent BFC offset should be known here"; |
116 LayoutUnit from_block_offset = | 99 |
117 container_builder->BfcOffset().value().block_offset; | 100 const auto& unpositioned_floats = container_builder->UnpositionedFloats(); |
118 PositionPendingFloatsFromOffset(origin_block_offset, from_block_offset, | 101 const auto positioned_floats = PositionFloats( |
119 container_builder, space); | 102 origin_block_offset, container_builder->BfcOffset().value().block_offset, |
103 unpositioned_floats, space); | |
104 | |
105 for (const auto& positioned_float : positioned_floats) | |
106 container_builder->AddPositionedFloat(positioned_float); | |
107 | |
108 container_builder->MutableUnpositionedFloats().clear(); | |
eae
2017/06/29 22:21:18
Exposing the mutable list like this is a little we
ikilpatrick
2017/06/29 22:34:42
So this will actually go away in the larger patch,
| |
120 } | 109 } |
121 | 110 |
122 NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm(NGBlockNode node, | 111 NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm(NGBlockNode node, |
123 NGConstraintSpace* space, | 112 NGConstraintSpace* space, |
124 NGBlockBreakToken* break_token) | 113 NGBlockBreakToken* break_token) |
125 : NGLayoutAlgorithm(node, space, break_token) {} | 114 : NGLayoutAlgorithm(node, space, break_token) {} |
126 | 115 |
127 Optional<MinMaxContentSize> NGBlockLayoutAlgorithm::ComputeMinMaxContentSize() | 116 Optional<MinMaxContentSize> NGBlockLayoutAlgorithm::ComputeMinMaxContentSize() |
128 const { | 117 const { |
129 MinMaxContentSize sizes; | 118 MinMaxContentSize sizes; |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 container_builder_.AddOutOfFlowChildCandidate(child, offset); | 356 container_builder_.AddOutOfFlowChildCandidate(child, offset); |
368 } | 357 } |
369 | 358 |
370 void NGBlockLayoutAlgorithm::HandleFloating( | 359 void NGBlockLayoutAlgorithm::HandleFloating( |
371 const NGPreviousInflowPosition& previous_inflow_position, | 360 const NGPreviousInflowPosition& previous_inflow_position, |
372 NGBlockNode child, | 361 NGBlockNode child, |
373 NGBlockBreakToken* token) { | 362 NGBlockBreakToken* token) { |
374 // Calculate margins in the BFC's writing mode. | 363 // Calculate margins in the BFC's writing mode. |
375 NGBoxStrut margins = CalculateMargins(child); | 364 NGBoxStrut margins = CalculateMargins(child); |
376 | 365 |
377 NGLogicalOffset origin_offset = constraint_space_->BfcOffset(); | 366 LayoutUnit origin_inline_offset = |
378 origin_offset.inline_offset += border_scrollbar_padding_.inline_start; | 367 constraint_space_->BfcOffset().inline_offset + |
368 border_scrollbar_padding_.inline_start; | |
369 | |
379 RefPtr<NGUnpositionedFloat> unpositioned_float = NGUnpositionedFloat::Create( | 370 RefPtr<NGUnpositionedFloat> unpositioned_float = NGUnpositionedFloat::Create( |
380 child_available_size_, child_percentage_size_, origin_offset, | 371 child_available_size_, child_percentage_size_, origin_inline_offset, |
381 constraint_space_->BfcOffset(), margins, child, token); | 372 constraint_space_->BfcOffset().inline_offset, margins, child, token); |
382 container_builder_.AddUnpositionedFloat(unpositioned_float); | 373 container_builder_.AddUnpositionedFloat(unpositioned_float); |
383 | 374 |
384 // If there is a break token for a float we must be resuming layout, we must | 375 // If there is a break token for a float we must be resuming layout, we must |
385 // always know our position in the BFC. | 376 // always know our position in the BFC. |
386 DCHECK(!token || container_builder_.BfcOffset()); | 377 DCHECK(!token || container_builder_.BfcOffset()); |
387 | 378 |
388 // No need to postpone the positioning if we know the correct offset. | 379 // No need to postpone the positioning if we know the correct offset. |
389 if (container_builder_.BfcOffset()) { | 380 if (container_builder_.BfcOffset()) { |
390 // Adjust origin point to the margins of the last child. | 381 // Adjust origin point to the margins of the last child. |
391 // Example: <div style="margin-bottom: 20px"><float></div> | 382 // Example: <div style="margin-bottom: 20px"><float></div> |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
529 | 520 |
530 LayoutUnit child_bfc_offset_estimate = | 521 LayoutUnit child_bfc_offset_estimate = |
531 child_data.bfc_offset_estimate.block_offset; | 522 child_data.bfc_offset_estimate.block_offset; |
532 | 523 |
533 // 1. Position all pending floats to a temporary space. | 524 // 1. Position all pending floats to a temporary space. |
534 RefPtr<NGConstraintSpace> tmp_space = | 525 RefPtr<NGConstraintSpace> tmp_space = |
535 NGConstraintSpaceBuilder(&child_space) | 526 NGConstraintSpaceBuilder(&child_space) |
536 .SetIsNewFormattingContext(false) | 527 .SetIsNewFormattingContext(false) |
537 .ToConstraintSpace(child_space.WritingMode()); | 528 .ToConstraintSpace(child_space.WritingMode()); |
538 PositionFloats(child_bfc_offset_estimate, child_bfc_offset_estimate, | 529 PositionFloats(child_bfc_offset_estimate, child_bfc_offset_estimate, |
539 child_bfc_offset_estimate, | |
540 container_builder_.UnpositionedFloats(), tmp_space.Get()); | 530 container_builder_.UnpositionedFloats(), tmp_space.Get()); |
541 | 531 |
542 NGLogicalOffset origin_offset = {ConstraintSpace().BfcOffset().inline_offset + | 532 NGLogicalOffset origin_offset = {ConstraintSpace().BfcOffset().inline_offset + |
543 border_scrollbar_padding_.inline_start, | 533 border_scrollbar_padding_.inline_start, |
544 child_bfc_offset_estimate}; | 534 child_bfc_offset_estimate}; |
545 AdjustToClearance( | 535 AdjustToClearance( |
546 GetClearanceOffset(ConstraintSpace().Exclusions(), child_style.Clear()), | 536 GetClearanceOffset(ConstraintSpace().Exclusions(), child_style.Clear()), |
547 &origin_offset); | 537 &origin_offset); |
548 | 538 |
549 // 2. Find an estimated layout opportunity for our fragment. | 539 // 2. Find an estimated layout opportunity for our fragment. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
603 DCHECK_EQ(fragment.BlockSize(), LayoutUnit()); | 593 DCHECK_EQ(fragment.BlockSize(), LayoutUnit()); |
604 | 594 |
605 NGLogicalOffset child_bfc_offset = { | 595 NGLogicalOffset child_bfc_offset = { |
606 ConstraintSpace().BfcOffset().inline_offset + | 596 ConstraintSpace().BfcOffset().inline_offset + |
607 border_scrollbar_padding_.inline_start + | 597 border_scrollbar_padding_.inline_start + |
608 child_data.margins.inline_start, | 598 child_data.margins.inline_start, |
609 child_data.bfc_offset_estimate.block_offset + | 599 child_data.bfc_offset_estimate.block_offset + |
610 layout_result.EndMarginStrut().Sum()}; | 600 layout_result.EndMarginStrut().Sum()}; |
611 | 601 |
612 AdjustToClearance(space.ClearanceOffset(), &child_bfc_offset); | 602 AdjustToClearance(space.ClearanceOffset(), &child_bfc_offset); |
613 PositionPendingFloatsFromOffset( | 603 PositionPendingFloats(child_bfc_offset.block_offset, &container_builder_, |
614 child_bfc_offset.block_offset, child_bfc_offset.block_offset, | 604 MutableConstraintSpace()); |
615 &container_builder_, MutableConstraintSpace()); | |
616 return child_bfc_offset; | 605 return child_bfc_offset; |
617 } | 606 } |
618 | 607 |
619 void NGBlockLayoutAlgorithm::FinalizeForFragmentation() { | 608 void NGBlockLayoutAlgorithm::FinalizeForFragmentation() { |
620 LayoutUnit used_block_size = | 609 LayoutUnit used_block_size = |
621 BreakToken() ? BreakToken()->UsedBlockSize() : LayoutUnit(); | 610 BreakToken() ? BreakToken()->UsedBlockSize() : LayoutUnit(); |
622 LayoutUnit block_size = ComputeBlockSizeForFragment( | 611 LayoutUnit block_size = ComputeBlockSizeForFragment( |
623 ConstraintSpace(), Style(), used_block_size + content_size_); | 612 ConstraintSpace(), Style(), used_block_size + content_size_); |
624 | 613 |
625 block_size -= used_block_size; | 614 block_size -= used_block_size; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
725 if (is_new_fc) { | 714 if (is_new_fc) { |
726 space_available -= child_data.bfc_offset_estimate.block_offset; | 715 space_available -= child_data.bfc_offset_estimate.block_offset; |
727 } | 716 } |
728 } | 717 } |
729 space_builder.SetFragmentainerSpaceAvailable(space_available); | 718 space_builder.SetFragmentainerSpaceAvailable(space_available); |
730 | 719 |
731 return space_builder.ToConstraintSpace( | 720 return space_builder.ToConstraintSpace( |
732 FromPlatformWritingMode(child_style.GetWritingMode())); | 721 FromPlatformWritingMode(child_style.GetWritingMode())); |
733 } | 722 } |
734 } // namespace blink | 723 } // namespace blink |
OLD | NEW |