Add Ellipse to basic_shape.rs

This commit is contained in:
Manish Goregaokar 2016-08-01 17:56:54 +05:30
parent 77f345476f
commit 78ce65d5a8
No known key found for this signature in database
GPG key ID: 3BBF4D3E2EF79F98
2 changed files with 92 additions and 2 deletions

View file

@ -18,7 +18,7 @@ use cssparser::{self, Parser, ToCss, Token};
pub enum BasicShape {
Inset(InsetRect),
Circle(Circle),
// Ellipse(Ellipse),
Ellipse(Ellipse),
// Polygon(Polygon),
}
@ -27,6 +27,7 @@ impl ToCss for BasicShape {
match *self {
BasicShape::Inset(rect) => rect.to_css(dest),
BasicShape::Circle(circle) => circle.to_css(dest),
BasicShape::Ellipse(e) => e.to_css(dest),
}
}
}
@ -75,6 +76,28 @@ impl ToCss for Circle {
}
}
#[derive(Clone, PartialEq, Copy, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct Ellipse {
pub semiaxis_a: ShapeRadius,
pub semiaxis_b: ShapeRadius,
pub position: Position,
}
impl ToCss for Ellipse {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
if ShapeRadius::ClosestSide != self.semiaxis_a
&& ShapeRadius::ClosestSide != self.semiaxis_b {
try!(self.semiaxis_a.to_css(dest));
try!(dest.write_str(" "));
try!(self.semiaxis_b.to_css(dest));
try!(dest.write_str(" "));
}
try!(dest.write_str("at "));
self.position.to_css(dest)
}
}
/// https://drafts.csswg.org/css-shapes/#typedef-shape-radius
#[derive(Clone, PartialEq, Copy, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]