servo: Merge #20190 - style: Don't guard the context opacity keywords with the svg in opentype pref (from emilio:context-opacity); r=upsuper
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sat, 03 Mar 2018 19:12:18 -0500
changeset 461498 1fb5d2d675ab178768684c668e053a4763d37c5f
parent 461497 4f949bd26e326af7189a4abcbee46d496dd8812e
child 461499 67fa0cfa27ef5a4ec21df9740fb9f72709475208
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersupsuper
bugs1365926, 1442867
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #20190 - style: Don't guard the context opacity keywords with the svg in opentype pref (from emilio:context-opacity); r=upsuper This is effectively the stylo version of the second patch for bug 1365926, and should fix bug 1442867. Source-Repo: https://github.com/servo/servo Source-Revision: b59a8afd0fe922613d545fcb062d5bf4bb305980
servo/components/style/values/specified/svg.rs
--- a/servo/components/style/values/specified/svg.rs
+++ b/servo/components/style/values/specified/svg.rs
@@ -30,37 +30,41 @@ fn is_context_value_enabled() -> bool {
     use gecko_bindings::structs::mozilla;
     unsafe { mozilla::StylePrefs_sOpentypeSVGEnabled }
 }
 #[cfg(not(feature = "gecko"))]
 fn is_context_value_enabled() -> bool {
     false
 }
 
-fn parse_context_value<'i, 't, T>(input: &mut Parser<'i, 't>, value: T)
-                                  -> Result<T, ParseError<'i>> {
-    if is_context_value_enabled() {
-        if input.expect_ident_matching("context-value").is_ok() {
-            return Ok(value);
-        }
+fn parse_context_value<'i, 't, T>(
+    input: &mut Parser<'i, 't>,
+    value: T,
+) -> Result<T, ParseError<'i>> {
+    if !is_context_value_enabled() {
+        return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
     }
-    Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
+
+    input.expect_ident_matching("context-value")?;
+    Ok(value)
 }
 
 /// A value of <length> | <percentage> | <number> for stroke-dashoffset.
 /// <https://www.w3.org/TR/SVG11/painting.html#StrokeProperties>
 pub type SvgLengthOrPercentageOrNumber =
     generic::SvgLengthOrPercentageOrNumber<LengthOrPercentage, Number>;
 
 /// <length> | <percentage> | <number> | context-value
 pub type SVGLength = generic::SVGLength<SvgLengthOrPercentageOrNumber>;
 
 impl Parse for SVGLength {
-    fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-                     -> Result<Self, ParseError<'i>> {
+    fn parse<'i, 't>(
+        context: &ParserContext,
+        input: &mut Parser<'i, 't>,
+    ) -> Result<Self, ParseError<'i>> {
         input.try(|i| SvgLengthOrPercentageOrNumber::parse(context, i))
              .map(Into::into)
              .or_else(|_| parse_context_value(input, generic::SVGLength::ContextValue))
     }
 }
 
 impl From<SvgLengthOrPercentageOrNumber> for SVGLength {
     fn from(length: SvgLengthOrPercentageOrNumber) -> Self {
@@ -72,63 +76,67 @@ impl From<SvgLengthOrPercentageOrNumber>
 /// <https://www.w3.org/TR/SVG11/painting.html#StrokeProperties>
 pub type NonNegativeSvgLengthOrPercentageOrNumber =
     generic::SvgLengthOrPercentageOrNumber<NonNegativeLengthOrPercentage, NonNegativeNumber>;
 
 /// A non-negative version of SVGLength.
 pub type SVGWidth = generic::SVGLength<NonNegativeSvgLengthOrPercentageOrNumber>;
 
 impl Parse for SVGWidth {
-    fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-                     -> Result<Self, ParseError<'i>> {
+    fn parse<'i, 't>(
+        context: &ParserContext,
+        input: &mut Parser<'i, 't>,
+    ) -> Result<Self, ParseError<'i>> {
         input.try(|i| NonNegativeSvgLengthOrPercentageOrNumber::parse(context, i))
              .map(Into::into)
              .or_else(|_| parse_context_value(input, generic::SVGLength::ContextValue))
     }
 }
 
 impl From<NonNegativeSvgLengthOrPercentageOrNumber> for SVGWidth {
     fn from(length: NonNegativeSvgLengthOrPercentageOrNumber) -> Self {
         generic::SVGLength::Length(length)
     }
 }
 
 /// [ <length> | <percentage> | <number> ]# | context-value
 pub type SVGStrokeDashArray = generic::SVGStrokeDashArray<NonNegativeSvgLengthOrPercentageOrNumber>;
 
 impl Parse for SVGStrokeDashArray {
-    fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-                     -> Result<Self, ParseError<'i>> {
+    fn parse<'i, 't>(
+        context: &ParserContext,
+        input: &mut Parser<'i, 't>,
+    ) -> Result<Self, ParseError<'i>> {
         if let Ok(values) = input.try(|i| CommaWithSpace::parse(i, |i| {
             NonNegativeSvgLengthOrPercentageOrNumber::parse(context, i)
         })) {
             Ok(generic::SVGStrokeDashArray::Values(values))
         } else if let Ok(_) = input.try(|i| i.expect_ident_matching("none")) {
             Ok(generic::SVGStrokeDashArray::Values(vec![]))
         } else {
             parse_context_value(input, generic::SVGStrokeDashArray::ContextValue)
         }
     }
 }
 
 /// <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>> {
+    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,
-                "context-fill-opacity" => Ok(generic::SVGOpacity::ContextFillOpacity),
-                "context-stroke-opacity" => Ok(generic::SVGOpacity::ContextStrokeOpacity),
-            }
-        } else {
-            Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
+            return Ok(generic::SVGOpacity::Opacity(opacity));
+        }
+
+        try_match_ident_ignore_ascii_case! { input,
+            "context-fill-opacity" => Ok(generic::SVGOpacity::ContextFillOpacity),
+            "context-stroke-opacity" => Ok(generic::SVGOpacity::ContextStrokeOpacity),
         }
     }
 }
 
 /// The specified value for a single CSS paint-order property.
 #[repr(u8)]
 #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, ToCss)]
 pub enum PaintOrder {