servo/components
yvt effd5a3107 fix(script): request animation ticks if Animations::pending_events is not empty
Fixes the test case `/_mozilla/css/css-transition-cancel-event
.html`, which was failing under a specific circumstance.

The observed sequence of events during the failing test run looks like
this:

1. Transitions start in `div1` and `div2`.

2. `div1` generates a `transitionend` event.

3. The `transitionend` event handler removes `div2` from DOM, cancelling
   its ongoing transition.

4. `div2` is supposed to generate a `transitioncancel` event in a timely
   manner, which it does not. The test fails as a result.

What is going on here? Here's a possible explaination:

1. During one invocation of `ScriptThread::handle_msgs`...

2. In step 2, `ScriptThread::update_animations_send_events` -> `Document
   ::update_for_new_timeline_value` detects the completion of the
   transition, and in response, pends the `transitionend` event.

3. In step 3, `ScriptThread::update_animations_send_events` ->
   `Animations::send_pending_events` calls the `transitionend` handler.

4. The `transitionend` event handler removes `div2`, thereby cancelling
   its ongoing transition and triggering a reflow.

5. Reflow takes place. During this, `Animations::do_post_reflow_update`
   -> `Animations::handle_canceled_animations` pends the
   `transitioncancel` event (precursor to step 4).

6. Having discovering that there was no running animation, `Animations::
   do_post_reflow_update` calls `self.update_running_animation_presence
   (_, false)`, which sends `AnimationState::NoAnimationsPresent`.

7. The invocation of `ScriptThread::handle_msgs` ends, and another
   starts. It blocks waiting for events.

8. Meanwhile, the compositor receives `AnimationState::
   NoAnimationsPresent` and stops further generation of animation ticks.

9. With no events to wake it up, the script thread is stuck waiting
   despite having the pending `transitioncancel` event (step 4).

The HTML specification [says][1] that "an event loop must continually
run [...] as long as it exists" and does not say it can block if there
is nothing to do. Blocking is merely optimization in a user agent
implementation. Pending animation-related events must be processed every
time a "rendering opportunity" arises unless the user agent has a reason
to believe that it "would have no visible effect".

Skipping the processing of animation-related events would have visible
effect if such events are indeed present. The correct implementation in
Servo, therefore, would be to request more animation ticks so that such
events are processed in a subsequent tick.

[1]: https://html.spec.whatwg.org/multipage/#event-loop-processing-model
2023-02-10 14:44:27 +01:00
..
allocator
atoms Implement GPUUncapturedErrorEvent 2020-08-11 14:24:58 +05:30
background_hang_monitor fix(bhm): deliver exit signal reliably (for real) 2021-06-21 00:07:26 +09:00
bluetooth feat: shorten thread names 2021-07-19 00:57:48 +09:00
bluetooth_traits Fix some Clippy lints. 2022-08-04 00:13:36 +08:00
canvas Bump euclid to 0.22 2023-01-26 08:59:21 +01:00
canvas_traits Bump euclid to 0.22 2023-01-26 08:59:21 +01:00
compositing Bump euclid to 0.22 2023-01-26 08:59:21 +01:00
config Bump euclid to 0.22 2023-01-26 08:59:21 +01:00
config_plugins Fix some Clippy lints. 2022-08-04 00:13:36 +08:00
constellation Bump euclid to 0.22 2023-01-26 08:59:21 +01:00
deny_public_fields
derive_common Miscellaneous build / tidy fixes. 2021-02-26 17:53:55 +01:00
devtools Upgrade Hyper 2022-01-16 09:34:17 -08:00
devtools_traits Fix some Clippy lints. 2022-08-04 00:13:36 +08:00
dom_struct
domobject_derive More Cargo.toml cleanups 2020-05-14 22:20:18 -07:00
embedder_traits Update keyboard-types. 2022-04-01 00:35:22 -04:00
fallible More Cargo.toml cleanups 2020-05-14 22:20:18 -07:00
geometry Bump euclid to 0.22 2023-01-26 08:59:21 +01:00
gfx Bump euclid to 0.22 2023-01-26 08:59:21 +01:00
gfx_traits Update webrender. 2020-06-11 14:07:39 -04:00
hashglobe Use SPDX license format 2022-10-10 15:48:05 -07:00
jstraceable_derive
layout Bump euclid to 0.22 2023-01-26 08:59:21 +01:00
layout_2020 Bump euclid to 0.22 2023-01-26 08:59:21 +01:00
layout_thread Bump euclid to 0.22 2023-01-26 08:59:21 +01:00
layout_thread_2020 Bump euclid to 0.22 2023-01-26 08:59:21 +01:00
layout_traits ensure clean shutdown of all threads running JS 2020-06-30 13:22:38 +08:00
malloc_size_of Bump euclid to 0.22 2023-01-26 08:59:21 +01:00
media Bump euclid to 0.22 2023-01-26 08:59:21 +01:00
metrics Remove support for energy profiling 2020-06-04 16:39:08 +02:00
msg Fix some Clippy lints. 2022-08-04 00:13:36 +08:00
net Fix intermittency when loading poster images 2023-01-11 12:27:27 +01:00
net_traits Auto merge of #28893 - EnnuiL:master, r=jdm 2022-08-15 18:16:23 -04:00
pixels Bump euclid to 0.22 2023-01-26 08:59:21 +01:00
profile feat: shorten thread names 2021-07-19 00:57:48 +09:00
profile_traits Bump time to latest v0.1.x version. 2021-06-25 17:19:14 +01:00
rand Removed the commented code. 2022-12-01 18:27:59 +04:00
range More Cargo.toml updates 2020-05-30 18:18:57 -07:00
remutex Fix rust's remutex source code link 2020-06-01 21:24:05 +09:00
script fix(script): request animation ticks if Animations::pending_events is not empty 2023-02-10 14:44:27 +01:00
script_layout_interface Bump euclid to 0.22 2023-01-26 08:59:21 +01:00
script_plugins Upgrade the Rust toolchain to 'nightly-2023-02-01' 2023-02-01 19:38:06 +05:30
script_traits Bump euclid to 0.22 2023-01-26 08:59:21 +01:00
selectors Remove some badges 2023-01-19 19:38:30 -08:00
servo Bump euclid to 0.22 2023-01-26 08:59:21 +01:00
servo_arc Auto merge of #28967 - servo:jdm-patch-52, r=jdm 2022-11-20 11:42:39 -05:00
size_of_test
std_test_override
style Bump euclid to 0.22 2023-01-26 08:59:21 +01:00
style_derive Fix some Clippy lints. 2022-08-04 00:13:36 +08:00
style_traits Bump euclid to 0.22 2023-01-26 08:59:21 +01:00
to_shmem Updated cssparser dependency to 0.29. 2021-11-18 16:16:46 +01:00
to_shmem_derive Fix warnings introduced in newer Rust Nightly 2021-02-25 15:36:03 +01:00
url Fix some build warnings 2023-01-11 12:50:36 +01:00
webdriver_server Bump euclid to 0.22 2023-01-26 08:59:21 +01:00
webgpu Bump euclid to 0.22 2023-01-26 08:59:21 +01:00
webrender_surfman Bump euclid to 0.22 2023-01-26 08:59:21 +01:00
webrender_traits Bump euclid to 0.22 2023-01-26 08:59:21 +01:00