Chromium Code Reviews| 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 c58908fa0a69c57eedc41a5a6306add279ad892a..5647731d0e0866f0ae6497f6f7890a6d9e7a688c 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 |
| @@ -172,8 +172,9 @@ const NGLayoutOpportunity FindLayoutOpportunityForFragment( |
| NGLogicalOffset CalculateLogicalOffsetForOpportunity( |
| const NGLayoutOpportunity& opportunity, |
| const LayoutUnit float_offset, |
| - const NGBoxStrut& margins, |
| - const NGLogicalOffset& space_offset) { |
| + const NGLogicalOffset& from_offset, |
| + NGFloatingObject* floating_object) { |
| + auto margins = floating_object->margins; |
| // Adjust to child's margin. |
| LayoutUnit inline_offset = margins.inline_start; |
| LayoutUnit block_offset = margins.block_start; |
| @@ -182,10 +183,11 @@ NGLogicalOffset CalculateLogicalOffsetForOpportunity( |
| inline_offset += opportunity.offset.inline_offset; |
| block_offset += opportunity.offset.block_offset; |
| + // Adjust to float: right offset if needed. |
| inline_offset += float_offset; |
| - block_offset -= space_offset.block_offset; |
| - inline_offset -= space_offset.inline_offset; |
| + block_offset -= from_offset.block_offset; |
| + inline_offset -= from_offset.inline_offset; |
| return NGLogicalOffset(inline_offset, block_offset); |
| } |
| @@ -221,21 +223,44 @@ NGLogicalOffset PositionFloat(const NGLogicalOffset& origin_point, |
| floating_object->exclusion_type); |
| float_space->AddExclusion(exclusion); |
| - return CalculateLogicalOffsetForOpportunity( |
| - opportunity, float_offset, floating_object->margins, from_offset); |
| + return CalculateLogicalOffsetForOpportunity(opportunity, float_offset, |
| + from_offset, floating_object); |
| +} |
| + |
| +// Updates the Floating Object's left offset from the provided parent_space and |
| +// {@code floating_object}'s space and margins. |
| +void UpdateFloatingObjectLeftOffset( |
|
cbiesinger
2017/02/08 22:39:01
Left -> Inline, no?
Gleb Lanbin
2017/02/09 18:39:25
you're right. We should use physical coordinates h
|
| + const NGConstraintSpace& parent_space, |
| + const Persistent<NGFloatingObject>& floating_object) { |
| + const auto& float_space = floating_object->space; |
| + floating_object->left_offset = float_space->BfcOffset().inline_offset - |
| + parent_space.BfcOffset().inline_offset + |
| + floating_object->margins.inline_start; |
| } |
| // Positions pending floats stored on the fragment builder starting from |
| -// {@code origin_point}. |
| -void PositionPendingFloats(const NGLogicalOffset& origin_point, |
| +// {@code origin_point_block_offset}. |
| +void PositionPendingFloats(const LayoutUnit origin_point_block_offset, |
| + const NGConstraintSpace& parent_space, |
| NGFragmentBuilder* builder) { |
| DCHECK(builder->BfcOffset()) << "Parent BFC offset should be known here"; |
| - NGLogicalOffset from_offset = builder->BfcOffset().value(); |
| + LayoutUnit from_offset_block_offset = |
|
cbiesinger
2017/02/08 22:39:01
I think "from_offset_block" reads better
Gleb Lanbin
2017/02/09 18:39:25
Done.
|
| + builder->BfcOffset().value().block_offset; |
| for (auto& floating_object : builder->UnpositionedFloats()) { |
| + auto float_space = floating_object->space; |
|
cbiesinger
2017/02/08 22:39:01
auto*
Gleb Lanbin
2017/02/09 18:39:25
done. it's Member<const NGConstraintSpace> which i
|
| + auto float_parent_space = floating_object->parent_space; |
| + |
| + NGLogicalOffset origin_point = {float_space->BfcOffset().inline_offset, |
| + origin_point_block_offset}; |
| + NGLogicalOffset from_offset = { |
| + float_parent_space->BfcOffset().inline_offset, |
| + from_offset_block_offset}; |
| + |
| NGLogicalOffset float_fragment_offset = |
| PositionFloat(origin_point, from_offset, floating_object); |
| builder->AddFloatingObject(floating_object, float_fragment_offset); |
| + UpdateFloatingObjectLeftOffset(parent_space, floating_object); |
| } |
| builder->MutableUnpositionedFloats().clear(); |
| } |
| @@ -458,7 +483,8 @@ RefPtr<NGPhysicalFragment> NGBlockLayoutAlgorithm::Layout() { |
| curr_bfc_offset_.block_offset += curr_margin_strut_.Sum(); |
| UpdateFragmentBfcOffset(curr_bfc_offset_, ConstraintSpace(), |
| builder_.get()); |
| - PositionPendingFloats(curr_bfc_offset_, builder_.get()); |
| + PositionPendingFloats(curr_bfc_offset_.block_offset, ConstraintSpace(), |
| + builder_.get()); |
| } |
| // Margins collapsing: |
| @@ -512,8 +538,8 @@ void NGBlockLayoutAlgorithm::FinishCurrentChildLayout( |
| CurrentChildStyle().isFloating()) { |
| NGFloatingObject* floating_object = |
| new NGFloatingObject(physical_fragment.get(), space_for_current_child_, |
| - toNGBlockNode(current_child_), CurrentChildStyle(), |
| - curr_child_margins_); |
| + constraint_space_, toNGBlockNode(current_child_), |
| + CurrentChildStyle(), curr_child_margins_); |
| builder_->AddUnpositionedFloat(floating_object); |
| // No need to postpone the positioning if we know the correct offset. |
| if (builder_->BfcOffset()) { |
| @@ -522,7 +548,8 @@ void NGBlockLayoutAlgorithm::FinishCurrentChildLayout( |
| // Example: <div style="margin-bottom: 20px"><float></div> |
| // <div style="margin-bottom: 30px"></div> |
| origin_point.block_offset += curr_margin_strut_.Sum(); |
| - PositionPendingFloats(origin_point, builder_.get()); |
| + PositionPendingFloats(origin_point.block_offset, ConstraintSpace(), |
| + builder_.get()); |
| } |
| return; |
| } |
| @@ -532,7 +559,8 @@ void NGBlockLayoutAlgorithm::FinishCurrentChildLayout( |
| curr_bfc_offset_.block_offset = fragment.BfcOffset().value().block_offset; |
| UpdateFragmentBfcOffset(curr_bfc_offset_, ConstraintSpace(), |
| builder_.get()); |
| - PositionPendingFloats(curr_bfc_offset_, builder_.get()); |
| + PositionPendingFloats(curr_bfc_offset_.block_offset, ConstraintSpace(), |
| + builder_.get()); |
| } |
| NGLogicalOffset fragment_offset = CalculateRelativeOffset(fragment); |
| @@ -756,7 +784,8 @@ NGBlockLayoutAlgorithm::CreateConstraintSpaceForCurrentChild() { |
| curr_margin_strut_ = NGMarginStrut(); |
| curr_child_margins_.block_start = LayoutUnit(); |
| } |
| - PositionPendingFloats(curr_bfc_offset_, builder_.get()); |
| + PositionPendingFloats(curr_bfc_offset_.block_offset, ConstraintSpace(), |
| + builder_.get()); |
| AdjustToClearance(constraint_space_->Exclusions(), current_child_style, |
| builder_->BfcOffset().value(), &content_size_); |
| } |
| @@ -772,9 +801,11 @@ NGBlockLayoutAlgorithm::CreateConstraintSpaceForCurrentChild() { |
| : ConstraintSpace().BfcOffset(); |
| curr_bfc_offset_.block_offset += content_size_; |
| curr_bfc_offset_.inline_offset += border_and_padding_.inline_start; |
| - if (ConstraintSpace().IsNewFormattingContext()) { |
| + |
| + if (!CurrentChildStyle().isFloating()) { |
| curr_bfc_offset_.inline_offset += curr_child_margins_.inline_start; |
| } |
| + |
| space_builder_->SetBfcOffset(curr_bfc_offset_); |
| return space_builder_->ToConstraintSpace(); |