summaryrefslogtreecommitdiffstats
path: root/servo/components/style/color/mod.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:33 +0000
commit086c044dc34dfc0f74fbe41f4ecb402b2cd34884 (patch)
treea4f824bd33cb075dd5aa3eb5a0a94af221bbe83a /servo/components/style/color/mod.rs
parentAdding debian version 124.0.1-1. (diff)
downloadfirefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.tar.xz
firefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'servo/components/style/color/mod.rs')
-rw-r--r--servo/components/style/color/mod.rs92
1 files changed, 19 insertions, 73 deletions
diff --git a/servo/components/style/color/mod.rs b/servo/components/style/color/mod.rs
index 797a1cb00f..6f35daaa8a 100644
--- a/servo/components/style/color/mod.rs
+++ b/servo/components/style/color/mod.rs
@@ -4,14 +4,15 @@
//! Color support functions.
+pub mod component;
/// cbindgen:ignore
pub mod convert;
pub mod mix;
pub mod parsing;
+mod to_css;
+use component::ColorComponent;
use cssparser::color::PredefinedColorSpace;
-use std::fmt::{self, Write};
-use style_traits::{CssWriter, ToCss};
/// The 3 components that make up a color. (Does not include the alpha component)
#[derive(Copy, Clone, Debug, MallocSizeOf, PartialEq, ToShmem)]
@@ -260,6 +261,22 @@ impl From<Option<f32>> for ComponentDetails {
}
}
+impl From<ColorComponent<f32>> for ComponentDetails {
+ fn from(value: ColorComponent<f32>) -> Self {
+ if let ColorComponent::Value(value) = value {
+ Self {
+ value,
+ is_none: false,
+ }
+ } else {
+ Self {
+ value: 0.0,
+ is_none: true,
+ }
+ }
+ }
+}
+
impl AbsoluteColor {
/// A fully transparent color in the legacy syntax.
pub const TRANSPARENT_BLACK: Self = Self {
@@ -540,74 +557,3 @@ impl From<PredefinedColorSpace> for ColorSpace {
}
}
}
-
-impl ToCss for AbsoluteColor {
- fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
- where
- W: Write,
- {
- match self.color_space {
- ColorSpace::Srgb if self.flags.contains(ColorFlags::IS_LEGACY_SRGB) => {
- // The "none" keyword is not supported in the rgb/rgba legacy syntax.
- cssparser::ToCss::to_css(
- &parsing::RgbaLegacy::from_floats(
- self.components.0,
- self.components.1,
- self.components.2,
- self.alpha,
- ),
- dest,
- )
- },
- ColorSpace::Hsl | ColorSpace::Hwb => self.into_srgb_legacy().to_css(dest),
- ColorSpace::Lab => cssparser::ToCss::to_css(
- &parsing::Lab::new(self.c0(), self.c1(), self.c2(), self.alpha()),
- dest,
- ),
- ColorSpace::Lch => cssparser::ToCss::to_css(
- &parsing::Lch::new(self.c0(), self.c1(), self.c2(), self.alpha()),
- dest,
- ),
- ColorSpace::Oklab => cssparser::ToCss::to_css(
- &parsing::Oklab::new(self.c0(), self.c1(), self.c2(), self.alpha()),
- dest,
- ),
- ColorSpace::Oklch => cssparser::ToCss::to_css(
- &parsing::Oklch::new(self.c0(), self.c1(), self.c2(), self.alpha()),
- dest,
- ),
- _ => {
- let color_space = match self.color_space {
- ColorSpace::Srgb => {
- debug_assert!(
- !self.flags.contains(ColorFlags::IS_LEGACY_SRGB),
- "legacy srgb is not a color function"
- );
- PredefinedColorSpace::Srgb
- },
- ColorSpace::SrgbLinear => PredefinedColorSpace::SrgbLinear,
- ColorSpace::DisplayP3 => PredefinedColorSpace::DisplayP3,
- ColorSpace::A98Rgb => PredefinedColorSpace::A98Rgb,
- ColorSpace::ProphotoRgb => PredefinedColorSpace::ProphotoRgb,
- ColorSpace::Rec2020 => PredefinedColorSpace::Rec2020,
- ColorSpace::XyzD50 => PredefinedColorSpace::XyzD50,
- ColorSpace::XyzD65 => PredefinedColorSpace::XyzD65,
-
- _ => {
- unreachable!("other color spaces do not support color() syntax")
- },
- };
-
- let color_function = parsing::ColorFunction {
- color_space,
- c1: self.c0(),
- c2: self.c1(),
- c3: self.c2(),
- alpha: self.alpha(),
- };
- let color = parsing::Color::ColorFunction(color_function);
- cssparser::ToCss::to_css(&color, dest)
- },
- }
- }
-}