Skip to content

Commit

Permalink
Separate serialization function for BorderRadius
Browse files Browse the repository at this point in the history
  • Loading branch information
wafflespeanut committed Apr 13, 2017
1 parent 9c0d8e4 commit 26fda04
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 46 deletions.
28 changes: 4 additions & 24 deletions components/style/values/computed/basic_shape.rs
Expand Up @@ -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))]
Expand Down Expand Up @@ -209,28 +208,9 @@ pub struct BorderRadius {
}

impl ToCss for BorderRadius {
#[inline]
fn to_css<W>(&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)
}
}
56 changes: 34 additions & 22 deletions components/style/values/specified/basic_shape.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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<L, W>(dest: &mut W, top_left: &Size2D<L>,
top_right: &Size2D<L>, bottom_right: &Size2D<L>,
bottom_left: &Size2D<L>) -> 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<W>(&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)
}
}

Expand Down

0 comments on commit 26fda04

Please sign in to comment.