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_out_of_flow_layout_part.h" | 5 #include "core/layout/ng/ng_out_of_flow_layout_part.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_node.h" | 8 #include "core/layout/ng/ng_block_node.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_constraint_space_builder.h" | 10 #include "core/layout/ng/ng_constraint_space_builder.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 while (out_of_flow_candidates.size() > 0) { | 71 while (out_of_flow_candidates.size() > 0) { |
72 size_t position_index = 0; | 72 size_t position_index = 0; |
73 | 73 |
74 for (auto& descendant : out_of_flow_candidates) { | 74 for (auto& descendant : out_of_flow_candidates) { |
75 NGStaticPosition static_position = | 75 NGStaticPosition static_position = |
76 out_of_flow_candidate_positions[position_index++]; | 76 out_of_flow_candidate_positions[position_index++]; |
77 | 77 |
78 if (IsContainingBlockForAbsoluteDescendant(container_style_, | 78 if (IsContainingBlockForAbsoluteDescendant(container_style_, |
79 descendant->Style())) { | 79 descendant->Style())) { |
80 NGLogicalOffset offset; | 80 NGLogicalOffset offset; |
81 RefPtr<NGPhysicalFragment> physical_fragment = | 81 RefPtr<NGLayoutResult> result = |
82 LayoutDescendant(*descendant, static_position, &offset); | 82 LayoutDescendant(*descendant, static_position, &offset); |
83 // TODO(atotic) Need to adjust size of overflow rect per spec. | 83 // TODO(atotic) Need to adjust size of overflow rect per spec. |
84 container_builder_->AddChild(std::move(physical_fragment), offset); | 84 container_builder_->AddChild(result, offset); |
ikilpatrick
2017/02/21 22:26:02
std::move needed?
cbiesinger
2017/02/22 18:09:01
Done.
| |
85 } else { | 85 } else { |
86 container_builder_->AddOutOfFlowDescendant(descendant, static_position); | 86 container_builder_->AddOutOfFlowDescendant(descendant, static_position); |
87 } | 87 } |
88 } | 88 } |
89 // Sweep any descendants that might have been added. | 89 // Sweep any descendants that might have been added. |
90 // This happens when an absolute container has a fixed child. | 90 // This happens when an absolute container has a fixed child. |
91 out_of_flow_candidates.clear(); | 91 out_of_flow_candidates.clear(); |
92 out_of_flow_candidate_positions.clear(); | 92 out_of_flow_candidate_positions.clear(); |
93 container_builder_->GetAndClearOutOfFlowDescendantCandidates( | 93 container_builder_->GetAndClearOutOfFlowDescendantCandidates( |
94 &out_of_flow_candidates, &out_of_flow_candidate_positions); | 94 &out_of_flow_candidates, &out_of_flow_candidate_positions); |
95 } | 95 } |
96 } | 96 } |
97 | 97 |
98 RefPtr<NGPhysicalFragment> NGOutOfFlowLayoutPart::LayoutDescendant( | 98 RefPtr<NGLayoutResult> NGOutOfFlowLayoutPart::LayoutDescendant( |
99 NGBlockNode& descendant, | 99 NGBlockNode& descendant, |
100 NGStaticPosition static_position, | 100 NGStaticPosition static_position, |
101 NGLogicalOffset* offset) { | 101 NGLogicalOffset* offset) { |
102 // Adjust the static_position origin. The static_position coordinate origin is | 102 // Adjust the static_position origin. The static_position coordinate origin is |
103 // relative to the container's border box, ng_absolute_utils expects it to be | 103 // relative to the container's border box, ng_absolute_utils expects it to be |
104 // relative to the container's padding box. | 104 // relative to the container's padding box. |
105 static_position.offset -= container_border_physical_offset_; | 105 static_position.offset -= container_border_physical_offset_; |
106 | 106 |
107 RefPtr<NGPhysicalFragment> physical_fragment = nullptr; | 107 RefPtr<NGLayoutResult> layout_result = nullptr; |
108 Optional<MinAndMaxContentSizes> inline_estimate; | 108 Optional<MinAndMaxContentSizes> inline_estimate; |
109 Optional<LayoutUnit> block_estimate; | 109 Optional<LayoutUnit> block_estimate; |
110 | 110 |
111 if (AbsoluteNeedsChildInlineSize(descendant.Style())) { | 111 if (AbsoluteNeedsChildInlineSize(descendant.Style())) { |
112 inline_estimate = descendant.ComputeMinAndMaxContentSizes(); | 112 inline_estimate = descendant.ComputeMinAndMaxContentSizes(); |
113 } | 113 } |
114 | 114 |
115 NGAbsolutePhysicalPosition node_position = | 115 NGAbsolutePhysicalPosition node_position = |
116 ComputePartialAbsoluteWithChildInlineSize( | 116 ComputePartialAbsoluteWithChildInlineSize( |
117 *container_space_, descendant.Style(), static_position, | 117 *container_space_, descendant.Style(), static_position, |
118 inline_estimate); | 118 inline_estimate); |
119 | 119 |
120 if (AbsoluteNeedsChildBlockSize(descendant.Style())) { | 120 if (AbsoluteNeedsChildBlockSize(descendant.Style())) { |
121 physical_fragment = | 121 layout_result = GenerateFragment(descendant, block_estimate, node_position); |
122 GenerateFragment(descendant, block_estimate, node_position); | |
123 | 122 |
124 // TODO(ikilpatrick): the writing mode switching here looks wrong. | 123 // TODO(ikilpatrick): the writing mode switching here looks wrong. |
125 NGBoxFragment fragment(container_space_->WritingMode(), | 124 NGBoxFragment fragment( |
126 toNGPhysicalBoxFragment(physical_fragment.get())); | 125 container_space_->WritingMode(), |
126 toNGPhysicalBoxFragment(layout_result->PhysicalFragment().get())); | |
127 | 127 |
128 block_estimate = fragment.BlockSize(); | 128 block_estimate = fragment.BlockSize(); |
129 } | 129 } |
130 | 130 |
131 ComputeFullAbsoluteWithChildBlockSize(*container_space_, descendant.Style(), | 131 ComputeFullAbsoluteWithChildBlockSize(*container_space_, descendant.Style(), |
132 static_position, block_estimate, | 132 static_position, block_estimate, |
133 &node_position); | 133 &node_position); |
134 | 134 |
135 // Skip this step if we produced a fragment when estimating the block size. | 135 // Skip this step if we produced a fragment when estimating the block size. |
136 if (!physical_fragment) { | 136 if (!layout_result) { |
137 block_estimate = | 137 block_estimate = |
138 node_position.size.ConvertToLogical(container_space_->WritingMode()) | 138 node_position.size.ConvertToLogical(container_space_->WritingMode()) |
139 .block_size; | 139 .block_size; |
140 physical_fragment = | 140 layout_result = GenerateFragment(descendant, block_estimate, node_position); |
141 GenerateFragment(descendant, block_estimate, node_position); | |
142 } | 141 } |
143 | 142 |
144 // Compute logical offset, NGAbsolutePhysicalPosition is calculated relative | 143 // Compute logical offset, NGAbsolutePhysicalPosition is calculated relative |
145 // to the padding box so add back the container's borders. | 144 // to the padding box so add back the container's borders. |
146 NGBoxStrut inset = node_position.inset.ConvertToLogical( | 145 NGBoxStrut inset = node_position.inset.ConvertToLogical( |
147 container_space_->WritingMode(), container_space_->Direction()); | 146 container_space_->WritingMode(), container_space_->Direction()); |
148 offset->inline_offset = | 147 offset->inline_offset = |
149 inset.inline_start + container_border_offset_.inline_offset; | 148 inset.inline_start + container_border_offset_.inline_offset; |
150 offset->block_offset = | 149 offset->block_offset = |
151 inset.block_start + container_border_offset_.block_offset; | 150 inset.block_start + container_border_offset_.block_offset; |
152 | 151 |
153 return physical_fragment; | 152 return layout_result; |
154 } | 153 } |
155 | 154 |
156 RefPtr<NGPhysicalFragment> NGOutOfFlowLayoutPart::GenerateFragment( | 155 RefPtr<NGLayoutResult> NGOutOfFlowLayoutPart::GenerateFragment( |
157 NGBlockNode& descendant, | 156 NGBlockNode& descendant, |
158 const Optional<LayoutUnit>& block_estimate, | 157 const Optional<LayoutUnit>& block_estimate, |
159 const NGAbsolutePhysicalPosition node_position) { | 158 const NGAbsolutePhysicalPosition node_position) { |
160 // The fragment is generated in one of these two scenarios: | 159 // The fragment is generated in one of these two scenarios: |
161 // 1. To estimate descendant's block size, in this case block_size is | 160 // 1. To estimate descendant's block size, in this case block_size is |
162 // container's available size. | 161 // container's available size. |
163 // 2. To compute final fragment, when block size is known from the absolute | 162 // 2. To compute final fragment, when block size is known from the absolute |
164 // position calculation. | 163 // position calculation. |
165 LayoutUnit inline_size = | 164 LayoutUnit inline_size = |
166 node_position.size.ConvertToLogical(container_space_->WritingMode()) | 165 node_position.size.ConvertToLogical(container_space_->WritingMode()) |
(...skipping 11 matching lines...) Expand all Loading... | |
178 builder.SetIsFixedSizeBlock(true); | 177 builder.SetIsFixedSizeBlock(true); |
179 builder.SetIsFixedSizeInline(true); | 178 builder.SetIsFixedSizeInline(true); |
180 builder.SetIsNewFormattingContext(true); | 179 builder.SetIsNewFormattingContext(true); |
181 NGConstraintSpace* space = | 180 NGConstraintSpace* space = |
182 builder.ToConstraintSpace(container_space_->WritingMode()); | 181 builder.ToConstraintSpace(container_space_->WritingMode()); |
183 | 182 |
184 return descendant.Layout(space); | 183 return descendant.Layout(space); |
185 } | 184 } |
186 | 185 |
187 } // namespace blink | 186 } // namespace blink |
OLD | NEW |