aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHiroyuki Ikezoe <hikezoe@mozilla.com>2019-02-18 23:10:08 +0000
committerEmilio Cobos Álvarez <emilio@crisal.io>2019-02-23 21:03:55 -0800
commit22e12a0f52bd075e36d17dcc935ed1bfd41d35b7 (patch)
tree4265c0a8c7961a337a3ac0456f58833dc893dee3
parent7cbaaf6734756774546b87f253b4516a65fb8756 (diff)
downloadservo-22e12a0f52bd075e36d17dcc935ed1bfd41d35b7.tar.gz
servo-22e12a0f52bd075e36d17dcc935ed1bfd41d35b7.zip
style: Implement scroll-snap-align parser and serializer.
https://drafts.csswg.org/css-scroll-snap-1/#scroll-snap-align Differential Revision: https://phabricator.services.mozilla.com/D20205
-rw-r--r--components/style/cbindgen.toml1
-rw-r--r--components/style/properties/data.py1
-rw-r--r--components/style/properties/gecko.mako.rs1
-rw-r--r--components/style/properties/longhands/box.mako.rs10
-rw-r--r--components/style/values/computed/box.rs2
-rw-r--r--components/style/values/computed/mod.rs2
-rw-r--r--components/style/values/specified/box.rs80
-rw-r--r--components/style/values/specified/mod.rs3
8 files changed, 97 insertions, 3 deletions
diff --git a/components/style/cbindgen.toml b/components/style/cbindgen.toml
index 29aafa4945b..17f78d83309 100644
--- a/components/style/cbindgen.toml
+++ b/components/style/cbindgen.toml
@@ -70,6 +70,7 @@ include = [
"UserSelect",
"Float",
"OverscrollBehavior",
+ "ScrollSnapAlign",
"ScrollSnapType",
"OverflowAnchor",
"OverflowClipBox",
diff --git a/components/style/properties/data.py b/components/style/properties/data.py
index b897cc140d2..f3b4e43c225 100644
--- a/components/style/properties/data.py
+++ b/components/style/properties/data.py
@@ -339,6 +339,7 @@ class Longhand(object):
"Resize",
"SVGOpacity",
"SVGPaintOrder",
+ "ScrollSnapAlign",
"ScrollSnapType",
"TextAlign",
"TextDecorationLine",
diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs
index 13480948ecf..4466ebc06d5 100644
--- a/components/style/properties/gecko.mako.rs
+++ b/components/style/properties/gecko.mako.rs
@@ -1354,6 +1354,7 @@ impl Clone for ${style_struct.gecko_struct_name} {
"Appearance": impl_simple,
"OverscrollBehavior": impl_simple,
"OverflowClipBox": impl_simple,
+ "ScrollSnapAlign": impl_simple,
"ScrollSnapType": impl_simple,
"Float": impl_simple,
"Overflow": impl_simple,
diff --git a/components/style/properties/longhands/box.mako.rs b/components/style/properties/longhands/box.mako.rs
index 223db1d6e7c..1a8abfb3611 100644
--- a/components/style/properties/longhands/box.mako.rs
+++ b/components/style/properties/longhands/box.mako.rs
@@ -417,6 +417,16 @@ ${helpers.single_keyword(
animation_value_type="discrete",
)}
+${helpers.predefined_type(
+ "scroll-snap-align",
+ "ScrollSnapAlign",
+ "computed::ScrollSnapAlign::none()",
+ products="gecko",
+ gecko_pref="layout.css.scroll-snap-v1.enabled",
+ spec="https://drafts.csswg.org/css-scroll-snap-1/#scroll-snap-align",
+ animation_value_type="discrete",
+)}
+
% for axis in ["x", "y"]:
${helpers.predefined_type(
"scroll-snap-type-" + axis,
diff --git a/components/style/values/computed/box.rs b/components/style/values/computed/box.rs
index 46d3f93854e..decba9f342f 100644
--- a/components/style/values/computed/box.rs
+++ b/components/style/values/computed/box.rs
@@ -15,7 +15,7 @@ pub use crate::values::specified::box_::{AnimationName, Appearance, BreakBetween
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, ScrollSnapType};
+pub use crate::values::specified::box_::{OverscrollBehavior, ScrollSnapAlign, 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 8158e1a16d7..ab6425a20e7 100644
--- a/components/style/values/computed/mod.rs
+++ b/components/style/values/computed/mod.rs
@@ -44,7 +44,7 @@ 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_::{ScrollSnapType, TouchAction, VerticalAlign, WillChange};
+pub use self::box_::{ScrollSnapAlign, ScrollSnapType, TouchAction, VerticalAlign, WillChange};
pub use self::color::{Color, ColorPropertyValue, RGBAColor};
pub use self::column::ColumnCount;
pub use self::counters::{Content, ContentItem, CounterIncrement, CounterReset};
diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs
index b94ec8a0f26..06ce826d108 100644
--- a/components/style/values/specified/box.rs
+++ b/components/style/values/specified/box.rs
@@ -392,6 +392,86 @@ pub enum ScrollSnapType {
Proximity,
}
+/// Specified value of scroll-snap-align keyword value.
+#[allow(missing_docs)]
+#[derive(
+ Clone,
+ Copy,
+ Debug,
+ Eq,
+ FromPrimitive,
+ Hash,
+ MallocSizeOf,
+ Parse,
+ PartialEq,
+ SpecifiedValueInfo,
+ ToComputedValue,
+ ToCss,
+)]
+#[repr(u8)]
+pub enum ScrollSnapAlignKeyword {
+ None,
+ Start,
+ End,
+ Center,
+}
+
+/// https://drafts.csswg.org/css-scroll-snap-1/#scroll-snap-align
+#[allow(missing_docs)]
+#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
+#[derive(
+ Clone,
+ Copy,
+ Debug,
+ Eq,
+ MallocSizeOf,
+ PartialEq,
+ SpecifiedValueInfo,
+ ToComputedValue,
+)]
+#[repr(C)]
+pub struct ScrollSnapAlign {
+ block: ScrollSnapAlignKeyword,
+ inline: ScrollSnapAlignKeyword,
+}
+
+impl ScrollSnapAlign {
+ /// Returns `none`.
+ #[inline]
+ pub fn none() -> Self {
+ ScrollSnapAlign {
+ block: ScrollSnapAlignKeyword::None,
+ inline: ScrollSnapAlignKeyword::None,
+ }
+ }
+}
+
+impl Parse for ScrollSnapAlign {
+ /// [ none | start | end | center ]{1,2}
+ fn parse<'i, 't>(
+ _context: &ParserContext,
+ input: &mut Parser<'i, 't>,
+ ) -> Result<ScrollSnapAlign, ParseError<'i>> {
+ let block = ScrollSnapAlignKeyword::parse(input)?;
+ let inline = input.try(ScrollSnapAlignKeyword::parse).unwrap_or(block);
+ Ok(ScrollSnapAlign { block, inline })
+ }
+}
+
+impl ToCss for ScrollSnapAlign {
+ fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
+ where
+ W: Write,
+ {
+ self.block.to_css(dest)?;
+ if self.block != self.inline {
+ dest.write_str(" ")?;
+ self.inline.to_css(dest)?;
+ }
+ Ok(())
+ }
+}
+
#[allow(missing_docs)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive(
diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs
index a9582e90307..3af896baeb0 100644
--- a/components/style/values/specified/mod.rs
+++ b/components/style/values/specified/mod.rs
@@ -39,7 +39,8 @@ 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_::{ScrollSnapType, TouchAction, TransitionProperty, VerticalAlign, WillChange};
+pub use self::box_::{ScrollSnapAlign, ScrollSnapType};
+pub use self::box_::{TouchAction, TransitionProperty, VerticalAlign, WillChange};
pub use self::color::{Color, ColorPropertyValue, RGBAColor};
pub use self::column::ColumnCount;
pub use self::counters::{Content, ContentItem, CounterIncrement, CounterReset};