stylo: Implement scroll-snap-coordinate

MozReview-Commit-ID: 6mr4ktfeEGT
This commit is contained in:
Manish Goregaokar 2017-02-06 17:45:09 -08:00 committed by Manish Goregaokar
parent a095565a8c
commit 20796ee94e
4 changed files with 62 additions and 4 deletions

View file

@ -93,4 +93,13 @@ impl<T> nsTArray<T> {
let mut header = self.header_mut(); let mut header = self.header_mut();
header.mLength = len; 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;
}
} }

View file

@ -1169,7 +1169,8 @@ fn static_assert() {
animation-iteration-count animation-timing-function animation-iteration-count animation-timing-function
-moz-binding page-break-before page-break-after -moz-binding page-break-before page-break-after
scroll-snap-points-x scroll-snap-points-y transform 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}"> <%self:impl_trait style_struct_name="Box" skip_longhands="${skip_box_longhands}">
// We manually-implement the |display| property until we get general // We manually-implement the |display| property until we get general
@ -1347,6 +1348,34 @@ fn static_assert() {
${impl_simple_copy('scroll_snap_destination', 'mScrollSnapDestination')} ${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)"> <%def name="transform_function_arm(name, keyword, items)">
<% <%
pattern = None pattern = None

View file

@ -21,8 +21,9 @@
</%call> </%call>
</%def> </%def>
<%def name="predefined_type(name, type, initial_value, parse_method='parse', needs_context=True, **kwargs)"> <%def name="predefined_type(name, type, initial_value, parse_method='parse',
<%call expr="longhand(name, predefined_type=type, **kwargs)"> needs_context=True, vector=False, **kwargs)">
<%def name="predefined_type_inner(name, type, initial_value, parse_method)">
#[allow(unused_imports)] #[allow(unused_imports)]
use app_units::Au; use app_units::Au;
use cssparser::{Color as CSSParserColor, RGBA}; use cssparser::{Color as CSSParserColor, RGBA};
@ -40,7 +41,16 @@
specified::${type}::${parse_method}(input) specified::${type}::${parse_method}(input)
% endif % endif
} }
</%call> </%def>
% if vector:
<%call expr="vector_longhand(name, predefined_type=type, **kwargs)">
${predefined_type_inner(name, type, initial_value, parse_method)}
</%call>
% else:
<%call expr="longhand(name, predefined_type=type, **kwargs)">
${predefined_type_inner(name, type, initial_value, parse_method)}
</%call>
% endif
</%def> </%def>
// FIXME (Manishearth): Add computed_value_as_specified argument // FIXME (Manishearth): Add computed_value_as_specified argument

View file

@ -1056,6 +1056,16 @@ ${helpers.predefined_type("scroll-snap-destination",
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-snap-destination)", spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-snap-destination)",
animatable=False)} 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" <%helpers:longhand name="transform" products="gecko servo" extra_prefixes="webkit"
animatable="True" animatable="True"
spec="https://drafts.csswg.org/css-transforms/#propdef-transform"> spec="https://drafts.csswg.org/css-transforms/#propdef-transform">