mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Make computed serialization of calc() match the spec too.
This commit is contained in:
parent
1d54a8e857
commit
22d6a73436
1 changed files with 18 additions and 17 deletions
|
@ -194,23 +194,24 @@ impl From<LengthOrPercentageOrNone> for Option<CalcLengthOrPercentage> {
|
||||||
|
|
||||||
impl ToCss for CalcLengthOrPercentage {
|
impl ToCss for CalcLengthOrPercentage {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
// FIXME(emilio): This should be consistent with specified calc().
|
use num_traits::Zero;
|
||||||
//
|
|
||||||
// Also, serialisation here is kinda weird with negative percentages,
|
let (length, percentage) = match (self.length, self.percentage) {
|
||||||
// for example, as of right now:
|
(l, None) => return l.to_css(dest),
|
||||||
//
|
(l, Some(p)) if l == Au(0) => return p.to_css(dest),
|
||||||
// calc(10px - 5%)
|
(l, Some(p)) => (l, p),
|
||||||
//
|
};
|
||||||
// would serialize as:
|
|
||||||
//
|
dest.write_str("calc(")?;
|
||||||
// calc(10px + -5%)
|
percentage.to_css(dest)?;
|
||||||
//
|
|
||||||
// Need to update and run through try.
|
dest.write_str(if length < Zero::zero() { " - " } else { " + " })?;
|
||||||
match (self.length, self.percentage) {
|
|
||||||
(l, Some(p)) if l == Au(0) => p.to_css(dest),
|
// FIXME(emilio): Au::abs would be nice.
|
||||||
(l, Some(p)) => write!(dest, "calc({}px + {}%)", Au::to_px(l), p.0 * 100.),
|
let length = if length < Zero::zero() { -length } else { length };
|
||||||
(l, None) => write!(dest, "{}px", Au::to_px(l)),
|
|
||||||
}
|
length.to_css(dest)?;
|
||||||
|
dest.write_str(")")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue