Add context-{fill,stroke}-opacity support to {fill,stroke}-opacity.

This commit is contained in:
Xidorn Quan 2017-08-02 09:27:49 +10:00
parent 7827ca6bb5
commit ef4352d2a5
8 changed files with 149 additions and 7 deletions

View file

@ -43,7 +43,7 @@ pub use self::length::{LengthOrPercentageOrNone, MaxLength, MozLength};
pub use self::length::{NoCalcLength, Percentage, ViewportPercentageLength};
pub use self::rect::LengthOrNumberRect;
pub use self::position::{Position, PositionComponent};
pub use self::svg::{SVGLength, SVGPaint, SVGPaintKind, SVGStrokeDashArray};
pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind, SVGStrokeDashArray};
pub use self::text::{InitialLetter, LetterSpacing, LineHeight, WordSpacing};
pub use self::transform::{TimingFunction, TransformOrigin};
pub use super::generics::grid::GridLine;

View file

@ -8,7 +8,7 @@ use cssparser::Parser;
use parser::{Parse, ParserContext};
use style_traits::{CommaWithSpace, ParseError, Separator, StyleParseError};
use values::generics::svg as generic;
use values::specified::LengthOrPercentageOrNumber;
use values::specified::{LengthOrPercentageOrNumber, Opacity};
use values::specified::color::RGBAColor;
/// Specified SVG Paint value
@ -87,3 +87,22 @@ impl Parse for SVGStrokeDashArray {
}
}
}
/// <opacity-value> | context-fill-opacity | context-stroke-opacity
pub type SVGOpacity = generic::SVGOpacity<Opacity>;
impl Parse for SVGOpacity {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Self, ParseError<'i>> {
if let Ok(opacity) = input.try(|i| Opacity::parse(context, i)) {
Ok(generic::SVGOpacity::Opacity(opacity))
} else if is_context_value_enabled() {
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
"context-fill-opacity" => Ok(generic::SVGOpacity::ContextFillOpacity),
"context-stroke-opacity" => Ok(generic::SVGOpacity::ContextStrokeOpacity),
}
} else {
Err(StyleParseError::UnspecifiedError.into())
}
}
}