CSSTransition.cpp 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (c) 2024, Matthew Olsson <mattco@serenityos.org>.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/Intrinsics.h>
  7. #include <LibWeb/CSS/CSSStyleDeclaration.h>
  8. #include <LibWeb/CSS/CSSTransition.h>
  9. #include <LibWeb/DOM/Element.h>
  10. namespace Web::CSS {
  11. JS_DEFINE_ALLOCATOR(CSSTransition);
  12. JS::NonnullGCPtr<CSSTransition> CSSTransition::create(JS::Realm& realm, PropertyID property_id, size_t transition_generation)
  13. {
  14. return realm.heap().allocate<CSSTransition>(realm, realm, property_id, transition_generation);
  15. }
  16. Animations::AnimationClass CSSTransition::animation_class() const
  17. {
  18. return Animations::AnimationClass::CSSTransition;
  19. }
  20. Optional<int> CSSTransition::class_specific_composite_order(JS::NonnullGCPtr<Animations::Animation> other_animation) const
  21. {
  22. auto other = JS::NonnullGCPtr { verify_cast<CSSTransition>(*other_animation) };
  23. // Within the set of CSS Transitions, two animations A and B are sorted in composite order (first to last) as
  24. // follows:
  25. // 1. If neither A nor B has an owning element, sort based on their relative position in the global animation list.
  26. if (!m_owning_element && !other->m_owning_element)
  27. return global_animation_list_order() - other->global_animation_list_order();
  28. // 2. Otherwise, if only one of A or B has an owning element, let the animation with an owning element sort first.
  29. if (m_owning_element && !other->m_owning_element)
  30. return -1;
  31. if (!m_owning_element && other->m_owning_element)
  32. return 1;
  33. // 3. Otherwise, if the owning element of A and B differs, sort A and B by tree order of their corresponding owning
  34. // elements. With regard to pseudo-elements, the sort order is as follows:
  35. // - element
  36. // - ::marker
  37. // - ::before
  38. // - any other pseudo-elements not mentioned specifically in this list, sorted in ascending order by the Unicode
  39. // codepoints that make up each selector
  40. // - ::after
  41. // - element children
  42. if (m_owning_element.ptr() != other->m_owning_element.ptr()) {
  43. // FIXME: Actually sort by tree order
  44. return {};
  45. }
  46. // 4. Otherwise, if A and B have different transition generation values, sort by their corresponding transition
  47. // generation in ascending order.
  48. if (m_transition_generation != other->m_transition_generation)
  49. return m_transition_generation - other->m_transition_generation;
  50. // FIXME:
  51. // 5. Otherwise, sort A and B in ascending order by the Unicode codepoints that make up the expanded transition
  52. // property name of each transition (i.e. without attempting case conversion and such that ‘-moz-column-width’
  53. // sorts before ‘column-width’).
  54. return {};
  55. }
  56. CSSTransition::CSSTransition(JS::Realm& realm, PropertyID property_id, size_t transition_generation)
  57. : Animations::Animation(realm)
  58. , m_transition_property(property_id)
  59. , m_transition_generation(transition_generation)
  60. {
  61. // FIXME:
  62. // Transitions generated using the markup defined in this specification are not added to the global animation list
  63. // when they are created. Instead, these animations are appended to the global animation list at the first moment
  64. // when they transition out of the idle play state after being disassociated from their owning element. Transitions
  65. // that have been disassociated from their owning element but are still idle do not have a defined composite order.
  66. }
  67. void CSSTransition::initialize(JS::Realm& realm)
  68. {
  69. Base::initialize(realm);
  70. WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSTransition);
  71. }
  72. void CSSTransition::visit_edges(Cell::Visitor& visitor)
  73. {
  74. Base::visit_edges(visitor);
  75. visitor.visit(m_owning_element);
  76. visitor.visit(m_cached_declaration);
  77. }
  78. }