mirror of
https://github.com/servo/servo.git
synced 2025-08-13 01:15:34 +01:00
Auto merge of #16527 - BorisChiou:stylo/transition/shorthands, r=emilio
stylo: Bug 1353628 - Support shorthand properties for CSS Transition. These patches add shorthand properties into TransitionProperty, so we can parse the shorthand properties properly and create transitions for them. --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix Bug 1353628 - [X] There are tests for these changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16527) <!-- Reviewable:end -->
This commit is contained in:
commit
355d5f89da
8 changed files with 150 additions and 25 deletions
|
@ -54,10 +54,16 @@ pub enum TransitionProperty {
|
|||
${prop.camel_case},
|
||||
% endif
|
||||
% endfor
|
||||
// Shorthand properties may or may not contain any animatable property. Either should still be
|
||||
// parsed properly.
|
||||
% for prop in data.shorthands_except_all():
|
||||
/// ${prop.name}
|
||||
${prop.camel_case},
|
||||
% endfor
|
||||
}
|
||||
|
||||
impl TransitionProperty {
|
||||
/// Iterates over each property that is not `All`.
|
||||
/// Iterates over each longhand property.
|
||||
pub fn each<F: FnMut(TransitionProperty) -> ()>(mut cb: F) {
|
||||
% for prop in data.longhands:
|
||||
% if prop.animatable:
|
||||
|
@ -88,6 +94,9 @@ impl TransitionProperty {
|
|||
"${prop.name}" => Ok(TransitionProperty::${prop.camel_case}),
|
||||
% endif
|
||||
% endfor
|
||||
% for prop in data.shorthands_except_all():
|
||||
"${prop.name}" => Ok(TransitionProperty::${prop.camel_case}),
|
||||
% endfor
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +127,8 @@ impl TransitionProperty {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns true if this TransitionProperty is one of the discrete animatable properties.
|
||||
/// Returns true if this TransitionProperty is one of the discrete animatable properties and
|
||||
/// this TransitionProperty should be a longhand property.
|
||||
pub fn is_discrete(&self) -> bool {
|
||||
match *self {
|
||||
% for prop in data.longhands:
|
||||
|
@ -129,6 +139,35 @@ impl TransitionProperty {
|
|||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
/// Return animatable longhands of this shorthand TransitionProperty, except for "all".
|
||||
pub fn longhands(&self) -> &'static [TransitionProperty] {
|
||||
% for prop in data.shorthands_except_all():
|
||||
static ${prop.ident.upper()}: &'static [TransitionProperty] = &[
|
||||
% for sub in prop.sub_properties:
|
||||
% if sub.animatable:
|
||||
TransitionProperty::${sub.camel_case},
|
||||
% endif
|
||||
% endfor
|
||||
];
|
||||
% endfor
|
||||
match *self {
|
||||
% for prop in data.shorthands_except_all():
|
||||
TransitionProperty::${prop.camel_case} => ${prop.ident.upper()},
|
||||
% endfor
|
||||
_ => panic!("Not allowed to call longhands() for this TransitionProperty")
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if this TransitionProperty is a shorthand.
|
||||
pub fn is_shorthand(&self) -> bool {
|
||||
match *self {
|
||||
% for prop in data.shorthands_except_all():
|
||||
TransitionProperty::${prop.camel_case} => true,
|
||||
% endfor
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if this nsCSSPropertyID is one of the animatable properties.
|
||||
|
@ -155,6 +194,9 @@ impl ToCss for TransitionProperty {
|
|||
TransitionProperty::${prop.camel_case} => dest.write_str("${prop.name}"),
|
||||
% endif
|
||||
% endfor
|
||||
% for prop in data.shorthands_except_all():
|
||||
TransitionProperty::${prop.camel_case} => dest.write_str("${prop.name}"),
|
||||
% endfor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -171,6 +213,10 @@ impl From<TransitionProperty> for nsCSSPropertyID {
|
|||
=> ${helpers.to_nscsspropertyid(prop.ident)},
|
||||
% endif
|
||||
% endfor
|
||||
% for prop in data.shorthands_except_all():
|
||||
TransitionProperty::${prop.camel_case}
|
||||
=> ${helpers.to_nscsspropertyid(prop.ident)},
|
||||
% endfor
|
||||
TransitionProperty::All => nsCSSPropertyID::eCSSPropertyExtra_all_properties,
|
||||
}
|
||||
}
|
||||
|
@ -188,6 +234,10 @@ impl From<nsCSSPropertyID> for TransitionProperty {
|
|||
=> TransitionProperty::${prop.camel_case},
|
||||
% endif
|
||||
% endfor
|
||||
% for prop in data.shorthands_except_all():
|
||||
${helpers.to_nscsspropertyid(prop.ident)}
|
||||
=> TransitionProperty::${prop.camel_case},
|
||||
% endfor
|
||||
nsCSSPropertyID::eCSSPropertyExtra_all_properties => TransitionProperty::All,
|
||||
_ => panic!("Unsupported Servo transition property: {:?}", property),
|
||||
}
|
||||
|
@ -206,7 +256,7 @@ impl<'a> From<TransitionProperty> for PropertyDeclarationId<'a> {
|
|||
=> PropertyDeclarationId::Longhand(LonghandId::${prop.camel_case}),
|
||||
% endif
|
||||
% endfor
|
||||
TransitionProperty::All => panic!(),
|
||||
_ => panic!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -304,6 +354,7 @@ impl AnimatedProperty {
|
|||
}
|
||||
% endif
|
||||
% endfor
|
||||
other => panic!("Can't use TransitionProperty::{:?} here", other),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -459,6 +510,7 @@ impl AnimationValue {
|
|||
}
|
||||
% endif
|
||||
% endfor
|
||||
other => panic!("Can't use TransitionProperty::{:?} here.", other),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -257,7 +257,7 @@ impl LonghandIdSet {
|
|||
TransitionProperty::${prop.camel_case} => self.insert(LonghandId::${prop.camel_case}),
|
||||
% endif
|
||||
% endfor
|
||||
TransitionProperty::All => unreachable!("Tried to set TransitionProperty::All in a PropertyBitfield"),
|
||||
other => unreachable!("Tried to set TransitionProperty::{:?} in a PropertyBitfield", other),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -270,7 +270,7 @@ impl LonghandIdSet {
|
|||
TransitionProperty::${prop.camel_case} => self.contains(LonghandId::${prop.camel_case}),
|
||||
% endif
|
||||
% endfor
|
||||
TransitionProperty::All => unreachable!("Tried to get TransitionProperty::All in a PropertyBitfield"),
|
||||
other => unreachable!("Tried to get TransitionProperty::{:?} in a PropertyBitfield", other),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue