Skip to content

Commit

Permalink
style: Part 1: Add SVG d property in CSS
Browse files Browse the repository at this point in the history
Add d property for style system. d property only supports path() for now
and it has the functional notation without fill rule.

w3c/svgwg#320 (comment)

Differential Revision: https://phabricator.services.mozilla.com/D81237
  • Loading branch information
Loirooriol committed May 21, 2023
1 parent a613212 commit 488338e
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 4 deletions.
1 change: 0 additions & 1 deletion components/style/properties/counted_unknown_properties.py
Expand Up @@ -63,7 +63,6 @@
"-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",
Expand Down
10 changes: 10 additions & 0 deletions components/style/properties/longhands/svg.mako.rs
Expand Up @@ -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",
)}
2 changes: 1 addition & 1 deletion components/style/values/computed/mod.rs
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion components/style/values/computed/svg.rs
Expand Up @@ -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>;
Expand Down
2 changes: 1 addition & 1 deletion components/style/values/specified/mod.rs
Expand Up @@ -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;
Expand Down
55 changes: 55 additions & 0 deletions components/style/values/specified/svg.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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))
}
}

0 comments on commit 488338e

Please sign in to comment.