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

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

Issue 2289353002: [layoutng] Add methods to compute border and padding (Closed)
Patch Set: better enum name 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 97c79543d977b06764c0c0f78739f925d2f6eee4..10b9102d797bb0a73e69da7ab4577a0cb45d9393 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
@@ -14,6 +14,7 @@ namespace blink {
// - Handle border-box correctly
// - positioned and/or replaced calculations
// - Handle margins for fill-available and width: auto
+// - Take scrollbars into account
LayoutUnit resolveInlineLength(const NGConstraintSpace& constraintSpace,
const Length& length,
@@ -25,7 +26,7 @@ LayoutUnit resolveInlineLength(const NGConstraintSpace& constraintSpace,
if (type == LengthResolveType::MinSize && length.isAuto())
return LayoutUnit();
- if (type == LengthResolveType::MarginSize && length.isAuto())
+ if (type == LengthResolveType::MarginBorderPaddingSize && length.isAuto())
return LayoutUnit();
return valueForLength(length, constraintSpace.ContainerSize().inline_size);
@@ -36,7 +37,7 @@ LayoutUnit resolveBlockLength(const NGConstraintSpace& constraintSpace,
LayoutUnit contentSize,
LengthResolveType type) {
DCHECK(!length.isMaxSizeNone());
- DCHECK(type != LengthResolveType::MarginSize);
+ DCHECK(type != LengthResolveType::MarginBorderPaddingSize);
if (type == LengthResolveType::MinSize && length.isAuto())
return LayoutUnit();
@@ -120,15 +121,48 @@ NGBoxStrut computeMargins(const NGConstraintSpace& constraintSpace,
// Margins always get computed relative to the inline size:
// https://www.w3.org/TR/CSS2/box.html#value-def-margin-width
NGBoxStrut margins;
- margins.inline_start = resolveInlineLength(
- constraintSpace, style.marginStart(), LengthResolveType::MarginSize);
- margins.inline_end = resolveInlineLength(constraintSpace, style.marginEnd(),
- LengthResolveType::MarginSize);
- margins.block_start = resolveInlineLength(
- constraintSpace, style.marginBefore(), LengthResolveType::MarginSize);
- margins.block_end = resolveInlineLength(constraintSpace, style.marginAfter(),
- LengthResolveType::MarginSize);
+ margins.inline_start =
+ resolveInlineLength(constraintSpace, style.marginStart(),
+ LengthResolveType::MarginBorderPaddingSize);
+ margins.inline_end =
+ resolveInlineLength(constraintSpace, style.marginEnd(),
+ LengthResolveType::MarginBorderPaddingSize);
+ margins.block_start =
+ resolveInlineLength(constraintSpace, style.marginBefore(),
+ LengthResolveType::MarginBorderPaddingSize);
+ margins.block_end =
+ resolveInlineLength(constraintSpace, style.marginAfter(),
+ LengthResolveType::MarginBorderPaddingSize);
return margins;
}
+NGBoxStrut computeBorders(const ComputedStyle& style) {
+ NGBoxStrut borders;
+ borders.inline_start = LayoutUnit(style.borderStartWidth());
+ borders.inline_end = LayoutUnit(style.borderEndWidth());
+ borders.block_start = LayoutUnit(style.borderBeforeWidth());
+ borders.block_end = LayoutUnit(style.borderAfterWidth());
+ return borders;
+}
+
+NGBoxStrut computePadding(const NGConstraintSpace& constraintSpace,
+ const ComputedStyle& style) {
+ // Padding always gets computed relative to the inline size:
+ // https://www.w3.org/TR/CSS2/box.html#value-def-padding-width
+ NGBoxStrut padding;
+ padding.inline_start =
+ resolveInlineLength(constraintSpace, style.paddingStart(),
+ LengthResolveType::MarginBorderPaddingSize);
+ padding.inline_end =
+ resolveInlineLength(constraintSpace, style.paddingEnd(),
+ LengthResolveType::MarginBorderPaddingSize);
+ padding.block_start =
+ resolveInlineLength(constraintSpace, style.paddingBefore(),
+ LengthResolveType::MarginBorderPaddingSize);
+ padding.block_end =
+ resolveInlineLength(constraintSpace, style.paddingAfter(),
+ LengthResolveType::MarginBorderPaddingSize);
+ return padding;
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698