mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Refactor how calc() clamping is done on computed values (fixes #15296)
This commit is contained in:
parent
f935f2da01
commit
d0b9bd9c64
13 changed files with 173 additions and 154 deletions
|
@ -412,7 +412,7 @@ impl MaybeAuto {
|
|||
MaybeAuto::Specified(containing_length.scale_by(percent))
|
||||
}
|
||||
LengthOrPercentageOrAuto::Calc(calc) => {
|
||||
MaybeAuto::from_option(calc.to_computed(Some(containing_length)))
|
||||
MaybeAuto::from_option(calc.to_used_value(Some(containing_length)))
|
||||
}
|
||||
LengthOrPercentageOrAuto::Length(length) => MaybeAuto::Specified(length)
|
||||
}
|
||||
|
@ -463,24 +463,6 @@ pub fn style_length(style_length: LengthOrPercentageOrAuto,
|
|||
}
|
||||
}
|
||||
|
||||
pub fn specified_or_none(length: LengthOrPercentageOrNone, containing_length: Au) -> Option<Au> {
|
||||
match length {
|
||||
LengthOrPercentageOrNone::None => None,
|
||||
LengthOrPercentageOrNone::Percentage(percent) => Some(containing_length.scale_by(percent)),
|
||||
LengthOrPercentageOrNone::Calc(calc) => calc.to_computed(Some(containing_length)),
|
||||
LengthOrPercentageOrNone::Length(length) => Some(length),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn specified(length: LengthOrPercentage, containing_length: Au) -> Au {
|
||||
match length {
|
||||
LengthOrPercentage::Length(length) => length,
|
||||
LengthOrPercentage::Percentage(p) => containing_length.scale_by(p),
|
||||
LengthOrPercentage::Calc(calc) =>
|
||||
containing_length.scale_by(calc.percentage()) + calc.length(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Computes a border radius size against the containing size.
|
||||
///
|
||||
/// Note that percentages in `border-radius` are resolved against the relevant
|
||||
|
@ -495,8 +477,8 @@ pub fn specified_border_radius(
|
|||
-> Size2D<Au>
|
||||
{
|
||||
let generics::BorderRadiusSize(size) = radius;
|
||||
let w = specified(size.width, containing_size.width);
|
||||
let h = specified(size.height, containing_size.height);
|
||||
let w = size.width.to_used_value(containing_size.width);
|
||||
let h = size.height.to_used_value(containing_size.height);
|
||||
Size2D::new(w, h)
|
||||
}
|
||||
|
||||
|
@ -507,10 +489,10 @@ pub fn padding_from_style(style: &ServoComputedValues,
|
|||
-> LogicalMargin<Au> {
|
||||
let padding_style = style.get_padding();
|
||||
LogicalMargin::from_physical(writing_mode, SideOffsets2D::new(
|
||||
specified(padding_style.padding_top, containing_block_inline_size),
|
||||
specified(padding_style.padding_right, containing_block_inline_size),
|
||||
specified(padding_style.padding_bottom, containing_block_inline_size),
|
||||
specified(padding_style.padding_left, containing_block_inline_size)))
|
||||
padding_style.padding_top.to_used_value(containing_block_inline_size),
|
||||
padding_style.padding_right.to_used_value(containing_block_inline_size),
|
||||
padding_style.padding_bottom.to_used_value(containing_block_inline_size),
|
||||
padding_style.padding_left.to_used_value(containing_block_inline_size)))
|
||||
}
|
||||
|
||||
/// Returns the explicitly-specified margin lengths from the given style. Percentage and auto
|
||||
|
@ -559,7 +541,7 @@ impl SizeConstraint {
|
|||
max_size: LengthOrPercentageOrNone,
|
||||
border: Option<Au>) -> SizeConstraint {
|
||||
let mut min_size = match container_size {
|
||||
Some(container_size) => specified(min_size, container_size),
|
||||
Some(container_size) => min_size.to_used_value(container_size),
|
||||
None => if let LengthOrPercentage::Length(length) = min_size {
|
||||
length
|
||||
} else {
|
||||
|
@ -568,7 +550,7 @@ impl SizeConstraint {
|
|||
};
|
||||
|
||||
let mut max_size = match container_size {
|
||||
Some(container_size) => specified_or_none(max_size, container_size),
|
||||
Some(container_size) => max_size.to_used_value(container_size),
|
||||
None => if let LengthOrPercentageOrNone::Length(length) = max_size {
|
||||
Some(length)
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue