Bug 1374161 - Support none fallback for Paint server with URL. r?manishearth draft
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Wed, 05 Jul 2017 15:07:48 +0900
changeset 604045 b31e7905874fb878e425566d4b98e1f78fb20d0a
parent 604039 5022caca1ad1e139d960f82a1652154fb3c7c789
child 604046 c3cf63c992e07ee86ddc85efd8b6a8bc1d30d4f6
push id66933
push usermantaroh@gmail.com
push dateWed, 05 Jul 2017 06:08:15 +0000
reviewersmanishearth
bugs1374161
milestone56.0a1
Bug 1374161 - Support none fallback for Paint server with URL. r?manishearth MozReview-Commit-ID: KfKd3dfx8jQ
servo/components/style/values/generics/mod.rs
--- a/servo/components/style/values/generics/mod.rs
+++ b/servo/components/style/values/generics/mod.rs
@@ -318,35 +318,46 @@ impl<ColorType> SVGPaintKind<ColorType> 
         try_match_ident_ignore_ascii_case! { input.expect_ident()?,
             "none" => Ok(SVGPaintKind::None),
             "context-fill" => Ok(SVGPaintKind::ContextFill),
             "context-stroke" => Ok(SVGPaintKind::ContextStroke),
         }
     }
 }
 
+/// Parse SVGPaint's fallback.
+/// fallback is keyword(none) or Color.
+/// https://svgwg.org/svg2-draft/painting.html#SpecifyingPaint
+fn parse_fallback<'i, 't, ColorType: Parse>(context: &ParserContext,
+                                            input: &mut Parser<'i, 't>)
+                                            -> Option<ColorType> {
+    if input.try(|i| i.expect_ident_matching("none")).is_ok() {
+        None
+    } else {
+        input.try(|i| ColorType::parse(context, i)).ok()
+    }
+}
+
 impl<ColorType: Parse> Parse for SVGPaint<ColorType> {
     fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
         if let Ok(url) = input.try(|i| SpecifiedUrl::parse(context, i)) {
-            let fallback = input.try(|i| ColorType::parse(context, i));
             Ok(SVGPaint {
                 kind: SVGPaintKind::PaintServer(url),
-                fallback: fallback.ok(),
+                fallback: parse_fallback(context, input),
             })
         } else if let Ok(kind) = input.try(SVGPaintKind::parse_ident) {
             if let SVGPaintKind::None = kind {
                 Ok(SVGPaint {
                     kind: kind,
                     fallback: None,
                 })
             } else {
-                let fallback = input.try(|i| ColorType::parse(context, i));
                 Ok(SVGPaint {
                     kind: kind,
-                    fallback: fallback.ok(),
+                    fallback: parse_fallback(context, input),
                 })
             }
         } else if let Ok(color) = input.try(|i| ColorType::parse(context, i)) {
             Ok(SVGPaint {
                 kind: SVGPaintKind::Color(color),
                 fallback: None,
             })
         } else {