| 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 | 8 |
| 9 namespace blink { | 9 namespace blink { |
| 10 namespace { | 10 namespace { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 NGConstraintSpace* new_parent_space) { | 120 NGConstraintSpace* new_parent_space) { |
| 121 DCHECK(floating_object); | 121 DCHECK(floating_object); |
| 122 DCHECK(floating_object->fragment) << "Fragment cannot be null here"; | 122 DCHECK(floating_object->fragment) << "Fragment cannot be null here"; |
| 123 | 123 |
| 124 // TODO(ikilpatrick): The writing mode switching here looks wrong. | 124 // TODO(ikilpatrick): The writing mode switching here looks wrong. |
| 125 NGBoxFragment float_fragment( | 125 NGBoxFragment float_fragment( |
| 126 floating_object->writing_mode, | 126 floating_object->writing_mode, |
| 127 toNGPhysicalBoxFragment(floating_object->fragment.get())); | 127 toNGPhysicalBoxFragment(floating_object->fragment.get())); |
| 128 | 128 |
| 129 // Find a layout opportunity that will fit our float. | 129 // Find a layout opportunity that will fit our float. |
| 130 const NGLayoutOpportunity opportunity = FindLayoutOpportunityForFragment( | 130 NGLayoutOpportunity opportunity = FindLayoutOpportunityForFragment( |
| 131 new_parent_space, float_fragment, floating_object); | 131 new_parent_space, float_fragment, floating_object); |
| 132 DCHECK(!opportunity.IsEmpty()) << "Opportunity is empty but it shouldn't be"; | 132 |
| 133 // TODO(glebl): This should check for infinite opportunity instead. |
| 134 if (opportunity.IsEmpty()) { |
| 135 // Because of the implementation specific of the layout opportunity iterator |
| 136 // an empty opportunity can mean 2 things: |
| 137 // - search for layout opportunities is exhausted. |
| 138 // - opportunity has an infinite size. That's because CS is infinite. |
| 139 opportunity = NGLayoutOpportunity( |
| 140 NGLogicalOffset(), |
| 141 NGLogicalSize(float_fragment.InlineSize(), float_fragment.BlockSize())); |
| 142 } |
| 133 | 143 |
| 134 // Calculate the float offset if needed. | 144 // Calculate the float offset if needed. |
| 135 LayoutUnit float_offset; | 145 LayoutUnit float_offset; |
| 136 if (floating_object->exclusion_type == NGExclusion::kFloatRight) { | 146 if (floating_object->exclusion_type == NGExclusion::kFloatRight) { |
| 137 LayoutUnit float_margin_box_inline_size = | 147 LayoutUnit float_margin_box_inline_size = |
| 138 float_fragment.InlineSize() + floating_object->margins.InlineSum(); | 148 float_fragment.InlineSize() + floating_object->margins.InlineSum(); |
| 139 float_offset = opportunity.size.inline_size - float_margin_box_inline_size; | 149 float_offset = opportunity.size.inline_size - float_margin_box_inline_size; |
| 140 } | 150 } |
| 141 | 151 |
| 142 // Add the float as an exclusion. | 152 // Add the float as an exclusion. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 163 floating_object->origin_offset.block_offset = origin_block_offset; | 173 floating_object->origin_offset.block_offset = origin_block_offset; |
| 164 floating_object->from_offset.block_offset = bfc_block_offset; | 174 floating_object->from_offset.block_offset = bfc_block_offset; |
| 165 | 175 |
| 166 NGLogicalOffset offset = PositionFloat(floating_object.get(), space); | 176 NGLogicalOffset offset = PositionFloat(floating_object.get(), space); |
| 167 builder->AddFloatingObject(floating_object, offset); | 177 builder->AddFloatingObject(floating_object, offset); |
| 168 } | 178 } |
| 169 builder->MutableUnpositionedFloats().clear(); | 179 builder->MutableUnpositionedFloats().clear(); |
| 170 } | 180 } |
| 171 | 181 |
| 172 } // namespace blink | 182 } // namespace blink |
| OLD | NEW |