mirror of
https://github.com/servo/servo.git
synced 2025-08-12 08:55:32 +01:00
style: Serialize background-size: auto auto
as "auto".
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. Differential Revision: https://phabricator.services.mozilla.com/D10446
This commit is contained in:
parent
68f4ad9557
commit
56fd3b786f
4 changed files with 53 additions and 3 deletions
|
@ -4,6 +4,10 @@
|
|||
|
||||
//! Generic types for CSS values related to backgrounds.
|
||||
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
use values::IsAuto;
|
||||
|
||||
/// A generic value for the `background-size` property.
|
||||
#[derive(
|
||||
Animate,
|
||||
|
@ -17,7 +21,6 @@
|
|||
ToAnimatedValue,
|
||||
ToAnimatedZero,
|
||||
ToComputedValue,
|
||||
ToCss,
|
||||
)]
|
||||
pub enum BackgroundSize<LengthOrPercentageOrAuto> {
|
||||
/// `<width> <height>`
|
||||
|
@ -34,3 +37,29 @@ pub enum BackgroundSize<LengthOrPercentageOrAuto> {
|
|||
#[animation(error)]
|
||||
Contain,
|
||||
}
|
||||
|
||||
impl<LengthOrPercentageOrAuto> ToCss for BackgroundSize<LengthOrPercentageOrAuto>
|
||||
where
|
||||
LengthOrPercentageOrAuto: ToCss + IsAuto,
|
||||
{
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
match self {
|
||||
BackgroundSize::Explicit { width, height } => {
|
||||
width.to_css(dest)?;
|
||||
// NOTE(emilio): We should probably simplify all these in case
|
||||
// `width == `height`, but all other browsers agree on only
|
||||
// special-casing `auto`.
|
||||
if !width.is_auto() || !height.is_auto() {
|
||||
dest.write_str(" ")?;
|
||||
height.to_css(dest)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
BackgroundSize::Cover => dest.write_str("cover"),
|
||||
BackgroundSize::Contain => dest.write_str("contain"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue