mirror of
https://github.com/servo/servo.git
synced 2025-07-16 11:53:39 +01:00
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
This commit is contained in:
parent
7cbaaf6734
commit
22e12a0f52
8 changed files with 97 additions and 3 deletions
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue