mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Add to_computed method for CalcLengthOrPercentage
* Add to_computed method to calculate `calc()` value with parent size, if parent container size is `None`, the result will be `None`. * Add from_option method for `MaybeAuto`, to construct from `Option<Au>`. * Update some test case.
This commit is contained in:
parent
5062c4b117
commit
22f99c71b9
8 changed files with 47 additions and 32 deletions
|
@ -408,12 +408,20 @@ impl MaybeAuto {
|
|||
MaybeAuto::Specified(containing_length.scale_by(percent))
|
||||
}
|
||||
LengthOrPercentageOrAuto::Calc(calc) => {
|
||||
MaybeAuto::Specified(calc.length() + containing_length.scale_by(calc.percentage()))
|
||||
MaybeAuto::from_option(calc.to_computed(Some(containing_length)))
|
||||
}
|
||||
LengthOrPercentageOrAuto::Length(length) => MaybeAuto::Specified(length)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_option(au: Option<Au>) -> MaybeAuto {
|
||||
match au {
|
||||
Some(l) => MaybeAuto::Specified(l),
|
||||
_ => MaybeAuto::Auto,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn specified_or_default(&self, default: Au) -> Au {
|
||||
match *self {
|
||||
|
@ -455,8 +463,7 @@ pub fn specified_or_none(length: LengthOrPercentageOrNone, containing_length: Au
|
|||
match length {
|
||||
LengthOrPercentageOrNone::None => None,
|
||||
LengthOrPercentageOrNone::Percentage(percent) => Some(containing_length.scale_by(percent)),
|
||||
LengthOrPercentageOrNone::Calc(calc) =>
|
||||
Some(containing_length.scale_by(calc.percentage()) + calc.length()),
|
||||
LengthOrPercentageOrNone::Calc(calc) => calc.to_computed(Some(containing_length)),
|
||||
LengthOrPercentageOrNone::Length(length) => Some(length),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue