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_ShadowParts_h
8 #define mozilla_ShadowParts_h
11 #include "nsTHashtable.h"
12 #include "nsClassHashtable.h"
13 #include "nsRefPtrHashtable.h"
14 #include "nsStringFwd.h"
18 class ShadowParts final
{
20 ShadowParts(ShadowParts
&&) = default;
21 ShadowParts(const ShadowParts
&) = delete;
22 static ShadowParts
Parse(const nsAString
&);
24 using PartList
= AutoTArray
<RefPtr
<nsAtom
>, 1>;
26 PartList
* Get(nsAtom
* aName
) const { return mMappings
.Get(aName
); }
28 nsAtom
* GetReverse(nsAtom
* aName
) const {
29 return mReverseMappings
.GetWeak(aName
);
37 ShadowParts() = default;
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
<nsRefPtrHashKey
<nsAtom
>, PartList
> mMappings
;
42 nsRefPtrHashtable
<nsRefPtrHashKey
<nsAtom
>, nsAtom
> mReverseMappings
;
45 } // namespace mozilla
47 #endif // mozilla_ShadowParts_h