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

@ -16,6 +16,7 @@ use std::borrow::Cow;
use std::fmt::{self, Debug};
use std::hash;
use style_traits::ToCss;
pub use style_traits::HasViewportPercentage;
pub mod computed;
pub mod generics;
@ -30,24 +31,11 @@ pub type CSSInteger = i32;
/// The default font size.
pub const FONT_MEDIUM_PX: i32 = 16;
/// A trait used to query whether this value has viewport units.
pub trait HasViewportPercentage {
/// Returns true if this value has viewport units.
fn has_viewport_percentage(&self) -> bool;
}
impl<T: HasViewportPercentage> HasViewportPercentage for Box<T> {
#[inline]
fn has_viewport_percentage(&self) -> bool {
(**self).has_viewport_percentage()
}
}
define_keyword_type!(None_, "none");
define_keyword_type!(Auto, "auto");
define_keyword_type!(Normal, "normal");
#[derive(Clone, PartialEq, Copy)]
#[derive(Clone, Copy, HasViewportPercentage, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
/// A struct representing one of two kinds of values.
pub enum Either<A, B> {
@ -75,15 +63,6 @@ impl<A: ToCss, B: ToCss> ToCss for Either<A, B> {
}
}
impl<A: HasViewportPercentage, B: HasViewportPercentage> HasViewportPercentage for Either<A, B> {
fn has_viewport_percentage(&self) -> bool {
match *self {
Either::First(ref v) => v.has_viewport_percentage(),
Either::Second(ref v) => v.has_viewport_percentage(),
}
}
}
impl<A: Parse, B: Parse> Parse for Either<A, B> {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Either<A, B>, ()> {
if let Ok(v) = input.try(|i| A::parse(context, i)) {
@ -209,3 +188,4 @@ define_css_keyword_enum!(ExtremumLength:
"-moz-min-content" => MinContent,
"-moz-fit-content" => FitContent,
"-moz-available" => FillAvailable);
no_viewport_percentage!(ExtremumLength);