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
This commit is contained in:
Boris Chiou 2023-05-21 23:31:35 +02:00 committed by Oriol Brufau
parent 4c7ddd63b3
commit fa6ab91acd
6 changed files with 68 additions and 4 deletions

View file

@ -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",

View file

@ -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",
)}

View file

@ -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;

View file

@ -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<Color, ComputedUrl>;

View file

@ -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;

View file

@ -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(<string>) or just a <string>.
#[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<Self, ParseError<'i>> {
// 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))
}
}