Fix origin/clip parsing behavior in mask and background shorthands

This commit is contained in:
Nazım Can Altınova 2016-10-02 01:23:48 +03:00
parent 36222cf543
commit 1b35a3d9a8
4 changed files with 38 additions and 22 deletions

View file

@ -11,6 +11,20 @@
use properties::longhands::{background_color, background_position, background_repeat, background_attachment}; use properties::longhands::{background_color, background_position, background_repeat, background_attachment};
use properties::longhands::{background_image, background_size, background_origin, background_clip}; use properties::longhands::{background_image, background_size, background_origin, background_clip};
impl From<background_origin::single_value::SpecifiedValue> for background_clip::single_value::SpecifiedValue {
fn from(origin: background_origin::single_value::SpecifiedValue) ->
background_clip::single_value::SpecifiedValue {
match origin {
background_origin::single_value::SpecifiedValue::content_box =>
background_clip::single_value::SpecifiedValue::content_box,
background_origin::single_value::SpecifiedValue::padding_box =>
background_clip::single_value::SpecifiedValue::padding_box,
background_origin::single_value::SpecifiedValue::border_box =>
background_clip::single_value::SpecifiedValue::border_box,
}
}
}
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> { pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
let mut background_color = None; let mut background_color = None;
@ -56,6 +70,11 @@
% endfor % endfor
break break
} }
if clip.is_none() {
if let Some(origin) = origin {
clip = Some(background_clip::single_value::SpecifiedValue::from(origin));
}
}
let mut any = false; let mut any = false;
% for name in "image position repeat size attachment origin clip".split(): % for name in "image position repeat size attachment origin clip".split():
any = any || ${name}.is_some(); any = any || ${name}.is_some();
@ -199,14 +218,6 @@
} }
} }
}, },
(Some(origin), _) => {
try!(write!(dest, " "));
try!(origin.to_css(dest));
},
(_, Some(clip)) => {
try!(write!(dest, " "));
try!(clip.to_css(dest));
},
_ => {} _ => {}
}; };
} }

View file

@ -10,6 +10,19 @@
use properties::longhands::{mask_mode, mask_repeat, mask_clip, mask_origin, mask_composite, mask_position}; use properties::longhands::{mask_mode, mask_repeat, mask_clip, mask_origin, mask_composite, mask_position};
use properties::longhands::{mask_size, mask_image}; use properties::longhands::{mask_size, mask_image};
impl From<mask_origin::single_value::SpecifiedValue> for mask_clip::single_value::SpecifiedValue {
fn from(origin: mask_origin::single_value::SpecifiedValue) -> mask_clip::single_value::SpecifiedValue {
match origin {
mask_origin::single_value::SpecifiedValue::content_box =>
mask_clip::single_value::SpecifiedValue::content_box,
mask_origin::single_value::SpecifiedValue::padding_box =>
mask_clip::single_value::SpecifiedValue::padding_box,
mask_origin::single_value::SpecifiedValue::border_box =>
mask_clip::single_value::SpecifiedValue::border_box,
}
}
}
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> { pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
% for name in "image mode position size repeat origin clip composite".split(): % for name in "image mode position size repeat origin clip composite".split():
let mut mask_${name} = mask_${name}::SpecifiedValue(Vec::new()); let mut mask_${name} = mask_${name}::SpecifiedValue(Vec::new());
@ -56,6 +69,11 @@
% endfor % endfor
break break
} }
if clip.is_none() {
if let Some(origin) = origin {
clip = Some(mask_clip::single_value::SpecifiedValue::from(origin));
}
}
let mut any = false; let mut any = false;
% for name in "image mode position size repeat origin clip composite".split(): % for name in "image mode position size repeat origin clip composite".split():
any = any || ${name}.is_some(); any = any || ${name}.is_some();
@ -169,14 +187,6 @@
} }
} }
}, },
(Some(origin), _) => {
try!(write!(dest, " "));
try!(origin.to_css(dest));
},
(_, Some(clip)) => {
try!(write!(dest, " "));
try!(clip.to_css(dest));
},
_ => {} _ => {}
}; };

View file

@ -106,8 +106,8 @@ fn mask_shorthand_should_parse_origin_and_clip_correctly() {
let mut parser = Parser::new("padding-box"); let mut parser = Parser::new("padding-box");
let result = mask::parse_value(&context, &mut parser).unwrap(); let result = mask::parse_value(&context, &mut parser).unwrap();
// TODO(#13466): We should fix origin/clip parsing behavior.
assert_eq!(result.mask_origin.unwrap(), parse_longhand!(mask_origin, "padding-box")); assert_eq!(result.mask_origin.unwrap(), parse_longhand!(mask_origin, "padding-box"));
assert_eq!(result.mask_clip.unwrap(), parse_longhand!(mask_clip, "padding-box"));
} }
#[test] #[test]

View file

@ -1,5 +0,0 @@
[background-335.htm]
type: testharness
[background_specified_box_one_clip]
expected: FAIL