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

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

Issue 2399963002: [layoutng] margin: auto support (Closed)
Patch Set: one more test now passes! Created 4 years, 2 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 87894828d679bff724a9b0adefe525186176be38..54d4172ea63a45e1d55d251fb2db70f6d9dcf977 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_fragment.h"
#include "core/style/ComputedStyle.h"
#include "platform/LayoutUnit.h"
#include "platform/Length.h"
@@ -283,4 +284,23 @@ NGBoxStrut computePadding(const NGConstraintSpace& constraintSpace,
return padding;
}
+void ApplyAutoMargins(const NGConstraintSpace& constraint_space,
+ const ComputedStyle& style,
+ const NGFragment& fragment,
+ NGBoxStrut& margins) {
+ const LayoutUnit used_space = fragment.InlineSize() + margins.InlineSum();
+ const LayoutUnit available_space =
+ constraint_space.ContainerSize().inline_size - used_space;
+ if (available_space < LayoutUnit())
+ return;
+ if (style.marginStart().isAuto() && style.marginEnd().isAuto()) {
+ margins.inline_start = available_space / 2;
+ margins.inline_end = available_space - margins.inline_start;
+ } else if (style.marginStart().isAuto()) {
+ margins.inline_start = available_space;
+ } else if (style.marginEnd().isAuto()) {
+ margins.inline_end = available_space;
+ }
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698