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_constraint_space_builder.h" | 8 #include "core/layout/ng/ng_constraint_space_builder.h" |
9 #include "core/layout/ng/ng_layout_opportunity_iterator.h" | 9 #include "core/layout/ng/ng_layout_opportunity_iterator.h" |
10 #include "core/layout/ng/ng_layout_result.h" | 10 #include "core/layout/ng/ng_layout_result.h" |
11 #include "core/layout/ng/ng_length_utils.h" | 11 #include "core/layout/ng/ng_length_utils.h" |
12 #include "core/layout/ng/ng_min_max_content_size.h" | 12 #include "core/layout/ng/ng_min_max_content_size.h" |
| 13 #include "core/layout/ng/ng_space_utils.h" |
13 | 14 |
14 namespace blink { | 15 namespace blink { |
15 namespace { | 16 namespace { |
16 | 17 |
17 // Adjusts the provided offset to the top edge alignment rule. | 18 // Adjusts the provided offset to the top edge alignment rule. |
18 // Top edge alignment rule: the outer top of a floating box may not be higher | 19 // Top edge alignment rule: the outer top of a floating box may not be higher |
19 // than the outer top of any block or floated box generated by an element | 20 // than the outer top of any block or floated box generated by an element |
20 // earlier in the source document. | 21 // earlier in the source document. |
21 NGLogicalOffset AdjustToTopEdgeAlignmentRule(const NGConstraintSpace& space, | 22 NGLogicalOffset AdjustToTopEdgeAlignmentRule(const NGConstraintSpace& space, |
22 const NGLogicalOffset& offset) { | 23 const NGLogicalOffset& offset) { |
23 NGLogicalOffset adjusted_offset = offset; | 24 NGLogicalOffset adjusted_offset = offset; |
24 LayoutUnit& adjusted_block_offset = adjusted_offset.block_offset; | 25 LayoutUnit& adjusted_block_offset = adjusted_offset.block_offset; |
25 if (space.Exclusions()->last_left_float) | 26 if (space.Exclusions()->last_left_float) |
26 adjusted_block_offset = | 27 adjusted_block_offset = |
27 std::max(adjusted_block_offset, | 28 std::max(adjusted_block_offset, |
28 space.Exclusions()->last_left_float->rect.BlockStartOffset()); | 29 space.Exclusions()->last_left_float->rect.BlockStartOffset()); |
29 if (space.Exclusions()->last_right_float) | 30 if (space.Exclusions()->last_right_float) |
30 adjusted_block_offset = | 31 adjusted_block_offset = |
31 std::max(adjusted_block_offset, | 32 std::max(adjusted_block_offset, |
32 space.Exclusions()->last_right_float->rect.BlockStartOffset()); | 33 space.Exclusions()->last_right_float->rect.BlockStartOffset()); |
33 return adjusted_offset; | 34 return adjusted_offset; |
34 } | 35 } |
35 | 36 |
36 NGLayoutOpportunity FindLayoutOpportunityForFloat( | 37 NGLayoutOpportunity FindLayoutOpportunityForFloat( |
37 const NGConstraintSpace& space, | 38 const NGConstraintSpace& space, |
38 const NGUnpositionedFloat& unpositioned_float, | 39 const NGUnpositionedFloat& unpositioned_float, |
39 LayoutUnit inline_size) { | 40 LayoutUnit inline_size) { |
40 NGLogicalOffset adjusted_origin_point = | 41 NGLogicalOffset adjusted_origin_point = |
41 AdjustToTopEdgeAlignmentRule(space, unpositioned_float.origin_offset); | 42 AdjustToTopEdgeAlignmentRule(space, unpositioned_float.origin_offset); |
| 43 WTF::Optional<LayoutUnit> clearance_offset = |
| 44 GetClearanceOffset(space.Exclusions(), unpositioned_float.ClearType()); |
| 45 |
| 46 AdjustToClearance(clearance_offset, &adjusted_origin_point); |
| 47 |
42 return FindLayoutOpportunityForFragment( | 48 return FindLayoutOpportunityForFragment( |
43 space.Exclusions().get(), unpositioned_float.available_size, | 49 space.Exclusions().get(), unpositioned_float.available_size, |
44 adjusted_origin_point, unpositioned_float.margins, | 50 adjusted_origin_point, unpositioned_float.margins, |
45 {inline_size, LayoutUnit()}); | 51 {inline_size, LayoutUnit()}); |
46 } | 52 } |
47 | 53 |
48 // Calculates the logical offset for opportunity. | 54 // Calculates the logical offset for opportunity. |
49 NGLogicalOffset CalculateLogicalOffsetForOpportunity( | 55 NGLogicalOffset CalculateLogicalOffsetForOpportunity( |
50 const NGLayoutOpportunity& opportunity, | 56 const NGLayoutOpportunity& opportunity, |
51 const LayoutUnit float_offset, | 57 const LayoutUnit float_offset, |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 unpositioned_float->origin_offset.block_offset = origin_block_offset; | 290 unpositioned_float->origin_offset.block_offset = origin_block_offset; |
285 unpositioned_float->from_offset.block_offset = from_block_offset; | 291 unpositioned_float->from_offset.block_offset = from_block_offset; |
286 unpositioned_float->parent_bfc_block_offset = parent_bfc_offset; | 292 unpositioned_float->parent_bfc_block_offset = parent_bfc_offset; |
287 positioned_floats.push_back(PositionFloat(unpositioned_float.Get(), space)); | 293 positioned_floats.push_back(PositionFloat(unpositioned_float.Get(), space)); |
288 } | 294 } |
289 | 295 |
290 return positioned_floats; | 296 return positioned_floats; |
291 } | 297 } |
292 | 298 |
293 } // namespace blink | 299 } // namespace blink |
OLD | NEW |