diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs index 3e5328afc274..ec881ea9bcb8 100644 --- a/components/layout/display_list_builder.rs +++ b/components/layout/display_list_builder.rs @@ -52,9 +52,8 @@ use style::logical_geometry::{LogicalPoint, LogicalRect, LogicalSize, WritingMod use style::properties::{self, ServoComputedValues}; use style::properties::style_structs; use style::servo::restyle_damage::REPAINT; -use style::values::RGBA; -use style::values::computed; -use style::values::computed::{Gradient, GradientKind, LengthOrNone, LengthOrPercentage, LengthOrPercentageOrAuto}; +use style::values::{self, Either, RGBA, computed}; +use style::values::computed::{Gradient, GradientKind, LengthOrPercentage, LengthOrPercentageOrAuto}; use style::values::specified::{AngleOrCorner, HorizontalDirection, VerticalDirection}; use style_traits::cursor::Cursor; use table_cell::CollapsedBordersForCell; @@ -1563,7 +1562,7 @@ impl FragmentDisplayListBuilding for Fragment { let transform = self.transform_matrix(&border_box); let perspective = match self.style().get_effects().perspective { - LengthOrNone::Length(d) => { + Either::First(length) => { let perspective_origin = self.style().get_effects().perspective_origin; let perspective_origin = Point2D::new(model::specified(perspective_origin.horizontal, @@ -1578,11 +1577,11 @@ impl FragmentDisplayListBuilding for Fragment { -perspective_origin.y, 0.0); - let perspective_matrix = create_perspective_matrix(d); + let perspective_matrix = create_perspective_matrix(length); pre_transform.pre_mul(&perspective_matrix).pre_mul(&post_transform) } - LengthOrNone::None => { + Either::Second(values::None_) => { Matrix4D::identity() } }; diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 1fa3ae0612a0..e1079804f206 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -49,7 +49,8 @@ use style::properties::ServoComputedValues; use style::selector_impl::RestyleDamage; use style::servo::restyle_damage::RECONSTRUCT_FLOW; use style::str::char_is_whitespace; -use style::values::computed::{LengthOrNone, LengthOrPercentage, LengthOrPercentageOrAuto}; +use style::values::Either; +use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto}; use style::values::computed::LengthOrPercentageOrNone; use text; use text::TextRunScanner; @@ -2579,7 +2580,7 @@ impl Fragment { // TODO(mrobinson): Determine if this is necessary, since blocks with // transformations already create stacking contexts. - if self.style().get_effects().perspective != LengthOrNone::None { + if let Either::First(ref _length) = self.style().get_effects().perspective { return true } diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index fe7bac7efe9a..9c0aa6161367 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -178,7 +178,7 @@ use parser::{ParserContext, ParserContextExtraData}; use properties::{CSSWideKeyword, DeclaredValue, Shorthand}; % endif - #[allow(unused_imports)] + use values::{Auto, Either, None_, Normal}; use cascade_info::CascadeInfo; use error_reporting::ParseErrorReporter; use parser::Parse; diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index 8b8e3c0b92f9..39f9abaf29bb 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -22,6 +22,7 @@ use std::cmp; use std::fmt; use style_traits::ToCss; use super::ComputedValues; +use values::Either; use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; use values::computed::{BorderRadiusSize, LengthOrNone}; use values::computed::{CalcLengthOrPercentage, LengthOrPercentage}; @@ -682,8 +683,8 @@ impl Interpolate for BoxShadow { impl Interpolate for LengthOrNone { fn interpolate(&self, other: &Self, progress: f64) -> Result { match (*self, *other) { - (LengthOrNone::Length(ref len), LengthOrNone::Length(ref other)) => - len.interpolate(&other, progress).map(LengthOrNone::Length), + (Either::First(ref length), Either::First(ref other)) => + length.interpolate(&other, progress).map(Either::First), _ => Err(()), } } diff --git a/components/style/properties/longhand/effects.mako.rs b/components/style/properties/longhand/effects.mako.rs index 5949bc48704e..87595133b91d 100644 --- a/components/style/properties/longhand/effects.mako.rs +++ b/components/style/properties/longhand/effects.mako.rs @@ -1395,7 +1395,7 @@ ${helpers.single_keyword("transform-style", ${helpers.predefined_type("perspective", "LengthOrNone", - "computed::LengthOrNone::None", + "Either::Second(None_)", products="servo", animatable=True)} diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index ca72c0c38aa1..dfa2593e1cb3 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -30,6 +30,7 @@ use logical_geometry::WritingMode; use parser::{ParserContext, ParserContextExtraData}; use style_traits::ToCss; use stylesheets::Origin; +#[cfg(feature = "servo")] use values::Either; use values::{HasViewportPercentage, computed}; use cascade_info::CascadeInfo; use rule_tree::StrongRuleNode; @@ -1249,7 +1250,7 @@ impl ComputedValues { if effects.transform.0.is_some() { return transform_style::T::flat; } - if effects.perspective != computed::LengthOrNone::None { + if let Either::First(ref _length) = effects.perspective { return transform_style::T::flat; } } diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index 5d3044c3ac7e..b08c3806cebc 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -7,7 +7,7 @@ use ordered_float::NotNaN; use std::fmt; use style_traits::ToCss; use super::{Number, ToComputedValue, Context}; -use values::{CSSFloat, specified}; +use values::{CSSFloat, Either, None_, specified}; pub use cssparser::Color as CSSColor; pub use super::image::{EndingShape as GradientShape, Gradient, GradientKind, Image}; @@ -452,61 +452,7 @@ impl ToCss for LengthOrPercentageOrNone { } } -#[derive(PartialEq, Clone, Copy)] -#[cfg_attr(feature = "servo", derive(HeapSizeOf))] -pub enum LengthOrNone { - Length(Au), - None, -} - -impl fmt::Debug for LengthOrNone { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - LengthOrNone::Length(length) => write!(f, "{:?}", length), - LengthOrNone::None => write!(f, "none"), - } - } -} - -impl ToComputedValue for specified::LengthOrNone { - type ComputedValue = LengthOrNone; - - #[inline] - fn to_computed_value(&self, context: &Context) -> LengthOrNone { - match *self { - specified::LengthOrNone::Length(specified::Length::Calc(calc, range)) => { - LengthOrNone::Length(range.clamp(calc.to_computed_value(context).length())) - } - specified::LengthOrNone::Length(value) => { - LengthOrNone::Length(value.to_computed_value(context)) - } - specified::LengthOrNone::None => { - LengthOrNone::None - } - } - } - - #[inline] - fn from_computed_value(computed: &LengthOrNone) -> Self { - match *computed { - LengthOrNone::Length(au) => { - specified::LengthOrNone::Length(ToComputedValue::from_computed_value(&au)) - } - LengthOrNone::None => { - specified::LengthOrNone::None - } - } - } -} - -impl ToCss for LengthOrNone { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - match *self { - LengthOrNone::Length(length) => length.to_css(dest), - LengthOrNone::None => dest.write_str("none"), - } - } -} +pub type LengthOrNone = Either; #[derive(Clone, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index c73fcd73e83c..14e4f49d76cd 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -12,6 +12,7 @@ use super::{CSSFloat, specified}; pub use cssparser::Color as CSSColor; pub use self::image::{EndingShape as GradientShape, Gradient, GradientKind, Image}; pub use self::image::{LengthOrKeyword, LengthOrPercentageOrKeyword}; +pub use super::{Either, None_}; pub use super::specified::{Angle, BorderStyle, Time, UrlExtraData, UrlOrNone}; pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto}; pub use self::length::{LengthOrPercentageOrAutoOrContent, LengthOrPercentageOrNone, LengthOrNone}; diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index a0ed172cab14..a8b33cb041e6 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -13,7 +13,7 @@ use std::ops::Mul; use style_traits::ToCss; use style_traits::values::specified::AllowedNumericType; use super::{Angle, Number, SimplifiedValueNode, SimplifiedSumNode, Time}; -use values::{CSSFloat, FONT_MEDIUM_PX, HasViewportPercentage, computed}; +use values::{CSSFloat, Either, FONT_MEDIUM_PX, HasViewportPercentage, None_, computed}; pub use super::image::{AngleOrCorner, ColorStop, EndingShape as GradientEndingShape, Gradient}; pub use super::image::{GradientKind, HorizontalDirection, Image, LengthOrKeyword, LengthOrPercentageOrKeyword}; @@ -908,55 +908,12 @@ impl LengthOrPercentageOrNone { } } -#[derive(Clone, PartialEq, Copy, Debug)] -#[cfg_attr(feature = "servo", derive(HeapSizeOf))] -pub enum LengthOrNone { - Length(Length), - None, -} - -impl HasViewportPercentage for LengthOrNone { - fn has_viewport_percentage(&self) -> bool { - match *self { - LengthOrNone::Length(ref length) => length.has_viewport_percentage(), - _ => false - } - } -} +pub type LengthOrNone = Either; -impl ToCss for LengthOrNone { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - match *self { - LengthOrNone::Length(length) => length.to_css(dest), - LengthOrNone::None => dest.write_str("none"), - } - } -} impl LengthOrNone { - fn parse_internal(input: &mut Parser, context: AllowedNumericType) - -> Result - { - match try!(input.next()) { - Token::Dimension(ref value, ref unit) if context.is_ok(value.value) => - Length::parse_dimension(value.value, unit).map(LengthOrNone::Length), - Token::Number(ref value) if value.value == 0. => - Ok(LengthOrNone::Length(Length::Absolute(Au(0)))), - Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => - input.parse_nested_block(|input| { - CalcLengthOrPercentage::parse_length(input, context) - }).map(LengthOrNone::Length), - Token::Ident(ref value) if value.eq_ignore_ascii_case("none") => - Ok(LengthOrNone::None), - _ => Err(()) - } - } - #[inline] - pub fn parse(input: &mut Parser) -> Result { - LengthOrNone::parse_internal(input, AllowedNumericType::All) - } #[inline] pub fn parse_non_negative(input: &mut Parser) -> Result { - LengthOrNone::parse_internal(input, AllowedNumericType::NonNegative) + Length::parse_internal(input, AllowedNumericType::NonNegative).map(Either::First) } } diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 92a8532f52d9..339c565a2401 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -83,7 +83,6 @@ impl ToCss for CSSRGBA { } } - #[derive(Clone, Debug)] pub struct SimplifiedSumNode { values: Vec,