implements nsStyleCoord type properties animatable

This commit is contained in:
Daisuke Akatsuka 2017-07-05 12:54:45 +09:00
parent 006037f798
commit 983361eb0f
4 changed files with 53 additions and 12 deletions

View file

@ -22,6 +22,7 @@ use values::computed::{MaxLength, MozLength};
use values::computed::basic_shape::ShapeRadius as ComputedShapeRadius; use values::computed::basic_shape::ShapeRadius as ComputedShapeRadius;
use values::generics::CounterStyleOrNone; use values::generics::CounterStyleOrNone;
use values::generics::basic_shape::ShapeRadius; use values::generics::basic_shape::ShapeRadius;
use values::generics::gecko::ScrollSnapPoint;
use values::generics::grid::{TrackBreadth, TrackKeyword}; use values::generics::grid::{TrackBreadth, TrackKeyword};
use values::specified::Percentage; use values::specified::Percentage;
@ -368,6 +369,30 @@ impl GeckoStyleCoordConvertible for MaxLength {
} }
} }
impl GeckoStyleCoordConvertible for ScrollSnapPoint<LengthOrPercentage> {
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
match self.repeated() {
None => coord.set_value(CoordDataValue::None),
Some(l) => l.to_gecko_style_coord(coord),
};
}
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
use gecko_bindings::structs::root::nsStyleUnit;
use values::generics::gecko::ScrollSnapPoint;
Some(
match coord.unit() {
nsStyleUnit::eStyleUnit_None => ScrollSnapPoint::None,
nsStyleUnit::eStyleUnit_Coord | nsStyleUnit::eStyleUnit_Percent =>
ScrollSnapPoint::Repeat(LengthOrPercentage::from_gecko_style_coord(coord)
.expect("coord could not convert to LengthOrPercentage")),
x => panic!("Unexpected unit {:?}", x)
}
)
}
}
/// Convert a given RGBA value to `nscolor`. /// Convert a given RGBA value to `nscolor`.
pub fn convert_rgba_to_nscolor(rgba: &RGBA) -> u32 { pub fn convert_rgba_to_nscolor(rgba: &RGBA) -> u32 {
((rgba.alpha as u32) << 24) | ((rgba.alpha as u32) << 24) |

View file

@ -1250,6 +1250,30 @@ fn static_assert() {
self.gecko.mGridAuto${kind.title()}Max.copy_from(&other.gecko.mGridAuto${kind.title()}Max); self.gecko.mGridAuto${kind.title()}Max.copy_from(&other.gecko.mGridAuto${kind.title()}Max);
} }
pub fn clone_grid_auto_${kind}(&self) -> longhands::grid_auto_${kind}::computed_value::T {
use gecko_bindings::structs::root::nsStyleUnit::eStyleUnit_None;
use values::computed::length::LengthOrPercentage;
use values::generics::grid::{TrackSize, TrackBreadth};
let ref min_gecko = self.gecko.mGridAuto${kind.title()}Min;
let ref max_gecko = self.gecko.mGridAuto${kind.title()}Max;
if min_gecko.unit() == eStyleUnit_None {
debug_assert!(max_gecko.unit() != eStyleUnit_None);
return TrackSize::FitContent(LengthOrPercentage::from_gecko_style_coord(max_gecko)
.expect("mGridAuto${kind.title()}Max contains style coord"));
}
let min = TrackBreadth::from_gecko_style_coord(min_gecko)
.expect("mGridAuto${kind.title()}Min contains style coord");
let max = TrackBreadth::from_gecko_style_coord(max_gecko)
.expect("mGridAuto${kind.title()}Max contains style coord");
if min == max {
TrackSize::Breadth(max)
} else {
TrackSize::MinMax(min, max)
}
}
pub fn set_grid_template_${kind}(&mut self, v: longhands::grid_template_${kind}::computed_value::T) { pub fn set_grid_template_${kind}(&mut self, v: longhands::grid_template_${kind}::computed_value::T) {
<% self_grid = "self.gecko.mGridTemplate%s" % kind.title() %> <% self_grid = "self.gecko.mGridTemplate%s" % kind.title() %>
use gecko::values::GeckoStyleCoordConvertible; use gecko::values::GeckoStyleCoordConvertible;
@ -2223,16 +2247,8 @@ fn static_assert() {
} }
% endfor % endfor
% for axis in ["x", "y"]: ${impl_style_coord("scroll_snap_points_x", "mScrollSnapPointsX", True)}
pub fn set_scroll_snap_points_${axis}(&mut self, v: longhands::scroll_snap_points_${axis}::computed_value::T) { ${impl_style_coord("scroll_snap_points_y", "mScrollSnapPointsY", True)}
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_' + axis, 'mScrollSnapPoints' + axis.upper())}
% endfor
pub fn set_scroll_snap_coordinate<I>(&mut self, v: I) pub fn set_scroll_snap_coordinate<I>(&mut self, v: I)
where I: IntoIterator<Item = longhands::scroll_snap_coordinate::computed_value::single_value::T>, where I: IntoIterator<Item = longhands::scroll_snap_coordinate::computed_value::single_value::T>,

View file

@ -656,7 +656,7 @@ ${helpers.predefined_type("animation-delay",
"scroll-snap-points-" + axis, "scroll-snap-points-" + axis,
"ScrollSnapPoint", "ScrollSnapPoint",
"computed::ScrollSnapPoint::none()", "computed::ScrollSnapPoint::none()",
animation_value_type="none", animation_value_type="discrete",
products="gecko", products="gecko",
disable_when_testing=True, disable_when_testing=True,
spec="Nonstandard (https://www.w3.org/TR/2015/WD-css-snappoints-1-20150326/#scroll-snap-points)", spec="Nonstandard (https://www.w3.org/TR/2015/WD-css-snappoints-1-20150326/#scroll-snap-points)",

View file

@ -271,7 +271,7 @@ ${helpers.predefined_type("object-position",
${helpers.predefined_type("grid-auto-%ss" % kind, ${helpers.predefined_type("grid-auto-%ss" % kind,
"TrackSize", "TrackSize",
"Default::default()", "Default::default()",
animation_value_type="none", animation_value_type="discrete",
spec="https://drafts.csswg.org/css-grid/#propdef-grid-auto-%ss" % kind, spec="https://drafts.csswg.org/css-grid/#propdef-grid-auto-%ss" % kind,
products="gecko", products="gecko",
boxed=True)} boxed=True)}