diff --git a/Libraries/LibWeb/Animations/Animation.cpp b/Libraries/LibWeb/Animations/Animation.cpp index 936fef9811e..e00c9cbce45 100644 --- a/Libraries/LibWeb/Animations/Animation.cpp +++ b/Libraries/LibWeb/Animations/Animation.cpp @@ -279,7 +279,7 @@ WebIDL::ExceptionOr 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); } } diff --git a/Libraries/LibWeb/Animations/Animation.h b/Libraries/LibWeb/Animations/Animation.h index 2849c5ce08a..da6bf8cb26e 100644 --- a/Libraries/LibWeb/Animations/Animation.h +++ b/Libraries/LibWeb/Animations/Animation.h @@ -8,6 +8,7 @@ #include #include +#include #include 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 owning_element() const { return m_owning_element; } - void set_owning_element(GC::Ptr value) { m_owning_element = value; } + Optional owning_element() const { return m_owning_element; } + void set_owning_element(Optional&& value) { m_owning_element = move(value); } virtual AnimationClass animation_class() const { return AnimationClass::None; } virtual int class_specific_composite_order(GC::Ref) 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 m_owning_element; + Optional m_owning_element; Optional m_pending_finish_microtask_id; diff --git a/Libraries/LibWeb/CSS/CSSAnimation.cpp b/Libraries/LibWeb/CSS/CSSAnimation.cpp index 7c6fd096ccb..914b2499722 100644 --- a/Libraries/LibWeb/CSS/CSSAnimation.cpp +++ b/Libraries/LibWeb/CSS/CSSAnimation.cpp @@ -26,11 +26,11 @@ int CSSAnimation::class_specific_composite_order(GC::Ref // 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 // 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::AnimationClass CSSAnimation::animation_class() const { - if (owning_element()) + if (owning_element().has_value()) return Animations::AnimationClass::CSSAnimationWithOwningElement; return Animations::AnimationClass::CSSAnimationWithoutOwningElement; } diff --git a/Libraries/LibWeb/CSS/CSSTransition.cpp b/Libraries/LibWeb/CSS/CSSTransition.cpp index 6ef34964b5a..21296cfd541 100644 --- a/Libraries/LibWeb/CSS/CSSTransition.cpp +++ b/Libraries/LibWeb/CSS/CSSTransition.cpp @@ -46,13 +46,13 @@ int CSSTransition::class_specific_composite_order(GC::Ref // 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 // 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); diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp index 98feed2479a..7b0522fe569 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -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); diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index b4eef237384..ca00f9b8eee 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -2672,7 +2672,7 @@ void Document::dispatch_events_for_transition(GC::Ref 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 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 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::Refrealm(), + owning_element->element().realm(), name, { { .bubbles = true },