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

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

Issue 2313873002: Initial implementation of Collapsing Margins computational logic for LayoutNG (Closed)
Patch Set: synced to the head 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 9082202d9d96b05d55c48895f491046eab5438f6..ae4722e5639624aede739e87e0b97c50998941fa 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
@@ -14,6 +14,18 @@
#include "platform/LengthFunctions.h"
namespace blink {
+namespace {
+
+LayoutUnit ComputeCollapsedMarginBlockStart(
+ const NGMarginStrut& prev_margin_strut,
+ const NGMarginStrut& curr_margin_strut) {
+ return std::max(prev_margin_strut.margin_block_end,
+ curr_margin_strut.margin_block_start) -
+ std::max(prev_margin_strut.negative_margin_block_end.abs(),
+ curr_margin_strut.negative_margin_block_start.abs());
+}
+
+} // namespace
NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm(
PassRefPtr<const ComputedStyle> style,
@@ -50,13 +62,16 @@ bool NGBlockLayoutAlgorithm::Layout(const NGConstraintSpace* constraint_space,
return false;
NGBoxStrut child_margins = computeMargins(
*constraint_space_for_children_, *current_child_->Style());
+
+ LayoutUnit margin_block_start =
+ CollapseMargins(child_margins, fragment->MarginStrut());
+
// TODO(layout-ng): Support auto margins
- builder_->AddChild(
- fragment,
- NGLogicalOffset(child_margins.inline_start,
- content_size_ + child_margins.block_start));
+ builder_->AddChild(fragment,
+ NGLogicalOffset(child_margins.inline_start,
+ content_size_ + margin_block_start));
- content_size_ += fragment->BlockSize() + child_margins.BlockSum();
+ content_size_ += fragment->BlockSize() + margin_block_start;
max_inline_size_ =
std::max(max_inline_size_,
fragment->InlineSize() + child_margins.InlineSum());
@@ -64,7 +79,6 @@ bool NGBlockLayoutAlgorithm::Layout(const NGConstraintSpace* constraint_space,
if (current_child_)
return false;
}
-
state_ = kStateFinalize;
return false;
}
@@ -86,4 +100,31 @@ bool NGBlockLayoutAlgorithm::Layout(const NGConstraintSpace* constraint_space,
return true;
}
+LayoutUnit NGBlockLayoutAlgorithm::CollapseMargins(
+ const NGBoxStrut& margins,
+ const NGMarginStrut& children_margin_strut) {
+ // Calculate margin strut for the current child.
+ NGMarginStrut curr_margin_strut = children_margin_strut;
+ curr_margin_strut.AppendMarginBlockStart(margins.block_start);
+ curr_margin_strut.AppendMarginBlockEnd(margins.block_end);
+
+ // Set the margin strut for the resultant fragment if this is the first or
+ // last child fragment.
+ if (current_child_ == first_child_)
+ builder_->SetMarginStrutBlockStart(curr_margin_strut);
+ if (!current_child_->NextSibling())
+ builder_->SetMarginStrutBlockEnd(curr_margin_strut);
+
+ // Compute the margin block start for adjoining blocks.
+ LayoutUnit margin_block_start;
+ if (current_child_ != first_child_)
+ margin_block_start = ComputeCollapsedMarginBlockStart(
+ prev_child_margin_strut_, curr_margin_strut);
+
+ prev_child_margin_strut_ = curr_margin_strut;
+ // TODO(layout-ng): support other Margin Collapsing use cases,
+ // i.e. support 0 height elements etc.
+ return margin_block_start;
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698