зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1882754 - Remove unused DefaultColorParser and serde code r=layout-reviewers,emilio
This code was added when we moved the color code from cssparser into style. We don't need the default implementations. Differential Revision: https://phabricator.services.mozilla.com/D202209
This commit is contained in:
Родитель
0bb313c8eb
Коммит
34929d2ccf
|
@ -539,3 +539,73 @@ 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(),
|
||||
};
|
||||
cssparser::ToCss::to_css(&color_function, dest)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,6 @@ use cssparser::color::{
|
|||
PredefinedColorSpace, OPAQUE,
|
||||
};
|
||||
use cssparser::{match_ignore_ascii_case, CowRcStr, ParseError, Parser, ToCss, Token};
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use std::f32::consts::PI;
|
||||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
|
@ -494,27 +492,6 @@ impl RgbaLegacy {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl Serialize for RgbaLegacy {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
(self.red, self.green, self.blue, self.alpha).serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl<'de> Deserialize<'de> for RgbaLegacy {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let (r, g, b, a) = Deserialize::deserialize(deserializer)?;
|
||||
Ok(RgbaLegacy::new(r, g, b, a))
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for RgbaLegacy {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where
|
||||
|
@ -582,27 +559,6 @@ impl ToCss for Hsl {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl Serialize for Hsl {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
(self.hue, self.saturation, self.lightness, self.alpha).serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl<'de> Deserialize<'de> for Hsl {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let (lightness, a, b, alpha) = Deserialize::deserialize(deserializer)?;
|
||||
Ok(Self::new(lightness, a, b, alpha))
|
||||
}
|
||||
}
|
||||
|
||||
/// Color specified by hue, whiteness and blackness components.
|
||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||
pub struct Hwb {
|
||||
|
@ -649,27 +605,6 @@ impl ToCss for Hwb {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl Serialize for Hwb {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
(self.hue, self.whiteness, self.blackness, self.alpha).serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl<'de> Deserialize<'de> for Hwb {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let (lightness, whiteness, blackness, alpha) = Deserialize::deserialize(deserializer)?;
|
||||
Ok(Self::new(lightness, whiteness, blackness, alpha))
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: LAB and OKLAB is not declared inside the [impl_lab_like] macro,
|
||||
// because it causes cbindgen to ignore them.
|
||||
|
||||
|
@ -718,27 +653,6 @@ macro_rules! impl_lab_like {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl Serialize for $cls {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
(self.lightness, self.a, self.b, self.alpha).serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl<'de> Deserialize<'de> for $cls {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let (lightness, a, b, alpha) = Deserialize::deserialize(deserializer)?;
|
||||
Ok(Self::new(lightness, a, b, alpha))
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for $cls {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where
|
||||
|
@ -809,27 +723,6 @@ macro_rules! impl_lch_like {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl Serialize for $cls {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
(self.lightness, self.chroma, self.hue, self.alpha).serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl<'de> Deserialize<'de> for $cls {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let (lightness, chroma, hue, alpha) = Deserialize::deserialize(deserializer)?;
|
||||
Ok(Self::new(lightness, chroma, hue, alpha))
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for $cls {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where
|
||||
|
@ -908,60 +801,6 @@ impl ToCss for ColorFunction {
|
|||
}
|
||||
}
|
||||
|
||||
/// Describes one of the value <color> values according to the CSS
|
||||
/// specification.
|
||||
///
|
||||
/// Most components are `Option<_>`, so when the value is `None`, that component
|
||||
/// serializes to the "none" keyword.
|
||||
///
|
||||
/// <https://drafts.csswg.org/css-color-4/#color-type>
|
||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||
pub enum Color {
|
||||
/// The 'currentcolor' keyword.
|
||||
CurrentColor,
|
||||
/// Specify sRGB colors directly by their red/green/blue/alpha chanels.
|
||||
Rgba(RgbaLegacy),
|
||||
/// Specifies a color in sRGB using hue, saturation and lightness components.
|
||||
Hsl(Hsl),
|
||||
/// Specifies a color in sRGB using hue, whiteness and blackness components.
|
||||
Hwb(Hwb),
|
||||
/// Specifies a CIELAB color by CIE Lightness and its a- and b-axis hue
|
||||
/// coordinates (red/green-ness, and yellow/blue-ness) using the CIE LAB
|
||||
/// rectangular coordinate model.
|
||||
Lab(Lab),
|
||||
/// Specifies a CIELAB color by CIE Lightness, Chroma, and hue using the
|
||||
/// CIE LCH cylindrical coordinate model.
|
||||
Lch(Lch),
|
||||
/// Specifies an Oklab color by Oklab Lightness and its a- and b-axis hue
|
||||
/// coordinates (red/green-ness, and yellow/blue-ness) using the Oklab
|
||||
/// rectangular coordinate model.
|
||||
Oklab(Oklab),
|
||||
/// Specifies an Oklab color by Oklab Lightness, Chroma, and hue using
|
||||
/// the OKLCH cylindrical coordinate model.
|
||||
Oklch(Oklch),
|
||||
/// Specifies a color in a predefined color space.
|
||||
ColorFunction(ColorFunction),
|
||||
}
|
||||
|
||||
impl ToCss for Color {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where
|
||||
W: fmt::Write,
|
||||
{
|
||||
match *self {
|
||||
Color::CurrentColor => dest.write_str("currentcolor"),
|
||||
Color::Rgba(rgba) => rgba.to_css(dest),
|
||||
Color::Hsl(hsl) => hsl.to_css(dest),
|
||||
Color::Hwb(hwb) => hwb.to_css(dest),
|
||||
Color::Lab(lab) => lab.to_css(dest),
|
||||
Color::Lch(lch) => lch.to_css(dest),
|
||||
Color::Oklab(lab) => lab.to_css(dest),
|
||||
Color::Oklch(lch) => lch.to_css(dest),
|
||||
Color::ColorFunction(color_function) => color_function.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Either a number or a percentage.
|
||||
pub enum NumberOrPercentage {
|
||||
/// `<number>`.
|
||||
|
@ -1085,23 +924,6 @@ pub trait ColorParser<'i> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Default implementation of a [`ColorParser`]
|
||||
pub struct DefaultColorParser;
|
||||
|
||||
impl<'i> ColorParser<'i> for DefaultColorParser {
|
||||
type Output = Color;
|
||||
type Error = ();
|
||||
}
|
||||
|
||||
impl Color {
|
||||
/// Parse a <color> value, per CSS Color Module Level 3.
|
||||
///
|
||||
/// FIXME(#2) Deprecated CSS2 System Colors are not supported yet.
|
||||
pub fn parse<'i>(input: &mut Parser<'i, '_>) -> Result<Color, ParseError<'i, ()>> {
|
||||
parse_color_with(&DefaultColorParser, input)
|
||||
}
|
||||
}
|
||||
|
||||
/// This trait is used by the [`ColorParser`] to construct colors of any type.
|
||||
pub trait FromParsedColor {
|
||||
/// Construct a new color from the CSS `currentcolor` keyword.
|
||||
|
@ -1163,84 +985,3 @@ pub trait FromParsedColor {
|
|||
alpha: Option<f32>,
|
||||
) -> Self;
|
||||
}
|
||||
|
||||
impl FromParsedColor for Color {
|
||||
#[inline]
|
||||
fn from_current_color() -> Self {
|
||||
Color::CurrentColor
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_rgba(red: u8, green: u8, blue: u8, alpha: f32) -> Self {
|
||||
Color::Rgba(RgbaLegacy::new(red, green, blue, alpha))
|
||||
}
|
||||
|
||||
fn from_hsl(
|
||||
hue: Option<f32>,
|
||||
saturation: Option<f32>,
|
||||
lightness: Option<f32>,
|
||||
alpha: Option<f32>,
|
||||
) -> Self {
|
||||
Color::Hsl(Hsl::new(hue, saturation, lightness, alpha))
|
||||
}
|
||||
|
||||
fn from_hwb(
|
||||
hue: Option<f32>,
|
||||
blackness: Option<f32>,
|
||||
whiteness: Option<f32>,
|
||||
alpha: Option<f32>,
|
||||
) -> Self {
|
||||
Color::Hwb(Hwb::new(hue, blackness, whiteness, alpha))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_lab(
|
||||
lightness: Option<f32>,
|
||||
a: Option<f32>,
|
||||
b: Option<f32>,
|
||||
alpha: Option<f32>,
|
||||
) -> Self {
|
||||
Color::Lab(Lab::new(lightness, a, b, alpha))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_lch(
|
||||
lightness: Option<f32>,
|
||||
chroma: Option<f32>,
|
||||
hue: Option<f32>,
|
||||
alpha: Option<f32>,
|
||||
) -> Self {
|
||||
Color::Lch(Lch::new(lightness, chroma, hue, alpha))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_oklab(
|
||||
lightness: Option<f32>,
|
||||
a: Option<f32>,
|
||||
b: Option<f32>,
|
||||
alpha: Option<f32>,
|
||||
) -> Self {
|
||||
Color::Oklab(Oklab::new(lightness, a, b, alpha))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_oklch(
|
||||
lightness: Option<f32>,
|
||||
chroma: Option<f32>,
|
||||
hue: Option<f32>,
|
||||
alpha: Option<f32>,
|
||||
) -> Self {
|
||||
Color::Oklch(Oklch::new(lightness, chroma, hue, alpha))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_color_function(
|
||||
color_space: PredefinedColorSpace,
|
||||
c1: Option<f32>,
|
||||
c2: Option<f32>,
|
||||
c3: Option<f32>,
|
||||
alpha: Option<f32>,
|
||||
) -> Self {
|
||||
Color::ColorFunction(ColorFunction::new(color_space, c1, c2, c3, alpha))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,14 +4,13 @@
|
|||
|
||||
//! Computed color values.
|
||||
|
||||
use crate::color::parsing::Color as CSSParserColor;
|
||||
use crate::color::AbsoluteColor;
|
||||
use crate::values::animated::ToAnimatedZero;
|
||||
use crate::values::computed::percentage::Percentage;
|
||||
use crate::values::generics::color::{
|
||||
GenericCaretColor, GenericColor, GenericColorMix, GenericColorOrAuto,
|
||||
};
|
||||
use std::fmt;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
|
||||
pub use crate::values::specified::color::{ColorScheme, ForcedColorAdjust, PrintColorAdjust};
|
||||
|
@ -32,7 +31,7 @@ impl ToCss for Color {
|
|||
{
|
||||
match *self {
|
||||
Self::Absolute(ref c) => c.to_css(dest),
|
||||
Self::CurrentColor => cssparser::ToCss::to_css(&CSSParserColor::CurrentColor, dest),
|
||||
Self::CurrentColor => dest.write_str("currentcolor"),
|
||||
Self::ColorMix(ref m) => m.to_css(dest),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,7 @@
|
|||
//! Specified color values.
|
||||
|
||||
use super::AllowQuirks;
|
||||
use crate::color::parsing::{
|
||||
self, AngleOrNumber, Color as CSSParserColor, FromParsedColor, NumberOrPercentage,
|
||||
};
|
||||
use crate::color::parsing::{self, AngleOrNumber, FromParsedColor, NumberOrPercentage};
|
||||
use crate::color::{mix::ColorInterpolationMethod, AbsoluteColor, ColorSpace};
|
||||
use crate::media_queries::Device;
|
||||
use crate::parser::{Parse, ParserContext};
|
||||
|
@ -700,7 +698,7 @@ impl ToCss for Color {
|
|||
W: Write,
|
||||
{
|
||||
match *self {
|
||||
Color::CurrentColor => cssparser::ToCss::to_css(&CSSParserColor::CurrentColor, dest),
|
||||
Color::CurrentColor => dest.write_str("currentcolor"),
|
||||
Color::Absolute(ref absolute) => absolute.to_css(dest),
|
||||
Color::ColorMix(ref mix) => mix.to_css(dest),
|
||||
Color::LightDark(ref ld) => ld.to_css(dest),
|
||||
|
|
Загрузка…
Ссылка в новой задаче