diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
commit | a90a5cba08fdf6c0ceb95101c275108a152a3aed (patch) | |
tree | 532507288f3defd7f4dcf1af49698bcb76034855 /servo/components/style/values/computed | |
parent | Adding debian version 126.0.1-1. (diff) | |
download | firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.tar.xz firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'servo/components/style/values/computed')
-rw-r--r-- | servo/components/style/values/computed/length_percentage.rs | 41 | ||||
-rw-r--r-- | servo/components/style/values/computed/mod.rs | 19 |
2 files changed, 45 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") }, }); diff --git a/servo/components/style/values/computed/mod.rs b/servo/components/style/values/computed/mod.rs index 85aadb401f..ca32408a79 100644 --- a/servo/components/style/values/computed/mod.rs +++ b/servo/components/style/values/computed/mod.rs @@ -649,6 +649,25 @@ where } } +impl<T> ToComputedValue for thin_vec::ThinVec<T> +where + T: ToComputedValue, +{ + type ComputedValue = thin_vec::ThinVec<<T as ToComputedValue>::ComputedValue>; + + #[inline] + fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { + self.iter() + .map(|item| item.to_computed_value(context)) + .collect() + } + + #[inline] + fn from_computed_value(computed: &Self::ComputedValue) -> Self { + computed.iter().map(T::from_computed_value).collect() + } +} + // NOTE(emilio): This is implementable more generically, but it's unlikely // what you want there, as it forces you to have an extra allocation. // |