AnimationTarget.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_AnimationTarget_h
  6. #define mozilla_AnimationTarget_h
  7. #include "mozilla/Attributes.h" // For MOZ_NON_OWNING_REF
  8. #include "mozilla/Maybe.h"
  9. #include "mozilla/RefPtr.h"
  10. #include "nsCSSPseudoElements.h"
  11. namespace mozilla {
  12. namespace dom {
  13. class Element;
  14. } // namespace dom
  15. struct OwningAnimationTarget
  16. {
  17. OwningAnimationTarget(dom::Element* aElement, CSSPseudoElementType aType)
  18. : mElement(aElement), mPseudoType(aType) { }
  19. explicit OwningAnimationTarget(dom::Element* aElement)
  20. : mElement(aElement) { }
  21. bool operator==(const OwningAnimationTarget& aOther) const
  22. {
  23. return mElement == aOther.mElement &&
  24. mPseudoType == aOther.mPseudoType;
  25. }
  26. // mElement represents the parent element of a pseudo-element, not the
  27. // generated content element.
  28. RefPtr<dom::Element> mElement;
  29. CSSPseudoElementType mPseudoType = CSSPseudoElementType::NotPseudo;
  30. };
  31. struct NonOwningAnimationTarget
  32. {
  33. NonOwningAnimationTarget(dom::Element* aElement, CSSPseudoElementType aType)
  34. : mElement(aElement), mPseudoType(aType) { }
  35. explicit NonOwningAnimationTarget(const OwningAnimationTarget& aOther)
  36. : mElement(aOther.mElement), mPseudoType(aOther.mPseudoType) { }
  37. // mElement represents the parent element of a pseudo-element, not the
  38. // generated content element.
  39. dom::Element* MOZ_NON_OWNING_REF mElement = nullptr;
  40. CSSPseudoElementType mPseudoType = CSSPseudoElementType::NotPseudo;
  41. };
  42. // Helper functions for cycle-collecting Maybe<OwningAnimationTarget>
  43. inline void
  44. ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
  45. Maybe<OwningAnimationTarget>& aTarget,
  46. const char* aName,
  47. uint32_t aFlags = 0)
  48. {
  49. if (aTarget) {
  50. ImplCycleCollectionTraverse(aCallback, aTarget->mElement, aName, aFlags);
  51. }
  52. }
  53. inline void
  54. ImplCycleCollectionUnlink(Maybe<OwningAnimationTarget>& aTarget)
  55. {
  56. if (aTarget) {
  57. ImplCycleCollectionUnlink(aTarget->mElement);
  58. }
  59. }
  60. } // namespace mozilla
  61. #endif // mozilla_AnimationTarget_h