Add Circle to basic_shape.rs

This commit is contained in:
Manish Goregaokar 2016-08-01 16:10:17 +05:30
parent 44e33bcdc5
commit 77f345476f
No known key found for this signature in database
GPG key ID: 3BBF4D3E2EF79F98
3 changed files with 88 additions and 4 deletions

View file

@ -9,6 +9,7 @@
use values::computed::{Length, LengthOrPercentage};
use values::computed::BorderRadiusSize;
use values::computed::position::Position;
use std::fmt;
use cssparser::{self, Parser, ToCss, Token};
@ -16,11 +17,20 @@ use cssparser::{self, Parser, ToCss, Token};
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum BasicShape {
Inset(InsetRect),
// Circle(Circle),
Circle(Circle),
// Ellipse(Ellipse),
// Polygon(Polygon),
}
impl ToCss for BasicShape {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
BasicShape::Inset(rect) => rect.to_css(dest),
BasicShape::Circle(circle) => circle.to_css(dest),
}
}
}
#[derive(Clone, PartialEq, Copy, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct InsetRect {
@ -50,6 +60,21 @@ impl ToCss for InsetRect {
}
}
#[derive(Clone, PartialEq, Copy, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct Circle {
pub radius: ShapeRadius,
pub position: Position,
}
impl ToCss for Circle {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
try!(self.radius.to_css(dest));
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))]