Chromium Code Reviews| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 return false; | 59 return false; |
| 60 } | 60 } |
| 61 case kStateChildLayout: { | 61 case kStateChildLayout: { |
| 62 if (current_child_) { | 62 if (current_child_) { |
| 63 NGFragment* fragment; | 63 NGFragment* fragment; |
| 64 if (!current_child_->Layout(constraint_space_for_children_, &fragment)) | 64 if (!current_child_->Layout(constraint_space_for_children_, &fragment)) |
| 65 return false; | 65 return false; |
| 66 NGBoxStrut child_margins = computeMargins( | 66 NGBoxStrut child_margins = computeMargins( |
| 67 *constraint_space_for_children_, *current_child_->Style()); | 67 *constraint_space_for_children_, *current_child_->Style()); |
| 68 | 68 |
| 69 LayoutUnit margin_block_start = | 69 LayoutUnit margin_block_start = CollapseMargins( |
| 70 CollapseMargins(child_margins, fragment->MarginStrut()); | 70 child_margins, fragment->MarginStrut(), *constraint_space); |
| 71 | 71 |
| 72 // TODO(layout-ng): Support auto margins | 72 // TODO(layout-ng): Support auto margins |
| 73 builder_->AddChild(fragment, | 73 builder_->AddChild(fragment, |
| 74 NGLogicalOffset(border_and_padding_.inline_start + | 74 NGLogicalOffset(border_and_padding_.inline_start + |
| 75 child_margins.inline_start, | 75 child_margins.inline_start, |
| 76 content_size_ + margin_block_start)); | 76 content_size_ + margin_block_start)); |
| 77 | 77 |
| 78 content_size_ += fragment->BlockSize() + margin_block_start; | 78 content_size_ += fragment->BlockSize() + margin_block_start; |
| 79 max_inline_size_ = | 79 max_inline_size_ = |
| 80 std::max(max_inline_size_, fragment->InlineSize() + | 80 std::max(max_inline_size_, fragment->InlineSize() + |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 101 return true; | 101 return true; |
| 102 } | 102 } |
| 103 }; | 103 }; |
| 104 NOTREACHED(); | 104 NOTREACHED(); |
| 105 *out = nullptr; | 105 *out = nullptr; |
| 106 return true; | 106 return true; |
| 107 } | 107 } |
| 108 | 108 |
| 109 LayoutUnit NGBlockLayoutAlgorithm::CollapseMargins( | 109 LayoutUnit NGBlockLayoutAlgorithm::CollapseMargins( |
| 110 const NGBoxStrut& margins, | 110 const NGBoxStrut& margins, |
| 111 const NGMarginStrut& children_margin_strut) { | 111 const NGMarginStrut& children_margin_strut, |
| 112 const NGConstraintSpace& space) { | |
| 112 // Calculate margin strut for the current child. | 113 // Calculate margin strut for the current child. |
| 113 NGMarginStrut curr_margin_strut = children_margin_strut; | 114 NGMarginStrut curr_margin_strut = children_margin_strut; |
| 114 curr_margin_strut.AppendMarginBlockStart(margins.block_start); | 115 LayoutUnit margin_block_start; |
| 115 if (current_child_->Style()->logicalHeight().isAuto()) { | 116 |
| 116 // bottom margin of a last in-flow child is only collapsed if | 117 // Calculate borders and padding for the current child. |
| 117 // the parent has 'auto' computed height | 118 LayoutUnit border_and_padding_before = |
| 119 computeBorderAndPaddingBlockStart(space, *current_child_->Style()); | |
| 120 LayoutUnit border_and_padding_after = | |
| 121 computeBorderAndPaddingBlockEnd(space, *current_child_->Style()); | |
| 122 | |
| 123 // Collapse TOP margins if there is no padding or border between | |
|
ikilpatrick
2016/09/14 18:45:25
s/TOP/BLOCK-START
Gleb Lanbin
2016/09/14 18:58:31
Done.
| |
| 124 // parent(current child) and its first in-flow child. | |
|
ikilpatrick
2016/09/14 18:45:25
insert space between "parent ("
Gleb Lanbin
2016/09/14 18:58:31
Done.
| |
| 125 if (border_and_padding_before) { | |
| 126 curr_margin_strut.SetMarginBlockStart(margins.block_start); | |
| 127 } else { | |
| 128 curr_margin_strut.AppendMarginBlockStart(margins.block_start); | |
| 129 } | |
| 130 | |
| 131 // Collapse BOTOM margins if | |
|
ikilpatrick
2016/09/14 18:45:25
s/BOTTOM/BLOCK-END
Gleb Lanbin
2016/09/14 18:58:31
Done.
| |
| 132 // 1) there is no padding or border between parent(current child) and its | |
|
ikilpatrick
2016/09/14 18:45:25
This this change if box-sizing: border-box is appl
ikilpatrick
2016/09/14 18:45:25
insert space between "parent ("
Gleb Lanbin
2016/09/14 18:58:31
Setting box-sizing doesn't have any affect on marg
Gleb Lanbin
2016/09/14 18:58:31
Done.
| |
| 133 // first/last in-flow child | |
| 134 // 2) parent's logical height is auto. | |
| 135 if (current_child_->Style()->logicalHeight().isAuto() && | |
| 136 !border_and_padding_after) { | |
| 118 curr_margin_strut.AppendMarginBlockEnd(margins.block_end); | 137 curr_margin_strut.AppendMarginBlockEnd(margins.block_end); |
| 119 } else { | 138 } else { |
| 120 curr_margin_strut.SetMarginBlockEnd(margins.block_end); | 139 curr_margin_strut.SetMarginBlockEnd(margins.block_end); |
| 121 } | 140 } |
| 122 | 141 |
| 123 // Set the margin strut for the resultant fragment if this is the first or | 142 // Set the margin strut for the resultant fragment if this is the first or |
| 124 // last child fragment. | 143 // last child fragment. |
| 125 if (current_child_ == first_child_) | 144 if (current_child_ == first_child_) |
| 126 builder_->SetMarginStrutBlockStart(curr_margin_strut); | 145 builder_->SetMarginStrutBlockStart(curr_margin_strut); |
| 127 if (!current_child_->NextSibling()) | 146 if (!current_child_->NextSibling()) |
| 128 builder_->SetMarginStrutBlockEnd(curr_margin_strut); | 147 builder_->SetMarginStrutBlockEnd(curr_margin_strut); |
| 129 | 148 |
| 130 // Compute the margin block start for adjoining blocks. | 149 // Compute the margin block start for adjoining blocks. |
| 131 LayoutUnit margin_block_start; | 150 LayoutUnit margin_block_start; |
| 132 if (current_child_ != first_child_) | 151 if (current_child_ != first_child_) |
| 133 margin_block_start = ComputeCollapsedMarginBlockStart( | 152 margin_block_start = ComputeCollapsedMarginBlockStart( |
| 134 prev_child_margin_strut_, curr_margin_strut); | 153 prev_child_margin_strut_, curr_margin_strut); |
| 135 | 154 |
| 136 prev_child_margin_strut_ = curr_margin_strut; | 155 prev_child_margin_strut_ = curr_margin_strut; |
| 137 // TODO(layout-ng): support other Margin Collapsing use cases, | 156 // TODO(layout-ng): support other Margin Collapsing use cases, |
| 138 // i.e. support 0 height elements etc. | 157 // i.e. support 0 height elements etc. |
| 139 return margin_block_start; | 158 return margin_block_start; |
| 140 } | 159 } |
| 141 | 160 |
| 142 } // namespace blink | 161 } // namespace blink |
| OLD | NEW |