Derive HasViewportPercentage 🍷

This commit is contained in:
Anthony Ramine 2017-05-20 01:36:34 +02:00
parent d1e31f7aa4
commit 90bae7f802
27 changed files with 202 additions and 452 deletions

View file

@ -21,7 +21,7 @@ use std::fmt;
use std::io::Write;
use style_traits::ToCss;
use style_traits::values::specified::AllowedNumericType;
use super::{Auto, CSSFloat, CSSInteger, HasViewportPercentage, Either, None_};
use super::{Auto, CSSFloat, CSSInteger, Either, None_};
use super::computed::{self, Context};
use super::computed::{Shadow as ComputedShadow, ToComputedValue};
use super::generics::BorderRadiusSize as GenericBorderRadiusSize;
@ -76,8 +76,6 @@ impl ComputedValueAsSpecified for SpecifiedUrl {}
no_viewport_percentage!(SpecifiedUrl);
}
no_viewport_percentage!(i32); // For PropertyDeclaration::Order
#[derive(Clone, PartialEq, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[allow(missing_docs)]
@ -289,7 +287,7 @@ impl Parse for BorderRadiusSize {
}
}
#[derive(Clone, PartialEq, Copy, Debug)]
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
/// An angle consisting of a value and a unit.
///
@ -455,7 +453,7 @@ pub fn parse_border_width(context: &ParserContext, input: &mut Parser) -> Result
})
}
#[derive(Clone, PartialEq, Debug)]
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[allow(missing_docs)]
pub enum BorderWidth {
@ -507,15 +505,6 @@ impl ToCss for BorderWidth {
}
}
impl HasViewportPercentage for BorderWidth {
fn has_viewport_percentage(&self) -> bool {
match *self {
BorderWidth::Thin | BorderWidth::Medium | BorderWidth::Thick => false,
BorderWidth::Width(ref length) => length.has_viewport_percentage()
}
}
}
impl ToComputedValue for BorderWidth {
type ComputedValue = Au;
@ -950,7 +939,7 @@ pub type TrackList = GenericTrackList<TrackSizeOrRepeat>;
/// `<track-list> | none`
pub type TrackListOrNone = Either<TrackList, None_>;
#[derive(Debug, Clone, PartialEq)]
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[allow(missing_docs)]
pub struct Shadow {
@ -962,15 +951,6 @@ pub struct Shadow {
pub inset: bool,
}
impl HasViewportPercentage for Shadow {
fn has_viewport_percentage(&self) -> bool {
self.offset_x.has_viewport_percentage() ||
self.offset_y.has_viewport_percentage() ||
self.blur_radius.has_viewport_percentage() ||
self.spread_radius.has_viewport_percentage()
}
}
impl ToComputedValue for Shadow {
type ComputedValue = ComputedShadow;
@ -1230,16 +1210,7 @@ impl LengthOrPercentageOrNumber {
}
}
impl HasViewportPercentage for ClipRect {
fn has_viewport_percentage(&self) -> bool {
self.top.as_ref().map_or(false, |x| x.has_viewport_percentage()) ||
self.right.as_ref().map_or(false, |x| x.has_viewport_percentage()) ||
self.bottom.as_ref().map_or(false, |x| x.has_viewport_percentage()) ||
self.left.as_ref().map_or(false, |x| x.has_viewport_percentage())
}
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
/// rect(<top>, <left>, <bottom>, <right>) used by clip and image-region
pub struct ClipRect {