diff --git a/components/style/cbindgen.toml b/components/style/cbindgen.toml index 4c0b631d31d..cda462d654e 100644 --- a/components/style/cbindgen.toml +++ b/components/style/cbindgen.toml @@ -79,6 +79,9 @@ include = [ "LengthPercentageOrAuto", "Rect", "IntersectionObserverRootMargin", + "Size", + "MaxSize", + "FlexBasis", ] item_types = ["enums", "structs", "typedefs"] @@ -86,10 +89,12 @@ item_types = ["enums", "structs", "typedefs"] "LengthPercentage" = """ // Defined in nsStyleCoord.h static constexpr inline StyleLengthPercentage Zero(); + static inline StyleLengthPercentage FromAppUnits(nscoord); inline bool HasPercent() const; inline bool ConvertsToLength() const; inline nscoord ToLength() const; inline bool ConvertsToPercentage() const; + inline bool HasLengthAndPercentage() const; inline float ToPercentage() const; inline CSSCoord LengthInCSSPixels() const; inline float Percentage() const; @@ -101,8 +106,41 @@ item_types = ["enums", "structs", "typedefs"] "GenericLengthPercentageOrAuto" = """ inline const StyleLengthPercentage& AsLengthPercentage() const; - inline bool HasPercent() const; inline bool ConvertsToLength() const; + inline nscoord ToLength() const; + inline bool ConvertsToPercentage() const; + inline float ToPercentage() const; + inline bool HasPercent() const; + inline bool HasLengthAndPercentage() const; +""" + +"GenericSize" = """ + inline const StyleLengthPercentage& AsLengthPercentage() const; + inline StyleExtremumLength AsExtremumLength() const; + inline bool ConvertsToLength() const; + inline nscoord ToLength() const; + inline bool ConvertsToPercentage() const; + inline float ToPercentage() const; + inline bool HasPercent() const; + inline bool HasLengthAndPercentage() const; + inline bool BehavesLikeInitialValueOnBlockAxis() const; +""" + +"GenericFlexBasis" = """ + inline bool IsAuto() const; + inline const StyleSize& AsSize() const; +""" + +"GenericMaxSize" = """ + inline const StyleLengthPercentage& AsLengthPercentage() const; + inline StyleExtremumLength AsExtremumLength() const; + inline bool ConvertsToLength() const; + inline nscoord ToLength() const; + inline bool ConvertsToPercentage() const; + inline float ToPercentage() const; + inline bool HasPercent() const; + inline bool HasLengthAndPercentage() const; + inline bool BehavesLikeInitialValueOnBlockAxis() const; """ "Rect" = """ diff --git a/components/style/gecko/values.rs b/components/style/gecko/values.rs index 33706f70537..8aad380ab44 100644 --- a/components/style/gecko/values.rs +++ b/components/style/gecko/values.rs @@ -7,22 +7,18 @@ //! Different kind of helpers to interact with Gecko values. use crate::counter_style::{Symbol, Symbols}; -use crate::gecko_bindings::structs::{self, nsStyleCoord, CounterStylePtr}; +use crate::gecko_bindings::structs::{nsStyleCoord, CounterStylePtr}; use crate::gecko_bindings::structs::{StyleGridTrackBreadth, StyleShapeRadius}; use crate::gecko_bindings::sugar::ns_style_coord::{CoordData, CoordDataMut, CoordDataValue}; use crate::media_queries::Device; use crate::values::computed::basic_shape::ShapeRadius as ComputedShapeRadius; -use crate::values::computed::FlexBasis as ComputedFlexBasis; -use crate::values::computed::{Angle, ExtremumLength, Length, LengthPercentage}; -use crate::values::computed::{MaxSize as ComputedMaxSize, Size as ComputedSize}; -use crate::values::computed::{NonNegativeLengthPercentage, Percentage}; -use crate::values::computed::{Number, NumberOrPercentage}; +use crate::values::computed::{Angle, Length, LengthPercentage}; +use crate::values::computed::{Number, NumberOrPercentage, Percentage}; use crate::values::generics::basic_shape::ShapeRadius; use crate::values::generics::box_::Perspective; -use crate::values::generics::flex::FlexBasis; use crate::values::generics::gecko::ScrollSnapPoint; use crate::values::generics::grid::{TrackBreadth, TrackKeyword}; -use crate::values::generics::length::{LengthPercentageOrAuto, MaxSize, Size}; +use crate::values::generics::length::LengthPercentageOrAuto; use crate::values::generics::{CounterStyleOrNone, NonNegative}; use crate::values::{Auto, Either, None_, Normal}; use crate::Atom; @@ -80,29 +76,6 @@ where } } -impl GeckoStyleCoordConvertible for ComputedFlexBasis { - fn to_gecko_style_coord(&self, coord: &mut T) { - match *self { - FlexBasis::Content => coord.set_value(CoordDataValue::Enumerated( - structs::NS_STYLE_FLEX_BASIS_CONTENT, - )), - FlexBasis::Width(ref w) => w.to_gecko_style_coord(coord), - } - } - - fn from_gecko_style_coord(coord: &T) -> Option { - if let Some(width) = ComputedSize::from_gecko_style_coord(coord) { - return Some(FlexBasis::Width(width)); - } - - if let CoordDataValue::Enumerated(structs::NS_STYLE_FLEX_BASIS_CONTENT) = coord.as_value() { - return Some(FlexBasis::Content); - } - - None - } -} - impl GeckoStyleCoordConvertible for Number { fn to_gecko_style_coord(&self, coord: &mut T) { coord.set_value(CoordDataValue::Factor(*self)); @@ -336,60 +309,6 @@ impl GeckoStyleCoordConvertible for Normal { } } -impl GeckoStyleCoordConvertible for ExtremumLength { - fn to_gecko_style_coord(&self, coord: &mut T) { - coord.set_value(CoordDataValue::Enumerated(*self as u32)); - } - - fn from_gecko_style_coord(coord: &T) -> Option { - use num_traits::FromPrimitive; - match coord.as_value() { - CoordDataValue::Enumerated(v) => ExtremumLength::from_u32(v), - _ => None, - } - } -} - -impl GeckoStyleCoordConvertible for ComputedSize { - fn to_gecko_style_coord(&self, coord: &mut T) { - match *self { - Size::LengthPercentage(ref lpoa) => lpoa.to_gecko_style_coord(coord), - Size::Auto => coord.set_value(CoordDataValue::Auto), - Size::ExtremumLength(ref e) => e.to_gecko_style_coord(coord), - } - } - - fn from_gecko_style_coord(coord: &T) -> Option { - if let CoordDataValue::Auto = coord.as_value() { - return Some(Size::Auto); - } - if let Some(lp) = NonNegativeLengthPercentage::from_gecko_style_coord(coord) { - return Some(Size::LengthPercentage(lp)); - } - ExtremumLength::from_gecko_style_coord(coord).map(Size::ExtremumLength) - } -} - -impl GeckoStyleCoordConvertible for ComputedMaxSize { - fn to_gecko_style_coord(&self, coord: &mut T) { - match *self { - MaxSize::LengthPercentage(ref lpon) => lpon.to_gecko_style_coord(coord), - MaxSize::None => coord.set_value(CoordDataValue::None), - MaxSize::ExtremumLength(ref e) => e.to_gecko_style_coord(coord), - } - } - - fn from_gecko_style_coord(coord: &T) -> Option { - if let CoordDataValue::None = coord.as_value() { - return Some(MaxSize::None); - } - if let Some(lp) = NonNegativeLengthPercentage::from_gecko_style_coord(coord) { - return Some(MaxSize::LengthPercentage(lp)); - } - ExtremumLength::from_gecko_style_coord(coord).map(MaxSize::ExtremumLength) - } -} - 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 6baae1d9063..26f786923c7 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -1385,13 +1385,13 @@ impl Clone for ${style_struct.gecko_struct_name} { "length::NonNegativeLengthOrAuto": impl_style_coord, "length::NonNegativeLengthPercentageOrNormal": impl_style_coord, "FillRule": impl_simple, - "FlexBasis": impl_style_coord, + "FlexBasis": impl_simple, "Length": impl_absolute_length, "LengthOrNormal": impl_style_coord, "LengthPercentage": impl_simple, "LengthPercentageOrAuto": impl_style_coord, - "MaxSize": impl_style_coord, - "Size": impl_style_coord, + "MaxSize": impl_simple, + "Size": impl_simple, "MozScriptMinSize": impl_absolute_length, "MozScriptSizeMultiplier": impl_simple, "NonNegativeLengthPercentage": impl_simple, diff --git a/components/style/properties/longhands/position.mako.rs b/components/style/properties/longhands/position.mako.rs index 714de149b56..2e9517cc853 100644 --- a/components/style/properties/longhands/position.mako.rs +++ b/components/style/properties/longhands/position.mako.rs @@ -225,7 +225,7 @@ ${helpers.predefined_type( extra_prefixes="webkit", animation_value_type="ComputedValue", spec="https://drafts.csswg.org/css-flexbox/#order-property", - servo_restyle_damage = "reflow", + servo_restyle_damage="reflow", )} ${helpers.predefined_type( @@ -235,7 +235,8 @@ ${helpers.predefined_type( spec="https://drafts.csswg.org/css-flexbox/#flex-basis-property", extra_prefixes="webkit", animation_value_type="FlexBasis", - servo_restyle_damage = "reflow", + servo_restyle_damage="reflow", + boxed=True, )} % for (size, logical) in ALL_SIZES: diff --git a/components/style/values/computed/flex.rs b/components/style/values/computed/flex.rs index c0c2703732f..95c497ecf63 100644 --- a/components/style/values/computed/flex.rs +++ b/components/style/values/computed/flex.rs @@ -14,6 +14,6 @@ impl FlexBasis { /// `auto` #[inline] pub fn auto() -> Self { - GenericFlexBasis::Width(Size::auto()) + GenericFlexBasis::Size(Size::auto()) } } diff --git a/components/style/values/generics/flex.rs b/components/style/values/generics/flex.rs index 31e32a91f81..258247ec2a8 100644 --- a/components/style/values/generics/flex.rs +++ b/components/style/values/generics/flex.rs @@ -19,9 +19,12 @@ ToComputedValue, ToCss, )] -pub enum FlexBasis { +#[repr(C)] +pub enum GenericFlexBasis { /// `content` Content, /// `` - Width(Width), + Size(S), } + +pub use self::GenericFlexBasis as FlexBasis; diff --git a/components/style/values/generics/grid.rs b/components/style/values/generics/grid.rs index 7dbee9b8dbe..6650996c794 100644 --- a/components/style/values/generics/grid.rs +++ b/components/style/values/generics/grid.rs @@ -192,10 +192,7 @@ impl TrackBreadth { /// #[inline] pub fn is_fixed(&self) -> bool { - match *self { - TrackBreadth::Breadth(ref _lp) => true, - _ => false, - } + matches!(*self, TrackBreadth::Breadth(..)) } } diff --git a/components/style/values/generics/length.rs b/components/style/values/generics/length.rs index f55db4f52c5..64860bd07b2 100644 --- a/components/style/values/generics/length.rs +++ b/components/style/values/generics/length.rs @@ -96,14 +96,17 @@ impl Parse for LengthPercentageOrAuto ToComputedValue, ToCss, )] -pub enum Size { - LengthPercentage(LengthPercentage), +#[repr(C, u8)] +pub enum GenericSize { + LengthPercentage(LengthPercent), Auto, #[cfg(feature = "gecko")] #[animation(error)] ExtremumLength(ExtremumLength), } +pub use self::GenericSize as Size; + impl Size { /// `auto` value. #[inline] @@ -134,14 +137,17 @@ impl Size { ToComputedValue, ToCss, )] -pub enum MaxSize { - LengthPercentage(LengthPercentage), +#[repr(C, u8)] +pub enum GenericMaxSize { + LengthPercentage(LengthPercent), None, #[cfg(feature = "gecko")] #[animation(error)] ExtremumLength(ExtremumLength), } +pub use self::GenericMaxSize as MaxSize; + impl MaxSize { /// `none` value. #[inline] diff --git a/components/style/values/specified/flex.rs b/components/style/values/specified/flex.rs index a1131dbff5f..4c5bf0efb4b 100644 --- a/components/style/values/specified/flex.rs +++ b/components/style/values/specified/flex.rs @@ -18,8 +18,8 @@ impl Parse for FlexBasis { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(width) = input.try(|i| Size::parse(context, i)) { - return Ok(GenericFlexBasis::Width(width)); + if let Ok(size) = input.try(|i| Size::parse(context, i)) { + return Ok(GenericFlexBasis::Size(size)); } try_match_ident_ignore_ascii_case! { input, "content" => Ok(GenericFlexBasis::Content), @@ -31,12 +31,12 @@ impl FlexBasis { /// `auto` #[inline] pub fn auto() -> Self { - GenericFlexBasis::Width(Size::auto()) + GenericFlexBasis::Size(Size::auto()) } /// `0%` #[inline] pub fn zero_percent() -> Self { - GenericFlexBasis::Width(Size::zero_percent()) + GenericFlexBasis::Size(Size::zero_percent()) } }