PseudoElementHashEntry.h (1863B)
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/. */ 6 7 #ifndef mozilla_PseudoElementHashEntry_h 8 #define mozilla_PseudoElementHashEntry_h 9 10 #include "PLDHashTable.h" 11 #include "mozilla/AnimationTarget.h" 12 #include "mozilla/HashFunctions.h" 13 #include "mozilla/dom/Element.h" 14 15 namespace mozilla { 16 17 // A hash entry that uses a RefPtr<dom::Element>, PseudoStyleType pair 18 class PseudoElementHashEntry : public PLDHashEntryHdr { 19 public: 20 typedef NonOwningAnimationTarget KeyType; 21 typedef const NonOwningAnimationTarget* KeyTypePointer; 22 23 explicit PseudoElementHashEntry(KeyTypePointer aKey) 24 : mElement(aKey->mElement), mPseudoRequest(aKey->mPseudoRequest) {} 25 PseudoElementHashEntry(PseudoElementHashEntry&& aOther) = default; 26 27 ~PseudoElementHashEntry() = default; 28 29 KeyType GetKey() const { return {mElement, mPseudoRequest}; } 30 bool KeyEquals(KeyTypePointer aKey) const { 31 return mElement == aKey->mElement && mPseudoRequest == aKey->mPseudoRequest; 32 } 33 34 static KeyTypePointer KeyToPointer(KeyType& aKey) { return &aKey; } 35 static PLDHashNumber HashKey(KeyTypePointer aKey) { 36 if (!aKey) return 0; 37 38 // Convert the scoped enum into an integer while adding it to hash. 39 static_assert(sizeof(PseudoStyleType) == sizeof(uint8_t), ""); 40 return mozilla::HashGeneric( 41 aKey->mElement, static_cast<uint8_t>(aKey->mPseudoRequest.mType), 42 aKey->mPseudoRequest.mIdentifier.get()); 43 } 44 enum { ALLOW_MEMMOVE = true }; 45 46 RefPtr<dom::Element> mElement; 47 PseudoStyleRequest mPseudoRequest; 48 }; 49 50 } // namespace mozilla 51 52 #endif // mozilla_PseudoElementHashEntry_h