ShadowParts.h (1320B)
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_ShadowParts_h 8 #define mozilla_ShadowParts_h 9 10 #include "nsAtomHashKeys.h" 11 #include "nsClassHashtable.h" 12 #include "nsRefPtrHashtable.h" 13 #include "nsStringFwd.h" 14 #include "nsTHashtable.h" 15 16 namespace mozilla { 17 18 class ShadowParts final { 19 public: 20 ShadowParts(ShadowParts&&) = default; 21 ShadowParts(const ShadowParts&) = delete; 22 static ShadowParts Parse(const nsAString&); 23 24 using PartList = AutoTArray<RefPtr<nsAtom>, 1>; 25 26 PartList* Get(nsAtom* aName) const { return mMappings.Get(aName); } 27 28 nsAtom* GetReverse(nsAtom* aName) const { 29 return mReverseMappings.GetWeak(aName); 30 } 31 32 #ifdef DEBUG 33 void Dump() const; 34 #endif 35 36 private: 37 ShadowParts() = default; 38 39 // TODO(emilio): If the two hashtables take a lot of memory we should consider 40 // just using an nsTArray<Pair<>> or something. 41 nsClassHashtable<nsAtomHashKey, PartList> mMappings; 42 nsRefPtrHashtable<nsAtomHashKey, nsAtom> mReverseMappings; 43 }; 44 45 } // namespace mozilla 46 47 #endif // mozilla_ShadowParts_h