mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
make -webkit-text-stroke color and width shorthand no longer sensitive to order of values
This commit is contained in:
parent
231481570e
commit
f3bcb0a496
2 changed files with 46 additions and 14 deletions
|
@ -76,25 +76,34 @@
|
||||||
use values::specified::{BorderWidth, Length};
|
use values::specified::{BorderWidth, Length};
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
|
|
||||||
let (mut color, mut width, mut any) = (None, None, false);
|
let mut color = None;
|
||||||
% for value in "color width".split():
|
let mut width = None;
|
||||||
if ${value}.is_none() {
|
loop {
|
||||||
if let Ok(value) = input.try(|input| _webkit_text_stroke_${value}::parse(context, input)) {
|
if color.is_none() {
|
||||||
${value} = Some(value);
|
if let Ok(value) = input.try(|input| _webkit_text_stroke_color::parse(context, input)) {
|
||||||
any = true;
|
color = Some(value);
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
% endfor
|
|
||||||
|
|
||||||
if !any {
|
if width.is_none() {
|
||||||
return Err(());
|
if let Ok(value) = input.try(|input| _webkit_text_stroke_width::parse(context, input)) {
|
||||||
|
width = Some(value);
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Longhands {
|
if color.is_some() || width.is_some() {
|
||||||
_webkit_text_stroke_color: color.or(Some(CSSColor { parsed: CSSParserColor::CurrentColor,
|
Ok(Longhands {
|
||||||
authored: None })),
|
_webkit_text_stroke_color: color.or(Some(CSSColor { parsed: CSSParserColor::CurrentColor,
|
||||||
_webkit_text_stroke_width: width.or(Some(BorderWidth::from_length(Length::Absolute(Au::from_px(0))))),
|
authored: None })),
|
||||||
})
|
_webkit_text_stroke_width: width.or(Some(BorderWidth::from_length(Length::Absolute(Au::from_px(0))))),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> LonghandsToSerialize<'a> {
|
impl<'a> LonghandsToSerialize<'a> {
|
||||||
|
|
|
@ -78,3 +78,26 @@ fn test_text_emphasis_position() {
|
||||||
let left_under = parse_longhand!(text_emphasis_position, "left under");
|
let left_under = parse_longhand!(text_emphasis_position, "left under");
|
||||||
assert_eq!(left_under, SpecifiedValue(HorizontalWritingModeValue::Under, VerticalWritingModeValue::Left));
|
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"));
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue