CSSAnimation.cpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (c) 2024, Matthew Olsson <mattco@serenityos.org>.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Animations/KeyframeEffect.h>
  7. #include <LibWeb/Bindings/Intrinsics.h>
  8. #include <LibWeb/CSS/CSSAnimation.h>
  9. #include <LibWeb/DOM/Element.h>
  10. namespace Web::CSS {
  11. JS::NonnullGCPtr<CSSAnimation> CSSAnimation::create(JS::Realm& realm)
  12. {
  13. return realm.heap().allocate<CSSAnimation>(realm, realm);
  14. }
  15. // https://www.w3.org/TR/css-animations-2/#animation-composite-order
  16. Optional<int> CSSAnimation::class_specific_composite_order(JS::NonnullGCPtr<Animations::Animation> other_animation) const
  17. {
  18. auto other = JS::NonnullGCPtr { verify_cast<CSSAnimation>(*other_animation) };
  19. // The existance of an owning element determines the animation class, so both animations should have their owning
  20. // element in the same state
  21. VERIFY(!m_owning_element == !other->m_owning_element);
  22. // Within the set of CSS Animations with an owning element, two animations A and B are sorted in composite order
  23. // (first to last) as follows:
  24. if (m_owning_element) {
  25. // 1. If the owning element of A and B differs, sort A and B by tree order of their corresponding owning elements.
  26. // With regard to pseudo-elements, the sort order is as follows:
  27. // - element
  28. // - ::marker
  29. // - ::before
  30. // - any other pseudo-elements not mentioned specifically in this list, sorted in ascending order by the Unicode
  31. // codepoints that make up each selector
  32. // - ::after
  33. // - element children
  34. if (m_owning_element.ptr() != other->m_owning_element.ptr()) {
  35. // FIXME: Sort by tree order
  36. return {};
  37. }
  38. // 2. Otherwise, sort A and B based on their position in the computed value of the animation-name property of the
  39. // (common) owning element.
  40. // FIXME: Do this when animation-name supports multiple values
  41. return {};
  42. }
  43. // The composite order of CSS Animations without an owning element is based on their position in the global animation list.
  44. return global_animation_list_order() - other->global_animation_list_order();
  45. }
  46. Animations::AnimationClass CSSAnimation::animation_class() const
  47. {
  48. if (m_owning_element)
  49. return Animations::AnimationClass::CSSAnimationWithOwningElement;
  50. return Animations::AnimationClass::CSSAnimationWithoutOwningElement;
  51. }
  52. CSSAnimation::CSSAnimation(JS::Realm& realm)
  53. : Animations::Animation(realm)
  54. {
  55. // FIXME:
  56. // CSS Animations generated using the markup defined in this specification are not added to the global animation
  57. // list when they are created. Instead, these animations are appended to the global animation list at the first
  58. // moment when they transition out of the idle play state after being disassociated from their owning element. CSS
  59. // Animations that have been disassociated from their owning element but are still idle do not have a defined
  60. // composite order.
  61. }
  62. void CSSAnimation::initialize(JS::Realm& realm)
  63. {
  64. Base::initialize(realm);
  65. WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSAnimation);
  66. }
  67. void CSSAnimation::visit_edges(Cell::Visitor& visitor)
  68. {
  69. Base::visit_edges(visitor);
  70. visitor.visit(m_owning_element);
  71. }
  72. }