CSSTransition.cpp 3.8 KB

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