mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
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
This commit is contained in:
parent
2f457ed144
commit
21481e315e
7 changed files with 109 additions and 47 deletions
|
@ -341,7 +341,9 @@ class Longhand(object):
|
|||
"SVGOpacity",
|
||||
"SVGPaintOrder",
|
||||
"ScrollSnapAlign",
|
||||
"ScrollSnapAxis",
|
||||
"ScrollSnapStrictness",
|
||||
"ScrollSnapType",
|
||||
"TextAlign",
|
||||
"TextDecorationLine",
|
||||
"TextEmphasisPosition",
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue