Commit graph

36 commits

Author SHA1 Message Date
TIN TUN AUNG
23ce7b31ac
Animation: update image active frame when update the rendering (#36286)
When no CSS animation exist, register timer for image animation, update
animated image active image frame as part of update_the_rendering, mark
node as dirty if the corresponding image need update. Added unit test to
test ImageAnimationState.

Part of https://github.com/servo/servo/issues/36057, the last step to
let the Animated Image "Move".

Testing: Introduced new WPT RefTest for animated image, but fail because
of https://github.com/servo/servo/issues/36931. New unit test for
`ImageAnimationState`.
Fixes: https://github.com/servo/servo/issues/22903
https://github.com/servo/servo/issues/36057

[Try](1472472966)

---------

Signed-off-by: rayguo17 <rayguo17@gmail.com>
2025-05-23 03:13:35 +00:00
Martin Robinson
6031a12fd1
Move ScriptToConstellationMsg to constellation_traits (#36364)
This is the last big change necessary to create the
`constellation_traits` crate. This moves the data structure for messages
that originate from the `ScriptThread` and are sent to the
`Contellation` to `constellation_traits`, effectively splitting
`script_traits` in half. Before, `script_traits` was responsible for
exposing the API of both the `ScriptThread` and the `Constellation` to
the rest of Servo.

- Data structures that are used by `ScriptToConstellationMsg` are moved
  to `constellation_traits`. The dependency graph looks a bit like this:
  `script_layout_interface` depends on `script_traits` depends on
  `constellation_traits` depends on `embedder_traits`.
- Data structures that are used in the embedding layer
  (`UntrustedNodeAddress`, `CompositorHitTestResult`, `TouchEventResult`
  and `AnimationState`) are moved to embedder_traits, to avoid a
  dependency cycle between `webrender_traits` and
  `constellation_traits`.
- Types dealing with MessagePorts and serialization are moved to
  `constellation_traits::message_port`.

Testing: This is covered by existing tests as it just moves types
around.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-04-05 22:13:29 +00:00
Martin Robinson
5a35e1faec
constellation: Rename messages sent to the Constellation (#36341)
Messages that are sent to the `Constellation` have pretty ambiguous
names.
This change does two renames:

- `ConstellationMsg` → `EmbedderToConstellationMessage`
- `ScriptMsg` → `ScriptToConstellationMessage`

This naming reflects that the `Constellation` stands in between the
embedding layer and the script layer and can receive messages from both.
Soon both of these message types will live in `constellation_traits`,
reflecting the idea that the `_traits` variant for a crate is
responsible for exposing the API for that crate.

Testing: No new tests are necessary here as this just renames two enums.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-04-04 19:39:38 +00:00
Martin Robinson
7c574141c0
Create a constellation_traits crate (#36088)
This change creates a `constellation_traits` crate. Previously messages
to the `Constellation` were in the `compositing_traits` crate, which
came about organically. This change moves these to a new crate which
also contains data types that are used in both compositing/libservo and
script (ie types that cross the process boundary). The idea is similar
to `embedding_traits`, but this is meant for types not exposed to the
API.

This change allows deduplicating `UntrustedNodeAddress`, which
previously had two versions to avoid circular dependencies.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-03-22 15:49:08 +00:00
Simon Wülker
3d320fa96a
Update rustfmt to the 2024 style edition (#35764)
* Use 2024 style edition

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Reformat all code

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-03-03 11:26:53 +00:00
Simon Wülker
1b882f2729
Implement Event propagation across shadow roots (#34884)
* Implement Event.composed flag

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Allow composed events to pass shadow boundaries

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Update WPT expectations

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-01-22 15:25:16 +00:00
Josh Matthews
875e387004
script: Feature-gate all crown support. (#35055)
* script: Feature-gate all crown support.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Use cfg(crown) instead of a cargo feature.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2025-01-18 21:36:15 +00:00
Josh Matthews
c94d909a86
script: Limit public exports. (#34915)
* script: Restrict reexport visibility of DOM types.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Mass pub->pub(crate) conversion.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Hide existing dead code warnings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Formatting.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Fix clippy warnings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Formatting.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Fix unit tests.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Fix clippy.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* More formatting.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2025-01-10 08:19:19 +00:00
Martin Robinson
e8f75c9aea
script: Expose node helpers as NodeTraits and give more descriptive names (#34832)
This puts a few commonly used `Node` helpers into a trait (`NodeTraits`)
and gives them more descriptive names and documentation. The renames:

- `document_from_node` -> `NodeTraits::owner_document`
- `window_from_node` -> `NodeTraits::owner_window`
- `stylesheets_owner_from_node<T:` -> `NodeTraits::stylesheet_list_owner`
- `containing_shadow_root` -> `NodeTraits::containing_shadow_root`

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-01-03 18:55:01 +00:00
Martin Robinson
54761b4f32
script: Update animations once per-Document during update_the_rendering() (#34489)
Before, `update_the_rendering()` would update all animations for all
Documents once per-Document. Apart from being generally wrong, the
specification says this should be done once per-Document. This
theoretically means that `update_the_rendering()` is just doing less
work every time it runs.

In addition:
 - Don't redirty animations nodes when running rAF callbacks. They
   should already be dirty when animations are updated.
 - Perform a microtask checkpoint while updating animations as dictacted
   by the specification.
 - Update comments to reflect the specification text.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2024-12-05 16:37:59 +00:00
chickenleaf
7ad8822d94
cangc fixes in several files + event.rs + rtcpeerconnection.rs (#34002)
Signed-off-by: L Ashwin B <lashwinib@gmail.com>
2024-10-25 12:44:15 +00:00
tanishka
46d6c0c883
CanGc fixes in components/script/dom (#33843)
Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>
2024-10-15 04:45:16 +00:00
chickenleaf
fc0835bae3
CanGc fixes in focusevent.rs oscillartornode.rs response.rs resizeobserversize.rs animationevent.rs (#33827)
Signed-off-by: L Ashwin B <lashwinib@gmail.com>
2024-10-13 21:35:59 +00:00
Simon Wülker
f0045a7686
remove usage of legacy numeric operations in script (#33095)
These operations are deprecated and might be removed
in a future rust version. Clippy is also complaining
about them.

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2024-08-16 21:30:13 +00:00
Martin Robinson
3398fc017b
Move non-gfx things out of gfx_traits and create a base crate (#32296)
For a long time, `gfx_traits` has held a lot of things unrelated to graphics
and also unrelated to the `gfx` crate (which is mostly about fonts).
This is a cleanup which does a few things:

1. Move non `gfx` crate things out of `gfx_traits`. This is important in
   order to prevent dependency cycles with a different integration between
   layout, script, and fonts.
2. Rename the `msg` crate to `base`. It didn't really contain anything
   to do with messages and instead mostly holds ids, which are used
   across many different crates in Servo. This new crate will hold the
   *rare* data types that are widely used.

Details:

 - All BackgroundHangMonitor-related things from base to a new
   `background_hang_monitor_api` crate.
 - Moved `TraversalDirection` to `script_traits`
 - Moved `Epoch`-related things from `gfx_traits` to `base`.
 - Moved `PrintTree` to base. This should be widely useful in Servo.
 - Moved `WebrenderApi` from `base` to `webrender_traits` and renamed it
   to `WebRenderFontApi`.
2024-05-17 12:28:58 +00:00
Oluwatobi Sofela
66ad795014
clippy: Fix mem_replace_with_default warnings (#31921) 2024-03-28 13:10:37 +00:00
Oluwatobi Sofela
da76ebabe9
clippy: Fix option_map_unit_fn warnings (#31906) 2024-03-27 18:43:56 +00:00
Oluwatobi Sofela
b55d0a2053
clippy: Fix clone-on-copy warnings (#31877) 2024-03-26 19:55:20 +00:00
Samson
604979e367
Replace script_plugins with a clippy like rustc driver (named crown) (#30508)
* Remove script_plugins

* Use crown instead of script_plugins

* crown_is_not_used

* Use crown in command base

* bootstrap crown

* tidy happy

* disable sccache

* Bring crown in tree

* Install crown from tree

* fix windows ci

* fix warning

* fix mac

libscript_plugins.dylib is not available anymore

* Update components/script/lib.rs

Co-authored-by: Martin Robinson <mrobinson@igalia.com>

* Update for nightly-2023-03-18

Mostly just based off https://github.com/servo/servo/pull/30630

* Always install crown

it's slow only when there is new version

* Run crown test with `mach test-unit`

* Small fixups; better trace_in_no_trace tests

* Better doc

* crown in config.toml

* Fix tidy for real

* no sccache on rustc_wrapper

* document rustc overrides

* fixup of compiletest

* Make a few minor comment adjustments

* Fix a typo in python/servo/platform/base.py

Co-authored-by: Samson <16504129+sagudev@users.noreply.github.com>

* Proper test types

* Ignore tidy on crown/tests

---------

Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2023-12-01 15:50:52 +00:00
Samson
aad2dccc9c
Strict import formatting (grouping and granularity) (#30325)
* strict imports formatting

* Reformat all imports
2023-09-11 19:16:54 +00:00
Samson
711dbbd4af
remove extern crate (#30311)
* remove extern crate

* Update components/script_plugins/lib.rs

Co-authored-by: Martin Robinson <mrobinson@igalia.com>

---------

Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2023-09-08 12:11:31 +00:00
Samson
9514f670d1
No tracing of nop traceable fields (#29926)
* Add `no_trace` option to JSTraceable derive

* NoTrace wrapper

* Port some types to no_trace schematics

* Fixing my unsafe mistakes (not tracing traceables)

* Add docs & safety guards for no_trace

Safety guards (trait shenanigans) guarantees safety usage of `no_trace`

* Port canvas_traits to no_trace

* Port servo_media to no_trace

* Port net_traits to no_trace

* Port style to no_trace

* Port webgpu to no_trace

* Port script_traits to no_trace

* Port canvas_traits, devtools_traits, embedder_traits, profile_traits to no_trace

* unrooted_must_root lint in seperate file

* Add trace_in_no_trace_lint as script_plugin

* Composable types in must_not_have_traceable

* Introduced HashMapTracedValues wrapper

* `HashMap<NoTrace<K>,V>`->`HashMapTracedValues<K,V>`

* Port rest of servo's types to no_trace

* Port html5ever, euclid, mime and http to no_trace

* Port remaining externals to no_trace

* Port webxr and Arc<Mutex<_>>

* Fix spelling in notrace doc
2023-08-04 10:17:43 +00:00
Martin Robinson
17e3f34e65 Fix flakiness in animation tests
1. When updating the animation timeline, ensure that nodes that are
   animating are marked dirty, if necessary, so any style queries will
   force an layout flush.
2. Disable the problematic transition test suites, as they are in Gecko.
   These suites often fail when Servo is so overloaded that it cannot
   deliver frames fast enough to get more than two samples during the
   animation lifecycle.

Fixes #28334.
Fixes #26435.
Fixes #21486.
2023-05-02 08:37:15 +02:00
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
teymour-aldridge
ff767b13a9 Remove unused arguments from methods. 2021-02-05 14:29:45 +00:00
bors-servo
6659e9004d
Auto merge of #27032 - mrobinson:fractional-iteration, r=jdm
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.

Fixes: #14858

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #14858
- [x] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
2020-06-24 15:54:27 -04: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
Martin Robinson
e901fa2c39 Cancel animations for nodes which are removed from the DOM
This includes nodes which are being reparented.
2020-06-17 16:35:06 +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
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
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