Skip to content

Commit 1c402e7

Browse files
committed
apply Martin's suggestions
Signed-off-by: Euclid Ye <[email protected]>
1 parent 714141e commit 1c402e7

File tree

1 file changed

+53
-50
lines changed

1 file changed

+53
-50
lines changed

style/animation.rs

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ impl AnimationState {
110110
}
111111
}
112112

113+
enum IncludedTransitions {
114+
Active,
115+
Running,
116+
}
117+
113118
/// This structure represents a keyframes animation current iteration state.
114119
///
115120
/// If the iteration count is infinite, there's no other state, otherwise we
@@ -869,7 +874,7 @@ impl ElementAnimationSet {
869874
}
870875
}
871876

872-
if let Some(map) = self.get_value_map_for_active_transitions(now) {
877+
if let Some(map) = self.get_value_map_for_transitions(now, IncludedTransitions::Active) {
873878
for value in map.values() {
874879
value.set_in_style_for_servo(mutable_style);
875880
}
@@ -991,30 +996,30 @@ impl ElementAnimationSet {
991996
continue;
992997
}
993998
// Step 3 in https://drafts.csswg.org/css-transitions/#starting
994-
// "If the element has a running transition or completed transition for the property,
995-
// and there is not a matching transition-property value, then implementations
996-
// must cancel the running transition or remove the completed transition from the set of completed transitions."
997-
let transition_property_id = transition.property_animation.property_id();
998-
if !transitioning_properties.contains(transition_property_id) {
999-
transition.state = AnimationState::Canceled;
1000-
self.dirty = true;
999+
// "If the element has a running transition or completed transition for the property, and there
1000+
// is not a matching transition-property value, then implementations must cancel the running
1001+
// transition or remove the completed transition from the set of completed transitions."
1002+
if transitioning_properties.contains(transition.property_animation.property_id()) {
1003+
continue;
10011004
}
1005+
transition.state = AnimationState::Canceled;
1006+
self.dirty = true;
10021007
// Step 4 was done in `fn start_transition_if_applicable`
10031008
}
10041009
}
10051010

10061011
fn start_transition_if_applicable(
10071012
&mut self,
10081013
context: &SharedStyleContext,
1009-
property_declaration: PropertyDeclarationId,
1014+
property_declaration_id: PropertyDeclarationId,
10101015
index: usize,
10111016
old_style: &ComputedValues,
10121017
new_style: &Arc<ComputedValues>,
10131018
) {
10141019
let style = new_style.get_ui();
10151020
let allow_discrete = style.transition_behavior_mod(index) == TransitionBehavior::AllowDiscrete;
1016-
let not_transitionable = !property_declaration.is_animatable() ||
1017-
(!allow_discrete && property_declaration.is_discrete_animatable());
1021+
let not_transitionable = !property_declaration_id.is_animatable()
1022+
|| (!allow_discrete && property_declaration_id.is_discrete_animatable());
10181023

10191024
let mut start_new_transition = !not_transitionable;
10201025

@@ -1028,10 +1033,10 @@ impl ElementAnimationSet {
10281033
}
10291034

10301035
// FIXME(emilio): Handle the case where old_style and new_style's writing mode differ.
1031-
let Some(from) = AnimationValue::from_computed_values(property_declaration, old_style) else {
1036+
let Some(from) = AnimationValue::from_computed_values(property_declaration_id, old_style) else {
10321037
return;
10331038
};
1034-
let Some(to) = AnimationValue::from_computed_values(property_declaration, new_style) else {
1039+
let Some(to) = AnimationValue::from_computed_values(property_declaration_id, new_style) else {
10351040
return;
10361041
};
10371042

@@ -1050,31 +1055,33 @@ impl ElementAnimationSet {
10501055
}
10511056

10521057
// Step 4 in https://drafts.csswg.org/css-transitions/#starting
1053-
// "If the element has a running transition for the property, there is a matching transition-property value,
1058+
// "If the element has a running transition for the property, there is a matching
1059+
// transition-property value, and the end value of the running transition is not equal
1060+
// to the value of the property in the after-change style, then:"
10541061
let mut running_transition = None;
10551062
if let Some(old_transition) = self
10561063
.transitions
10571064
.iter_mut()
10581065
.filter(|transition| transition.state != AnimationState::Canceled)
10591066
.find(|transition| {
1060-
transition.property_animation.property_id() == property_declaration
1067+
transition.property_animation.property_id() == property_declaration_id
10611068
})
10621069
{
1063-
// and the end value of the running transition is not equal to the value of the property in the after-change style, then:"
10641070
if to != old_transition.property_animation.to {
10651071
if old_transition.state != AnimationState::Finished {
10661072
let current_val = old_transition.calculate_value(now);
10671073
let not_transitionable = not_transitionable||
10681074
(!allow_discrete && !current_val.interpolable_with(&to));
10691075

10701076
// Step 4.1
1071-
//"If the current value of the property in the running transition is equal
1072-
// to the value of the property in the after-change style,
1073-
// or if these two values are not transitionable, then implementations must cancel the running transition."
1077+
// > If the current value of the property in the running transition
1078+
// > is equal to the value of theproperty in the after-change style,
1079+
// > or if these two values are not transitionable, then
1080+
// > implementations must cancel the running transition.
10741081
if current_val == to || not_transitionable {
10751082
old_transition.state = AnimationState::Canceled;
10761083
self.dirty = true;
1077-
start_new_transition = false;
1084+
return;
10781085
}
10791086
// Step 4.2
10801087
// "Otherwise, if the combined duration is less than or equal to 0s, or if the current value of the property in the
@@ -1083,7 +1090,7 @@ impl ElementAnimationSet {
10831090
else if duration + delay <= 0.0 {
10841091
old_transition.state = AnimationState::Canceled;
10851092
self.dirty = true;
1086-
start_new_transition = false;
1093+
return;
10871094
}
10881095
running_transition = Some(old_transition);
10891096
}
@@ -1093,7 +1100,7 @@ impl ElementAnimationSet {
10931100
// completed. We don't take into account any canceled animations.
10941101
// [1]: https://drafts.csswg.org/css-transitions/#starting
10951102
else {
1096-
start_new_transition = false;
1103+
return;
10971104
}
10981105
}
10991106

@@ -1130,39 +1137,33 @@ impl ElementAnimationSet {
11301137
}
11311138
}
11321139

1133-
/// Generate a `AnimationValueMap` for this `ElementAnimationSet`'s
1134-
/// active transitions at the given time value.
1135-
pub fn get_value_map_for_active_transitions(&self, now: f64) -> Option<AnimationValueMap> {
1136-
if !self.has_active_transition() {
1137-
return None;
1138-
}
1139-
1140-
let mut map =
1141-
AnimationValueMap::with_capacity_and_hasher(self.transitions.len(), Default::default());
1142-
for transition in &self.transitions {
1143-
if transition.state == AnimationState::Canceled {
1144-
continue;
1145-
}
1146-
let value = transition.calculate_value(now);
1147-
map.insert(value.id().to_owned(), value);
1148-
}
1149-
1150-
Some(map)
1151-
}
1140+
11521141

11531142
/// Generate a `AnimationValueMap` for this `ElementAnimationSet`'s
1154-
/// transitions that are not canceled or finished at the given time value.
1155-
pub fn get_value_map_for_running_transitions(&self, now: f64) -> Option<AnimationValueMap> {
1143+
/// transitions that depends on flag.
1144+
fn get_value_map_for_transitions(&self, now: f64, flag: IncludedTransitions) -> Option<AnimationValueMap> {
11561145
if !self.has_active_transition() {
11571146
return None;
11581147
}
11591148

11601149
let mut map =
11611150
AnimationValueMap::with_capacity_and_hasher(self.transitions.len(), Default::default());
11621151
for transition in &self.transitions {
1163-
if transition.state == AnimationState::Canceled || transition.state == AnimationState::Finished {
1164-
continue;
1152+
match flag {
1153+
IncludedTransitions::Active => {
1154+
if transition.state == AnimationState::Canceled {
1155+
continue;
1156+
}
1157+
}
1158+
IncludedTransitions::Running => {
1159+
if transition.state == AnimationState::Canceled
1160+
|| transition.state == AnimationState::Finished
1161+
{
1162+
continue;
1163+
}
1164+
}
11651165
}
1166+
11661167
let value = transition.calculate_value(now);
11671168
map.insert(value.id().to_owned(), value);
11681169
}
@@ -1276,7 +1277,7 @@ impl DocumentAnimationSet {
12761277
self.sets
12771278
.read()
12781279
.get(key)
1279-
.and_then(|set| set.get_value_map_for_running_transitions(time))
1280+
.and_then(|set| set.get_value_map_for_transitions(time, IncludedTransitions::Running))
12801281
.map(|map| {
12811282
let block = PropertyDeclarationBlock::from_animation_value_map(&map);
12821283
Arc::new(shared_lock.wrap(block))
@@ -1301,10 +1302,12 @@ impl DocumentAnimationSet {
13011302
let block = PropertyDeclarationBlock::from_animation_value_map(&map);
13021303
Arc::new(shared_lock.wrap(block))
13031304
});
1304-
let transitions = set.get_value_map_for_running_transitions(time).map(|map| {
1305-
let block = PropertyDeclarationBlock::from_animation_value_map(&map);
1306-
Arc::new(shared_lock.wrap(block))
1307-
});
1305+
let transitions = set
1306+
.get_value_map_for_transitions(time, IncludedTransitions::Running)
1307+
.map(|map| {
1308+
let block = PropertyDeclarationBlock::from_animation_value_map(&map);
1309+
Arc::new(shared_lock.wrap(block))
1310+
});
13081311
AnimationDeclarations {
13091312
animations,
13101313
transitions,

0 commit comments

Comments
 (0)