mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Support None and NotSet for the fallback type of SVGPaint.
This commit is contained in:
parent
e97f28e2a6
commit
2d84686113
2 changed files with 32 additions and 15 deletions
|
@ -60,7 +60,7 @@ use selector_parser::PseudoElement;
|
||||||
use servo_arc::{Arc, RawOffsetArc};
|
use servo_arc::{Arc, RawOffsetArc};
|
||||||
use std::mem::{forget, uninitialized, transmute, zeroed};
|
use std::mem::{forget, uninitialized, transmute, zeroed};
|
||||||
use std::{cmp, ops, ptr};
|
use std::{cmp, ops, ptr};
|
||||||
use values::{self, Auto, CustomIdent, Either, KeyframesName};
|
use values::{self, Auto, CustomIdent, Either, KeyframesName, None_};
|
||||||
use values::computed::{NonNegativeAu, ToComputedValue, Percentage};
|
use values::computed::{NonNegativeAu, ToComputedValue, Percentage};
|
||||||
use values::computed::effects::{BoxShadow, Filter, SimpleShadow};
|
use values::computed::effects::{BoxShadow, Filter, SimpleShadow};
|
||||||
use computed_values::border_style;
|
use computed_values::border_style;
|
||||||
|
@ -743,10 +743,16 @@ def set_gecko_property(ffi_name, expr):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(fallback) = fallback {
|
paint.mFallbackType = match fallback {
|
||||||
paint.mFallbackType = nsStyleSVGFallbackType::eStyleSVGFallbackType_Color;
|
Some(Either::First(color)) => {
|
||||||
paint.mFallbackColor = convert_rgba_to_nscolor(&fallback);
|
paint.mFallbackColor = convert_rgba_to_nscolor(&color);
|
||||||
}
|
nsStyleSVGFallbackType::eStyleSVGFallbackType_Color
|
||||||
|
},
|
||||||
|
Some(Either::Second(_)) => {
|
||||||
|
nsStyleSVGFallbackType::eStyleSVGFallbackType_None
|
||||||
|
},
|
||||||
|
None => nsStyleSVGFallbackType::eStyleSVGFallbackType_NotSet
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
|
@ -771,11 +777,17 @@ def set_gecko_property(ffi_name, expr):
|
||||||
use self::structs::nsStyleSVGPaintType;
|
use self::structs::nsStyleSVGPaintType;
|
||||||
use self::structs::nsStyleSVGFallbackType;
|
use self::structs::nsStyleSVGFallbackType;
|
||||||
let ref paint = ${get_gecko_property(gecko_ffi_name)};
|
let ref paint = ${get_gecko_property(gecko_ffi_name)};
|
||||||
let fallback = if let nsStyleSVGFallbackType::eStyleSVGFallbackType_Color = paint.mFallbackType {
|
|
||||||
Some(convert_nscolor_to_rgba(paint.mFallbackColor))
|
let fallback = match paint.mFallbackType {
|
||||||
} else {
|
nsStyleSVGFallbackType::eStyleSVGFallbackType_Color => {
|
||||||
None
|
Some(Either::First(convert_nscolor_to_rgba(paint.mFallbackColor)))
|
||||||
|
},
|
||||||
|
nsStyleSVGFallbackType::eStyleSVGFallbackType_None => {
|
||||||
|
Some(Either::Second(None_))
|
||||||
|
},
|
||||||
|
nsStyleSVGFallbackType::eStyleSVGFallbackType_NotSet => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let kind = match paint.mType {
|
let kind = match paint.mType {
|
||||||
nsStyleSVGPaintType::eStyleSVGPaintType_None => SVGPaintKind::None,
|
nsStyleSVGPaintType::eStyleSVGPaintType_None => SVGPaintKind::None,
|
||||||
nsStyleSVGPaintType::eStyleSVGPaintType_ContextFill => SVGPaintKind::ContextFill,
|
nsStyleSVGPaintType::eStyleSVGPaintType_ContextFill => SVGPaintKind::ContextFill,
|
||||||
|
|
|
@ -8,6 +8,7 @@ use cssparser::Parser;
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::{ParseError, StyleParseError, ToCss};
|
use style_traits::{ParseError, StyleParseError, ToCss};
|
||||||
|
use values::{Either, None_};
|
||||||
use values::computed::NumberOrPercentage;
|
use values::computed::NumberOrPercentage;
|
||||||
use values::computed::length::LengthOrPercentage;
|
use values::computed::length::LengthOrPercentage;
|
||||||
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||||
|
@ -21,8 +22,8 @@ use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||||
pub struct SVGPaint<ColorType, UrlPaintServer> {
|
pub struct SVGPaint<ColorType, UrlPaintServer> {
|
||||||
/// The paint source
|
/// The paint source
|
||||||
pub kind: SVGPaintKind<ColorType, UrlPaintServer>,
|
pub kind: SVGPaintKind<ColorType, UrlPaintServer>,
|
||||||
/// The fallback color
|
/// The fallback color. It would be empty, the `none` keyword or <color>.
|
||||||
pub fallback: Option<ColorType>,
|
pub fallback: Option<Either<ColorType, None_>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An SVG paint value without the fallback
|
/// An SVG paint value without the fallback
|
||||||
|
@ -60,15 +61,19 @@ impl<ColorType, UrlPaintServer> SVGPaintKind<ColorType, UrlPaintServer> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse SVGPaint's fallback.
|
/// Parse SVGPaint's fallback.
|
||||||
/// fallback is keyword(none) or Color.
|
/// fallback is keyword(none), Color or empty.
|
||||||
/// https://svgwg.org/svg2-draft/painting.html#SpecifyingPaint
|
/// https://svgwg.org/svg2-draft/painting.html#SpecifyingPaint
|
||||||
fn parse_fallback<'i, 't, ColorType: Parse>(context: &ParserContext,
|
fn parse_fallback<'i, 't, ColorType: Parse>(context: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>)
|
input: &mut Parser<'i, 't>)
|
||||||
-> Option<ColorType> {
|
-> Option<Either<ColorType, None_>> {
|
||||||
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
|
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
|
||||||
None
|
Some(Either::Second(None_))
|
||||||
} else {
|
} else {
|
||||||
input.try(|i| ColorType::parse(context, i)).ok()
|
if let Ok(color) = input.try(|i| ColorType::parse(context, i)) {
|
||||||
|
Some(Either::First(color))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue