summaryrefslogtreecommitdiffstats
path: root/servo/components/style/values/computed/length_percentage.rs
diff options
context:
space:
mode:
Diffstat (limited to 'servo/components/style/values/computed/length_percentage.rs')
-rw-r--r--servo/components/style/values/computed/length_percentage.rs41
1 files changed, 26 insertions, 15 deletions
diff --git a/servo/components/style/values/computed/length_percentage.rs b/servo/components/style/values/computed/length_percentage.rs
index c448025dd1..f5f3303141 100644
--- a/servo/components/style/values/computed/length_percentage.rs
+++ b/servo/components/style/values/computed/length_percentage.rs
@@ -680,12 +680,12 @@ impl calc::CalcNodeLeaf for CalcLengthPercentageLeaf {
}
}
- fn unitless_value(&self) -> f32 {
- match *self {
+ fn unitless_value(&self) -> Option<f32> {
+ Some(match *self {
Self::Length(ref l) => l.px(),
Self::Percentage(ref p) => p.0,
Self::Number(n) => n,
- }
+ })
}
fn new_number(value: f32) -> Self {
@@ -709,9 +709,18 @@ impl calc::CalcNodeLeaf for CalcLengthPercentageLeaf {
return None;
}
- let self_negative = self.is_negative();
- if self_negative != other.is_negative() {
- return Some(if self_negative { std::cmp::Ordering::Less } else { std::cmp::Ordering::Greater });
+ let Ok(self_negative) = self.is_negative() else {
+ return None;
+ };
+ let Ok(other_negative) = other.is_negative() else {
+ return None;
+ };
+ if self_negative != other_negative {
+ return Some(if self_negative {
+ std::cmp::Ordering::Less
+ } else {
+ std::cmp::Ordering::Greater
+ });
}
match (self, other) {
@@ -774,15 +783,17 @@ impl calc::CalcNodeLeaf for CalcLengthPercentageLeaf {
} else {
// The right side is not a number, so the result should be in the units of the right
// side.
- other.map(|v| v * *left);
- std::mem::swap(self, other);
- true
+ if other.map(|v| v * *left).is_ok() {
+ std::mem::swap(self, other);
+ true
+ } else {
+ false
+ }
}
} else if let Self::Number(ref right) = *other {
// The left side is not a number, but the right side is, so the result is the left
// side unit.
- self.map(|v| v * *right);
- true
+ self.map(|v| v * *right).is_ok()
} else {
// Neither side is a number, so a product is not possible.
false
@@ -814,8 +825,8 @@ impl calc::CalcNodeLeaf for CalcLengthPercentageLeaf {
})
}
- fn map(&mut self, mut op: impl FnMut(f32) -> f32) {
- match self {
+ fn map(&mut self, mut op: impl FnMut(f32) -> f32) -> Result<(), ()> {
+ Ok(match self {
Self::Length(value) => {
*value = Length::new(op(value.px()));
},
@@ -825,7 +836,7 @@ impl calc::CalcNodeLeaf for CalcLengthPercentageLeaf {
Self::Number(value) => {
*value = op(*value);
},
- }
+ })
}
fn simplify(&mut self) {}
@@ -921,7 +932,7 @@ impl specified::CalcLengthPercentage {
}
}),
Leaf::Number(n) => CalcLengthPercentageLeaf::Number(n),
- Leaf::Angle(..) | Leaf::Time(..) | Leaf::Resolution(..) => {
+ Leaf::Angle(..) | Leaf::Time(..) | Leaf::Resolution(..) | Leaf::ColorComponent(..) => {
unreachable!("Shouldn't have parsed")
},
});