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_constraint_space.h" | 7 #include "core/layout/ng/ng_constraint_space.h" |
8 #include "core/layout/ng/ng_fragment_builder.h" | 8 #include "core/layout/ng/ng_fragment_builder.h" |
9 #include "core/layout/ng/ng_fragment.h" | 9 #include "core/layout/ng/ng_fragment.h" |
10 #include "core/layout/ng/ng_layout_opportunity_iterator.h" | 10 #include "core/layout/ng/ng_layout_opportunity_iterator.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 } | 48 } |
49 | 49 |
50 // Finds a layout opportunity for the fragment. | 50 // Finds a layout opportunity for the fragment. |
51 // It iterates over all layout opportunities in the constraint space and returns | 51 // It iterates over all layout opportunities in the constraint space and returns |
52 // the first layout opportunity that is wider than the fragment or returns the | 52 // the first layout opportunity that is wider than the fragment or returns the |
53 // last one which is always the widest. | 53 // last one which is always the widest. |
54 // | 54 // |
55 // @param space Constraint space that is used to find layout opportunity for | 55 // @param space Constraint space that is used to find layout opportunity for |
56 // the fragment. | 56 // the fragment. |
57 // @param fragment Fragment that needs to be placed. | 57 // @param fragment Fragment that needs to be placed. |
| 58 // @param margins Margins of the fragment. |
58 // @return Layout opportunity for the fragment. | 59 // @return Layout opportunity for the fragment. |
59 const NGLayoutOpportunity FindLayoutOpportunityForFragment( | 60 const NGLayoutOpportunity FindLayoutOpportunityForFragment( |
60 const Member<NGConstraintSpace>& space, | 61 const Member<NGConstraintSpace>& space, |
61 const NGFragment& fragment) { | 62 const NGFragment& fragment, |
| 63 const NGBoxStrut& margins) { |
62 NGLayoutOpportunityIterator* opportunity_iter = space->LayoutOpportunities(); | 64 NGLayoutOpportunityIterator* opportunity_iter = space->LayoutOpportunities(); |
63 NGLayoutOpportunity opportunity; | 65 NGLayoutOpportunity opportunity; |
64 NGLayoutOpportunity opportunity_candidate = opportunity_iter->Next(); | 66 NGLayoutOpportunity opportunity_candidate = opportunity_iter->Next(); |
65 | 67 |
66 while (!opportunity_candidate.IsEmpty()) { | 68 while (!opportunity_candidate.IsEmpty()) { |
67 opportunity = opportunity_candidate; | 69 opportunity = opportunity_candidate; |
68 // Checking opportunity's block size is not necessary as a float cannot be | 70 // Checking opportunity's block size is not necessary as a float cannot be |
69 // positioned on top of another float inside of the same constraint space. | 71 // positioned on top of another float inside of the same constraint space. |
70 if (opportunity.size.inline_size > fragment.InlineSize()) | 72 auto fragment_inline_size = fragment.InlineSize() + margins.InlineSum(); |
| 73 if (opportunity.size.inline_size > fragment_inline_size) |
71 break; | 74 break; |
72 | 75 |
73 opportunity_candidate = opportunity_iter->Next(); | 76 opportunity_candidate = opportunity_iter->Next(); |
74 } | 77 } |
75 | 78 |
76 return opportunity; | 79 return opportunity; |
77 } | 80 } |
78 | 81 |
79 // Calculates the logical offset for opportunity. | 82 // Calculates the logical offset for opportunity. |
80 NGLogicalOffset CalculateLogicalOffsetForOpportunity( | 83 NGLogicalOffset CalculateLogicalOffsetForOpportunity( |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 border_and_padding_.InlineSum()); | 323 border_and_padding_.InlineSum()); |
321 return NGLogicalOffset(inline_offset, block_offset); | 324 return NGLogicalOffset(inline_offset, block_offset); |
322 } | 325 } |
323 | 326 |
324 NGLogicalOffset NGBlockLayoutAlgorithm::PositionFloatFragment( | 327 NGLogicalOffset NGBlockLayoutAlgorithm::PositionFloatFragment( |
325 const NGFragment& fragment, | 328 const NGFragment& fragment, |
326 const NGBoxStrut& margins) { | 329 const NGBoxStrut& margins) { |
327 // TODO(glebl@chromium.org): Support the top edge alignment rule. | 330 // TODO(glebl@chromium.org): Support the top edge alignment rule. |
328 // Find a layout opportunity that will fit our float. | 331 // Find a layout opportunity that will fit our float. |
329 const NGLayoutOpportunity opportunity = FindLayoutOpportunityForFragment( | 332 const NGLayoutOpportunity opportunity = FindLayoutOpportunityForFragment( |
330 constraint_space_for_children_, fragment); | 333 constraint_space_for_children_, fragment, margins); |
331 DCHECK(!opportunity.IsEmpty()) << "Opportunity is empty but it shouldn't be"; | 334 DCHECK(!opportunity.IsEmpty()) << "Opportunity is empty but it shouldn't be"; |
332 | 335 |
333 // Calculate the float offset if needed. | 336 // Calculate the float offset if needed. |
334 LayoutUnit float_offset; | 337 LayoutUnit float_offset; |
335 if (current_child_->Style()->floating() == EFloat::Right) { | 338 if (current_child_->Style()->floating() == EFloat::Right) { |
336 float_offset = opportunity.size.inline_size - fragment.InlineSize(); | 339 float_offset = opportunity.size.inline_size - fragment.InlineSize(); |
337 } | 340 } |
338 | 341 |
339 // Add the float as an exclusion. | 342 // Add the float as an exclusion. |
340 NGExclusion* exclusion = | 343 const NGExclusion* exclusion = |
341 CreateExclusion(fragment, opportunity, float_offset, margins); | 344 CreateExclusion(fragment, opportunity, float_offset, margins); |
342 constraint_space_for_children_->AddExclusion(exclusion); | 345 constraint_space_for_children_->AddExclusion(exclusion); |
343 | 346 |
344 return CalculateLogicalOffsetForOpportunity(opportunity, border_and_padding_, | 347 return CalculateLogicalOffsetForOpportunity(opportunity, border_and_padding_, |
345 float_offset, margins); | 348 float_offset, margins); |
346 } | 349 } |
347 | 350 |
348 void NGBlockLayoutAlgorithm::UpdateMarginStrut(const NGMarginStrut& from) { | 351 void NGBlockLayoutAlgorithm::UpdateMarginStrut(const NGMarginStrut& from) { |
349 if (!is_fragment_margin_strut_block_start_updated_) { | 352 if (!is_fragment_margin_strut_block_start_updated_) { |
350 builder_->SetMarginStrutBlockStart(from); | 353 builder_->SetMarginStrutBlockStart(from); |
351 is_fragment_margin_strut_block_start_updated_ = true; | 354 is_fragment_margin_strut_block_start_updated_ = true; |
352 } | 355 } |
353 builder_->SetMarginStrutBlockEnd(from); | 356 builder_->SetMarginStrutBlockEnd(from); |
354 } | 357 } |
355 | 358 |
356 } // namespace blink | 359 } // namespace blink |
OLD | NEW |