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 #ifndef NGBlockLayoutAlgorithm_h | 5 #ifndef NGBlockLayoutAlgorithm_h |
6 #define NGBlockLayoutAlgorithm_h | 6 #define NGBlockLayoutAlgorithm_h |
7 | 7 |
8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
9 #include "core/layout/ng/geometry/ng_margin_strut.h" | 9 #include "core/layout/ng/geometry/ng_margin_strut.h" |
10 #include "core/layout/ng/ng_block_break_token.h" | 10 #include "core/layout/ng/ng_block_break_token.h" |
11 #include "core/layout/ng/ng_block_node.h" | 11 #include "core/layout/ng/ng_block_node.h" |
12 #include "core/layout/ng/ng_box_fragment.h" | 12 #include "core/layout/ng/ng_box_fragment.h" |
13 #include "core/layout/ng/ng_constraint_space_builder.h" | 13 #include "core/layout/ng/ng_constraint_space_builder.h" |
14 #include "core/layout/ng/ng_layout_algorithm.h" | 14 #include "core/layout/ng/ng_layout_algorithm.h" |
15 #include "platform/wtf/RefPtr.h" | 15 #include "platform/wtf/RefPtr.h" |
16 | 16 |
17 namespace blink { | 17 namespace blink { |
18 | 18 |
19 class NGConstraintSpace; | 19 class NGConstraintSpace; |
20 class NGLayoutResult; | 20 class NGLayoutResult; |
| 21 struct NGInflowChildData; |
| 22 struct NGPreviousInflowPosition; |
21 | 23 |
22 // Updates the fragment's BFC offset if it's not already set. | 24 // Updates the fragment's BFC offset if it's not already set. |
23 void MaybeUpdateFragmentBfcOffset(const NGConstraintSpace&, | 25 void MaybeUpdateFragmentBfcOffset(const NGConstraintSpace&, |
24 const NGLogicalOffset&, | 26 LayoutUnit bfc_block_offset, |
25 NGFragmentBuilder* builder); | 27 NGFragmentBuilder* builder); |
26 | 28 |
27 // Positions pending floats starting from {@origin_block_offset} and relative | 29 // Positions pending floats starting from {@origin_block_offset} and relative |
28 // to container's BFC offset. | 30 // to container's BFC offset. |
29 void PositionPendingFloats(LayoutUnit origin_block_offset, | 31 void PositionPendingFloats(LayoutUnit origin_block_offset, |
30 NGFragmentBuilder* container_builder, | 32 NGFragmentBuilder* container_builder, |
31 NGConstraintSpace* space); | 33 NGConstraintSpace* space); |
32 | 34 |
33 // A class for general block layout (e.g. a <div> with no special style). | 35 // A class for general block layout (e.g. a <div> with no special style). |
34 // Lays out the children in sequence. | 36 // Lays out the children in sequence. |
(...skipping 10 matching lines...) Expand all Loading... |
45 NGBlockBreakToken* break_token = nullptr); | 47 NGBlockBreakToken* break_token = nullptr); |
46 | 48 |
47 Optional<MinMaxContentSize> ComputeMinMaxContentSize() const override; | 49 Optional<MinMaxContentSize> ComputeMinMaxContentSize() const override; |
48 virtual RefPtr<NGLayoutResult> Layout() override; | 50 virtual RefPtr<NGLayoutResult> Layout() override; |
49 | 51 |
50 private: | 52 private: |
51 NGBoxStrut CalculateMargins(NGLayoutInputNode* child); | 53 NGBoxStrut CalculateMargins(NGLayoutInputNode* child); |
52 | 54 |
53 // Creates a new constraint space for the current child. | 55 // Creates a new constraint space for the current child. |
54 RefPtr<NGConstraintSpace> CreateConstraintSpaceForChild( | 56 RefPtr<NGConstraintSpace> CreateConstraintSpaceForChild( |
55 const NGLogicalOffset& child_bfc_offset, | 57 const NGLayoutInputNode& child, |
56 const NGLayoutInputNode&); | 58 const NGInflowChildData& child_data); |
57 | 59 |
58 // @return Estimated BFC offset for the "to be layout" child. | 60 // @return Estimated BFC offset for the "to be layout" child. |
59 NGLogicalOffset PrepareChildLayout(NGLayoutInputNode*); | 61 NGInflowChildData PrepareChildLayout(const NGPreviousInflowPosition&, |
| 62 NGLayoutInputNode*); |
60 | 63 |
61 void FinishChildLayout(const NGConstraintSpace&, | 64 NGPreviousInflowPosition FinishChildLayout( |
62 const NGLayoutInputNode* child, | 65 const NGConstraintSpace&, |
63 NGLayoutResult*); | 66 const NGPreviousInflowPosition& prev_data, |
| 67 const NGInflowChildData& child_data, |
| 68 const NGLayoutInputNode* child, |
| 69 NGLayoutResult*); |
64 | 70 |
65 // Positions the fragment that establishes a new formatting context. | 71 // Positions the fragment that establishes a new formatting context. |
66 // | 72 // |
67 // This uses Layout Opportunity iterator to position the fragment. | 73 // This uses Layout Opportunity iterator to position the fragment. |
68 // That's because an element that establishes a new block formatting context | 74 // That's because an element that establishes a new block formatting context |
69 // must not overlap the margin box of any floats in the same block formatting | 75 // must not overlap the margin box of any floats in the same block formatting |
70 // context as the element itself. | 76 // context as the element itself. |
71 // | 77 // |
72 // So if necessary, we clear the new BFC by placing it below any preceding | 78 // So if necessary, we clear the new BFC by placing it below any preceding |
73 // floats or place it adjacent to such floats if there is sufficient space. | 79 // floats or place it adjacent to such floats if there is sufficient space. |
74 // | 80 // |
75 // Example: | 81 // Example: |
76 // <div id="container"> | 82 // <div id="container"> |
77 // <div id="float"></div> | 83 // <div id="float"></div> |
78 // <div id="new-fc" style="margin-top: 20px;"></div> | 84 // <div id="new-fc" style="margin-top: 20px;"></div> |
79 // </div> | 85 // </div> |
80 // 1) If #new-fc is small enough to fit the available space right from #float | 86 // 1) If #new-fc is small enough to fit the available space right from #float |
81 // then it will be placed there and we collapse its margin. | 87 // then it will be placed there and we collapse its margin. |
82 // 2) If #new-fc is too big then we need to clear its position and place it | 88 // 2) If #new-fc is too big then we need to clear its position and place it |
83 // below #float ignoring its vertical margin. | 89 // below #float ignoring its vertical margin. |
84 NGLogicalOffset PositionNewFc(const NGBoxFragment&, | 90 NGLogicalOffset PositionNewFc(const NGLayoutInputNode& child, |
| 91 const NGPreviousInflowPosition&, |
| 92 const NGBoxFragment&, |
| 93 const NGInflowChildData& child_data, |
85 const NGConstraintSpace& child_space); | 94 const NGConstraintSpace& child_space); |
86 | 95 |
87 // Positions the fragment that knows its BFC offset. | 96 // Positions the fragment that knows its BFC offset. |
88 NGLogicalOffset PositionWithBfcOffset(const NGBoxFragment&); | 97 NGLogicalOffset PositionWithBfcOffset(const NGBoxFragment&); |
89 | 98 |
90 // Positions using the parent BFC offset. | 99 // Positions using the parent BFC offset. |
91 // Fragment doesn't know its offset but we can still calculate its BFC | 100 // Fragment doesn't know its offset but we can still calculate its BFC |
92 // position because the parent fragment's BFC is known. | 101 // position because the parent fragment's BFC is known. |
93 // Example: | 102 // Example: |
94 // BFC Offset is known here because of the padding. | 103 // BFC Offset is known here because of the padding. |
95 // <div style="padding: 1px"> | 104 // <div style="padding: 1px"> |
96 // <div id="empty-div" style="margins: 1px"></div> | 105 // <div id="empty-div" style="margins: 1px"></div> |
97 NGLogicalOffset PositionWithParentBfc(const NGConstraintSpace&, | 106 NGLogicalOffset PositionWithParentBfc(const NGConstraintSpace&, |
| 107 const NGInflowChildData& child_data, |
98 const NGBoxFragment&); | 108 const NGBoxFragment&); |
99 | 109 |
100 NGLogicalOffset PositionLegacy(const NGConstraintSpace& child_space); | 110 NGLogicalOffset PositionLegacy(const NGConstraintSpace& child_space, |
| 111 const NGInflowChildData& child_data); |
101 | 112 |
102 void HandleOutOfFlowPositioned(NGBlockNode*); | 113 void HandleOutOfFlowPositioned(const NGPreviousInflowPosition&, NGBlockNode*); |
103 void HandleFloating(NGBlockNode*, NGBlockBreakToken*); | 114 void HandleFloating(const NGPreviousInflowPosition&, |
| 115 NGBlockNode*, |
| 116 NGBlockBreakToken*); |
104 | 117 |
105 // Final adjustments before fragment creation. We need to prevent the | 118 // Final adjustments before fragment creation. We need to prevent the |
106 // fragment from crossing fragmentainer boundaries, and rather create a break | 119 // fragment from crossing fragmentainer boundaries, and rather create a break |
107 // token if we're out of space. | 120 // token if we're out of space. |
108 void FinalizeForFragmentation(); | 121 void FinalizeForFragmentation(); |
109 | 122 |
110 // Calculates logical offset for the current fragment using either | 123 // Calculates logical offset for the current fragment using either |
111 // {@code content_size_} when the fragment doesn't know it's offset | 124 // {@code content_size_} when the fragment doesn't know it's offset |
112 // or {@code known_fragment_offset} if the fragment knows it's offset | 125 // or {@code known_fragment_offset} if the fragment knows it's offset |
113 // @return Fragment's offset relative to the fragment's parent. | 126 // @return Fragment's offset relative to the fragment's parent. |
114 NGLogicalOffset CalculateLogicalOffset( | 127 NGLogicalOffset CalculateLogicalOffset( |
| 128 const NGBoxStrut& child_margins, |
115 const WTF::Optional<NGLogicalOffset>& known_fragment_offset); | 129 const WTF::Optional<NGLogicalOffset>& known_fragment_offset); |
116 | 130 |
117 NGLogicalSize child_available_size_; | 131 NGLogicalSize child_available_size_; |
118 NGLogicalSize child_percentage_size_; | 132 NGLogicalSize child_percentage_size_; |
119 | 133 |
120 NGBoxStrut border_and_padding_; | 134 NGBoxStrut border_and_padding_; |
121 LayoutUnit content_size_; | 135 LayoutUnit content_size_; |
122 LayoutUnit max_inline_size_; | 136 LayoutUnit max_inline_size_; |
123 // MarginStrut for the previous child. | |
124 NGMarginStrut curr_margin_strut_; | |
125 NGLogicalOffset curr_bfc_offset_; | |
126 NGBoxStrut curr_child_margins_; | |
127 }; | 137 }; |
128 | 138 |
129 } // namespace blink | 139 } // namespace blink |
130 | 140 |
131 #endif // NGBlockLayoutAlgorithm_h | 141 #endif // NGBlockLayoutAlgorithm_h |
OLD | NEW |