| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_floats_utils.h" | 5 #include "core/layout/ng/ng_floats_utils.h" |
| 6 | 6 |
| 7 #include "core/layout/ng/ng_box_fragment.h" | 7 #include "core/layout/ng/ng_box_fragment.h" |
| 8 #include "core/layout/ng/ng_layout_opportunity_iterator.h" | 8 #include "core/layout/ng/ng_layout_opportunity_iterator.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 exclusion.type = exclusion_type; | 71 exclusion.type = exclusion_type; |
| 72 NGLogicalRect& rect = exclusion.rect; | 72 NGLogicalRect& rect = exclusion.rect; |
| 73 rect.offset = opportunity.offset; | 73 rect.offset = opportunity.offset; |
| 74 rect.offset.inline_offset += float_offset; | 74 rect.offset.inline_offset += float_offset; |
| 75 | 75 |
| 76 rect.size.inline_size = fragment.InlineSize() + margins.InlineSum(); | 76 rect.size.inline_size = fragment.InlineSize() + margins.InlineSum(); |
| 77 rect.size.block_size = fragment.BlockSize() + margins.BlockSum(); | 77 rect.size.block_size = fragment.BlockSize() + margins.BlockSum(); |
| 78 return exclusion; | 78 return exclusion; |
| 79 } | 79 } |
| 80 | 80 |
| 81 // Updates the Floating Object's left offset from the provided parent_space | 81 // Calculates the Floating Object's left offset from the provided parent_space |
| 82 // and {@code floating_object}'s space and margins. | 82 // and {@code floating_object}'s space and margins. |
| 83 void UpdateFloatingObjectLeftOffset(const NGConstraintSpace& new_parent_space, | 83 LayoutUnit CalculateLeftOffset(const NGConstraintSpace& new_parent_space, |
| 84 const NGLogicalOffset& float_logical_offset, | 84 const NGLogicalOffset& float_logical_offset, |
| 85 NGFloatingObject* floating_object) { | 85 const NGFloatingObject& floating_object) { |
| 86 DCHECK(floating_object); | |
| 87 // TODO(glebl): We should use physical offset here. | 86 // TODO(glebl): We should use physical offset here. |
| 88 floating_object->left_offset = floating_object->from_offset.inline_offset - | 87 return floating_object.from_offset.inline_offset - |
| 89 new_parent_space.BfcOffset().inline_offset + | 88 new_parent_space.BfcOffset().inline_offset + |
| 90 float_logical_offset.inline_offset; | 89 float_logical_offset.inline_offset; |
| 91 } | 90 } |
| 92 } // namespace | 91 } // namespace |
| 93 | 92 |
| 94 NGLogicalOffset PositionFloat(NGFloatingObject* floating_object, | 93 NGPositionedFloat PositionFloat(NGFloatingObject* floating_object, |
| 95 NGConstraintSpace* new_parent_space) { | 94 NGConstraintSpace* new_parent_space) { |
| 96 DCHECK(floating_object); | 95 DCHECK(floating_object); |
| 97 DCHECK(floating_object->fragment) << "Fragment cannot be null here"; | 96 DCHECK(floating_object->fragment) << "Fragment cannot be null here"; |
| 98 | 97 |
| 99 // TODO(ikilpatrick): The writing mode switching here looks wrong. | 98 // TODO(ikilpatrick): The writing mode switching here looks wrong. |
| 100 NGBoxFragment float_fragment( | 99 NGBoxFragment float_fragment( |
| 101 floating_object->writing_mode, | 100 floating_object->writing_mode, |
| 102 ToNGPhysicalBoxFragment(floating_object->fragment.Get())); | 101 ToNGPhysicalBoxFragment(floating_object->fragment.Get())); |
| 103 | 102 |
| 104 // Find a layout opportunity that will fit our float. | 103 // Find a layout opportunity that will fit our float. |
| 105 NGLayoutOpportunity opportunity = FindLayoutOpportunityForFloat( | 104 NGLayoutOpportunity opportunity = FindLayoutOpportunityForFloat( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 125 } | 124 } |
| 126 | 125 |
| 127 // Add the float as an exclusion. | 126 // Add the float as an exclusion. |
| 128 const NGExclusion exclusion = CreateExclusion( | 127 const NGExclusion exclusion = CreateExclusion( |
| 129 float_fragment, opportunity, float_offset, floating_object->margins, | 128 float_fragment, opportunity, float_offset, floating_object->margins, |
| 130 floating_object->exclusion_type); | 129 floating_object->exclusion_type); |
| 131 new_parent_space->AddExclusion(exclusion); | 130 new_parent_space->AddExclusion(exclusion); |
| 132 | 131 |
| 133 NGLogicalOffset logical_offset = CalculateLogicalOffsetForOpportunity( | 132 NGLogicalOffset logical_offset = CalculateLogicalOffsetForOpportunity( |
| 134 opportunity, float_offset, floating_object); | 133 opportunity, float_offset, floating_object); |
| 135 UpdateFloatingObjectLeftOffset(*new_parent_space, logical_offset, | 134 |
| 136 floating_object); | 135 LayoutUnit left_offset = |
| 137 return logical_offset; | 136 CalculateLeftOffset(*new_parent_space, logical_offset, *floating_object); |
| 137 |
| 138 return NGPositionedFloat(floating_object->fragment, logical_offset, |
| 139 left_offset); |
| 138 } | 140 } |
| 139 | 141 |
| 140 void PositionFloats(LayoutUnit origin_block_offset, | 142 void PositionFloats(LayoutUnit origin_block_offset, |
| 141 LayoutUnit from_block_offset, | 143 LayoutUnit from_block_offset, |
| 142 const Vector<RefPtr<NGFloatingObject>>& floating_objects, | 144 const Vector<RefPtr<NGFloatingObject>>& floating_objects, |
| 145 Vector<NGPositionedFloat>* positioned_floats, |
| 143 NGConstraintSpace* space) { | 146 NGConstraintSpace* space) { |
| 144 for (auto& floating_object : floating_objects) { | 147 for (auto& floating_object : floating_objects) { |
| 145 floating_object->origin_offset.block_offset = origin_block_offset; | 148 floating_object->origin_offset.block_offset = origin_block_offset; |
| 146 floating_object->from_offset.block_offset = from_block_offset; | 149 floating_object->from_offset.block_offset = from_block_offset; |
| 147 floating_object->logical_offset = | 150 if (positioned_floats) { |
| 148 PositionFloat(floating_object.Get(), space); | 151 positioned_floats->push_back(PositionFloat(floating_object.Get(), space)); |
| 152 } else { |
| 153 PositionFloat(floating_object.Get(), space); |
| 154 } |
| 149 } | 155 } |
| 150 } | 156 } |
| 151 | 157 |
| 152 } // namespace blink | 158 } // namespace blink |
| OLD | NEW |