mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +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
|
@ -76,6 +76,16 @@ impl CalcLengthOrPercentage {
|
|||
pub fn percentage(&self) -> CSSFloat {
|
||||
self.percentage.unwrap_or(0.)
|
||||
}
|
||||
|
||||
/// If there are special rules for computing percentages in a value (e.g. the height property),
|
||||
/// they apply whenever a calc() expression contains percentages.
|
||||
pub fn to_computed(&self, container_len: Option<Au>) -> Option<Au> {
|
||||
match (container_len, self.percentage) {
|
||||
(Some(len), Some(percent)) => Some(self.length + len.scale_by(percent)),
|
||||
(_, None) => Some(self.length),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LengthOrPercentage> for CalcLengthOrPercentage {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue