Chromium Code Reviews| 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_box_fragment.h" | 9 #include "core/layout/ng/ng_box_fragment.h" |
| 10 #include "core/layout/ng/ng_column_mapper.h" | 10 #include "core/layout/ng/ng_column_mapper.h" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 | 203 |
| 204 // Find a layout opportunity that will fit our float. | 204 // Find a layout opportunity that will fit our float. |
| 205 const NGLayoutOpportunity opportunity = | 205 const NGLayoutOpportunity opportunity = |
| 206 FindLayoutOpportunityForFragment(floating_object->space, float_fragment, | 206 FindLayoutOpportunityForFragment(floating_object->space, float_fragment, |
| 207 origin_point, floating_object->margins); | 207 origin_point, floating_object->margins); |
| 208 DCHECK(!opportunity.IsEmpty()) << "Opportunity is empty but it shouldn't be"; | 208 DCHECK(!opportunity.IsEmpty()) << "Opportunity is empty but it shouldn't be"; |
| 209 | 209 |
| 210 // Calculate the float offset if needed. | 210 // Calculate the float offset if needed. |
| 211 LayoutUnit float_offset; | 211 LayoutUnit float_offset; |
| 212 if (floating_object->exclusion_type == NGExclusion::kFloatRight) { | 212 if (floating_object->exclusion_type == NGExclusion::kFloatRight) { |
| 213 float_offset = opportunity.size.inline_size - float_fragment.InlineSize(); | 213 LayoutUnit float_box_inline_size = |
|
ikilpatrick
2017/02/22 18:04:36
float_margin_box_inline_size? (up to you)
Gleb Lanbin
2017/02/22 18:47:17
Done.
| |
| 214 float_fragment.InlineSize() + floating_object->margins.InlineSum(); | |
| 215 float_offset = opportunity.size.inline_size - float_box_inline_size; | |
| 214 } | 216 } |
| 215 | 217 |
| 216 // Add the float as an exclusion. | 218 // Add the float as an exclusion. |
| 217 const NGExclusion exclusion = CreateExclusion( | 219 const NGExclusion exclusion = CreateExclusion( |
| 218 float_fragment, opportunity, float_offset, floating_object->margins, | 220 float_fragment, opportunity, float_offset, floating_object->margins, |
| 219 floating_object->exclusion_type); | 221 floating_object->exclusion_type); |
| 220 float_space->AddExclusion(exclusion); | 222 float_space->AddExclusion(exclusion); |
| 221 | 223 |
| 222 return CalculateLogicalOffsetForOpportunity(opportunity, float_offset, | 224 return CalculateLogicalOffsetForOpportunity(opportunity, float_offset, |
| 223 from_offset, floating_object); | 225 from_offset, floating_object); |
| 224 } | 226 } |
| 225 | 227 |
| 226 // Updates the Floating Object's left offset from the provided parent_space | 228 // Updates the Floating Object's left offset from the provided parent_space |
| 227 // and {@code floating_object}'s space and margins. | 229 // and {@code floating_object}'s space and margins. |
| 228 void UpdateFloatingObjectLeftOffset( | 230 void UpdateFloatingObjectLeftOffset( |
| 229 const NGConstraintSpace& new_parent_space, | 231 const NGConstraintSpace& new_parent_space, |
| 230 const Persistent<NGFloatingObject>& floating_object) { | 232 const Persistent<NGFloatingObject>& floating_object, |
| 231 const auto& float_space = floating_object->space; | 233 const NGLogicalOffset& float_logical_offset) { |
| 232 // TODO(glebl): We should use physical offset here. | 234 // TODO(glebl): We should use physical offset here. |
| 233 floating_object->left_offset = float_space->BfcOffset().inline_offset - | 235 floating_object->left_offset = |
| 234 new_parent_space.BfcOffset().inline_offset + | 236 floating_object->original_parent_space->BfcOffset().inline_offset - |
| 235 floating_object->margins.inline_start; | 237 new_parent_space.BfcOffset().inline_offset + |
| 238 float_logical_offset.inline_offset; | |
| 236 } | 239 } |
| 237 | 240 |
| 238 // Positions pending floats stored on the fragment builder starting from | 241 // Positions pending floats stored on the fragment builder starting from |
| 239 // {@code origin_point_block_offset}. | 242 // {@code origin_point_block_offset}. |
| 240 void PositionPendingFloats(const LayoutUnit origin_point_block_offset, | 243 void PositionPendingFloats(const LayoutUnit origin_point_block_offset, |
| 241 const NGConstraintSpace& new_parent_space, | 244 const NGConstraintSpace& new_parent_space, |
| 242 NGFragmentBuilder* builder) { | 245 NGFragmentBuilder* builder) { |
| 243 DCHECK(builder->BfcOffset()) << "Parent BFC offset should be known here"; | 246 DCHECK(builder->BfcOffset()) << "Parent BFC offset should be known here"; |
| 244 LayoutUnit bfc_block_offset = builder->BfcOffset().value().block_offset; | 247 LayoutUnit bfc_block_offset = builder->BfcOffset().value().block_offset; |
| 245 | 248 |
| 246 for (auto& floating_object : builder->UnpositionedFloats()) { | 249 for (auto& floating_object : builder->UnpositionedFloats()) { |
| 247 Member<NGConstraintSpace> float_space = floating_object->space; | 250 Member<NGConstraintSpace> float_space = floating_object->space; |
| 248 Member<const NGConstraintSpace> float_parent_space = | 251 Member<const NGConstraintSpace> original_parent_space = |
| 249 floating_object->parent_space; | 252 floating_object->original_parent_space; |
| 250 | 253 |
| 251 NGLogicalOffset origin_point = {float_space->BfcOffset().inline_offset, | 254 NGLogicalOffset origin_point = {float_space->BfcOffset().inline_offset, |
| 252 origin_point_block_offset}; | 255 origin_point_block_offset}; |
| 253 NGLogicalOffset from_offset = { | 256 NGLogicalOffset from_offset = { |
| 254 float_parent_space->BfcOffset().inline_offset, bfc_block_offset}; | 257 original_parent_space->BfcOffset().inline_offset, bfc_block_offset}; |
| 255 | 258 |
| 256 NGLogicalOffset float_fragment_offset = | 259 NGLogicalOffset float_fragment_offset = |
| 257 PositionFloat(origin_point, from_offset, floating_object); | 260 PositionFloat(origin_point, from_offset, floating_object); |
| 258 builder->AddFloatingObject(floating_object, float_fragment_offset); | 261 builder->AddFloatingObject(floating_object, float_fragment_offset); |
| 259 UpdateFloatingObjectLeftOffset(new_parent_space, floating_object); | 262 UpdateFloatingObjectLeftOffset(new_parent_space, floating_object, |
| 263 float_fragment_offset); | |
| 260 } | 264 } |
| 261 builder->MutableUnpositionedFloats().clear(); | 265 builder->MutableUnpositionedFloats().clear(); |
| 262 } | 266 } |
| 263 | 267 |
| 264 // Whether an in-flow block-level child creates a new formatting context. | 268 // Whether an in-flow block-level child creates a new formatting context. |
| 265 // | 269 // |
| 266 // This will *NOT* check the following cases: | 270 // This will *NOT* check the following cases: |
| 267 // - The child is out-of-flow, e.g. floating or abs-pos. | 271 // - The child is out-of-flow, e.g. floating or abs-pos. |
| 268 // - The child is a inline-level, e.g. "display: inline-block". | 272 // - The child is a inline-level, e.g. "display: inline-block". |
| 269 // - The child establishes a new formatting context, but should be a child of | 273 // - The child establishes a new formatting context, but should be a child of |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 830 space_builder_->SetMarginStrut(curr_margin_strut_); | 834 space_builder_->SetMarginStrut(curr_margin_strut_); |
| 831 } | 835 } |
| 832 | 836 |
| 833 space_builder_->SetBfcOffset(curr_bfc_offset_); | 837 space_builder_->SetBfcOffset(curr_bfc_offset_); |
| 834 | 838 |
| 835 return space_builder_->ToConstraintSpace( | 839 return space_builder_->ToConstraintSpace( |
| 836 FromPlatformWritingMode(current_child_style.getWritingMode())); | 840 FromPlatformWritingMode(current_child_style.getWritingMode())); |
| 837 } | 841 } |
| 838 | 842 |
| 839 } // namespace blink | 843 } // namespace blink |
| OLD | NEW |