From f3bcb0a49641239246e2f369d42517f924436b9f Mon Sep 17 00:00:00 2001 From: Dexter Haslem Date: Tue, 24 Jan 2017 00:01:44 -0700 Subject: [PATCH 1/2] make -webkit-text-stroke color and width shorthand no longer sensitive to order of values --- .../shorthand/inherited_text.mako.rs | 37 ++++++++++++------- tests/unit/style/parsing/inherited_text.rs | 23 ++++++++++++ 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/components/style/properties/shorthand/inherited_text.mako.rs b/components/style/properties/shorthand/inherited_text.mako.rs index 38789c5275e..a75e6d8925d 100644 --- a/components/style/properties/shorthand/inherited_text.mako.rs +++ b/components/style/properties/shorthand/inherited_text.mako.rs @@ -76,25 +76,34 @@ use values::specified::{BorderWidth, Length}; use app_units::Au; - let (mut color, mut width, mut any) = (None, None, false); - % for value in "color width".split(): - if ${value}.is_none() { - if let Ok(value) = input.try(|input| _webkit_text_stroke_${value}::parse(context, input)) { - ${value} = Some(value); - any = true; + let mut color = None; + let mut width = None; + loop { + if color.is_none() { + if let Ok(value) = input.try(|input| _webkit_text_stroke_color::parse(context, input)) { + color = Some(value); + continue } } - % endfor - if !any { - return Err(()); + if width.is_none() { + if let Ok(value) = input.try(|input| _webkit_text_stroke_width::parse(context, input)) { + width = Some(value); + continue + } + } + break } - Ok(Longhands { - _webkit_text_stroke_color: color.or(Some(CSSColor { parsed: CSSParserColor::CurrentColor, - authored: None })), - _webkit_text_stroke_width: width.or(Some(BorderWidth::from_length(Length::Absolute(Au::from_px(0))))), - }) + if color.is_some() || width.is_some() { + Ok(Longhands { + _webkit_text_stroke_color: color.or(Some(CSSColor { parsed: CSSParserColor::CurrentColor, + authored: None })), + _webkit_text_stroke_width: width.or(Some(BorderWidth::from_length(Length::Absolute(Au::from_px(0))))), + }) + } else { + Err(()) + } } impl<'a> LonghandsToSerialize<'a> { diff --git a/tests/unit/style/parsing/inherited_text.rs b/tests/unit/style/parsing/inherited_text.rs index 51c801b6f91..5585b62d4b4 100644 --- a/tests/unit/style/parsing/inherited_text.rs +++ b/tests/unit/style/parsing/inherited_text.rs @@ -78,3 +78,26 @@ fn test_text_emphasis_position() { let left_under = parse_longhand!(text_emphasis_position, "left under"); assert_eq!(left_under, SpecifiedValue(HorizontalWritingModeValue::Under, VerticalWritingModeValue::Left)); } + + +#[test] +fn webkit_text_stroke_shorthand_should_parse_properly() { + use style::properties::longhands::_webkit_text_stroke_color; + use style::properties::longhands::_webkit_text_stroke_width; + use style::properties::shorthands::_webkit_text_stroke; + use media_queries::CSSErrorReporterTest; + use servo_url::ServoUrl; + let url = ServoUrl::parse("http://localhost").unwrap(); + let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest)); + + let mut parser = Parser::new("thin red"); + let result = _webkit_text_stroke::parse_value(&context, &mut parser).unwrap(); + assert_eq!(result._webkit_text_stroke_color.unwrap(), parse_longhand!(_webkit_text_stroke_color, "red")); + assert_eq!(result._webkit_text_stroke_width.unwrap(), parse_longhand!(_webkit_text_stroke_width, "thin")); + + // ensure its no longer sensitive to order + let mut parser = Parser::new("red thin"); + let result = _webkit_text_stroke::parse_value(&context, &mut parser).unwrap(); + assert_eq!(result._webkit_text_stroke_color.unwrap(), parse_longhand!(_webkit_text_stroke_color, "red")); + assert_eq!(result._webkit_text_stroke_width.unwrap(), parse_longhand!(_webkit_text_stroke_width, "thin")); +} \ No newline at end of file From 305db366a1ad5e39a8b41ce71e652acff477a777 Mon Sep 17 00:00:00 2001 From: Dexter Haslem Date: Tue, 24 Jan 2017 01:33:29 -0700 Subject: [PATCH 2/2] forgot to tidy unit test --- tests/unit/style/parsing/inherited_text.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/unit/style/parsing/inherited_text.rs b/tests/unit/style/parsing/inherited_text.rs index 5585b62d4b4..faaa1cce02e 100644 --- a/tests/unit/style/parsing/inherited_text.rs +++ b/tests/unit/style/parsing/inherited_text.rs @@ -82,11 +82,12 @@ fn test_text_emphasis_position() { #[test] fn webkit_text_stroke_shorthand_should_parse_properly() { + use media_queries::CSSErrorReporterTest; + use servo_url::ServoUrl; use style::properties::longhands::_webkit_text_stroke_color; use style::properties::longhands::_webkit_text_stroke_width; use style::properties::shorthands::_webkit_text_stroke; - use media_queries::CSSErrorReporterTest; - use servo_url::ServoUrl; + let url = ServoUrl::parse("http://localhost").unwrap(); let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest)); @@ -100,4 +101,4 @@ fn webkit_text_stroke_shorthand_should_parse_properly() { let result = _webkit_text_stroke::parse_value(&context, &mut parser).unwrap(); assert_eq!(result._webkit_text_stroke_color.unwrap(), parse_longhand!(_webkit_text_stroke_color, "red")); assert_eq!(result._webkit_text_stroke_width.unwrap(), parse_longhand!(_webkit_text_stroke_width, "thin")); -} \ No newline at end of file +}