style: Serialize a bunch of image properties with Servo.

I had to fix the conversion for BackgroundSize too, hopefully we can
simplify all this using cbindgen in the future instead of CalcValue.

Differential Revision: https://phabricator.services.mozilla.com/D7580
This commit is contained in:
Emilio Cobos Álvarez 2018-10-05 20:08:55 +00:00
parent 0d5d5a9c82
commit 7345af613a
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
4 changed files with 63 additions and 19 deletions

View file

@ -202,21 +202,34 @@ impl ToCss for CalcLengthOrPercentage {
{
use num_traits::Zero;
let (length, percentage) = match (self.length, self.percentage) {
(l, None) => return l.to_css(dest),
(l, Some(p)) if l.px() == 0. => return p.to_css(dest),
(l, Some(p)) => (l, p),
};
let length = self.unclamped_length();
match self.percentage {
Some(p) => {
if length.px() == 0. && self.clamping_mode.clamp(p.0) == p.0 {
return p.to_css(dest);
}
}
None => {
if self.clamping_mode.clamp(length.px()) == length.px() {
return length.to_css(dest);
}
}
}
dest.write_str("calc(")?;
percentage.to_css(dest)?;
dest.write_str(if length.px() < Zero::zero() {
" - "
if let Some(percentage) = self.percentage {
percentage.to_css(dest)?;
if length.px() != 0. {
dest.write_str(if length.px() < Zero::zero() {
" - "
} else {
" + "
})?;
length.abs().to_css(dest)?;
}
} else {
" + "
})?;
length.abs().to_css(dest)?;
length.to_css(dest)?;
}
dest.write_str(")")
}