servo: Merge #14017 - Parsing/Serialization for scroll-snap-points-* (from iamrohit7:scroll-snap-points); r=Manishearth
authorRohit Burra <iamrohit7@gmail.com>
Wed, 02 Nov 2016 12:00:11 -0500
changeset 340041 b603cad6140f8ca51d36cdf429e795e78254ab2c
parent 340040 0d0319546f11018dd82053e21d4e3b086e7407f9
child 340042 95dbf80ffecd90f5b67575d0d028376722e0c3c1
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersManishearth
servo: Merge #14017 - Parsing/Serialization for scroll-snap-points-* (from iamrohit7:scroll-snap-points); r=Manishearth <!-- Please describe your changes on the following line: --> Implements Parsing/Serialization for scroll-snap-points-x and scroll-snap-points-y --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #13871 <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 193a4d88ed6497ebefcf776607a7647dd88628c1
servo/components/style/properties/gecko.mako.rs
servo/components/style/properties/longhand/box.mako.rs
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -845,17 +845,18 @@ fn static_assert() {
 
     pub fn copy_font_synthesis_from(&mut self, other: &Self) {
         self.gecko.mFont.synthesis = other.gecko.mFont.synthesis;
     }
 
 </%self:impl_trait>
 
 <% skip_box_longhands= """display overflow-y vertical-align
-                          -moz-binding page-break-before page-break-after""" %>
+                          -moz-binding page-break-before page-break-after
+                          scroll-snap-points-x scroll-snap-points-y""" %>
 <%self:impl_trait style_struct_name="Box" skip_longhands="${skip_box_longhands}">
 
     // We manually-implement the |display| property until we get general
     // infrastructure for preffing certain values.
     <% display_keyword = Keyword("display", "inline block inline-block table inline-table table-row-group " +
                                             "table-header-group table-footer-group table-row table-column-group " +
                                             "table-column table-cell table-caption list-item flex none " +
                                             "-moz-box -moz-inline-box",
@@ -971,16 +972,34 @@ fn static_assert() {
             T::left   => true,
             T::right  => true
         };
         self.gecko.mBreakBefore = result;
     }
 
     ${impl_simple_copy('page_break_after', 'mBreakAfter')}
 
+    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),
+        };
+    }
+
+    ${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')}
+
 </%self:impl_trait>
 
 <%def name="simple_image_array_property(name, shorthand, field_name)">
     <%
         image_layers_field = "mImage" if shorthand == "background" else "mMask"
     %>
     pub fn copy_${shorthand}_${name}_from(&mut self, other: &Self) {
         use gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType;
--- a/servo/components/style/properties/longhand/box.mako.rs
+++ b/servo/components/style/properties/longhand/box.mako.rs
@@ -836,16 +836,119 @@
                    allowed_in_keyframe_block="False">
     pub use super::transition_duration::computed_value;
     pub use super::transition_duration::{get_initial_value, get_initial_single_value};
     pub use super::transition_duration::{parse, parse_one};
     pub use super::transition_duration::SpecifiedValue;
     pub use super::transition_duration::SingleSpecifiedValue;
 </%helpers:longhand>
 
+<%helpers:longhand products="gecko" name="scroll-snap-points-y" animatable="False">
+    use cssparser::ToCss;
+    use std::fmt;
+    use values::LocalToCss;
+    use values::HasViewportPercentage;
+    use values::specified::LengthOrPercentage;
+
+    impl HasViewportPercentage for SpecifiedValue {
+        fn has_viewport_percentage(&self) -> bool {
+            match *self {
+                SpecifiedValue::Repeat(length) => length.has_viewport_percentage(),
+                _ => false
+            }
+        }
+    }
+
+    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(Debug, Clone, Copy, 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(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(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(input).map(SpecifiedValue::Repeat)
+            })
+        } else {
+            Err(())
+        }
+    }
+</%helpers:longhand>
+
+<%helpers:longhand products="gecko" name="scroll-snap-points-x" animatable="False">
+    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>
+
+
 // CSSOM View Module
 // https://www.w3.org/TR/cssom-view-1/
 ${helpers.single_keyword("scroll-behavior",
                          "auto smooth",
                          products="gecko",
                          animatable=False)}
 
 // Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-snap-type-x