CSSTransition.cpp 3.7 KB

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