diff --git a/components/style/gecko/values.rs b/components/style/gecko/values.rs index 946fa437d64..8b05e1520b4 100644 --- a/components/style/gecko/values.rs +++ b/components/style/gecko/values.rs @@ -18,7 +18,7 @@ use crate::values::generics::gecko::ScrollSnapPoint; use crate::values::generics::grid::{TrackBreadth, TrackKeyword}; use crate::values::generics::length::LengthPercentageOrAuto; use crate::values::generics::{CounterStyleOrNone, NonNegative}; -use crate::values::{Auto, Either, None_, Normal}; +use crate::values::Either; use crate::{Atom, Zero}; use app_units::Au; use cssparser::RGBA; @@ -44,23 +44,6 @@ impl nsStyleCoord { } } -impl GeckoStyleCoordConvertible - for Either -{ - fn to_gecko_style_coord(&self, coord: &mut T) { - match *self { - Either::First(ref v) => v.to_gecko_style_coord(coord), - Either::Second(ref v) => v.to_gecko_style_coord(coord), - } - } - - fn from_gecko_style_coord(coord: &T) -> Option { - A::from_gecko_style_coord(coord) - .map(Either::First) - .or_else(|| B::from_gecko_style_coord(coord).map(Either::Second)) - } -} - impl GeckoStyleCoordConvertible for NonNegative where Inner: GeckoStyleCoordConvertible, @@ -265,48 +248,6 @@ impl GeckoStyleCoordConvertible for Angle { } } -impl GeckoStyleCoordConvertible for Auto { - fn to_gecko_style_coord(&self, coord: &mut T) { - coord.set_value(CoordDataValue::Auto) - } - - fn from_gecko_style_coord(coord: &T) -> Option { - if let CoordDataValue::Auto = coord.as_value() { - Some(Auto) - } else { - None - } - } -} - -impl GeckoStyleCoordConvertible for None_ { - fn to_gecko_style_coord(&self, coord: &mut T) { - coord.set_value(CoordDataValue::None) - } - - fn from_gecko_style_coord(coord: &T) -> Option { - if let CoordDataValue::None = coord.as_value() { - Some(None_) - } else { - None - } - } -} - -impl GeckoStyleCoordConvertible for Normal { - fn to_gecko_style_coord(&self, coord: &mut T) { - coord.set_value(CoordDataValue::Normal) - } - - fn from_gecko_style_coord(coord: &T) -> Option { - if let CoordDataValue::Normal = coord.as_value() { - Some(Normal) - } else { - None - } - } -} - impl GeckoStyleCoordConvertible for ScrollSnapPoint { fn to_gecko_style_coord(&self, coord: &mut T) { match self.repeated() { diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 837a295fb60..81e1ee4307d 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -1190,7 +1190,6 @@ impl Clone for ${style_struct.gecko_struct_name} { # Types used with predefined_type()-defined properties that we can auto-generate. predefined_types = { - "length::NonNegativeLengthPercentageOrNormal": impl_style_coord, "MozScriptMinSize": impl_absolute_length, "SVGLength": impl_svg_length, "SVGOpacity": impl_svg_opacity, diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index c441268975d..8310d537f36 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -105,7 +105,7 @@ #[allow(unused_imports)] use crate::values::{computed, specified}; #[allow(unused_imports)] - use crate::values::{Auto, Either, None_, Normal}; + use crate::values::{Auto, Either, None_}; ${caller.body()} } @@ -292,7 +292,7 @@ #[allow(unused_imports)] use crate::properties::{UnparsedValue, ShorthandId}; #[allow(unused_imports)] - use crate::values::{Auto, Either, None_, Normal}; + use crate::values::{Auto, Either, None_}; #[allow(unused_imports)] use crate::error_reporting::ParseErrorReporter; #[allow(unused_imports)] diff --git a/components/style/properties/longhands/position.mako.rs b/components/style/properties/longhands/position.mako.rs index 725f0862a99..096349f4b1c 100644 --- a/components/style/properties/longhands/position.mako.rs +++ b/components/style/properties/longhands/position.mako.rs @@ -372,7 +372,7 @@ ${helpers.predefined_type( ${helpers.predefined_type( "column-gap", "length::NonNegativeLengthPercentageOrNormal", - "Either::Second(Normal)", + "computed::length::NonNegativeLengthPercentageOrNormal::normal()", alias="grid-column-gap" if product == "gecko" else "", extra_prefixes="moz", servo_pref="layout.columns.enabled", @@ -385,7 +385,7 @@ ${helpers.predefined_type( ${helpers.predefined_type( "row-gap", "length::NonNegativeLengthPercentageOrNormal", - "Either::Second(Normal)", + "computed::length::NonNegativeLengthPercentageOrNormal::normal()", alias="grid-row-gap", products="gecko", spec="https://drafts.csswg.org/css-align-3/#propdef-row-gap", diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index 92215541e8a..1e1fedd41bf 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -10,12 +10,13 @@ use crate::values::computed::NonNegativeNumber; use crate::values::distance::{ComputeSquaredDistance, SquaredDistance}; use crate::values::generics::length as generics; use crate::values::generics::length::{ - GenericLengthOrNumber, MaxSize as GenericMaxSize, Size as GenericSize, + GenericLengthPercentageOrNormal, GenericLengthOrNumber, + GenericMaxSize, GenericSize, }; use crate::values::generics::NonNegative; use crate::values::specified::length::ViewportPercentageLength; use crate::values::specified::length::{AbsoluteLength, FontBaseSize, FontRelativeLength}; -use crate::values::{specified, CSSFloat, Either, Normal}; +use crate::values::{specified, CSSFloat}; use crate::Zero; use app_units::Au; use ordered_float::NotNan; @@ -782,7 +783,7 @@ impl From for Au { } /// Either a computed NonNegativeLengthPercentage or the `normal` keyword. -pub type NonNegativeLengthPercentageOrNormal = Either; +pub type NonNegativeLengthPercentageOrNormal = GenericLengthPercentageOrNormal; /// Either a non-negative `` or a ``. pub type NonNegativeLengthOrNumber = GenericLengthOrNumber; diff --git a/components/style/values/generics/length.rs b/components/style/values/generics/length.rs index 1275e739cfe..1665f144778 100644 --- a/components/style/values/generics/length.rs +++ b/components/style/values/generics/length.rs @@ -219,3 +219,38 @@ impl Zero for LengthOrNumber { } } } + +/// A generic `` | normal` value. +#[derive( + Animate, + Clone, + ComputeSquaredDistance, + Copy, + Debug, + MallocSizeOf, + Parse, + PartialEq, + SpecifiedValueInfo, + ToAnimatedValue, + ToAnimatedZero, + ToComputedValue, + ToCss, + ToResolvedValue, + ToShmem, +)] +#[repr(C, u8)] +#[allow(missing_docs)] +pub enum GenericLengthPercentageOrNormal { + LengthPercentage(LengthPercent), + Normal, +} + +pub use self::GenericLengthPercentageOrNormal as LengthPercentageOrNormal; + +impl LengthPercentageOrNormal { + /// Returns the normal value. + #[inline] + pub fn normal() -> Self { + LengthPercentageOrNormal::Normal + } +} diff --git a/components/style/values/mod.rs b/components/style/values/mod.rs index b0132d3c341..89f0de816f2 100644 --- a/components/style/values/mod.rs +++ b/components/style/values/mod.rs @@ -39,7 +39,6 @@ pub type CSSInteger = i32; define_keyword_type!(None_, "none"); define_keyword_type!(Auto, "auto"); -define_keyword_type!(Normal, "normal"); /// Serialize an identifier which is represented as an atom. #[cfg(feature = "gecko")] diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index 8d29fe53a00..a6beef91ee5 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -13,12 +13,13 @@ use crate::properties::computed_value_flags::ComputedValueFlags; use crate::values::computed::{self, CSSPixelLength, Context}; use crate::values::generics::length as generics; use crate::values::generics::length::{ - GenericLengthOrNumber, MaxSize as GenericMaxSize, Size as GenericSize, + GenericLengthPercentageOrNormal, GenericLengthOrNumber, + GenericMaxSize, GenericSize, }; use crate::values::generics::NonNegative; use crate::values::specified::calc::CalcNode; use crate::values::specified::NonNegativeNumber; -use crate::values::{CSSFloat, Either, Normal}; +use crate::values::CSSFloat; use crate::Zero; use app_units::Au; use cssparser::{Parser, Token}; @@ -957,7 +958,7 @@ impl NonNegativeLengthPercentageOrAuto { pub type NonNegativeLengthPercentage = NonNegative; /// Either a NonNegativeLengthPercentage or the `normal` keyword. -pub type NonNegativeLengthPercentageOrNormal = Either; +pub type NonNegativeLengthPercentageOrNormal = GenericLengthPercentageOrNormal; impl From for NonNegativeLengthPercentage { #[inline]