AnimationTimeline.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) 2023, Matthew Olsson <mattco@serenityos.org>.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Animations/AnimationTimeline.h>
  7. #include <LibWeb/DOM/Document.h>
  8. namespace Web::Animations {
  9. WebIDL::ExceptionOr<void> AnimationTimeline::set_current_time(Optional<double> value)
  10. {
  11. if (value == m_current_time)
  12. return {};
  13. if (m_is_monotonically_increasing && m_current_time.has_value()) {
  14. if (!value.has_value() || value.value() < m_current_time.value())
  15. m_is_monotonically_increasing = false;
  16. }
  17. m_current_time = value;
  18. return {};
  19. }
  20. void AnimationTimeline::set_associated_document(JS::GCPtr<DOM::Document> document)
  21. {
  22. m_associated_document = document;
  23. }
  24. // https://www.w3.org/TR/web-animations-1/#inactive-timeline
  25. bool AnimationTimeline::is_inactive() const
  26. {
  27. // A timeline is considered to be inactive when its time value is unresolved.
  28. return !m_current_time.has_value();
  29. }
  30. AnimationTimeline::AnimationTimeline(JS::Realm& realm)
  31. : Bindings::PlatformObject(realm)
  32. {
  33. }
  34. void AnimationTimeline::initialize(JS::Realm& realm)
  35. {
  36. Base::initialize(realm);
  37. set_prototype(&Bindings::ensure_web_prototype<Bindings::AnimationTimelinePrototype>(realm, "AnimationTimeline"));
  38. }
  39. void AnimationTimeline::visit_edges(Cell::Visitor& visitor)
  40. {
  41. Base::visit_edges(visitor);
  42. visitor.visit(m_associated_document);
  43. }
  44. }