Commit graph

211 commits

Author SHA1 Message Date
Martin Robinson
cf4510011f animations: Don't convert linear easing to a bezier
This conversion can lead to floating point errors and extra work when
computing animations. Avoiding it allows animation-iteration-count-009.html
to pass.
2020-06-24 17:19:25 +02:00
Martin Robinson
954b5177f0 animations: Finish support for fractional iteration counts
This change also improves support for creating animations with negative
delays, as that is necessary to test support for fractional iteration
lengths.

This change also adjusts existing Servo animation tests which assumed
that advancing to the exact moment of the end of the animation would be
considered "before the end." With this change, this moment is "after the
end."

Fixes: #14858
2020-06-24 17:19:25 +02:00
Emilio Cobos Álvarez
97f29c893f
style: Fix gecko build. 2020-06-18 23:51:18 +02:00
Martin Robinson
f92164144e animations: Don't apply animation delay to every iteration
The delay should only be applied to the animation before the first
iteration.
2020-06-18 16:36:14 +02:00
Martin Robinson
36701e0223 Combine AnimationAndTransitionDeclarations and AnimationRules
These two structs are very similar, so we can combine them.
2020-06-16 19:25:52 +02:00
Martin Robinson
f3e373bc62 Add animation and transition support for pseudo-elements
This change extends the DocumentAnimationSet to hold animations for
pseudo-elements. Since pseudo-elements in Servo are not in the DOM like
in Gecko, they need to be handled a bit carefully in stylo.  When a
pseudo-element has an animation, recascade the style. Finally, this
change passes the pseudo-element string properly to animation events.

Fixes: #10316
2020-06-16 16:33:55 +02:00
Martin Robinson
4a3995bb37 Add DocumentAnimationSet and AnimationSetKey
This will be used in order to hold animations for pseudo elements in the
DocumentAnimationSet. Also no longer store the OpaqueNode in the
animation and transition data structures. This is already part of the
DocumentAnimationSet key.
2020-06-15 10:28:30 +02:00
Martin Robinson
af0bb1f728 animations: Don't always re-resolve the node style
When animations and transitions change don't always re-resolve node
style, just replace the animation and transition rules and re-cascade.
2020-06-10 17:03:58 +02:00
Martin Robinson
364235ac0c Include animations and transitions in the cascade
Instead of applying animations and transitions to styled elements,
include them in the cascade. This allows them to interact properly with
things like font-size and !important rules.
2020-06-09 11:41:07 +02:00
Martin Robinson
b875f14e86 Better computation of animation keyframes
This begins to address #26625 by properly applying CSS variables during
keyframe computation and no longer using `apply_declarations`. Instead,
walk the declarations, combining them into IntermediateComputedKeyframe,
maintaining declarations that modify CSS custom properties. Then compute
a set of AnimationValues for each keyframe and use those to produce
interpolated animation values.
2020-06-05 13:40:29 +02:00
Martin Robinson
83fa1b9eaa Cache animation computed values when animations change
Instead of recalculating the animation style every tick of an animation,
cache the computed values when animations change. In addition to being
more efficient, this will allow us to return animation rules as property
declarations because we don't need to consult the final style to produce
them.
2020-06-05 13:21:19 +02:00
Emilio Cobos Álvarez
ec6ecf7d21 style: Clean up cascade rule iteration. r=nordzilla
The current API was pretty awkward as a result of two things:

 * Not being able to create empty iterators for smallbitvec.
 * We used to call the `F` function multiple times, but turns out that
   collecting the declarations in a SmallVec was a perf win.

So clean this up so that it looks more similar to other APIs, taking an
iterator directly.

This is a bit more code, but hopefully easier to understand (and also hopefully
easier to optimize).

The motivation for this work is that I plan to investigate rebasing / landing
https://github.com/servo/servo/pull/20151, and I don't want more instantiations
of apply_declarations and such.

Differential Revision: https://phabricator.services.mozilla.com/D74369
2020-06-04 01:50:36 +02:00
Martin Robinson
77aa3721c5 Add support for remaining animation and transition events
Fixes #21564.
2020-05-26 20:34:58 +02:00
Martin Robinson
47642e0eee Have Animations struct handle rooting nodes
Instead of having `ScriptThread` handle rooting nodes, do this in
`Animations`. This makes it easier to know when it is appropriate to
root and unroot nodes instead of relying on a certain order of events.
This also allows reducing quite a bit the amount of unsafe code.
2020-05-26 20:24:28 +02:00
Martin Robinson
218beb9218 Improve ending of transitions
For legacy reasons, transitions were marked as finished after updating the
style. According to the spec, they should be marked as finished when
animations are updated and before restyle. This change does that as well
as preventing replacement of finished transitions.

Having finished transitions survive a full restyle cycle and allowing
the replacement of finished transition, could lead to issues were
removed from the global list of animating transitions too soon:

 1. A transitions finishes
 2. Restyle
 3. Transitions is marked as finished and events are queued
 4. Restyle cancels finished transition and replaces it instead of
    clearing finished transition
 5. Events are sent for the incorrectly canceled transition removing it
    completely from the list of running transitions due to the extra
    event.
2020-05-21 19:56:29 +02:00
Martin Robinson
873cdd1336 Implement animationiteration event
This event is triggered when an animation iterates. This change also
moves iteration out of style calculation to an "update animations" which
is the next part of having animation event handling match the HTML spec.
2020-05-21 15:19:34 +02:00
Martin Robinson
4ba15c33e3 Add support for faster reversing of interrupted transitions
This is described in the spec and allows interrupted transitions to
reverse in a more natural way. Unfortunately, most of the tests that
exercise this behavior use the WebAnimations API. This change adds a
test using our custom clock control API.
2020-05-20 16:25:27 +02:00
Martin Robinson
183f15d5aa Implement animation-fill-mode
Fixes #26460.
2020-05-17 20:42:57 +02:00
Martin Robinson
0f1831e2fa Remove AnimatedProperty
This removes an extra layer of abstraction and allows Servo to share
more code with Gecko. In addition, we will need to handle raw
`AnimationValue` structs soon in order to fully implement "faster
reversing of interrupted transitions."
2020-05-13 11:02:52 +02:00
Martin Robinson
3b0619aedd Move most animation processing to script
This is preparation for sharing this code with layout_2020 and
implementing selective off-the-main-thread animations.

We still look for nodes not in the flow tree in the layout thread.
2020-05-12 10:22:14 +02:00
Martin Robinson
b8874ad6ac Split animations and transitions into separate lists
This change splits the list of animations and transitions, which are
almost always handled differently. It also renames
`ElementAnimationState` to `ElementAnimationSet` and establishes an
`AnimationState` for every transition and animation. This allows us to
stop continually reallocating lists every time a transition or animation
needs to be canceled.

Fixes #14419.
2020-05-06 19:26:50 +02:00
Martin Robinson
b585ce5b1f Use a restyle for animation ticks
This change corrects synchronization issues with animations, by
reworking the animation processing model to do a quick restyle and
incremental layout when ticking animations.

While this change adds overhead to animation ticks, the idea is that
this will be the fallback when synchronous behavior is required to
fulfill specification requirements. In the optimistic case, many
animations could be updated and applied off-the-main-thread and then
resynchronized when style information is queried by script.

Fixes #13865.
2020-05-05 15:13:35 +02:00
Martin Robinson
3903c1fb98 Add support for animationend event
This is triggered when an animation finishes. This is a high priority
because it allows us to start rooting nodes with animations in the
script thread.

This doesn't yet cause a lot of tests to pass because they rely on the
existence of `Document.getAnimations()` and the presence of
`animationstart` and animationiteration` events.
2020-05-01 15:29:57 +02:00
Martin Robinson
0ab4260d6b Split animation cancellation from update_style_for_animation
`update_style_for_animation` previously handled both canceling defunct
animations and also updating style to reflect current animation state.
This change splits those two concerns because we want to start handling
replaced or canceled animations and finished animations in two different
places.

This is a refactor, so ideally it shouldn't change any behavior.
2020-04-30 15:45:07 +02:00
Martin Robinson
5ca2e7ce91 Restyle should reflect animations and transitions
When doing a restyle, we should apply animations and transitions to the
new style so that it is reflected in `getComputedStyle()` and the new
style information properly cascades. This is the first part of properly
ticking animations and transitions.

This causes a couple new animations tests failures (along with many new
passes), but we currently don't have support for properly handling
animations after they have completed, so this isn't totally unexpected.
2020-04-29 15:31:31 +02:00
Martin Robinson
8f988be18a Add ElementAnimationState and PossibleElementAnimationState
This refactor is preparation for implementing a specification
compliant transitions and animations processing model.

These data structures hold all the animation information about a single
node. Since adding, updating, and modifying animations for a single node
are all interdependent, it makes sense to start encapsulating animation
data and functionality into a single data structure. This also opens up
the possibility for easier concurrency in the future by more easily
allowing per-node mutexes.
2020-04-24 11:51:17 +02:00
Emilio Cobos Álvarez
2fd13b302b
style: Minor build fixes 2020-04-23 05:14:55 +02:00
Martin Robinson
453b252a65 Add support for canceling CSS transitions
This change adds support for canceling CSS transitions when a property
is no longer transitionable or when an element becomes styled with
display:none. Support for canceling and replacing CSS transitions when
the end value changes is still pending. This change also takes advantage
of updating the constellation message to fix a bug where transition
events could be sent for closed pipelines.

Fixes #15079.
2020-04-22 17:23:26 +02:00
Martin Robinson
a0b495750e Eliminate AnimationFrame
This intermediate data structure doesn't really buy us anything and is a
bit confusing.
2020-04-18 13:48:52 +02:00
Martin Robinson
fad79a724c Add an iterator for transition properties
This simplifies the code a bit and also will allow us to more easily
make improvements to servo's animation implementation in the future.
2020-04-17 15:11:49 +02:00
Martin Robinson
304b283811 style: Refactor some animations code
This change modifies the names of some methods to make it clearer what
they are doing. It also adds some clarifying comments to explain some
confusing behavior.
2020-04-14 13:40:43 +02:00
Josh Matthews
2bb6ab4567 Avoid infinitely looping CSS transitions. 2020-04-01 12:13:52 -04:00
Emilio Cobos Álvarez
425025c230
style: Use only Origin during the cascade, rather than CascadeLevel.
The micro-benchmark `style-attr-1.html` regressed slightly with my patch, after
the CascadeLevel size increase.

This benchmark is meant to test for the "changing the style attribute doesn't
cause selector-matching" optimization (which, mind you, keeps working).

But in the process it creates 10k rules which form a perfect path in the rule
tree and that we put into a SmallVec during the cascade, and the benchmark
spends most of the time pushing to that SmallVec and iterating the declarations
(as there's only one property to apply).

So we could argue that the regression is minor and is not what the benchark is
supposed to be testing, but given I did the digging... :)

My patch made CascadeLevel bigger, which means that we create a somewhat bigger
vector in this case. Thankfully it also removed the dependency in the
CascadeLevel, so we can stop using that and use just Origin which is one byte to
revert the perf regression.

Differential Revision: https://phabricator.services.mozilla.com/D53181
2019-11-30 20:45:00 +01:00
Simon Sapin
1d38bc0419 Fix some new warnings 2019-06-22 14:59:09 +02:00
est31
642b7c3ea1 Remove unused code from selector and style crates 2019-06-07 15:14:21 +02:00
Emilio Cobos Álvarez
27322abeda style: Minor build fixup after the Servo crossbeam_channel update. 2018-12-16 13:35:08 +01:00
Jan Andre Ikenmeyer
1d6fe65401
Update MPL license to https (part 4) 2018-11-19 14:47:27 +01:00
Bastien Orivel
9a7eeb349a Update crossbeam-channel to 0.3 2018-11-18 19:33:19 +01:00
Simon Sapin
a15d33a10e cargo fix --edition 2018-11-10 17:47:28 +01:00
Pyfisch
9e92eb205a Reorder imports 2018-11-06 22:35:07 +01:00
Pyfisch
cb07debcb6 Format remaining files 2018-11-06 22:30:31 +01:00
Emilio Cobos Álvarez
05f9f10a1c
style: Fix servo build and tidy lints. 2018-10-28 23:52:13 +01:00
Boris Chiou
0c057d9299
style: Implement steps(jump-*) functions.
1. Add a new preference, layout.css.step-position-jump.enabled, for
   step(_, jump-*) timing functions.
2. We still keep JumpEnd and End tags, even though there is no difference
   between them. Therefore, we could disable the preference if needed.
3. Update the calculation of StepTiming to match the algorithm in the spec.
4. For servo, we implement the correct step function algorithm except
   for the handling of before_flag. This could be fixed later.

Depends on D9313

Differential Revision: https://phabricator.services.mozilla.com/D9314
2018-10-28 23:45:03 +01:00
Boris Chiou
a20b6a5166
style: Split TimingFunction into a separate file to match spec.
TimingFunction is defined in a separate spec (i.e. css-easing), instead
of transform, so we move it into a different file.

Depends on D9310

Differential Revision: https://phabricator.services.mozilla.com/D9311
2018-10-28 23:44:26 +01:00
Boris Chiou
3a536f463c
style: Drop frames() timing function.
frames() timing function was removed from the spec, so we drop it.
Besides, some devtool tests are removed because they use frame(). I will
add them back by using new step function later.

Differential Revision: https://phabricator.services.mozilla.com/D9309
2018-10-28 23:44:16 +01:00
Emilio Cobos Álvarez
3b7b21ebb5
Revert "style: Make the transitions code make sense again."
This reverts commit d6092fae27.

This change actually makes transitions start, and our code for stopping
transitions is just bogus, so we just keep re-starting them over and over, which
is not good.
2018-10-19 01:21:04 +02:00
Emilio Cobos Álvarez
561e9c81f1
style: More useful logging for transition-related stuff.
Transitions are still broken, but I found these messages more helpful than the
previous ones when diagnosing problems.
2018-10-15 14:50:13 +02:00
Emilio Cobos Álvarez
a949e9e1e8
style: Expire keyframes animations when no longer referenced by the style.
It's a long way to make this sound in general...

Fixes #20731
2018-10-15 04:52:50 +02:00
Emilio Cobos Álvarez
1ba57cbaad
style: Remove unused expired boolean in Animation::Transition.
The last caller who used was #14418, which did fix a problem but introduced
multiple. In particular, now transitions don't get expired ever, until they
finish running of course.

That is not ok, given you can have something that the user can trigger to change
the style (hi, :hover, for example), and right now that triggers new
transitions, getting this into a really funny state.

I should give fixing this a shot, but it's non-trivial at all.
2018-10-15 04:52:50 +02:00
Emilio Cobos Álvarez
d6092fae27
style: Make the transitions code make sense again. 2018-10-15 04:50:45 +02:00