mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #17150 - asajeffrey:script-paint-worklets-plumbing, r=jdm
Implemented the plumbing for paint worklets <!-- Please describe your changes on the following line: --> This PR implements the plumbing for paint worklets: * Adding CSS values for paint worklets. * Implementing a skeleton for the `PaintWorkletGlobalScope` webidl. * Implementing an executor for paint worklet tasks, and passing it from script to layout. * Building the display list items for paint worklet images. This PR does not implement registering or calling paint worklets in JS. Before it merges, this PR needs a reftest added for basic paint worklet functionality. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17150) <!-- Reviewable:end -->
This commit is contained in:
commit
bf46da065d
23 changed files with 600 additions and 156 deletions
|
@ -27,6 +27,10 @@ pub enum Image<Gradient, ImageRect> {
|
|||
Rect(ImageRect),
|
||||
/// A `-moz-element(# <element-id>)`
|
||||
Element(Atom),
|
||||
/// A paint worklet image.
|
||||
/// https://drafts.css-houdini.org/css-paint-api/
|
||||
#[cfg(feature = "servo")]
|
||||
PaintWorklet(PaintWorklet),
|
||||
}
|
||||
|
||||
/// A CSS gradient.
|
||||
|
@ -128,6 +132,23 @@ pub struct ColorStop<Color, LengthOrPercentage> {
|
|||
pub position: Option<LengthOrPercentage>,
|
||||
}
|
||||
|
||||
/// Specified values for a paint worklet.
|
||||
/// https://drafts.css-houdini.org/css-paint-api/
|
||||
#[derive(Clone, Debug, PartialEq, ToComputedValue)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct PaintWorklet {
|
||||
/// The name the worklet was registered with.
|
||||
pub name: Atom,
|
||||
}
|
||||
|
||||
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)?;
|
||||
dest.write_str(")")
|
||||
}
|
||||
}
|
||||
|
||||
/// Values for `moz-image-rect`.
|
||||
///
|
||||
/// `-moz-image-rect(<uri>, top, right, bottom, left);`
|
||||
|
@ -150,6 +171,8 @@ impl<G, R> fmt::Debug for Image<G, R>
|
|||
Image::Url(ref url) => url.to_css(f),
|
||||
Image::Gradient(ref grad) => grad.fmt(f),
|
||||
Image::Rect(ref rect) => rect.fmt(f),
|
||||
#[cfg(feature = "servo")]
|
||||
Image::PaintWorklet(ref paint_worklet) => paint_worklet.fmt(f),
|
||||
Image::Element(ref selector) => {
|
||||
f.write_str("-moz-element(#")?;
|
||||
serialize_identifier(&selector.to_string(), f)?;
|
||||
|
@ -167,6 +190,8 @@ impl<G, R> ToCss for Image<G, R>
|
|||
Image::Url(ref url) => url.to_css(dest),
|
||||
Image::Gradient(ref gradient) => gradient.to_css(dest),
|
||||
Image::Rect(ref rect) => rect.to_css(dest),
|
||||
#[cfg(feature = "servo")]
|
||||
Image::PaintWorklet(ref paint_worklet) => paint_worklet.to_css(dest),
|
||||
Image::Element(ref selector) => {
|
||||
dest.write_str("-moz-element(#")?;
|
||||
serialize_identifier(&selector.to_string(), dest)?;
|
||||
|
|
|
@ -22,6 +22,7 @@ use values::generics::image::{EndingShape as GenericEndingShape, Gradient as Gen
|
|||
use values::generics::image::{GradientItem as GenericGradientItem, GradientKind as GenericGradientKind};
|
||||
use values::generics::image::{Image as GenericImage, ImageRect as GenericImageRect};
|
||||
use values::generics::image::{LineDirection as GenericsLineDirection, ShapeExtent};
|
||||
use values::generics::image::PaintWorklet;
|
||||
use values::generics::position::Position as GenericPosition;
|
||||
use values::specified::{Angle, CSSColor, Color, Length, LengthOrPercentage};
|
||||
use values::specified::{Number, NumberOrPercentage, Percentage};
|
||||
|
@ -98,6 +99,12 @@ impl Parse for Image {
|
|||
if let Ok(gradient) = input.try(|i| Gradient::parse(context, i)) {
|
||||
return Ok(GenericImage::Gradient(gradient));
|
||||
}
|
||||
#[cfg(feature = "servo")]
|
||||
{
|
||||
if let Ok(paint_worklet) = input.try(|i| PaintWorklet::parse(context, i)) {
|
||||
return Ok(GenericImage::PaintWorklet(paint_worklet));
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "gecko")]
|
||||
{
|
||||
if let Ok(mut image_rect) = input.try(|input| ImageRect::parse(context, input)) {
|
||||
|
@ -673,6 +680,18 @@ impl Parse for ColorStop {
|
|||
}
|
||||
}
|
||||
|
||||
impl Parse for PaintWorklet {
|
||||
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
input.expect_function_matching("paint")?;
|
||||
input.parse_nested_block(|i| {
|
||||
let name = i.expect_ident()?;
|
||||
Ok(PaintWorklet {
|
||||
name: Atom::from(name),
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for ImageRect {
|
||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
input.try(|i| i.expect_function_matching("-moz-image-rect"))?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue