style: Use cbindgen for fill and stroke.

Differential Revision: https://phabricator.services.mozilla.com/D36807
This commit is contained in:
Emilio Cobos Álvarez 2019-07-06 08:31:02 +00:00
parent 83da7c1535
commit 341023690c
No known key found for this signature in database
GPG key ID: E1152D0994E4BF8A
5 changed files with 33 additions and 129 deletions

View file

@ -523,110 +523,6 @@ def set_gecko_property(ffi_name, expr):
} }
</%def> </%def>
<%def name="impl_svg_paint(ident, gecko_ffi_name)">
#[allow(non_snake_case)]
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
use crate::values::generics::svg::{SVGPaintKind, SVGPaintFallback};
use self::structs::nsStyleSVGPaintType;
use self::structs::nsStyleSVGFallbackType;
let ref mut paint = ${get_gecko_property(gecko_ffi_name)};
unsafe {
bindings::Gecko_nsStyleSVGPaint_Reset(paint);
}
match v.kind {
SVGPaintKind::None => return,
SVGPaintKind::ContextFill => {
paint.mType = nsStyleSVGPaintType::eStyleSVGPaintType_ContextFill;
}
SVGPaintKind::ContextStroke => {
paint.mType = nsStyleSVGPaintType::eStyleSVGPaintType_ContextStroke;
}
SVGPaintKind::PaintServer(url) => {
unsafe {
bindings::Gecko_nsStyleSVGPaint_SetURLValue(
paint,
&url
)
}
}
SVGPaintKind::Color(color) => {
paint.mType = nsStyleSVGPaintType::eStyleSVGPaintType_Color;
unsafe {
*paint.mPaint.mColor.as_mut() = color.into();
}
}
}
paint.mFallbackType = match v.fallback {
SVGPaintFallback::Color(c) => {
paint.mFallbackColor = c.into();
nsStyleSVGFallbackType::eStyleSVGFallbackType_Color
},
SVGPaintFallback::None => {
nsStyleSVGFallbackType::eStyleSVGFallbackType_None
},
SVGPaintFallback::Unset => {
nsStyleSVGFallbackType::eStyleSVGFallbackType_NotSet
}
};
}
#[allow(non_snake_case)]
pub fn copy_${ident}_from(&mut self, other: &Self) {
unsafe {
bindings::Gecko_nsStyleSVGPaint_CopyFrom(
&mut ${get_gecko_property(gecko_ffi_name)},
& ${get_gecko_property(gecko_ffi_name, "other")}
);
}
}
#[allow(non_snake_case)]
pub fn reset_${ident}(&mut self, other: &Self) {
self.copy_${ident}_from(other)
}
#[allow(non_snake_case)]
pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
use crate::values::generics::svg::{SVGPaint, SVGPaintKind, SVGPaintFallback};
use self::structs::nsStyleSVGPaintType;
use self::structs::nsStyleSVGFallbackType;
let ref paint = ${get_gecko_property(gecko_ffi_name)};
let fallback = match paint.mFallbackType {
nsStyleSVGFallbackType::eStyleSVGFallbackType_Color => {
SVGPaintFallback::Color(paint.mFallbackColor.into())
},
nsStyleSVGFallbackType::eStyleSVGFallbackType_None => {
SVGPaintFallback::None
},
nsStyleSVGFallbackType::eStyleSVGFallbackType_NotSet => {
SVGPaintFallback::Unset
}
};
let kind = match paint.mType {
nsStyleSVGPaintType::eStyleSVGPaintType_None => SVGPaintKind::None,
nsStyleSVGPaintType::eStyleSVGPaintType_ContextFill => SVGPaintKind::ContextFill,
nsStyleSVGPaintType::eStyleSVGPaintType_ContextStroke => SVGPaintKind::ContextStroke,
nsStyleSVGPaintType::eStyleSVGPaintType_Server => {
SVGPaintKind::PaintServer(unsafe {
paint.mPaint.mPaintServer.as_ref().clone()
})
}
nsStyleSVGPaintType::eStyleSVGPaintType_Color => {
let col = unsafe { *paint.mPaint.mColor.as_ref() };
SVGPaintKind::Color(col.into())
}
};
SVGPaint {
kind: kind,
fallback: fallback,
}
}
</%def>
<%def name="impl_non_negative_length(ident, gecko_ffi_name, inherit_from=None, <%def name="impl_non_negative_length(ident, gecko_ffi_name, inherit_from=None,
round_to_pixels=False)"> round_to_pixels=False)">
#[allow(non_snake_case)] #[allow(non_snake_case)]
@ -836,7 +732,6 @@ impl Clone for ${style_struct.gecko_struct_name} {
"MozScriptMinSize": impl_absolute_length, "MozScriptMinSize": impl_absolute_length,
"SVGLength": impl_svg_length, "SVGLength": impl_svg_length,
"SVGOpacity": impl_svg_opacity, "SVGOpacity": impl_svg_opacity,
"SVGPaint": impl_svg_paint,
"SVGWidth": impl_svg_length, "SVGWidth": impl_svg_length,
} }

View file

@ -11,14 +11,13 @@ use crate::values::generics::svg as generic;
use crate::values::RGBA; use crate::values::RGBA;
use crate::Zero; use crate::Zero;
pub use crate::values::specified::SVGPaintOrder; pub use crate::values::specified::{SVGPaintOrder, MozContextProperties};
pub use crate::values::specified::MozContextProperties;
/// Computed SVG Paint value /// Computed SVG Paint value
pub type SVGPaint = generic::SVGPaint<Color, ComputedUrl>; pub type SVGPaint = generic::GenericSVGPaint<Color, ComputedUrl>;
/// Computed SVG Paint Kind value /// Computed SVG Paint Kind value
pub type SVGPaintKind = generic::SVGPaintKind<Color, ComputedUrl>; pub type SVGPaintKind = generic::GenericSVGPaintKind<Color, ComputedUrl>;
impl SVGPaint { impl SVGPaint {
/// Opaque black color /// Opaque black color

View file

@ -9,6 +9,7 @@ use cssparser::Parser;
use style_traits::ParseError; use style_traits::ParseError;
/// The fallback of an SVG paint server value. /// The fallback of an SVG paint server value.
/// cbindgen:derive-tagged-enum-copy-constructor=true
#[derive( #[derive(
Animate, Animate,
Clone, Clone,
@ -25,7 +26,8 @@ use style_traits::ParseError;
ToResolvedValue, ToResolvedValue,
ToShmem, ToShmem,
)] )]
pub enum SVGPaintFallback<C> { #[repr(C, u8)]
pub enum GenericSVGPaintFallback<C> {
/// The `none` keyword. /// The `none` keyword.
None, None,
/// A magic value that represents no fallback specified and serializes to /// A magic value that represents no fallback specified and serializes to
@ -36,10 +38,14 @@ pub enum SVGPaintFallback<C> {
Color(C), Color(C),
} }
pub use self::GenericSVGPaintFallback as SVGPaintFallback;
/// An SVG paint value /// An SVG paint value
/// ///
/// <https://www.w3.org/TR/SVG2/painting.html#SpecifyingPaint> /// <https://www.w3.org/TR/SVG2/painting.html#SpecifyingPaint>
#[animation(no_bound(UrlPaintServer))] ///
/// cbindgen:derive-tagged-enum-copy-constructor=true
#[animation(no_bound(Url))]
#[derive( #[derive(
Animate, Animate,
Clone, Clone,
@ -55,13 +61,16 @@ pub enum SVGPaintFallback<C> {
ToResolvedValue, ToResolvedValue,
ToShmem, ToShmem,
)] )]
pub struct SVGPaint<ColorType, UrlPaintServer> { #[repr(C)]
pub struct GenericSVGPaint<Color, Url> {
/// The paint source. /// The paint source.
pub kind: SVGPaintKind<ColorType, UrlPaintServer>, pub kind: GenericSVGPaintKind<Color, Url>,
/// The fallback color. /// The fallback color.
pub fallback: SVGPaintFallback<ColorType>, pub fallback: GenericSVGPaintFallback<Color>,
} }
pub use self::GenericSVGPaint as SVGPaint;
impl<C, U> Default for SVGPaint<C, U> { impl<C, U> Default for SVGPaint<C, U> {
fn default() -> Self { fn default() -> Self {
Self { Self {
@ -71,12 +80,13 @@ impl<C, U> Default for SVGPaint<C, U> {
} }
} }
/// An SVG paint value without the fallback /// An SVG paint value without the fallback.
/// ///
/// Whereas the spec only allows PaintServer /// Whereas the spec only allows PaintServer to have a fallback, Gecko lets the
/// to have a fallback, Gecko lets the context /// context properties have a fallback as well.
/// properties have a fallback as well. ///
#[animation(no_bound(UrlPaintServer))] /// cbindgen:derive-tagged-enum-copy-constructor=true
#[animation(no_bound(U))]
#[derive( #[derive(
Animate, Animate,
Clone, Clone,
@ -93,22 +103,25 @@ impl<C, U> Default for SVGPaint<C, U> {
ToResolvedValue, ToResolvedValue,
ToShmem, ToShmem,
)] )]
pub enum SVGPaintKind<ColorType, UrlPaintServer> { #[repr(C, u8)]
pub enum GenericSVGPaintKind<C, U> {
/// `none` /// `none`
#[animation(error)] #[animation(error)]
None, None,
/// `<color>` /// `<color>`
Color(ColorType), Color(C),
/// `url(...)` /// `url(...)`
#[animation(error)] #[animation(error)]
PaintServer(UrlPaintServer), PaintServer(U),
/// `context-fill` /// `context-fill`
ContextFill, ContextFill,
/// `context-stroke` /// `context-stroke`
ContextStroke, ContextStroke,
} }
impl<ColorType: Parse, UrlPaintServer: Parse> Parse for SVGPaint<ColorType, UrlPaintServer> { pub use self::GenericSVGPaintKind as SVGPaintKind;
impl<C: Parse, U: Parse> Parse for SVGPaint<C, U> {
fn parse<'i, 't>( fn parse<'i, 't>(
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,

View file

@ -74,7 +74,7 @@ pub use self::position::{PositionComponent, ZIndex};
pub use self::rect::NonNegativeLengthOrNumberRect; pub use self::rect::NonNegativeLengthOrNumberRect;
pub use self::resolution::Resolution; pub use self::resolution::Resolution;
pub use self::svg::MozContextProperties; pub use self::svg::MozContextProperties;
pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind}; pub use self::svg::{SVGLength, SVGOpacity, SVGPaint};
pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth}; pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth};
pub use self::svg_path::SVGPathData; pub use self::svg_path::SVGPathData;
pub use self::table::XSpan; pub use self::table::XSpan;

View file

@ -18,10 +18,7 @@ use style_traits::{CommaWithSpace, CssWriter, ParseError, Separator};
use style_traits::{StyleParseErrorKind, ToCss}; use style_traits::{StyleParseErrorKind, ToCss};
/// Specified SVG Paint value /// Specified SVG Paint value
pub type SVGPaint = generic::SVGPaint<Color, SpecifiedUrl>; pub type SVGPaint = generic::GenericSVGPaint<Color, SpecifiedUrl>;
/// Specified SVG Paint Kind value
pub type SVGPaintKind = generic::SVGPaintKind<Color, SpecifiedUrl>;
/// <length> | <percentage> | <number> | context-value /// <length> | <percentage> | <number> | context-value
pub type SVGLength = generic::SVGLength<LengthPercentage>; pub type SVGLength = generic::SVGLength<LengthPercentage>;