Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.cc

Issue 2350603002: Ignore zero-height fragments during margin collapsing (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 case kStateChildLayout: { 63 case kStateChildLayout: {
64 if (current_child_) { 64 if (current_child_) {
65 NGFragment* fragment; 65 NGFragment* fragment;
66 if (!current_child_->Layout(constraint_space_for_children_, &fragment)) 66 if (!current_child_->Layout(constraint_space_for_children_, &fragment))
67 return false; 67 return false;
68 NGBoxStrut child_margins = computeMargins( 68 NGBoxStrut child_margins = computeMargins(
69 *constraint_space_for_children_, *current_child_->Style(), 69 *constraint_space_for_children_, *current_child_->Style(),
70 constraint_space_for_children_->WritingMode(), 70 constraint_space_for_children_->WritingMode(),
71 constraint_space_for_children_->Direction()); 71 constraint_space_for_children_->Direction());
72 72
73 LayoutUnit margin_block_start = CollapseMargins( 73 LayoutUnit margin_block_start =
74 *constraint_space, child_margins, fragment->MarginStrut()); 74 CollapseMargins(*constraint_space, child_margins, *fragment);
75 75
76 // TODO(layout-ng): Support auto margins 76 // TODO(layout-ng): Support auto margins
77 builder_->AddChild(fragment, 77 builder_->AddChild(fragment,
78 NGLogicalOffset(border_and_padding_.inline_start + 78 NGLogicalOffset(border_and_padding_.inline_start +
79 child_margins.inline_start, 79 child_margins.inline_start,
80 content_size_ + margin_block_start)); 80 content_size_ + margin_block_start));
81 81
82 content_size_ += fragment->BlockSize() + margin_block_start; 82 content_size_ += fragment->BlockSize() + margin_block_start;
83 max_inline_size_ = 83 max_inline_size_ =
84 std::max(max_inline_size_, fragment->InlineSize() + 84 std::max(max_inline_size_, fragment->InlineSize() +
(...skipping 21 matching lines...) Expand all
106 } 106 }
107 }; 107 };
108 NOTREACHED(); 108 NOTREACHED();
109 *out = nullptr; 109 *out = nullptr;
110 return true; 110 return true;
111 } 111 }
112 112
113 LayoutUnit NGBlockLayoutAlgorithm::CollapseMargins( 113 LayoutUnit NGBlockLayoutAlgorithm::CollapseMargins(
114 const NGConstraintSpace& space, 114 const NGConstraintSpace& space,
115 const NGBoxStrut& margins, 115 const NGBoxStrut& margins,
116 const NGMarginStrut& children_margin_strut) { 116 const NGFragment& children_fragment) {
ikilpatrick 2016/09/19 17:04:19 child_fragment?
Gleb Lanbin 2016/09/19 17:39:52 Done.
117 // Calculate margin strut for the current child. 117 // Zero-height boxes are ignored.
ikilpatrick 2016/09/19 17:04:19 ... are ignored and do not participate in margin c
Gleb Lanbin 2016/09/19 17:39:52 Done.
118 NGMarginStrut curr_margin_strut = children_margin_strut; 118 bool is_zero_height_box = !children_fragment.BlockSize() && margins.IsEmpty();
cbiesinger 2016/09/19 17:05:30 We may eventually need to check for "does not esta
Gleb Lanbin 2016/09/19 17:39:52 Done.
119 if (is_zero_height_box)
120 return LayoutUnit(0);
cbiesinger 2016/09/19 17:05:30 We usually just use LayoutUnit() for zero, it's a
Gleb Lanbin 2016/09/19 17:39:52 Done.
121
122 // Create the current child's margin strut from its children's margin strut.
123 NGMarginStrut curr_margin_strut = children_fragment.MarginStrut();
119 124
120 // Calculate borders and padding for the current child. 125 // Calculate borders and padding for the current child.
121 NGBoxStrut borders = computeBorders(*current_child_->Style()); 126 NGBoxStrut border_and_padding =
122 NGBoxStrut paddings = computePadding(space, *current_child_->Style()); 127 computeBorders(*current_child_->Style()) +
123 LayoutUnit border_and_padding_before = 128 computePadding(space, *current_child_->Style());
124 borders.block_start + paddings.block_start;
125 LayoutUnit border_and_padding_after = borders.block_end + paddings.block_end;
126 129
127 // Collapse BLOCK-START margins if there is no padding or border between 130 // Collapse BLOCK-START margins if there is no padding or border between
128 // parent (current child) and its first in-flow child. 131 // parent (current child) and its first in-flow child.
129 if (border_and_padding_before) { 132 if (border_and_padding.block_start) {
130 curr_margin_strut.SetMarginBlockStart(margins.block_start); 133 curr_margin_strut.SetMarginBlockStart(margins.block_start);
131 } else { 134 } else {
132 curr_margin_strut.AppendMarginBlockStart(margins.block_start); 135 curr_margin_strut.AppendMarginBlockStart(margins.block_start);
133 } 136 }
134 137
135 // Collapse BLOCK-END margins if 138 // Collapse BLOCK-END margins if
136 // 1) there is no padding or border between parent (current child) and its 139 // 1) there is no padding or border between parent (current child) and its
137 // first/last in-flow child 140 // first/last in-flow child
138 // 2) parent's logical height is auto. 141 // 2) parent's logical height is auto.
139 if (current_child_->Style()->logicalHeight().isAuto() && 142 if (current_child_->Style()->logicalHeight().isAuto() &&
140 !border_and_padding_after) { 143 !border_and_padding.block_end) {
141 curr_margin_strut.AppendMarginBlockEnd(margins.block_end); 144 curr_margin_strut.AppendMarginBlockEnd(margins.block_end);
142 } else { 145 } else {
143 curr_margin_strut.SetMarginBlockEnd(margins.block_end); 146 curr_margin_strut.SetMarginBlockEnd(margins.block_end);
144 } 147 }
145 148
146 // Set the margin strut for the resultant fragment if this is the first or 149 // Update the parent fragment's margin strut and calculate the margin
147 // last child fragment. 150 // block start position.
148 if (current_child_ == first_child_) 151 builder_->UpdateMarginStrut(curr_margin_strut);
149 builder_->SetMarginStrutBlockStart(curr_margin_strut); 152 LayoutUnit margin_block_start = ComputeCollapsedMarginBlockStart(
150 if (!current_child_->NextSibling()) 153 prev_child_margin_strut_, curr_margin_strut);
151 builder_->SetMarginStrutBlockEnd(curr_margin_strut);
152
153 // Compute the margin block start for adjoining blocks.
154 LayoutUnit margin_block_start;
155 if (current_child_ != first_child_)
cbiesinger 2016/09/19 17:05:30 Why do you no longer need this check?
Gleb Lanbin 2016/09/19 17:39:52 I mistakenly thought that we only need to calculat
156 margin_block_start = ComputeCollapsedMarginBlockStart(
157 prev_child_margin_strut_, curr_margin_strut);
158
159 prev_child_margin_strut_ = curr_margin_strut; 154 prev_child_margin_strut_ = curr_margin_strut;
160 // TODO(layout-ng): support other Margin Collapsing use cases,
161 // i.e. support 0 height elements etc.
162 return margin_block_start; 155 return margin_block_start;
163 } 156 }
164 157
165 } // namespace blink 158 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698