Derive ToComputedValue for TrackBreadth<L>

This commit is contained in:
Anthony Ramine 2017-08-28 10:38:11 +02:00
parent 735e093de7
commit 3751fe9fdc
3 changed files with 5 additions and 29 deletions

View file

@ -2265,11 +2265,8 @@ https://drafts.csswg.org/css-fonts-4/#low-level-font-variation-settings-control-
predefined_type="Number" gecko_ffi_name="mScriptSizeMultiplier"
spec="Internal (not web-exposed)"
internal="True">
use values::computed::ComputedValueAsSpecified;
pub use self::computed_value::T as SpecifiedValue;
impl ComputedValueAsSpecified for SpecifiedValue {}
pub mod computed_value {
pub type T = f32;
}

View file

@ -327,6 +327,7 @@ impl<T> ToComputedValue for T
impl ComputedValueAsSpecified for Atom {}
impl ComputedValueAsSpecified for bool {}
impl ComputedValueAsSpecified for f32 {}
impl ComputedValueAsSpecified for specified::BorderStyle {}

View file

@ -10,7 +10,7 @@ use parser::{Parse, ParserContext};
use std::{fmt, mem, usize};
use style_traits::{ToCss, ParseError, StyleParseError};
use values::{CSSFloat, CustomIdent, serialize_dimension};
use values::computed::{ComputedValueAsSpecified, Context, ToComputedValue};
use values::computed::ComputedValueAsSpecified;
use values::specified::Integer;
use values::specified::grid::parse_line_names;
@ -137,13 +137,14 @@ define_css_keyword_enum!{ TrackKeyword:
"max-content" => MaxContent,
"min-content" => MinContent
}
impl ComputedValueAsSpecified for TrackKeyword {}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
/// A track breadth for explicit grid track sizing. It's generic solely to
/// avoid re-implementing it for the computed type.
///
/// https://drafts.csswg.org/css-grid/#typedef-track-breadth
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Debug, PartialEq, ToComputedValue)]
pub enum TrackBreadth<L> {
/// The generic type is almost always a non-negative `<length-percentage>`
Breadth(L),
@ -176,29 +177,6 @@ impl<L: ToCss> ToCss for TrackBreadth<L> {
}
}
impl<L: ToComputedValue> ToComputedValue for TrackBreadth<L> {
type ComputedValue = TrackBreadth<L::ComputedValue>;
#[inline]
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
match *self {
TrackBreadth::Breadth(ref lop) => TrackBreadth::Breadth(lop.to_computed_value(context)),
TrackBreadth::Flex(fr) => TrackBreadth::Flex(fr),
TrackBreadth::Keyword(k) => TrackBreadth::Keyword(k),
}
}
#[inline]
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
match *computed {
TrackBreadth::Breadth(ref lop) =>
TrackBreadth::Breadth(ToComputedValue::from_computed_value(lop)),
TrackBreadth::Flex(fr) => TrackBreadth::Flex(fr),
TrackBreadth::Keyword(k) => TrackBreadth::Keyword(k),
}
}
}
/// A `<track-size>` type for explicit grid track sizing. Like `<track-breadth>`, this is
/// generic only to avoid code bloat. It only takes `<length-percentage>`
///