mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Create a module for generics and make BorderRadiusSize generic
This commit is contained in:
parent
c5c6e8c442
commit
0249270f61
9 changed files with 91 additions and 74 deletions
|
@ -22,6 +22,7 @@ use style_traits::values::specified::AllowedNumericType;
|
|||
use super::{Auto, CSSFloat, CSSInteger, HasViewportPercentage, Either, None_};
|
||||
use super::computed::{self, Context};
|
||||
use super::computed::{Shadow as ComputedShadow, ToComputedValue};
|
||||
use super::generics::BorderRadiusSize as GenericBorderRadiusSize;
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, JustifyItems};
|
||||
|
@ -282,30 +283,8 @@ pub fn parse_number_with_clamping_mode(context: &ParserContext,
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
pub struct BorderRadiusSize(pub Size2D<LengthOrPercentage>);
|
||||
|
||||
no_viewport_percentage!(BorderRadiusSize);
|
||||
|
||||
impl BorderRadiusSize {
|
||||
#[allow(missing_docs)]
|
||||
pub fn zero() -> BorderRadiusSize {
|
||||
let zero = LengthOrPercentage::Length(NoCalcLength::zero());
|
||||
BorderRadiusSize(Size2D::new(zero.clone(), zero))
|
||||
}
|
||||
|
||||
#[allow(missing_docs)]
|
||||
pub fn new(width: LengthOrPercentage, height: LengthOrPercentage) -> BorderRadiusSize {
|
||||
BorderRadiusSize(Size2D::new(width, height))
|
||||
}
|
||||
|
||||
#[allow(missing_docs)]
|
||||
pub fn circle(radius: LengthOrPercentage) -> BorderRadiusSize {
|
||||
BorderRadiusSize(Size2D::new(radius.clone(), radius))
|
||||
}
|
||||
}
|
||||
/// The specified value of `BorderRadiusSize`
|
||||
pub type BorderRadiusSize = GenericBorderRadiusSize<LengthOrPercentage>;
|
||||
|
||||
impl Parse for BorderRadiusSize {
|
||||
#[inline]
|
||||
|
@ -313,15 +292,7 @@ impl Parse for BorderRadiusSize {
|
|||
let first = try!(LengthOrPercentage::parse_non_negative(context, input));
|
||||
let second = input.try(|i| LengthOrPercentage::parse_non_negative(context, i))
|
||||
.unwrap_or_else(|()| first.clone());
|
||||
Ok(BorderRadiusSize(Size2D::new(first, second)))
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for BorderRadiusSize {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
try!(self.0.width.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
self.0.height.to_css(dest)
|
||||
Ok(GenericBorderRadiusSize(Size2D::new(first, second)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue