mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Introduce #[css(function)] for #[derive(ToCss)]
Any variant with this attribute gets serialised as a CSS function, using the variant name as the function name.
This commit is contained in:
parent
fd1ab75af9
commit
43a5257a0c
7 changed files with 66 additions and 66 deletions
|
@ -5,15 +5,13 @@
|
|||
//! Generic types for legacy Gecko-only properties that should probably be
|
||||
//! unshipped at some point in the future.
|
||||
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
|
||||
/// A generic value for scroll snap points.
|
||||
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
|
||||
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue, ToCss)]
|
||||
pub enum ScrollSnapPoint<LengthOrPercentage> {
|
||||
/// `none`
|
||||
None,
|
||||
/// `repeat(<length-or-percentage>)`
|
||||
#[css(function)]
|
||||
Repeat(LengthOrPercentage)
|
||||
}
|
||||
|
||||
|
@ -33,22 +31,3 @@ impl<L> ScrollSnapPoint<L> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<L> ToCss for ScrollSnapPoint<L>
|
||||
where
|
||||
L: ToCss,
|
||||
{
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where
|
||||
W: fmt::Write,
|
||||
{
|
||||
match *self {
|
||||
ScrollSnapPoint::None => dest.write_str("none"),
|
||||
ScrollSnapPoint::Repeat(ref length) => {
|
||||
dest.write_str("repeat(")?;
|
||||
length.to_css(dest)?;
|
||||
dest.write_str(")")
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,13 +54,14 @@ impl SymbolsType {
|
|||
///
|
||||
/// Since wherever <counter-style> is used, 'none' is a valid value as
|
||||
/// well, we combine them into one type to make code simpler.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, ToCss)]
|
||||
pub enum CounterStyleOrNone {
|
||||
/// none
|
||||
None_,
|
||||
/// <counter-style-name>
|
||||
/// `none`
|
||||
None,
|
||||
/// `<counter-style-name>`
|
||||
Name(CustomIdent),
|
||||
/// symbols()
|
||||
/// `symbols()`
|
||||
#[css(function)]
|
||||
Symbols(SymbolsType, Symbols),
|
||||
}
|
||||
|
||||
|
@ -84,7 +85,7 @@ impl Parse for CounterStyleOrNone {
|
|||
return Ok(CounterStyleOrNone::Name(name));
|
||||
}
|
||||
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
return Ok(CounterStyleOrNone::None_);
|
||||
return Ok(CounterStyleOrNone::None);
|
||||
}
|
||||
if input.try(|i| i.expect_function_matching("symbols")).is_ok() {
|
||||
return input.parse_nested_block(|input| {
|
||||
|
@ -108,23 +109,6 @@ impl Parse for CounterStyleOrNone {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToCss for CounterStyleOrNone {
|
||||
#[inline]
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match self {
|
||||
&CounterStyleOrNone::None_ => dest.write_str("none"),
|
||||
&CounterStyleOrNone::Name(ref name) => name.to_css(dest),
|
||||
&CounterStyleOrNone::Symbols(ref symbols_type, ref symbols) => {
|
||||
dest.write_str("symbols(")?;
|
||||
symbols_type.to_css(dest)?;
|
||||
dest.write_str(" ")?;
|
||||
symbols.to_css(dest)?;
|
||||
dest.write_str(")")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A settings tag, defined by a four-character tag and a setting value
|
||||
///
|
||||
/// For font-feature-settings, this is a tag and an integer,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue