Skip to content

Commit

Permalink
Fix handling of all shorthand with var() functions
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Jul 13, 2017
1 parent 42813bc commit 66c357f
Showing 1 changed file with 11 additions and 42 deletions.
53 changes: 11 additions & 42 deletions components/style/properties/properties.mako.rs
Expand Up @@ -215,43 +215,6 @@ pub mod shorthands {
<% data.declare_shorthand("all",
[p.name for p in data.longhands if p.name not in ['direction', 'unicode-bidi']],
spec="https://drafts.csswg.org/css-cascade-3/#all-shorthand") %>
pub mod all {
use cssparser::Parser;
use parser::ParserContext;
use properties::{SourcePropertyDeclaration, AllShorthand, ShorthandId, UnparsedValue};
use stylearc::Arc;
use style_traits::{ParseError, StyleParseError};

pub fn parse_into<'i, 't>(declarations: &mut SourcePropertyDeclaration,
context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<(), ParseError<'i>> {
// This function is like the parse() that is generated by
// helpers:shorthand, but since the only values for the 'all'
// shorthand when not just a single CSS-wide keyword is one
// with variable references, we can make this function a
// little simpler.
//
// FIXME(heycam) Try to share code with the helpers:shorthand
// definition.
input.look_for_var_functions();
let start = input.position();
while let Ok(_) = input.next() {} // Look for var()
if input.seen_var_functions() {
input.reset(start);
let (first_token_type, css) =
::custom_properties::parse_non_custom_with_var(input)?;
declarations.all_shorthand = AllShorthand::WithVariables(Arc::new(UnparsedValue {
css: css.into_owned(),
first_token_type: first_token_type,
url_data: context.url_data.clone(),
from_shorthand: Some(ShorthandId::All),
}));
Ok(())
} else {
Err(StyleParseError::UnspecifiedError.into())
}
}
}
}

/// A module with all the code related to animated properties.
Expand Down Expand Up @@ -863,11 +826,13 @@ impl ShorthandId {
context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<(), ParseError<'i>> {
match *self {
% for shorthand in data.shorthands:
% for shorthand in data.shorthands_except_all():
ShorthandId::${shorthand.camel_case} => {
shorthands::${shorthand.ident}::parse_into(declarations, context, input)
}
% endfor
// 'all' accepts no value other than CSS-wide keywords
ShorthandId::All => Err(StyleParseError::UnspecifiedError.into())
}
}
}
Expand Down Expand Up @@ -1603,10 +1568,14 @@ impl PropertyDeclaration {
url_data: context.url_data.clone(),
from_shorthand: Some(id),
});
for &longhand in id.longhands() {
declarations.push(
PropertyDeclaration::WithVariables(longhand, unparsed.clone())
)
if id == ShorthandId::All {
declarations.all_shorthand = AllShorthand::WithVariables(unparsed)
} else {
for &longhand in id.longhands() {
declarations.push(
PropertyDeclaration::WithVariables(longhand, unparsed.clone())
)
}
}
Ok(())
} else {
Expand Down

0 comments on commit 66c357f

Please sign in to comment.