diff options
-rw-r--r-- | components/style/cbindgen.toml | 13 | ||||
-rw-r--r-- | components/style/gecko/conversions.rs | 26 | ||||
-rw-r--r-- | components/style/properties/gecko.mako.rs | 35 | ||||
-rw-r--r-- | components/style/values/generics/position.rs | 10 |
4 files changed, 26 insertions, 58 deletions
diff --git a/components/style/cbindgen.toml b/components/style/cbindgen.toml index fca08a8e2ea..53108f0d273 100644 --- a/components/style/cbindgen.toml +++ b/components/style/cbindgen.toml @@ -82,6 +82,7 @@ include = [ "Size", "MaxSize", "FlexBasis", + "Position", ] item_types = ["enums", "structs", "typedefs"] @@ -90,6 +91,7 @@ item_types = ["enums", "structs", "typedefs"] // Defined in nsStyleCoord.h static constexpr inline StyleLengthPercentage Zero(); static inline StyleLengthPercentage FromAppUnits(nscoord); + static inline StyleLengthPercentage FromPercentage(float); inline CSSCoord LengthInCSSPixels() const; private: inline nscoord LengthComponent() const; @@ -103,8 +105,12 @@ item_types = ["enums", "structs", "typedefs"] inline float ToPercentage() const; inline CSSCoord ResolveToCSSPixels(CSSCoord aPercentageBasisInCSSPixels) const; template<typename T> inline CSSCoord ResolveToCSSPixelsWith(T aPercentageGetter) const; + template<typename T, typename U> + inline nscoord Resolve(T aPercentageGetter, U aPercentRoundingFunction) const; + template<typename T> + inline nscoord Resolve(nscoord aPercentageBasis, T aPercentRoundingFunction) const; + template<typename T> inline nscoord Resolve(T aPercentageGetter) const; inline nscoord Resolve(nscoord aPercentageBasis) const; - template<typename T> inline nscoord ResolveWith(T aPercentageGetter) const; """ "GenericLengthPercentageOrAuto" = """ @@ -146,6 +152,11 @@ item_types = ["enums", "structs", "typedefs"] inline bool BehavesLikeInitialValueOnBlockAxis() const; """ +"GenericPosition" = """ + inline bool DependsOnPositioningAreaSize() const; + static inline StyleGenericPosition FromPercentage(float); +""" + "Rect" = """ // Defined in nsStyleCoord.h template<typename Predicate> inline bool All(Predicate) const; diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs index ccaa16c844c..91dc77c3ceb 100644 --- a/components/style/gecko/conversions.rs +++ b/components/style/gecko/conversions.rs @@ -614,7 +614,6 @@ pub mod basic_shape { //! Conversions from and to CSS shape representations. use crate::gecko::values::GeckoStyleCoordConvertible; - use crate::gecko_bindings::structs; use crate::gecko_bindings::structs::{nsStyleCoord, nsStyleCorners}; use crate::gecko_bindings::structs::{StyleBasicShape, StyleBasicShapeType}; use crate::gecko_bindings::structs::{ @@ -628,7 +627,6 @@ pub mod basic_shape { use crate::values::computed::border::{BorderCornerRadius, BorderRadius}; use crate::values::computed::length::LengthPercentage; use crate::values::computed::motion::OffsetPath; - use crate::values::computed::position; use crate::values::computed::url::ComputedUrl; use crate::values::generics::basic_shape::{ BasicShape as GenericBasicShape, InsetRect, Polygon, @@ -759,12 +757,12 @@ pub mod basic_shape { }, StyleBasicShapeType::Circle => GenericBasicShape::Circle(Circle { radius: (&other.mCoordinates[0]).into(), - position: (&other.mPosition).into(), + position: other.mPosition, }), StyleBasicShapeType::Ellipse => GenericBasicShape::Ellipse(Ellipse { semiaxis_x: (&other.mCoordinates[0]).into(), semiaxis_y: (&other.mCoordinates[1]).into(), - position: (&other.mPosition).into(), + position: other.mPosition, }), StyleBasicShapeType::Polygon => { let mut coords = Vec::with_capacity(other.mCoordinates.len() / 2); @@ -852,17 +850,6 @@ pub mod basic_shape { } } - // Can't be a From impl since we need to set an existing - // Position, not create a new one - impl From<position::Position> for structs::Position { - fn from(other: position::Position) -> Self { - structs::Position { - mXPosition: other.horizontal.into(), - mYPosition: other.vertical.into(), - } - } - } - impl<'a> From<&'a nsStyleCoord> for ShapeRadius { fn from(other: &'a nsStyleCoord) -> Self { let other = other.borrow(); @@ -871,15 +858,6 @@ pub mod basic_shape { } } - impl<'a> From<&'a structs::Position> for position::Position { - fn from(other: &'a structs::Position) -> Self { - position::Position { - horizontal: other.mXPosition.into(), - vertical: other.mYPosition.into(), - } - } - } - impl From<ShapeBox> for StyleGeometryBox { fn from(reference: ShapeBox) -> Self { use crate::gecko_bindings::structs::StyleGeometryBox::*; diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 26f786923c7..11c0c8906f7 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -453,22 +453,6 @@ def set_gecko_property(ffi_name, expr): } </%def> -<%def name="impl_position(ident, gecko_ffi_name)"> - #[allow(non_snake_case)] - pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) { - ${set_gecko_property("%s.mXPosition" % gecko_ffi_name, "v.horizontal.into()")} - ${set_gecko_property("%s.mYPosition" % gecko_ffi_name, "v.vertical.into()")} - } - <%call expr="impl_simple_copy(ident, gecko_ffi_name)"></%call> - #[allow(non_snake_case)] - pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { - longhands::${ident}::computed_value::T { - horizontal: self.gecko.${gecko_ffi_name}.mXPosition.into(), - vertical: self.gecko.${gecko_ffi_name}.mYPosition.into(), - } - } -</%def> - <%def name="impl_color(ident, gecko_ffi_name)"> <%call expr="impl_color_setter(ident, gecko_ffi_name)"></%call> <%call expr="impl_color_copy(ident, gecko_ffi_name)"></%call> @@ -1401,7 +1385,7 @@ impl Clone for ${style_struct.gecko_struct_name} { "OverflowWrap": impl_simple, "OverflowAnchor": impl_simple, "Perspective": impl_style_coord, - "Position": impl_position, + "Position": impl_simple, "RGBAColor": impl_rgba_color, "SVGLength": impl_svg_length, "SVGOpacity": impl_svg_opacity, @@ -3095,11 +3079,7 @@ fn static_assert() { where I: IntoIterator<Item = longhands::scroll_snap_coordinate::computed_value::single_value::T>, I::IntoIter: ExactSizeIterator { - let iter = v.into_iter().map(|c| structs::mozilla::Position { - mXPosition: c.horizontal.into(), - mYPosition: c.vertical.into(), - }); - self.gecko.mScrollSnapCoordinate.assign_from_iter_pod(iter); + self.gecko.mScrollSnapCoordinate.assign_from_iter_pod(v.into_iter()); } pub fn copy_scroll_snap_coordinate_from(&mut self, other: &Self) { @@ -3112,7 +3092,7 @@ fn static_assert() { } pub fn clone_scroll_snap_coordinate(&self) -> longhands::scroll_snap_coordinate::computed_value::T { - let vec = self.gecko.mScrollSnapCoordinate.iter().map(|f| f.into()).collect(); + let vec = self.gecko.mScrollSnapCoordinate.iter().cloned().collect(); longhands::scroll_snap_coordinate::computed_value::List(vec) } @@ -3759,7 +3739,7 @@ fn static_assert() { <% impl_simple_image_array_property("clip", shorthand, image_layers_field, "mClip", struct_name) %> <% impl_simple_image_array_property("origin", shorthand, image_layers_field, "mOrigin", struct_name) %> - % for orientation in ["x", "y"]: + % for (orientation, keyword) in [("x", "horizontal"), ("y", "vertical")]: pub fn copy_${shorthand}_position_${orientation}_from(&mut self, other: &Self) { use crate::gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType; @@ -3774,8 +3754,7 @@ fn static_assert() { for (layer, other) in self.gecko.${image_layers_field}.mLayers.iter_mut() .zip(other.gecko.${image_layers_field}.mLayers.iter()) .take(count as usize) { - layer.mPosition.m${orientation.upper()}Position - = other.mPosition.m${orientation.upper()}Position; + layer.mPosition.${keyword} = other.mPosition.${keyword}; } self.gecko.${image_layers_field}.mPosition${orientation.upper()}Count = count; } @@ -3789,7 +3768,7 @@ fn static_assert() { longhands::${shorthand}_position_${orientation}::computed_value::List( self.gecko.${image_layers_field}.mLayers.iter() .take(self.gecko.${image_layers_field}.mPosition${orientation.upper()}Count as usize) - .map(|position| position.mPosition.m${orientation.upper()}Position.into()) + .map(|position| position.mPosition.${keyword}) .collect() ) } @@ -3812,7 +3791,7 @@ fn static_assert() { self.gecko.${image_layers_field}.mPosition${orientation[0].upper()}Count = v.len() as u32; for (servo, geckolayer) in v.zip(self.gecko.${image_layers_field} .mLayers.iter_mut()) { - geckolayer.mPosition.m${orientation[0].upper()}Position = servo.into(); + geckolayer.mPosition.${keyword} = servo; } } % endfor diff --git a/components/style/values/generics/position.rs b/components/style/values/generics/position.rs index 07612913c0a..2916a64f777 100644 --- a/components/style/values/generics/position.rs +++ b/components/style/values/generics/position.rs @@ -19,20 +19,20 @@ ToAnimatedZero, ToComputedValue, )] -pub struct Position<H, V> { +#[repr(C)] +pub struct GenericPosition<H, V> { /// The horizontal component of position. pub horizontal: H, /// The vertical component of position. pub vertical: V, } +pub use self::GenericPosition as Position; + impl<H, V> Position<H, V> { /// Returns a new position. pub fn new(horizontal: H, vertical: V) -> Self { - Self { - horizontal: horizontal, - vertical: vertical, - } + Self { horizontal, vertical } } } |