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

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

Issue 2259963002: [layoutng] Margin support, part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dcheck Created 4 years, 4 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_length_utils.cc
diff --git a/third_party/WebKit/Source/core/layout/ng/ng_length_utils.cc b/third_party/WebKit/Source/core/layout/ng/ng_length_utils.cc
index 30fb60ad79621718f22be82b5eaa164432c10414..53713be8297314022d3c48a35bd918882ad225a7 100644
--- a/third_party/WebKit/Source/core/layout/ng/ng_length_utils.cc
+++ b/third_party/WebKit/Source/core/layout/ng/ng_length_utils.cc
@@ -5,6 +5,7 @@
#include "core/layout/ng/ng_length_utils.h"
#include "core/layout/ng/ng_constraint_space.h"
+#include "core/layout/ng/ng_margin_strut.h"
#include "core/style/ComputedStyle.h"
#include "platform/LayoutUnit.h"
#include "platform/Length.h"
@@ -24,6 +25,9 @@ LayoutUnit resolveInlineLength(const NGConstraintSpace& constraintSpace,
if (type == LengthResolveType::MinSize && length.isAuto())
return LayoutUnit();
+ if (type == LengthResolveType::MarginSize && length.isAuto())
+ return LayoutUnit();
+
return valueForLength(length, constraintSpace.ContainerSize().inlineSize);
}
@@ -32,6 +36,7 @@ LayoutUnit resolveBlockLength(const NGConstraintSpace& constraintSpace,
LayoutUnit contentSize,
LengthResolveType type) {
DCHECK(!length.isMaxSizeNone());
+ DCHECK(type != LengthResolveType::MarginSize);
if (type == LengthResolveType::MinSize && length.isAuto())
return LayoutUnit();
@@ -100,4 +105,20 @@ LayoutUnit computeBlockSizeForFragment(const NGConstraintSpace& constraintSpace,
return extent;
}
+NGBoxMargins computeMargins(const NGConstraintSpace& constraintSpace,
+ const ComputedStyle& style) {
+ // Margins always get computed relative to the inline size:
+ // https://www.w3.org/TR/CSS2/box.html#value-def-margin-width
+ NGBoxMargins margins;
+ margins.inlineStart = resolveInlineLength(
+ constraintSpace, style.marginStart(), LengthResolveType::MarginSize);
+ margins.inlineEnd = resolveInlineLength(constraintSpace, style.marginEnd(),
+ LengthResolveType::MarginSize);
+ margins.blockStart = resolveInlineLength(
+ constraintSpace, style.marginBefore(), LengthResolveType::MarginSize);
+ margins.blockEnd = resolveInlineLength(constraintSpace, style.marginAfter(),
+ LengthResolveType::MarginSize);
+ return margins;
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698