Add serialize_four_sides, use for serializing BorderRadius

This commit is contained in:
Manish Goregaokar 2016-08-02 15:43:52 +05:30
parent c6feae3c5c
commit d1e45f78af
No known key found for this signature in database
GPG key ID: 3BBF4D3E2EF79F98
5 changed files with 110 additions and 27 deletions

View file

@ -9,7 +9,7 @@
use app_units::Au;
use cssparser::{Parser, ToCss};
use properties::shorthands::parse_four_sides;
use properties::shorthands::{parse_four_sides, serialize_four_sides};
use std::fmt;
use values::computed::basic_shape as computed_basic_shape;
use values::computed::{Context, ToComputedValue, ComputedValueAsSpecified};
@ -408,21 +408,28 @@ impl ToCss for BorderRadius {
// a helper function somewhere, for all the parse_four_sides-like
// values
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
try!(self.top_left.0.width.to_css(dest));
try!(dest.write_str(" "));
try!(self.top_right.0.width.to_css(dest));
try!(dest.write_str(" "));
try!(self.bottom_left.0.width.to_css(dest));
try!(dest.write_str(" "));
try!(self.bottom_right.0.width.to_css(dest));
try!(dest.write_str(" / "));
try!(self.top_left.0.height.to_css(dest));
try!(dest.write_str(" "));
try!(self.top_right.0.height.to_css(dest));
try!(dest.write_str(" "));
try!(self.bottom_left.0.height.to_css(dest));
try!(dest.write_str(" "));
self.bottom_right.0.height.to_css(dest)
if self.top_left.0.width == self.top_left.0.height &&
self.top_right.0.width == self.top_right.0.height &&
self.bottom_left.0.width == self.bottom_left.0.height &&
self.bottom_right.0.width == self.bottom_right.0.height {
serialize_four_sides((&self.top_left.0.width,
&self.top_right.0.width,
&self.bottom_left.0.width,
&self.bottom_right.0.width),
dest)
} else {
try!(serialize_four_sides((&self.top_left.0.width,
&self.top_right.0.width,
&self.bottom_left.0.width,
&self.bottom_right.0.width),
dest));
try!(dest.write_str(" / "));
serialize_four_sides((&self.top_left.0.height,
&self.top_right.0.height,
&self.bottom_left.0.height,
&self.bottom_right.0.height),
dest)
}
}
}