style: When serializing background shorthand skip initial values and order values according to grammar

Differential Revision: https://phabricator.services.mozilla.com/D155077
This commit is contained in:
Connor Pearson 2022-08-21 22:13:04 +00:00 committed by Martin Robinson
parent 76192031d3
commit c8e3dc4d19

View file

@ -12,7 +12,7 @@
background-clip"
spec="https://drafts.csswg.org/css-backgrounds/#the-background">
use crate::properties::longhands::{background_position_x, background_position_y, background_repeat};
use crate::properties::longhands::{background_attachment, background_image, background_size, background_origin};
use crate::properties::longhands::{background_attachment, background_color, background_image, background_size, background_origin};
use crate::properties::longhands::background_clip;
use crate::properties::longhands::background_clip::single_value::computed_value::T as Clip;
use crate::properties::longhands::background_origin::single_value::computed_value::T as Origin;
@ -156,35 +156,71 @@
dest.write_str(", ")?;
}
let mut wrote_value = false;
if i == len - 1 {
self.background_color.to_css(dest)?;
dest.write_str(" ")?;
if *self.background_color != background_color::get_initial_specified_value() {
self.background_color.to_css(dest)?;
wrote_value = true;
}
}
if *image != background_image::single_value::get_initial_specified_value() {
if wrote_value {
dest.write_str(" ")?;
}
image.to_css(dest)?;
wrote_value = true;
}
// Size is only valid after a position so when there is a
// non-initial size we must also serialize position
if *position_x != PositionComponent::zero() ||
*position_y != PositionComponent::zero() ||
*size != background_size::single_value::get_initial_specified_value()
{
if wrote_value {
dest.write_str(" ")?;
}
Position {
horizontal: position_x.clone(),
vertical: position_y.clone()
}.to_css(dest)?;
wrote_value = true;
if *size != background_size::single_value::get_initial_specified_value() {
dest.write_str(" / ")?;
size.to_css(dest)?;
}
}
image.to_css(dest)?;
% for name in "repeat attachment".split():
dest.write_str(" ")?;
${name}.to_css(dest)?;
if *${name} != background_${name}::single_value::get_initial_specified_value() {
if wrote_value {
dest.write_str(" ")?;
}
${name}.to_css(dest)?;
wrote_value = true;
}
% endfor
dest.write_str(" ")?;
Position {
horizontal: position_x.clone(),
vertical: position_y.clone()
}.to_css(dest)?;
if *size != background_size::single_value::get_initial_specified_value() {
dest.write_str(" / ")?;
size.to_css(dest)?;
}
if *origin != Origin::PaddingBox || *clip != Clip::BorderBox {
dest.write_str(" ")?;
if wrote_value {
dest.write_str(" ")?;
}
origin.to_css(dest)?;
if *clip != From::from(*origin) {
dest.write_str(" ")?;
clip.to_css(dest)?;
}
wrote_value = true;
}
if !wrote_value {
image.to_css(dest)?;
}
}