Index: third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.cc |
diff --git a/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.cc b/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.cc |
index f9d504ef81b166d163bc2b9cd69df9df9979fdd0..69d205dda68efb11878f1a76f8d32d32be44cb2d 100644 |
--- a/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.cc |
+++ b/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.cc |
@@ -102,8 +102,7 @@ void PositionPendingFloats(LayoutUnit origin_block_offset, |
NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm(NGBlockNode* node, |
NGConstraintSpace* space, |
NGBlockBreakToken* break_token) |
- : NGLayoutAlgorithm(node, space, break_token), |
- space_builder_(constraint_space_) {} |
+ : NGLayoutAlgorithm(node, space, break_token) {} |
Optional<MinMaxContentSize> NGBlockLayoutAlgorithm::ComputeMinMaxContentSize() |
const { |
@@ -175,8 +174,8 @@ RefPtr<NGLayoutResult> NGBlockLayoutAlgorithm::Layout() { |
else |
adjusted_size -= border_and_padding_; |
- space_builder_.SetAvailableSize(adjusted_size) |
- .SetPercentageResolutionSize(adjusted_size); |
+ child_available_size_ = adjusted_size; |
+ child_percentage_size_ = adjusted_size; |
container_builder_.SetDirection(constraint_space_->Direction()); |
container_builder_.SetWritingMode(constraint_space_->WritingMode()); |
@@ -241,7 +240,7 @@ RefPtr<NGLayoutResult> NGBlockLayoutAlgorithm::Layout() { |
NGLogicalOffset child_bfc_offset = PrepareChildLayout(child); |
RefPtr<NGConstraintSpace> child_space = |
- CreateConstraintSpaceForChild(child_bfc_offset, child); |
+ CreateConstraintSpaceForChild(child_bfc_offset, *child); |
RefPtr<NGLayoutResult> layout_result = |
child->Layout(child_space.Get(), child_break_token); |
@@ -314,9 +313,7 @@ NGLogicalOffset NGBlockLayoutAlgorithm::PrepareChildLayout( |
curr_bfc_offset_.block_offset += content_size_; |
// Calculate margins in parent's writing mode. |
- curr_child_margins_ = CalculateMargins( |
- child, *space_builder_.ToConstraintSpace( |
- FromPlatformWritingMode(Style().GetWritingMode()))); |
+ curr_child_margins_ = CalculateMargins(child); |
bool should_position_pending_floats = |
!child->IsFloating() && |
@@ -560,57 +557,66 @@ void NGBlockLayoutAlgorithm::FinalizeForFragmentation() { |
container_builder_.SetBlockOverflow(content_size_); |
} |
-NGBoxStrut NGBlockLayoutAlgorithm::CalculateMargins( |
- NGLayoutInputNode* child, |
- const NGConstraintSpace& space) { |
+NGBoxStrut NGBlockLayoutAlgorithm::CalculateMargins(NGLayoutInputNode* child) { |
DCHECK(child); |
if (child->IsInline()) |
return {}; |
const ComputedStyle& child_style = child->Style(); |
- WTF::Optional<MinMaxContentSize> sizes; |
- if (NeedMinMaxContentSize(space, child_style)) |
- sizes = child->ComputeMinMaxContentSize(); |
+ RefPtr<NGConstraintSpace> space = |
+ NGConstraintSpaceBuilder(MutableConstraintSpace()) |
+ .SetAvailableSize(child_available_size_) |
+ .SetPercentageResolutionSize(child_percentage_size_) |
+ .ToConstraintSpace(ConstraintSpace().WritingMode()); |
- LayoutUnit child_inline_size = |
- ComputeInlineSizeForFragment(space, child_style, sizes); |
- NGBoxStrut margins = ComputeMargins(space, child_style, space.WritingMode(), |
- space.Direction()); |
+ NGBoxStrut margins = ComputeMargins(*space, child_style, space->WritingMode(), |
+ space->Direction()); |
+ |
+ // TODO(ikilpatrick): Move the auto margins calculation for different writing |
+ // modes to post-layout. |
if (!child->IsFloating()) { |
- ApplyAutoMargins(space, child_style, child_inline_size, &margins); |
+ WTF::Optional<MinMaxContentSize> sizes; |
+ if (NeedMinMaxContentSize(*space, child_style)) |
+ sizes = child->ComputeMinMaxContentSize(); |
+ |
+ LayoutUnit child_inline_size = |
+ ComputeInlineSizeForFragment(*space, child_style, sizes); |
+ ApplyAutoMargins(*space, child_style, child_inline_size, &margins); |
} |
return margins; |
} |
RefPtr<NGConstraintSpace> NGBlockLayoutAlgorithm::CreateConstraintSpaceForChild( |
const NGLogicalOffset& child_bfc_offset, |
- NGLayoutInputNode* child) { |
- DCHECK(child); |
- |
- const ComputedStyle& child_style = child->Style(); |
- bool is_new_bfc = IsNewFormattingContextForBlockLevelChild(Style(), *child); |
- space_builder_.SetIsNewFormattingContext(is_new_bfc) |
+ const NGLayoutInputNode& child) { |
+ NGConstraintSpaceBuilder space_builder(MutableConstraintSpace()); |
+ space_builder.SetAvailableSize(child_available_size_) |
+ .SetPercentageResolutionSize(child_percentage_size_); |
+ |
+ const ComputedStyle& child_style = child.Style(); |
+ bool is_new_bfc = IsNewFormattingContextForBlockLevelChild(Style(), child); |
+ space_builder.SetIsNewFormattingContext(is_new_bfc) |
.SetBfcOffset(child_bfc_offset); |
// Float's margins are not included in child's space because: |
// 1) Floats do not participate in margins collapsing. |
// 2) Floats margins are used separately to calculate floating exclusions. |
- space_builder_.SetMarginStrut(child->IsFloating() ? NGMarginStrut() |
- : curr_margin_strut_); |
+ space_builder.SetMarginStrut(child.IsFloating() ? NGMarginStrut() |
+ : curr_margin_strut_); |
if (!is_new_bfc) { |
- space_builder_.SetUnpositionedFloats( |
+ space_builder.SetUnpositionedFloats( |
container_builder_.MutableUnpositionedFloats()); |
} |
- if (child->IsInline()) { |
- // TODO(kojii): Setup space_builder_ appropriately for inline child. |
- space_builder_.SetClearanceOffset(ConstraintSpace().ClearanceOffset()); |
- return space_builder_.ToConstraintSpace( |
+ if (child.IsInline()) { |
+ // TODO(kojii): Setup space_builder appropriately for inline child. |
+ space_builder.SetClearanceOffset(ConstraintSpace().ClearanceOffset()); |
+ return space_builder.ToConstraintSpace( |
FromPlatformWritingMode(Style().GetWritingMode())); |
} |
- space_builder_ |
+ space_builder |
.SetClearanceOffset( |
GetClearanceOffset(constraint_space_->Exclusions(), child_style)) |
.SetIsShrinkToFit(ShouldShrinkToFit(Style(), child_style)) |
@@ -626,9 +632,9 @@ RefPtr<NGConstraintSpace> NGBlockLayoutAlgorithm::CreateConstraintSpaceForChild( |
space_available -= child_bfc_offset.block_offset; |
} |
} |
- space_builder_.SetFragmentainerSpaceAvailable(space_available); |
+ space_builder.SetFragmentainerSpaceAvailable(space_available); |
- return space_builder_.ToConstraintSpace( |
+ return space_builder.ToConstraintSpace( |
FromPlatformWritingMode(child_style.GetWritingMode())); |
} |
} // namespace blink |