mirror of
https://github.com/servo/servo.git
synced 2025-07-13 18:33:40 +01:00
Add ShapeRadius to basic_shape.rs
This commit is contained in:
parent
2580c1dc6e
commit
88c1a67d89
2 changed files with 79 additions and 0 deletions
|
@ -50,6 +50,31 @@ impl ToCss for InsetRect {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// https://drafts.csswg.org/css-shapes/#typedef-shape-radius
|
||||||
|
#[derive(Clone, PartialEq, Copy, Debug)]
|
||||||
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
pub enum ShapeRadius {
|
||||||
|
Length(LengthOrPercentage),
|
||||||
|
ClosestSide,
|
||||||
|
FarthestSide,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ShapeRadius {
|
||||||
|
fn default() -> Self {
|
||||||
|
ShapeRadius::ClosestSide
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToCss for ShapeRadius {
|
||||||
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
|
match *self {
|
||||||
|
ShapeRadius::Length(lop) => lop.to_css(dest),
|
||||||
|
ShapeRadius::ClosestSide => dest.write_str("closest-side"),
|
||||||
|
ShapeRadius::FarthestSide => dest.write_str("farthest-side"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// https://drafts.csswg.org/css-backgrounds-3/#border-radius
|
/// https://drafts.csswg.org/css-backgrounds-3/#border-radius
|
||||||
#[derive(Clone, PartialEq, Copy, Debug)]
|
#[derive(Clone, PartialEq, Copy, Debug)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
|
|
@ -126,6 +126,60 @@ impl ToComputedValue for InsetRect {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// https://drafts.csswg.org/css-shapes/#typedef-shape-radius
|
||||||
|
#[derive(Clone, PartialEq, Copy, Debug)]
|
||||||
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
pub enum ShapeRadius {
|
||||||
|
Length(LengthOrPercentage),
|
||||||
|
ClosestSide,
|
||||||
|
FarthestSide,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ShapeRadius {
|
||||||
|
fn default() -> Self {
|
||||||
|
ShapeRadius::ClosestSide
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ShapeRadius {
|
||||||
|
pub fn parse(input: &mut Parser) -> Result<ShapeRadius, ()> {
|
||||||
|
input.try(LengthOrPercentage::parse).map(ShapeRadius::Length)
|
||||||
|
.or_else(|_| {
|
||||||
|
match_ignore_ascii_case! { try!(input.expect_ident()),
|
||||||
|
"closest-side" => Ok(ShapeRadius::ClosestSide),
|
||||||
|
"farthest-side" => Ok(ShapeRadius::FarthestSide),
|
||||||
|
_ => Err(())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToCss for ShapeRadius {
|
||||||
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
|
match *self {
|
||||||
|
ShapeRadius::Length(lop) => lop.to_css(dest),
|
||||||
|
ShapeRadius::ClosestSide => dest.write_str("closest-side"),
|
||||||
|
ShapeRadius::FarthestSide => dest.write_str("farthest-side"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl ToComputedValue for ShapeRadius {
|
||||||
|
type ComputedValue = computed_basic_shape::ShapeRadius;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn to_computed_value(&self, cx: &Context) -> Self::ComputedValue {
|
||||||
|
match *self {
|
||||||
|
ShapeRadius::Length(lop) => {
|
||||||
|
computed_basic_shape::ShapeRadius::Length(lop.to_computed_value(cx))
|
||||||
|
}
|
||||||
|
ShapeRadius::ClosestSide => computed_basic_shape::ShapeRadius::ClosestSide,
|
||||||
|
ShapeRadius::FarthestSide => computed_basic_shape::ShapeRadius::FarthestSide,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// https://drafts.csswg.org/css-backgrounds-3/#border-radius
|
/// https://drafts.csswg.org/css-backgrounds-3/#border-radius
|
||||||
#[derive(Clone, PartialEq, Copy, Debug)]
|
#[derive(Clone, PartialEq, Copy, Debug)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue