mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +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
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue