mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Multiple style nits and cleanups.
This commit is contained in:
parent
835d95eb41
commit
66f00c5566
2 changed files with 43 additions and 32 deletions
|
@ -411,11 +411,13 @@ impl ToCss for PropertyDeclarationBlock {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Substep 1
|
// Substep 1:
|
||||||
/* Assuming that the PropertyDeclarationBlock contains no duplicate entries,
|
//
|
||||||
if the current_longhands length is equal to the properties length, it means
|
// Assuming that the PropertyDeclarationBlock contains no
|
||||||
that the properties that map to shorthand are present in longhands */
|
// duplicate entries, if the current_longhands length is
|
||||||
if current_longhands.is_empty() || current_longhands.len() != properties.len() {
|
// equal to the properties length, it means that the
|
||||||
|
// properties that map to shorthand are present in longhands
|
||||||
|
if current_longhands.len() != properties.len() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -432,41 +434,50 @@ impl ToCss for PropertyDeclarationBlock {
|
||||||
|
|
||||||
// Substep 5 - Let value be the result of invoking serialize
|
// Substep 5 - Let value be the result of invoking serialize
|
||||||
// a CSS value of current longhands.
|
// a CSS value of current longhands.
|
||||||
let mut value = String::new();
|
let appendable_value =
|
||||||
let has_variables = {
|
match shorthand.get_shorthand_appendable_value(current_longhands.iter().cloned()) {
|
||||||
let appendable_value =
|
None => continue,
|
||||||
match shorthand.get_shorthand_appendable_value(current_longhands.iter().cloned()) {
|
Some(appendable_value) => appendable_value,
|
||||||
None => continue,
|
|
||||||
Some(appendable_value) => appendable_value,
|
|
||||||
};
|
|
||||||
|
|
||||||
let has_variables = match appendable_value {
|
|
||||||
AppendableValue::Css { with_variables, .. } => with_variables,
|
|
||||||
_ => false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
append_declaration_value(&mut value, appendable_value)?;
|
// We avoid re-serializing if we're already an
|
||||||
|
// AppendableValue::Css.
|
||||||
|
let mut value = String::new();
|
||||||
|
let value = match appendable_value {
|
||||||
|
AppendableValue::Css { css, with_variables } => {
|
||||||
|
debug_assert!(!css.is_empty());
|
||||||
|
AppendableValue::Css {
|
||||||
|
css: css,
|
||||||
|
with_variables: with_variables,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
other @ _ => {
|
||||||
|
append_declaration_value(&mut value, other)?;
|
||||||
|
|
||||||
has_variables
|
// Substep 6
|
||||||
|
if value.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
AppendableValue::Css {
|
||||||
|
css: &value,
|
||||||
|
with_variables: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Substep 6
|
|
||||||
if value.is_empty() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Substeps 7 and 8
|
// Substeps 7 and 8
|
||||||
append_serialization::<_, Cloned<slice::Iter< _>>, _>(
|
append_serialization::<_, Cloned<slice::Iter< _>>, _>(
|
||||||
dest,
|
dest,
|
||||||
&shorthand,
|
&shorthand,
|
||||||
AppendableValue::Css { css: &value, with_variables: has_variables },
|
value,
|
||||||
importance,
|
importance,
|
||||||
&mut is_first_serialization)?;
|
&mut is_first_serialization)?;
|
||||||
|
|
||||||
for current_longhand in current_longhands {
|
for current_longhand in ¤t_longhands {
|
||||||
// Substep 9
|
// Substep 9
|
||||||
already_serialized.push(current_longhand.id());
|
already_serialized.push(current_longhand.id());
|
||||||
let index_to_remove = longhands.iter().position(|l| l.0 == *current_longhand);
|
let index_to_remove = longhands.iter().position(|l| l.0 == **current_longhand);
|
||||||
if let Some(index) = index_to_remove {
|
if let Some(index) = index_to_remove {
|
||||||
// Substep 10
|
// Substep 10
|
||||||
longhands.remove(index);
|
longhands.remove(index);
|
||||||
|
@ -488,12 +499,12 @@ impl ToCss for PropertyDeclarationBlock {
|
||||||
// "error: unable to infer enough type information about `_`;
|
// "error: unable to infer enough type information about `_`;
|
||||||
// type annotations or generic parameter binding required [E0282]"
|
// type annotations or generic parameter binding required [E0282]"
|
||||||
// Use the same type as earlier call to reuse generated code.
|
// Use the same type as earlier call to reuse generated code.
|
||||||
try!(append_serialization::<W, Cloned<slice::Iter< &PropertyDeclaration>>, _>(
|
append_serialization::<_, Cloned<slice::Iter<_>>, _>(
|
||||||
dest,
|
dest,
|
||||||
&property,
|
&property,
|
||||||
AppendableValue::Declaration(declaration),
|
AppendableValue::Declaration(declaration),
|
||||||
importance,
|
importance,
|
||||||
&mut is_first_serialization));
|
&mut is_first_serialization)?;
|
||||||
|
|
||||||
// Step 3.3.8
|
// Step 3.3.8
|
||||||
already_serialized.push(property);
|
already_serialized.push(property);
|
||||||
|
@ -597,10 +608,10 @@ pub fn append_serialization<'a, W, I, N>(dest: &mut W,
|
||||||
try!(append_declaration_value(dest, appendable_value));
|
try!(append_declaration_value(dest, appendable_value));
|
||||||
|
|
||||||
if importance.important() {
|
if importance.important() {
|
||||||
try!(write!(dest, " !important"));
|
try!(dest.write_str(" !important"));
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(dest, ";")
|
dest.write_char(';')
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A helper to parse the style attribute of an element, in order for this to be
|
/// A helper to parse the style attribute of an element, in order for this to be
|
||||||
|
|
|
@ -1197,10 +1197,10 @@ impl PropertyDeclaration {
|
||||||
/// the longhand declarations.
|
/// the longhand declarations.
|
||||||
pub fn may_serialize_as_part_of_shorthand(&self) -> bool {
|
pub fn may_serialize_as_part_of_shorthand(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
PropertyDeclaration::CSSWideKeyword(..) => false,
|
PropertyDeclaration::CSSWideKeyword(..) |
|
||||||
PropertyDeclaration::WithVariables(..) => false,
|
PropertyDeclaration::WithVariables(..) => false,
|
||||||
PropertyDeclaration::Custom(..) =>
|
PropertyDeclaration::Custom(..) =>
|
||||||
unreachable!("Serialize a custom property as part of shorthand?"),
|
unreachable!("Serializing a custom property as part of shorthand?"),
|
||||||
_ => true,
|
_ => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue