style: Improve border-image shorthand serialization, and annotate more passes

This commit is contained in:
Emilio Cobos Álvarez 2023-06-12 12:09:58 -04:00 committed by Martin Robinson
parent 733222fffe
commit 127e00e48a

View file

@ -357,25 +357,39 @@ pub fn parse_border<'i, 't>(
impl<'a> ToCss for LonghandsToSerialize<'a> { impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
self.border_image_source.to_css(dest)?; let mut has_any = false;
% for name in "slice outset width repeat".split(): % for name in "source slice outset width repeat".split():
let has_${name} = *self.border_image_${name} != border_image_${name}::get_initial_specified_value(); let has_${name} = *self.border_image_${name} != border_image_${name}::get_initial_specified_value();
has_any = has_any || has_${name};
% endfor % endfor
if has_source || !has_any {
self.border_image_source.to_css(dest)?;
if !has_any {
return Ok(());
}
}
let needs_slice = has_slice || has_width || has_outset; let needs_slice = has_slice || has_width || has_outset;
if needs_slice { if needs_slice {
dest.write_char(' ')?; if has_source {
self.border_image_slice.to_css(dest)?; dest.write_char(' ')?;
if has_width {
dest.write_str(" / ")?;
self.border_image_width.to_css(dest)?;
} }
if has_outset { self.border_image_slice.to_css(dest)?;
dest.write_str(" / ")?; if has_width || has_outset {
self.border_image_outset.to_css(dest)?; dest.write_str(" /")?;
if has_width {
dest.write_char(' ')?;
self.border_image_width.to_css(dest)?;
}
if has_outset {
dest.write_str(" / ")?;
self.border_image_outset.to_css(dest)?;
}
} }
} }
if has_repeat { if has_repeat {
dest.write_char(' ')?; if has_source || needs_slice {
dest.write_char(' ')?;
}
self.border_image_repeat.to_css(dest)?; self.border_image_repeat.to_css(dest)?;
} }
Ok(()) Ok(())