Commit 7bf730c6 authored by Morten Stenshorne's avatar Morten Stenshorne Committed by Commit Bot

Add more functionality to MinMaxSize.

It can now constrain the min/max sizes to a value, and also adjust them
to be at least as large as some value.

Also added an assignment operator for LayoutUnit. There are cases where
we want to set min and max to the same value.

Updated ComputeMinAndMaxContentContribution() implementation to use this
new functionality.

Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: I251c523213539acc9e508efebf701ed8f64e4265
Reviewed-on: https://chromium-review.googlesource.com/1236000Reviewed-by: default avatarChristian Biesinger <cbiesinger@chromium.org>
Reviewed-by: default avatarAleks Totic <atotic@chromium.org>
Commit-Queue: Morten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592892}
parent abe09b26
...@@ -8,6 +8,16 @@ ...@@ -8,6 +8,16 @@
namespace blink { namespace blink {
void MinMaxSize::Encompass(LayoutUnit value) {
min_size = std::max(min_size, value);
max_size = std::max(max_size, value);
}
void MinMaxSize::Constrain(LayoutUnit value) {
min_size = std::min(min_size, value);
max_size = std::min(max_size, value);
}
LayoutUnit MinMaxSize::ShrinkToFit(LayoutUnit available_size) const { LayoutUnit MinMaxSize::ShrinkToFit(LayoutUnit available_size) const {
DCHECK_GE(max_size, min_size); DCHECK_GE(max_size, min_size);
return std::min(max_size, std::max(min_size, available_size)); return std::min(max_size, std::max(min_size, available_size));
......
...@@ -17,6 +17,12 @@ struct CORE_EXPORT MinMaxSize { ...@@ -17,6 +17,12 @@ struct CORE_EXPORT MinMaxSize {
LayoutUnit min_size; LayoutUnit min_size;
LayoutUnit max_size; LayoutUnit max_size;
// Make sure that our min/max sizes are at least as large as |value|.
void Encompass(LayoutUnit value);
// Make sure that our min/max sizes aren't larger than |value|.
void Constrain(LayoutUnit value);
// Interprets the sizes as a min-content/max-content pair and computes the // Interprets the sizes as a min-content/max-content pair and computes the
// "shrink-to-fit" size based on them for the given available size. // "shrink-to-fit" size based on them for the given available size.
LayoutUnit ShrinkToFit(LayoutUnit available_size) const; LayoutUnit ShrinkToFit(LayoutUnit available_size) const;
...@@ -29,6 +35,7 @@ struct CORE_EXPORT MinMaxSize { ...@@ -29,6 +35,7 @@ struct CORE_EXPORT MinMaxSize {
return min_size == other.min_size && max_size == other.max_size; return min_size == other.min_size && max_size == other.max_size;
} }
void operator=(LayoutUnit value) { min_size = max_size = value; }
MinMaxSize& operator+=(const LayoutUnit); MinMaxSize& operator+=(const LayoutUnit);
MinMaxSize& operator-=(const LayoutUnit); MinMaxSize& operator-=(const LayoutUnit);
}; };
......
...@@ -316,11 +316,11 @@ MinMaxSize ComputeMinAndMaxContentContribution( ...@@ -316,11 +316,11 @@ MinMaxSize ComputeMinAndMaxContentContribution(
computed_sizes = *min_and_max; computed_sizes = *min_and_max;
} else { } else {
if (IsParallelWritingMode(writing_mode, style.GetWritingMode())) { if (IsParallelWritingMode(writing_mode, style.GetWritingMode())) {
computed_sizes.min_size = computed_sizes.max_size = ResolveInlineLength( computed_sizes = ResolveInlineLength(
space, style, min_and_max, inline_size, space, style, min_and_max, inline_size,
LengthResolveType::kContentSize, LengthResolvePhase::kIntrinsic); LengthResolveType::kContentSize, LengthResolvePhase::kIntrinsic);
} else { } else {
computed_sizes.min_size = computed_sizes.max_size = ResolveBlockLength( computed_sizes = ResolveBlockLength(
space, style, inline_size, content_size, space, style, inline_size, content_size,
LengthResolveType::kContentSize, LengthResolvePhase::kIntrinsic); LengthResolveType::kContentSize, LengthResolvePhase::kIntrinsic);
} }
...@@ -339,8 +339,7 @@ MinMaxSize ComputeMinAndMaxContentContribution( ...@@ -339,8 +339,7 @@ MinMaxSize ComputeMinAndMaxContentContribution(
LengthResolveType::kMaxSize, LengthResolveType::kMaxSize,
LengthResolvePhase::kIntrinsic); LengthResolvePhase::kIntrinsic);
} }
computed_sizes.min_size = std::min(computed_sizes.min_size, max); computed_sizes.Constrain(max);
computed_sizes.max_size = std::min(computed_sizes.max_size, max);
Length min_length = writing_mode == WritingMode::kHorizontalTb Length min_length = writing_mode == WritingMode::kHorizontalTb
? style.MinWidth() ? style.MinWidth()
...@@ -355,8 +354,7 @@ MinMaxSize ComputeMinAndMaxContentContribution( ...@@ -355,8 +354,7 @@ MinMaxSize ComputeMinAndMaxContentContribution(
LengthResolveType::kMinSize, LengthResolveType::kMinSize,
LengthResolvePhase::kIntrinsic); LengthResolvePhase::kIntrinsic);
} }
computed_sizes.min_size = std::max(computed_sizes.min_size, min); computed_sizes.Encompass(min);
computed_sizes.max_size = std::max(computed_sizes.max_size, min);
return computed_sizes; return computed_sizes;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment