no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / layout / style / TimelineCollection.h
blob21e0b2b6bc39ce9ba8961ea7d00c43c7380477b9
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);
58 const TimelineMap& Timelines() const { return mTimelines; }
60 private:
61 // The element. Weak reference is fine since it owns us.
62 dom::Element& mElement;
63 const PseudoStyleType mPseudo;
65 TimelineMap mTimelines;
68 } // namespace mozilla
70 #endif // mozilla_TimelineCollection_h