mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Implement parsing/serialization of will-change
This commit is contained in:
parent
5a656cfa54
commit
56b8c1d8b7
3 changed files with 93 additions and 0 deletions
|
@ -1973,3 +1973,67 @@ ${helpers.single_keyword("-moz-orient",
|
|||
gecko_enum_prefix="StyleOrient",
|
||||
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-orient)",
|
||||
animatable=False)}
|
||||
|
||||
<%helpers:longhand name="will-change" products="none" animatable="False"
|
||||
spec="https://drafts.csswg.org/css-will-change/#will-change">
|
||||
use cssparser::serialize_identifier;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::HasViewportPercentage;
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
|
||||
impl ComputedValueAsSpecified for SpecifiedValue {}
|
||||
no_viewport_percentage!(SpecifiedValue);
|
||||
|
||||
pub mod computed_value {
|
||||
pub use super::SpecifiedValue as T;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum SpecifiedValue {
|
||||
Auto,
|
||||
AnimateableFeatures(Vec<Atom>),
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
SpecifiedValue::Auto => dest.write_str("auto"),
|
||||
SpecifiedValue::AnimateableFeatures(ref features) => {
|
||||
let (first, rest) = features.split_first().unwrap();
|
||||
// handle head element
|
||||
serialize_identifier(&*first.to_string(), dest)?;
|
||||
// handle tail, precede each with a delimiter
|
||||
for feature in rest {
|
||||
dest.write_str(", ")?;
|
||||
serialize_identifier(&*feature.to_string(), dest)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T::Auto
|
||||
}
|
||||
|
||||
/// auto | <animateable-feature>#
|
||||
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
if input.try(|input| input.expect_ident_matching("auto")).is_ok() {
|
||||
Ok(computed_value::T::Auto)
|
||||
} else {
|
||||
input.parse_comma_separated(|i| {
|
||||
let ident = i.expect_ident()?;
|
||||
match_ignore_ascii_case! { &ident,
|
||||
"will-change" | "none" | "all" | "auto" |
|
||||
"initial" | "inherit" | "unset" | "default" => return Err(()),
|
||||
_ => {},
|
||||
}
|
||||
Ok((Atom::from(ident)))
|
||||
}).map(SpecifiedValue::AnimateableFeatures)
|
||||
}
|
||||
}
|
||||
</%helpers:longhand>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue