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 22 matching lines...) Expand all Loading... | |
33 // the first layout opportunity that is wider than the fragment or returns the | 33 // the first layout opportunity that is wider than the fragment or returns the |
34 // last one which is always the widest. | 34 // last one which is always the widest. |
35 // | 35 // |
36 // @param space Constraint space that is used to find layout opportunity for | 36 // @param space Constraint space that is used to find layout opportunity for |
37 // the fragment. | 37 // the fragment. |
38 // @param fragment Fragment that needs to be placed. | 38 // @param fragment Fragment that needs to be placed. |
39 // @param origin_point {@code space}'s offset relative to the space that | 39 // @param origin_point {@code space}'s offset relative to the space that |
40 // establishes a new formatting context that we're currently | 40 // establishes a new formatting context that we're currently |
41 // in and where all our exclusions reside. | 41 // in and where all our exclusions reside. |
42 // @param margins Margins of the fragment. | 42 // @param margins Margins of the fragment. |
43 // @param available_size Available size used by the layout opportunity iterator. | |
43 // @return Layout opportunity for the fragment. | 44 // @return Layout opportunity for the fragment. |
44 const NGLayoutOpportunity FindLayoutOpportunityForFragment( | 45 const NGLayoutOpportunity FindLayoutOpportunityForFragment( |
45 const NGConstraintSpace* space, | 46 const NGConstraintSpace* space, |
46 const NGFragment& fragment, | 47 const NGFragment& fragment, |
47 const NGLogicalOffset& origin_point, | 48 const NGLogicalOffset& origin_point, |
ikilpatrick
2017/03/24 21:17:34
so what i was imagining is that the caller to this
Gleb Lanbin
2017/03/24 21:49:36
Acknowledged.
| |
48 const NGBoxStrut& margins) { | 49 const NGBoxStrut& margins, |
50 const NGLogicalSize& available_size) { | |
49 NGLogicalOffset adjusted_origin_point = | 51 NGLogicalOffset adjusted_origin_point = |
50 AdjustToTopEdgeAlignmentRule(*space, origin_point); | 52 AdjustToTopEdgeAlignmentRule(*space, origin_point); |
51 | 53 |
52 NGLayoutOpportunityIterator opportunity_iter(space, adjusted_origin_point); | 54 NGLayoutOpportunityIterator opportunity_iter(space, available_size, |
55 adjusted_origin_point); | |
53 NGLayoutOpportunity opportunity; | 56 NGLayoutOpportunity opportunity; |
54 NGLayoutOpportunity opportunity_candidate = opportunity_iter.Next(); | 57 NGLayoutOpportunity opportunity_candidate = opportunity_iter.Next(); |
55 | 58 |
56 while (!opportunity_candidate.IsEmpty()) { | 59 while (!opportunity_candidate.IsEmpty()) { |
57 opportunity = opportunity_candidate; | 60 opportunity = opportunity_candidate; |
58 // Checking opportunity's block size is not necessary as a float cannot be | 61 // Checking opportunity's block size is not necessary as a float cannot be |
59 // positioned on top of another float inside of the same constraint space. | 62 // positioned on top of another float inside of the same constraint space. |
60 auto fragment_inline_size = fragment.InlineSize() + margins.InlineSum(); | 63 auto fragment_inline_size = fragment.InlineSize() + margins.InlineSum(); |
61 if (opportunity.size.inline_size >= fragment_inline_size) | 64 if (opportunity.size.inline_size >= fragment_inline_size) |
62 break; | 65 break; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 const auto* float_space = floating_object->space.get(); | 136 const auto* float_space = floating_object->space.get(); |
134 DCHECK(floating_object->fragment) << "Fragment cannot be null here"; | 137 DCHECK(floating_object->fragment) << "Fragment cannot be null here"; |
135 | 138 |
136 // TODO(ikilpatrick): The writing mode switching here looks wrong. | 139 // TODO(ikilpatrick): The writing mode switching here looks wrong. |
137 NGBoxFragment float_fragment( | 140 NGBoxFragment float_fragment( |
138 float_space->WritingMode(), | 141 float_space->WritingMode(), |
139 toNGPhysicalBoxFragment(floating_object->fragment.get())); | 142 toNGPhysicalBoxFragment(floating_object->fragment.get())); |
140 | 143 |
141 // Find a layout opportunity that will fit our float. | 144 // Find a layout opportunity that will fit our float. |
142 const NGLayoutOpportunity opportunity = FindLayoutOpportunityForFragment( | 145 const NGLayoutOpportunity opportunity = FindLayoutOpportunityForFragment( |
143 float_space, float_fragment, origin_point, floating_object->margins); | 146 new_parent_space, float_fragment, origin_point, floating_object->margins, |
ikilpatrick
2017/03/24 21:17:34
from above: e.g.
NGLogicalOffset adjusted_point({
Gleb Lanbin
2017/03/24 21:49:36
I find this additional adjustment a bit confusing.
| |
147 floating_object->available_size); | |
144 DCHECK(!opportunity.IsEmpty()) << "Opportunity is empty but it shouldn't be"; | 148 DCHECK(!opportunity.IsEmpty()) << "Opportunity is empty but it shouldn't be"; |
145 | 149 |
146 // Calculate the float offset if needed. | 150 // Calculate the float offset if needed. |
147 LayoutUnit float_offset; | 151 LayoutUnit float_offset; |
148 if (floating_object->exclusion_type == NGExclusion::kFloatRight) { | 152 if (floating_object->exclusion_type == NGExclusion::kFloatRight) { |
149 LayoutUnit float_margin_box_inline_size = | 153 LayoutUnit float_margin_box_inline_size = |
150 float_fragment.InlineSize() + floating_object->margins.InlineSum(); | 154 float_fragment.InlineSize() + floating_object->margins.InlineSum(); |
151 float_offset = opportunity.size.inline_size - float_margin_box_inline_size; | 155 float_offset = opportunity.size.inline_size - float_margin_box_inline_size; |
152 } | 156 } |
153 | 157 |
154 // Add the float as an exclusion. | 158 // Add the float as an exclusion. |
155 const NGExclusion exclusion = CreateExclusion( | 159 const NGExclusion exclusion = CreateExclusion( |
156 float_fragment, opportunity, float_offset, floating_object->margins, | 160 float_fragment, opportunity, float_offset, floating_object->margins, |
157 floating_object->exclusion_type); | 161 floating_object->exclusion_type); |
158 new_parent_space->AddExclusion(exclusion); | 162 new_parent_space->AddExclusion(exclusion); |
159 | 163 |
160 NGLogicalOffset logical_offset = CalculateLogicalOffsetForOpportunity( | 164 NGLogicalOffset logical_offset = CalculateLogicalOffsetForOpportunity( |
161 opportunity, float_offset, from_offset, floating_object); | 165 opportunity, float_offset, from_offset, floating_object); |
162 UpdateFloatingObjectLeftOffset(*new_parent_space, logical_offset, | 166 UpdateFloatingObjectLeftOffset(*new_parent_space, logical_offset, |
163 floating_object); | 167 floating_object); |
164 return logical_offset; | 168 return logical_offset; |
165 } | 169 } |
166 } // namespace blink | 170 } // namespace blink |
OLD | NEW |