mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Separate serialization function for BorderRadius
This commit is contained in:
parent
9c0d8e44a0
commit
26fda04888
2 changed files with 38 additions and 46 deletions
|
@ -7,14 +7,13 @@
|
||||||
//!
|
//!
|
||||||
//! [basic-shape]: https://drafts.csswg.org/css-shapes/#typedef-basic-shape
|
//! [basic-shape]: https://drafts.csswg.org/css-shapes/#typedef-basic-shape
|
||||||
|
|
||||||
use properties::shorthands::serialize_four_sides;
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
use values::computed::{BorderRadiusSize, LengthOrPercentage};
|
use values::computed::{BorderRadiusSize, LengthOrPercentage};
|
||||||
use values::computed::position::Position;
|
use values::computed::position::Position;
|
||||||
use values::specified::url::SpecifiedUrl;
|
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)]
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
@ -209,28 +208,9 @@ pub struct BorderRadius {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for BorderRadius {
|
impl ToCss for BorderRadius {
|
||||||
|
#[inline]
|
||||||
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 {
|
||||||
if self.top_left.0.width == self.top_left.0.height &&
|
basic_shape::serialize_radius_values(dest, &self.top_left.0, &self.top_right.0,
|
||||||
self.top_right.0.width == self.top_right.0.height &&
|
&self.bottom_right.0, &self.bottom_left.0)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
//! [basic-shape]: https://drafts.csswg.org/css-shapes/#typedef-basic-shape
|
//! [basic-shape]: https://drafts.csswg.org/css-shapes/#typedef-basic-shape
|
||||||
|
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
|
use euclid::size::Size2D;
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
use properties::shorthands::{parse_four_sides, serialize_four_sides};
|
use properties::shorthands::{parse_four_sides, serialize_four_sides};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -721,30 +722,41 @@ pub struct BorderRadius {
|
||||||
pub bottom_left: BorderRadiusSize,
|
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 {
|
impl ToCss for BorderRadius {
|
||||||
|
#[inline]
|
||||||
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 {
|
||||||
if self.top_left.0.width == self.top_left.0.height &&
|
serialize_radius_values(dest, &self.top_left.0, &self.top_right.0,
|
||||||
self.top_right.0.width == self.top_right.0.height &&
|
&self.bottom_right.0, &self.bottom_left.0)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue