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

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

Issue 2643043003: Constrain width/height to minmax values (Closed)
Patch Set: Clamp width/height to minmax values Created 3 years, 11 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
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_length_utils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 58c2b1caec83686914757e00c51238c562bd4b14..141b6b31f6d8aaa2c5f6c62ce1a6b638fe975238 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
@@ -242,18 +242,16 @@ LayoutUnit ComputeInlineSizeForFragment(
LayoutUnit extent = ResolveInlineLength(
space, style, min_and_max, logicalWidth, LengthResolveType::kContentSize);
- Length max_length = style.logicalMaxWidth();
- if (!max_length.isMaxSizeNone()) {
- LayoutUnit max = ResolveInlineLength(space, style, min_and_max, max_length,
- LengthResolveType::kMaxSize);
- extent = std::min(extent, max);
+ Optional<LayoutUnit> max_length;
+ if (!style.logicalMaxWidth().isMaxSizeNone()) {
+ max_length =
+ ResolveInlineLength(space, style, min_and_max, style.logicalMaxWidth(),
+ LengthResolveType::kMaxSize);
}
-
- LayoutUnit min =
+ Optional<LayoutUnit> min_length =
ResolveInlineLength(space, style, min_and_max, style.logicalMinWidth(),
LengthResolveType::kMinSize);
- extent = std::max(extent, min);
- return extent;
+ return ConstrainByMinMax(extent, min_length, max_length);
}
LayoutUnit ComputeBlockSizeForFragment(
@@ -270,20 +268,16 @@ LayoutUnit ComputeBlockSizeForFragment(
DCHECK_EQ(content_size, NGSizeIndefinite);
return extent;
}
-
- Length max_length = style.logicalMaxHeight();
- if (!max_length.isMaxSizeNone()) {
- LayoutUnit max =
- ResolveBlockLength(constraint_space, style, max_length, content_size,
- LengthResolveType::kMaxSize);
- extent = std::min(extent, max);
+ Optional<LayoutUnit> max_length;
+ if (!style.logicalMaxHeight().isMaxSizeNone()) {
+ max_length =
+ ResolveBlockLength(constraint_space, style, style.logicalMaxHeight(),
+ content_size, LengthResolveType::kMaxSize);
}
-
- LayoutUnit min =
+ Optional<LayoutUnit> min_length =
ResolveBlockLength(constraint_space, style, style.logicalMinHeight(),
content_size, LengthResolveType::kMinSize);
- extent = std::max(extent, min);
- return extent;
+ return ConstrainByMinMax(extent, min_length, max_length);
}
int ResolveUsedColumnCount(int computed_count,
@@ -408,4 +402,14 @@ void ApplyAutoMargins(const NGConstraintSpace& constraint_space,
}
}
+LayoutUnit ConstrainByMinMax(LayoutUnit length,
+ Optional<LayoutUnit> min,
+ Optional<LayoutUnit> max) {
+ if (max && length > max.value())
+ length = max.value();
+ if (min && length < min.value())
+ length = min.value();
+ return length;
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_length_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698