LibWeb: Move "owning element" of Animation classes into Animation

There's no need to have a virtual method here when we can just store the
owning element pointer on the Animation instead.
This commit is contained in:
Sam Atkins 2024-09-12 16:53:14 +01:00 committed by Andreas Kling
parent 3a10596136
commit a0b96280e4
Notes: github-actions[bot] 2024-09-22 04:43:15 +00:00
6 changed files with 14 additions and 29 deletions

View file

@ -1358,6 +1358,7 @@ void Animation::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_timeline); visitor.visit(m_timeline);
visitor.visit(m_current_ready_promise); visitor.visit(m_current_ready_promise);
visitor.visit(m_current_finished_promise); visitor.visit(m_current_finished_promise);
visitor.visit(m_owning_element);
} }
} }

View file

@ -101,7 +101,8 @@ public:
virtual bool is_css_animation() const { return false; } virtual bool is_css_animation() const { return false; }
virtual bool is_css_transition() const { return false; } virtual bool is_css_transition() const { return false; }
virtual JS::GCPtr<DOM::Element> owning_element() const { return {}; } JS::GCPtr<DOM::Element> owning_element() const { return m_owning_element; }
void set_owning_element(JS::GCPtr<DOM::Element> value) { m_owning_element = value; }
virtual AnimationClass animation_class() const { return AnimationClass::None; } virtual AnimationClass animation_class() const { return AnimationClass::None; }
virtual Optional<int> class_specific_composite_order(JS::NonnullGCPtr<Animation>) const { return {}; } virtual Optional<int> class_specific_composite_order(JS::NonnullGCPtr<Animation>) const { return {}; }
@ -192,6 +193,9 @@ private:
// https://www.w3.org/TR/web-animations-1/#pending-pause-task // https://www.w3.org/TR/web-animations-1/#pending-pause-task
TaskState m_pending_pause_task { TaskState::None }; TaskState m_pending_pause_task { TaskState::None };
// https://www.w3.org/TR/css-animations-2/#owning-element-section
JS::GCPtr<DOM::Element> m_owning_element;
Optional<HTML::TaskID> m_pending_finish_microtask_id; Optional<HTML::TaskID> m_pending_finish_microtask_id;
Optional<double> m_saved_play_time; Optional<double> m_saved_play_time;

View file

@ -26,11 +26,11 @@ Optional<int> CSSAnimation::class_specific_composite_order(JS::NonnullGCPtr<Anim
// The existance of an owning element determines the animation class, so both animations should have their owning // The existance of an owning element determines the animation class, so both animations should have their owning
// element in the same state // element in the same state
VERIFY(!m_owning_element == !other->m_owning_element); VERIFY(!owning_element() == !other->owning_element());
// Within the set of CSS Animations with an owning element, two animations A and B are sorted in composite order // 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: // (first to last) as follows:
if (m_owning_element) { if (owning_element()) {
// 1. If the owning element of A and B differs, sort A and B by tree order of their corresponding owning elements. // 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: // With regard to pseudo-elements, the sort order is as follows:
// - element // - element
@ -40,7 +40,7 @@ Optional<int> CSSAnimation::class_specific_composite_order(JS::NonnullGCPtr<Anim
// codepoints that make up each selector // codepoints that make up each selector
// - ::after // - ::after
// - element children // - element children
if (m_owning_element.ptr() != other->m_owning_element.ptr()) { if (owning_element().ptr() != other->owning_element().ptr()) {
// FIXME: Sort by tree order // FIXME: Sort by tree order
return {}; return {};
} }
@ -57,7 +57,7 @@ Optional<int> CSSAnimation::class_specific_composite_order(JS::NonnullGCPtr<Anim
Animations::AnimationClass CSSAnimation::animation_class() const Animations::AnimationClass CSSAnimation::animation_class() const
{ {
if (m_owning_element) if (owning_element())
return Animations::AnimationClass::CSSAnimationWithOwningElement; return Animations::AnimationClass::CSSAnimationWithOwningElement;
return Animations::AnimationClass::CSSAnimationWithoutOwningElement; return Animations::AnimationClass::CSSAnimationWithoutOwningElement;
} }
@ -79,10 +79,4 @@ void CSSAnimation::initialize(JS::Realm& realm)
WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSAnimation); WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSAnimation);
} }
void CSSAnimation::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_owning_element);
}
} }

View file

@ -20,9 +20,6 @@ class CSSAnimation : public Animations::Animation {
public: public:
static JS::NonnullGCPtr<CSSAnimation> create(JS::Realm&); static JS::NonnullGCPtr<CSSAnimation> create(JS::Realm&);
JS::GCPtr<DOM::Element> owning_element() const override { return m_owning_element; }
void set_owning_element(JS::GCPtr<DOM::Element> value) { m_owning_element = value; }
FlyString const& animation_name() const { return id(); } FlyString const& animation_name() const { return id(); }
virtual Animations::AnimationClass animation_class() const override; virtual Animations::AnimationClass animation_class() const override;
@ -32,12 +29,8 @@ private:
explicit CSSAnimation(JS::Realm&); explicit CSSAnimation(JS::Realm&);
virtual void initialize(JS::Realm&) override; virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
virtual bool is_css_animation() const override { return true; } virtual bool is_css_animation() const override { return true; }
// https://www.w3.org/TR/css-animations-2/#owning-element-section
JS::GCPtr<DOM::Element> m_owning_element;
}; };
} }

View file

@ -32,13 +32,13 @@ Optional<int> CSSTransition::class_specific_composite_order(JS::NonnullGCPtr<Ani
// follows: // follows:
// 1. If neither A nor B has an owning element, sort based on their relative position in the global animation list. // 1. If neither A nor B has an owning element, sort based on their relative position in the global animation list.
if (!m_owning_element && !other->m_owning_element) if (!owning_element() && !other->owning_element())
return global_animation_list_order() - other->global_animation_list_order(); 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. // 2. Otherwise, if only one of A or B has an owning element, let the animation with an owning element sort first.
if (m_owning_element && !other->m_owning_element) if (owning_element() && !other->owning_element())
return -1; return -1;
if (!m_owning_element && other->m_owning_element) if (!owning_element() && other->owning_element())
return 1; return 1;
// 3. Otherwise, if the owning element of A and B differs, sort A and B by tree order of their corresponding owning // 3. Otherwise, if the owning element of A and B differs, sort A and B by tree order of their corresponding owning
@ -50,7 +50,7 @@ Optional<int> CSSTransition::class_specific_composite_order(JS::NonnullGCPtr<Ani
// codepoints that make up each selector // codepoints that make up each selector
// - ::after // - ::after
// - element children // - element children
if (m_owning_element.ptr() != other->m_owning_element.ptr()) { if (owning_element().ptr() != other->owning_element().ptr()) {
// FIXME: Actually sort by tree order // FIXME: Actually sort by tree order
return {}; return {};
} }
@ -88,7 +88,6 @@ void CSSTransition::initialize(JS::Realm& realm)
void CSSTransition::visit_edges(Cell::Visitor& visitor) void CSSTransition::visit_edges(Cell::Visitor& visitor)
{ {
Base::visit_edges(visitor); Base::visit_edges(visitor);
visitor.visit(m_owning_element);
visitor.visit(m_cached_declaration); visitor.visit(m_cached_declaration);
} }

View file

@ -22,9 +22,6 @@ public:
StringView transition_property() const { return string_from_property_id(m_transition_property); } StringView transition_property() const { return string_from_property_id(m_transition_property); }
JS::GCPtr<DOM::Element> owning_element() const override { return m_owning_element; }
void set_owning_element(JS::GCPtr<DOM::Element> value) { m_owning_element = value; }
JS::GCPtr<CSS::CSSStyleDeclaration const> cached_declaration() const { return m_cached_declaration; } JS::GCPtr<CSS::CSSStyleDeclaration const> cached_declaration() const { return m_cached_declaration; }
void set_cached_declaration(JS::GCPtr<CSS::CSSStyleDeclaration const> declaration) { m_cached_declaration = declaration; } void set_cached_declaration(JS::GCPtr<CSS::CSSStyleDeclaration const> declaration) { m_cached_declaration = declaration; }
@ -44,9 +41,6 @@ private:
// https://drafts.csswg.org/css-transitions-2/#transition-generation // https://drafts.csswg.org/css-transitions-2/#transition-generation
size_t m_transition_generation; size_t m_transition_generation;
// https://drafts.csswg.org/css-transitions-2/#owning-element
JS::GCPtr<DOM::Element> m_owning_element;
JS::GCPtr<CSS::CSSStyleDeclaration const> m_cached_declaration; JS::GCPtr<CSS::CSSStyleDeclaration const> m_cached_declaration;
}; };