mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
style: Be a bit more explicit about background-size.
We have a ton of ad-hoc `From` impls which seem overly generic, I think.
This commit is contained in:
parent
2ac1327e4b
commit
7e4338eed8
4 changed files with 23 additions and 12 deletions
|
@ -167,8 +167,8 @@ ${helpers.single_keyword("background-origin",
|
||||||
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER")}
|
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER")}
|
||||||
|
|
||||||
${helpers.predefined_type("background-size", "BackgroundSize",
|
${helpers.predefined_type("background-size", "BackgroundSize",
|
||||||
initial_value="computed::LengthOrPercentageOrAuto::Auto.into()",
|
initial_value="computed::BackgroundSize::auto()",
|
||||||
initial_specified_value="specified::LengthOrPercentageOrAuto::Auto.into()",
|
initial_specified_value="specified::BackgroundSize::auto()",
|
||||||
spec="https://drafts.csswg.org/css-backgrounds/#the-background-size",
|
spec="https://drafts.csswg.org/css-backgrounds/#the-background-size",
|
||||||
vector=True,
|
vector=True,
|
||||||
animation_value_type="BackgroundSizeList",
|
animation_value_type="BackgroundSizeList",
|
||||||
|
|
|
@ -13,6 +13,16 @@ use values::generics::background::BackgroundSize as GenericBackgroundSize;
|
||||||
/// A computed value for the `background-size` property.
|
/// A computed value for the `background-size` property.
|
||||||
pub type BackgroundSize = GenericBackgroundSize<LengthOrPercentageOrAuto>;
|
pub type BackgroundSize = GenericBackgroundSize<LengthOrPercentageOrAuto>;
|
||||||
|
|
||||||
|
impl BackgroundSize {
|
||||||
|
/// Returns `auto auto`.
|
||||||
|
pub fn auto() -> Self {
|
||||||
|
GenericBackgroundSize::Explicit {
|
||||||
|
width: LengthOrPercentageOrAuto::Auto,
|
||||||
|
height: LengthOrPercentageOrAuto::Auto,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl RepeatableListAnimatable for BackgroundSize {}
|
impl RepeatableListAnimatable for BackgroundSize {}
|
||||||
|
|
||||||
impl ToAnimatedZero for BackgroundSize {
|
impl ToAnimatedZero for BackgroundSize {
|
||||||
|
|
|
@ -24,12 +24,3 @@ pub enum BackgroundSize<LengthOrPercentageOrAuto> {
|
||||||
#[animation(error)]
|
#[animation(error)]
|
||||||
Contain,
|
Contain,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<L> From<L> for BackgroundSize<L>
|
|
||||||
where L: Clone,
|
|
||||||
{
|
|
||||||
#[inline]
|
|
||||||
fn from(value: L) -> Self {
|
|
||||||
BackgroundSize::Explicit { width: value.clone(), height: value }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ impl Parse for BackgroundSize {
|
||||||
let height = input
|
let height = input
|
||||||
.try(|i| LengthOrPercentageOrAuto::parse_non_negative(context, i))
|
.try(|i| LengthOrPercentageOrAuto::parse_non_negative(context, i))
|
||||||
.unwrap_or(LengthOrPercentageOrAuto::Auto);
|
.unwrap_or(LengthOrPercentageOrAuto::Auto);
|
||||||
return Ok(GenericBackgroundSize::Explicit { width: width, height: height });
|
return Ok(GenericBackgroundSize::Explicit { width, height });
|
||||||
}
|
}
|
||||||
let ident = input.expect_ident()?;
|
let ident = input.expect_ident()?;
|
||||||
(match_ignore_ascii_case! { &ident,
|
(match_ignore_ascii_case! { &ident,
|
||||||
|
@ -30,3 +30,13 @@ impl Parse for BackgroundSize {
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident.clone()).into())
|
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident.clone()).into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl BackgroundSize {
|
||||||
|
/// Returns `auto auto`.
|
||||||
|
pub fn auto() -> Self {
|
||||||
|
GenericBackgroundSize::Explicit {
|
||||||
|
width: LengthOrPercentageOrAuto::Auto,
|
||||||
|
height: LengthOrPercentageOrAuto::Auto,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue