Backed out 8 changesets (bug 1873776) for causing vendor failures. CLOSED TREE
[gecko.git] / dom / animation / AnimationTarget.h
blob3a0dacb9aa83b30cda6d031c6791c42a12edec2c
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_AnimationTarget_h
8 #define mozilla_AnimationTarget_h
10 #include "mozilla/Attributes.h" // For MOZ_NON_OWNING_REF
11 #include "mozilla/HashFunctions.h" // For HashNumber, AddToHash
12 #include "mozilla/HashTable.h" // For DefaultHasher, PointerHasher
13 #include "mozilla/Maybe.h"
14 #include "mozilla/RefPtr.h"
15 #include "nsCSSPseudoElements.h"
17 namespace mozilla {
19 namespace dom {
20 class Element;
21 } // namespace dom
23 struct OwningAnimationTarget {
24 OwningAnimationTarget() = default;
26 OwningAnimationTarget(dom::Element* aElement, PseudoStyleType aType)
27 : mElement(aElement), mPseudoType(aType) {}
29 explicit OwningAnimationTarget(dom::Element* aElement) : mElement(aElement) {}
31 bool operator==(const OwningAnimationTarget& aOther) const {
32 return mElement == aOther.mElement && mPseudoType == aOther.mPseudoType;
35 explicit operator bool() const { return !!mElement; }
37 // mElement represents the parent element of a pseudo-element, not the
38 // generated content element.
39 RefPtr<dom::Element> mElement;
40 PseudoStyleType mPseudoType = PseudoStyleType::NotPseudo;
43 struct NonOwningAnimationTarget {
44 NonOwningAnimationTarget() = default;
46 NonOwningAnimationTarget(dom::Element* aElement, PseudoStyleType aType)
47 : mElement(aElement), mPseudoType(aType) {}
49 explicit NonOwningAnimationTarget(const OwningAnimationTarget& aOther)
50 : mElement(aOther.mElement), mPseudoType(aOther.mPseudoType) {}
52 bool operator==(const NonOwningAnimationTarget& aOther) const {
53 return mElement == aOther.mElement && mPseudoType == aOther.mPseudoType;
56 NonOwningAnimationTarget& operator=(const OwningAnimationTarget& aOther) {
57 mElement = aOther.mElement;
58 mPseudoType = aOther.mPseudoType;
59 return *this;
62 explicit operator bool() const { return !!mElement; }
64 // mElement represents the parent element of a pseudo-element, not the
65 // generated content element.
66 dom::Element* MOZ_NON_OWNING_REF mElement = nullptr;
67 PseudoStyleType mPseudoType = PseudoStyleType::NotPseudo;
70 // Helper functions for cycle-collecting Maybe<OwningAnimationTarget>
71 inline void ImplCycleCollectionTraverse(
72 nsCycleCollectionTraversalCallback& aCallback,
73 Maybe<OwningAnimationTarget>& aTarget, const char* aName,
74 uint32_t aFlags = 0) {
75 if (aTarget) {
76 ImplCycleCollectionTraverse(aCallback, aTarget->mElement, aName, aFlags);
80 inline void ImplCycleCollectionUnlink(Maybe<OwningAnimationTarget>& aTarget) {
81 if (aTarget) {
82 ImplCycleCollectionUnlink(aTarget->mElement);
86 // A DefaultHasher specialization for OwningAnimationTarget.
87 template <>
88 struct DefaultHasher<OwningAnimationTarget> {
89 using Key = OwningAnimationTarget;
90 using Lookup = OwningAnimationTarget;
91 using PtrHasher = PointerHasher<dom::Element*>;
93 static HashNumber hash(const Lookup& aLookup) {
94 return AddToHash(PtrHasher::hash(aLookup.mElement.get()),
95 static_cast<uint8_t>(aLookup.mPseudoType));
98 static bool match(const Key& aKey, const Lookup& aLookup) {
99 return PtrHasher::match(aKey.mElement.get(), aLookup.mElement.get()) &&
100 aKey.mPseudoType == aLookup.mPseudoType;
103 static void rekey(Key& aKey, Key&& aNewKey) { aKey = std::move(aNewKey); }
106 } // namespace mozilla
108 #endif // mozilla_AnimationTarget_h