Commit Graph

116 Commits

Author SHA1 Message Date
Kenneth Myhra
a3661fd7f2 LibWeb: Let queue_global_task() take a JS::HeapFunction
Changes the signature of queue_global_task() from AK:Function to
JS::HeapFunction to be more clear to the user of the function that this
is what it uses internally.
2024-04-20 18:11:01 +02:00
Andreas Kling
53d0dd4a2e LibJS+LibWeb: Use new Cell::Visitor helpers to avoid manual iteration 2024-04-16 07:40:01 +02:00
Matthew Olsson
8450041b52 LibWeb: Fix some GCVerifier warnings 2024-04-07 07:03:13 +02:00
Idan Horowitz
c61f341320 LibWeb: Add missing visit_edges implementation to AnimationEffect 2024-04-06 06:59:36 +02:00
Andreas Kling
2ef37c0b06 LibWeb: Make EventLoop, TaskQueue, and Task GC-allocated
...and use HeapFunction instead of SafeFunction for task steps.

Since there is only one EventLoop per process, it lives as a global
handle in the VM custom data.

This makes it much easier to reason about lifetimes of tasks, task
steps, and random stuff captured by them.
2024-04-05 08:14:19 +02:00
Tim Ledbetter
eebdc7bc88 LibWeb: Allow the Performance object to be used by workers 2024-04-02 07:46:16 +02:00
Matthew Olsson
b2907f62a6 LibWeb: Reject invalid easing functions in AnimationEffect.updateTiming 2024-03-30 19:26:58 +01:00
Matthew Olsson
911088278d LibWeb: Add the CSSTransition IDL object 2024-03-29 21:58:12 +01:00
Matthew Olsson
560b07dda3 LibWeb: Use the timeline time when saving animation play/pause time 2024-03-28 21:08:32 +01:00
Matthew Olsson
e4dba9d932 LibWeb: Cache the last CSS play-state value on KeyframeEffect
This way we can just leave it alone if the property hasn't changed.
Notably, if the play-state property has been set to 'paused', and then
the user gets the animation with JS and calls .play() on it, it should
start playing despite the play-state property value.
2024-03-27 09:40:05 -06:00
Aliaksandr Kalenik
42d5883d57 LibWeb: Set animation update flag from Animation::invalidate_effect()
Fixes regressed animation tests.
2024-03-21 16:10:26 +01:00
Matthew Olsson
0d70311c90 LibWeb: Resolve unresolved style values eagerly in KeyframeEffect
This isn't required as the StyleComputer will do this when animating,
but this allows the properties to be resolved once instead of on
every animation frame.

Note that we still pass AllowUnresolved::Yes because the properties will
not be resolved if there is no target.
2024-03-20 09:17:33 +01:00
Matthew Olsson
3dd9f2715f LibWeb: Resolve unresolved style values when animating properties 2024-03-20 09:17:33 +01:00
Matthew Olsson
b2fb9cc7d3 LibWeb: Allow ignoring unresolved style values when iterating properties
When iterating through a @keyframes rule, it isn't possible to resolve
unresolved style properties since there are no elements. This change
allows those properties to simply pass through this helper function.
2024-03-20 09:17:33 +01:00
Matthew Olsson
ebfc6c33a6 LibWeb: Remove "resolved" from the name of Keyframe's property map
These will need to store unresolved styles as well, since they may be
built during parsing of a @keyframes rule. In that case there is no
target element or pseudo-element, and thus the value cannot be resolved.
2024-03-20 09:17:33 +01:00
Aliaksandr Kalenik
cf7c933312 LibWeb: Add fast path to calculate invalidations for animated css props
- Compare only the animated properties
- Clone only the hash map containing animated properties, instead of
  the entire StyleProperties.

Reduces `KeyframeEffect::update_style_properties()` from 10% to 3% in
GitHub profiles.
2024-03-19 17:30:34 +01:00
Andreas Kling
c0d7f748ed LibWeb: Avoid FlyString lookups when setting IDL interface prototypes
This commit introduces a WEB_SET_PROTOTYPE_FOR_INTERFACE macro that
caches the interface name in a local static FlyString. This means that
we only pay for FlyString-from-literal lookup once per browser lifetime
instead of every time the interface is instantiated.
2024-03-16 16:35:54 +01:00
Aliaksandr Kalenik
a9b8840a82 LibWeb: Add fast path for animated style properties update
Patch up existing style properties instead of using the regular style
invalidation path, which requires rule matching for each element in the
invalidated subtree.

- !important properties: this change introduces a flag used to skip the
  update of animated properties overridden by !important.
- inherited animated properties: for now, these are invalidated by
  traversing animated element's subtree to propagate the update.
- StyleProperties has a separate array for animated properties that
  allows the removal animated properties after animation has ended,
  without requiring full style invalidation.
2024-03-16 09:49:40 +01:00
Aliaksandr Kalenik
dd07c7f729 LibWeb: Delete AnimationEffect::create() function
It should not be possible to create AnimationEffect because it is
an abstract interface according to the spec.
2024-03-16 09:49:40 +01:00
Andreas Kling
b98a2be96b LibWeb: Ignore window-forwarded document.body.onfoo in detached DOM
Normally, assigning to e.g document.body.onload will forward to
window.onload. However, in a detached DOM tree, there is no associated
window, so we have nowhere to forward to, making this a no-op.

The bulk of this change is making Document::window() return a nullable
pointer, as documents created by DOMParser or DOMImplementation do not
have an associated window object, and so must be able to return null
from here.
2024-03-11 18:29:10 +01:00
Aliaksandr Kalenik
2129c5d8b0 LibWeb: Unregister AnimationTimeline from document in finalize()
...instead of destructor because by the time it is executed, document
could already be destroyed.
2024-03-11 16:44:05 +01:00
Matthew Olsson
e91f4dcd79 LibWeb: Use Performance for animation time instead of MonotonicTime
Performance handles the document origin time correctly, and prevents
these times from being unusually large. Also initialize the
DocumentTimeline time in the constructor, since these can be created
from JS.
2024-03-10 15:13:47 +01:00
Matthew Olsson
d76c2d45c4 LibWeb: Remove scopes for execution contexts in Animation finish steps 2024-03-09 15:34:27 +01:00
Matthew Olsson
fc6a6d29ec LibWeb: Ensure m_is_finished is false after cancelling Animation 2024-03-09 15:34:27 +01:00
Matthew Olsson
e11b9658ed LibWeb: Disassociate animations from Animatables when setting effects 2024-03-09 15:34:27 +01:00
Matthew Olsson
90290eb985 LibWeb: Store Animations in Animatable instead of AnimationEffects
This is closer to what the spec instructs us to do, and matches how
associations are maintained in the timelines. Also note that the removed
destructor logic is not necessary since we visit the associated
animations anyways.
2024-03-09 15:34:27 +01:00
Matthew Olsson
f386c01ae1 LibWeb: Use the correct start time when pausing/playing animations 2024-03-09 15:34:27 +01:00
Matthew Olsson
24ec5838ba LibWeb: Visit Animatable::m_associated_effects 2024-03-09 15:34:27 +01:00
Matthew Olsson
c1ab6ca6b4 LibWeb: Do not invalidate elements with animations in the CSS cascade
See the note added to Animation::cancel for more info
2024-03-02 19:58:12 +01:00
Matthew Olsson
0f54d797d2 LibWeb: Handle pre-existing animations when considering animation-name
If a DOM::Element has an animation-name property, then in addition to
remembering where it came from, it will also remember the
Animations::Animation object that was created for it. This allows
StyleComputer to cancel that animation if the animation-name property
changes as well as to apply any changes required (for example, if
animation-play-state changes from "running" to "paused", it needs to
call .pause() on the animation).
2024-02-25 21:12:42 +00:00
Matthew Olsson
2ee022dead LibWeb: Set KeyframeEffect's pseudo-element if applicable 2024-02-25 21:12:42 +00:00
Matthew Olsson
921f6c1e78 LibWeb: Run play tasks before pause tasks
The logic of play() and pause() assumes this to be the case
2024-02-25 21:12:42 +00:00
Matthew Olsson
62f62a0e52 LibWeb: Correctly set timing function in AnimationEffect::update_timing
Also pulls out the parse_easing_string function out since it will be
needed elsewhere
2024-02-25 08:51:50 +01:00
Matthew Olsson
b33bb0997a LibWeb: Move easing parsing code out into a dedicated function
This will be used outside of StyleComputer
2024-02-25 08:51:50 +01:00
Matthew Olsson
ee63c729e5 LibWeb: Expand shorthand properties in KeyframeEffect 2024-02-25 08:51:50 +01:00
Matthew Olsson
d2cfea5acc LibWeb: Add Animation event handler attributes 2024-02-23 21:23:57 +01:00
Matthew Olsson
2dd5d0c310 LibWeb: Implement Animation.reverse() 2024-02-23 21:23:57 +01:00
Matthew Olsson
9ab73f2675 LibWeb: Implement Animation.updatePlaybackRate() 2024-02-23 21:23:57 +01:00
Matthew Olsson
d351389d72 LibWeb: Implement Animation.persist() 2024-02-23 21:23:57 +01:00
Matthew Olsson
3c055ff76d LibWeb: Implement Animation.cancel() 2024-02-23 21:23:57 +01:00
Matthew Olsson
9abe472928 LibWeb: Implement Animation.finish() 2024-02-23 21:23:57 +01:00
Matthew Olsson
c0b9179d9a LibWeb: Implement Animation.pause() 2024-02-23 21:23:57 +01:00
Matthew Olsson
ae3326a447 LibWeb: Transition StyleComputer to Web Animations
With this commit, we are finally running animations off of the web
animations spec! A lot of the work StyleComputer is doing is now done
elsewhere. For example, fill-forward animations are handled by
Animation::is_relevant() returning true in the after phase, meaning the
"active_state_if_fill_forward" map is no longer needed.
2024-02-23 20:52:37 +01:00
Matthew Olsson
ee4abacde6 LibWeb: Add AnimationEffect::target_properties() 2024-02-22 07:31:54 +01:00
Matthew Olsson
10fddb99fc LibWeb: Implement Document::remove_replaced_animations() 2024-02-22 07:31:54 +01:00
Matthew Olsson
9bab1a95a5 LibWeb: Keep track of AnimationEffect's previous phase and iteration
This will be required for detecting transitions in StyleComputer
2024-02-22 07:31:54 +01:00
Matthew Olsson
35859c0467 LibWeb: Add helpers to convert between FillMode and Direction enums 2024-02-22 07:31:54 +01:00
Matthew Olsson
3ea26327c7 LibWeb: Implement Animatable::get_animations() 2024-02-21 19:52:35 +01:00
Matthew Olsson
145ae54718 LibWeb: Add a few Animation/AnimationEffect getters 2024-02-21 19:52:35 +01:00
Matthew Olsson
06a8674eec LibWeb: Simplify Animation::update_finished_state a bit
This removes the two boolean hack in favor of using the existing
mechanism to remove queued tasks. It also exposes the element
invalidation behavior for call sites that don't necessarily want to
update the finished state, but still need to invalidate the associated
target.
2024-02-21 19:52:35 +01:00