style: Move background-repeat and mask-repeat outside of mako.

This commit is contained in:
Emilio Cobos Álvarez 2017-10-24 14:30:12 +02:00
parent 326f914018
commit fd1e2c1f3f
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
8 changed files with 168 additions and 126 deletions

View file

@ -15,7 +15,10 @@ use values::specified::length::LengthOrPercentageOrAuto;
pub type BackgroundSize = GenericBackgroundSize<LengthOrPercentageOrAuto>;
impl Parse for BackgroundSize {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
if let Ok(width) = input.try(|i| LengthOrPercentageOrAuto::parse_non_negative(context, i)) {
let height = input
.try(|i| LengthOrPercentageOrAuto::parse_non_negative(context, i))
@ -41,3 +44,59 @@ impl BackgroundSize {
}
}
}
/// One of the keywords for `background-repeat`.
define_css_keyword_enum! { RepeatKeyword:
"repeat" => Repeat,
"space" => Space,
"round" => Round,
"no-repeat" => NoRepeat
}
/// The specified value for the `background-repeat` property.
///
/// https://drafts.csswg.org/css-backgrounds/#the-background-repeat
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
pub enum BackgroundRepeat {
/// `repeat-x`
RepeatX,
/// `repeat-y`
RepeatY,
/// `[repeat | space | round | no-repeat]{1,2}`
Keywords(RepeatKeyword, Option<RepeatKeyword>),
}
impl BackgroundRepeat {
/// Returns the `repeat` value.
#[inline]
pub fn repeat() -> Self {
BackgroundRepeat::Keywords(RepeatKeyword::Repeat, None)
}
}
impl Parse for BackgroundRepeat {
fn parse<'i, 't>(
_context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
let ident = input.expect_ident_cloned()?;
match_ignore_ascii_case! { &ident,
"repeat-x" => return Ok(BackgroundRepeat::RepeatX),
"repeat-y" => return Ok(BackgroundRepeat::RepeatY),
_ => {},
}
let horizontal = match RepeatKeyword::from_ident(&ident) {
Ok(h) => h,
Err(()) => {
return Err(input.new_custom_error(
SelectorParseErrorKind::UnexpectedIdent(ident.clone())
));
}
};
let vertical = input.try(RepeatKeyword::parse).ok();
Ok(BackgroundRepeat::Keywords(horizontal, vertical))
}
}