diff --git a/components/style/gecko_bindings/sugar/ns_t_array.rs b/components/style/gecko_bindings/sugar/ns_t_array.rs index 5d9c005f0e3..6bc389702f5 100644 --- a/components/style/gecko_bindings/sugar/ns_t_array.rs +++ b/components/style/gecko_bindings/sugar/ns_t_array.rs @@ -93,4 +93,13 @@ impl nsTArray { let mut header = self.header_mut(); header.mLength = len; } + + /// Resizes an array containing only POD elements + /// + /// This will not leak since it only works on POD types (and thus doesn't assert) + pub unsafe fn set_len_pod(&mut self, len: u32) where T: Copy { + self.ensure_capacity(len as usize); + let mut header = unsafe { self.header_mut() }; + header.mLength = len; + } } diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 34377f37c73..1148a25bbcc 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -1169,7 +1169,8 @@ 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 perspective-origin transform-origin""" %> + scroll-snap-type-y scroll-snap-destination scroll-snap-coordinate + perspective-origin transform-origin""" %> <%self:impl_trait style_struct_name="Box" skip_longhands="${skip_box_longhands}"> // We manually-implement the |display| property until we get general @@ -1347,6 +1348,34 @@ fn static_assert() { ${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 + .iter_mut() + .zip(v.0.iter()) { + gecko.mXPosition = servo.horizontal.into(); + gecko.mYPosition = servo.vertical.into(); + } + } + + pub fn copy_scroll_snap_coordinate_from(&mut self, other: &Self) { + unsafe { + self.gecko.mScrollSnapCoordinate + .set_len_pod(other.gecko.mScrollSnapCoordinate.len() as u32); + } + + for (this, that) in self.gecko.mScrollSnapCoordinate + .iter_mut() + .zip(other.gecko.mScrollSnapCoordinate.iter()) { + *this = *that; + } + } + + 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(); + longhands::scroll_snap_coordinate::computed_value::T(vec) + } + <%def name="transform_function_arm(name, keyword, items)"> <% pattern = None diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 30c6873a8a2..37b4bed744d 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -21,8 +21,9 @@ -<%def name="predefined_type(name, type, initial_value, parse_method='parse', needs_context=True, **kwargs)"> - <%call expr="longhand(name, predefined_type=type, **kwargs)"> +<%def name="predefined_type(name, type, initial_value, parse_method='parse', + needs_context=True, vector=False, **kwargs)"> + <%def name="predefined_type_inner(name, type, initial_value, parse_method)"> #[allow(unused_imports)] use app_units::Au; use cssparser::{Color as CSSParserColor, RGBA}; @@ -40,7 +41,16 @@ specified::${type}::${parse_method}(input) % endif } - + + % if vector: + <%call expr="vector_longhand(name, predefined_type=type, **kwargs)"> + ${predefined_type_inner(name, type, initial_value, parse_method)} + + % else: + <%call expr="longhand(name, predefined_type=type, **kwargs)"> + ${predefined_type_inner(name, type, initial_value, parse_method)} + + % endif // FIXME (Manishearth): Add computed_value_as_specified argument diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 81108d47b66..fa6d9a10a41 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -1056,6 +1056,16 @@ ${helpers.predefined_type("scroll-snap-destination", spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-snap-destination)", animatable=False)} +${helpers.predefined_type("scroll-snap-coordinate", + "Position", + "computed::Position::zero()", + vector=True, + products="gecko", + spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-snap-destination)", + animatable=False, + allow_empty=True)} + + <%helpers:longhand name="transform" products="gecko servo" extra_prefixes="webkit" animatable="True" spec="https://drafts.csswg.org/css-transforms/#propdef-transform">