Bug 1839315: part 4) Link from `SheetLoadData::mWasAlternate` to spec. r=emilio DONTBUILD
[gecko.git] / layout / style / TimelineCollection.h
blob1f61845e2e2645f7165f51b5c63eff9c04102d5f
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_TimelineCollection_h
8 #define mozilla_TimelineCollection_h
10 #include "mozilla/Assertions.h"
11 #include "mozilla/LinkedList.h"
12 #include "mozilla/Maybe.h"
13 #include "mozilla/RefPtr.h"
14 #include "nsAtomHashKeys.h"
15 #include "nsTHashMap.h"
17 class nsAtom;
19 namespace mozilla {
20 namespace dom {
21 class Element;
23 enum class PseudoStyleType : uint8_t;
25 // The collection of ScrollTimeline or ViewTimeline. We use the template class
26 // to share the implementation for these two timeline types.
27 template <class TimelineType>
28 class TimelineCollection final
29 : public LinkedListElement<TimelineCollection<TimelineType>> {
30 public:
31 using SelfType = TimelineCollection<TimelineType>;
32 using TimelineMap = nsTHashMap<RefPtr<nsAtom>, RefPtr<TimelineType>>;
34 TimelineCollection(dom::Element& aElement, PseudoStyleType aPseudoType)
35 : mElement(aElement), mPseudo(aPseudoType) {
36 MOZ_COUNT_CTOR(TimelineCollection);
39 ~TimelineCollection();
41 already_AddRefed<TimelineType> Lookup(nsAtom* aName) const {
42 return mTimelines.Get(aName).forget();
45 already_AddRefed<TimelineType> Extract(nsAtom* aName) {
46 Maybe<RefPtr<TimelineType>> timeline = mTimelines.Extract(aName);
47 return timeline ? timeline->forget() : nullptr;
50 void Swap(TimelineMap& aValue) { mTimelines.SwapElements(aValue); }
52 void Destroy();
54 // Get the collection of timelines for the given |aElement| and or create it
55 // if it does not already exist.
56 static TimelineCollection* Get(const dom::Element* aElement,
57 PseudoStyleType aPseudoType);
59 private:
60 // The element. Weak reference is fine since it owns us.
61 dom::Element& mElement;
62 const PseudoStyleType mPseudo;
64 TimelineMap mTimelines;
67 } // namespace mozilla
69 #endif // mozilla_TimelineCollection_h