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

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

Issue 2346473003: Do not collapse margins with padding/border b/w parent and first/last child (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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.cc
diff --git a/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.cc b/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.cc
index 3c77a6bce448f472f72ccb3eea153facd476dbd9..477e89b9d2f9fd80a0b92929f9448ae5a0cf9e02 100644
--- a/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.cc
+++ b/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.cc
@@ -66,8 +66,8 @@ bool NGBlockLayoutAlgorithm::Layout(const NGConstraintSpace* constraint_space,
NGBoxStrut child_margins = computeMargins(
*constraint_space_for_children_, *current_child_->Style());
- LayoutUnit margin_block_start =
- CollapseMargins(child_margins, fragment->MarginStrut());
+ LayoutUnit margin_block_start = CollapseMargins(
+ child_margins, fragment->MarginStrut(), *constraint_space);
// TODO(layout-ng): Support auto margins
builder_->AddChild(fragment,
@@ -108,13 +108,32 @@ bool NGBlockLayoutAlgorithm::Layout(const NGConstraintSpace* constraint_space,
LayoutUnit NGBlockLayoutAlgorithm::CollapseMargins(
const NGBoxStrut& margins,
- const NGMarginStrut& children_margin_strut) {
+ const NGMarginStrut& children_margin_strut,
+ const NGConstraintSpace& space) {
// Calculate margin strut for the current child.
NGMarginStrut curr_margin_strut = children_margin_strut;
- curr_margin_strut.AppendMarginBlockStart(margins.block_start);
- if (current_child_->Style()->logicalHeight().isAuto()) {
- // bottom margin of a last in-flow child is only collapsed if
- // the parent has 'auto' computed height
+ LayoutUnit margin_block_start;
+
+ // Calculate borders and padding for the current child.
+ LayoutUnit border_and_padding_before =
+ computeBorderAndPaddingBlockStart(space, *current_child_->Style());
+ LayoutUnit border_and_padding_after =
+ computeBorderAndPaddingBlockEnd(space, *current_child_->Style());
+
+ // 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.
+ // 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.
+ if (border_and_padding_before) {
+ curr_margin_strut.SetMarginBlockStart(margins.block_start);
+ } else {
+ curr_margin_strut.AppendMarginBlockStart(margins.block_start);
+ }
+
+ // Collapse BOTOM margins if
ikilpatrick 2016/09/14 18:45:25 s/BOTTOM/BLOCK-END
Gleb Lanbin 2016/09/14 18:58:31 Done.
+ // 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.
+ // first/last in-flow child
+ // 2) parent's logical height is auto.
+ if (current_child_->Style()->logicalHeight().isAuto() &&
+ !border_and_padding_after) {
curr_margin_strut.AppendMarginBlockEnd(margins.block_end);
} else {
curr_margin_strut.SetMarginBlockEnd(margins.block_end);

Powered by Google App Engine
This is Rietveld 408576698