AnimationEffectReadOnly.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_dom_AnimationEffectReadOnly_h
  6. #define mozilla_dom_AnimationEffectReadOnly_h
  7. #include "mozilla/ComputedTiming.h"
  8. #include "mozilla/dom/AnimationEffectTimingReadOnly.h"
  9. #include "mozilla/dom/BindingDeclarations.h"
  10. #include "mozilla/dom/Nullable.h"
  11. #include "mozilla/Maybe.h"
  12. #include "mozilla/StickyTimeDuration.h"
  13. #include "mozilla/TimeStamp.h"
  14. #include "mozilla/TimingParams.h"
  15. #include "nsCycleCollectionParticipant.h"
  16. #include "nsWrapperCache.h"
  17. namespace mozilla {
  18. struct ElementPropertyTransition;
  19. namespace dom {
  20. class Animation;
  21. class AnimationEffectTimingReadOnly;
  22. class KeyframeEffectReadOnly;
  23. struct ComputedTimingProperties;
  24. class AnimationEffectReadOnly : public nsISupports,
  25. public nsWrapperCache
  26. {
  27. public:
  28. NS_DECL_CYCLE_COLLECTING_ISUPPORTS
  29. NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(AnimationEffectReadOnly)
  30. AnimationEffectReadOnly(nsIDocument* aDocument,
  31. AnimationEffectTimingReadOnly* aTiming);
  32. virtual KeyframeEffectReadOnly* AsKeyframeEffect() { return nullptr; }
  33. virtual ElementPropertyTransition* AsTransition() { return nullptr; }
  34. virtual const ElementPropertyTransition* AsTransition() const
  35. {
  36. return nullptr;
  37. }
  38. nsISupports* GetParentObject() const { return mDocument; }
  39. bool IsCurrent() const;
  40. bool IsInEffect() const;
  41. bool IsActiveDurationZero() const
  42. {
  43. return SpecifiedTiming().ActiveDuration() == StickyTimeDuration();
  44. }
  45. already_AddRefed<AnimationEffectTimingReadOnly> Timing();
  46. const TimingParams& SpecifiedTiming() const
  47. {
  48. return mTiming->AsTimingParams();
  49. }
  50. void SetSpecifiedTiming(const TimingParams& aTiming);
  51. // This function takes as input the timing parameters of an animation and
  52. // returns the computed timing at the specified local time.
  53. //
  54. // The local time may be null in which case only static parameters such as the
  55. // active duration are calculated. All other members of the returned object
  56. // are given a null/initial value.
  57. //
  58. // This function returns a null mProgress member of the return value
  59. // if the animation should not be run
  60. // (because it is not currently active and is not filling at this time).
  61. static ComputedTiming
  62. GetComputedTimingAt(const Nullable<TimeDuration>& aLocalTime,
  63. const TimingParams& aTiming,
  64. double aPlaybackRate);
  65. // Shortcut that gets the computed timing using the current local time as
  66. // calculated from the timeline time.
  67. ComputedTiming GetComputedTiming(const TimingParams* aTiming = nullptr) const;
  68. void GetComputedTimingAsDict(ComputedTimingProperties& aRetVal) const;
  69. virtual void SetAnimation(Animation* aAnimation) = 0;
  70. Animation* GetAnimation() const { return mAnimation; };
  71. protected:
  72. virtual ~AnimationEffectReadOnly();
  73. Nullable<TimeDuration> GetLocalTime() const;
  74. protected:
  75. RefPtr<nsIDocument> mDocument;
  76. RefPtr<AnimationEffectTimingReadOnly> mTiming;
  77. RefPtr<Animation> mAnimation;
  78. };
  79. } // namespace dom
  80. } // namespace mozilla
  81. #endif // mozilla_dom_AnimationEffectReadOnly_h