Bug 1371115 - Part 1: implements nsStyleCoord type properties animatable. r?hiro
In this patch. implement following properties.
* grid-auto-columns
* grid-auto-rows
* scroll-snap-points-x
* scroll-snap-points-y
MozReview-Commit-ID: 3XdA3pSGcsn
--- a/servo/components/style/gecko/values.rs
+++ b/servo/components/style/gecko/values.rs
@@ -17,16 +17,17 @@ use nsstring::{nsACString, nsCString};
use std::cmp::max;
use values::{Auto, Either, ExtremumLength, None_, Normal};
use values::computed::{Angle, LengthOrPercentage, LengthOrPercentageOrAuto};
use values::computed::{LengthOrPercentageOrNone, Number, NumberOrPercentage};
use values::computed::{MaxLength, MozLength};
use values::computed::basic_shape::ShapeRadius as ComputedShapeRadius;
use values::generics::CounterStyleOrNone;
use values::generics::basic_shape::ShapeRadius;
+use values::generics::gecko::ScrollSnapPoint;
use values::generics::grid::{TrackBreadth, TrackKeyword};
use values::specified::Percentage;
/// A trait that defines an interface to convert from and to `nsStyleCoord`s.
pub trait GeckoStyleCoordConvertible : Sized {
/// Convert this to a `nsStyleCoord`.
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T);
/// Given a `nsStyleCoord`, try to get a value of this type..
@@ -363,16 +364,40 @@ impl GeckoStyleCoordConvertible for MaxL
}
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
LengthOrPercentageOrNone::from_gecko_style_coord(coord).map(MaxLength::LengthOrPercentageOrNone)
.or_else(|| ExtremumLength::from_gecko_style_coord(coord).map(MaxLength::ExtremumLength))
}
}
+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`.
pub fn convert_rgba_to_nscolor(rgba: &RGBA) -> u32 {
((rgba.alpha as u32) << 24) |
((rgba.blue as u32) << 16) |
((rgba.green as u32) << 8) |
(rgba.red as u32)
}
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -1245,16 +1245,40 @@ fn static_assert() {
}
}
pub fn copy_grid_auto_${kind}_from(&mut self, other: &Self) {
self.gecko.mGridAuto${kind.title()}Min.copy_from(&other.gecko.mGridAuto${kind.title()}Min);
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) {
<% self_grid = "self.gecko.mGridTemplate%s" % kind.title() %>
use gecko::values::GeckoStyleCoordConvertible;
use gecko_bindings::structs::{nsTArray, nsStyleGridLine_kMaxLine};
use nsstring::nsStringRepr;
use std::usize;
use values::CustomIdent;
use values::generics::grid::TrackListType::Auto;
@@ -2218,26 +2242,18 @@ fn static_assert() {
match self.gecko.mBreak${kind.title()} {
true => T::always,
false => T::auto,
}
}
% endfor
- % 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_' + axis, 'mScrollSnapPoints' + axis.upper())}
- % endfor
+ ${impl_style_coord("scroll_snap_points_x", "mScrollSnapPointsX", True)}
+ ${impl_style_coord("scroll_snap_points_y", "mScrollSnapPointsY", True)}
pub fn set_scroll_snap_coordinate<I>(&mut self, v: I)
where I: IntoIterator<Item = longhands::scroll_snap_coordinate::computed_value::single_value::T>,
I::IntoIter: ExactSizeIterator
{
let v = v.into_iter();
unsafe { self.gecko.mScrollSnapCoordinate.set_len_pod(v.len() as u32); }
--- a/servo/components/style/properties/longhand/box.mako.rs
+++ b/servo/components/style/properties/longhand/box.mako.rs
@@ -651,17 +651,17 @@
spec="https://drafts.csswg.org/css-animations/#propdef-animation-delay",
allowed_in_keyframe_block=False)}
% for axis in ["x", "y"]:
${helpers.predefined_type(
"scroll-snap-points-" + axis,
"ScrollSnapPoint",
"computed::ScrollSnapPoint::none()",
- animation_value_type="none",
+ animation_value_type="discrete",
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",
--- a/servo/components/style/properties/longhand/position.mako.rs
+++ b/servo/components/style/properties/longhand/position.mako.rs
@@ -266,17 +266,17 @@ macro_rules! impl_align_conversions {
boxed=True)}
% endfor
// NOTE: According to the spec, this should handle multiple values of `<track-size>`,
// but gecko supports only a single value
${helpers.predefined_type("grid-auto-%ss" % kind,
"TrackSize",
"Default::default()",
- animation_value_type="none",
+ animation_value_type="discrete",
spec="https://drafts.csswg.org/css-grid/#propdef-grid-auto-%ss" % kind,
products="gecko",
boxed=True)}
${helpers.predefined_type("grid-template-%ss" % kind,
"GridTemplateComponent",
"specified::GenericGridTemplateComponent::None",
products="gecko",