Use generics for scroll-snap-points-*

This commit is contained in:
Anthony Ramine 2017-06-06 14:28:24 +02:00
parent bc1eef8f5e
commit 195e98e745
8 changed files with 122 additions and 110 deletions

View file

@ -2232,23 +2232,16 @@ fn static_assert() {
}
% endfor
pub fn set_scroll_snap_points_x(&mut self, v: longhands::scroll_snap_points_x::computed_value::T) {
match v.0 {
None => self.gecko.mScrollSnapPointsX.set_value(CoordDataValue::None),
Some(l) => l.to_gecko_style_coord(&mut self.gecko.mScrollSnapPointsX),
};
}
% for axis in ["x", "y"]:
pub fn set_scroll_snap_points_${axis}(&mut self, v: longhands::scroll_snap_points_${axis}::computed_value::T) {
match v.repeated() {
None => self.gecko.mScrollSnapPoints${axis.upper()}.set_value(CoordDataValue::None),
Some(l) => l.to_gecko_style_coord(&mut self.gecko.mScrollSnapPoints${axis.upper()}),
};
}
${impl_coord_copy('scroll_snap_points_x', 'mScrollSnapPointsX')}
pub fn set_scroll_snap_points_y(&mut self, v: longhands::scroll_snap_points_y::computed_value::T) {
match v.0 {
None => self.gecko.mScrollSnapPointsY.set_value(CoordDataValue::None),
Some(l) => l.to_gecko_style_coord(&mut self.gecko.mScrollSnapPointsY),
};
}
${impl_coord_copy('scroll_snap_points_y', 'mScrollSnapPointsY')}
${impl_coord_copy('scroll_snap_points_' + axis, 'mScrollSnapPoints' + axis.upper())}
% endfor
pub fn set_scroll_snap_coordinate<I>(&mut self, v: I)
where I: IntoIterator<Item = longhands::scroll_snap_coordinate::computed_value::single_value::T>,

View file

@ -650,99 +650,17 @@ ${helpers.predefined_type("animation-delay",
spec="https://drafts.csswg.org/css-animations/#propdef-animation-delay",
allowed_in_keyframe_block=False)}
<%helpers:longhand products="gecko" name="scroll-snap-points-y" animation_value_type="none"
spec="Nonstandard (https://www.w3.org/TR/2015/WD-css-snappoints-1-20150326/#scroll-snap-points)">
use std::fmt;
use style_traits::ToCss;
use values::specified::LengthOrPercentage;
pub mod computed_value {
use values::computed::LengthOrPercentage;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct T(pub Option<LengthOrPercentage>);
}
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum SpecifiedValue {
None,
Repeat(LengthOrPercentage),
}
impl ToCss for computed_value::T {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match self.0 {
None => dest.write_str("none"),
Some(ref l) => {
try!(dest.write_str("repeat("));
try!(l.to_css(dest));
dest.write_str(")")
},
}
}
}
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
SpecifiedValue::None => dest.write_str("none"),
SpecifiedValue::Repeat(ref l) => {
try!(dest.write_str("repeat("));
try!(l.to_css(dest));
dest.write_str(")")
},
}
}
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T(None)
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
#[inline]
fn to_computed_value(&self, context: &Context) -> computed_value::T {
match *self {
SpecifiedValue::None => computed_value::T(None),
SpecifiedValue::Repeat(ref l) =>
computed_value::T(Some(l.to_computed_value(context))),
}
}
#[inline]
fn from_computed_value(computed: &computed_value::T) -> Self {
match *computed {
computed_value::T(None) => SpecifiedValue::None,
computed_value::T(Some(l)) =>
SpecifiedValue::Repeat(ToComputedValue::from_computed_value(&l))
}
}
}
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
Ok(SpecifiedValue::None)
} else if input.try(|input| input.expect_function_matching("repeat")).is_ok() {
input.parse_nested_block(|input| {
LengthOrPercentage::parse_non_negative(context, input).map(SpecifiedValue::Repeat)
})
} else {
Err(())
}
}
</%helpers:longhand>
<%helpers:longhand products="gecko" name="scroll-snap-points-x" animation_value_type="none"
spec="Nonstandard (https://www.w3.org/TR/2015/WD-css-snappoints-1-20150326/#scroll-snap-points)">
pub use super::scroll_snap_points_y::SpecifiedValue;
pub use super::scroll_snap_points_y::computed_value;
pub use super::scroll_snap_points_y::get_initial_value;
pub use super::scroll_snap_points_y::parse;
</%helpers:longhand>
% for axis in ["x", "y"]:
${helpers.predefined_type(
"scroll-snap-points-" + axis,
"ScrollSnapPoint",
"computed::ScrollSnapPoint::none()",
animation_value_type="none",
products="gecko",
disable_when_testing=True,
spec="Nonstandard (https://www.w3.org/TR/2015/WD-css-snappoints-1-20150326/#scroll-snap-points)",
)}
% endfor
${helpers.predefined_type("scroll-snap-destination",
"Position",