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

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

Issue 2243513003: [LayoutNG] Add tests for ng_length_utils. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: .. 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 0f039e89d86f3b915849abba362050727e8cfd9f..ee0480fb987e66698f9b58249dfc39e75127f81b 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
@@ -15,69 +15,88 @@ namespace blink {
// - positioned and/or replaced calculations
// - Handle margins for fill-available and width: auto
-LayoutUnit resolveInlineLength(LengthResolveType type,
+LayoutUnit resolveInlineLength(const NGConstraintSpace& constraintSpace,
const Length& length,
- const NGConstraintSpace& constraintSpace) {
+ LengthResolveType type) {
+ // TODO(layout-ng): Handle min/max/fit-content
DCHECK(!length.isMaxSizeNone());
+
if (type == LengthResolveType::MinSize && length.isAuto())
return LayoutUnit();
- // TODO(layout-ng): Handle min/max/fit-content
+
return valueForLength(length, constraintSpace.inlineContainerSize());
}
-LayoutUnit resolveBlockLength(LengthResolveType type,
+LayoutUnit resolveBlockLength(const NGConstraintSpace& constraintSpace,
const Length& length,
- const NGConstraintSpace& constraintSpace,
- LayoutUnit contentContribution) {
+ LayoutUnit contentSize,
+ LengthResolveType type) {
DCHECK(!length.isMaxSizeNone());
+
if (type == LengthResolveType::MinSize && length.isAuto())
return LayoutUnit();
+
if (length.isAuto())
- return contentContribution;
+ return contentSize;
+
if (length.isMinContent() || length.isMaxContent() || length.isFitContent())
- return contentContribution;
+ return contentSize;
+
return valueForLength(length, constraintSpace.blockContainerSize());
}
LayoutUnit computeInlineSizeForFragment(
const NGConstraintSpace& constraintSpace,
const ComputedStyle& style) {
- LayoutUnit extent = resolveInlineLength(
- LengthResolveType::ContentSize, style.logicalWidth(), constraintSpace);
+ if (constraintSpace.fixedInlineSize())
+ return constraintSpace.inlineContainerSize();
+
+ LayoutUnit extent = resolveInlineLength(constraintSpace, style.logicalWidth(),
+ LengthResolveType::ContentSize);
+
Length maxLength = style.logicalMaxWidth();
if (!maxLength.isMaxSizeNone()) {
- LayoutUnit max = resolveInlineLength(LengthResolveType::MaxSize, maxLength,
- constraintSpace);
+ LayoutUnit max = resolveInlineLength(constraintSpace, maxLength,
+ LengthResolveType::MaxSize);
extent = std::min(extent, max);
}
- LayoutUnit min = resolveInlineLength(
- LengthResolveType::MinSize, style.logicalMinWidth(), constraintSpace);
+
+ LayoutUnit min = resolveInlineLength(constraintSpace, style.logicalMinWidth(),
+ LengthResolveType::MinSize);
extent = std::max(extent, min);
+
if (style.boxSizing() == BoxSizingContentBox) {
// TODO(layout-ng): Compute border/padding size and add it
}
+
return extent;
}
LayoutUnit computeBlockSizeForFragment(const NGConstraintSpace& constraintSpace,
const ComputedStyle& style,
- LayoutUnit contentContribution) {
+ LayoutUnit contentSize) {
+ if (constraintSpace.fixedBlockSize())
+ return constraintSpace.blockContainerSize();
+
LayoutUnit extent =
- resolveBlockLength(LengthResolveType::ContentSize, style.logicalHeight(),
- constraintSpace, contentContribution);
+ resolveBlockLength(constraintSpace, style.logicalHeight(), contentSize,
+ LengthResolveType::ContentSize);
Length maxLength = style.logicalMaxHeight();
+
if (!maxLength.isMaxSizeNone()) {
- LayoutUnit max = resolveBlockLength(LengthResolveType::MaxSize, maxLength,
- constraintSpace, contentContribution);
+ LayoutUnit max = resolveBlockLength(constraintSpace, maxLength, contentSize,
+ LengthResolveType::MaxSize);
extent = std::min(extent, max);
}
- LayoutUnit min =
- resolveBlockLength(LengthResolveType::MinSize, style.logicalMinHeight(),
- constraintSpace, contentContribution);
+
+ LayoutUnit min = resolveBlockLength(constraintSpace, style.logicalMinHeight(),
+ contentSize, LengthResolveType::MinSize);
extent = std::max(extent, min);
+
if (style.boxSizing() == BoxSizingContentBox) {
// TODO(layout-ng): Compute border/padding size and add it
}
+
return extent;
}

Powered by Google App Engine
This is Rietveld 408576698