add support for mask_position_parse/serial

This commit is contained in:
mrmiywj 2017-02-05 00:38:03 +08:00
parent 725b805c45
commit eb115e02e1
5 changed files with 212 additions and 181 deletions

View file

@ -7,7 +7,7 @@ use media_queries::CSSErrorReporterTest;
use servo_url::ServoUrl;
use style::parser::ParserContext;
use style::properties::longhands::{mask_clip, mask_composite, mask_image, mask_mode};
use style::properties::longhands::{mask_origin, mask_position, mask_repeat, mask_size};
use style::properties::longhands::{mask_origin, mask_position_x, mask_position_y, mask_repeat, mask_size};
use style::properties::shorthands::mask;
use style::stylesheets::Origin;
@ -21,7 +21,8 @@ fn mask_shorthand_should_parse_all_available_properties_when_specified() {
assert_eq!(result.mask_image.unwrap(), parse_longhand!(mask_image, "url(\"http://servo/test.png\")"));
assert_eq!(result.mask_mode.unwrap(), parse_longhand!(mask_mode, "luminance"));
assert_eq!(result.mask_position.unwrap(), parse_longhand!(mask_position, "7px 4px"));
assert_eq!(result.mask_position_x.unwrap(), parse_longhand!(mask_position_x, "7px"));
assert_eq!(result.mask_position_y.unwrap(), parse_longhand!(mask_position_y, "4px"));
assert_eq!(result.mask_size.unwrap(), parse_longhand!(mask_size, "70px 50px"));
assert_eq!(result.mask_repeat.unwrap(), parse_longhand!(mask_repeat, "repeat-x"));
assert_eq!(result.mask_origin.unwrap(), parse_longhand!(mask_origin, "padding-box"));
@ -36,7 +37,8 @@ fn mask_shorthand_should_parse_when_some_fields_set() {
let mut parser = Parser::new("14px 40px repeat-y");
let result = mask::parse_value(&context, &mut parser).unwrap();
assert_eq!(result.mask_position.unwrap(), parse_longhand!(mask_position, "14px 40px"));
assert_eq!(result.mask_position_x.unwrap(), parse_longhand!(mask_position_x, "14px"));
assert_eq!(result.mask_position_y.unwrap(), parse_longhand!(mask_position_y, "40px"));
assert_eq!(result.mask_repeat.unwrap(), parse_longhand!(mask_repeat, "repeat-y"));
let mut parser = Parser::new("url(\"http://servo/test.png\") repeat add");
@ -64,12 +66,14 @@ fn mask_shorthand_should_parse_position_and_size_correctly() {
let mut parser = Parser::new("7px 4px");
let result = mask::parse_value(&context, &mut parser).unwrap();
assert_eq!(result.mask_position.unwrap(), parse_longhand!(mask_position, "7px 4px"));
assert_eq!(result.mask_position_x.unwrap(), parse_longhand!(mask_position_x, "7px"));
assert_eq!(result.mask_position_y.unwrap(), parse_longhand!(mask_position_y, "4px"));
let mut parser = Parser::new("7px 4px / 30px 20px");
let result = mask::parse_value(&context, &mut parser).unwrap();
assert_eq!(result.mask_position.unwrap(), parse_longhand!(mask_position, "7px 4px"));
assert_eq!(result.mask_position_x.unwrap(), parse_longhand!(mask_position_x, "7px"));
assert_eq!(result.mask_position_y.unwrap(), parse_longhand!(mask_position_y, "4px"));
assert_eq!(result.mask_size.unwrap(), parse_longhand!(mask_size, "30px 20px"));
let mut parser = Parser::new("/ 30px 20px");

View file

@ -879,7 +879,8 @@ mod shorthand_serialization {
use style::properties::longhands::mask_image as image;
use style::properties::longhands::mask_mode as mode;
use style::properties::longhands::mask_origin as origin;
use style::properties::longhands::mask_position as position;
use style::properties::longhands::mask_position_x as position_x;
use style::properties::longhands::mask_position_y as position_y;
use style::properties::longhands::mask_repeat as repeat;
use style::properties::longhands::mask_size as size;
use style::values::specified::Image;
@ -918,16 +919,16 @@ mod shorthand_serialization {
let mode = single_vec_keyword_value!(mode, luminance);
let position = single_vec_value_typedef!(position,
Position {
horizontal: HorizontalPosition {
keyword: None,
position: Some(LengthOrPercentage::Length(NoCalcLength::from_px(7f32))),
},
vertical: VerticalPosition {
keyword: None,
position: Some(LengthOrPercentage::Length(NoCalcLength::from_px(4f32))),
},
let position_x = single_vec_value_typedef!(position_x,
HorizontalPosition {
keyword: None,
position: Some(LengthOrPercentage::Length(NoCalcLength::from_px(7f32))),
}
);
let position_y = single_vec_value_typedef!(position_y,
VerticalPosition {
keyword: None,
position: Some(LengthOrPercentage::Length(NoCalcLength::from_px(4f32))),
}
);
@ -947,7 +948,8 @@ mod shorthand_serialization {
properties.push(PropertyDeclaration::MaskImage(image));
properties.push(PropertyDeclaration::MaskMode(mode));
properties.push(PropertyDeclaration::MaskPosition(position));
properties.push(PropertyDeclaration::MaskPositionX(position_x));
properties.push(PropertyDeclaration::MaskPositionY(position_y));
properties.push(PropertyDeclaration::MaskSize(size));
properties.push(PropertyDeclaration::MaskRepeat(repeat));
properties.push(PropertyDeclaration::MaskOrigin(origin));
@ -972,16 +974,17 @@ mod shorthand_serialization {
let mode = single_vec_keyword_value!(mode, luminance);
let position = single_vec_value_typedef!(position,
Position {
horizontal: HorizontalPosition {
keyword: None,
position: Some(LengthOrPercentage::Length(NoCalcLength::from_px(7f32))),
},
vertical: VerticalPosition {
keyword: None,
position: Some(LengthOrPercentage::Length(NoCalcLength::from_px(4f32))),
},
let position_x = single_vec_value_typedef!(position_x,
HorizontalPosition {
keyword: None,
position: Some(LengthOrPercentage::Length(NoCalcLength::from_px(7f32))),
}
);
let position_y = single_vec_value_typedef!(position_y,
VerticalPosition {
keyword: None,
position: Some(LengthOrPercentage::Length(NoCalcLength::from_px(4f32))),
}
);
@ -1001,7 +1004,8 @@ mod shorthand_serialization {
properties.push(PropertyDeclaration::MaskImage(image));
properties.push(PropertyDeclaration::MaskMode(mode));
properties.push(PropertyDeclaration::MaskPosition(position));
properties.push(PropertyDeclaration::MaskPositionX(position_x));
properties.push(PropertyDeclaration::MaskPositionY(position_y));
properties.push(PropertyDeclaration::MaskSize(size));
properties.push(PropertyDeclaration::MaskRepeat(repeat));
properties.push(PropertyDeclaration::MaskOrigin(origin));