CSSAnimation.cpp 3.3 KB

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