mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibWeb: Make Animation's owning element an AbstractElement
From the spec: > The owning element of a transition refers to the element or pseudo-element to which the transition-property property was applied that generated the animation. https://drafts.csswg.org/css-transitions-2/#owning-element Previously we only stored the element.
This commit is contained in:
parent
b61c857c64
commit
d717dd64b3
Notes:
github-actions[bot]
2025-12-03 12:31:08 +00:00
Author: https://github.com/AtkinsSJ
Commit: d717dd64b3
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6998
6 changed files with 22 additions and 20 deletions
|
|
@ -279,7 +279,7 @@ WebIDL::ExceptionOr<void> Animation::set_playback_rate(double new_playback_rate)
|
|||
// https://www.w3.org/TR/web-animations-1/#animation-play-state
|
||||
Bindings::AnimationPlayState Animation::play_state_for_bindings() const
|
||||
{
|
||||
if (m_owning_element)
|
||||
if (m_owning_element.has_value())
|
||||
m_owning_element->document().update_style();
|
||||
|
||||
return play_state();
|
||||
|
|
@ -338,7 +338,7 @@ bool Animation::is_replaceable() const
|
|||
|
||||
// - The existence of the animation is not prescribed by markup. That is, it is not a CSS animation with an owning
|
||||
// element, nor a CSS transition with an owning element.
|
||||
if ((is_css_animation() || is_css_transition()) && owning_element())
|
||||
if ((is_css_animation() || is_css_transition()) && owning_element().has_value())
|
||||
return false;
|
||||
|
||||
// - The animation's play state is finished.
|
||||
|
|
@ -1368,7 +1368,8 @@ void Animation::visit_edges(Cell::Visitor& visitor)
|
|||
visitor.visit(m_timeline);
|
||||
visitor.visit(m_current_ready_promise);
|
||||
visitor.visit(m_current_finished_promise);
|
||||
visitor.visit(m_owning_element);
|
||||
if (m_owning_element.has_value())
|
||||
m_owning_element->visit(visitor);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <LibJS/Runtime/PromiseCapability.h>
|
||||
#include <LibWeb/Bindings/AnimationPrototype.h>
|
||||
#include <LibWeb/DOM/AbstractElement.h>
|
||||
#include <LibWeb/DOM/EventTarget.h>
|
||||
|
||||
namespace Web::Animations {
|
||||
|
|
@ -104,8 +105,8 @@ public:
|
|||
virtual bool is_css_animation() const { return false; }
|
||||
virtual bool is_css_transition() const { return false; }
|
||||
|
||||
GC::Ptr<DOM::Element> owning_element() const { return m_owning_element; }
|
||||
void set_owning_element(GC::Ptr<DOM::Element> value) { m_owning_element = value; }
|
||||
Optional<DOM::AbstractElement> owning_element() const { return m_owning_element; }
|
||||
void set_owning_element(Optional<DOM::AbstractElement>&& value) { m_owning_element = move(value); }
|
||||
|
||||
virtual AnimationClass animation_class() const { return AnimationClass::None; }
|
||||
virtual int class_specific_composite_order(GC::Ref<Animation>) const { return 0; }
|
||||
|
|
@ -200,7 +201,7 @@ private:
|
|||
TaskState m_pending_pause_task { TaskState::None };
|
||||
|
||||
// https://www.w3.org/TR/css-animations-2/#owning-element-section
|
||||
GC::Ptr<DOM::Element> m_owning_element;
|
||||
Optional<DOM::AbstractElement> m_owning_element;
|
||||
|
||||
Optional<HTML::TaskID> m_pending_finish_microtask_id;
|
||||
|
||||
|
|
|
|||
|
|
@ -26,11 +26,11 @@ int CSSAnimation::class_specific_composite_order(GC::Ref<Animations::Animation>
|
|||
|
||||
// The existence of an owning element determines the animation class, so both animations should have their owning
|
||||
// element in the same state
|
||||
VERIFY(!owning_element() == !other->owning_element());
|
||||
VERIFY(owning_element().has_value() == other->owning_element().has_value());
|
||||
|
||||
// Within the set of CSS Animations with an owning element, two animations A and B are sorted in composite order
|
||||
// (first to last) as follows:
|
||||
if (owning_element()) {
|
||||
if (owning_element().has_value()) {
|
||||
// 1. If the owning element of A and B differs, sort A and B by tree order of their corresponding owning elements.
|
||||
// With regard to pseudo-elements, the sort order is as follows:
|
||||
// - element
|
||||
|
|
@ -40,7 +40,7 @@ int CSSAnimation::class_specific_composite_order(GC::Ref<Animations::Animation>
|
|||
// codepoints that make up each selector
|
||||
// - ::after
|
||||
// - element children
|
||||
if (owning_element().ptr() != other->owning_element().ptr()) {
|
||||
if (owning_element() != other->owning_element()) {
|
||||
// FIXME: Sort by tree order
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -57,7 +57,7 @@ int CSSAnimation::class_specific_composite_order(GC::Ref<Animations::Animation>
|
|||
|
||||
Animations::AnimationClass CSSAnimation::animation_class() const
|
||||
{
|
||||
if (owning_element())
|
||||
if (owning_element().has_value())
|
||||
return Animations::AnimationClass::CSSAnimationWithOwningElement;
|
||||
return Animations::AnimationClass::CSSAnimationWithoutOwningElement;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,13 +46,13 @@ int CSSTransition::class_specific_composite_order(GC::Ref<Animations::Animation>
|
|||
// follows:
|
||||
|
||||
// 1. If neither A nor B has an owning element, sort based on their relative position in the global animation list.
|
||||
if (!owning_element() && !other->owning_element())
|
||||
if (!owning_element().has_value() && !other->owning_element().has_value())
|
||||
return global_animation_list_order() - other->global_animation_list_order();
|
||||
|
||||
// 2. Otherwise, if only one of A or B has an owning element, let the animation with an owning element sort first.
|
||||
if (owning_element() && !other->owning_element())
|
||||
if (owning_element().has_value() && !other->owning_element().has_value())
|
||||
return -1;
|
||||
if (!owning_element() && other->owning_element())
|
||||
if (!owning_element().has_value() && other->owning_element().has_value())
|
||||
return 1;
|
||||
|
||||
// 3. Otherwise, if the owning element of A and B differs, sort A and B by tree order of their corresponding owning
|
||||
|
|
@ -64,7 +64,7 @@ int CSSTransition::class_specific_composite_order(GC::Ref<Animations::Animation>
|
|||
// codepoints that make up each selector
|
||||
// - ::after
|
||||
// - element children
|
||||
if (owning_element().ptr() != other->owning_element().ptr()) {
|
||||
if (owning_element() != other->owning_element()) {
|
||||
// FIXME: Actually sort by tree order
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -119,7 +119,7 @@ CSSTransition::CSSTransition(JS::Realm& realm, DOM::AbstractElement abstract_ele
|
|||
|
||||
m_keyframe_effect->set_key_frame_set(key_frame_set);
|
||||
set_timeline(abstract_element.document().timeline());
|
||||
set_owning_element(abstract_element.element());
|
||||
set_owning_element(abstract_element);
|
||||
set_effect(m_keyframe_effect);
|
||||
abstract_element.element().set_transition(abstract_element.pseudo_element(), m_transition_property, *this);
|
||||
|
||||
|
|
|
|||
|
|
@ -1176,7 +1176,7 @@ void StyleComputer::process_animation_definitions(ComputedProperties const& comp
|
|||
auto animation = CSSAnimation::create(document.realm());
|
||||
animation->set_animation_name(animation_properties.name);
|
||||
animation->set_timeline(document.timeline());
|
||||
animation->set_owning_element(abstract_element.element());
|
||||
animation->set_owning_element(abstract_element);
|
||||
|
||||
auto effect = Animations::KeyframeEffect::create(document.realm());
|
||||
animation->set_effect(effect);
|
||||
|
|
|
|||
|
|
@ -2672,7 +2672,7 @@ void Document::dispatch_events_for_transition(GC::Ref<CSS::CSSTransition> transi
|
|||
auto dispatch_event = [&](FlyString const& type, Interval interval) {
|
||||
// The target for a transition event is the transition’s owning element. If there is no owning element,
|
||||
// no transition events are dispatched.
|
||||
if (!transition->effect() || !transition->owning_element())
|
||||
if (!transition->effect() || !transition->owning_element().has_value())
|
||||
return;
|
||||
|
||||
auto effect = transition->effect();
|
||||
|
|
@ -2692,7 +2692,7 @@ void Document::dispatch_events_for_transition(GC::Ref<CSS::CSSTransition> transi
|
|||
|
||||
append_pending_animation_event({
|
||||
.event = CSS::TransitionEvent::create(
|
||||
transition->owning_element()->realm(),
|
||||
transition->owning_element()->element().realm(),
|
||||
type,
|
||||
CSS::TransitionEventInit {
|
||||
{ .bubbles = true },
|
||||
|
|
@ -2702,7 +2702,7 @@ void Document::dispatch_events_for_transition(GC::Ref<CSS::CSSTransition> transi
|
|||
String {},
|
||||
}),
|
||||
.animation = transition,
|
||||
.target = *transition->owning_element(),
|
||||
.target = transition->owning_element()->element(),
|
||||
.scheduled_event_time = HighResolutionTime::unsafe_shared_current_time(),
|
||||
});
|
||||
};
|
||||
|
|
@ -2785,7 +2785,7 @@ void Document::dispatch_events_for_animation_if_necessary(GC::Ref<Animations::An
|
|||
|
||||
append_pending_animation_event({
|
||||
.event = CSS::AnimationEvent::create(
|
||||
owning_element->realm(),
|
||||
owning_element->element().realm(),
|
||||
name,
|
||||
{
|
||||
{ .bubbles = true },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue