mirror of
https://github.com/servo/servo.git
synced 2025-07-03 05:23:38 +01:00
Add RepeatCount enum for handling the first component of repeat()
This commit is contained in:
parent
efe1a5d256
commit
d3e394c68a
1 changed files with 46 additions and 1 deletions
|
@ -11,7 +11,7 @@ use std::fmt;
|
|||
use style_traits::ToCss;
|
||||
use values::{CSSFloat, CustomIdent, HasViewportPercentage};
|
||||
use values::computed::{ComputedValueAsSpecified, Context, ToComputedValue};
|
||||
use values::specified::LengthOrPercentage;
|
||||
use values::specified::{Integer, LengthOrPercentage};
|
||||
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
|
@ -363,3 +363,48 @@ pub fn parse_line_names(input: &mut Parser) -> Result<Vec<String>, ()> {
|
|||
Ok(values)
|
||||
})
|
||||
}
|
||||
|
||||
/// The initial argument of the `repeat` function.
|
||||
///
|
||||
/// https://drafts.csswg.org/css-grid/#typedef-track-repeat
|
||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum RepeatCount {
|
||||
/// A positive integer. This is allowed only for `<track-repeat>` and `<fixed-repeat>`
|
||||
Number(Integer),
|
||||
/// An `<auto-fill>` keyword allowed only for `<auto-repeat>`
|
||||
AutoFill,
|
||||
/// An `<auto-fit>` keyword allowed only for `<auto-repeat>`
|
||||
AutoFit,
|
||||
}
|
||||
|
||||
impl Parse for RepeatCount {
|
||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
if let Ok(i) = input.try(|i| Integer::parse(context, i)) {
|
||||
if i.value > 0 {
|
||||
Ok(RepeatCount::Number(i))
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
} else {
|
||||
match_ignore_ascii_case! { &input.expect_ident()?,
|
||||
"auto-fill" => Ok(RepeatCount::AutoFill),
|
||||
"auto-fit" => Ok(RepeatCount::AutoFit),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for RepeatCount {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
RepeatCount::Number(ref c) => c.to_css(dest),
|
||||
RepeatCount::AutoFill => dest.write_str("auto-fill"),
|
||||
RepeatCount::AutoFit => dest.write_str("auto-fit"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ComputedValueAsSpecified for RepeatCount {}
|
||||
no_viewport_percentage!(RepeatCount);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue