use super::*;
pub(in crate::layout) fn constrain(mut value: f32, min: Option<f32>, max: Option<f32>) -> f32 {
if let Some(max) = max {
value = value.min(max);
}
if let Some(min) = min {
value = value.max(min);
}
value
}
pub(in crate::layout) fn stretch_fit_content_box_size(
available_margin_box_size: LayoutLength,
margin_size: LayoutLength,
non_content_size: NonContentLength,
) -> ContentBoxLength {
content_box_pt(
(available_margin_box_size.points() - margin_size.points() - non_content_size.points())
.max(0.0),
)
}
pub(in crate::layout) fn used_content_box_width(
style: &ComputedStyle,
available_outer_width: LayoutLength,
horizontal_non_content: NonContentLength,
) -> ContentBoxLength {
used_content_box_size(
style.box_values.width.clone(),
style.box_sizing,
PercentageBasis::definite(crate::units::layout_to_content_box_length(
available_outer_width,
)),
horizontal_non_content,
)
.unwrap_or_else(|| {
content_box_pt((available_outer_width.points() - horizontal_non_content.points()).max(0.0))
})
}
pub(in crate::layout) fn used_content_box_width_or_auto(
style: &ComputedStyle,
available_outer_width: LayoutLength,
horizontal_non_content: NonContentLength,
) -> Option<ContentBoxLength> {
used_content_box_size(
style.box_values.width.clone(),
style.box_sizing,
PercentageBasis::definite(crate::units::layout_to_content_box_length(
available_outer_width,
)),
horizontal_non_content,
)
}
pub(in crate::layout) fn used_content_box_width_or_auto_with_basis<Source>(
style: &ComputedStyle,
available_outer_width: PercentageBasis<ContentBoxLength, Source>,
horizontal_non_content: NonContentLength,
) -> Option<ContentBoxLength> {
used_content_box_size_with_basis(
style.box_values.width.clone(),
style.box_sizing,
available_outer_width,
horizontal_non_content,
)
}
pub(in crate::layout) fn used_content_box_height_or_auto(
style: &ComputedStyle,
available_outer_height: LayoutLength,
vertical_non_content: NonContentLength,
) -> Option<ContentBoxLength> {
used_content_box_size(
style.box_values.height.value().clone(),
style.box_sizing,
PercentageBasis::definite(crate::units::layout_to_content_box_length(
available_outer_height,
)),
vertical_non_content,
)
}
pub(in crate::layout) fn used_content_box_height_or_auto_with_basis<Source>(
style: &ComputedStyle,
available_outer_height: PercentageBasis<ContentBoxLength, Source>,
vertical_non_content: NonContentLength,
) -> Option<ContentBoxLength> {
used_content_box_size_with_basis(
style.box_values.height.value().clone(),
style.box_sizing,
available_outer_height,
vertical_non_content,
)
}
pub(in crate::layout) fn used_non_replaced_content_box_height_or_auto(
style: &ComputedStyle,
context: DescendantBlockPercentageContext,
vertical_non_content: NonContentLength,
) -> Option<ContentBoxLength> {
let value = style.box_values.height.value().clone();
if context.is_content_sized()
&& matches!(&value, css::ComputedLengthPercentageOrAuto::LengthPercentage(value) if value.needs_percentage_basis())
{
return None;
}
used_content_box_size_with_basis(
value,
style.box_sizing,
context.percentage_basis(),
vertical_non_content,
)
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(in crate::layout) enum AspectRatioCalculationBox {
ContentBox,
BorderBox,
}
#[derive(Debug, Clone, Copy)]
pub(in crate::layout) struct ResolvedAspectRatio {
ratio: f32,
calculation_box: AspectRatioCalculationBox,
horizontal_non_content: NonContentLength,
vertical_non_content: NonContentLength,
}
impl ResolvedAspectRatio {
pub(in crate::layout) fn for_non_replaced(
style: &ComputedStyle,
horizontal_non_content: NonContentLength,
vertical_non_content: NonContentLength,
) -> Option<Self> {
let ratio = style.aspect_ratio.preferred_ratio_for_non_replaced(false)?;
Self::new(
ratio,
if style.aspect_ratio.uses_content_box_for_non_replaced()
|| style.box_sizing == BoxSizing::ContentBox
{
AspectRatioCalculationBox::ContentBox
} else {
AspectRatioCalculationBox::BorderBox
},
horizontal_non_content,
vertical_non_content,
)
}
pub(in crate::layout) fn new(
ratio: f32,
calculation_box: AspectRatioCalculationBox,
horizontal_non_content: NonContentLength,
vertical_non_content: NonContentLength,
) -> Option<Self> {
(ratio.is_finite() && ratio > 0.0).then_some(Self {
ratio,
calculation_box,
horizontal_non_content,
vertical_non_content,
})
}
pub(in crate::layout) fn width_from_height(
self,
content_height: ContentBoxLength,
) -> ContentBoxLength {
match self.calculation_box {
AspectRatioCalculationBox::ContentBox => {
content_box_pt(content_height.points() * self.ratio)
}
AspectRatioCalculationBox::BorderBox => {
let border_box_height =
content_box_to_border_box_length(content_height, self.vertical_non_content);
border_box_to_content_box_length(
border_box_pt(border_box_height.points() * self.ratio),
self.horizontal_non_content,
)
}
}
}
pub(in crate::layout) fn height_from_width(
self,
content_width: ContentBoxLength,
) -> ContentBoxLength {
match self.calculation_box {
AspectRatioCalculationBox::ContentBox => {
content_box_pt(content_width.points() / self.ratio)
}
AspectRatioCalculationBox::BorderBox => {
let border_box_width =
content_box_to_border_box_length(content_width, self.horizontal_non_content);
border_box_to_content_box_length(
border_box_pt(border_box_width.points() / self.ratio),
self.vertical_non_content,
)
}
}
}
}
#[derive(Debug, Clone, Copy, Default)]
pub(in crate::layout) struct AspectRatioAxisConstraints {
pub(in crate::layout) preferred: Option<ContentBoxLength>,
pub(in crate::layout) minimum: Option<ContentBoxLength>,
pub(in crate::layout) maximum: Option<ContentBoxLength>,
}
impl AspectRatioAxisConstraints {
pub(in crate::layout) fn constrain(self, value: ContentBoxLength) -> ContentBoxLength {
constrain_aspect_ratio_axis(value, self)
}
}
#[derive(Debug, Clone, Copy)]
pub(in crate::layout) struct ResolvedAspectRatioConstraints {
pub(in crate::layout) width: AspectRatioAxisConstraints,
pub(in crate::layout) height: AspectRatioAxisConstraints,
}
impl ResolvedAspectRatioConstraints {
pub(in crate::layout) fn resolve(
ratio: ResolvedAspectRatio,
width: AspectRatioAxisConstraints,
height: AspectRatioAxisConstraints,
) -> Self {
let transferred_width_minimum = height.minimum.map(|minimum| {
cap_transferred_minimum(
ratio.width_from_height(minimum),
width.preferred,
width.maximum,
)
});
let transferred_height_minimum = width.minimum.map(|minimum| {
cap_transferred_minimum(
ratio.height_from_width(minimum),
height.preferred,
height.maximum,
)
});
let resolved_width_minimum = combine_minimum(width.minimum, transferred_width_minimum);
let resolved_height_minimum = combine_minimum(height.minimum, transferred_height_minimum);
let transferred_width_maximum = height.maximum.map(|maximum| {
floor_transferred_maximum(
ratio.width_from_height(maximum),
width.preferred,
resolved_width_minimum,
)
});
let transferred_height_maximum = width.maximum.map(|maximum| {
floor_transferred_maximum(
ratio.height_from_width(maximum),
height.preferred,
resolved_height_minimum,
)
});
let resolved_width = AspectRatioAxisConstraints {
minimum: resolved_width_minimum,
maximum: combine_maximum(width.maximum, transferred_width_maximum),
..width
};
let resolved_height = AspectRatioAxisConstraints {
minimum: resolved_height_minimum,
maximum: combine_maximum(height.maximum, transferred_height_maximum),
..height
};
Self {
width: resolved_width,
height: resolved_height,
}
}
pub(in crate::layout) fn constrain_width(self, value: ContentBoxLength) -> ContentBoxLength {
constrain_aspect_ratio_axis(value, self.width)
}
pub(in crate::layout) fn constrain_height(self, value: ContentBoxLength) -> ContentBoxLength {
constrain_aspect_ratio_axis(value, self.height)
}
}
fn combine_minimum(
authored: Option<ContentBoxLength>,
transferred: Option<ContentBoxLength>,
) -> Option<ContentBoxLength> {
match (authored, transferred) {
(Some(authored), Some(transferred)) => {
Some(content_box_pt(authored.points().max(transferred.points())))
}
(authored, transferred) => authored.or(transferred),
}
}
fn combine_maximum(
authored: Option<ContentBoxLength>,
transferred: Option<ContentBoxLength>,
) -> Option<ContentBoxLength> {
match (authored, transferred) {
(Some(authored), Some(transferred)) => {
Some(content_box_pt(authored.points().min(transferred.points())))
}
(authored, transferred) => authored.or(transferred),
}
}
fn cap_transferred_minimum(
transferred: ContentBoxLength,
preferred: Option<ContentBoxLength>,
maximum: Option<ContentBoxLength>,
) -> ContentBoxLength {
content_box_pt(
[preferred, maximum]
.into_iter()
.flatten()
.fold(transferred.points(), |value, limit| {
value.min(limit.points())
})
.max(0.0),
)
}
fn floor_transferred_maximum(
transferred: ContentBoxLength,
preferred: Option<ContentBoxLength>,
minimum: Option<ContentBoxLength>,
) -> ContentBoxLength {
content_box_pt(
[preferred, minimum]
.into_iter()
.flatten()
.fold(transferred.points(), |value, limit| {
value.max(limit.points())
})
.max(0.0),
)
}
fn constrain_aspect_ratio_axis(
value: ContentBoxLength,
constraints: AspectRatioAxisConstraints,
) -> ContentBoxLength {
content_box_pt(constrain(
value.points(),
constraints.minimum.map(SemanticLengthExt::points),
constraints.maximum.map(SemanticLengthExt::points),
))
}
pub(in crate::layout) fn non_replaced_aspect_ratio_content_height(
style: &ComputedStyle,
content_width: f32,
horizontal_non_content: f32,
vertical_non_content: f32,
) -> Option<f32> {
let calc_size = style.box_values.height.calc_size_with_auto_basis();
if !style.box_values.height.is_auto() && calc_size.is_none() {
return None;
}
let ratio = ResolvedAspectRatio::for_non_replaced(
style,
non_content_pt(horizontal_non_content),
non_content_pt(vertical_non_content),
)?;
let height = ratio
.height_from_width(content_box_pt(content_width))
.points();
Some(
calc_size
.map(|value| {
value
.used_value(
height,
0.0,
0.0,
0.0,
0.0,
PercentageBasis::definite(layout_pt(0.0)),
)
.points()
})
.unwrap_or(height)
.max(0.0),
)
}
pub(in crate::layout) fn non_replaced_aspect_ratio_content_width(
style: &ComputedStyle,
content_height: f32,
horizontal_non_content: f32,
vertical_non_content: f32,
) -> Option<f32> {
let calc_size = style.box_values.width.clone().calc_size_with_auto_basis();
if !style.box_values.width.clone().is_auto() && calc_size.is_none() {
return None;
}
let ratio = ResolvedAspectRatio::for_non_replaced(
style,
non_content_pt(horizontal_non_content),
non_content_pt(vertical_non_content),
)?;
let width = ratio
.width_from_height(content_box_pt(content_height))
.points();
Some(
calc_size
.map(|value| {
value
.used_value(
width,
0.0,
0.0,
0.0,
0.0,
PercentageBasis::definite(layout_pt(0.0)),
)
.points()
})
.unwrap_or(width)
.max(0.0),
)
}
pub(in crate::layout) fn used_content_box_size<Source>(
value: css::ComputedLengthPercentageOrAuto,
box_sizing: BoxSizing,
percentage_basis: PercentageBasis<ContentBoxLength, Source>,
non_content: NonContentLength,
) -> Option<ContentBoxLength> {
used_content_box_size_with_basis(value, box_sizing, percentage_basis, non_content)
}
pub(in crate::layout) fn used_content_box_size_with_basis<Source>(
value: css::ComputedLengthPercentageOrAuto,
box_sizing: BoxSizing,
percentage_basis: PercentageBasis<ContentBoxLength, Source>,
non_content: NonContentLength,
) -> Option<ContentBoxLength> {
let specified = match value {
css::ComputedLengthPercentageOrAuto::Auto => return None,
css::ComputedLengthPercentageOrAuto::Stretch => {
return percentage_basis.points().map(|basis| {
stretch_fit_content_box_size(layout_pt(basis), layout_pt(0.0), non_content)
});
}
css::ComputedLengthPercentageOrAuto::LengthPercentage(value) => {
layout_points(used_length_percentage_with_basis(value, percentage_basis)?)
}
css::ComputedLengthPercentageOrAuto::MinContent
| css::ComputedLengthPercentageOrAuto::MaxContent
| css::ComputedLengthPercentageOrAuto::FitContent(_)
| css::ComputedLengthPercentageOrAuto::CalcSize(_) => return None,
};
Some(used_content_box_size_from_specified(
specified,
box_sizing,
non_content,
))
}
fn used_content_box_size_from_specified(
specified: f32,
box_sizing: BoxSizing,
non_content: NonContentLength,
) -> ContentBoxLength {
match box_sizing {
BoxSizing::BorderBox => {
border_box_to_content_box_length(border_box_pt(specified), non_content)
}
BoxSizing::ContentBox => content_box_pt(specified.max(0.0)),
}
}
pub(in crate::layout) fn used_min_width<T, Source>(
style: &ComputedStyle,
percentage_basis: PercentageBasis<T, Source>,
) -> Option<ContentBoxLength>
where
T: SemanticLengthExt,
{
used_length_percentage_or_auto(style.box_values.min_width.clone(), percentage_basis)
.map(|value| content_box_pt(value.points().max(0.0)))
}
pub(in crate::layout) fn used_max_width<T, Source>(
style: &ComputedStyle,
percentage_basis: PercentageBasis<T, Source>,
) -> Option<ContentBoxLength>
where
T: SemanticLengthExt,
{
used_length_percentage_or_auto(style.box_values.max_width.clone(), percentage_basis)
.map(|value| content_box_pt(value.points().max(0.0)))
}
pub(in crate::layout) fn needs_intrinsic_width_contribution(
value: css::ComputedLengthPercentageOrAuto,
) -> bool {
matches!(
value,
css::ComputedLengthPercentageOrAuto::MinContent
| css::ComputedLengthPercentageOrAuto::MaxContent
| css::ComputedLengthPercentageOrAuto::FitContent(_)
) || matches!(&value, css::ComputedLengthPercentageOrAuto::CalcSize(value) if value.needs_intrinsic_size())
|| matches!(&value, css::ComputedLengthPercentageOrAuto::LengthPercentage(value) if value.needs_percentage_basis())
}
pub(in crate::layout) fn needs_intrinsic_height_contribution(
value: css::ComputedLengthPercentageOrAuto,
) -> bool {
matches!(
value,
css::ComputedLengthPercentageOrAuto::MinContent
| css::ComputedLengthPercentageOrAuto::MaxContent
| css::ComputedLengthPercentageOrAuto::FitContent(_)
) || matches!(value, css::ComputedLengthPercentageOrAuto::CalcSize(value) if value.needs_intrinsic_size())
}
pub(in crate::layout) fn used_min_height<T, Source>(
style: &ComputedStyle,
percentage_basis: PercentageBasis<T, Source>,
) -> Option<ContentBoxLength>
where
T: SemanticLengthExt,
{
match style.box_values.min_height.clone() {
css::ComputedLengthPercentageOrAuto::LengthPercentage(value) => {
Some(content_box_pt(
used_length_percentage(value, percentage_basis)
.points()
.max(0.0),
))
}
css::ComputedLengthPercentageOrAuto::Auto
| css::ComputedLengthPercentageOrAuto::Stretch
| css::ComputedLengthPercentageOrAuto::MinContent
| css::ComputedLengthPercentageOrAuto::MaxContent
| css::ComputedLengthPercentageOrAuto::FitContent(_)
| css::ComputedLengthPercentageOrAuto::CalcSize(_) => None,
}
}
pub(in crate::layout) fn used_max_height<T, Source>(
style: &ComputedStyle,
percentage_basis: PercentageBasis<T, Source>,
) -> Option<ContentBoxLength>
where
T: SemanticLengthExt,
{
used_length_percentage_or_auto(style.box_values.max_height.clone(), percentage_basis)
.map(|value| content_box_pt(value.points().max(0.0)))
}
pub(in crate::layout) fn used_non_replaced_max_height(
style: &ComputedStyle,
context: DescendantBlockPercentageContext,
) -> Option<ContentBoxLength> {
let value = style.box_values.max_height.clone();
if context.is_content_sized()
&& matches!(&value, css::ComputedLengthPercentageOrAuto::LengthPercentage(value) if value.needs_percentage_basis())
{
return None;
}
used_max_height(style, context.percentage_basis())
}
pub(in crate::layout) fn constrain_non_replaced_content_height(
style: &ComputedStyle,
value: ContentBoxLength,
context: DescendantBlockPercentageContext,
) -> ContentBoxLength {
let mut cyclic_style;
let style = if context.is_content_sized()
&& matches!(
&style.box_values.max_height,
css::ComputedLengthPercentageOrAuto::LengthPercentage(value) if value.needs_percentage_basis()
) {
cyclic_style = style.clone();
cyclic_style.box_values.max_height = css::ComputedLengthPercentageOrAuto::Auto;
&cyclic_style
} else {
style
};
constrain_content_height(style, value, context.percentage_basis())
}
pub(in crate::layout) trait ConstraintPercentageBasis {
fn into_layout_basis(self) -> PercentageBasis<LayoutLength>;
}
impl<T, Source> ConstraintPercentageBasis for PercentageBasis<T, Source>
where
T: crate::units::IntoLayoutLength,
{
fn into_layout_basis(self) -> PercentageBasis<LayoutLength> {
match self {
PercentageBasis::Definite { value, .. } => {
PercentageBasis::definite(crate::units::IntoLayoutLength::into_layout_length(value))
}
PercentageBasis::Indefinite => PercentageBasis::indefinite(),
}
}
}
pub(in crate::layout) fn constrain_content_width<B>(
style: &ComputedStyle,
value: ContentBoxLength,
percentage_basis: B,
) -> ContentBoxLength
where
B: ConstraintPercentageBasis,
{
let percentage_basis = percentage_basis.into_layout_basis();
content_box_pt(constrain(
value.points(),
used_min_width(style, percentage_basis).map(SemanticLengthExt::points),
used_max_width(style, percentage_basis).map(SemanticLengthExt::points),
))
}
pub(in crate::layout) fn constrain_width_with_stretch_fit(
style: &ComputedStyle,
value: ContentBoxLength,
available_margin_box_width: LayoutLength,
horizontal_margin: LayoutLength,
horizontal_non_content: NonContentLength,
) -> ContentBoxLength {
let stretch = || {
stretch_fit_content_box_size(
available_margin_box_width,
horizontal_margin,
horizontal_non_content,
)
.points()
};
let min = if style.box_values.min_width == css::ComputedLengthPercentageOrAuto::Stretch {
Some(stretch())
} else {
used_min_width(style, PercentageBasis::definite(available_margin_box_width))
.map(SemanticLengthExt::points)
};
let max = if style.box_values.max_width == css::ComputedLengthPercentageOrAuto::Stretch {
Some(stretch())
} else {
used_max_width(style, PercentageBasis::definite(available_margin_box_width))
.map(SemanticLengthExt::points)
};
content_box_pt(constrain(value.points(), min, max))
}
pub(in crate::layout) fn constrain_width_with_intrinsic<Source>(
style: &ComputedStyle,
value: ContentBoxLength,
min_content: ContentBoxLength,
max_content: ContentBoxLength,
percentage_basis: PercentageBasis<ContentBoxLength, Source>,
horizontal_non_content: NonContentLength,
) -> ContentBoxLength {
let min_content = content_box_pt(min_content.points().max(0.0));
let max_content = content_box_pt(max_content.points().max(min_content.points()).max(0.0));
let percentage_basis = match percentage_basis {
PercentageBasis::Definite { value, .. } => PercentageBasis::definite(value),
PercentageBasis::Indefinite => PercentageBasis::indefinite(),
};
let min_constraint = intrinsic_width_constraint(
style.box_values.min_width.clone(),
style.box_sizing,
percentage_basis,
horizontal_non_content,
min_content,
max_content,
);
let max_constraint = intrinsic_width_constraint(
style.box_values.max_width.clone(),
style.box_sizing,
percentage_basis,
horizontal_non_content,
min_content,
max_content,
);
content_box_pt(
constrain(
value.points().max(0.0),
min_constraint.map(SemanticLengthExt::points),
max_constraint.map(SemanticLengthExt::points),
)
.max(0.0),
)
}
pub(in crate::layout) fn intrinsic_width_constraint(
value: css::ComputedLengthPercentageOrAuto,
box_sizing: BoxSizing,
percentage_basis: PercentageBasis<ContentBoxLength>,
horizontal_non_content: NonContentLength,
min_content: ContentBoxLength,
max_content: ContentBoxLength,
) -> Option<ContentBoxLength> {
match value {
css::ComputedLengthPercentageOrAuto::Auto => None,
css::ComputedLengthPercentageOrAuto::MinContent => Some(min_content),
css::ComputedLengthPercentageOrAuto::MaxContent => Some(max_content),
css::ComputedLengthPercentageOrAuto::FitContent(limit) => {
let stretch = limit
.map(|limit| {
intrinsic_constraint_length(
limit,
box_sizing,
percentage_basis,
horizontal_non_content,
)
})
.unwrap_or_else(|| {
percentage_basis.points().map(|basis| {
stretch_fit_content_box_size(
layout_pt(basis),
layout_pt(0.0),
horizontal_non_content,
)
})
})?;
Some(content_box_pt(
max_content
.points()
.min(min_content.points().max(stretch.points()))
.max(0.0),
))
}
css::ComputedLengthPercentageOrAuto::LengthPercentage(value) => {
intrinsic_constraint_length(value, box_sizing, percentage_basis, horizontal_non_content)
}
css::ComputedLengthPercentageOrAuto::Stretch => percentage_basis.points().map(|basis| {
stretch_fit_content_box_size(layout_pt(basis), layout_pt(0.0), horizontal_non_content)
}),
css::ComputedLengthPercentageOrAuto::CalcSize(value) => calc_size_intrinsic_constraint(
value,
box_sizing,
percentage_basis,
horizontal_non_content,
min_content,
max_content,
),
}
}
fn intrinsic_constraint_length(
value: css::ComputedLengthPercentage,
box_sizing: BoxSizing,
percentage_basis: PercentageBasis<ContentBoxLength>,
horizontal_non_content: NonContentLength,
) -> Option<ContentBoxLength> {
if !percentage_basis.is_definite() && value.contains_percentage() {
return None;
}
let specified = used_length_percentage_with_basis(value, percentage_basis)?.points();
Some(used_content_box_size_from_specified(
specified,
box_sizing,
horizontal_non_content,
))
}
pub(in crate::layout) fn calc_size_intrinsic_constraint(
value: css::CalcSize,
box_sizing: BoxSizing,
percentage_basis: PercentageBasis<ContentBoxLength>,
non_content: NonContentLength,
min_content: ContentBoxLength,
max_content: ContentBoxLength,
) -> Option<ContentBoxLength> {
let percentage_basis_points = percentage_basis.points().unwrap_or(0.0);
let to_specified = |content: ContentBoxLength| match box_sizing {
BoxSizing::ContentBox => content.points(),
BoxSizing::BorderBox => content.points() + non_content.points(),
};
let min_content = to_specified(min_content);
let max_content = to_specified(max_content).max(min_content);
let stretch = stretch_fit_content_box_size(
layout_pt(percentage_basis_points),
layout_pt(0.0),
non_content,
)
.points();
let fit_content = max_content.min(min_content.max(stretch));
let basis = match &value.basis {
css::CalcSizeBasis::Auto | css::CalcSizeBasis::MinContent => min_content,
css::CalcSizeBasis::MaxContent => max_content,
css::CalcSizeBasis::FitContent => fit_content,
css::CalcSizeBasis::Stretch => stretch,
css::CalcSizeBasis::LengthPercentage(value) => {
used_length_percentage_with_basis(value.clone(), percentage_basis)?.points()
}
};
Some(used_content_box_size_from_specified(
value
.used_value(
basis,
min_content,
max_content,
fit_content,
stretch,
percentage_basis,
)
.max(layout_pt(0.0))
.points(),
box_sizing,
non_content,
))
}
pub(in crate::layout) fn non_replaced_intrinsic_width_contributions(
style: &ComputedStyle,
min_content: ContentBoxLength,
max_content: ContentBoxLength,
horizontal_non_content: NonContentLength,
) -> (ContentBoxLength, ContentBoxLength) {
let intrinsic_min_content = content_box_pt(min_content.points().max(0.0));
let intrinsic_max_content = content_box_pt(
max_content
.points()
.max(intrinsic_min_content.points())
.max(0.0),
);
let preferred_width = non_replaced_intrinsic_preferred_width(
style.box_values.width.clone(),
style.box_sizing,
horizontal_non_content,
intrinsic_min_content,
intrinsic_max_content,
);
let intrinsic_min_percentage_basis = PercentageBasis::definite(content_box_pt(0.0));
let intrinsic_max_percentage_basis = PercentageBasis::indefinite();
let min_constraint = intrinsic_width_constraint(
style.box_values.min_width.clone(),
style.box_sizing,
intrinsic_min_percentage_basis,
horizontal_non_content,
intrinsic_min_content,
intrinsic_max_content,
)
.map(SemanticLengthExt::points);
let max_constraint = intrinsic_width_constraint(
style.box_values.max_width.clone(),
style.box_sizing,
intrinsic_max_percentage_basis,
horizontal_non_content,
intrinsic_min_content,
intrinsic_max_content,
)
.map(SemanticLengthExt::points);
let transferred_aspect_width = (!matches!(
style.box_values.width.clone(),
css::ComputedLengthPercentageOrAuto::LengthPercentage(_)
))
.then(|| {
let vertical_non_content = intrinsic_box_metrics(style).vertical_non_content_length();
used_content_box_size(
style.box_values.height.value().clone(),
style.box_sizing,
PercentageBasis::definite(content_box_pt(0.0)),
vertical_non_content,
)
.map(|height| {
constrain_height_with_intrinsic(
style,
height,
height,
height,
PercentageBasis::definite(content_box_pt(0.0)),
vertical_non_content,
)
.points()
})
.and_then(|height| {
non_replaced_aspect_ratio_content_width(
style,
height,
horizontal_non_content.points(),
vertical_non_content.points(),
)
})
})
.flatten();
let preferred_min_content = preferred_width
.map(|value| value.0)
.unwrap_or(intrinsic_min_content)
.points();
let preferred_max_content = preferred_width
.map(|value| value.1)
.unwrap_or(intrinsic_max_content)
.points();
let (min_content, max_content) = if style.box_values.width.clone().is_auto() {
transferred_aspect_width
.map(|width| (width, width))
.unwrap_or((preferred_min_content, preferred_max_content))
} else {
(
preferred_min_content.max(transferred_aspect_width.unwrap_or(0.0)),
preferred_max_content.max(transferred_aspect_width.unwrap_or(0.0)),
)
};
(
content_box_pt(constrain(min_content, min_constraint, max_constraint).max(0.0)),
content_box_pt(constrain(max_content, min_constraint, max_constraint).max(0.0)),
)
}
pub(in crate::layout) fn constrain_non_replaced_intrinsic_widths(
style: &ComputedStyle,
min_content: f32,
max_content: f32,
horizontal_non_content: f32,
) -> (f32, f32) {
let (min_content, max_content) = non_replaced_intrinsic_width_contributions(
style,
content_box_pt(min_content),
content_box_pt(max_content),
non_content_pt(horizontal_non_content),
);
(min_content.points(), max_content.points())
}
fn non_replaced_intrinsic_preferred_width(
value: css::ComputedLengthPercentageOrAuto,
box_sizing: BoxSizing,
horizontal_non_content: NonContentLength,
min_content: ContentBoxLength,
max_content: ContentBoxLength,
) -> Option<(ContentBoxLength, ContentBoxLength)> {
match value {
css::ComputedLengthPercentageOrAuto::LengthPercentage(value) => {
non_cyclic_content_box_length(value, box_sizing, horizontal_non_content)
.map(|value| (value, value))
}
css::ComputedLengthPercentageOrAuto::MinContent => Some((min_content, min_content)),
css::ComputedLengthPercentageOrAuto::MaxContent => Some((max_content, max_content)),
css::ComputedLengthPercentageOrAuto::FitContent(Some(limit)) => {
non_replaced_intrinsic_fit_content_width(
limit,
box_sizing,
horizontal_non_content,
min_content,
max_content,
)
.map(|value| (value, value))
}
css::ComputedLengthPercentageOrAuto::CalcSize(value) => {
let min_content_points = min_content.points();
let max_content_points = max_content.points();
let intrinsic_basis = |min_size: f32, max_size: f32| match &value.basis {
css::CalcSizeBasis::Auto
| css::CalcSizeBasis::FitContent
| css::CalcSizeBasis::MinContent => (min_size, max_size),
css::CalcSizeBasis::MaxContent => (max_size, max_size),
css::CalcSizeBasis::Stretch => (0.0, 0.0),
css::CalcSizeBasis::LengthPercentage(basis) => {
let basis = used_length_percentage(
basis.clone(),
PercentageBasis::definite(layout_pt(0.0)),
)
.points();
(basis, basis)
}
};
let (min_basis, max_basis) = intrinsic_basis(min_content_points, max_content_points);
let min_specified = value
.used_value(
min_basis,
min_content_points,
max_content_points,
min_basis,
0.0,
PercentageBasis::definite(layout_pt(0.0)),
)
.points();
let max_specified = value
.used_value(
max_basis,
min_content_points,
max_content_points,
max_basis,
0.0,
PercentageBasis::definite(layout_pt(0.0)),
)
.points();
Some((
used_content_box_size_from_specified(
min_specified.max(0.0),
box_sizing,
horizontal_non_content,
),
used_content_box_size_from_specified(
max_specified.max(0.0),
box_sizing,
horizontal_non_content,
),
))
}
css::ComputedLengthPercentageOrAuto::Auto
| css::ComputedLengthPercentageOrAuto::FitContent(None)
| css::ComputedLengthPercentageOrAuto::Stretch => None,
}
}
fn non_replaced_intrinsic_fit_content_width(
limit: css::ComputedLengthPercentage,
box_sizing: BoxSizing,
horizontal_non_content: NonContentLength,
min_content: ContentBoxLength,
max_content: ContentBoxLength,
) -> Option<ContentBoxLength> {
let limit = non_cyclic_content_box_length(limit, box_sizing, horizontal_non_content)?;
Some(content_box_pt(
max_content
.points()
.min(min_content.points().max(limit.points()))
.max(0.0),
))
}
fn non_cyclic_content_box_length(
value: css::ComputedLengthPercentage,
box_sizing: BoxSizing,
horizontal_non_content: NonContentLength,
) -> Option<ContentBoxLength> {
let specified = value.length_if_no_percent()?;
Some(used_content_box_size_from_specified(
specified,
box_sizing,
horizontal_non_content,
))
}
pub(in crate::layout) fn constrain_content_height<B>(
style: &ComputedStyle,
value: ContentBoxLength,
percentage_basis: B,
) -> ContentBoxLength
where
B: ConstraintPercentageBasis,
{
let percentage_basis = percentage_basis.into_layout_basis();
let vertical_non_content = intrinsic_box_metrics(style).vertical_non_content_length();
let content_box_constraint = |value: ContentBoxLength| {
used_content_box_size_from_specified(
value.points().max(0.0),
style.box_sizing,
vertical_non_content,
)
.points()
};
content_box_pt(constrain(
value.points(),
used_min_height(style, percentage_basis).map(content_box_constraint),
used_max_height(style, percentage_basis).map(content_box_constraint),
))
}
pub(in crate::layout) fn constrain_height_with_stretch_fit(
style: &ComputedStyle,
value: ContentBoxLength,
available_margin_box_height: LayoutLength,
_vertical_margin: LayoutLength,
vertical_non_content: NonContentLength,
) -> ContentBoxLength {
let stretch = || {
stretch_fit_content_box_size(
available_margin_box_height,
layout_pt(0.0),
vertical_non_content,
)
.points()
};
let min = if style.box_values.min_height == css::ComputedLengthPercentageOrAuto::Stretch {
Some(stretch())
} else {
used_min_height(
style,
PercentageBasis::definite(available_margin_box_height),
)
.map(|value| {
used_content_box_size_from_specified(
value.points(),
style.box_sizing,
vertical_non_content,
)
.points()
})
};
let max = if style.box_values.max_height == css::ComputedLengthPercentageOrAuto::Stretch {
Some(stretch())
} else {
used_max_height(
style,
PercentageBasis::definite(available_margin_box_height),
)
.map(|value| {
used_content_box_size_from_specified(
value.points(),
style.box_sizing,
vertical_non_content,
)
.points()
})
};
content_box_pt(constrain(value.points(), min, max))
}
pub(in crate::layout) fn constrain_height_with_intrinsic<Source>(
style: &ComputedStyle,
value: ContentBoxLength,
min_content: ContentBoxLength,
max_content: ContentBoxLength,
percentage_basis: PercentageBasis<ContentBoxLength, Source>,
vertical_non_content: NonContentLength,
) -> ContentBoxLength {
let min_content = content_box_pt(min_content.points().max(0.0));
let max_content = content_box_pt(max_content.points().max(min_content.points()).max(0.0));
let percentage_basis = match percentage_basis {
PercentageBasis::Definite { value, .. } => PercentageBasis::definite(value),
PercentageBasis::Indefinite => PercentageBasis::indefinite(),
};
let min_constraint = intrinsic_height_constraint(
style.box_values.min_height.clone(),
style.box_sizing,
percentage_basis,
vertical_non_content,
min_content,
max_content,
);
let max_constraint = intrinsic_height_constraint(
style.box_values.max_height.clone(),
style.box_sizing,
percentage_basis,
vertical_non_content,
min_content,
max_content,
);
content_box_pt(
constrain(
value.points().max(0.0),
min_constraint.map(SemanticLengthExt::points),
max_constraint.map(SemanticLengthExt::points),
)
.max(0.0),
)
}
pub(in crate::layout) fn constrain_non_replaced_height_with_intrinsic(
style: &ComputedStyle,
value: ContentBoxLength,
min_content: ContentBoxLength,
max_content: ContentBoxLength,
context: DescendantBlockPercentageContext,
vertical_non_content: NonContentLength,
) -> ContentBoxLength {
let mut cyclic_style;
let style = if context.is_content_sized()
&& matches!(
&style.box_values.max_height,
css::ComputedLengthPercentageOrAuto::LengthPercentage(value) if value.needs_percentage_basis()
) {
cyclic_style = style.clone();
cyclic_style.box_values.max_height = css::ComputedLengthPercentageOrAuto::Auto;
&cyclic_style
} else {
style
};
constrain_height_with_intrinsic(
style,
value,
min_content,
max_content,
context.percentage_basis(),
vertical_non_content,
)
}
pub(in crate::layout) fn intrinsic_height_constraint(
value: css::ComputedLengthPercentageOrAuto,
box_sizing: BoxSizing,
percentage_basis: PercentageBasis<ContentBoxLength>,
vertical_non_content: NonContentLength,
min_content: ContentBoxLength,
max_content: ContentBoxLength,
) -> Option<ContentBoxLength> {
match value {
css::ComputedLengthPercentageOrAuto::Auto => None,
css::ComputedLengthPercentageOrAuto::MinContent => Some(min_content),
css::ComputedLengthPercentageOrAuto::MaxContent => Some(max_content),
css::ComputedLengthPercentageOrAuto::FitContent(limit) => {
let stretch = limit
.map(|limit| {
intrinsic_constraint_length(
limit,
box_sizing,
percentage_basis,
vertical_non_content,
)
})
.unwrap_or_else(|| {
percentage_basis.points().map(|basis| {
stretch_fit_content_box_size(
layout_pt(basis),
layout_pt(0.0),
vertical_non_content,
)
})
})?;
Some(content_box_pt(
max_content
.points()
.min(min_content.points().max(stretch.points()))
.max(0.0),
))
}
css::ComputedLengthPercentageOrAuto::LengthPercentage(value) => {
intrinsic_constraint_length(value, box_sizing, percentage_basis, vertical_non_content)
}
css::ComputedLengthPercentageOrAuto::Stretch => percentage_basis.points().map(|basis| {
stretch_fit_content_box_size(layout_pt(basis), layout_pt(0.0), vertical_non_content)
}),
css::ComputedLengthPercentageOrAuto::CalcSize(value) => calc_size_intrinsic_constraint(
value,
box_sizing,
percentage_basis,
vertical_non_content,
min_content,
max_content,
),
}
}
#[cfg(test)]
mod tests {
use super::super::*;
fn length_auto(value: f32) -> css::ComputedLengthPercentageOrAuto {
css::ComputedLengthPercentageOrAuto::LengthPercentage(
css::ComputedLengthPercentage::from_points(value),
)
}
fn percent_auto(value: f32) -> css::ComputedLengthPercentageOrAuto {
css::ComputedLengthPercentageOrAuto::LengthPercentage(
css::ComputedLengthPercentage::from_percent(value),
)
}
fn fit_content(points: f32) -> css::ComputedLengthPercentageOrAuto {
css::ComputedLengthPercentageOrAuto::FitContent(Some(
css::ComputedLengthPercentage::from_points(points),
))
}
fn fit_content_percent(percent: f32) -> css::ComputedLengthPercentageOrAuto {
css::ComputedLengthPercentageOrAuto::FitContent(Some(
css::ComputedLengthPercentage::from_percent(percent),
))
}
fn intrinsic_width_constraint_result(style: &ComputedStyle, value: f32) -> f32 {
constrain_width_with_intrinsic(
style,
content_box_pt(value),
content_box_pt(60.0),
content_box_pt(120.0),
PercentageBasis::definite(content_box_pt(300.0)),
non_content_pt(0.0),
)
.points()
}
#[test]
fn intrinsic_fit_content_min_width_clamps_tentative_content_width() {
let mut style = ComputedStyle::initial();
style.box_values.min_width = fit_content(100.0);
assert_eq!(intrinsic_width_constraint_result(&style, 10.0), 100.0);
}
#[test]
fn intrinsic_fit_content_max_width_clamps_tentative_content_width() {
let mut style = ComputedStyle::initial();
style.box_values.max_width = fit_content(100.0);
assert_eq!(intrinsic_width_constraint_result(&style, 150.0), 100.0);
}
#[test]
fn intrinsic_min_and_max_content_constraints_clamp_content_width() {
let mut min_style = ComputedStyle::initial();
min_style.box_values.min_width = css::ComputedLengthPercentageOrAuto::MinContent;
let mut max_style = ComputedStyle::initial();
max_style.box_values.max_width = css::ComputedLengthPercentageOrAuto::MaxContent;
assert_eq!(intrinsic_width_constraint_result(&min_style, 10.0), 60.0);
assert_eq!(intrinsic_width_constraint_result(&max_style, 150.0), 120.0);
}
#[test]
fn intrinsic_width_constraints_convert_border_box_limits_to_content_box() {
let mut style = ComputedStyle::initial();
style.box_sizing = BoxSizing::BorderBox;
style.box_values.min_width = fit_content(100.0);
let constrained = constrain_width_with_intrinsic(
&style,
content_box_pt(10.0),
content_box_pt(60.0),
content_box_pt(120.0),
PercentageBasis::definite(content_box_pt(300.0)),
non_content_pt(20.0),
);
assert_eq!(constrained.points(), 80.0);
}
#[test]
fn non_replaced_intrinsic_width_uses_fit_content_length_preferred_size() {
let mut style = ComputedStyle::initial();
style.box_values.width = fit_content(100.0);
let contributions = non_replaced_intrinsic_width_contributions(
&style,
content_box_pt(60.0),
content_box_pt(120.0),
non_content_pt(0.0),
);
assert_eq!(contributions.0.points(), 100.0);
assert_eq!(contributions.1.points(), 100.0);
}
#[test]
fn non_replaced_intrinsic_width_treats_fit_content_percentage_as_auto() {
let mut style = ComputedStyle::initial();
style.box_values.width = fit_content_percent(0.5);
let contributions = non_replaced_intrinsic_width_contributions(
&style,
content_box_pt(100.0),
content_box_pt(200.0),
non_content_pt(0.0),
);
assert_eq!(contributions.0.points(), 100.0);
assert_eq!(contributions.1.points(), 200.0);
}
#[test]
fn non_replaced_intrinsic_width_converts_border_box_preferred_size() {
let mut style = ComputedStyle::initial();
style.box_sizing = BoxSizing::BorderBox;
style.box_values.width = length_auto(100.0);
let contributions = non_replaced_intrinsic_width_contributions(
&style,
content_box_pt(60.0),
content_box_pt(120.0),
non_content_pt(20.0),
);
assert_eq!(contributions.0.points(), 80.0);
assert_eq!(contributions.1.points(), 80.0);
}
#[test]
fn non_replaced_intrinsic_width_preserves_min_and_cyclic_max_constraints() {
let mut style = ComputedStyle::initial();
style.box_values.min_width = percent_auto(0.5);
style.box_values.max_width = fit_content_percent(0.5);
let contributions = non_replaced_intrinsic_width_contributions(
&style,
content_box_pt(20.0),
content_box_pt(120.0),
non_content_pt(0.0),
);
assert_eq!(contributions.0.points(), 20.0);
assert_eq!(contributions.1.points(), 120.0);
}
#[test]
fn cyclic_min_height_keeps_the_fixed_calc_component() {
let mut style = ComputedStyle::initial();
style.box_values.min_height = css::ComputedLengthPercentageOrAuto::LengthPercentage(
css::ComputedLengthPercentage::from_affine(layout_pt(18.75), 0.5, true),
);
let used = used_min_height(&style, PercentageBasis::<ContentBoxLength>::indefinite())
.expect("a fixed calc component remains a used min-height");
assert_eq!(used.points(), 18.75);
}
#[test]
fn content_sized_context_uses_initial_preferred_and_maximum_values() {
let mut style = ComputedStyle::initial();
let cyclic_calc = css::ComputedLengthPercentageOrAuto::LengthPercentage(
css::ComputedLengthPercentage::from_affine(layout_pt(10.0), 0.5, true),
);
style
.box_values
.height
.replace_with_used(cyclic_calc.clone());
style.box_values.max_height = percent(1.0);
style.box_values.min_height = cyclic_calc;
let content_sized = DescendantBlockPercentageContext::ContentSized;
assert!(
used_non_replaced_content_box_height_or_auto(
&style,
content_sized,
non_content_pt(0.0),
)
.is_none()
);
assert!(used_non_replaced_max_height(&style, content_sized).is_none());
assert_eq!(
used_min_height(&style, content_sized.percentage_basis())
.expect("cyclic minimum retains its length component")
.points(),
10.0,
);
}
#[test]
fn definite_context_resolves_preferred_and_maximum_percentages() {
let mut style = ComputedStyle::initial();
style.box_values.height.replace_with_used(
css::ComputedLengthPercentageOrAuto::LengthPercentage(
css::ComputedLengthPercentage::from_affine(layout_pt(10.0), 0.5, true),
),
);
style.box_values.max_height = percent(1.0);
let context = DescendantBlockPercentageContext::definite(
content_box_pt(200.0),
BlockSizeBasisSource::ContainingBlock,
);
assert_eq!(
used_non_replaced_content_box_height_or_auto(&style, context, non_content_pt(0.0))
.expect("a definite basis resolves the preferred size")
.points(),
110.0,
);
assert_eq!(
used_non_replaced_max_height(&style, context)
.expect("a definite basis resolves the maximum")
.points(),
200.0,
);
}
#[test]
fn typed_constraint_entry_points_preserve_content_box_lengths() {
let style = ComputedStyle::initial();
let width: ContentBoxLength = constrain_content_width(
&style,
content_box_pt(42.0),
PercentageBasis::definite(layout_pt(100.0)),
);
let height: ContentBoxLength = constrain_content_height(
&style,
content_box_pt(24.0),
PercentageBasis::definite(layout_pt(100.0)),
);
assert_eq!(width.points(), 42.0);
assert_eq!(height.points(), 24.0);
}
fn length(points: f32) -> css::ComputedLengthPercentageOrAuto {
css::ComputedLengthPercentageOrAuto::LengthPercentage(
css::ComputedLengthPercentage::from_points(points),
)
}
fn percent(percent: f32) -> css::ComputedLengthPercentageOrAuto {
css::ComputedLengthPercentageOrAuto::LengthPercentage(
css::ComputedLengthPercentage::from_percent(percent),
)
}
#[test]
fn stretch_fit_content_size_is_non_negative_after_borders() {
let non_content = 200.0;
let content = stretch_fit_content_box_size(
layout_pt(0.0),
layout_pt(0.0),
non_content_pt(non_content),
)
.points();
assert_eq!(content, 0.0);
assert_eq!(content + non_content, 200.0);
}
#[test]
fn used_content_box_size_keeps_content_box_specified_size() {
let content = used_content_box_size(
length(120.0),
BoxSizing::ContentBox,
PercentageBasis::definite(content_box_pt(300.0)),
non_content_pt(40.0),
)
.expect("content-box length should resolve");
assert_eq!(content.points(), 120.0);
}
#[test]
fn used_content_box_size_subtracts_border_box_non_content_and_clamps() {
let content = used_content_box_size(
length(100.0),
BoxSizing::BorderBox,
PercentageBasis::definite(content_box_pt(300.0)),
non_content_pt(150.0),
)
.expect("border-box length should resolve");
assert_eq!(content.points(), 0.0);
}
#[test]
fn stretch_fit_content_box_size_returns_typed_non_negative_content() {
let content =
stretch_fit_content_box_size(layout_pt(100.0), layout_pt(30.0), non_content_pt(120.0));
assert_eq!(content.points(), 0.0);
}
#[test]
fn used_content_box_size_indefinite_basis_resolves_lengths_not_percentages() {
let length_content = used_content_box_size_with_basis(
length(42.0),
BoxSizing::ContentBox,
PercentageBasis::<ContentBoxLength>::indefinite(),
non_content_pt(10.0),
)
.expect("length-only value should resolve without a basis");
let percentage_content = used_content_box_size_with_basis(
percent(0.5),
BoxSizing::ContentBox,
PercentageBasis::<ContentBoxLength>::indefinite(),
non_content_pt(10.0),
);
assert_eq!(length_content.points(), 42.0);
assert!(percentage_content.is_none());
}
#[test]
fn resolved_aspect_ratio_distinguishes_content_and_border_box_with_asymmetric_padding() {
let content_box = ResolvedAspectRatio::new(
2.0,
AspectRatioCalculationBox::ContentBox,
non_content_pt(40.0),
non_content_pt(10.0),
)
.unwrap();
let border_box = ResolvedAspectRatio::new(
2.0,
AspectRatioCalculationBox::BorderBox,
non_content_pt(40.0),
non_content_pt(10.0),
)
.unwrap();
assert_eq!(
content_box
.height_from_width(content_box_pt(100.0))
.points(),
50.0
);
assert_eq!(
border_box.height_from_width(content_box_pt(100.0)).points(),
60.0
);
assert_eq!(
content_box.width_from_height(content_box_pt(50.0)).points(),
100.0
);
assert_eq!(
border_box.width_from_height(content_box_pt(50.0)).points(),
80.0
);
}
#[test]
fn aspect_ratio_constraints_transfer_minimums_and_maximums_in_both_directions() {
let ratio = ResolvedAspectRatio::new(
2.0,
AspectRatioCalculationBox::ContentBox,
non_content_pt(0.0),
non_content_pt(0.0),
)
.unwrap();
let resolved = ResolvedAspectRatioConstraints::resolve(
ratio,
AspectRatioAxisConstraints {
minimum: Some(content_box_pt(80.0)),
maximum: Some(content_box_pt(240.0)),
..Default::default()
},
AspectRatioAxisConstraints::default(),
);
assert_eq!(resolved.height.minimum.unwrap().points(), 40.0);
assert_eq!(resolved.height.maximum.unwrap().points(), 120.0);
let reverse = ResolvedAspectRatioConstraints::resolve(
ratio,
AspectRatioAxisConstraints::default(),
AspectRatioAxisConstraints {
minimum: Some(content_box_pt(30.0)),
maximum: Some(content_box_pt(90.0)),
..Default::default()
},
);
assert_eq!(reverse.width.minimum.unwrap().points(), 60.0);
assert_eq!(reverse.width.maximum.unwrap().points(), 180.0);
}
#[test]
fn aspect_ratio_constraints_do_not_replace_a_larger_content_minimum() {
let ratio = ResolvedAspectRatio::new(
2.0,
AspectRatioCalculationBox::ContentBox,
non_content_pt(0.0),
non_content_pt(0.0),
)
.unwrap();
let resolved = ResolvedAspectRatioConstraints::resolve(
ratio,
AspectRatioAxisConstraints {
minimum: Some(content_box_pt(100.0)),
..Default::default()
},
AspectRatioAxisConstraints {
minimum: Some(content_box_pt(20.0)),
..Default::default()
},
);
assert_eq!(resolved.width.minimum.unwrap().points(), 100.0);
assert_eq!(
resolved.constrain_width(content_box_pt(50.0)).points(),
100.0
);
}
}