From 88c1a67d89a3bbab93d77a6db222810dc337bce1 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 1 Aug 2016 15:00:01 +0530 Subject: [PATCH] Add ShapeRadius to basic_shape.rs --- .../style/values/computed/basic_shape.rs | 25 +++++++++ .../style/values/specified/basic_shape.rs | 54 +++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/components/style/values/computed/basic_shape.rs b/components/style/values/computed/basic_shape.rs index 2f85667851b..462234b7b75 100644 --- a/components/style/values/computed/basic_shape.rs +++ b/components/style/values/computed/basic_shape.rs @@ -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(&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 #[derive(Clone, PartialEq, Copy, Debug)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] diff --git a/components/style/values/specified/basic_shape.rs b/components/style/values/specified/basic_shape.rs index cf263adde77..c7bd7dea837 100644 --- a/components/style/values/specified/basic_shape.rs +++ b/components/style/values/specified/basic_shape.rs @@ -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 { + 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(&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 #[derive(Clone, PartialEq, Copy, Debug)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]