mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Move parse method of PropertyDeclaration to ParsedDeclaration
This is what it now returns.
This commit is contained in:
parent
9d663ea7af
commit
4b4a873c3e
5 changed files with 93 additions and 93 deletions
|
@ -401,7 +401,7 @@ impl<'a, 'b> DeclarationParser for KeyframeDeclarationParser<'a, 'b> {
|
|||
|
||||
fn parse_value(&mut self, name: &str, input: &mut Parser) -> Result<ParsedDeclaration, ()> {
|
||||
let id = try!(PropertyId::parse(name.into()));
|
||||
match PropertyDeclaration::parse(id, self.context, input, true) {
|
||||
match ParsedDeclaration::parse(id, self.context, input, true) {
|
||||
Ok(parsed) => {
|
||||
// In case there is still unparsed text in the declaration, we should roll back.
|
||||
if !input.is_exhausted() {
|
||||
|
|
|
@ -557,7 +557,7 @@ pub fn parse_one_declaration(id: PropertyId,
|
|||
-> Result<ParsedDeclaration, ()> {
|
||||
let context = ParserContext::new_with_extra_data(Origin::Author, base_url, error_reporter, extra_data);
|
||||
Parser::new(input).parse_entirely(|parser| {
|
||||
PropertyDeclaration::parse(id, &context, parser, false)
|
||||
ParsedDeclaration::parse(id, &context, parser, false)
|
||||
.map_err(|_| ())
|
||||
})
|
||||
}
|
||||
|
@ -582,7 +582,7 @@ impl<'a, 'b> DeclarationParser for PropertyDeclarationParser<'a, 'b> {
|
|||
-> Result<(ParsedDeclaration, Importance), ()> {
|
||||
let id = try!(PropertyId::parse(name.into()));
|
||||
let parsed = input.parse_until_before(Delimiter::Bang, |input| {
|
||||
PropertyDeclaration::parse(id, self.context, input, false)
|
||||
ParsedDeclaration::parse(id, self.context, input, false)
|
||||
.map_err(|_| ())
|
||||
})?;
|
||||
let importance = match input.try(parse_important) {
|
||||
|
|
|
@ -857,6 +857,92 @@ impl ParsedDeclaration {
|
|||
ParsedDeclaration::LonghandOrCustom(declaration) => f(declaration),
|
||||
}
|
||||
}
|
||||
|
||||
/// The `in_keyframe_block` parameter controls this:
|
||||
///
|
||||
/// https://drafts.csswg.org/css-animations/#keyframes
|
||||
/// > The <declaration-list> inside of <keyframe-block> accepts any CSS property
|
||||
/// > except those defined in this specification,
|
||||
/// > but does accept the `animation-play-state` property and interprets it specially.
|
||||
///
|
||||
/// This will not actually parse Importance values, and will always set things
|
||||
/// to Importance::Normal. Parsing Importance values is the job of PropertyDeclarationParser,
|
||||
/// we only set them here so that we don't have to reallocate
|
||||
pub fn parse(id: PropertyId, context: &ParserContext, input: &mut Parser,
|
||||
in_keyframe_block: bool)
|
||||
-> Result<ParsedDeclaration, PropertyDeclarationParseError> {
|
||||
match id {
|
||||
PropertyId::Custom(name) => {
|
||||
let value = match input.try(|i| CSSWideKeyword::parse(context, i)) {
|
||||
Ok(keyword) => DeclaredValue::CSSWideKeyword(keyword),
|
||||
Err(()) => match ::custom_properties::SpecifiedValue::parse(context, input) {
|
||||
Ok(value) => DeclaredValue::Value(value),
|
||||
Err(()) => return Err(PropertyDeclarationParseError::InvalidValue),
|
||||
}
|
||||
};
|
||||
Ok(ParsedDeclaration::LonghandOrCustom(PropertyDeclaration::Custom(name, value)))
|
||||
}
|
||||
PropertyId::Longhand(id) => match id {
|
||||
% for property in data.longhands:
|
||||
LonghandId::${property.camel_case} => {
|
||||
% if not property.derived_from:
|
||||
% if not property.allowed_in_keyframe_block:
|
||||
if in_keyframe_block {
|
||||
return Err(PropertyDeclarationParseError::AnimationPropertyInKeyframeBlock)
|
||||
}
|
||||
% endif
|
||||
% if property.internal:
|
||||
if context.stylesheet_origin != Origin::UserAgent {
|
||||
return Err(PropertyDeclarationParseError::UnknownProperty)
|
||||
}
|
||||
% endif
|
||||
|
||||
${property_pref_check(property)}
|
||||
|
||||
match longhands::${property.ident}::parse_declared(context, input) {
|
||||
Ok(value) => {
|
||||
Ok(ParsedDeclaration::LonghandOrCustom(
|
||||
PropertyDeclaration::${property.camel_case}(value)
|
||||
))
|
||||
},
|
||||
Err(()) => Err(PropertyDeclarationParseError::InvalidValue),
|
||||
}
|
||||
% else:
|
||||
Err(PropertyDeclarationParseError::UnknownProperty)
|
||||
% endif
|
||||
}
|
||||
% endfor
|
||||
},
|
||||
PropertyId::Shorthand(id) => match id {
|
||||
% for shorthand in data.shorthands:
|
||||
ShorthandId::${shorthand.camel_case} => {
|
||||
% if not shorthand.allowed_in_keyframe_block:
|
||||
if in_keyframe_block {
|
||||
return Err(PropertyDeclarationParseError::AnimationPropertyInKeyframeBlock)
|
||||
}
|
||||
% endif
|
||||
% if shorthand.internal:
|
||||
if context.stylesheet_origin != Origin::UserAgent {
|
||||
return Err(PropertyDeclarationParseError::UnknownProperty)
|
||||
}
|
||||
% endif
|
||||
|
||||
${property_pref_check(shorthand)}
|
||||
|
||||
match input.try(|i| CSSWideKeyword::parse(context, i)) {
|
||||
Ok(keyword) => {
|
||||
Ok(ParsedDeclaration::${shorthand.camel_case}CSSWideKeyword(keyword))
|
||||
},
|
||||
Err(()) => {
|
||||
shorthands::${shorthand.ident}::parse(context, input)
|
||||
.map_err(|()| PropertyDeclarationParseError::InvalidValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
% endfor
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Servo's representation for a property declaration.
|
||||
|
@ -1051,92 +1137,6 @@ impl PropertyDeclaration {
|
|||
}
|
||||
}
|
||||
|
||||
/// The `in_keyframe_block` parameter controls this:
|
||||
///
|
||||
/// https://drafts.csswg.org/css-animations/#keyframes
|
||||
/// > The <declaration-list> inside of <keyframe-block> accepts any CSS property
|
||||
/// > except those defined in this specification,
|
||||
/// > but does accept the `animation-play-state` property and interprets it specially.
|
||||
///
|
||||
/// This will not actually parse Importance values, and will always set things
|
||||
/// to Importance::Normal. Parsing Importance values is the job of PropertyDeclarationParser,
|
||||
/// we only set them here so that we don't have to reallocate
|
||||
pub fn parse(id: PropertyId, context: &ParserContext, input: &mut Parser,
|
||||
in_keyframe_block: bool)
|
||||
-> Result<ParsedDeclaration, PropertyDeclarationParseError> {
|
||||
match id {
|
||||
PropertyId::Custom(name) => {
|
||||
let value = match input.try(|i| CSSWideKeyword::parse(context, i)) {
|
||||
Ok(keyword) => DeclaredValue::CSSWideKeyword(keyword),
|
||||
Err(()) => match ::custom_properties::SpecifiedValue::parse(context, input) {
|
||||
Ok(value) => DeclaredValue::Value(value),
|
||||
Err(()) => return Err(PropertyDeclarationParseError::InvalidValue),
|
||||
}
|
||||
};
|
||||
Ok(ParsedDeclaration::LonghandOrCustom(PropertyDeclaration::Custom(name, value)))
|
||||
}
|
||||
PropertyId::Longhand(id) => match id {
|
||||
% for property in data.longhands:
|
||||
LonghandId::${property.camel_case} => {
|
||||
% if not property.derived_from:
|
||||
% if not property.allowed_in_keyframe_block:
|
||||
if in_keyframe_block {
|
||||
return Err(PropertyDeclarationParseError::AnimationPropertyInKeyframeBlock)
|
||||
}
|
||||
% endif
|
||||
% if property.internal:
|
||||
if context.stylesheet_origin != Origin::UserAgent {
|
||||
return Err(PropertyDeclarationParseError::UnknownProperty)
|
||||
}
|
||||
% endif
|
||||
|
||||
${property_pref_check(property)}
|
||||
|
||||
match longhands::${property.ident}::parse_declared(context, input) {
|
||||
Ok(value) => {
|
||||
Ok(ParsedDeclaration::LonghandOrCustom(
|
||||
PropertyDeclaration::${property.camel_case}(value)
|
||||
))
|
||||
},
|
||||
Err(()) => Err(PropertyDeclarationParseError::InvalidValue),
|
||||
}
|
||||
% else:
|
||||
Err(PropertyDeclarationParseError::UnknownProperty)
|
||||
% endif
|
||||
}
|
||||
% endfor
|
||||
},
|
||||
PropertyId::Shorthand(id) => match id {
|
||||
% for shorthand in data.shorthands:
|
||||
ShorthandId::${shorthand.camel_case} => {
|
||||
% if not shorthand.allowed_in_keyframe_block:
|
||||
if in_keyframe_block {
|
||||
return Err(PropertyDeclarationParseError::AnimationPropertyInKeyframeBlock)
|
||||
}
|
||||
% endif
|
||||
% if shorthand.internal:
|
||||
if context.stylesheet_origin != Origin::UserAgent {
|
||||
return Err(PropertyDeclarationParseError::UnknownProperty)
|
||||
}
|
||||
% endif
|
||||
|
||||
${property_pref_check(shorthand)}
|
||||
|
||||
match input.try(|i| CSSWideKeyword::parse(context, i)) {
|
||||
Ok(keyword) => {
|
||||
Ok(ParsedDeclaration::${shorthand.camel_case}CSSWideKeyword(keyword))
|
||||
},
|
||||
Err(()) => {
|
||||
shorthands::${shorthand.ident}::parse(context, input)
|
||||
.map_err(|()| PropertyDeclarationParseError::InvalidValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
% endfor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The shorthands that this longhand is part of.
|
||||
pub fn shorthands(&self) -> &'static [ShorthandId] {
|
||||
// first generate longhand to shorthands lookup map
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
use cssparser::{parse_important, Parser, Token};
|
||||
use parser::ParserContext;
|
||||
use properties::{PropertyDeclaration, PropertyId};
|
||||
use properties::{PropertyId, ParsedDeclaration};
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
|
||||
|
@ -211,7 +211,7 @@ impl Declaration {
|
|||
return false
|
||||
};
|
||||
let mut input = Parser::new(&self.val);
|
||||
let res = PropertyDeclaration::parse(id, cx, &mut input, /* in_keyframe */ false);
|
||||
let res = ParsedDeclaration::parse(id, cx, &mut input, /* in_keyframe */ false);
|
||||
let _ = input.try(parse_important);
|
||||
res.is_ok() && input.is_exhausted()
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ use style::gecko_properties::{self, style_structs};
|
|||
use style::keyframes::KeyframesStepValue;
|
||||
use style::parallel;
|
||||
use style::parser::{ParserContext, ParserContextExtraData};
|
||||
use style::properties::{ComputedValues, Importance, PropertyDeclaration};
|
||||
use style::properties::{ComputedValues, Importance, ParsedDeclaration};
|
||||
use style::properties::{PropertyDeclarationBlock, PropertyId};
|
||||
use style::properties::animated_properties::{AnimationValue, Interpolate, TransitionProperty};
|
||||
use style::properties::parse_one_declaration;
|
||||
|
@ -713,7 +713,7 @@ pub extern "C" fn Servo_ParseProperty(property: *const nsACString, value: *const
|
|||
Box::new(StdoutErrorReporter),
|
||||
extra_data);
|
||||
|
||||
match PropertyDeclaration::parse(id, &context, &mut Parser::new(value), false) {
|
||||
match ParsedDeclaration::parse(id, &context, &mut Parser::new(value), false) {
|
||||
Ok(parsed) => {
|
||||
let mut declarations = Vec::new();
|
||||
parsed.expand(|d| declarations.push((d, Importance::Normal)));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue