aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Chen <jeremychen@mozilla.com>2017-04-18 16:56:04 +0000
committerJeremy Chen <jeremychen@mozilla.com>2017-04-21 18:52:39 +0800
commit43525819f4f40d0852f49724592ebc75dd5cf849 (patch)
treedf285d0c64f941ab1d1ef67ce750aa4b398c5a14
parent350d9c6c47fe1f20ebbd911f7675c23bcaa9ba2f (diff)
downloadservo-43525819f4f40d0852f49724592ebc75dd5cf849.tar.gz
servo-43525819f4f40d0852f49724592ebc75dd5cf849.zip
Stylo - reset longhands of border-image to their initial value while parsing border shorthand.
To do so, we need to declare the border-image longhands as part of border shorthand and always reset them. This could fix couple stylo test failures. See Gecko Bug 1357350 for the test update patches. Spec link: https://drafts.csswg.org/css-backgrounds-3/#the-border-shorthands Note that two unit tests have been fixed as well: 1. border_should_serialize_correctly To verify the correctness of serialization of 'border' shorthand, we need to reset 'border-image' as well. 2. same_longhands_should_serialize_correctly Due to the same reason as above, since the 'border-image' is not reset, the test expectation should be fixed.
-rw-r--r--components/style/properties/shorthand/border.mako.rs21
-rw-r--r--tests/unit/style/properties/serialization.rs30
2 files changed, 28 insertions, 23 deletions
diff --git a/components/style/properties/shorthand/border.mako.rs b/components/style/properties/shorthand/border.mako.rs
index 8441f5ce395..1ee9d3ff8da 100644
--- a/components/style/properties/shorthand/border.mako.rs
+++ b/components/style/properties/shorthand/border.mako.rs
@@ -122,13 +122,18 @@ pub fn parse_border(context: &ParserContext, input: &mut Parser)
</%helpers:shorthand>
% endfor
-<%helpers:shorthand name="border" sub_properties="${' '.join(
- 'border-%s-%s' % (side, prop)
- for side in ['top', 'right', 'bottom', 'left']
- for prop in ['color', 'style', 'width']
-)}" spec="https://drafts.csswg.org/css-backgrounds/#border">
+<%helpers:shorthand name="border"
+ sub_properties="${' '.join('border-%s-%s' % (side, prop)
+ for side in ['top', 'right', 'bottom', 'left']
+ for prop in ['color', 'style', 'width'])}
+ ${' '.join('border-image-%s' % name
+ for name in ['outset', 'repeat', 'slice', 'source', 'width'])}"
+ spec="https://drafts.csswg.org/css-backgrounds/#border">
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
+ use properties::longhands::{border_image_outset, border_image_repeat, border_image_slice};
+ use properties::longhands::{border_image_source, border_image_width};
+
let (color, style, width) = try!(super::parse_border(context, input));
Ok(Longhands {
% for side in ["top", "right", "bottom", "left"]:
@@ -136,6 +141,12 @@ pub fn parse_border(context: &ParserContext, input: &mut Parser)
border_${side}_style: style,
border_${side}_width: width.clone(),
% endfor
+
+ // The ‘border’ shorthand resets ‘border-image’ to its initial value.
+ // See https://drafts.csswg.org/css-backgrounds-3/#the-border-shorthands
+ % for name in "outset repeat slice source width".split():
+ border_image_${name}: border_image_${name}::get_initial_specified_value(),
+ % endfor
})
}
diff --git a/tests/unit/style/properties/serialization.rs b/tests/unit/style/properties/serialization.rs
index 53ed381ff4b..7e862e51204 100644
--- a/tests/unit/style/properties/serialization.rs
+++ b/tests/unit/style/properties/serialization.rs
@@ -274,7 +274,7 @@ mod shorthand_serialization {
properties.push(PropertyDeclaration::BorderLeftColor(blue.clone()));
let serialization = shorthand_properties_to_string(properties);
- assert_eq!(serialization, "border: 30px solid rgb(0, 0, 255);");
+ assert_eq!(serialization, "border-style: solid; border-width: 30px; border-color: rgb(0, 0, 255);");
}
#[test]
@@ -475,26 +475,20 @@ mod shorthand_serialization {
#[test]
fn border_should_serialize_correctly() {
- let mut properties = Vec::new();
- let (width, style, color) = get_border_property_values();
-
- properties.push(PropertyDeclaration::BorderTopWidth(width.clone()));
- properties.push(PropertyDeclaration::BorderTopStyle(style.clone()));
- properties.push(PropertyDeclaration::BorderTopColor(color.clone()));
-
- properties.push(PropertyDeclaration::BorderRightWidth(width.clone()));
- properties.push(PropertyDeclaration::BorderRightStyle(style.clone()));
- properties.push(PropertyDeclaration::BorderRightColor(color.clone()));
+ // According to https://drafts.csswg.org/css-backgrounds-3/#the-border-shorthands,
+ // the ‘border’ shorthand resets ‘border-image’ to its initial value. To verify the
+ // serialization of 'border' shorthand, we need to set 'border-image' as well.
+ let block_text = "\
+ border-top: 4px solid; \
+ border-right: 4px solid; \
+ border-bottom: 4px solid; \
+ border-left: 4px solid; \
+ border-image: none;";
- properties.push(PropertyDeclaration::BorderBottomWidth(width.clone()));
- properties.push(PropertyDeclaration::BorderBottomStyle(style.clone()));
- properties.push(PropertyDeclaration::BorderBottomColor(color.clone()));
+ let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
- properties.push(PropertyDeclaration::BorderLeftWidth(width.clone()));
- properties.push(PropertyDeclaration::BorderLeftStyle(style.clone()));
- properties.push(PropertyDeclaration::BorderLeftColor(color.clone()));
+ let serialization = block.to_css_string();
- let serialization = shorthand_properties_to_string(properties);
assert_eq!(serialization, "border: 4px solid;");
}
}