From 8b7bb97aa981c9301e0f1dfde3acbc1d7948b4d5 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 6 Feb 2017 17:45:09 -0800 Subject: [PATCH] stylo: Implement object-position MozReview-Commit-ID: 6mr4ktfeEGT --- components/style/properties/gecko.mako.rs | 29 ++++++++++++++----- .../properties/longhand/position.mako.rs | 8 +++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index cd8440f089a..72385f19ea6 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -342,6 +342,25 @@ def set_gecko_property(ffi_name, expr): % endif +<%def name="impl_position(ident, gecko_ffi_name, need_clone=False)"> + #[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)"> + % if need_clone: + #[allow(non_snake_case)] + pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { + use values::computed::Position; + Position { + horizontal: self.gecko.${gecko_ffi_name}.mXPosition.into(), + vertical: self.gecko.${gecko_ffi_name}.mYPosition.into(), + } + } + % endif + + <%def name="impl_color(ident, gecko_ffi_name, need_clone=False, complex_color=True)"> <%call expr="impl_color_setter(ident, gecko_ffi_name, complex_color)"> <%call expr="impl_color_copy(ident, gecko_ffi_name, complex_color)"> @@ -516,6 +535,7 @@ impl Debug for ${style_struct.gecko_struct_name} { predefined_types = { "length::LengthOrAuto": impl_style_coord, "Length": impl_absolute_length, + "Position": impl_position, "LengthOrPercentage": impl_style_coord, "LengthOrPercentageOrAuto": impl_style_coord, "LengthOrPercentageOrNone": impl_style_coord, @@ -1183,7 +1203,7 @@ fn static_assert() { animation-iteration-count animation-timing-function -moz-binding page-break-before page-break-after scroll-snap-points-x scroll-snap-points-y transform - scroll-snap-type-y scroll-snap-destination scroll-snap-coordinate + scroll-snap-type-y scroll-snap-coordinate perspective-origin transform-origin""" %> <%self:impl_trait style_struct_name="Box" skip_longhands="${skip_box_longhands}"> @@ -1355,13 +1375,6 @@ fn static_assert() { ${impl_coord_copy('scroll_snap_points_y', 'mScrollSnapPointsY')} - pub fn set_scroll_snap_destination(&mut self, v: longhands::scroll_snap_destination::computed_value::T) { - self.gecko.mScrollSnapDestination.mXPosition = v.horizontal.into(); - self.gecko.mScrollSnapDestination.mYPosition = v.vertical.into(); - } - - ${impl_simple_copy('scroll_snap_destination', 'mScrollSnapDestination')} - pub fn set_scroll_snap_coordinate(&mut self, v: longhands::scroll_snap_coordinate::computed_value::T) { unsafe { self.gecko.mScrollSnapCoordinate.set_len_pod(v.0.len() as u32); } for (gecko, servo) in self.gecko.mScrollSnapCoordinate diff --git a/components/style/properties/longhand/position.mako.rs b/components/style/properties/longhand/position.mako.rs index 3e55cb2bd3b..4ff10a91839 100644 --- a/components/style/properties/longhand/position.mako.rs +++ b/components/style/properties/longhand/position.mako.rs @@ -210,6 +210,14 @@ ${helpers.single_keyword("object-fit", "fill contain cover none scale-down", products="gecko", animatable=False, spec="https://drafts.csswg.org/css-images/#propdef-object-fit")} +${helpers.predefined_type("object-position", + "Position", + "computed::Position::zero()", + products="gecko", + boxed="True", + spec="https://drafts.csswg.org/css-images-3/#the-object-position", + animatable=False)} + <% grid_longhands = ["grid-row-start", "grid-row-end", "grid-column-start", "grid-column-end"] %> % for longhand in grid_longhands: