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_block_child_iterator.h" | 9 #include "core/layout/ng/ng_block_child_iterator.h" |
10 #include "core/layout/ng/ng_box_fragment.h" | 10 #include "core/layout/ng/ng_box_fragment.h" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 inline_offset -= from_offset.inline_offset; | 180 inline_offset -= from_offset.inline_offset; |
181 | 181 |
182 return NGLogicalOffset(inline_offset, block_offset); | 182 return NGLogicalOffset(inline_offset, block_offset); |
183 } | 183 } |
184 | 184 |
185 // Calculates the relative position from {@code from_offset} of the | 185 // Calculates the relative position from {@code from_offset} of the |
186 // floating object that is requested to be positioned from {@code origin_point}. | 186 // floating object that is requested to be positioned from {@code origin_point}. |
187 NGLogicalOffset PositionFloat(const NGLogicalOffset& origin_point, | 187 NGLogicalOffset PositionFloat(const NGLogicalOffset& origin_point, |
188 const NGLogicalOffset& from_offset, | 188 const NGLogicalOffset& from_offset, |
189 NGFloatingObject* floating_object) { | 189 NGFloatingObject* floating_object) { |
190 NGConstraintSpace* float_space = floating_object->space; | 190 NGConstraintSpace* float_space = floating_object->space.get(); |
191 DCHECK(floating_object->fragment) << "Fragment cannot be null here"; | 191 DCHECK(floating_object->fragment) << "Fragment cannot be null here"; |
192 | 192 |
193 // TODO(ikilpatrick): The writing mode switching here looks wrong. | 193 // TODO(ikilpatrick): The writing mode switching here looks wrong. |
194 NGBoxFragment float_fragment( | 194 NGBoxFragment float_fragment( |
195 float_space->WritingMode(), | 195 float_space->WritingMode(), |
196 toNGPhysicalBoxFragment(floating_object->fragment.get())); | 196 toNGPhysicalBoxFragment(floating_object->fragment.get())); |
197 | 197 |
198 // Find a layout opportunity that will fit our float. | 198 // Find a layout opportunity that will fit our float. |
199 const NGLayoutOpportunity opportunity = | 199 const NGLayoutOpportunity opportunity = FindLayoutOpportunityForFragment( |
200 FindLayoutOpportunityForFragment(floating_object->space, float_fragment, | 200 float_space, float_fragment, origin_point, floating_object->margins); |
201 origin_point, floating_object->margins); | |
202 DCHECK(!opportunity.IsEmpty()) << "Opportunity is empty but it shouldn't be"; | 201 DCHECK(!opportunity.IsEmpty()) << "Opportunity is empty but it shouldn't be"; |
203 | 202 |
204 // Calculate the float offset if needed. | 203 // Calculate the float offset if needed. |
205 LayoutUnit float_offset; | 204 LayoutUnit float_offset; |
206 if (floating_object->exclusion_type == NGExclusion::kFloatRight) { | 205 if (floating_object->exclusion_type == NGExclusion::kFloatRight) { |
207 LayoutUnit float_margin_box_inline_size = | 206 LayoutUnit float_margin_box_inline_size = |
208 float_fragment.InlineSize() + floating_object->margins.InlineSum(); | 207 float_fragment.InlineSize() + floating_object->margins.InlineSum(); |
209 float_offset = opportunity.size.inline_size - float_margin_box_inline_size; | 208 float_offset = opportunity.size.inline_size - float_margin_box_inline_size; |
210 } | 209 } |
211 | 210 |
(...skipping 22 matching lines...) Expand all Loading... |
234 | 233 |
235 // Positions pending floats stored on the fragment builder starting from | 234 // Positions pending floats stored on the fragment builder starting from |
236 // {@code origin_point_block_offset}. | 235 // {@code origin_point_block_offset}. |
237 void PositionPendingFloats(const LayoutUnit origin_point_block_offset, | 236 void PositionPendingFloats(const LayoutUnit origin_point_block_offset, |
238 const NGConstraintSpace& new_parent_space, | 237 const NGConstraintSpace& new_parent_space, |
239 NGFragmentBuilder* builder) { | 238 NGFragmentBuilder* builder) { |
240 DCHECK(builder->BfcOffset()) << "Parent BFC offset should be known here"; | 239 DCHECK(builder->BfcOffset()) << "Parent BFC offset should be known here"; |
241 LayoutUnit bfc_block_offset = builder->BfcOffset().value().block_offset; | 240 LayoutUnit bfc_block_offset = builder->BfcOffset().value().block_offset; |
242 | 241 |
243 for (auto& floating_object : builder->UnpositionedFloats()) { | 242 for (auto& floating_object : builder->UnpositionedFloats()) { |
244 Member<NGConstraintSpace> float_space = floating_object->space; | 243 NGConstraintSpace* float_space = floating_object->space.get(); |
245 Member<const NGConstraintSpace> original_parent_space = | 244 const NGConstraintSpace* original_parent_space = |
246 floating_object->original_parent_space; | 245 floating_object->original_parent_space.get(); |
247 | 246 |
248 NGLogicalOffset origin_point = {float_space->BfcOffset().inline_offset, | 247 NGLogicalOffset origin_point = {float_space->BfcOffset().inline_offset, |
249 origin_point_block_offset}; | 248 origin_point_block_offset}; |
250 NGLogicalOffset from_offset = { | 249 NGLogicalOffset from_offset = { |
251 original_parent_space->BfcOffset().inline_offset, bfc_block_offset}; | 250 original_parent_space->BfcOffset().inline_offset, bfc_block_offset}; |
252 | 251 |
253 NGLogicalOffset float_fragment_offset = | 252 NGLogicalOffset float_fragment_offset = |
254 PositionFloat(origin_point, from_offset, floating_object); | 253 PositionFloat(origin_point, from_offset, floating_object); |
255 builder->AddFloatingObject(floating_object, float_fragment_offset); | 254 builder->AddFloatingObject(floating_object, float_fragment_offset); |
256 UpdateFloatingObjectLeftOffset(new_parent_space, floating_object, | 255 UpdateFloatingObjectLeftOffset(new_parent_space, floating_object, |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 if (position == EPosition::kAbsolute || position == EPosition::kFixed) { | 448 if (position == EPosition::kAbsolute || position == EPosition::kFixed) { |
450 builder_.AddOutOfFlowChildCandidate(current_block_child, | 449 builder_.AddOutOfFlowChildCandidate(current_block_child, |
451 GetChildSpaceOffset()); | 450 GetChildSpaceOffset()); |
452 NGBlockChildIterator::Entry entry = child_iterator.NextChild(); | 451 NGBlockChildIterator::Entry entry = child_iterator.NextChild(); |
453 child = entry.node; | 452 child = entry.node; |
454 child_break_token = entry.token; | 453 child_break_token = entry.token; |
455 continue; | 454 continue; |
456 } | 455 } |
457 } | 456 } |
458 | 457 |
459 NGConstraintSpace* child_space = CreateConstraintSpaceForChild(child); | 458 RefPtr<NGConstraintSpace> child_space = |
| 459 CreateConstraintSpaceForChild(child); |
460 | 460 |
461 if (child->Type() == NGLayoutInputNode::kLegacyInline) { | 461 if (child->Type() == NGLayoutInputNode::kLegacyInline) { |
462 LayoutInlineChildren(toNGInlineNode(child), child_space); | 462 LayoutInlineChildren(toNGInlineNode(child), child_space.get()); |
463 break; | 463 break; |
464 } | 464 } |
465 | 465 |
466 RefPtr<NGLayoutResult> layout_result = | 466 RefPtr<NGLayoutResult> layout_result = |
467 child->Layout(child_space, child_break_token); | 467 child->Layout(child_space.get(), child_break_token); |
468 | 468 |
469 FinishChildLayout(child, child_space, layout_result); | 469 FinishChildLayout(child, child_space.get(), layout_result); |
470 | 470 |
471 entry = child_iterator.NextChild(); | 471 entry = child_iterator.NextChild(); |
472 child = entry.node; | 472 child = entry.node; |
473 child_break_token = entry.token; | 473 child_break_token = entry.token; |
474 | 474 |
475 if (IsOutOfSpace(ConstraintSpace(), content_size_)) | 475 if (IsOutOfSpace(ConstraintSpace(), content_size_)) |
476 break; | 476 break; |
477 } | 477 } |
478 | 478 |
479 // Margins collapsing: | 479 // Margins collapsing: |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 LayoutUnit child_inline_size = | 679 LayoutUnit child_inline_size = |
680 ComputeInlineSizeForFragment(space, child_style, sizes); | 680 ComputeInlineSizeForFragment(space, child_style, sizes); |
681 NGBoxStrut margins = ComputeMargins(space, child_style, space.WritingMode(), | 681 NGBoxStrut margins = ComputeMargins(space, child_style, space.WritingMode(), |
682 space.Direction()); | 682 space.Direction()); |
683 if (!child_style.isFloating()) { | 683 if (!child_style.isFloating()) { |
684 ApplyAutoMargins(space, child_style, child_inline_size, &margins); | 684 ApplyAutoMargins(space, child_style, child_inline_size, &margins); |
685 } | 685 } |
686 return margins; | 686 return margins; |
687 } | 687 } |
688 | 688 |
689 NGConstraintSpace* NGBlockLayoutAlgorithm::CreateConstraintSpaceForChild( | 689 RefPtr<NGConstraintSpace> NGBlockLayoutAlgorithm::CreateConstraintSpaceForChild( |
690 NGLayoutInputNode* child) { | 690 NGLayoutInputNode* child) { |
691 DCHECK(child); | 691 DCHECK(child); |
692 | 692 |
693 if (child->Type() == NGLayoutInputNode::kLegacyInline) { | 693 if (child->Type() == NGLayoutInputNode::kLegacyInline) { |
694 // TODO(kojii): Setup space_builder_ appropriately for inline child. | 694 // TODO(kojii): Setup space_builder_ appropriately for inline child. |
695 | 695 |
696 // Margins collapsing: Inline block. | 696 // Margins collapsing: Inline block. |
697 curr_bfc_offset_.block_offset += curr_margin_strut_.Sum(); | 697 curr_bfc_offset_.block_offset += curr_margin_strut_.Sum(); |
698 UpdateFragmentBfcOffset(curr_bfc_offset_); | 698 UpdateFragmentBfcOffset(curr_bfc_offset_); |
699 PositionPendingFloats(curr_bfc_offset_.block_offset, ConstraintSpace(), | 699 PositionPendingFloats(curr_bfc_offset_.block_offset, ConstraintSpace(), |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 DCHECK(builder_.BfcOffset()); | 767 DCHECK(builder_.BfcOffset()); |
768 space_available -= curr_bfc_offset_.block_offset; | 768 space_available -= curr_bfc_offset_.block_offset; |
769 } | 769 } |
770 } | 770 } |
771 space_builder_.SetFragmentainerSpaceAvailable(space_available); | 771 space_builder_.SetFragmentainerSpaceAvailable(space_available); |
772 | 772 |
773 return space_builder_.ToConstraintSpace( | 773 return space_builder_.ToConstraintSpace( |
774 FromPlatformWritingMode(child_style.getWritingMode())); | 774 FromPlatformWritingMode(child_style.getWritingMode())); |
775 } | 775 } |
776 } // namespace blink | 776 } // namespace blink |
OLD | NEW |