You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CSS transition start value is not computed correctly #7816
In the example below, the transform:translateX value is incremented every 2 seconds. A CSS transition animates the div. But during the animation, the start value is not the value set via the style attribute, but the initial value set in the CSS rule.
Without digging too much, I just assumed that it meant that when a DOM element goes from transition:scale(1) to transition:scale(2), we keep the computed style at transition:scale(1) until the transition is done, then update to transition:scale(2).
By "reset to its initial value", I meant that we do not switch to transition:scale(2) immediately.
Assuming I assumed right:
Like you said, we can't update it during the transition, so it's done at the end. But:
Why is it done at the end and not before the transition start? It doesn't impact the transition itself. And what about getComputedStyle() in the middle of a transition?
Even if we want to do it at the end, the above-mentionned code is not called at the end of the transition (and really, that's the only thing I think we need to fix for this bug).
If a transition on the same property happens in the middle of the transition, where would we find the current computed value to compute the new animation?
Hmm, there's something wrong in my reasoning. The computed style (as seen from JS), is correctly updated during the transition and, of course, layout is properly updated overtime.Edit: nope. See next comment.
The computed style (as seen from JS), is correctly updated during the transition and, of course, layout is properly updated overtime.
Not all of them! opacity style (getComputedStyle().opacity) is not updated. width is.
div{position: absolute;top:10px;left:10px;width:100px;height:100px;background: red;transition: all 1000ms linear;opacity:0.1;}div.foo{width:200px;opacity:1;transform:translateY(200px);}
3 properties are being animated.
From div to div.foo, on screen, everything is animated correctly. The computed style (as seen from JS) of width is properly updated. Opacity is not (stays at 0.1). Transform can't be printed (empty string), so I can't tell, but I guess it behaves like the opacity property.
From div.foo to div, on screen, transform and opacity are properly reset to their initial value (none and 0.1), but without the transition (because Servo animates from the very initial state, skipping the div.foo values). And the width property stays at 200px. As for the computed style, it is stuck at the div.foo values for the 3 properties.
Opacity and transform are properties that do not require reflow. They have that in common. So I guess that explain why they behave differently (something like OMTA in Gecko).
So here, I see 3 issues, and I don't know how much they are related:
computed style (as seen from JS) of opacity and transforms are never updated
width of the div (on screen and computed style as seen from JS) is not updated on the 2nd animation
For 2 animations chaining (state A -> B -> C), on the 2nd animation (B -> C), the opacity and transform values at t0 come from A, not from B
But I'm not sure to understand why it's here in the first place.
There's a very short and barely noticeable flickering at the beginning of the animation where the width of the div jumps to its final value, and then, it's properly animated. I guess this is what the reset to 0.0 is for. So then, what would be missing is to call cascade_node_pseudo_element once the animation is over I guess.
To be more specific, there is no access to the DOM during animations. It's forbidden, because JS could be running concurrently during a transition (which is the whole point of OMT animations).
We should keep a list of finished animations, then at the next cascade, we can update the property value. Also, if animations are not finished, we should cancel them and update the style according to the current time.
@pcwalton does this require some big changes or it's just a matter of piping the right things together? In other words, do you think I can fix that or it's better if you take care of it?
In cascade_node_pseudo_element, at the beginning of the function, when we go through the animations and update the style to its progress=1.0 value, we should not assume the animation is over and update it to the its real progress value.
We should also cancel the animation at this point (not sure how yet).
Now, we also need to handle finished animations here, but finished animations are not accessible at this point. So in components/layout/animation.rs#update_animation_state, I'd suggest that we fill a finished_animations array (the same way we have a running_animations array), that we would flush in cascade_node_pseudo_element after we updated the style to its progress=1.0 value.
Well, I think this is beyond what I can do. Things are getting hairy when trying to cancel the animation on a property that is being modified in cascade_node. Maybe someone else can take over. Summary of what (I think) should be done:
save a list of finished animation, then, at the next cascade, the property value can be updated (at progress=1.0) (see a quick & dirty implementation here: b8379dd). The finished animation list should be flushed once the new property value has been computed.
on each cascade, update the value of the animated properties (also addressed in b8379dd)
cancel animations on properties that have changed. Maybe we need a sender/receiver for canceled animations. update_animation_state would check if there's any canceled animations and update the running animation list.
Activity
paulrouget commentedon Oct 1, 2015
Maybe related to #7781.
jdm commentedon Oct 1, 2015
Presumably we're getting incorrect values in http://mxr.mozilla.org/servo/source/components/layout/animation.rs#22 . The trick is figuring out why that's happening.
paulrouget commentedon Oct 6, 2015
The new style is reset to old style in
start_transitions_if_applicable:then it's supposed to be set to the final style in
cascade_node_pseudo_element:But
cascade_nodeis not called once the animation is over.paulrouget commentedon Oct 6, 2015
@pcwalton why is
this_stylereset to its initial value if there's a transition?paulrouget commentedon Oct 8, 2015
Can animations be interrupted or updated? Doesn't appear to work. Did it ever work or it's not implemented yet?
pcwalton commentedon Oct 8, 2015
@paulrouget I'm confused by what "reset to its initial value" means here—could you elaborate?
It's not safe to call
cascade_node_pseudo_elementduring transitions because they run off the main thread.paulrouget commentedon Oct 8, 2015
Sure. Keep in mind that I'm really not familiar with this code, so feel free to tell me if I'm totally off track :)
I'm looking at when
animation::start_transitions_if_applicableis called (https://mxr.mozilla.org/servo/source/components/layout/css/matching.rs#483):… and in
animation::start_transitions_if_applicable(https://mxr.mozilla.org/servo/source/components/layout/animation.rs#24):So in
cascade_node_pseudo_element, we do not update the style until the animation is finished. The final update happens here: https://mxr.mozilla.org/servo/source/components/layout/css/matching.rs#449Without digging too much, I just assumed that it meant that when a DOM element goes from
transition:scale(1)totransition:scale(2), we keep the computed style attransition:scale(1)until the transition is done, then update totransition:scale(2).By "reset to its initial value", I meant that we do not switch to
transition:scale(2)immediately.Assuming I assumed right:
Like you said, we can't update it during the transition, so it's done at the end. But:
getComputedStyle()in the middle of a transition?paulrouget commentedon Oct 9, 2015
Hmm, there's something wrong in my reasoning. The computed style (as seen from JS), is correctly updated during the transition and, of course, layout is properly updated overtime.Edit: nope. See next comment.paulrouget commentedon Oct 14, 2015
Not all of them!
opacitystyle (getComputedStyle().opacity) is not updated.widthis.3 properties are being animated.
From
divtodiv.foo, on screen, everything is animated correctly. The computed style (as seen from JS) ofwidthis properly updated. Opacity is not (stays at 0.1). Transform can't be printed (empty string), so I can't tell, but I guess it behaves like the opacity property.From
div.footodiv, on screen, transform and opacity are properly reset to their initial value (noneand 0.1), but without the transition (because Servo animates from the very initial state, skipping thediv.foovalues). And thewidthproperty stays at200px. As for the computed style, it is stuck at thediv.foovalues for the 3 properties.Opacity and transform are properties that do not require reflow. They have that in common. So I guess that explain why they behave differently (something like OMTA in Gecko).
So here, I see 3 issues, and I don't know how much they are related:
t0come from A, not from Bpaulrouget commentedon Oct 14, 2015
Commenting out this line:
https://mxr.mozilla.org/servo/source/components/layout/animation.rs#33
solves all the issues mentioned above.
But I'm not sure to understand why it's here in the first place.
There's a very short and barely noticeable flickering at the beginning of the animation where the
widthof the div jumps to its final value, and then, it's properly animated. I guess this is what the reset to 0.0 is for. So then, what would be missing is to callcascade_node_pseudo_elementonce the animation is over I guess.paulrouget commentedon Oct 14, 2015
@pcwalton: can you please explain why this line is necessary: https://mxr.mozilla.org/servo/source/components/layout/animation.rs#33
Can you confirm that
cascade_node_pseudo_elementshould be called at the end of the animation to trigger this code: https://mxr.mozilla.org/servo/source/components/layout/css/matching.rs#449 - if so, how can this be done?paulrouget commentedon Oct 14, 2015
I guess we could do that on
Msg::ChangeRunningAnimationsState.pcwalton commentedon Oct 15, 2015
You can't call
cascade_node_pseudo_elementduring animations. That's for nodes, not for fragments.pcwalton commentedon Oct 15, 2015
To be more specific, there is no access to the DOM during animations. It's forbidden, because JS could be running concurrently during a transition (which is the whole point of OMT animations).
1 remaining item
paulrouget commentedon Oct 23, 2015
We should keep a list of finished animations, then at the next cascade, we can update the property value. Also, if animations are not finished, we should cancel them and update the style according to the current time.
@pcwalton does this require some big changes or it's just a matter of piping the right things together? In other words, do you think I can fix that or it's better if you take care of it?
metajack commentedon Nov 2, 2015
Pinging @pcwalton
This is blocking browser.html progress.
pcwalton commentedon Nov 3, 2015
@paulrouget I don't think it'll be too tough—a medium-sized change, perhaps?
paulrouget commentedon Nov 3, 2015
In
cascade_node_pseudo_element, at the beginning of the function, when we go through the animations and update the style to itsprogress=1.0value, we should not assume the animation is over and update it to the its real progress value.Something like replacing:
with:
This appears to work.
We should also cancel the animation at this point (not sure how yet).
Now, we also need to handle finished animations here, but finished animations are not accessible at this point. So in
components/layout/animation.rs#update_animation_state, I'd suggest that we fill afinished_animationsarray (the same way we have arunning_animationsarray), that we would flush incascade_node_pseudo_elementafter we updated the style to itsprogress=1.0value.paulrouget commentedon Nov 3, 2015
@pcwalton could you take a quick look at this commit: b8379dd
I just want to know if that looks like the proper approach.
I still need to cancel animations in
cascade_node_pseudo_elementand flush thefinished_animationsarray.pcwalton commentedon Nov 4, 2015
Seems reasonable to me.
paulrouget commentedon Nov 9, 2015
Well, I think this is beyond what I can do. Things are getting hairy when trying to cancel the animation on a property that is being modified in cascade_node. Maybe someone else can take over. Summary of what (I think) should be done:
progress=1.0) (see a quick & dirty implementation here: b8379dd). The finished animation list should be flushed once the new property value has been computed.update_animation_statewould check if there's any canceled animations and update the running animation list.metajack commentedon Nov 10, 2015
@pcwalton agreed to take this
pcwalton commentedon Nov 24, 2015
I have a fix for this locally. Testing performance now.
Write animated values into the `ComputedValues` structures when
Auto merge of #8670 - pcwalton:animation-expiration, r=glennw
Write animated values into the `ComputedValues` structures when