mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Implemented paint worklet arguments.
This commit is contained in:
parent
d859734702
commit
d101f9c945
8 changed files with 78 additions and 27 deletions
|
@ -8,6 +8,7 @@
|
|||
|
||||
use Atom;
|
||||
use cssparser::serialize_identifier;
|
||||
use custom_properties::SpecifiedValue;
|
||||
use std::fmt;
|
||||
use style_traits::{HasViewportPercentage, ToCss};
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
|
@ -136,17 +137,26 @@ pub struct ColorStop<Color, LengthOrPercentage> {
|
|||
|
||||
/// Specified values for a paint worklet.
|
||||
/// https://drafts.css-houdini.org/css-paint-api/
|
||||
#[derive(Clone, Debug, PartialEq, ToComputedValue)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct PaintWorklet {
|
||||
/// The name the worklet was registered with.
|
||||
pub name: Atom,
|
||||
/// The arguments for the worklet.
|
||||
/// TODO: store a parsed representation of the arguments.
|
||||
pub arguments: Vec<SpecifiedValue>,
|
||||
}
|
||||
|
||||
impl ComputedValueAsSpecified for PaintWorklet {}
|
||||
|
||||
impl ToCss for PaintWorklet {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
dest.write_str("paint(")?;
|
||||
serialize_identifier(&*self.name.to_string(), dest)?;
|
||||
for argument in &self.arguments {
|
||||
dest.write_str(", ")?;
|
||||
argument.to_css(dest)?;
|
||||
}
|
||||
dest.write_str(")")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
use Atom;
|
||||
use cssparser::{Parser, Token, BasicParseError};
|
||||
use custom_properties::SpecifiedValue;
|
||||
use parser::{Parse, ParserContext};
|
||||
use selectors::parser::SelectorParseError;
|
||||
#[cfg(feature = "servo")]
|
||||
|
@ -874,12 +875,17 @@ impl Parse for ColorStop {
|
|||
}
|
||||
|
||||
impl Parse for PaintWorklet {
|
||||
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||
input.expect_function_matching("paint")?;
|
||||
input.parse_nested_block(|i| {
|
||||
let name = i.expect_ident()?;
|
||||
input.parse_nested_block(|input| {
|
||||
let name = Atom::from(&**input.expect_ident()?);
|
||||
let arguments = input.try(|input| {
|
||||
input.expect_comma()?;
|
||||
input.parse_comma_separated(|input| Ok(*SpecifiedValue::parse(context, input)?))
|
||||
}).unwrap_or(vec![]);
|
||||
Ok(PaintWorklet {
|
||||
name: Atom::from(name.as_ref()),
|
||||
name: name,
|
||||
arguments: arguments,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue