mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Add a tweak to avoid calling interpolate() if animation_type is discrete.
For discrete type of animations, we just need to return 'from' value if progress is less than 0.5 and otherwise return 'to' value. https://w3c.github.io/web-animations/#discrete-animation-type
This commit is contained in:
parent
03d354afba
commit
4ff5a1ef70
1 changed files with 20 additions and 4 deletions
|
@ -233,9 +233,16 @@ impl AnimatedProperty {
|
||||||
% for prop in data.longhands:
|
% for prop in data.longhands:
|
||||||
% if prop.animatable:
|
% if prop.animatable:
|
||||||
AnimatedProperty::${prop.camel_case}(ref from, ref to) => {
|
AnimatedProperty::${prop.camel_case}(ref from, ref to) => {
|
||||||
if let Ok(value) = from.interpolate(to, progress) {
|
// https://w3c.github.io/web-animations/#discrete-animation-type
|
||||||
style.mutate_${prop.style_struct.ident.strip("_")}().set_${prop.ident}(value);
|
% if prop.animation_type == "discrete":
|
||||||
}
|
let value = if progress < 0.5 { *from } else { *to };
|
||||||
|
% else:
|
||||||
|
let value = match from.interpolate(to, progress) {
|
||||||
|
Ok(value) => value,
|
||||||
|
Err(()) => return,
|
||||||
|
};
|
||||||
|
% endif
|
||||||
|
style.mutate_${prop.style_struct.ident.strip("_")}().set_${prop.ident}(value);
|
||||||
}
|
}
|
||||||
% endif
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
|
@ -425,7 +432,16 @@ impl Interpolate for AnimationValue {
|
||||||
% if prop.animatable:
|
% if prop.animatable:
|
||||||
(&AnimationValue::${prop.camel_case}(ref from),
|
(&AnimationValue::${prop.camel_case}(ref from),
|
||||||
&AnimationValue::${prop.camel_case}(ref to)) => {
|
&AnimationValue::${prop.camel_case}(ref to)) => {
|
||||||
from.interpolate(to, progress).map(AnimationValue::${prop.camel_case})
|
// https://w3c.github.io/web-animations/#discrete-animation-type
|
||||||
|
% if prop.animation_type == "discrete":
|
||||||
|
if progress < 0.5 {
|
||||||
|
Ok(AnimationValue::${prop.camel_case}(*from))
|
||||||
|
} else {
|
||||||
|
Ok(AnimationValue::${prop.camel_case}(*to))
|
||||||
|
}
|
||||||
|
% else:
|
||||||
|
from.interpolate(to, progress).map(AnimationValue::${prop.camel_case})
|
||||||
|
% endif
|
||||||
}
|
}
|
||||||
% endif
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue