Skip to content

Commit 7fcf0d7

Browse files
committed
Bug 1870676 - Clean up transition-property handling, and remove eCSSPropertyExtra_all_properties. r=firefox-style-system-reviewers,zrhoffman
While we're at it, let's fix this long-standing TODO. Differential Revision: https://phabricator.services.mozilla.com/D196760
1 parent 2ced0c5 commit 7fcf0d7

File tree

7 files changed

+47
-82
lines changed

7 files changed

+47
-82
lines changed

layout/style/nsCSSPropertyID.h.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ $property_ids
2929
// Extra values for use in the values of the 'transition-property'
3030
// property.
3131
eCSSPropertyExtra_no_properties,
32-
eCSSPropertyExtra_all_properties,
3332

3433
// Extra value to represent custom properties (--*).
3534
eCSSPropertyExtra_variable,

layout/style/nsStyleStruct.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2031,7 +2031,7 @@ void StyleTransition::SetInitialValues() {
20312031
StyleComputedTimingFunction::Keyword(StyleTimingKeyword::Ease);
20322032
mDuration = {0.0};
20332033
mDelay = {0.0};
2034-
mProperty = eCSSPropertyExtra_all_properties;
2034+
mProperty = eCSSProperty_all;
20352035
}
20362036

20372037
bool StyleTransition::operator==(const StyleTransition& aOther) const {

layout/style/nsTransitionManager.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,7 @@ static void ExpandTransitionProperty(nsCSSPropertyID aProperty,
7676
return;
7777
}
7878

79-
// FIXME(emilio): This should probably just use the "all" shorthand id, and we
80-
// should probably remove eCSSPropertyExtra_all_properties.
81-
if (aProperty == eCSSPropertyExtra_all_properties) {
82-
for (nsCSSPropertyID p = nsCSSPropertyID(0);
83-
p < eCSSProperty_COUNT_no_shorthands; p = nsCSSPropertyID(p + 1)) {
84-
if (!nsCSSProps::IsEnabled(p, CSSEnabledState::ForAllContent)) {
85-
continue;
86-
}
87-
AnimatedPropertyID property(p);
88-
aHandler(property);
89-
}
90-
} else if (nsCSSProps::IsShorthand(aProperty)) {
79+
if (nsCSSProps::IsShorthand(aProperty)) {
9180
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subprop, aProperty,
9281
CSSEnabledState::ForAllContent) {
9382
AnimatedPropertyID property(*subprop);
@@ -138,8 +127,8 @@ bool nsTransitionManager::DoUpdateTransitions(
138127
// transition. This can happen delay and duration are both zero, or
139128
// because the new value is not interpolable.
140129
if (aElementTransitions) {
141-
bool checkProperties =
142-
aStyle.GetTransitionProperty(0) != eCSSPropertyExtra_all_properties;
130+
const bool checkProperties =
131+
aStyle.GetTransitionProperty(0) != eCSSProperty_all;
143132
AnimatedPropertyIDSet allTransitionProperties;
144133
if (checkProperties) {
145134
for (uint32_t i = aStyle.mTransitionPropertyCount; i-- != 0;) {

servo/components/style/properties/gecko.mako.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,8 +1761,10 @@ mask-mode mask-repeat mask-clip mask-origin mask-composite mask-position-x mask-
17611761
TransitionProperty::Custom(name) => {
17621762
gecko.mProperty = eCSSPropertyExtra_variable;
17631763
gecko.mUnknownProperty.mRawPtr = name.into_addrefed();
1764-
}
1765-
_ => gecko.mProperty = servo.to_nscsspropertyid().unwrap(),
1764+
},
1765+
TransitionProperty::NonCustom(id) => {
1766+
gecko.mProperty = id.to_nscsspropertyid();
1767+
},
17661768
}
17671769
}
17681770
} else {
@@ -1774,9 +1776,9 @@ mask-mode mask-repeat mask-clip mask-origin mask-composite mask-position-x mask-
17741776

17751777
/// Returns whether there are any transitions specified.
17761778
pub fn specifies_transitions(&self) -> bool {
1777-
use crate::gecko_bindings::structs::nsCSSPropertyID::eCSSPropertyExtra_all_properties;
1779+
use crate::gecko_bindings::structs::nsCSSPropertyID::eCSSProperty_all;
17781780
if self.mTransitionPropertyCount == 1 &&
1779-
self.mTransitions[0].mProperty == eCSSPropertyExtra_all_properties &&
1781+
self.mTransitions[0].mProperty == eCSSProperty_all &&
17801782
self.transition_combined_duration_at(0).seconds() <= 0.0f32 {
17811783
return false;
17821784
}

servo/components/style/properties/helpers/animated_properties.mako.rs

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::properties::{
1616
self, content_visibility::computed_value::T as ContentVisibility,
1717
visibility::computed_value::T as Visibility,
1818
},
19-
CSSWideKeyword, CustomDeclaration, CustomDeclarationValue, LonghandId,
19+
CSSWideKeyword, CustomDeclaration, CustomDeclarationValue, NonCustomPropertyId, LonghandId,
2020
NonCustomPropertyIterator, PropertyDeclaration, PropertyDeclarationId,
2121
};
2222
use std::ptr;
@@ -38,25 +38,7 @@ use void::{self, Void};
3838
#[allow(non_upper_case_globals)]
3939
impl From<nsCSSPropertyID> for TransitionProperty {
4040
fn from(property: nsCSSPropertyID) -> TransitionProperty {
41-
use crate::properties::ShorthandId;
42-
match property {
43-
% for prop in data.longhands:
44-
${prop.nscsspropertyid()} => {
45-
TransitionProperty::Longhand(LonghandId::${prop.camel_case})
46-
}
47-
% endfor
48-
% for prop in data.shorthands_except_all():
49-
${prop.nscsspropertyid()} => {
50-
TransitionProperty::Shorthand(ShorthandId::${prop.camel_case})
51-
}
52-
% endfor
53-
nsCSSPropertyID::eCSSPropertyExtra_all_properties => {
54-
TransitionProperty::Shorthand(ShorthandId::All)
55-
}
56-
_ => {
57-
panic!("non-convertible nsCSSPropertyID")
58-
}
59-
}
41+
TransitionProperty::NonCustom(NonCustomPropertyId::from_nscsspropertyid(property).unwrap())
6042
}
6143
}
6244

@@ -791,17 +773,22 @@ impl<'a> Iterator for TransitionPropertyIterator<'a> {
791773

792774
let index = self.index_range.next()?;
793775
match self.style.get_ui().transition_property_at(index) {
794-
TransitionProperty::Longhand(longhand_id) => {
795-
return Some(TransitionPropertyIteration {
796-
longhand_id,
797-
index,
798-
})
776+
TransitionProperty::NonCustom(id) => {
777+
match id.longhand_or_shorthand() {
778+
Ok(longhand_id) => {
779+
return Some(TransitionPropertyIteration {
780+
longhand_id,
781+
index,
782+
});
783+
},
784+
Err(shorthand_id) => {
785+
// In the other cases, we set up our state so that we are ready to
786+
// compute the next value of the iterator and then loop (equivalent
787+
// to calling self.next()).
788+
self.longhand_iterator = Some(shorthand_id.longhands());
789+
},
790+
}
799791
}
800-
// In the other cases, we set up our state so that we are ready to
801-
// compute the next value of the iterator and then loop (equivalent
802-
// to calling self.next()).
803-
TransitionProperty::Shorthand(ref shorthand_id) =>
804-
self.longhand_iterator = Some(shorthand_id.longhands()),
805792
TransitionProperty::Custom(..) | TransitionProperty::Unsupported(..) => {}
806793
}
807794
}

servo/components/style/properties/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,19 @@ impl fmt::Debug for PropertyDeclaration {
191191
}
192192

193193
/// A longhand or shorthand property.
194-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
194+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, ToComputedValue, ToResolvedValue, ToShmem, MallocSizeOf)]
195195
pub struct NonCustomPropertyId(u16);
196196

197+
impl ToCss for NonCustomPropertyId {
198+
#[inline]
199+
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
200+
where
201+
W: Write,
202+
{
203+
dest.write_str(self.name())
204+
}
205+
}
206+
197207
impl NonCustomPropertyId {
198208
/// Returns the underlying index, used for use counter.
199209
pub fn bit(self) -> usize {

servo/components/style/values/specified/animation.rs

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
//! Specified types for properties related to animations and transitions.
66
7-
use crate::custom_properties::Name as CustomPropertyName;
87
use crate::parser::{Parse, ParserContext};
9-
use crate::properties::{LonghandId, PropertyDeclarationId, PropertyId, ShorthandId};
8+
use crate::properties::{NonCustomPropertyId, PropertyId, ShorthandId};
109
use crate::values::generics::animation as generics;
1110
use crate::values::specified::{LengthPercentage, NonNegativeNumber};
1211
use crate::values::{CustomIdent, KeyframesName, TimelineName};
@@ -23,12 +22,10 @@ use style_traits::{
2322
Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem,
2423
)]
2524
pub enum TransitionProperty {
26-
/// A shorthand.
27-
Shorthand(ShorthandId),
28-
/// A longhand transitionable property.
29-
Longhand(LonghandId),
25+
/// A non-custom property.
26+
NonCustom(NonCustomPropertyId),
3027
/// A custom property.
31-
Custom(CustomPropertyName),
28+
Custom(Atom),
3229
/// Unrecognized property which could be any non-transitionable, custom property, or
3330
/// unknown property.
3431
Unsupported(CustomIdent),
@@ -41,8 +38,7 @@ impl ToCss for TransitionProperty {
4138
{
4239
use crate::values::serialize_atom_name;
4340
match *self {
44-
TransitionProperty::Shorthand(ref s) => s.to_css(dest),
45-
TransitionProperty::Longhand(ref l) => l.to_css(dest),
41+
TransitionProperty::NonCustom(ref id) => id.to_css(dest),
4642
TransitionProperty::Custom(ref name) => {
4743
dest.write_str("--")?;
4844
serialize_atom_name(name, dest)
@@ -71,12 +67,9 @@ impl Parse for TransitionProperty {
7167
},
7268
};
7369

74-
Ok(match id.as_shorthand() {
75-
Ok(s) => TransitionProperty::Shorthand(s),
76-
Err(longhand_or_custom) => match longhand_or_custom {
77-
PropertyDeclarationId::Longhand(id) => TransitionProperty::Longhand(id),
78-
PropertyDeclarationId::Custom(custom) => TransitionProperty::Custom(custom.clone()),
79-
},
70+
Ok(match id {
71+
PropertyId::NonCustom(id) => TransitionProperty::NonCustom(id.unaliased()),
72+
PropertyId::Custom(name) => TransitionProperty::Custom(name),
8073
})
8174
}
8275
}
@@ -94,22 +87,7 @@ impl TransitionProperty {
9487
/// Returns `all`.
9588
#[inline]
9689
pub fn all() -> Self {
97-
TransitionProperty::Shorthand(ShorthandId::All)
98-
}
99-
100-
/// Convert TransitionProperty to nsCSSPropertyID.
101-
#[cfg(feature = "gecko")]
102-
pub fn to_nscsspropertyid(
103-
&self,
104-
) -> Result<crate::gecko_bindings::structs::nsCSSPropertyID, ()> {
105-
Ok(match *self {
106-
TransitionProperty::Shorthand(ShorthandId::All) => {
107-
crate::gecko_bindings::structs::nsCSSPropertyID::eCSSPropertyExtra_all_properties
108-
},
109-
TransitionProperty::Shorthand(ref id) => id.to_nscsspropertyid(),
110-
TransitionProperty::Longhand(ref id) => id.to_nscsspropertyid(),
111-
TransitionProperty::Custom(..) | TransitionProperty::Unsupported(..) => return Err(()),
112-
})
90+
TransitionProperty::NonCustom(NonCustomPropertyId::from_shorthand(ShorthandId::All))
11391
}
11492
}
11593

0 commit comments

Comments
 (0)