mirror of
https://github.com/servo/servo.git
synced 2025-08-07 22:45:34 +01:00
Auto merge of #18131 - emilio:calc-serialization, r=canaltinova
style: Multiple calc serialization fixes. This puts us in line with the spec as written, except for caveat in https://github.com/w3c/csswg-drafts/issues/1731. Need to fix computed calc() too, I'm less confident that we won't need to change test expectations. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18131) <!-- Reviewable:end -->
This commit is contained in:
commit
92176d1152
8 changed files with 122 additions and 46 deletions
|
@ -195,11 +195,21 @@ impl From<LengthOrPercentageOrNone> for Option<CalcLengthOrPercentage> {
|
|||
|
||||
impl ToCss for CalcLengthOrPercentage {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match (self.length, self.percentage) {
|
||||
(l, Some(p)) if l == Au(0) => p.to_css(dest),
|
||||
(l, Some(p)) => write!(dest, "calc({}px + {}%)", Au::to_px(l), p.0 * 100.),
|
||||
(l, None) => write!(dest, "{}px", Au::to_px(l)),
|
||||
}
|
||||
use num_traits::Zero;
|
||||
|
||||
let (length, percentage) = match (self.length, self.percentage) {
|
||||
(l, None) => return l.to_css(dest),
|
||||
(l, Some(p)) if l == Au(0) => return p.to_css(dest),
|
||||
(l, Some(p)) => (l, p),
|
||||
};
|
||||
|
||||
dest.write_str("calc(")?;
|
||||
percentage.to_css(dest)?;
|
||||
|
||||
dest.write_str(if length < Zero::zero() { " - " } else { " + " })?;
|
||||
length.abs().to_css(dest)?;
|
||||
|
||||
dest.write_str(")")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue