diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index c522baf81b8..43b3d7bda17 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -479,6 +479,36 @@ } } + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + let mut all_inherit = true; + let mut all_initial = true; + let mut with_variables = false; + % for sub_property in shorthand.sub_properties: + match *self.${sub_property.ident} { + DeclaredValue::Initial => all_inherit = false, + DeclaredValue::Inherit => all_initial = false, + DeclaredValue::WithVariables {..} => with_variables = true, + DeclaredValue::Value(..) => { + all_initial = false; + all_inherit = false; + } + } + % endfor + + if with_variables { + // We don't serialize shorthands with variables + dest.write_str("") + } else if all_inherit { + dest.write_str("inherit") + } else if all_initial { + dest.write_str("initial") + } else { + self.to_css_declared(dest) + } + } + } + pub fn parse(context: &ParserContext, input: &mut Parser, declarations: &mut Vec) @@ -541,8 +571,8 @@ }) } - impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> LonghandsToSerialize<'a> { + fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { super::serialize_four_sides( dest, self.${to_rust_ident(sub_property_pattern % 'top')}, diff --git a/components/style/properties/shorthand/background.mako.rs b/components/style/properties/shorthand/background.mako.rs index 60f0727442b..31cd555ab23 100644 --- a/components/style/properties/shorthand/background.mako.rs +++ b/components/style/properties/shorthand/background.mako.rs @@ -101,8 +101,8 @@ }) } - impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> LonghandsToSerialize<'a> { + fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { // mako doesn't like ampersands following `<` fn extract_value(x: &DeclaredValue) -> Option< &T> { match *x { @@ -120,7 +120,7 @@ // There should be at least one declared value if len == 0 { - return Err(()) + return dest.write_str("") } let iter = repeat(None).take(len - 1).chain(once(Some(self.background_color))) diff --git a/components/style/properties/shorthand/border.mako.rs b/components/style/properties/shorthand/border.mako.rs index f1d868b26cc..c29a6a2e7fb 100644 --- a/components/style/properties/shorthand/border.mako.rs +++ b/components/style/properties/shorthand/border.mako.rs @@ -25,8 +25,8 @@ ${helpers.four_sides_shorthand("border-style", "border-%s-style", }) } - impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> LonghandsToSerialize<'a> { + fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { // extract tuple container values so that the different border widths // can be compared via partial eq % for side in ["top", "right", "bottom", "left"]: @@ -102,8 +102,8 @@ pub fn parse_border(context: &ParserContext, input: &mut Parser) }) } - impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> LonghandsToSerialize<'a> { + fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { super::serialize_directional_border( dest, self.border_${side}_width, @@ -134,8 +134,8 @@ pub fn parse_border(context: &ParserContext, input: &mut Parser) }) } - impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> LonghandsToSerialize<'a> { + fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { // If all longhands are all present, then all sides should be the same, // so we can just one set of color/style/width super::serialize_directional_border( @@ -170,8 +170,8 @@ pub fn parse_border(context: &ParserContext, input: &mut Parser) // TODO: I do not understand how border radius works with respect to the slashes /, // so putting a default generic impl for now // https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius - impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> LonghandsToSerialize<'a> { + fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { try!(self.border_top_left_radius.to_css(dest)); try!(write!(dest, " ")); diff --git a/components/style/properties/shorthand/box.mako.rs b/components/style/properties/shorthand/box.mako.rs index 0825a8fc314..2465a91ae8a 100644 --- a/components/style/properties/shorthand/box.mako.rs +++ b/components/style/properties/shorthand/box.mako.rs @@ -19,8 +19,8 @@ // Overflow does not behave like a normal shorthand. When overflow-x and overflow-y are not of equal // values, they no longer use the shared property name "overflow". // Other shorthands do not include their name in the to_css method - impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> LonghandsToSerialize<'a> { + fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { let x_and_y_equal = match (self.overflow_x, self.overflow_y) { (&DeclaredValue::Value(ref x_value), &DeclaredValue::Value(ref y_container)) => { *x_value == y_container.0 @@ -132,8 +132,8 @@ macro_rules! try_parse_one { }) } - impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> LonghandsToSerialize<'a> { + fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { try!(self.transition_property.to_css(dest)); try!(write!(dest, " ")); @@ -268,8 +268,8 @@ macro_rules! try_parse_one { }) } - impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> LonghandsToSerialize<'a> { + fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { try!(self.animation_duration.to_css(dest)); try!(write!(dest, " ")); diff --git a/components/style/properties/shorthand/column.mako.rs b/components/style/properties/shorthand/column.mako.rs index 563ef210fdf..e8ccf00bf47 100644 --- a/components/style/properties/shorthand/column.mako.rs +++ b/components/style/properties/shorthand/column.mako.rs @@ -48,8 +48,8 @@ } } - impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> LonghandsToSerialize<'a> { + fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { try!(self.column_width.to_css(dest)); try!(write!(dest, " ")); diff --git a/components/style/properties/shorthand/font.mako.rs b/components/style/properties/shorthand/font.mako.rs index aae11eb3cf6..555b098e575 100644 --- a/components/style/properties/shorthand/font.mako.rs +++ b/components/style/properties/shorthand/font.mako.rs @@ -68,8 +68,8 @@ } // This may be a bit off, unsure, possibly needs changes - impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> LonghandsToSerialize<'a> { + fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { if let DeclaredValue::Value(ref style) = *self.font_style { try!(style.to_css(dest)); try!(write!(dest, " ")); diff --git a/components/style/properties/shorthand/inherited_text.mako.rs b/components/style/properties/shorthand/inherited_text.mako.rs index e7c19127a15..64ef03b1138 100644 --- a/components/style/properties/shorthand/inherited_text.mako.rs +++ b/components/style/properties/shorthand/inherited_text.mako.rs @@ -15,8 +15,8 @@ }) } - impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> LonghandsToSerialize<'a> { + fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { self.overflow_wrap.to_css(dest) } } diff --git a/components/style/properties/shorthand/list.mako.rs b/components/style/properties/shorthand/list.mako.rs index 6e1abf337fe..955d93f7c16 100644 --- a/components/style/properties/shorthand/list.mako.rs +++ b/components/style/properties/shorthand/list.mako.rs @@ -92,8 +92,8 @@ } } - impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> LonghandsToSerialize<'a> { + fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self.list_style_position { DeclaredValue::Initial => try!(write!(dest, "outside")), _ => try!(self.list_style_position.to_css(dest)) diff --git a/components/style/properties/shorthand/outline.mako.rs b/components/style/properties/shorthand/outline.mako.rs index d09fe2152b2..852fce2b292 100644 --- a/components/style/properties/shorthand/outline.mako.rs +++ b/components/style/properties/shorthand/outline.mako.rs @@ -49,8 +49,8 @@ } } - impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> LonghandsToSerialize<'a> { + fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { try!(self.outline_width.to_css(dest)); try!(write!(dest, " ")); diff --git a/components/style/properties/shorthand/position.mako.rs b/components/style/properties/shorthand/position.mako.rs index 9fc33e00f42..5064c375215 100644 --- a/components/style/properties/shorthand/position.mako.rs +++ b/components/style/properties/shorthand/position.mako.rs @@ -38,8 +38,8 @@ } - impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> LonghandsToSerialize<'a> { + fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self.flex_direction { DeclaredValue::Initial => try!(write!(dest, "row")), _ => try!(self.flex_direction.to_css(dest)) @@ -107,8 +107,8 @@ }) } - impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> LonghandsToSerialize<'a> { + fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { try!(self.flex_grow.to_css(dest)); try!(write!(dest, " ")); diff --git a/components/style/properties/shorthand/text.mako.rs b/components/style/properties/shorthand/text.mako.rs index 2bcfbfcd7b9..d09e00b6ba4 100644 --- a/components/style/properties/shorthand/text.mako.rs +++ b/components/style/properties/shorthand/text.mako.rs @@ -46,8 +46,8 @@ }) } - impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> LonghandsToSerialize<'a> { + fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self.text_decoration_line { DeclaredValue::Value(ref line) => { try!(line.to_css(dest)); diff --git a/tests/wpt/metadata-css/cssom-1_dev/html/cssom-setProperty-shorthand.htm.ini b/tests/wpt/metadata-css/cssom-1_dev/html/cssom-setProperty-shorthand.htm.ini deleted file mode 100644 index 0107a131efa..00000000000 --- a/tests/wpt/metadata-css/cssom-1_dev/html/cssom-setProperty-shorthand.htm.ini +++ /dev/null @@ -1,35 +0,0 @@ -[cssom-setProperty-shorthand.htm] - type: testharness - [shorthand font can be set with setProperty] - expected: FAIL - - [shorthand border-top can be set with setProperty] - expected: FAIL - - [shorthand border-right can be set with setProperty] - expected: FAIL - - [shorthand border-bottom can be set with setProperty] - expected: FAIL - - [shorthand border-left can be set with setProperty] - expected: FAIL - - [shorthand border can be set with setProperty] - expected: FAIL - - [shorthand list-style can be set with setProperty] - expected: FAIL - - [shorthand outline can be set with setProperty] - expected: FAIL - - [shorthand background can be set with setProperty] - expected: FAIL - - [shorthand overflow can be set with setProperty] - expected: FAIL - - [shorthand border-radius can be set with setProperty] - expected: FAIL -