diff --git a/components/style/values/computed/basic_shape.rs b/components/style/values/computed/basic_shape.rs index a3848195e47b..2ae1675bb3c4 100644 --- a/components/style/values/computed/basic_shape.rs +++ b/components/style/values/computed/basic_shape.rs @@ -7,14 +7,13 @@ //! //! [basic-shape]: https://drafts.csswg.org/css-shapes/#typedef-basic-shape -use properties::shorthands::serialize_four_sides; use std::fmt; use style_traits::ToCss; use values::computed::{BorderRadiusSize, LengthOrPercentage}; use values::computed::position::Position; use values::specified::url::SpecifiedUrl; -pub use values::specified::basic_shape::{FillRule, GeometryBox, ShapeBox}; +pub use values::specified::basic_shape::{self, FillRule, GeometryBox, ShapeBox}; #[derive(Clone, PartialEq, Debug)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] @@ -209,28 +208,9 @@ pub struct BorderRadius { } impl ToCss for BorderRadius { + #[inline] fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - if self.top_left.0.width == self.top_left.0.height && - self.top_right.0.width == self.top_right.0.height && - self.bottom_right.0.width == self.bottom_right.0.height && - self.bottom_left.0.width == self.bottom_left.0.height { - serialize_four_sides(dest, - &self.top_left.0.width, - &self.top_right.0.width, - &self.bottom_right.0.width, - &self.bottom_left.0.width) - } else { - try!(serialize_four_sides(dest, - &self.top_left.0.width, - &self.top_right.0.width, - &self.bottom_right.0.width, - &self.bottom_left.0.width)); - try!(dest.write_str(" / ")); - serialize_four_sides(dest, - &self.top_left.0.height, - &self.top_right.0.height, - &self.bottom_right.0.height, - &self.bottom_left.0.height) - } + basic_shape::serialize_radius_values(dest, &self.top_left.0, &self.top_right.0, + &self.bottom_right.0, &self.bottom_left.0) } } diff --git a/components/style/values/specified/basic_shape.rs b/components/style/values/specified/basic_shape.rs index 83a711b38b22..c1e4e71bcd94 100644 --- a/components/style/values/specified/basic_shape.rs +++ b/components/style/values/specified/basic_shape.rs @@ -8,6 +8,7 @@ //! [basic-shape]: https://drafts.csswg.org/css-shapes/#typedef-basic-shape use cssparser::Parser; +use euclid::size::Size2D; use parser::{Parse, ParserContext}; use properties::shorthands::{parse_four_sides, serialize_four_sides}; use std::fmt; @@ -721,30 +722,41 @@ pub struct BorderRadius { pub bottom_left: BorderRadiusSize, } +/// Serialization helper for types of longhands like `border-radius` and `outline-radius` +pub fn serialize_radius_values(dest: &mut W, top_left: &Size2D, + top_right: &Size2D, bottom_right: &Size2D, + bottom_left: &Size2D) -> fmt::Result + where L: ToCss + PartialEq, W: fmt::Write +{ + if top_left.width == top_left.height && + top_right.width == top_right.height && + bottom_right.width == bottom_right.height && + bottom_left.width == bottom_left.height { + serialize_four_sides(dest, + &top_left.width, + &top_right.width, + &bottom_right.width, + &bottom_left.width) + } else { + serialize_four_sides(dest, + &top_left.width, + &top_right.width, + &bottom_right.width, + &bottom_left.width)?; + dest.write_str(" / ")?; + serialize_four_sides(dest, + &top_left.height, + &top_right.height, + &bottom_right.height, + &bottom_left.height) + } +} + impl ToCss for BorderRadius { + #[inline] fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - if self.top_left.0.width == self.top_left.0.height && - self.top_right.0.width == self.top_right.0.height && - self.bottom_right.0.width == self.bottom_right.0.height && - self.bottom_left.0.width == self.bottom_left.0.height { - serialize_four_sides(dest, - &self.top_left.0.width, - &self.top_right.0.width, - &self.bottom_right.0.width, - &self.bottom_left.0.width) - } else { - try!(serialize_four_sides(dest, - &self.top_left.0.width, - &self.top_right.0.width, - &self.bottom_right.0.width, - &self.bottom_left.0.width)); - try!(dest.write_str(" / ")); - serialize_four_sides(dest, - &self.top_left.0.height, - &self.top_right.0.height, - &self.bottom_right.0.height, - &self.bottom_left.0.height) - } + serialize_radius_values(dest, &self.top_left.0, &self.top_right.0, + &self.bottom_right.0, &self.bottom_left.0) } }