Bug 951793 - Additional style support for overscroll-behavior in Stylo. r=emilio draft
authorBotond Ballo <botond@mozilla.com>
Wed, 22 Nov 2017 19:01:21 -0500
changeset 702345 a259e8e78a72e177bdc4158e5d126867a247a1c2
parent 702344 aab882e2d4e0f58b755d3ae9788ae3b612cc5863
child 741421 bd5f5372090435336d0c5859229109541870141e
push id90435
push userbballo@mozilla.com
push dateThu, 23 Nov 2017 00:11:12 +0000
reviewersemilio
bugs951793
milestone59.0a1
Bug 951793 - Additional style support for overscroll-behavior in Stylo. r=emilio MozReview-Commit-ID: 9qLpF11YeU5
layout/style/ServoBindings.toml
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/layout/style/ServoBindings.toml
+++ b/layout/style/ServoBindings.toml
@@ -170,16 +170,17 @@ rusty-enums = [
     "StyleBoxOrient",
     "StyleBoxAlign",
     "StyleUserFocus",
     "StyleUserSelect",
     "StyleImageLayerRepeat",
     "StyleBoxDecorationBreak",
     "StyleRuleInclusion",
     "StyleGridTrackBreadth",
+    "StyleOverscrollBehavior",
     "nsStyleImageType",
     "StyleWhiteSpace",
     "nsStyleSVGPaintType",
     "nsStyleSVGFallbackType",
     # ".*Style.*",
     "nsINode_BooleanFlag",
     "CSSPseudoElementType",
     "CSSPseudoClassType",
--- 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", gecko_enum_prefix="StyleOverscrollBehavior") %>
+    ${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/overscroll-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,58 @@ 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/overscroll-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 behavior_x = OverscrollBehavior::parse(input)?;
+        let behavior_y = input.try(OverscrollBehavior::parse).unwrap_or(behavior_x);
+        Ok(expanded! {
+            overscroll_behavior_x: behavior_x,
+            overscroll_behavior_y: behavior_y,
+        })
+    }
+
+    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 two values separated by a space.
+        fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
+          self.overscroll_behavior_x.to_css(dest)?;
+          if self.overscroll_behavior_y != self.overscroll_behavior_x {
+            dest.write_str(" ")?;
+            self.overscroll_behavior_y.to_css(dest)?;
+          }
+          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};