diff --git a/components/style/properties/longhand/position.mako.rs b/components/style/properties/longhand/position.mako.rs index cb666a27f38..013b93b2640 100644 --- a/components/style/properties/longhand/position.mako.rs +++ b/components/style/properties/longhand/position.mako.rs @@ -69,8 +69,8 @@ ${helpers.single_keyword("flex-wrap", "nowrap wrap wrap-reverse", animation_value_type="discrete")} % else: ${helpers.predefined_type(name="justify-content", - type="AlignJustifyContent", - initial_value="specified::AlignJustifyContent::normal()", + type="ContentDistribution", + initial_value="specified::ContentDistribution::normal()", spec="https://drafts.csswg.org/css-align/#propdef-justify-content", extra_prefixes="webkit", animation_value_type="discrete")} @@ -90,8 +90,8 @@ ${helpers.single_keyword("flex-wrap", "nowrap wrap wrap-reverse", animation_value_type="discrete")} % else: ${helpers.predefined_type(name="align-content", - type="AlignJustifyContent", - initial_value="specified::AlignJustifyContent::normal()", + type="ContentDistribution", + initial_value="specified::ContentDistribution::normal()", spec="https://drafts.csswg.org/css-align/#propdef-align-content", extra_prefixes="webkit", animation_value_type="discrete")} @@ -138,20 +138,20 @@ ${helpers.predefined_type("flex-shrink", "NonNegativeNumber", animation_value_type="discrete")} % else: ${helpers.predefined_type(name="align-self", - type="AlignJustifySelf", - initial_value="specified::AlignJustifySelf::auto()", + type="SelfAlignment", + initial_value="specified::SelfAlignment::auto()", spec="https://drafts.csswg.org/css-align/#align-self-property", extra_prefixes="webkit", animation_value_type="discrete")} ${helpers.predefined_type(name="justify-self", - type="AlignJustifySelf", - initial_value="specified::AlignJustifySelf::auto()", + type="SelfAlignment", + initial_value="specified::SelfAlignment::auto()", spec="https://drafts.csswg.org/css-align/#justify-self-property", animation_value_type="discrete")} #[cfg(feature = "gecko")] - impl_align_conversions!(::values::specified::align::AlignJustifySelf); + impl_align_conversions!(::values::specified::align::SelfAlignment); % endif // https://drafts.csswg.org/css-flexbox/#propdef-order diff --git a/components/style/properties/shorthand/position.mako.rs b/components/style/properties/shorthand/position.mako.rs index 95a4c183e20..8775eed5c2c 100644 --- a/components/style/properties/shorthand/position.mako.rs +++ b/components/style/properties/shorthand/position.mako.rs @@ -615,18 +615,18 @@ <%helpers:shorthand name="place-content" sub_properties="align-content justify-content" spec="https://drafts.csswg.org/css-align/#propdef-place-content" products="gecko"> - use values::specified::align::{AlignJustifyContent, FallbackAllowed}; + use values::specified::align::{ContentDistribution, FallbackAllowed}; pub fn parse_value<'i, 't>( _: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - let align = AlignJustifyContent::parse_with_fallback(input, FallbackAllowed::No)?; + let align = ContentDistribution::parse_with_fallback(input, FallbackAllowed::No)?; if align.has_extra_flags() { return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)); } let justify = - input.try(|input| AlignJustifyContent::parse_with_fallback(input, FallbackAllowed::No)) + input.try(|input| ContentDistribution::parse_with_fallback(input, FallbackAllowed::No)) .unwrap_or(align); if justify.has_extra_flags() { return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)); @@ -653,16 +653,16 @@ <%helpers:shorthand name="place-self" sub_properties="align-self justify-self" spec="https://drafts.csswg.org/css-align/#place-self-property" products="gecko"> - use values::specified::align::AlignJustifySelf; + use values::specified::align::SelfAlignment; use parser::Parse; pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { - let align = AlignJustifySelf::parse(context, input)?; + let align = SelfAlignment::parse(context, input)?; if align.has_extra_flags() { return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)); } - let justify = input.try(|input| AlignJustifySelf::parse(context, input)).unwrap_or(align.clone()); + let justify = input.try(|input| SelfAlignment::parse(context, input)).unwrap_or(align.clone()); if justify.has_extra_flags() { return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)); } diff --git a/components/style/values/computed/align.rs b/components/style/values/computed/align.rs index 85f8f70cb25..c7bf6a30c6b 100644 --- a/components/style/values/computed/align.rs +++ b/components/style/values/computed/align.rs @@ -11,7 +11,7 @@ use style_traits::{CssWriter, ToCss}; use values::computed::{Context, ToComputedValue}; use values::specified; -pub use super::specified::{AlignItems, AlignJustifyContent, AlignJustifySelf}; +pub use super::specified::{AlignItems, ContentDistribution, SelfAlignment}; /// The computed value for the `justify-items` property. /// diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index a559f4fbe87..7600d23a9d1 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -32,7 +32,7 @@ use super::specified; pub use app_units::Au; pub use properties::animated_properties::TransitionProperty; #[cfg(feature = "gecko")] -pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, JustifyItems}; +pub use self::align::{AlignItems, ContentDistribution, SelfAlignment, JustifyItems}; pub use self::angle::Angle; pub use self::background::{BackgroundSize, BackgroundRepeat}; pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth}; diff --git a/components/style/values/specified/align.rs b/components/style/values/specified/align.rs index a0900d4dc33..584a24b61fb 100644 --- a/components/style/values/specified/align.rs +++ b/components/style/values/specified/align.rs @@ -115,12 +115,12 @@ const ALIGN_ALL_SHIFT: u32 = structs::NS_STYLE_ALIGN_ALL_SHIFT; /// Value of the `align-content` or `justify-content` property. /// /// -/// -/// The 16-bit field stores the primary value in its lower 8 bits, and the optional fallback value -/// in its upper 8 bits. This matches the representation of these properties in Gecko. #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue)] #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] -pub struct AlignJustifyContent(u16); +pub struct ContentDistribution { + primary: AlignFlags, + fallback: AlignFlags, +} /// Whether fallback is allowed in align-content / justify-content parsing. /// @@ -136,8 +136,7 @@ pub enum FallbackAllowed { No, } - -impl AlignJustifyContent { +impl ContentDistribution { /// The initial value 'normal' #[inline] pub fn normal() -> Self { @@ -147,35 +146,34 @@ impl AlignJustifyContent { /// Construct a value with no fallback. #[inline] pub fn new(flags: AlignFlags) -> Self { - AlignJustifyContent(flags.bits() as u16) + Self::with_fallback(flags, AlignFlags::empty()) } /// Construct a value including a fallback alignment. /// /// #[inline] - pub fn with_fallback(flags: AlignFlags, fallback: AlignFlags) -> Self { - AlignJustifyContent(flags.bits() as u16 | ((fallback.bits() as u16) << ALIGN_ALL_SHIFT)) + pub fn with_fallback(primary: AlignFlags, fallback: AlignFlags) -> Self { + Self { primary, fallback } } /// The primary alignment #[inline] pub fn primary(self) -> AlignFlags { - AlignFlags::from_bits((self.0 & ALIGN_ALL_BITS) as u8) - .expect("AlignJustifyContent must contain valid flags") + self.primary } /// The fallback alignment #[inline] pub fn fallback(self) -> AlignFlags { - AlignFlags::from_bits((self.0 >> ALIGN_ALL_SHIFT) as u8) - .expect("AlignJustifyContent must contain valid flags") + self.fallback } /// Whether this value has extra flags. #[inline] pub fn has_extra_flags(self) -> bool { - self.primary().intersects(AlignFlags::FLAG_BITS) || self.fallback().intersects(AlignFlags::FLAG_BITS) + self.primary().intersects(AlignFlags::FLAG_BITS) || + self.fallback().intersects(AlignFlags::FLAG_BITS) } /// Parse a value for align-content / justify-content, optionally allowing @@ -186,32 +184,32 @@ impl AlignJustifyContent { ) -> Result> { // normal | if let Ok(value) = input.try(|input| parse_normal_or_baseline(input)) { - return Ok(AlignJustifyContent::new(value)) + return Ok(ContentDistribution::new(value)) } // followed by optional <*-position> if let Ok(value) = input.try(|input| parse_content_distribution(input)) { if fallback_allowed == FallbackAllowed::Yes { if let Ok(fallback) = input.try(|input| parse_overflow_content_position(input)) { - return Ok(AlignJustifyContent::with_fallback(value, fallback)) + return Ok(ContentDistribution::with_fallback(value, fallback)) } } - return Ok(AlignJustifyContent::new(value)) + return Ok(ContentDistribution::new(value)) } // <*-position> followed by optional let fallback = parse_overflow_content_position(input)?; if fallback_allowed == FallbackAllowed::Yes { if let Ok(value) = input.try(|input| parse_content_distribution(input)) { - return Ok(AlignJustifyContent::with_fallback(value, fallback)) + return Ok(ContentDistribution::with_fallback(value, fallback)) } } - Ok(AlignJustifyContent::new(fallback)) + Ok(ContentDistribution::new(fallback)) } } -impl ToCss for AlignJustifyContent { +impl ToCss for ContentDistribution { fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: Write, @@ -229,7 +227,7 @@ impl ToCss for AlignJustifyContent { } -impl Parse for AlignJustifyContent { +impl Parse for ContentDistribution { // normal | | // [ || [ ? && ] ] fn parse<'i, 't>(_: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { @@ -242,13 +240,13 @@ impl Parse for AlignJustifyContent { /// #[cfg_attr(feature = "gecko", derive(MallocSizeOf))] #[derive(Clone, Copy, Debug, Eq, PartialEq, ToComputedValue, ToCss)] -pub struct AlignJustifySelf(pub AlignFlags); +pub struct SelfAlignment(pub AlignFlags); -impl AlignJustifySelf { +impl SelfAlignment { /// The initial value 'auto' #[inline] pub fn auto() -> Self { - AlignJustifySelf(AlignFlags::AUTO) + SelfAlignment(AlignFlags::AUTO) } /// Whether this value has extra flags. @@ -259,19 +257,16 @@ impl AlignJustifySelf { } -impl Parse for AlignJustifySelf { +impl Parse for SelfAlignment { // auto | normal | stretch | | // [ ? && ] fn parse<'i, 't>(_: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { // auto | normal | stretch | if let Ok(value) = input.try(parse_auto_normal_stretch_baseline) { - return Ok(AlignJustifySelf(value)) + return Ok(SelfAlignment(value)) } // [ ? && ] - if let Ok(value) = input.try(parse_overflow_self_position) { - return Ok(AlignJustifySelf(value)) - } - Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) + Ok(SelfAlignment(parse_overflow_self_position(input)?)) } } @@ -306,10 +301,7 @@ impl Parse for AlignItems { return Ok(AlignItems(value)) } // [ ? && ] - if let Ok(value) = input.try(parse_overflow_self_position) { - return Ok(AlignItems(value)) - } - Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) + Ok(AlignItems(parse_overflow_self_position(input)?)) } } @@ -355,30 +347,33 @@ impl Parse for JustifyItems { return Ok(JustifyItems(value)) } // [ ? && ] - if let Ok(value) = parse_overflow_self_position(input) { - return Ok(JustifyItems(value)) - } - Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) + Ok(JustifyItems(parse_overflow_self_position(input)?)) } } #[cfg(feature = "gecko")] -impl From for AlignJustifyContent { - fn from(bits: u16) -> AlignJustifyContent { - AlignJustifyContent(bits) +impl From for ContentDistribution { + fn from(bits: u16) -> ContentDistribution { + let primary = + AlignFlags::from_bits_truncate((bits & ALIGN_ALL_BITS) as u8); + let fallback = + AlignFlags::from_bits_truncate((bits >> ALIGN_ALL_SHIFT) as u8); + ContentDistribution::with_fallback(primary, fallback) } } #[cfg(feature = "gecko")] -impl From for u16 { - fn from(v: AlignJustifyContent) -> u16 { - v.0 +impl From for u16 { + fn from(v: ContentDistribution) -> u16 { + v.primary().bits() as u16 | + ((v.fallback().bits() as u16) << ALIGN_ALL_SHIFT) } } // auto | normal | stretch | -fn parse_auto_normal_stretch_baseline<'i, 't>(input: &mut Parser<'i, 't>) - -> Result> { +fn parse_auto_normal_stretch_baseline<'i, 't>( + input: &mut Parser<'i, 't>, +) -> Result> { if let Ok(baseline) = input.try(parse_baseline) { return Ok(baseline); } diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 4a0ae8f9cbf..2a9e05f7e75 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -26,7 +26,7 @@ use values::specified::calc::CalcNode; pub use properties::animated_properties::TransitionProperty; pub use self::angle::Angle; #[cfg(feature = "gecko")] -pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, JustifyItems}; +pub use self::align::{AlignItems, ContentDistribution, SelfAlignment, JustifyItems}; pub use self::background::{BackgroundRepeat, BackgroundSize}; pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth}; pub use self::border::{BorderImageSideWidth, BorderRadius, BorderSideWidth, BorderSpacing};