With this change, all of Chrome, Edge, Firefox, and Safari serialize
background-size by omitting the second "auto" if the value is "auto
auto". Other keywords are still repeated.
Depends on D10445
Differential D10446
Bug 1501261 - Part 2: Serialize `background-size: auto auto` as "auto" Authored by heycam on Nov 1 2018, 12:16 AM.
Details
With this change, all of Chrome, Edge, Firefox, and Safari serialize Depends on D10445
Diff Detail
Event TimelineComment Actions I think this one is a bit unfortunate... But why not shortening all of them? That is, something like: impl<LengthOrPercentageOrAuto> ToCss for BackgroundSize<LengthOrPercentageOrAuto>
where
LengthOrPercentageOrAuto: ToCss + PartialEq,
{
pub fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
match self {
BackgroundSize::Explicit { width, height } => {
width.to_css(dest)?;
if width != height {
dest.write_str(" ")?;
height.to_css(dest)
}
}
BackgroundSize::Cover => dest.write_str("cover"),
BackgroundSize::Contain => dest.write_str("contain"),
}
}
}Comment Actions Just because all other browsers are consistent about shortening only "auto auto" and not for any other value. Comment Actions What's more unfortunate (IMO) is that it's impossible (or difficult enough that I didn't work out how) to add a trait bound on generic::BackgroundSize's LengthPercentageOrAuto type parameter for, say, an IsAuto trait, and then just add a #[css(skip_if = "is_auto")] on the height field or something. Comment Actions That's too bad :( That'd be wrong though, since you could have stretch auto or something like that, right? You'd need an skip_if_self or something of the sort... It shouldn't be hard to add a way to add extra bounds to the impl either, something like this should work: https://gist.github.com/emilio/421418d12864929a7d0d9c4a98ff7ccb Now there's the question of how useful it would generally be... I think the extra_bounds bit should not be needed, right? enum BackgroundSize<LengthOrPercentageOrAuto: IsAuto> should work without that, right? The #[derive] code I think parses and understands that.
Comment Actions Yeah, true.
Cool.
I couldn't get it to work.
Comment Actions Seems to work, wdyt about that? It's neutral in amount of lines, but I think it's a bit nicer. Comment Actions I bet the problem was that I was also trying to add the IsAuto trait bound to the BackgroundSize enum itself, and that was tripping up the derived traits. Comment Actions Yeah, I can see the bound on the enum causing havoc :)
| ||||||||||||||||||||||||||