From fa6ab91acd4a0d2c27b6dc927c16b5f03058bd62 Mon Sep 17 00:00:00 2001 From: Boris Chiou Date: Sun, 21 May 2023 23:31:35 +0200 Subject: [PATCH] style: Part 1: Add SVG d property in CSS Add d property for style system. d property only supports path() for now and it has the functional notation without fill rule. https://github.com/w3c/svgwg/issues/320#issuecomment-414462645 Differential Revision: https://phabricator.services.mozilla.com/D81237 --- .../properties/counted_unknown_properties.py | 1 - .../style/properties/longhands/svg.mako.rs | 10 ++++ components/style/values/computed/mod.rs | 2 +- components/style/values/computed/svg.rs | 2 +- components/style/values/specified/mod.rs | 2 +- components/style/values/specified/svg.rs | 55 +++++++++++++++++++ 6 files changed, 68 insertions(+), 4 deletions(-) diff --git a/components/style/properties/counted_unknown_properties.py b/components/style/properties/counted_unknown_properties.py index 577547d099d..56d647cb57d 100644 --- a/components/style/properties/counted_unknown_properties.py +++ b/components/style/properties/counted_unknown_properties.py @@ -63,7 +63,6 @@ COUNTED_UNKNOWN_PROPERTIES = [ "-webkit-text-combine", "-webkit-text-emphasis-style", "-webkit-text-emphasis", - "d", "-webkit-mask-box-image-width", "-webkit-mask-box-image-source", "-webkit-mask-box-image-outset", diff --git a/components/style/properties/longhands/svg.mako.rs b/components/style/properties/longhands/svg.mako.rs index f6128693582..3d711462ff3 100644 --- a/components/style/properties/longhands/svg.mako.rs +++ b/components/style/properties/longhands/svg.mako.rs @@ -246,3 +246,13 @@ ${helpers.predefined_type( animation_value_type="LengthPercentage", spec="https://svgwg.org/svg2-draft/geometry.html#R", )} + +${helpers.predefined_type( + "d", + "DProperty", + "specified::DProperty::none()", + engines="gecko", + animation_value_type="ComputedValue", + gecko_pref="layout.css.d-property.enabled", + spec="https://svgwg.org/svg2-draft/paths.html#TheDProperty", +)} diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 826bb2a2448..1098bae1209 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -82,7 +82,7 @@ pub use self::position::{ pub use self::ratio::Ratio; pub use self::rect::NonNegativeLengthOrNumberRect; pub use self::resolution::Resolution; -pub use self::svg::MozContextProperties; +pub use self::svg::{DProperty, MozContextProperties}; pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind}; pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth}; pub use self::text::TextUnderlinePosition; diff --git a/components/style/values/computed/svg.rs b/components/style/values/computed/svg.rs index a348d071ab9..344f1d83518 100644 --- a/components/style/values/computed/svg.rs +++ b/components/style/values/computed/svg.rs @@ -11,7 +11,7 @@ use crate::values::generics::svg as generic; use crate::values::RGBA; use crate::Zero; -pub use crate::values::specified::{MozContextProperties, SVGPaintOrder}; +pub use crate::values::specified::{DProperty, MozContextProperties, SVGPaintOrder}; /// Computed SVG Paint value pub type SVGPaint = generic::GenericSVGPaint; diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 8a9cb73f4da..11498337a7f 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -80,7 +80,7 @@ pub use self::position::{PositionComponent, ZIndex}; pub use self::ratio::Ratio; pub use self::rect::NonNegativeLengthOrNumberRect; pub use self::resolution::Resolution; -pub use self::svg::MozContextProperties; +pub use self::svg::{DProperty, MozContextProperties}; pub use self::svg::{SVGLength, SVGOpacity, SVGPaint}; pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth}; pub use self::svg_path::SVGPathData; diff --git a/components/style/values/specified/svg.rs b/components/style/values/specified/svg.rs index abc6587239c..f06fc43c46d 100644 --- a/components/style/values/specified/svg.rs +++ b/components/style/values/specified/svg.rs @@ -10,6 +10,7 @@ use crate::values::specified::color::Color; use crate::values::specified::url::SpecifiedUrl; use crate::values::specified::AllowQuirks; use crate::values::specified::LengthPercentage; +use crate::values::specified::SVGPathData; use crate::values::specified::{NonNegativeLengthPercentage, Opacity}; use crate::values::CustomIdent; use cssparser::{Parser, Token}; @@ -334,3 +335,57 @@ impl Parse for MozContextProperties { }) } } + +/// The svg d property type. +/// +/// https://svgwg.org/svg2-draft/paths.html#TheDProperty +#[derive( + Animate, + Clone, + ComputeSquaredDistance, + Debug, + Deserialize, + MallocSizeOf, + PartialEq, + Serialize, + SpecifiedValueInfo, + ToAnimatedZero, + ToComputedValue, + ToCss, + ToResolvedValue, + ToShmem, +)] +#[repr(C, u8)] +pub enum DProperty { + /// Path value for path() or just a . + #[css(function)] + Path(SVGPathData), + /// None value. + #[animation(error)] + None, +} + +impl DProperty { + /// return none. + #[inline] + pub fn none() -> Self { + DProperty::None + } +} + +impl Parse for DProperty { + fn parse<'i, 't>( + context: &ParserContext, + input: &mut Parser<'i, 't>, + ) -> Result> { + // Parse none. + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { + return Ok(DProperty::none()); + } + + // Parse possible functions. + input.expect_function_matching("path")?; + let path_data = input.parse_nested_block(|i| SVGPathData::parse(context, i))?; + Ok(DProperty::Path(path_data)) + } +}