diff --git a/components/style/values/specified/grid.rs b/components/style/values/specified/grid.rs index c0b11ddf146c..97d4f9ed5f0c 100644 --- a/components/style/values/specified/grid.rs +++ b/components/style/values/specified/grid.rs @@ -2,14 +2,14 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -//! A grid line type. +//! Necessary types for [grid](https://drafts.csswg.org/css-grid/). use cssparser::{Parser, Token}; use parser::{Parse, ParserContext}; use std::fmt; use style_traits::ToCss; use values::{CSSFloat, HasViewportPercentage}; -use values::computed::ComputedValueAsSpecified; +use values::computed::{ComputedValueAsSpecified, Context, ToComputedValue}; use values::specified::LengthOrPercentage; #[derive(PartialEq, Clone, Debug)] @@ -159,6 +159,29 @@ impl HasViewportPercentage for TrackBreadth { } } +impl ToComputedValue for TrackBreadth { + type ComputedValue = TrackBreadth; + + #[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), + } + } +} + #[allow(missing_docs)] #[derive(Clone, PartialEq, Debug)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] @@ -229,3 +252,30 @@ impl HasViewportPercentage for TrackSize { } } } + +impl ToComputedValue for TrackSize { + type ComputedValue = TrackSize; + + #[inline] + fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { + match *self { + TrackSize::Breadth(ref b) => TrackSize::Breadth(b.to_computed_value(context)), + TrackSize::MinMax(ref b_1, ref b_2) => + TrackSize::MinMax(b_1.to_computed_value(context), b_2.to_computed_value(context)), + TrackSize::FitContent(ref lop) => TrackSize::FitContent(lop.to_computed_value(context)), + } + } + + #[inline] + fn from_computed_value(computed: &Self::ComputedValue) -> Self { + match *computed { + TrackSize::Breadth(ref b) => + TrackSize::Breadth(ToComputedValue::from_computed_value(b)), + TrackSize::MinMax(ref b_1, ref b_2) => + TrackSize::MinMax(ToComputedValue::from_computed_value(b_1), + ToComputedValue::from_computed_value(b_2)), + TrackSize::FitContent(ref lop) => + TrackSize::FitContent(ToComputedValue::from_computed_value(lop)), + } + } +} diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 64c25c2d509d..d6b4842e59c1 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -22,7 +22,7 @@ use super::computed::Shadow as ComputedShadow; #[cfg(feature = "gecko")] pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, JustifyItems}; -pub use self::grid::GridLine; +pub use self::grid::{GridLine, TrackBreadth, TrackKeyword, TrackSize}; pub use self::image::{AngleOrCorner, ColorStop, EndingShape as GradientEndingShape, Gradient}; pub use self::image::{GradientKind, HorizontalDirection, Image, LengthOrKeyword, LengthOrPercentageOrKeyword}; pub use self::image::{SizeKeyword, VerticalDirection};