Bug 951793 - Additional style support for overscroll-behavior in Stylo. r=emilio draft
authorBotond Ballo <botond@mozilla.com>
Mon, 20 Nov 2017 16:15:19 -0500
changeset 700766 c69f6c8f1c16d2c6a0ddb21224e13e6c0bb8ec2a
parent 700765 9cab422108c0de8b9ef51a390aa7331914f62472
child 700767 6331c72a4cb64aa35ffb7e2c987db35c0dc646b4
push id89971
push userbballo@mozilla.com
push dateMon, 20 Nov 2017 22:06:14 +0000
reviewersemilio
bugs951793
milestone59.0a1
Bug 951793 - Additional style support for overscroll-behavior in Stylo. r=emilio MozReview-Commit-ID: 9qLpF11YeU5
servo/components/style/properties/gecko.mako.rs
servo/components/style/properties/longhand/box.mako.rs
servo/components/style/properties/shorthand/box.mako.rs
servo/components/style/values/computed/box.rs
servo/components/style/values/computed/mod.rs
servo/components/style/values/specified/box.rs
servo/components/style/values/specified/mod.rs
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -3093,16 +3093,18 @@ fn static_assert() {
                           animation-direction animation-fill-mode animation-play-state
                           animation-iteration-count animation-timing-function
                           transition-duration transition-delay
                           transition-timing-function transition-property
                           page-break-before page-break-after
                           scroll-snap-points-x scroll-snap-points-y
                           scroll-snap-type-x scroll-snap-type-y scroll-snap-coordinate
                           perspective-origin -moz-binding will-change
+                          overscroll-behavior-x overscroll-behavior-y
+                          perspective-origin -moz-binding will-change
                           shape-outside contain touch-action""" %>
 <%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 " +
@@ -3480,16 +3482,20 @@ fn static_assert() {
     ${impl_copy_animation_value('iteration_count', 'IterationCount')}
 
     ${impl_animation_timing_function()}
 
     <% scroll_snap_type_keyword = Keyword("scroll-snap-type", "None Mandatory Proximity") %>
     ${impl_keyword('scroll_snap_type_y', 'mScrollSnapTypeY', scroll_snap_type_keyword)}
     ${impl_keyword('scroll_snap_type_x', 'mScrollSnapTypeX', scroll_snap_type_keyword)}
 
+    <% overscroll_behavior_keyword = Keyword("overscroll-behavior", "Auto Contain None") %>
+    ${impl_keyword('overscroll_behavior_x', 'mOverscrollBehaviorX', overscroll_behavior_keyword)}
+    ${impl_keyword('overscroll_behavior_y', 'mOverscrollBehaviorY', overscroll_behavior_keyword)}
+
     pub fn set_perspective_origin(&mut self, v: longhands::perspective_origin::computed_value::T) {
         self.gecko.mPerspectiveOrigin[0].set(v.horizontal);
         self.gecko.mPerspectiveOrigin[1].set(v.vertical);
     }
 
     pub fn copy_perspective_origin_from(&mut self, other: &Self) {
         self.gecko.mPerspectiveOrigin[0].copy_from(&other.gecko.mPerspectiveOrigin[0]);
         self.gecko.mPerspectiveOrigin[1].copy_from(&other.gecko.mPerspectiveOrigin[1]);
--- a/servo/components/style/properties/longhand/box.mako.rs
+++ b/servo/components/style/properties/longhand/box.mako.rs
@@ -596,16 +596,29 @@
         products="gecko",
         needs_context=False,
         gecko_pref="layout.css.scroll-snap.enabled",
         spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-snap-type-x)",
         animation_value_type="discrete"
     )}
 % endfor
 
+% for axis in ["x", "y"]:
+    ${helpers.predefined_type(
+        "overscroll-behavior-" + axis,
+        "OverscrollBehavior",
+        "computed::OverscrollBehavior::Auto",
+        products="gecko",
+        needs_context=False,
+        gecko_pref="layout.css.overscroll-behavior.enabled",
+        spec="https://wicg.github.io/scroll-boundary-behavior/#overscroll-behavior-properties",
+        animation_value_type="discrete"
+    )}
+% endfor
+
 // Compositing and Blending Level 1
 // http://www.w3.org/TR/compositing-1/
 ${helpers.single_keyword("isolation",
                          "auto isolate",
                          products="gecko",
                          gecko_pref="layout.css.isolation.enabled",
                          spec="https://drafts.fxtf.org/compositing/#isolation",
                          flags="CREATES_STACKING_CONTEXT",
--- a/servo/components/style/properties/shorthand/box.mako.rs
+++ b/servo/components/style/properties/shorthand/box.mako.rs
@@ -341,28 +341,56 @@ macro_rules! try_parse_one {
         let result = scroll_snap_type_x::parse(context, input)?;
         Ok(expanded! {
             scroll_snap_type_x: result,
             scroll_snap_type_y: result,
         })
     }
 
     impl<'a> ToCss for LonghandsToSerialize<'a>  {
-        // Serializes into the single keyword value if both scroll-snap-type and scroll-snap-type-y are same.
+        // Serializes into the single keyword value if both scroll-snap-type-x and scroll-snap-type-y are same.
         // Otherwise into an empty string. This is done to match Gecko's behaviour.
         fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
             if self.scroll_snap_type_x == self.scroll_snap_type_y {
                 self.scroll_snap_type_x.to_css(dest)
             } else {
                 Ok(())
             }
         }
     }
 </%helpers:shorthand>
 
+<%helpers:shorthand name="overscroll-behavior" products="gecko"
+                    gecko_pref="layout.css.overscroll-behavior.enabled"
+                    sub_properties="overscroll-behavior-x overscroll-behavior-y"
+                    spec="https://wicg.github.io/scroll-boundary-behavior/#overscroll-behavior-properties">
+    pub fn parse_value<'i, 't>(
+        _: &ParserContext, 
+        input: &mut Parser<'i, 't>
+    ) -> Result<Longhands, ParseError<'i>> {
+        use values::specified::OverscrollBehavior;
+        let result = OverscrollBehavior::parse(input)?;
+        Ok(expanded! {
+            overscroll_behavior_x: result,
+            overscroll_behavior_y: result,
+        })
+    }
+
+    impl<'a> ToCss for LonghandsToSerialize<'a> {
+        // Serializes into the single keyword value if both overscroll-behavior-x and overscroll-behavior-y are same.
+        // Otherwise into an empty string.
+        fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
+          if self.overscroll_behavior_x == self.overscroll_behavior_y {
+              self.overscroll_behavior_x.to_css(dest)
+          } else {
+              Ok(())
+          }
+        }
+    }
+</%helpers:shorthand>
 
 <%helpers:shorthand name="-moz-transform" products="gecko"
                     sub_properties="transform"
                     gecko_pref="layout.css.prefixes.transforms"
                     flags="SHORTHAND_ALIAS_PROPERTY"
                     derive_serialize="True"
                     spec="Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/transform">
     pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
--- a/servo/components/style/values/computed/box.rs
+++ b/servo/components/style/values/computed/box.rs
@@ -4,17 +4,17 @@
 
 //! Computed types for box properties.
 
 use values::computed::Number;
 use values::computed::length::LengthOrPercentage;
 use values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount;
 use values::generics::box_::VerticalAlign as GenericVerticalAlign;
 
-pub use values::specified::box_::{AnimationName, ScrollSnapType};
+pub use values::specified::box_::{AnimationName, OverscrollBehavior, ScrollSnapType};
 
 /// A computed value for the `vertical-align` property.
 pub type VerticalAlign = GenericVerticalAlign<LengthOrPercentage>;
 
 /// A computed value for the `animation-iteration-count` property.
 pub type AnimationIterationCount = GenericAnimationIterationCount<Number>;
 
 impl AnimationIterationCount {
--- a/servo/components/style/values/computed/mod.rs
+++ b/servo/components/style/values/computed/mod.rs
@@ -34,17 +34,17 @@ pub use properties::animated_properties:
 pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, JustifyItems};
 pub use self::angle::Angle;
 pub use self::background::{BackgroundSize, BackgroundRepeat};
 pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth};
 pub use self::border::{BorderRadius, BorderCornerRadius, BorderSpacing};
 pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVariantAlternates};
 pub use self::font::{FontLanguageOverride, FontVariantSettings, FontVariantEastAsian};
 pub use self::font::{FontVariantLigatures, FontVariantNumeric, MozScriptLevel, MozScriptMinSize, XTextZoom};
-pub use self::box_::{AnimationIterationCount, AnimationName, ScrollSnapType, VerticalAlign};
+pub use self::box_::{AnimationIterationCount, AnimationName, OverscrollBehavior, ScrollSnapType, VerticalAlign};
 pub use self::color::{Color, ColorPropertyValue, RGBAColor};
 pub use self::effects::{BoxShadow, Filter, SimpleShadow};
 pub use self::flex::FlexBasis;
 pub use self::image::{Gradient, GradientItem, Image, ImageLayer, LineDirection, MozImageRect};
 #[cfg(feature = "gecko")]
 pub use self::gecko::ScrollSnapPoint;
 pub use self::rect::LengthOrNumberRect;
 pub use super::{Auto, Either, None_};
--- a/servo/components/style/values/specified/box.rs
+++ b/servo/components/style/values/specified/box.rs
@@ -112,8 +112,15 @@ impl Parse for AnimationName {
 }
 
 define_css_keyword_enum! { ScrollSnapType:
     "none" => None,
     "mandatory" => Mandatory,
     "proximity" => Proximity,
 }
 add_impls_for_keyword_enum!(ScrollSnapType);
+
+define_css_keyword_enum! { OverscrollBehavior:
+    "auto" => Auto,
+    "contain" => Contain,
+    "none" => None,
+}
+add_impls_for_keyword_enum!(OverscrollBehavior);
--- a/servo/components/style/values/specified/mod.rs
+++ b/servo/components/style/values/specified/mod.rs
@@ -28,17 +28,17 @@ pub use self::angle::Angle;
 #[cfg(feature = "gecko")]
 pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, JustifyItems};
 pub use self::background::{BackgroundRepeat, BackgroundSize};
 pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth};
 pub use self::border::{BorderImageSideWidth, BorderRadius, BorderSideWidth, BorderSpacing};
 pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVariantAlternates};
 pub use self::font::{FontLanguageOverride, FontVariantSettings, FontVariantEastAsian};
 pub use self::font::{FontVariantLigatures, FontVariantNumeric, MozScriptLevel, MozScriptMinSize, XTextZoom};
-pub use self::box_::{AnimationIterationCount, AnimationName, ScrollSnapType, VerticalAlign};
+pub use self::box_::{AnimationIterationCount, AnimationName, OverscrollBehavior, ScrollSnapType, VerticalAlign};
 pub use self::color::{Color, ColorPropertyValue, RGBAColor};
 pub use self::effects::{BoxShadow, Filter, SimpleShadow};
 pub use self::flex::FlexBasis;
 #[cfg(feature = "gecko")]
 pub use self::gecko::ScrollSnapPoint;
 pub use self::image::{ColorStop, EndingShape as GradientEndingShape, Gradient};
 pub use self::image::{GradientItem, GradientKind, Image, ImageLayer, MozImageRect};
 pub use self::length::{AbsoluteLength, CalcLengthOrPercentage, CharacterWidth};