Line data Source code
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 "mozilla/dom/Element.h"
11 : #include "mozilla/AnimationTarget.h"
12 : #include "mozilla/HashFunctions.h"
13 : #include "PLDHashTable.h"
14 :
15 : namespace mozilla {
16 :
17 : // A hash entry that uses a RefPtr<dom::Element>, CSSPseudoElementType pair
18 : class PseudoElementHashEntry : public PLDHashEntryHdr
19 : {
20 : public:
21 : typedef NonOwningAnimationTarget KeyType;
22 : typedef const NonOwningAnimationTarget* KeyTypePointer;
23 :
24 6 : explicit PseudoElementHashEntry(KeyTypePointer aKey)
25 12 : : mElement(aKey->mElement)
26 12 : , mPseudoType(aKey->mPseudoType) { }
27 : explicit PseudoElementHashEntry(const PseudoElementHashEntry& aCopy)=default;
28 :
29 6 : ~PseudoElementHashEntry() = default;
30 :
31 4 : KeyType GetKey() const { return { mElement, mPseudoType }; }
32 10 : bool KeyEquals(KeyTypePointer aKey) const
33 : {
34 20 : return mElement == aKey->mElement &&
35 20 : mPseudoType == aKey->mPseudoType;
36 : }
37 :
38 20530 : static KeyTypePointer KeyToPointer(KeyType& aKey) { return &aKey; }
39 3024 : static PLDHashNumber HashKey(KeyTypePointer aKey)
40 : {
41 3024 : if (!aKey)
42 0 : return 0;
43 :
44 : // Convert the scoped enum into an integer while adding it to hash.
45 : // Note: CSSPseudoElementTypeBase is uint8_t, so we convert it into
46 : // uint8_t directly to avoid including the header.
47 3024 : return mozilla::HashGeneric(aKey->mElement,
48 6048 : static_cast<uint8_t>(aKey->mPseudoType));
49 : }
50 : enum { ALLOW_MEMMOVE = true };
51 :
52 : RefPtr<dom::Element> mElement;
53 : CSSPseudoElementType mPseudoType;
54 : };
55 :
56 : } // namespace mozilla
57 :
58 : #endif // mozilla_PseudoElementHashEntry_h
|