Fix serialization of initial/inherit shorthands

This commit is contained in:
Manish Goregaokar 2016-08-20 12:55:40 +05:30
parent 69ada0d7a3
commit f29b748a59
12 changed files with 65 additions and 70 deletions

View file

@ -479,6 +479,36 @@
}
}
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&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<PropertyDeclaration>)
@ -541,8 +571,8 @@
})
}
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
impl<'a> LonghandsToSerialize<'a> {
fn to_css_declared<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
super::serialize_four_sides(
dest,
self.${to_rust_ident(sub_property_pattern % 'top')},

View file

@ -101,8 +101,8 @@
})
}
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
impl<'a> LonghandsToSerialize<'a> {
fn to_css_declared<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
// mako doesn't like ampersands following `<`
fn extract_value<T>(x: &DeclaredValue<T>) -> 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)))

View file

@ -25,8 +25,8 @@ ${helpers.four_sides_shorthand("border-style", "border-%s-style",
})
}
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
impl<'a> LonghandsToSerialize<'a> {
fn to_css_declared<W>(&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<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
impl<'a> LonghandsToSerialize<'a> {
fn to_css_declared<W>(&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<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
impl<'a> LonghandsToSerialize<'a> {
fn to_css_declared<W>(&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<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
impl<'a> LonghandsToSerialize<'a> {
fn to_css_declared<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
try!(self.border_top_left_radius.to_css(dest));
try!(write!(dest, " "));

View file

@ -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<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
impl<'a> LonghandsToSerialize<'a> {
fn to_css_declared<W>(&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<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
impl<'a> LonghandsToSerialize<'a> {
fn to_css_declared<W>(&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<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
impl<'a> LonghandsToSerialize<'a> {
fn to_css_declared<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
try!(self.animation_duration.to_css(dest));
try!(write!(dest, " "));

View file

@ -48,8 +48,8 @@
}
}
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
impl<'a> LonghandsToSerialize<'a> {
fn to_css_declared<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
try!(self.column_width.to_css(dest));
try!(write!(dest, " "));

View file

@ -68,8 +68,8 @@
}
// This may be a bit off, unsure, possibly needs changes
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
impl<'a> LonghandsToSerialize<'a> {
fn to_css_declared<W>(&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, " "));

View file

@ -15,8 +15,8 @@
})
}
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
impl<'a> LonghandsToSerialize<'a> {
fn to_css_declared<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
self.overflow_wrap.to_css(dest)
}
}

View file

@ -92,8 +92,8 @@
}
}
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
impl<'a> LonghandsToSerialize<'a> {
fn to_css_declared<W>(&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))

View file

@ -49,8 +49,8 @@
}
}
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
impl<'a> LonghandsToSerialize<'a> {
fn to_css_declared<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
try!(self.outline_width.to_css(dest));
try!(write!(dest, " "));

View file

@ -38,8 +38,8 @@
}
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
impl<'a> LonghandsToSerialize<'a> {
fn to_css_declared<W>(&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<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
impl<'a> LonghandsToSerialize<'a> {
fn to_css_declared<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
try!(self.flex_grow.to_css(dest));
try!(write!(dest, " "));

View file

@ -46,8 +46,8 @@
})
}
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
impl<'a> LonghandsToSerialize<'a> {
fn to_css_declared<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self.text_decoration_line {
DeclaredValue::Value(ref line) => {
try!(line.to_css(dest));

View file

@ -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