| 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 // Calculates the Floating Object's left offset from the provided parent_space | 81 // Updates the Floating Object's left and top offsets. |
| 82 // and {@code floating_object}'s space and margins. | 82 NGPhysicalOffset CalculateFloatingObjectPaintOffset( |
| 83 LayoutUnit CalculateLeftOffset(const NGConstraintSpace& new_parent_space, | 83 const NGConstraintSpace& new_parent_space, |
| 84 const NGLogicalOffset& float_logical_offset, | 84 const NGLogicalOffset& float_logical_offset, |
| 85 const NGFloatingObject& floating_object) { | 85 const NGFloatingObject& floating_object) { |
| 86 // TODO(glebl): We should use physical offset here. | 86 // TODO(glebl): We should use physical offset here. |
| 87 return floating_object.from_offset.inline_offset - | 87 LayoutUnit left_offset = floating_object.from_offset.inline_offset - |
| 88 new_parent_space.BfcOffset().inline_offset + | 88 new_parent_space.BfcOffset().inline_offset + |
| 89 float_logical_offset.inline_offset; | 89 float_logical_offset.inline_offset; |
| 90 DCHECK(floating_object.parent_bfc_block_offset); |
| 91 LayoutUnit top_offset = floating_object.from_offset.block_offset - |
| 92 floating_object.parent_bfc_block_offset.value() + |
| 93 float_logical_offset.block_offset; |
| 94 return {left_offset, top_offset}; |
| 90 } | 95 } |
| 91 } // namespace | 96 } // namespace |
| 92 | 97 |
| 93 NGPositionedFloat PositionFloat(NGFloatingObject* floating_object, | 98 NGPositionedFloat PositionFloat(NGFloatingObject* floating_object, |
| 94 NGConstraintSpace* new_parent_space) { | 99 NGConstraintSpace* new_parent_space) { |
| 95 DCHECK(floating_object); | 100 DCHECK(floating_object); |
| 96 DCHECK(floating_object->fragment) << "Fragment cannot be null here"; | 101 DCHECK(floating_object->fragment) << "Fragment cannot be null here"; |
| 97 | 102 |
| 98 // TODO(ikilpatrick): The writing mode switching here looks wrong. | 103 // TODO(ikilpatrick): The writing mode switching here looks wrong. |
| 99 NGBoxFragment float_fragment( | 104 NGBoxFragment float_fragment( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 124 } | 129 } |
| 125 | 130 |
| 126 // Add the float as an exclusion. | 131 // Add the float as an exclusion. |
| 127 const NGExclusion exclusion = CreateExclusion( | 132 const NGExclusion exclusion = CreateExclusion( |
| 128 float_fragment, opportunity, float_offset, floating_object->margins, | 133 float_fragment, opportunity, float_offset, floating_object->margins, |
| 129 floating_object->exclusion_type); | 134 floating_object->exclusion_type); |
| 130 new_parent_space->AddExclusion(exclusion); | 135 new_parent_space->AddExclusion(exclusion); |
| 131 | 136 |
| 132 NGLogicalOffset logical_offset = CalculateLogicalOffsetForOpportunity( | 137 NGLogicalOffset logical_offset = CalculateLogicalOffsetForOpportunity( |
| 133 opportunity, float_offset, floating_object); | 138 opportunity, float_offset, floating_object); |
| 134 | 139 NGPhysicalOffset paint_offset = CalculateFloatingObjectPaintOffset( |
| 135 LayoutUnit left_offset = | 140 *new_parent_space, logical_offset, *floating_object); |
| 136 CalculateLeftOffset(*new_parent_space, logical_offset, *floating_object); | |
| 137 | 141 |
| 138 return NGPositionedFloat(floating_object->fragment, logical_offset, | 142 return NGPositionedFloat(floating_object->fragment, logical_offset, |
| 139 left_offset); | 143 paint_offset); |
| 140 } | 144 } |
| 141 | 145 |
| 142 const Vector<NGPositionedFloat> PositionFloats( | 146 const Vector<NGPositionedFloat> PositionFloats( |
| 143 LayoutUnit origin_block_offset, | 147 LayoutUnit origin_block_offset, |
| 144 LayoutUnit from_block_offset, | 148 LayoutUnit from_block_offset, |
| 149 LayoutUnit parent_bfc_offset, |
| 145 const Vector<RefPtr<NGFloatingObject>>& floating_objects, | 150 const Vector<RefPtr<NGFloatingObject>>& floating_objects, |
| 146 NGConstraintSpace* space) { | 151 NGConstraintSpace* space) { |
| 147 Vector<NGPositionedFloat> positioned_floats; | 152 Vector<NGPositionedFloat> positioned_floats; |
| 148 positioned_floats.ReserveCapacity(floating_objects.size()); | 153 positioned_floats.ReserveCapacity(floating_objects.size()); |
| 149 | 154 |
| 150 for (auto& floating_object : floating_objects) { | 155 for (auto& floating_object : floating_objects) { |
| 151 floating_object->origin_offset.block_offset = origin_block_offset; | 156 floating_object->origin_offset.block_offset = origin_block_offset; |
| 152 floating_object->from_offset.block_offset = from_block_offset; | 157 floating_object->from_offset.block_offset = from_block_offset; |
| 158 floating_object->parent_bfc_block_offset = parent_bfc_offset; |
| 153 positioned_floats.push_back(PositionFloat(floating_object.Get(), space)); | 159 positioned_floats.push_back(PositionFloat(floating_object.Get(), space)); |
| 154 } | 160 } |
| 155 | 161 |
| 156 return positioned_floats; | 162 return positioned_floats; |
| 157 } | 163 } |
| 158 | 164 |
| 159 } // namespace blink | 165 } // namespace blink |
| OLD | NEW |