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

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

Issue 2274593002: [layoutng] Correctly resolve indefinite percentages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: NGSizeIndefinite 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 53713be8297314022d3c48a35bd918882ad225a7..454d1ea14e4ce8d97ba325e5bdb1a36e42b19ba2 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
@@ -21,6 +21,7 @@ LayoutUnit resolveInlineLength(const NGConstraintSpace& constraintSpace,
LengthResolveType type) {
// TODO(layout-ng): Handle min/max/fit-content
DCHECK(!length.isMaxSizeNone());
+ DCHECK_GE(constraintSpace.ContainerSize().inlineSize, LayoutUnit());
if (type == LengthResolveType::MinSize && length.isAuto())
return LayoutUnit();
@@ -47,6 +48,12 @@ LayoutUnit resolveBlockLength(const NGConstraintSpace& constraintSpace,
if (length.isMinContent() || length.isMaxContent() || length.isFitContent())
return contentSize;
+ // Make sure that indefinite percentages resolve to NGSizeIndefinite, not to
+ // a random negative number.
+ if (length.hasPercent() &&
+ constraintSpace.ContainerSize().blockSize == NGSizeIndefinite)
+ return contentSize;
+
return valueForLength(length, constraintSpace.ContainerSize().blockSize);
}
@@ -86,8 +93,12 @@ LayoutUnit computeBlockSizeForFragment(const NGConstraintSpace& constraintSpace,
LayoutUnit extent =
resolveBlockLength(constraintSpace, style.logicalHeight(), contentSize,
LengthResolveType::ContentSize);
- Length maxLength = style.logicalMaxHeight();
+ if (extent == NGSizeIndefinite) {
+ DCHECK_EQ(contentSize, NGSizeIndefinite);
+ return extent;
+ }
+ Length maxLength = style.logicalMaxHeight();
if (!maxLength.isMaxSizeNone()) {
LayoutUnit max = resolveBlockLength(constraintSpace, maxLength, contentSize,
LengthResolveType::MaxSize);

Powered by Google App Engine
This is Rietveld 408576698