Auto merge of #13541 - canaltinova:origin-clip, r=Manishearth

Fix origin/clip parsing behavior in mask and background shorthands

<!-- Please describe your changes on the following line: -->
We have tests for mask shorthand parsing, but we don't have tests for background parsing. Should I add some for it?
Also deleted inaccessible match arms in serialization function.
r? @Manishearth

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #13466 (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13541)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-10-02 14:33:43 -05:00 committed by GitHub
commit 7da20f2617
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_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, ()> {
let mut background_color = None;
@ -56,6 +70,11 @@
% endfor
break
}
if clip.is_none() {
if let Some(origin) = origin {
clip = Some(background_clip::single_value::SpecifiedValue::from(origin));
}
}
let mut any = false;
% for name in "image position repeat size attachment origin clip".split():
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_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, ()> {
% for name in "image mode position size repeat origin clip composite".split():
let mut mask_${name} = mask_${name}::SpecifiedValue(Vec::new());
@ -56,6 +69,11 @@
% endfor
break
}
if clip.is_none() {
if let Some(origin) = origin {
clip = Some(mask_clip::single_value::SpecifiedValue::from(origin));
}
}
let mut any = false;
% for name in "image mode position size repeat origin clip composite".split():
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));
},
_ => {}
};