aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorHiroyuki Ikezoe <hikezoe@mozilla.com>2019-04-11 06:19:31 +0000
committerEmilio Cobos Álvarez <emilio@crisal.io>2019-04-12 12:20:12 +0200
commit21481e315e5d82d33dab906980379fbd398d1ba9 (patch)
tree477cf809ea2f0706c233e0496a5b75b6cda4f88f /components
parent2f457ed144bf8960f54671c2e27705e59610e0dd (diff)
downloadservo-21481e315e5d82d33dab906980379fbd398d1ba9.tar.gz
servo-21481e315e5d82d33dab906980379fbd398d1ba9.zip
style: Switch to the new scroll-snap-type syntax for the old scroll snap implementation and drop the scroll-snap-type-{x,y} longhands.
Now scroll-snap-type is a longhand property. Differential Revision: https://phabricator.services.mozilla.com/D21622
Diffstat (limited to 'components')
-rw-r--r--components/style/properties/data.py2
-rw-r--r--components/style/properties/longhands/box.mako.rs21
-rw-r--r--components/style/properties/shorthands/box.mako.rs30
-rw-r--r--components/style/values/computed/box.rs4
-rw-r--r--components/style/values/computed/mod.rs3
-rw-r--r--components/style/values/specified/box.rs94
-rw-r--r--components/style/values/specified/mod.rs2
7 files changed, 109 insertions, 47 deletions
diff --git a/components/style/properties/data.py b/components/style/properties/data.py
index b6d42d8ecd5..407cc5fcdb0 100644
--- a/components/style/properties/data.py
+++ b/components/style/properties/data.py
@@ -341,7 +341,9 @@ class Longhand(object):
"SVGOpacity",
"SVGPaintOrder",
"ScrollSnapAlign",
+ "ScrollSnapAxis",
"ScrollSnapStrictness",
+ "ScrollSnapType",
"TextAlign",
"TextDecorationLine",
"TextEmphasisPosition",
diff --git a/components/style/properties/longhands/box.mako.rs b/components/style/properties/longhands/box.mako.rs
index 9d18753f53f..87d4f59af31 100644
--- a/components/style/properties/longhands/box.mako.rs
+++ b/components/style/properties/longhands/box.mako.rs
@@ -427,18 +427,15 @@ ${helpers.predefined_type(
animation_value_type="discrete",
)}
-% for axis in ["x", "y"]:
- ${helpers.predefined_type(
- "scroll-snap-type-" + axis,
- "ScrollSnapStrictness",
- "computed::ScrollSnapStrictness::None",
- 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
+${helpers.predefined_type(
+ "scroll-snap-type",
+ "ScrollSnapType",
+ "computed::ScrollSnapType::none()",
+ products="gecko",
+ gecko_pref="layout.css.scroll-snap.enabled",
+ spec="https://drafts.csswg.org/css-scroll-snap-1/#scroll-snap-type",
+ animation_value_type="discrete",
+)}
% for axis in ["x", "y"]:
${helpers.predefined_type(
diff --git a/components/style/properties/shorthands/box.mako.rs b/components/style/properties/shorthands/box.mako.rs
index 0acb72b6bb9..5c03dba8529 100644
--- a/components/style/properties/shorthands/box.mako.rs
+++ b/components/style/properties/shorthands/box.mako.rs
@@ -303,36 +303,6 @@ macro_rules! try_parse_one {
}
</%helpers:shorthand>
-<%helpers:shorthand name="scroll-snap-type" products="gecko"
- gecko_pref="layout.css.scroll-snap.enabled"
- sub_properties="scroll-snap-type-x scroll-snap-type-y"
- spec="https://drafts.csswg.org/css-scroll-snap/#propdef-scroll-snap-type">
- use crate::properties::longhands::scroll_snap_type_x;
-
- pub fn parse_value<'i, 't>(
- context: &ParserContext,
- input: &mut Parser<'i, 't>,
- ) -> Result<Longhands, ParseError<'i>> {
- 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-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 CssWriter<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.two_properties_shorthand(
"overscroll-behavior",
"overscroll-behavior-x",
diff --git a/components/style/values/computed/box.rs b/components/style/values/computed/box.rs
index fc7df203d54..c7a3ba7e36e 100644
--- a/components/style/values/computed/box.rs
+++ b/components/style/values/computed/box.rs
@@ -14,8 +14,8 @@ use crate::values::specified::box_ as specified;
pub use crate::values::specified::box_::{AnimationName, Appearance, BreakBetween, BreakWithin};
pub use crate::values::specified::box_::{Clear as SpecifiedClear, Float as SpecifiedFloat};
pub use crate::values::specified::box_::{Contain, Display, Overflow};
-pub use crate::values::specified::box_::{OverflowAnchor, OverflowClipBox};
-pub use crate::values::specified::box_::{OverscrollBehavior, ScrollSnapAlign, ScrollSnapStrictness};
+pub use crate::values::specified::box_::{OverflowAnchor, OverflowClipBox, OverscrollBehavior};
+pub use crate::values::specified::box_::{ScrollSnapAlign, ScrollSnapAxis, ScrollSnapStrictness, ScrollSnapType};
pub use crate::values::specified::box_::{TouchAction, TransitionProperty, WillChange};
/// A computed value for the `vertical-align` property.
diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs
index 74df937904d..72de7f2238e 100644
--- a/components/style/values/computed/mod.rs
+++ b/components/style/values/computed/mod.rs
@@ -42,7 +42,8 @@ pub use self::box_::{AnimationIterationCount, AnimationName, Contain};
pub use self::box_::{Appearance, BreakBetween, BreakWithin, Clear, Float};
pub use self::box_::{Display, Overflow, OverflowAnchor, TransitionProperty};
pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize};
-pub use self::box_::{ScrollSnapAlign, ScrollSnapStrictness, TouchAction, VerticalAlign, WillChange};
+pub use self::box_::{ScrollSnapAlign, ScrollSnapAxis, ScrollSnapStrictness, ScrollSnapType};
+pub use self::box_::{TouchAction, VerticalAlign, WillChange};
pub use self::color::{Color, ColorOrAuto, ColorPropertyValue};
pub use self::column::ColumnCount;
pub use self::counters::{Content, ContentItem, CounterIncrement, CounterSetOrReset};
diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs
index 29e2272f6b1..c003bf966bb 100644
--- a/components/style/values/specified/box.rs
+++ b/components/style/values/specified/box.rs
@@ -379,6 +379,32 @@ impl Parse for AnimationName {
}
}
+/// https://drafts.csswg.org/css-scroll-snap-1/#snap-axis
+#[allow(missing_docs)]
+#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
+#[derive(
+ Clone,
+ Copy,
+ Debug,
+ Eq,
+ MallocSizeOf,
+ Parse,
+ PartialEq,
+ SpecifiedValueInfo,
+ ToComputedValue,
+ ToCss,
+ ToResolvedValue,
+ ToShmem,
+)]
+#[repr(u8)]
+pub enum ScrollSnapAxis {
+ X,
+ Y,
+ Block,
+ Inline,
+ Both,
+}
+
/// https://drafts.csswg.org/css-scroll-snap-1/#snap-strictness
#[allow(missing_docs)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
@@ -398,11 +424,77 @@ impl Parse for AnimationName {
)]
#[repr(u8)]
pub enum ScrollSnapStrictness {
- None,
+ #[css(skip)]
+ None, // Used to represent scroll-snap-type: none. It's not parsed.
Mandatory,
Proximity,
}
+/// https://drafts.csswg.org/css-scroll-snap-1/#scroll-snap-type
+#[allow(missing_docs)]
+#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
+#[derive(
+ Clone,
+ Copy,
+ Debug,
+ Eq,
+ MallocSizeOf,
+ PartialEq,
+ SpecifiedValueInfo,
+ ToComputedValue,
+ ToResolvedValue,
+ ToShmem,
+)]
+#[repr(C)]
+pub struct ScrollSnapType {
+ axis: ScrollSnapAxis,
+ strictness: ScrollSnapStrictness,
+}
+
+impl ScrollSnapType {
+ /// Returns `none`.
+ #[inline]
+ pub fn none() -> Self {
+ Self {
+ axis: ScrollSnapAxis::Both,
+ strictness: ScrollSnapStrictness::None,
+ }
+ }
+}
+
+impl Parse for ScrollSnapType {
+ /// none | [ x | y | block | inline | both ] [ mandatory | proximity ]?
+ fn parse<'i, 't>(
+ _context: &ParserContext,
+ input: &mut Parser<'i, 't>,
+ ) -> Result<Self, ParseError<'i>> {
+ if input.try(|input| input.expect_ident_matching("none")).is_ok() {
+ return Ok(ScrollSnapType::none());
+ }
+
+ let axis = ScrollSnapAxis::parse(input)?;
+ let strictness = input.try(ScrollSnapStrictness::parse).unwrap_or(ScrollSnapStrictness::Proximity);
+ Ok(Self { axis, strictness })
+ }
+}
+
+impl ToCss for ScrollSnapType {
+ fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
+ where
+ W: Write,
+ {
+ if self.strictness == ScrollSnapStrictness::None {
+ return dest.write_str("none");
+ }
+ self.axis.to_css(dest)?;
+ if self.strictness != ScrollSnapStrictness::Proximity {
+ dest.write_str(" ")?;
+ self.strictness.to_css(dest)?;
+ }
+ Ok(())
+ }
+}
+
/// Specified value of scroll-snap-align keyword value.
#[allow(missing_docs)]
#[derive(
diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs
index 09675d01fe2..5c9e413cb09 100644
--- a/components/style/values/specified/mod.rs
+++ b/components/style/values/specified/mod.rs
@@ -40,7 +40,7 @@ pub use self::box_::{AnimationIterationCount, AnimationName, Contain, Display};
pub use self::box_::{Appearance, BreakBetween, BreakWithin};
pub use self::box_::{Clear, Float, Overflow, OverflowAnchor};
pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize};
-pub use self::box_::{ScrollSnapAlign, ScrollSnapStrictness};
+pub use self::box_::{ScrollSnapAlign, ScrollSnapAxis, ScrollSnapStrictness, ScrollSnapType};
pub use self::box_::{TouchAction, TransitionProperty, VerticalAlign, WillChange};
pub use self::color::{Color, ColorOrAuto, ColorPropertyValue};
pub use self::column::ColumnCount;