aboutsummaryrefslogtreecommitdiffstats
path: root/components/style/values/generics/color.rs
diff options
context:
space:
mode:
authorTiaan Louw <tlouw@mozilla.com>2023-05-10 13:39:42 +0000
committerMartin Robinson <mrobinson@igalia.com>2023-11-24 08:57:14 +0100
commit18c701e6b58a6a431cd808958d993e1a47e4b4b3 (patch)
tree29e5e28b0e3bb1d76026d2c66f7d202853bc2431 /components/style/values/generics/color.rs
parentf967d3c4fd68134c72e75dca2c2941ec402412d5 (diff)
downloadservo-18c701e6b58a6a431cd808958d993e1a47e4b4b3.tar.gz
servo-18c701e6b58a6a431cd808958d993e1a47e4b4b3.zip
style: Hardening color checks
Avoid trying to resolve a currentcolor when a foreground color is not available. Differential Revision: https://phabricator.services.mozilla.com/D177368
Diffstat (limited to 'components/style/values/generics/color.rs')
-rw-r--r--components/style/values/generics/color.rs37
1 files changed, 5 insertions, 32 deletions
diff --git a/components/style/values/generics/color.rs b/components/style/values/generics/color.rs
index 784f45cddad..d143e9d3c86 100644
--- a/components/style/values/generics/color.rs
+++ b/components/style/values/generics/color.rs
@@ -6,7 +6,6 @@
use crate::color::mix::ColorInterpolationMethod;
use crate::color::AbsoluteColor;
-use crate::values::animated::ToAnimatedValue;
use crate::values::specified::percentage::ToPercentage;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss};
@@ -94,23 +93,21 @@ impl<Color: ToCss, Percentage: ToCss + ToPercentage> ToCss for ColorMix<Color, P
impl<Percentage> ColorMix<GenericColor<Percentage>, Percentage> {
/// Mix the colors so that we get a single color. If any of the 2 colors are
/// not mixable (perhaps not absolute?), then return None.
- fn mix_into_absolute(&self) -> Option<AbsoluteColor>
+ pub fn mix_to_absolute(&self) -> Option<AbsoluteColor>
where
Percentage: ToPercentage,
{
- let left = self.left.as_absolute()?.to_animated_value();
- let right = self.right.as_absolute()?.to_animated_value();
+ let left = self.left.as_absolute()?;
+ let right = self.right.as_absolute()?;
- let mixed = crate::color::mix::mix(
+ Some(crate::color::mix::mix(
self.interpolation,
&left,
self.left_percentage.to_percentage(),
&right,
self.right_percentage.to_percentage(),
self.normalize_weights,
- );
-
- Some(ToAnimatedValue::from_animated_value(mixed.into()))
+ ))
}
}
@@ -125,30 +122,6 @@ impl<Percentage> Color<Percentage> {
}
}
- /// Simplifies the color-mix()es to the extent possible given a current
- /// color (or not).
- pub fn simplify(&mut self, current_color: Option<&AbsoluteColor>)
- where
- Percentage: ToPercentage,
- {
- match *self {
- Self::Absolute(..) => {},
- Self::CurrentColor => {
- if let Some(c) = current_color {
- *self = Self::Absolute(c.clone());
- }
- },
- Self::ColorMix(ref mut mix) => {
- mix.left.simplify(current_color);
- mix.right.simplify(current_color);
-
- if let Some(mix) = mix.mix_into_absolute() {
- *self = Self::Absolute(mix);
- }
- },
- }
- }
-
/// Returns a color value representing currentcolor.
pub fn currentcolor() -> Self {
Self::CurrentColor