diff --git a/components/style/cbindgen.toml b/components/style/cbindgen.toml index 7248ab11c1a..104893701c5 100644 --- a/components/style/cbindgen.toml +++ b/components/style/cbindgen.toml @@ -89,6 +89,8 @@ include = [ "BackgroundSize", "BorderImageSlice", "NonNegativeLengthOrNumberRect", + "Perspective", + "ZIndex", ] item_types = ["enums", "structs", "typedefs"] diff --git a/components/style/gecko/values.rs b/components/style/gecko/values.rs index 56f0ed4464d..fa1c7d1f6d3 100644 --- a/components/style/gecko/values.rs +++ b/components/style/gecko/values.rs @@ -14,7 +14,6 @@ use crate::values::computed::basic_shape::ShapeRadius as ComputedShapeRadius; 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::gecko::ScrollSnapPoint; use crate::values::generics::grid::{TrackBreadth, TrackKeyword}; use crate::values::generics::length::LengthPercentageOrAuto; @@ -330,27 +329,6 @@ impl GeckoStyleCoordConvertible for ScrollSnapPoint { } } -impl GeckoStyleCoordConvertible for Perspective -where - L: GeckoStyleCoordConvertible, -{ - fn to_gecko_style_coord(&self, coord: &mut T) { - match *self { - Perspective::None => coord.set_value(CoordDataValue::None), - Perspective::Length(ref l) => l.to_gecko_style_coord(coord), - }; - } - - fn from_gecko_style_coord(coord: &T) -> Option { - use crate::gecko_bindings::structs::root::nsStyleUnit; - - if coord.unit() == nsStyleUnit::eStyleUnit_None { - return Some(Perspective::None); - } - Some(Perspective::Length(L::from_gecko_style_coord(coord)?)) - } -} - /// Convert a given RGBA value to `nscolor`. pub fn convert_rgba_to_nscolor(rgba: &RGBA) -> u32 { ((rgba.alpha as u32) << 24) | diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index c3e788c9e10..ca1a75df321 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -60,7 +60,6 @@ use crate::values::computed::BorderStyle; use crate::values::computed::font::FontSize; use crate::values::computed::effects::{BoxShadow, Filter, SimpleShadow}; use crate::values::generics::column::ColumnCount; -use crate::values::generics::position::ZIndex; use crate::values::generics::transform::TransformStyle; use crate::values::generics::url::UrlOrNone; @@ -1378,7 +1377,7 @@ impl Clone for ${style_struct.gecko_struct_name} { "Opacity": impl_simple, "OverflowWrap": impl_simple, "OverflowAnchor": impl_simple, - "Perspective": impl_style_coord, + "Perspective": impl_simple, "Position": impl_simple, "RGBAColor": impl_rgba_color, "SVGLength": impl_svg_length, @@ -1389,6 +1388,7 @@ impl Clone for ${style_struct.gecko_struct_name} { "TransformOrigin": impl_transform_origin, "UserSelect": impl_simple, "url::UrlOrNone": impl_css_url, + "ZIndex": impl_simple, } def longhand_method(longhand): @@ -1655,7 +1655,7 @@ fn static_assert() { <% skip_position_longhands = " ".join(x.ident for x in SIDES + GRID_LINES) %> <%self:impl_trait style_struct_name="Position" - skip_longhands="${skip_position_longhands} z-index order + skip_longhands="${skip_position_longhands} order align-content justify-content align-self justify-self align-items justify-items grid-auto-rows grid-auto-columns @@ -1665,38 +1665,6 @@ fn static_assert() { <% impl_split_style_coord(side.ident, "mOffset", side.index) %> % endfor - pub fn set_z_index(&mut self, v: longhands::z_index::computed_value::T) { - match v { - ZIndex::Integer(n) => self.gecko.mZIndex.set_value(CoordDataValue::Integer(n)), - ZIndex::Auto => self.gecko.mZIndex.set_value(CoordDataValue::Auto), - } - } - - pub fn copy_z_index_from(&mut self, other: &Self) { - use crate::gecko_bindings::structs::nsStyleUnit; - // z-index is never a calc(). If it were, we'd be leaking here, so - // assert that it isn't. - debug_assert_ne!(self.gecko.mZIndex.unit(), nsStyleUnit::eStyleUnit_Calc); - unsafe { - self.gecko.mZIndex.copy_from_unchecked(&other.gecko.mZIndex); - } - } - - pub fn reset_z_index(&mut self, other: &Self) { - self.copy_z_index_from(other) - } - - pub fn clone_z_index(&self) -> longhands::z_index::computed_value::T { - return match self.gecko.mZIndex.as_value() { - CoordDataValue::Integer(n) => ZIndex::Integer(n), - CoordDataValue::Auto => ZIndex::Auto, - _ => { - debug_assert!(false); - ZIndex::Integer(0) - } - } - } - % for kind in ["align", "justify"]: ${impl_simple_type_with_conversion(kind + "_content")} ${impl_simple_type_with_conversion(kind + "_self")} diff --git a/components/style/values/generics/box.rs b/components/style/values/generics/box.rs index 8a8dc58fd92..f49cba4c2e1 100644 --- a/components/style/values/generics/box.rs +++ b/components/style/values/generics/box.rs @@ -74,6 +74,7 @@ pub enum AnimationIterationCount { Copy, Debug, MallocSizeOf, + Parse, PartialEq, SpecifiedValueInfo, ToAnimatedValue, @@ -81,13 +82,16 @@ pub enum AnimationIterationCount { ToComputedValue, ToCss, )] -pub enum Perspective { +#[repr(C, u8)] +pub enum GenericPerspective { /// A non-negative length. Length(NonNegativeLength), /// The keyword `none`. None, } +pub use self::GenericPerspective as Perspective; + impl Perspective { /// Returns `none`. #[inline] diff --git a/components/style/values/generics/position.rs b/components/style/values/generics/position.rs index 2916a64f777..3eae408164d 100644 --- a/components/style/values/generics/position.rs +++ b/components/style/values/generics/position.rs @@ -45,18 +45,22 @@ impl Position { Debug, MallocSizeOf, PartialEq, + Parse, SpecifiedValueInfo, ToAnimatedZero, ToComputedValue, ToCss, )] -pub enum ZIndex { +#[repr(C, u8)] +pub enum GenericZIndex { /// An integer value. - Integer(Integer), + Integer(I), /// The keyword `auto`. Auto, } +pub use self::GenericZIndex as ZIndex; + impl ZIndex { /// Returns `auto` #[inline] diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index 06ce826d108..4b39c6e1a2e 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -862,20 +862,6 @@ impl Parse for Contain { /// A specified value for the `perspective` property. pub type Perspective = GenericPerspective; -impl Parse for Perspective { - fn parse<'i, 't>( - context: &ParserContext, - input: &mut Parser<'i, 't>, - ) -> Result> { - if input.try(|i| i.expect_ident_matching("none")).is_ok() { - return Ok(GenericPerspective::None); - } - Ok(GenericPerspective::Length(NonNegativeLength::parse( - context, input, - )?)) - } -} - /// A given transition property, that is either `All`, a longhand or shorthand /// property, or an unsupported or custom property. #[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue)] diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 1896235bf61..de898b35fba 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -585,7 +585,7 @@ impl Parse for PositiveInteger { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - Integer::parse_positive(context, input).map(GreaterThanOrEqualToOne::) + Integer::parse_positive(context, input).map(GreaterThanOrEqualToOne) } } diff --git a/components/style/values/specified/position.rs b/components/style/values/specified/position.rs index b9006ee799b..0212763ec6d 100644 --- a/components/style/values/specified/position.rs +++ b/components/style/values/specified/position.rs @@ -731,15 +731,3 @@ impl GridTemplateAreas { /// A specified value for the `z-index` property. pub type ZIndex = GenericZIndex; - -impl Parse for ZIndex { - fn parse<'i, 't>( - context: &ParserContext, - input: &mut Parser<'i, 't>, - ) -> Result> { - if input.try(|i| i.expect_ident_matching("auto")).is_ok() { - return Ok(GenericZIndex::Auto); - } - Ok(GenericZIndex::Integer(Integer::parse(context, input)?)) - } -}