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_length_utils.h" | 10 #include "core/layout/ng/ng_length_utils.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 }; | 118 }; |
119 NOTREACHED(); | 119 NOTREACHED(); |
120 *out = nullptr; | 120 *out = nullptr; |
121 return true; | 121 return true; |
122 } | 122 } |
123 | 123 |
124 LayoutUnit NGBlockLayoutAlgorithm::CollapseMargins( | 124 LayoutUnit NGBlockLayoutAlgorithm::CollapseMargins( |
125 const NGConstraintSpace& space, | 125 const NGConstraintSpace& space, |
126 const NGBoxStrut& margins, | 126 const NGBoxStrut& margins, |
127 const NGFragment& fragment) { | 127 const NGFragment& fragment) { |
128 // TODO(chrome-layout-team): Do not collapse margins for elements that | |
129 // establish new block formatting contexts | |
130 | |
131 // Zero-height boxes are ignored and do not participate in margin collapsing. | 128 // Zero-height boxes are ignored and do not participate in margin collapsing. |
132 bool is_zero_height_box = !fragment.BlockSize() && margins.IsEmpty(); | 129 bool is_zero_height_box = !fragment.BlockSize() && margins.IsEmpty(); |
133 if (is_zero_height_box) | 130 if (is_zero_height_box) |
134 return LayoutUnit(); | 131 return LayoutUnit(); |
135 | 132 |
136 // Create the current child's margin strut from its children's margin strut. | 133 // Create the current child's margin strut from its children's margin strut. |
137 NGMarginStrut curr_margin_strut = fragment.MarginStrut(); | 134 NGMarginStrut curr_margin_strut = fragment.MarginStrut(); |
138 | 135 |
139 // Calculate borders and padding for the current child. | 136 // Calculate borders and padding for the current child. |
140 NGBoxStrut border_and_padding = | 137 NGBoxStrut border_and_padding = |
(...skipping 12 matching lines...) Expand all Loading... |
153 // 1) there is no padding or border between parent (current child) and its | 150 // 1) there is no padding or border between parent (current child) and its |
154 // first/last in-flow child | 151 // first/last in-flow child |
155 // 2) parent's logical height is auto. | 152 // 2) parent's logical height is auto. |
156 if (current_child_->Style()->logicalHeight().isAuto() && | 153 if (current_child_->Style()->logicalHeight().isAuto() && |
157 !border_and_padding.block_end) { | 154 !border_and_padding.block_end) { |
158 curr_margin_strut.AppendMarginBlockEnd(margins.block_end); | 155 curr_margin_strut.AppendMarginBlockEnd(margins.block_end); |
159 } else { | 156 } else { |
160 curr_margin_strut.SetMarginBlockEnd(margins.block_end); | 157 curr_margin_strut.SetMarginBlockEnd(margins.block_end); |
161 } | 158 } |
162 | 159 |
| 160 // Compute the margin block start for |
| 161 // 1) adjoining blocks |
| 162 // 2) 1st block in the newly established formatting context. |
| 163 LayoutUnit margin_block_start; |
| 164 if (is_fragment_margin_strut_block_start_updated_ || |
| 165 space.IsNewFormattingContext()) { |
| 166 margin_block_start = ComputeCollapsedMarginBlockStart( |
| 167 prev_child_margin_strut_, curr_margin_strut); |
| 168 } |
| 169 |
163 // Update the parent fragment's margin strut | 170 // Update the parent fragment's margin strut |
164 UpdateMarginStrut(curr_margin_strut); | 171 UpdateMarginStrut(curr_margin_strut); |
165 | 172 |
166 // Compute the margin block start for adjoining blocks. | |
167 LayoutUnit margin_block_start; | |
168 if (is_fragment_margin_strut_block_start_updated_) { | |
169 margin_block_start = ComputeCollapsedMarginBlockStart( | |
170 prev_child_margin_strut_, curr_margin_strut); | |
171 } | |
172 prev_child_margin_strut_ = curr_margin_strut; | 173 prev_child_margin_strut_ = curr_margin_strut; |
173 return margin_block_start; | 174 return margin_block_start; |
174 } | 175 } |
175 | 176 |
176 void NGBlockLayoutAlgorithm::UpdateMarginStrut(const NGMarginStrut& from) { | 177 void NGBlockLayoutAlgorithm::UpdateMarginStrut(const NGMarginStrut& from) { |
177 if (!is_fragment_margin_strut_block_start_updated_) { | 178 if (!is_fragment_margin_strut_block_start_updated_) { |
178 builder_->SetMarginStrutBlockStart(from); | 179 builder_->SetMarginStrutBlockStart(from); |
179 is_fragment_margin_strut_block_start_updated_ = true; | 180 is_fragment_margin_strut_block_start_updated_ = true; |
180 } | 181 } |
181 builder_->SetMarginStrutBlockEnd(from); | 182 builder_->SetMarginStrutBlockEnd(from); |
182 } | 183 } |
183 | 184 |
184 } // namespace blink | 185 } // namespace blink |
OLD | NEW |