From b676f1422ff0f272bfb036429faa10fc13658eef Mon Sep 17 00:00:00 2001 From: Rohit Burra Date: Wed, 2 Nov 2016 04:46:32 +0530 Subject: [PATCH 1/2] Parsing/Serialization for scroll-snap-points-* --- components/style/properties/gecko.mako.rs | 21 +++- .../style/properties/longhand/box.mako.rs | 95 +++++++++++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 8edbafb8019..7c2aa42b264 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -850,7 +850,8 @@ fn static_assert() { <% 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 @@ -976,6 +977,24 @@ fn static_assert() { ${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')} + <%def name="simple_image_array_property(name, shorthand, field_name)"> diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 067c37e6251..7c312a59000 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -841,6 +841,101 @@ ${helpers.keyword_list("animation-fill-mode", pub use super::transition_duration::SingleSpecifiedValue; +<%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::Length; + + impl HasViewportPercentage for SpecifiedValue { + fn has_viewport_percentage(&self) -> bool { + match *self { + SpecifiedValue::Specified(length) => length.has_viewport_percentage(), + _ => false + } + } + } + + pub mod computed_value { + use app_units::Au; + + #[derive(Debug, Clone, PartialEq)] + #[cfg_attr(feature = "servo", derive(HeapSizeOf))] + pub struct T(pub Option); + } + + #[derive(Debug, Clone, Copy, PartialEq)] + #[cfg_attr(feature = "servo", derive(HeapSizeOf))] + pub enum SpecifiedValue { + None, + Specified(Length), + } + + impl ToCss for computed_value::T { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + match self.0 { + None => dest.write_str("none"), + Some(l) => l.to_css(dest) + } + } + } + impl ToCss for SpecifiedValue { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + match *self { + SpecifiedValue::None => dest.write_str("none"), + SpecifiedValue::Specified(ref l) => l.to_css(dest), + } + } + } + + #[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::Specified(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::Specified(ToComputedValue::from_computed_value(&l)) + } + } + } + + pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result { + 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| { + Length::parse_non_negative(input).map(SpecifiedValue::Specified) + }) + } else { + Err(()) + } + } + + +<%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; + + + // CSSOM View Module // https://www.w3.org/TR/cssom-view-1/ ${helpers.single_keyword("scroll-behavior", From 6fe5bef45a083c5e30e0a21dc8fa582697449ad2 Mon Sep 17 00:00:00 2001 From: Rohit Burra Date: Wed, 2 Nov 2016 21:30:56 +0530 Subject: [PATCH 2/2] Use LengthOrPercentage instead of Length --- .../style/properties/longhand/box.mako.rs | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 7c312a59000..bba0eec7997 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -846,37 +846,41 @@ ${helpers.keyword_list("animation-fill-mode", use std::fmt; use values::LocalToCss; use values::HasViewportPercentage; - use values::specified::Length; + use values::specified::LengthOrPercentage; impl HasViewportPercentage for SpecifiedValue { fn has_viewport_percentage(&self) -> bool { match *self { - SpecifiedValue::Specified(length) => length.has_viewport_percentage(), + SpecifiedValue::Repeat(length) => length.has_viewport_percentage(), _ => false } } } pub mod computed_value { - use app_units::Au; + use values::computed::LengthOrPercentage; #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] - pub struct T(pub Option); + pub struct T(pub Option); } #[derive(Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub enum SpecifiedValue { None, - Specified(Length), + Repeat(LengthOrPercentage), } impl ToCss for computed_value::T { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match self.0 { None => dest.write_str("none"), - Some(l) => l.to_css(dest) + Some(l) => { + try!(dest.write_str("repeat(")); + try!(l.to_css(dest)); + dest.write_str(")") + }, } } } @@ -884,7 +888,11 @@ ${helpers.keyword_list("animation-fill-mode", fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { SpecifiedValue::None => dest.write_str("none"), - SpecifiedValue::Specified(ref l) => l.to_css(dest), + SpecifiedValue::Repeat(ref l) => { + try!(dest.write_str("repeat(")); + try!(l.to_css(dest)); + dest.write_str(")") + }, } } } @@ -901,7 +909,7 @@ ${helpers.keyword_list("animation-fill-mode", fn to_computed_value(&self, context: &Context) -> computed_value::T { match *self { SpecifiedValue::None => computed_value::T(None), - SpecifiedValue::Specified(l) => + SpecifiedValue::Repeat(l) => computed_value::T(Some(l.to_computed_value(context))), } } @@ -910,7 +918,7 @@ ${helpers.keyword_list("animation-fill-mode", match *computed { computed_value::T(None) => SpecifiedValue::None, computed_value::T(Some(l)) => - SpecifiedValue::Specified(ToComputedValue::from_computed_value(&l)) + SpecifiedValue::Repeat(ToComputedValue::from_computed_value(&l)) } } } @@ -920,7 +928,7 @@ ${helpers.keyword_list("animation-fill-mode", Ok(SpecifiedValue::None) } else if input.try(|input| input.expect_function_matching("repeat")).is_ok() { input.parse_nested_block(|input| { - Length::parse_non_negative(input).map(SpecifiedValue::Specified) + LengthOrPercentage::parse_non_negative(input).map(SpecifiedValue::Repeat) }) } else { Err(())