CSSAnimation.cpp 3.3 KB

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