Backed out 4 changesets (bug 1825722) for causing reftest failures CLOSED TREE
[gecko.git] / layout / style / AnimatedPropertyIDSet.h
blob667f081421c17eea88b32d4f92f58b5c8ee9bd04
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_AnimatedPropertyIDSet_h
8 #define mozilla_AnimatedPropertyIDSet_h
10 #include "mozilla/ServoBindings.h"
12 #include "AnimatedPropertyID.h"
13 #include "nsCSSPropertyIDSet.h"
14 #include "nsTHashSet.h"
16 namespace mozilla {
18 class AnimatedPropertyIDSet {
19 public:
20 void AddProperty(const AnimatedPropertyID& aProperty) {
21 if (aProperty.IsCustom()) {
22 mCustomNames.Insert(aProperty.mCustomName);
23 } else {
24 mIDs.AddProperty(aProperty.mID);
28 void RemoveProperty(const AnimatedPropertyID& aProperty) {
29 if (aProperty.IsCustom()) {
30 mCustomNames.Remove(aProperty.mCustomName);
31 } else {
32 mIDs.RemoveProperty(aProperty.mID);
36 bool HasProperty(const AnimatedPropertyID& aProperty) const {
37 if (aProperty.IsCustom()) {
38 return mCustomNames.Contains(aProperty.mCustomName);
40 return mIDs.HasProperty(aProperty.mID);
43 bool Intersects(const nsCSSPropertyIDSet& aIDs) const {
44 return mIDs.Intersects(aIDs);
47 bool IsSubsetOf(const AnimatedPropertyIDSet& aOther) const {
48 if (!mIDs.IsSubsetOf(aOther.mIDs) ||
49 mCustomNames.Count() > aOther.mCustomNames.Count()) {
50 return false;
52 for (const auto& name : mCustomNames) {
53 if (!aOther.mCustomNames.Contains(name)) {
54 return false;
57 return true;
60 void AddProperties(const AnimatedPropertyIDSet& aOther) {
61 mIDs |= aOther.mIDs;
62 for (const auto& name : aOther.mCustomNames) {
63 mCustomNames.Insert(name);
67 using CustomNameSet = nsTHashSet<RefPtr<nsAtom>>;
69 // Iterator for use in range-based for loops
70 class Iterator {
71 public:
72 Iterator(Iterator&& aOther)
73 : mPropertySet(aOther.mPropertySet),
74 mIDIterator(std::move(aOther.mIDIterator)),
75 mCustomNameIterator(std::move(aOther.mCustomNameIterator)),
76 mPropertyID(eCSSProperty_UNKNOWN) {}
77 Iterator() = delete;
78 Iterator(const Iterator&) = delete;
79 Iterator& operator=(const Iterator&) = delete;
80 Iterator& operator=(const Iterator&&) = delete;
82 static Iterator BeginIterator(const AnimatedPropertyIDSet& aPropertySet) {
83 return Iterator(aPropertySet, aPropertySet.mIDs.begin(),
84 aPropertySet.mCustomNames.begin());
87 static Iterator EndIterator(const AnimatedPropertyIDSet& aPropertySet) {
88 return Iterator(aPropertySet, aPropertySet.mIDs.end(),
89 aPropertySet.mCustomNames.end());
92 bool operator!=(const Iterator& aOther) const {
93 return mIDIterator != aOther.mIDIterator ||
94 mCustomNameIterator != aOther.mCustomNameIterator;
97 Iterator& operator++() {
98 MOZ_ASSERT(mIDIterator != mPropertySet.mIDs.end() ||
99 mCustomNameIterator != mPropertySet.mCustomNames.end(),
100 "Should not iterate beyond end");
101 if (mIDIterator != mPropertySet.mIDs.end()) {
102 ++mIDIterator;
103 } else {
104 ++mCustomNameIterator;
106 return *this;
109 AnimatedPropertyID operator*() {
110 if (mIDIterator != mPropertySet.mIDs.end()) {
111 mPropertyID.mID = *mIDIterator;
112 mPropertyID.mCustomName = nullptr;
113 } else if (mCustomNameIterator != mPropertySet.mCustomNames.end()) {
114 mPropertyID.mID = eCSSPropertyExtra_variable;
115 mPropertyID.mCustomName = *mCustomNameIterator;
116 } else {
117 MOZ_ASSERT_UNREACHABLE("Should not dereference beyond end");
118 mPropertyID.mID = eCSSProperty_UNKNOWN;
119 mPropertyID.mCustomName = nullptr;
121 return mPropertyID;
124 private:
125 Iterator(const AnimatedPropertyIDSet& aPropertySet,
126 nsCSSPropertyIDSet::Iterator aIDIterator,
127 CustomNameSet::const_iterator aCustomNameIterator)
128 : mPropertySet(aPropertySet),
129 mIDIterator(std::move(aIDIterator)),
130 mCustomNameIterator(std::move(aCustomNameIterator)),
131 mPropertyID(eCSSProperty_UNKNOWN) {}
133 const AnimatedPropertyIDSet& mPropertySet;
134 nsCSSPropertyIDSet::Iterator mIDIterator;
135 CustomNameSet::const_iterator mCustomNameIterator;
136 AnimatedPropertyID mPropertyID;
139 Iterator begin() const { return Iterator::BeginIterator(*this); }
140 Iterator end() const { return Iterator::EndIterator(*this); }
142 private:
143 nsCSSPropertyIDSet mIDs;
144 CustomNameSet mCustomNames;
147 } // namespace mozilla
149 #endif // mozilla_AnimatedPropertyIDSet_h